-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #845 from jlandowner/ui-support-yaml2
Show User and Workspace live manifests on UI
- Loading branch information
Showing
11 changed files
with
329 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { ContentCopy } from "@mui/icons-material"; | ||
import { Fab } from "@mui/material"; | ||
import { styled } from "@mui/material/styles"; | ||
import copy from "copy-to-clipboard"; | ||
import hljs from "highlight.js"; | ||
import "highlight.js/styles/default.css"; | ||
import { useSnackbar } from "notistack"; | ||
import React, { useState } from "react"; | ||
|
||
const StyledPre = styled("pre")({ | ||
fontFamily: "Menlo, Monaco, 'Courier New', monospace", | ||
fontSize: 12, | ||
lineHeight: 1.6, | ||
margin: 0, | ||
padding: 16, | ||
whiteSpace: "pre", | ||
wordWrap: "break-word", | ||
overflow: "auto", | ||
border: "1px solid #ccc", | ||
borderRadius: "4px", | ||
backgroundColor: "#1E1E1E", | ||
"& .hljs-attr": { | ||
color: "#9CDCFE", | ||
}, | ||
"& .hljs-string": { | ||
color: "#CE9178", | ||
}, | ||
"& .hljs-number": { | ||
color: "#B5CEA8", | ||
}, | ||
"& .hljs-literal": { | ||
color: "#569CD6", | ||
}, | ||
}); | ||
|
||
const YAMLTextArea: React.FC<{ | ||
code: string; | ||
}> = ({ code }) => { | ||
const [hover, setHover] = useState(false); | ||
const { enqueueSnackbar } = useSnackbar(); | ||
|
||
const onCopy = (text: string) => { | ||
copy(text); | ||
enqueueSnackbar("Copied!", { variant: "success" }); | ||
}; | ||
|
||
const highlightedCode = hljs.highlight(code, { | ||
language: "yaml", | ||
}).value; | ||
|
||
const highlightedCodeWithSpaces = highlightedCode.replace( | ||
/(^|\n)( +)/g, | ||
function (_, newline, spaces) { | ||
return newline + " ".repeat(spaces.length); | ||
} | ||
); | ||
|
||
return ( | ||
<div | ||
onMouseOver={() => setHover(true)} | ||
onMouseLeave={() => setHover(false)} | ||
> | ||
<StyledPre | ||
dangerouslySetInnerHTML={{ __html: highlightedCodeWithSpaces }} | ||
/> | ||
{hover && ( | ||
<Fab | ||
color="secondary" | ||
aria-label="copy" | ||
onClick={() => { | ||
onCopy(code); | ||
}} | ||
size="medium" | ||
sx={{ | ||
position: "absolute", | ||
bottom: 80, | ||
right: 64, | ||
}} | ||
> | ||
<ContentCopy fontSize="small" /> | ||
</Fab> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default YAMLTextArea; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { Close } from "@mui/icons-material"; | ||
import { | ||
Box, | ||
Button, | ||
Dialog, | ||
DialogActions, | ||
DialogContent, | ||
DialogTitle, | ||
IconButton, | ||
Stack, | ||
Tab, | ||
Tabs, | ||
} from "@mui/material"; | ||
import { styled } from "@mui/material/styles"; | ||
import "highlight.js/styles/default.css"; | ||
import React, { useEffect, useState } from "react"; | ||
import { DialogContext } from "../../components/ContextProvider"; | ||
import { User } from "../../proto/gen/dashboard/v1alpha1/user_pb"; | ||
import { useUserService } from "../../services/DashboardServices"; | ||
import YAMLTextArea from "../atoms/YAMLTextArea"; | ||
|
||
const StyledDialogContent = styled(DialogContent)({ | ||
overflow: "auto", | ||
}); | ||
|
||
const UserInfoDialog: React.FC<{ | ||
onClose: () => void; | ||
user: User; | ||
}> = ({ onClose, user }) => { | ||
const userService = useUserService(); | ||
|
||
const [code, setCode] = useState(""); | ||
const [showTab, setShowTab] = useState<"objects">("objects"); | ||
|
||
useEffect(() => { | ||
userService | ||
.getUser({ | ||
userName: user.name, | ||
withRaw: true, | ||
}) | ||
.then((res) => { | ||
setCode(res.user?.raw || "no yaml"); | ||
}); | ||
}, [user]); | ||
|
||
return ( | ||
<Dialog open={true} scroll="paper" fullWidth maxWidth="md"> | ||
<DialogTitle> | ||
<Stack direction="row" alignItems="center" spacing={1}> | ||
User Object | ||
<Box sx={{ flexGrow: 1 }} /> | ||
<IconButton | ||
sx={{ | ||
color: (theme) => theme.palette.grey[500], | ||
}} | ||
onClick={() => onClose()} | ||
> | ||
<Close /> | ||
</IconButton> | ||
</Stack> | ||
</DialogTitle> | ||
|
||
<StyledDialogContent> | ||
<Box sx={{ borderBottom: 1, borderColor: "divider" }}> | ||
<Tabs | ||
value={showTab} | ||
onChange={(_: React.SyntheticEvent, newValue: "objects") => { | ||
setShowTab(newValue); | ||
}} | ||
aria-label="basic tabs example" | ||
> | ||
<Tab label="Live Manifest" value="objects" /> | ||
</Tabs> | ||
</Box> | ||
{showTab === "objects" && <YAMLTextArea code={code}></YAMLTextArea>} | ||
</StyledDialogContent> | ||
<DialogActions> | ||
<Button onClick={() => onClose()} variant="contained" color="primary"> | ||
Close | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
); | ||
}; | ||
|
||
export const UserInfoDialogContext = DialogContext<{ | ||
user: User; | ||
}>((props) => <UserInfoDialog {...props} />); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
web/dashboard-ui/src/views/organisms/WorkspaceInfoDialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { Close } from "@mui/icons-material"; | ||
import { | ||
Box, | ||
Button, | ||
Dialog, | ||
DialogActions, | ||
DialogContent, | ||
DialogTitle, | ||
IconButton, | ||
Stack, | ||
Tab, | ||
Tabs, | ||
} from "@mui/material"; | ||
import { styled } from "@mui/material/styles"; | ||
import "highlight.js/styles/default.css"; | ||
import React, { useEffect, useState } from "react"; | ||
import { DialogContext } from "../../components/ContextProvider"; | ||
import { Workspace } from "../../proto/gen/dashboard/v1alpha1/workspace_pb"; | ||
import { useWorkspaceService } from "../../services/DashboardServices"; | ||
import YAMLTextArea from "../atoms/YAMLTextArea"; | ||
|
||
const StyledDialogContent = styled(DialogContent)({ | ||
overflow: "auto", | ||
}); | ||
|
||
const WorkspaceInfoDialog: React.FC<{ | ||
onClose: () => void; | ||
ws: Workspace; | ||
}> = ({ onClose, ws }) => { | ||
const wsService = useWorkspaceService(); | ||
|
||
const [code, setCode] = useState(""); | ||
const [showTab, setShowTab] = useState<"objects">("objects"); | ||
|
||
useEffect(() => { | ||
wsService | ||
.getWorkspace({ | ||
wsName: ws.name, | ||
userName: ws.ownerName, | ||
withRaw: true, | ||
}) | ||
.then((res) => { | ||
setCode(res.workspace?.raw || "no yaml"); | ||
}); | ||
}, [ws]); | ||
|
||
return ( | ||
<Dialog open={true} scroll="paper" fullWidth maxWidth="md"> | ||
<DialogTitle> | ||
<Stack direction="row" alignItems="center" spacing={1}> | ||
Workspace Object | ||
<Box sx={{ flexGrow: 1 }} /> | ||
<IconButton | ||
sx={{ | ||
color: (theme) => theme.palette.grey[500], | ||
}} | ||
onClick={() => onClose()} | ||
> | ||
<Close /> | ||
</IconButton> | ||
</Stack> | ||
</DialogTitle> | ||
|
||
<StyledDialogContent> | ||
<Box sx={{ borderBottom: 1, borderColor: "divider" }}> | ||
<Tabs | ||
value={showTab} | ||
onChange={(_: React.SyntheticEvent, newValue: "objects") => { | ||
setShowTab(newValue); | ||
}} | ||
aria-label="basic tabs example" | ||
> | ||
<Tab label="Live Manifest" value="objects" /> | ||
</Tabs> | ||
</Box> | ||
{showTab === "objects" && <YAMLTextArea code={code}></YAMLTextArea>} | ||
</StyledDialogContent> | ||
<DialogActions> | ||
<Button onClick={() => onClose()} variant="contained" color="primary"> | ||
Close | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
); | ||
}; | ||
|
||
export const WorkspaceInfoDialogContext = DialogContext<{ | ||
ws: Workspace; | ||
}>((props) => <WorkspaceInfoDialog {...props} />); |
Oops, something went wrong.