@ebubekirylmaz/link-test 1.2.44 → 1.2.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +9 -6
- package/src/Platform.jsx +14 -15
- package/src/config/schemas.js +1 -0
- package/src/context/Context.js +98 -0
- package/src/context/reducer.js +590 -10
- package/src/hooks/index.js +2 -1
- package/src/hooks/use-beta.js +8 -0
- package/src/layouts/auth/modern.jsx +4 -2
- package/src/layouts/common/account-popover.jsx +1 -2
- package/src/lib/APIDialogAction/APIDialogAction.jsx +109 -0
- package/src/lib/APIDialogAction/index.js +1 -0
- package/src/lib/APIDialogAction/styles.js +6 -0
- package/src/lib/APIParams/APIParams.jsx +57 -0
- package/src/lib/APIParams/index.js +1 -0
- package/src/lib/APIPath/APIPath.jsx +82 -0
- package/src/lib/APIPath/index.js +1 -0
- package/src/lib/APIPath/styles.js +19 -0
- package/src/lib/APITree/APITree.jsx +409 -0
- package/src/lib/APITree/Arrow.jsx +21 -0
- package/src/lib/APITree/DeleteMethodDialog.jsx +41 -0
- package/src/lib/APITree/index.js +1 -0
- package/src/lib/APITree/styles.js +19 -0
- package/src/lib/APITypes/APITypes.jsx +141 -0
- package/src/lib/APITypes/TypeEditor.jsx +46 -0
- package/src/lib/APITypes/TypeList.jsx +180 -0
- package/src/lib/APITypes/index.js +1 -0
- package/src/lib/BlankTreeMessage/BlankTreeMessage.jsx +39 -0
- package/src/lib/BlankTreeMessage/index.js +1 -0
- package/src/lib/DialogTootip/DialogTooltip.jsx +67 -0
- package/src/lib/DialogTootip/index.js +1 -0
- package/src/lib/DialogTootip/styles.js +9 -0
- package/src/lib/Flow/connectors/DynamicConnector.jsx +179 -107
- package/src/lib/Flow/core/Flow.jsx +2 -0
- package/src/lib/Flow/core/FlowNode.jsx +2 -0
- package/src/lib/Flow/core/FlowViewport.jsx +41 -9
- package/src/lib/Flow/hooks/useNodeStyle.js +14 -0
- package/src/lib/Flow/nodes/FlowNodeView.jsx +105 -21
- package/src/lib/Flow/styles.js +4 -0
- package/src/lib/NewApiBody/NewAPIBody.jsx +97 -0
- package/src/lib/NewApiBody/ParamView.jsx +38 -0
- package/src/lib/NucDialog/NucDialog.jsx +108 -0
- package/src/lib/NucDialog/index.js +1 -0
- package/src/lib/ParamTable/ParamTable.jsx +133 -0
- package/src/lib/ParamTable/TypeMenu.jsx +102 -0
- package/src/lib/ParamTable/defaults.js +47 -0
- package/src/lib/ParamTable/index.js +1 -0
- package/src/lib/ParamTable/styles.js +12 -0
- package/src/lib/ResourceMenu/AlertMassage.jsx +28 -0
- package/src/lib/ResourceMenu/DeleteResourceDialog.jsx +60 -0
- package/src/lib/ResourceMenu/ResourceMenu.jsx +156 -0
- package/src/lib/ResourceMenu/index.js +1 -0
- package/src/lib/ResourceMenu/styles.js +5 -0
- package/src/lib/Schema/Schema.jsx +204 -0
- package/src/lib/Schema/index.js +1 -0
- package/src/lib/SchemaEditor/SchemaEditor.jsx +258 -0
- package/src/lib/SchemaEditor/SchemaEditor.test.js +193 -0
- package/src/lib/SchemaEditor/SchemaPropertyEditor.jsx +135 -0
- package/src/lib/SchemaEditor/SchemaUtils.js +152 -0
- package/src/lib/SchemaEditor/index.js +1 -0
- package/src/lib/ToggleableMenu/ToggleableMenu.jsx +35 -0
- package/src/lib/ToggleableMenu/index.js +1 -0
- package/src/lib/index.js +14 -0
- package/src/pages/Callback.jsx +6 -8
- package/src/pages/LoginPage.jsx +3 -12
- package/src/stories/APITree.stories.jsx +429 -0
- package/src/stories/FlowChart.stories.jsx +1 -1
- package/src/templates/ActionTemplate.js +24 -0
- package/src/widgets/Login/CognitoLogin.jsx +163 -179
- package/src/widgets/Login/DemoLogin.jsx +9 -7
- package/src/widgets/Login/amplifyAuth.js +6 -6
- package/src/widgets/Login/amplifyConfig.js +3 -0
- package/src/widgets/LoginForm/LoginForm.jsx +8 -3
- package/src/widgets/SettingsDialog.jsx +171 -7
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import AlertMassage from "./AlertMassage";
|
|
2
|
+
import DeleteIcon from "@mui/icons-material/Delete";
|
|
3
|
+
import DeleteResourceDialog from "./DeleteResourceDialog";
|
|
4
|
+
import Fade from "@mui/material/Fade";
|
|
5
|
+
import HttpIcon from "@mui/icons-material/Http";
|
|
6
|
+
import React from "react";
|
|
7
|
+
import SourceIcon from "@mui/icons-material/Source";
|
|
8
|
+
import styles from "./styles";
|
|
9
|
+
import { useRef } from "react";
|
|
10
|
+
|
|
11
|
+
import { Divider, Menu, MenuItem, Typography } from "@mui/material";
|
|
12
|
+
import { publish, useEvent } from "@nucleoidai/react-event";
|
|
13
|
+
|
|
14
|
+
const ResourceMenu = (props) => {
|
|
15
|
+
const { anchor, openMenu, handleClose, hash, map } = props;
|
|
16
|
+
|
|
17
|
+
const [methodDisabled, setMethodDisabled] = React.useState();
|
|
18
|
+
const [alertMessage, setAlertMessage] = React.useState("");
|
|
19
|
+
const [open, setOpen] = React.useState(false);
|
|
20
|
+
const resourceRef = useRef();
|
|
21
|
+
|
|
22
|
+
const [api] = useEvent("API_DATA_CHANGED", []);
|
|
23
|
+
const [selectedAPI] = useEvent("SELECTED_API_CHANGED", {
|
|
24
|
+
path: "/",
|
|
25
|
+
method: "GET",
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
React.useEffect(() => {
|
|
29
|
+
const checkMethodAddable = () => {
|
|
30
|
+
const countMethodsForPath = (path) => {
|
|
31
|
+
return api.filter((endpoint) => endpoint.path === path).length;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
if (hash) {
|
|
35
|
+
const path = map ? map[hash].path : null;
|
|
36
|
+
return countMethodsForPath(path) > 3;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (selectedAPI) {
|
|
40
|
+
const apiSelectedPath = selectedAPI.path;
|
|
41
|
+
return countMethodsForPath(apiSelectedPath) > 4;
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
setMethodDisabled(checkMethodAddable());
|
|
47
|
+
}, [api, hash, map, selectedAPI]);
|
|
48
|
+
|
|
49
|
+
const addMethod = () => {
|
|
50
|
+
selectPath();
|
|
51
|
+
publish("API_DIALOG_OPEN", { type: "method", action: "add" });
|
|
52
|
+
handleClose();
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const addResource = () => {
|
|
56
|
+
selectPath();
|
|
57
|
+
publish("API_DIALOG_OPEN", { type: "resource", action: "add" });
|
|
58
|
+
handleClose();
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const deleteResource = () => {
|
|
62
|
+
const path = selectedAPI?.path;
|
|
63
|
+
if (!path) return;
|
|
64
|
+
|
|
65
|
+
publish("API_RESOURCE_DELETE", { path });
|
|
66
|
+
handleClose();
|
|
67
|
+
setOpen(false);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const handleResourceDeleteDialog = () => {
|
|
71
|
+
selectPath();
|
|
72
|
+
|
|
73
|
+
if (selectedAPI?.path === "/") {
|
|
74
|
+
setAlertMessage("Root path cannot be deleted");
|
|
75
|
+
handleClose();
|
|
76
|
+
} else {
|
|
77
|
+
const selectedPath = selectedAPI?.path;
|
|
78
|
+
const deleteList = api
|
|
79
|
+
.filter(
|
|
80
|
+
(item) =>
|
|
81
|
+
item.path.startsWith(selectedPath) && item.path !== selectedPath
|
|
82
|
+
)
|
|
83
|
+
.map((item) => item.path)
|
|
84
|
+
.filter((path, index, self) => self.indexOf(path) === index);
|
|
85
|
+
|
|
86
|
+
resourceRef.current = {
|
|
87
|
+
deleteAdress: selectedPath,
|
|
88
|
+
deleteList: deleteList,
|
|
89
|
+
};
|
|
90
|
+
handleClose();
|
|
91
|
+
setOpen(true);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const selectPath = () => {
|
|
96
|
+
const item = map ? map[hash] : null;
|
|
97
|
+
|
|
98
|
+
if (item) {
|
|
99
|
+
publish("SELECTED_API_CHANGED", { path: item.path, method: null });
|
|
100
|
+
} else if (selectedAPI) {
|
|
101
|
+
publish("SELECTED_API_CHANGED", {
|
|
102
|
+
path: selectedAPI.path,
|
|
103
|
+
method: null,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<>
|
|
110
|
+
{open && (
|
|
111
|
+
<DeleteResourceDialog
|
|
112
|
+
open={open}
|
|
113
|
+
setOpen={setOpen}
|
|
114
|
+
deleteResource={deleteResource}
|
|
115
|
+
ref={resourceRef}
|
|
116
|
+
/>
|
|
117
|
+
)}
|
|
118
|
+
{alertMessage && <AlertMassage message={alertMessage} />}
|
|
119
|
+
<Menu
|
|
120
|
+
open={openMenu}
|
|
121
|
+
onClose={handleClose}
|
|
122
|
+
onContextMenu={(event) => event.preventDefault()}
|
|
123
|
+
anchorReference="anchorPosition"
|
|
124
|
+
anchorPosition={{
|
|
125
|
+
top: anchor?.clientY || 0,
|
|
126
|
+
left: anchor?.clientX || 0,
|
|
127
|
+
}}
|
|
128
|
+
TransitionComponent={Fade}
|
|
129
|
+
>
|
|
130
|
+
<MenuItem onClick={addResource} data-cy="add-resource">
|
|
131
|
+
<SourceIcon />
|
|
132
|
+
<Typography sx={styles.menuItemText}>Resource</Typography>
|
|
133
|
+
</MenuItem>
|
|
134
|
+
<MenuItem
|
|
135
|
+
onClick={addMethod}
|
|
136
|
+
disabled={methodDisabled}
|
|
137
|
+
data-cy="add-method"
|
|
138
|
+
>
|
|
139
|
+
<HttpIcon />
|
|
140
|
+
<Typography sx={styles.menuItemText}>Method</Typography>
|
|
141
|
+
</MenuItem>
|
|
142
|
+
<Divider />
|
|
143
|
+
<MenuItem
|
|
144
|
+
onClick={handleResourceDeleteDialog}
|
|
145
|
+
disabled={selectedAPI?.path === "/"}
|
|
146
|
+
data-cy="delete-resource"
|
|
147
|
+
>
|
|
148
|
+
<DeleteIcon />
|
|
149
|
+
<Typography sx={styles.menuItemText}>Delete</Typography>
|
|
150
|
+
</MenuItem>
|
|
151
|
+
</Menu>
|
|
152
|
+
</>
|
|
153
|
+
);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export default ResourceMenu;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./ResourceMenu";
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import ChevronRightIcon from "@mui/icons-material/ChevronRight";
|
|
2
|
+
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
|
|
3
|
+
import { v4 as uuidv4 } from "uuid";
|
|
4
|
+
|
|
5
|
+
import { Box, Typography } from "@mui/material";
|
|
6
|
+
import React, { useEffect, useState } from "react";
|
|
7
|
+
import { SimpleTreeView } from "@mui/x-tree-view/SimpleTreeView";
|
|
8
|
+
import { TreeItem } from "@mui/x-tree-view/TreeItem";
|
|
9
|
+
|
|
10
|
+
const Schema = ({ initialData = {}, customTypes = [] }) => {
|
|
11
|
+
const [schemaData, setSchemaData] = useState({});
|
|
12
|
+
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
const addIdsToSchema = (schema) => {
|
|
15
|
+
if (!schema) return null;
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
...schema,
|
|
19
|
+
id: uuidv4(),
|
|
20
|
+
properties: schema.properties?.map(addIdsToSchema),
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
if (Object.keys(initialData).length === 0) {
|
|
25
|
+
setSchemaData({
|
|
26
|
+
type: "object",
|
|
27
|
+
properties: [],
|
|
28
|
+
});
|
|
29
|
+
} else {
|
|
30
|
+
setSchemaData(addIdsToSchema(initialData));
|
|
31
|
+
}
|
|
32
|
+
}, [initialData]);
|
|
33
|
+
|
|
34
|
+
const renderTree = (node, level = 0) => (
|
|
35
|
+
<TreeItem
|
|
36
|
+
key={node.id}
|
|
37
|
+
itemId={level === 0 ? "1" : node.id}
|
|
38
|
+
label={
|
|
39
|
+
<div
|
|
40
|
+
style={{
|
|
41
|
+
display: "flex",
|
|
42
|
+
alignItems: "center",
|
|
43
|
+
justifyContent: "space-between",
|
|
44
|
+
width: "100%",
|
|
45
|
+
}}
|
|
46
|
+
>
|
|
47
|
+
<div
|
|
48
|
+
style={{
|
|
49
|
+
display: "flex",
|
|
50
|
+
alignItems: "center",
|
|
51
|
+
gap: "1px",
|
|
52
|
+
width: "100%",
|
|
53
|
+
}}
|
|
54
|
+
>
|
|
55
|
+
<Box
|
|
56
|
+
sx={{
|
|
57
|
+
display: "flex",
|
|
58
|
+
justifyContent: "space-between",
|
|
59
|
+
width: "100%",
|
|
60
|
+
gap: "4px",
|
|
61
|
+
}}
|
|
62
|
+
>
|
|
63
|
+
<Box
|
|
64
|
+
sx={{
|
|
65
|
+
display: "flex",
|
|
66
|
+
alignItems: "center",
|
|
67
|
+
cursor: "pointer",
|
|
68
|
+
}}
|
|
69
|
+
>
|
|
70
|
+
<Typography
|
|
71
|
+
variant="body2"
|
|
72
|
+
sx={{
|
|
73
|
+
padding: "2px 2px",
|
|
74
|
+
borderRadius: "4px",
|
|
75
|
+
}}
|
|
76
|
+
>
|
|
77
|
+
{level === 0 ? "" : node.name}
|
|
78
|
+
</Typography>
|
|
79
|
+
</Box>
|
|
80
|
+
|
|
81
|
+
<Box
|
|
82
|
+
sx={{
|
|
83
|
+
display: "flex",
|
|
84
|
+
alignItems: "center",
|
|
85
|
+
cursor: "pointer",
|
|
86
|
+
}}
|
|
87
|
+
>
|
|
88
|
+
<Typography
|
|
89
|
+
variant="body2"
|
|
90
|
+
sx={{
|
|
91
|
+
cursor: "pointer",
|
|
92
|
+
borderRadius: "4px",
|
|
93
|
+
}}
|
|
94
|
+
>
|
|
95
|
+
{node.type}
|
|
96
|
+
</Typography>
|
|
97
|
+
</Box>
|
|
98
|
+
</Box>
|
|
99
|
+
</div>
|
|
100
|
+
</div>
|
|
101
|
+
}
|
|
102
|
+
>
|
|
103
|
+
{Array.isArray(node.properties)
|
|
104
|
+
? node.properties.map((childNode) => renderTree(childNode, level + 1))
|
|
105
|
+
: isCustomType(node.type)
|
|
106
|
+
? renderCustomTypeNode(node)
|
|
107
|
+
: null}
|
|
108
|
+
</TreeItem>
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
const isCustomType = (type) => {
|
|
112
|
+
return customTypes.some((customType) => customType.name === type);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const renderCustomTypeNode = (node) => {
|
|
116
|
+
const customTypeSchema = customTypes.find(
|
|
117
|
+
(type) => type.name === node.type
|
|
118
|
+
)?.schema;
|
|
119
|
+
|
|
120
|
+
if (!customTypeSchema || !customTypeSchema.properties) {
|
|
121
|
+
return <Box sx={{ paddingLeft: "20px" }}>No properties defined</Box>;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<Box sx={{ paddingLeft: "20px" }}>
|
|
126
|
+
{customTypeSchema.properties.map((prop, index) => (
|
|
127
|
+
<Box
|
|
128
|
+
key={index}
|
|
129
|
+
sx={{
|
|
130
|
+
paddingTop: "5px",
|
|
131
|
+
paddingBottom: "5px",
|
|
132
|
+
display: "flex",
|
|
133
|
+
alignItems: "center",
|
|
134
|
+
}}
|
|
135
|
+
>
|
|
136
|
+
<Typography
|
|
137
|
+
variant="body2"
|
|
138
|
+
sx={{
|
|
139
|
+
color: (theme) => theme.palette.grey[600],
|
|
140
|
+
}}
|
|
141
|
+
>
|
|
142
|
+
{prop.name}
|
|
143
|
+
</Typography>
|
|
144
|
+
<Typography
|
|
145
|
+
variant="body2"
|
|
146
|
+
sx={{
|
|
147
|
+
marginLeft: "8px",
|
|
148
|
+
color: (theme) => theme.palette.grey[500],
|
|
149
|
+
}}
|
|
150
|
+
>
|
|
151
|
+
{prop.type}
|
|
152
|
+
</Typography>
|
|
153
|
+
</Box>
|
|
154
|
+
))}
|
|
155
|
+
</Box>
|
|
156
|
+
);
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
return (
|
|
160
|
+
<SimpleTreeView
|
|
161
|
+
slots={{
|
|
162
|
+
collapseIcon: () => <ExpandMoreIcon />,
|
|
163
|
+
expandIcon: () => <ChevronRightIcon />,
|
|
164
|
+
}}
|
|
165
|
+
defaultExpandedItems={["1"]}
|
|
166
|
+
sx={{
|
|
167
|
+
flexGrow: 1,
|
|
168
|
+
overflowY: "auto",
|
|
169
|
+
width: "100%",
|
|
170
|
+
".MuiTreeItem-root": {
|
|
171
|
+
alignItems: "center",
|
|
172
|
+
},
|
|
173
|
+
".MuiTreeItem-content": {
|
|
174
|
+
width: "100%",
|
|
175
|
+
display: "flex",
|
|
176
|
+
justifyContent: "space-between",
|
|
177
|
+
padding: "1px 8px",
|
|
178
|
+
borderRadius: "4px",
|
|
179
|
+
margin: "1px 0",
|
|
180
|
+
transition: "width 0.3s ease-in-out, height 0.3s ease-in-out",
|
|
181
|
+
},
|
|
182
|
+
".MuiTreeItem-label": {
|
|
183
|
+
width: "100%",
|
|
184
|
+
fontWeight: "bold",
|
|
185
|
+
},
|
|
186
|
+
".MuiTreeItem-group": {
|
|
187
|
+
marginLeft: "16px !important",
|
|
188
|
+
paddingLeft: "8px",
|
|
189
|
+
borderLeft: `1px solid`,
|
|
190
|
+
borderColor: (theme) => theme.palette.grey[400],
|
|
191
|
+
},
|
|
192
|
+
".MuiTreeItem-iconContainer": {
|
|
193
|
+
minWidth: "0",
|
|
194
|
+
marginRight: "0px",
|
|
195
|
+
padding: "0px",
|
|
196
|
+
},
|
|
197
|
+
}}
|
|
198
|
+
>
|
|
199
|
+
{renderTree(schemaData, 0)}
|
|
200
|
+
</SimpleTreeView>
|
|
201
|
+
);
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
export default Schema;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./Schema";
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import AddCircleOutlineIcon from "@mui/icons-material/AddCircleOutline";
|
|
2
|
+
import ChevronRightIcon from "@mui/icons-material/ChevronRight";
|
|
3
|
+
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
|
|
4
|
+
import IconButton from "@mui/material/IconButton";
|
|
5
|
+
import RemoveCircleOutlineIcon from "@mui/icons-material/RemoveCircleOutline";
|
|
6
|
+
import SchemaPropertyEditor from "./SchemaPropertyEditor";
|
|
7
|
+
import { v4 as uuidv4 } from "uuid";
|
|
8
|
+
|
|
9
|
+
import { Box, Typography } from "@mui/material";
|
|
10
|
+
import React, { forwardRef, useEffect, useState } from "react";
|
|
11
|
+
import { SimpleTreeView } from "@mui/x-tree-view/SimpleTreeView";
|
|
12
|
+
import { TreeItem } from "@mui/x-tree-view/TreeItem";
|
|
13
|
+
import { addProperty, changeProperty, removeProperty } from "./SchemaUtils";
|
|
14
|
+
|
|
15
|
+
const SchemaEditor = forwardRef(
|
|
16
|
+
({ initialData = {}, customTypes = [] }, ref) => {
|
|
17
|
+
const [schemaData, setSchemaData] = useState({});
|
|
18
|
+
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
const addIdsToSchema = (schema) => {
|
|
21
|
+
return {
|
|
22
|
+
...schema,
|
|
23
|
+
id: uuidv4(),
|
|
24
|
+
properties: schema.properties?.map(addIdsToSchema),
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
if (!schemaData || Object.keys(schemaData).length === 0) {
|
|
29
|
+
if (Object.keys(initialData).length === 0) {
|
|
30
|
+
setSchemaData({
|
|
31
|
+
type: "object",
|
|
32
|
+
properties: [],
|
|
33
|
+
});
|
|
34
|
+
} else {
|
|
35
|
+
const dataWithIds = addIdsToSchema(initialData);
|
|
36
|
+
setSchemaData(dataWithIds);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}, [initialData, schemaData]);
|
|
40
|
+
|
|
41
|
+
const handleAddProperty = (newProperty, parentId = null) => {
|
|
42
|
+
addProperty(parentId, setSchemaData);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const handleRemoveProperty = (propertyId) => {
|
|
46
|
+
removeProperty(propertyId, setSchemaData);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const handleChangeProperty = (propertyId, changes) => {
|
|
50
|
+
changeProperty(propertyId, changes, setSchemaData);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const renderTree = (node, level = 0) => (
|
|
54
|
+
<TreeItem
|
|
55
|
+
key={node.id}
|
|
56
|
+
itemId={level === 0 ? "1" : node.id}
|
|
57
|
+
label={
|
|
58
|
+
<Box
|
|
59
|
+
sx={{
|
|
60
|
+
display: "flex",
|
|
61
|
+
alignItems: "center",
|
|
62
|
+
justifyContent: "space-between",
|
|
63
|
+
width: "100%",
|
|
64
|
+
}}
|
|
65
|
+
>
|
|
66
|
+
<Box
|
|
67
|
+
sx={{
|
|
68
|
+
display: "flex",
|
|
69
|
+
alignItems: "center",
|
|
70
|
+
gap: "1px",
|
|
71
|
+
width: "100%",
|
|
72
|
+
}}
|
|
73
|
+
>
|
|
74
|
+
<SchemaPropertyEditor
|
|
75
|
+
node={{ ...node, level }}
|
|
76
|
+
disableNameChange={level === 0}
|
|
77
|
+
onNameChange={(newName) => {
|
|
78
|
+
handleChangeProperty(node.id, {
|
|
79
|
+
name: newName,
|
|
80
|
+
type: node.type,
|
|
81
|
+
});
|
|
82
|
+
}}
|
|
83
|
+
onTypeChange={(newType) => {
|
|
84
|
+
handleChangeProperty(level === 0 ? "1" : node.id, {
|
|
85
|
+
name: node.name,
|
|
86
|
+
type: newType,
|
|
87
|
+
});
|
|
88
|
+
}}
|
|
89
|
+
customTypes={customTypes}
|
|
90
|
+
/>
|
|
91
|
+
{true && (
|
|
92
|
+
<IconButton
|
|
93
|
+
size="small"
|
|
94
|
+
onClick={(e) => {
|
|
95
|
+
e.preventDefault();
|
|
96
|
+
e.stopPropagation();
|
|
97
|
+
handleAddProperty(
|
|
98
|
+
{ type: "string", name: "newProperty" },
|
|
99
|
+
level === 0 ? null : node.id
|
|
100
|
+
);
|
|
101
|
+
}}
|
|
102
|
+
disabled={
|
|
103
|
+
node.type !== "object" ||
|
|
104
|
+
(node.type === "array" && node.properties.length >= 1)
|
|
105
|
+
}
|
|
106
|
+
sx={{
|
|
107
|
+
color: (theme) => theme.palette.grey[600],
|
|
108
|
+
marginRight: "-8px ",
|
|
109
|
+
}}
|
|
110
|
+
data-cy={`add-property-button-${node.id}`}
|
|
111
|
+
>
|
|
112
|
+
<AddCircleOutlineIcon fontSize="small" />
|
|
113
|
+
</IconButton>
|
|
114
|
+
)}
|
|
115
|
+
</Box>
|
|
116
|
+
|
|
117
|
+
{true && (
|
|
118
|
+
<IconButton
|
|
119
|
+
size="small"
|
|
120
|
+
style={{ marginLeft: "auto" }}
|
|
121
|
+
onClick={(e) => {
|
|
122
|
+
e.preventDefault();
|
|
123
|
+
e.stopPropagation();
|
|
124
|
+
handleRemoveProperty(node.id);
|
|
125
|
+
}}
|
|
126
|
+
disabled={level === 0}
|
|
127
|
+
sx={{
|
|
128
|
+
color: (theme) => theme.palette.grey[600],
|
|
129
|
+
}}
|
|
130
|
+
>
|
|
131
|
+
<RemoveCircleOutlineIcon fontSize="small" />
|
|
132
|
+
</IconButton>
|
|
133
|
+
)}
|
|
134
|
+
</Box>
|
|
135
|
+
}
|
|
136
|
+
>
|
|
137
|
+
{Array.isArray(node.properties)
|
|
138
|
+
? node.properties.map((childNode) => renderTree(childNode, level + 1))
|
|
139
|
+
: isCustomType(node.type)
|
|
140
|
+
? renderCustomTypeNode(node)
|
|
141
|
+
: null}
|
|
142
|
+
</TreeItem>
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
const isCustomType = (type) => {
|
|
146
|
+
return customTypes.some((customType) => customType.name === type);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const renderCustomTypeNode = (node) => {
|
|
150
|
+
const customTypeSchema = customTypes.find(
|
|
151
|
+
(type) => type.name === node.type
|
|
152
|
+
)?.schema;
|
|
153
|
+
|
|
154
|
+
if (!customTypeSchema || !customTypeSchema.properties) {
|
|
155
|
+
return <Box sx={{ paddingLeft: "20px" }}>No properties defined</Box>;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<Box sx={{ paddingLeft: "20px" }}>
|
|
160
|
+
{customTypeSchema.properties.map((prop, index) => (
|
|
161
|
+
<Box
|
|
162
|
+
key={index}
|
|
163
|
+
sx={{
|
|
164
|
+
paddingTop: "5px",
|
|
165
|
+
paddingBottom: "5px",
|
|
166
|
+
display: "flex",
|
|
167
|
+
alignItems: "center",
|
|
168
|
+
}}
|
|
169
|
+
>
|
|
170
|
+
<Typography
|
|
171
|
+
variant="body2"
|
|
172
|
+
sx={{
|
|
173
|
+
color: (theme) => theme.palette.grey[600],
|
|
174
|
+
}}
|
|
175
|
+
>
|
|
176
|
+
{prop.name}
|
|
177
|
+
</Typography>
|
|
178
|
+
<Typography
|
|
179
|
+
variant="body2"
|
|
180
|
+
sx={{
|
|
181
|
+
marginLeft: "8px",
|
|
182
|
+
color: (theme) => theme.palette.grey[500],
|
|
183
|
+
}}
|
|
184
|
+
>
|
|
185
|
+
{prop.type}
|
|
186
|
+
</Typography>
|
|
187
|
+
</Box>
|
|
188
|
+
))}
|
|
189
|
+
</Box>
|
|
190
|
+
);
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const schemaOutput = () => {
|
|
194
|
+
const removeIds = (node) => {
|
|
195
|
+
// eslint-disable-next-line no-unused-vars
|
|
196
|
+
const { id, properties, ...rest } = node;
|
|
197
|
+
if ((node.type === "object" || node.type === "array") && properties) {
|
|
198
|
+
return { ...rest, properties: properties.map(removeIds) };
|
|
199
|
+
}
|
|
200
|
+
return rest;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
return removeIds(schemaData);
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
React.useImperativeHandle(ref, () => ({
|
|
207
|
+
schemaOutput: schemaOutput,
|
|
208
|
+
}));
|
|
209
|
+
|
|
210
|
+
const schemaOutputWithIDs = () => schemaData;
|
|
211
|
+
|
|
212
|
+
return (
|
|
213
|
+
<SimpleTreeView
|
|
214
|
+
slots={{
|
|
215
|
+
collapseIcon: () => <ExpandMoreIcon data-cy="collapse-icon" />,
|
|
216
|
+
expandIcon: () => <ChevronRightIcon data-cy="expand-icon" />,
|
|
217
|
+
}}
|
|
218
|
+
defaultExpandedItems={["1"]}
|
|
219
|
+
sx={{
|
|
220
|
+
flexGrow: 1,
|
|
221
|
+
overflowY: "auto",
|
|
222
|
+
width: "100%",
|
|
223
|
+
".MuiTreeItem-root": {
|
|
224
|
+
alignItems: "center",
|
|
225
|
+
},
|
|
226
|
+
".MuiTreeItem-content": {
|
|
227
|
+
width: "100%",
|
|
228
|
+
display: "flex",
|
|
229
|
+
justifyContent: "space-between",
|
|
230
|
+
padding: "1px 8px",
|
|
231
|
+
borderRadius: "4px",
|
|
232
|
+
margin: "1px 0",
|
|
233
|
+
transition: "width 0.3s ease-in-out, height 0.3s ease-in-out",
|
|
234
|
+
},
|
|
235
|
+
".MuiTreeItem-label": {
|
|
236
|
+
width: "100%",
|
|
237
|
+
fontWeight: "bold",
|
|
238
|
+
},
|
|
239
|
+
".MuiTreeItem-group": {
|
|
240
|
+
marginLeft: "16px !important",
|
|
241
|
+
paddingLeft: "8px",
|
|
242
|
+
borderLeft: `1px solid`,
|
|
243
|
+
borderColor: (theme) => theme.palette.grey[400],
|
|
244
|
+
},
|
|
245
|
+
".MuiTreeItem-iconContainer": {
|
|
246
|
+
minWidth: "0",
|
|
247
|
+
marginRight: "0px",
|
|
248
|
+
padding: "0px",
|
|
249
|
+
},
|
|
250
|
+
}}
|
|
251
|
+
>
|
|
252
|
+
{renderTree(schemaData, 0)}
|
|
253
|
+
</SimpleTreeView>
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
);
|
|
257
|
+
|
|
258
|
+
export default SchemaEditor;
|