Skip to content

Commit 6e205fa

Browse files
authored
Change editor to react-textarea-code-editor. Tenant YAML a page. (#2084)
Signed-off-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com>
1 parent 5b3f6ad commit 6e205fa

File tree

10 files changed

+528
-551
lines changed

10 files changed

+528
-551
lines changed

portal-ui/package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
"homepage": ".",
55
"private": true,
66
"dependencies": {
7-
"@codemirror/lang-json": "^0.20.0",
8-
"@codemirror/legacy-modes": "^0.20.0",
9-
"@codemirror/stream-parser": "^0.19.9",
107
"@date-io/moment": "1.x",
118
"@emotion/react": "^11.9.0",
129
"@emotion/styled": "^11.8.1",
@@ -33,9 +30,8 @@
3330
"@types/superagent": "^4.1.12",
3431
"@types/webpack-env": "^1.14.1",
3532
"@types/websocket": "^1.0.0",
36-
"@uiw/react-codemirror": "^4.7.0",
33+
"@uiw/react-textarea-code-editor": "^2.0.2",
3734
"chart.js": "^2.9.3",
38-
"codemirror": "^5.65.4",
3935
"history": "^4.10.1",
4036
"kbar": "^0.1.0-beta.34",
4137
"local-storage-fallback": "^4.1.1",

portal-ui/src/screens/Console/Common/FormComponents/CodeMirrorWrapper/CodeMirrorWrapper.tsx

Lines changed: 53 additions & 188 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,18 @@
1414
// You should have received a copy of the GNU Affero General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17-
import React, { useState } from "react";
17+
import React from "react";
1818
import Grid from "@mui/material/Grid";
19-
import "codemirror/theme/dracula.css";
20-
/** Code mirror */
21-
import CodeMirror, { Extension } from "@uiw/react-codemirror";
22-
import { StreamLanguage } from "@codemirror/stream-parser";
23-
import { json } from "@codemirror/lang-json";
24-
import { yaml } from "@codemirror/legacy-modes/mode/yaml";
25-
26-
/** Code mirror */
2719
import { Box, InputLabel, Tooltip } from "@mui/material";
2820
import { Theme } from "@mui/material/styles";
2921
import createStyles from "@mui/styles/createStyles";
3022
import withStyles from "@mui/styles/withStyles";
3123
import HelpIcon from "../../../../../icons/HelpIcon";
3224
import { fieldBasic } from "../common/styleLibrary";
33-
import { CopyIcon, EditorThemeSwitchIcon } from "../../../../../icons";
25+
import { CopyIcon } from "../../../../../icons";
3426
import RBIconButton from "../../../Buckets/BucketDetails/SummaryItems/RBIconButton";
3527
import CopyToClipboard from "react-copy-to-clipboard";
36-
import { EditorView } from "@codemirror/view";
28+
import CodeEditor from "@uiw/react-textarea-code-editor";
3729

3830
interface ICodeWrapper {
3931
value: string;
@@ -52,104 +44,6 @@ const styles = (theme: Theme) =>
5244
...fieldBasic,
5345
});
5446

55-
const langHighlight: Record<string, any> = {
56-
json,
57-
yaml: () => StreamLanguage.define(yaml as any),
58-
};
59-
60-
const lightTheme = EditorView.theme(
61-
{
62-
"&": {
63-
backgroundColor: "#FBFAFA",
64-
},
65-
".cm-content": {
66-
caretColor: "#05122B",
67-
},
68-
"&.cm-focused .cm-cursor": {
69-
borderLeftColor: "#05122B",
70-
},
71-
".cm-gutters": {
72-
backgroundColor: "#FBFAFA",
73-
color: "#000000",
74-
border: "none",
75-
},
76-
".cm-gutter.cm-foldGutter": {
77-
borderRight: "1px solid #eaeaea",
78-
},
79-
".cm-gutterElement": {
80-
fontSize: "13px",
81-
},
82-
".cm-line": {
83-
fontSize: "13px",
84-
color: "#2781B0",
85-
"& .ͼc": {
86-
color: "#C83B51",
87-
},
88-
},
89-
"& .ͼb": {
90-
color: "#2781B0",
91-
},
92-
".cm-activeLine": {
93-
backgroundColor: "#dde1f1",
94-
},
95-
".cm-matchingBracket": {
96-
backgroundColor: "#05122B",
97-
color: "#ffffff",
98-
},
99-
".cm-selectionMatch": {
100-
backgroundColor: "#ebe7f1",
101-
},
102-
".cm-selectionLayer": {
103-
fontWeight: 500,
104-
},
105-
" .cm-selectionBackground": {
106-
backgroundColor: "#a180c7",
107-
color: "#ffffff",
108-
},
109-
},
110-
{
111-
dark: false,
112-
}
113-
);
114-
115-
const darkTheme = EditorView.theme(
116-
{
117-
"&": {
118-
backgroundColor: "#282a36",
119-
color: "#ffb86c",
120-
},
121-
122-
".cm-gutter.cm-foldGutter": {
123-
borderRight: "1px solid #eaeaea",
124-
},
125-
".cm-gutterElement": {
126-
fontSize: "13px",
127-
},
128-
".cm-line": {
129-
fontSize: "13px",
130-
"& .ͼd, & .ͼc": {
131-
color: "#8e6cef",
132-
},
133-
},
134-
"& .ͼb": {
135-
color: "#2781B0",
136-
},
137-
".cm-activeLine": {
138-
backgroundColor: "#44475a",
139-
},
140-
".cm-matchingBracket": {
141-
backgroundColor: "#842de5",
142-
color: "#ff79c6",
143-
},
144-
".cm-selectionLayer .cm-selectionBackground": {
145-
backgroundColor: "green",
146-
},
147-
},
148-
{
149-
dark: true,
150-
}
151-
);
152-
15347
const CodeMirrorWrapper = ({
15448
value,
15549
label = "",
@@ -160,104 +54,75 @@ const CodeMirrorWrapper = ({
16054
readOnly = false,
16155
editorHeight = "250px",
16256
}: ICodeWrapper) => {
163-
const [isDarkTheme, setIsDarkTheme] = useState<boolean>(false);
164-
165-
//based on the language mode pick . default to json
166-
let extensionList: Extension[] = [];
167-
if (langHighlight[mode]) {
168-
extensionList = [...extensionList, langHighlight[mode]()];
169-
}
170-
17157
return (
17258
<React.Fragment>
173-
<InputLabel className={classes.inputLabel}>
174-
<span>{label}</span>
175-
{tooltip !== "" && (
176-
<div className={classes.tooltipContainer}>
177-
<Tooltip title={tooltip} placement="top-start">
178-
<div className={classes.tooltip}>
179-
<HelpIcon />
180-
</div>
181-
</Tooltip>
182-
</div>
183-
)}
184-
</InputLabel>
18559
<Grid item xs={12}>
186-
<br />
60+
<InputLabel className={classes.inputLabel}>
61+
<span>{label}</span>
62+
{tooltip !== "" && (
63+
<div className={classes.tooltipContainer}>
64+
<Tooltip title={tooltip} placement="top-start">
65+
<div className={classes.tooltip}>
66+
<HelpIcon />
67+
</div>
68+
</Tooltip>
69+
</div>
70+
)}
71+
</InputLabel>
18772
</Grid>
18873

74+
<Grid item xs={12} style={{ maxHeight: editorHeight, overflow: "auto" }}>
75+
<CodeEditor
76+
value={value}
77+
language={mode}
78+
onChange={(evn) => {
79+
onBeforeChange(null, null, evn.target.value);
80+
}}
81+
padding={15}
82+
style={{
83+
fontSize: 12,
84+
backgroundColor: "#fefefe",
85+
fontFamily:
86+
"ui-monospace,SFMono-Regular,SF Mono,Consolas,Liberation Mono,Menlo,monospace",
87+
}}
88+
/>
89+
</Grid>
18990
<Grid
19091
item
19192
xs={12}
19293
sx={{
193-
border: "1px solid #eaeaea",
94+
borderTop: "1px solid #eaeaea",
95+
background: "#f7f7f7",
19496
}}
19597
>
196-
<Grid item xs={12}>
197-
<CodeMirror
198-
value={value}
199-
theme={isDarkTheme ? darkTheme : lightTheme}
200-
extensions={extensionList}
201-
editable={!readOnly}
202-
basicSetup={true}
203-
height={editorHeight}
204-
onChange={(v: string, vu: any) => {
205-
onBeforeChange(null, null, v);
206-
}}
207-
/>
208-
</Grid>
209-
<Grid
210-
item
211-
xs={12}
98+
<Box
21299
sx={{
213-
borderTop: "1px solid #eaeaea",
214-
background: isDarkTheme ? "#282c34" : "#f7f7f7",
215-
}}
216-
>
217-
<Box
218-
className={isDarkTheme ? "dark-theme" : ""}
219-
sx={{
220-
display: "flex",
221-
alignItems: "center",
100+
display: "flex",
101+
alignItems: "center",
102+
padding: "2px",
103+
paddingRight: "5px",
104+
justifyContent: "flex-end",
105+
"& button": {
106+
height: "26px",
107+
width: "26px",
222108
padding: "2px",
223-
paddingRight: "5px",
224-
justifyContent: "flex-end",
225-
"& button": {
226-
height: "26px",
227-
width: "26px",
228-
padding: "2px",
229-
" .min-icon": {
230-
marginLeft: "0",
231-
},
109+
" .min-icon": {
110+
marginLeft: "0",
232111
},
233-
234-
"&.dark-theme button": {
235-
background: "#FFFFFF",
236-
},
237-
}}
238-
>
112+
},
113+
}}
114+
>
115+
<CopyToClipboard text={value}>
239116
<RBIconButton
240-
tooltip={"Change theme"}
241-
onClick={() => {
242-
setIsDarkTheme(!isDarkTheme);
243-
}}
117+
tooltip={"Copy to Clipboard"}
118+
onClick={() => {}}
244119
text={""}
245-
icon={<EditorThemeSwitchIcon />}
120+
icon={<CopyIcon />}
246121
color={"primary"}
247122
variant={"outlined"}
248123
/>
249-
<CopyToClipboard text={value}>
250-
<RBIconButton
251-
tooltip={"Copy to Clipboard"}
252-
onClick={() => {}}
253-
text={""}
254-
icon={<CopyIcon />}
255-
color={"primary"}
256-
variant={"outlined"}
257-
/>
258-
</CopyToClipboard>
259-
</Box>
260-
</Grid>
124+
</CopyToClipboard>
125+
</Box>
261126
</Grid>
262127
</React.Fragment>
263128
);

portal-ui/src/screens/Console/Console.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,11 @@ const Console = ({ classes }: IConsoleProps) => {
481481
path: IAM_PAGES.NAMESPACE_TENANT_PVCS,
482482
forceDisplay: true,
483483
},
484+
{
485+
component: TenantDetails,
486+
path: `${IAM_PAGES.NAMESPACE_TENANT_SUMMARY}/yaml`,
487+
forceDisplay: true,
488+
},
484489
{
485490
component: TenantDetails,
486491
path: IAM_PAGES.NAMESPACE_TENANT_SUMMARY,

0 commit comments

Comments
 (0)