Skip to content

Commit f90ad78

Browse files
author
Benjamin Perez
committed
Replaced CodeMirrorWrapper internal components
Signed-off-by: Benjamin Perez <[email protected]>
1 parent e7fb3e0 commit f90ad78

File tree

12 files changed

+56
-170
lines changed

12 files changed

+56
-170
lines changed

portal-ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"local-storage-fallback": "^4.1.1",
2020
"lodash": "^4.17.21",
2121
"luxon": "^3.3.0",
22-
"mds": "https://github.com/minio/mds.git#v0.6.7",
22+
"mds": "https://github.com/minio/mds.git#v0.6.8",
2323
"react": "^18.1.0",
2424
"react-component-export-image": "^1.0.6",
2525
"react-copy-to-clipboard": "^5.0.2",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ const AddServiceAccount = () => {
201201
<Grid item xs={12} sx={{ ...modalStyleUtils.formScrollable }}>
202202
<CodeMirrorWrapper
203203
value={policyJSON}
204-
onBeforeChange={(editor, data, value) => {
204+
onChange={(value) => {
205205
setPolicyJSON(value);
206206
}}
207207
editorHeight={"350px"}

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

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,55 +15,25 @@
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

1717
import React, { useEffect, useState } from "react";
18-
19-
import { Button, ChangeAccessPolicyIcon } from "mds";
20-
import { Theme } from "@mui/material/styles";
21-
import createStyles from "@mui/styles/createStyles";
22-
import withStyles from "@mui/styles/withStyles";
23-
import Grid from "@mui/material/Grid";
18+
import { Button, ChangeAccessPolicyIcon, Grid } from "mds";
2419
import {
25-
formFieldStyles,
2620
modalStyleUtils,
27-
spacingUtils,
2821
} from "../Common/FormComponents/common/styleLibrary";
29-
30-
import ModalWrapper from "../Common/ModalWrapper/ModalWrapper";
31-
import CodeMirrorWrapper from "../Common/FormComponents/CodeMirrorWrapper/CodeMirrorWrapper";
3222
import { encodeURLString } from "../../../common/utils";
3323
import { setModalErrorSnackMessage } from "../../../systemSlice";
3424
import { useAppDispatch } from "../../../store";
3525
import { api } from "api";
3626
import { errorToHandler } from "api/errors";
37-
38-
const styles = (theme: Theme) =>
39-
createStyles({
40-
codeMirrorContainer: {
41-
marginBottom: 20,
42-
"& label": {
43-
marginBottom: ".5rem",
44-
},
45-
"& label + div": {
46-
display: "none",
47-
},
48-
},
49-
...formFieldStyles,
50-
...modalStyleUtils,
51-
...spacingUtils,
52-
});
53-
createStyles({
54-
...modalStyleUtils,
55-
...spacingUtils,
56-
});
27+
import ModalWrapper from "../Common/ModalWrapper/ModalWrapper";
28+
import CodeMirrorWrapper from "../Common/FormComponents/CodeMirrorWrapper/CodeMirrorWrapper";
5729

5830
interface IServiceAccountPolicyProps {
59-
classes: any;
6031
open: boolean;
6132
selectedAccessKey: string | null;
6233
closeModalAndRefresh: () => void;
6334
}
6435

6536
const ServiceAccountPolicy = ({
66-
classes,
6737
open,
6838
selectedAccessKey,
6939
closeModalAndRefresh,
@@ -117,17 +87,17 @@ const ServiceAccountPolicy = ({
11787
}}
11888
>
11989
<Grid container>
120-
<Grid item xs={12} className={classes.codeMirrorContainer}>
90+
<Grid item xs={12}>
12191
<CodeMirrorWrapper
12292
label={`Access Key Policy`}
12393
value={policyDefinition}
124-
onBeforeChange={(editor, data, value) => {
94+
onChange={(value) => {
12595
setPolicyDefinition(value);
12696
}}
12797
editorHeight={"350px"}
12898
/>
12999
</Grid>
130-
<Grid item xs={12} className={classes.modalButtonBar}>
100+
<Grid item xs={12} sx={modalStyleUtils.modalButtonBar}>
131101
<Button
132102
id={"cancel-sa-policy"}
133103
type="button"
@@ -153,4 +123,4 @@ const ServiceAccountPolicy = ({
153123
);
154124
};
155125

156-
export default withStyles(styles)(ServiceAccountPolicy);
126+
export default ServiceAccountPolicy;

portal-ui/src/screens/Console/Buckets/BucketDetails/SetAccessPolicy.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,14 @@ const SetAccessPolicy = ({
156156
</div>
157157
)}
158158
{accessPolicy === "CUSTOM" && (
159-
<Grid item xs={12} className={classes.codeMirrorContainer}>
159+
<Grid item xs={12}>
160160
<CodeMirrorWrapper
161161
label={`Write Policy`}
162162
value={policyDefinition}
163-
onBeforeChange={(editor, data, value) => {
163+
onChange={(value) => {
164164
setPolicyDefinition(value);
165165
}}
166-
editorHeight={"350px"}
166+
editorHeight={"300px"}
167167
/>
168168
</Grid>
169169
)}

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

Lines changed: 19 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -14,115 +14,38 @@
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 from "react";
18-
import Grid from "@mui/material/Grid";
19-
import { Box, InputLabel, Tooltip } from "@mui/material";
20-
import { Theme } from "@mui/material/styles";
21-
import createStyles from "@mui/styles/createStyles";
22-
import withStyles from "@mui/styles/withStyles";
23-
import { Button, CopyIcon, HelpIcon } from "mds";
24-
import { fieldBasic } from "../common/styleLibrary";
17+
import React, { Fragment } from "react";
18+
import { Button, CodeEditor, CopyIcon } from "mds";
2519
import CopyToClipboard from "react-copy-to-clipboard";
26-
import CodeEditor from "@uiw/react-textarea-code-editor";
2720
import TooltipWrapper from "../../TooltipWrapper/TooltipWrapper";
2821

2922
interface ICodeWrapper {
3023
value: string;
3124
label?: string;
3225
mode?: string;
3326
tooltip?: string;
34-
classes: any;
35-
onChange?: (editor: any, data: any, value: string) => any;
36-
onBeforeChange: (editor: any, data: any, value: string) => any;
37-
readOnly?: boolean;
38-
editorHeight?: string;
27+
onChange: (value: string) => any;
28+
editorHeight?: string | number;
3929
}
4030

41-
const styles = (theme: Theme) =>
42-
createStyles({
43-
...fieldBasic,
44-
});
45-
4631
const CodeMirrorWrapper = ({
4732
value,
4833
label = "",
4934
tooltip = "",
5035
mode = "json",
51-
classes,
52-
onBeforeChange,
53-
readOnly = false,
54-
editorHeight = "250px",
36+
onChange,
37+
editorHeight = 250,
5538
}: ICodeWrapper) => {
5639
return (
57-
<React.Fragment>
58-
<Grid item xs={12} sx={{ marginBottom: "10px" }}>
59-
<InputLabel className={classes.inputLabel}>
60-
<span>{label}</span>
61-
{tooltip !== "" && (
62-
<div className={classes.tooltipContainer}>
63-
<Tooltip title={tooltip} placement="top-start">
64-
<div className={classes.tooltip}>
65-
<HelpIcon />
66-
</div>
67-
</Tooltip>
68-
</div>
69-
)}
70-
</InputLabel>
71-
</Grid>
72-
73-
<Grid
74-
item
75-
xs={12}
76-
style={{
77-
maxHeight: editorHeight,
78-
overflow: "auto",
79-
border: "1px solid #eaeaea",
80-
}}
81-
>
82-
<CodeEditor
83-
value={value}
84-
language={mode}
85-
onChange={(evn) => {
86-
onBeforeChange(null, null, evn.target.value);
87-
}}
88-
id={"code_wrapper"}
89-
padding={15}
90-
style={{
91-
fontSize: 12,
92-
backgroundColor: "#fefefe",
93-
fontFamily:
94-
"ui-monospace,SFMono-Regular,SF Mono,Consolas,Liberation Mono,Menlo,monospace",
95-
minHeight: editorHeight || "initial",
96-
color: "#000000",
97-
}}
98-
/>
99-
</Grid>
100-
<Grid
101-
item
102-
xs={12}
103-
sx={{
104-
background: "#f7f7f7",
105-
border: "1px solid #eaeaea",
106-
borderTop: 0,
107-
}}
108-
>
109-
<Box
110-
sx={{
111-
display: "flex",
112-
alignItems: "center",
113-
padding: "2px",
114-
paddingRight: "5px",
115-
justifyContent: "flex-end",
116-
"& button": {
117-
height: "26px",
118-
width: "26px",
119-
padding: "2px",
120-
" .min-icon": {
121-
marginLeft: "0",
122-
},
123-
},
124-
}}
125-
>
40+
<CodeEditor
41+
value={value}
42+
onChange={(value) => onChange(value)}
43+
mode={mode}
44+
tooltip={tooltip}
45+
editorHeight={editorHeight}
46+
label={label}
47+
helpTools={
48+
<Fragment>
12649
<TooltipWrapper tooltip={"Copy to Clipboard"}>
12750
<CopyToClipboard text={value}>
12851
<Button
@@ -134,10 +57,10 @@ const CodeMirrorWrapper = ({
13457
/>
13558
</CopyToClipboard>
13659
</TooltipWrapper>
137-
</Box>
138-
</Grid>
139-
</React.Fragment>
60+
</Fragment>
61+
}
62+
/>
14063
);
14164
};
14265

143-
export default withStyles(styles)(CodeMirrorWrapper);
66+
export default CodeMirrorWrapper;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ const ImportKey = () => {
126126
<CodeMirrorWrapper
127127
label={"Set key Content"}
128128
value={keyContent}
129-
onBeforeChange={(editor, data, value) => {
129+
onChange={(value) => {
130130
setKeyContent(value);
131131
}}
132132
editorHeight={"350px"}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ const AddPolicyScreen = () => {
137137
<CodeMirrorWrapper
138138
label={"Write Policy"}
139139
value={policyDefinition}
140-
onBeforeChange={(editor, data, value) => {
140+
onChange={(value) => {
141141
setPolicyDefinition(value);
142142
}}
143143
editorHeight={"350px"}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -585,10 +585,11 @@ const PolicyDetails = ({ classes }: IPolicyDetailsProps) => {
585585
<Grid container>
586586
<Grid item xs={12}>
587587
<CodeMirrorWrapper
588-
readOnly={!canEditPolicy}
589588
value={policyDefinition}
590-
onBeforeChange={(editor, data, value) => {
591-
setPolicyDefinition(value);
589+
onChange={(value) => {
590+
if(canEditPolicy) {
591+
setPolicyDefinition(value);
592+
}
592593
}}
593594
editorHeight={"350px"}
594595
/>

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,7 @@ const STResults = ({ results, start }: ISTResults) => {
339339
<Fragment>
340340
<CodeMirrorWrapper
341341
value={finalResJSON}
342-
readOnly
343-
onBeforeChange={() => {}}
342+
onChange={() => {}}
344343
/>
345344
</Fragment>
346345
) : (

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ const AddServiceAccount = ({ classes }: IAddServiceAccountProps) => {
297297
<CodeMirrorWrapper
298298
label={"Policy"}
299299
value={policyJSON}
300-
onBeforeChange={(editor, data, value) => {
300+
onChange={(value) => {
301301
setPolicyJSON(value);
302302
}}
303303
/>

0 commit comments

Comments
 (0)