@ebubekirylmaz/link-test 1.2.44 → 1.2.46
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 +13 -6
- package/src/Platform.jsx +14 -15
- package/src/assets/illustrations/avatar-shape.jsx +6 -7
- package/src/assets/illustrations/booking-illustration.jsx +4 -14
- package/src/assets/illustrations/check-in-illustration.jsx +4 -10
- package/src/assets/illustrations/check-out-illustration.jsx +4 -3
- package/src/assets/illustrations/coming-soon-illustration.jsx +4 -17
- package/src/assets/illustrations/forbidden-illustration.jsx +4 -12
- package/src/assets/illustrations/maintenance-illustration.jsx +4 -24
- package/src/assets/illustrations/motivation-illustration.jsx +4 -9
- package/src/assets/illustrations/order-complete-illustration.jsx +4 -12
- package/src/assets/illustrations/page-not-found-illustration.jsx +4 -9
- package/src/assets/illustrations/seo-illustration.jsx +4 -16
- package/src/assets/illustrations/sever-error-illustration.jsx +4 -21
- package/src/assets/illustrations/upgrade-storage-illustration.jsx +4 -20
- package/src/assets/illustrations/upload-illustration.jsx +4 -81
- package/src/components/NucleoidLoginForm/NucleoidLoginForm.jsx +1 -0
- package/src/components/TopNavBar/TopNavBar.jsx +6 -2
- package/src/components/file-thumbnail/file-thumbnail.jsx +5 -6
- package/src/components/nav-section/horizontal/nav-section-horizontal.jsx +5 -6
- package/src/components/settings/drawer/layout-options.jsx +5 -4
- package/src/components/settings/drawer/presets-options.jsx +6 -5
- package/src/components/settings/drawer/settings-drawer.jsx +7 -4
- package/src/components/settings/drawer/stretch-options.jsx +5 -5
- 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/DashboardLayout/header.jsx +5 -4
- package/src/layouts/DashboardLayout/nav-mini.jsx +5 -7
- package/src/layouts/DashboardLayout/nav-vertical.jsx +11 -11
- package/src/layouts/FullScreenLayout/FullScreenLayout.jsx +5 -1
- package/src/layouts/FullScreenLayout/nav-vertical.jsx +11 -11
- package/src/layouts/MainLayout/footer.jsx +7 -7
- package/src/layouts/MainLayout/header.jsx +3 -2
- package/src/layouts/MainLayout/nav/desktop/nav-list.jsx +8 -8
- package/src/layouts/MainLayout/nav/mobile/index.jsx +7 -6
- package/src/layouts/auth/classic.jsx +6 -6
- package/src/layouts/auth/modern.jsx +7 -6
- package/src/layouts/common/ProjectBar/index.jsx +13 -11
- package/src/layouts/common/account-popover.jsx +1 -2
- package/src/layouts/common/header-sim.jsx +3 -2
- package/src/layouts/common/header-simple.jsx +6 -3
- package/src/layouts/common/notifications-popover/index.jsx +18 -13
- package/src/layouts/common/notifications-popover/notification-item.jsx +28 -16
- 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 +411 -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/AddItemWizard/AddItemWizard.jsx +21 -10
- package/src/lib/BlankTreeMessage/BlankTreeMessage.jsx +39 -0
- package/src/lib/BlankTreeMessage/index.js +1 -0
- package/src/lib/CustomBreadcrumbs/CustomBreadcrumbs.jsx +3 -2
- 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/layouts/CardLayout.jsx +4 -3
- package/src/lib/Flow/nodes/DefaultCard.jsx +6 -8
- package/src/lib/Flow/nodes/FlowNodeView.jsx +105 -21
- package/src/lib/Flow/styles.js +4 -0
- package/src/lib/IconSelector/IconSelector.jsx +5 -1
- package/src/lib/ItemSummary/ItemSummary.jsx +11 -6
- package/src/lib/ItemSummary/ItemsSummary.jsx +38 -26
- 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 +158 -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/SparkleInput/SparkleInput.jsx +31 -28
- package/src/lib/TableSelectedAction/TableSelectedAction.jsx +7 -8
- 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/ConfigError.jsx +3 -1
- 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/theme/overrides/default-props.jsx +17 -11
- package/src/widgets/Login/CognitoLogin.jsx +165 -173
- package/src/widgets/Login/DemoLogin.jsx +43 -38
- 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 +206 -16
|
@@ -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;
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import "@testing-library/jest-dom";
|
|
2
|
+
|
|
3
|
+
import React from "react";
|
|
4
|
+
import SchemaEditor from "./SchemaEditor";
|
|
5
|
+
import { act } from "react-dom/test-utils";
|
|
6
|
+
|
|
7
|
+
import { render, screen } from "@testing-library/react";
|
|
8
|
+
|
|
9
|
+
describe("SchemaEditor Component", () => {
|
|
10
|
+
const initialSchema = {
|
|
11
|
+
type: "object",
|
|
12
|
+
properties: [
|
|
13
|
+
{ type: "string", name: "initial" },
|
|
14
|
+
{ type: "integer", name: "schema" },
|
|
15
|
+
{
|
|
16
|
+
type: "object",
|
|
17
|
+
name: "object",
|
|
18
|
+
properties: [{ type: "integer", name: "nested" }],
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
test("renders with initial schema", () => {
|
|
24
|
+
console.log("rendering ");
|
|
25
|
+
render(<SchemaEditor initialData={initialSchema} />);
|
|
26
|
+
|
|
27
|
+
expect(screen.getByDisplayValue(/initial/)).toBeInTheDocument();
|
|
28
|
+
expect(screen.getByDisplayValue(/schema/)).toBeInTheDocument();
|
|
29
|
+
|
|
30
|
+
// expect(screen.getByText(/nested/)).toBeInTheDocument();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("initializes without initial data", () => {
|
|
34
|
+
console.log("initializing without initial data");
|
|
35
|
+
render(<SchemaEditor />);
|
|
36
|
+
|
|
37
|
+
const expectedSchema = {
|
|
38
|
+
type: "object",
|
|
39
|
+
properties: [],
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const outputSchema = SchemaEditor.schemaOutput();
|
|
43
|
+
expect(outputSchema).toEqual(expectedSchema);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("provides output correctly with initial data", () => {
|
|
47
|
+
console.log("provides output correctly with initial data");
|
|
48
|
+
render(<SchemaEditor initialData={initialSchema} />);
|
|
49
|
+
|
|
50
|
+
const outputSchema = SchemaEditor.schemaOutput();
|
|
51
|
+
expect(outputSchema).toEqual(initialSchema);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("adds a new property", () => {
|
|
55
|
+
console.log("adds a new property");
|
|
56
|
+
const emptySchema = { type: "object", properties: [] };
|
|
57
|
+
render(<SchemaEditor initialData={emptySchema} />);
|
|
58
|
+
|
|
59
|
+
act(() => {
|
|
60
|
+
SchemaEditor.addProperty(null);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
let updatedSchema = SchemaEditor.schemaOutput();
|
|
64
|
+
expect(updatedSchema.properties).toHaveLength(1);
|
|
65
|
+
expect(updatedSchema.properties[0].name).toBe("id");
|
|
66
|
+
|
|
67
|
+
act(() => {
|
|
68
|
+
SchemaEditor.addProperty(null);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
updatedSchema = SchemaEditor.schemaOutput();
|
|
72
|
+
expect(updatedSchema.properties).toHaveLength(2);
|
|
73
|
+
expect(updatedSchema.properties[1].name).toBe("prop2");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("removes a property by ID", () => {
|
|
77
|
+
console.log("removes a property by ID");
|
|
78
|
+
render(<SchemaEditor initialData={initialSchema} />);
|
|
79
|
+
|
|
80
|
+
const currentSchemaWithIDs = SchemaEditor.schemaOutputWithIDs();
|
|
81
|
+
|
|
82
|
+
const propertyToRemove = currentSchemaWithIDs.properties.find(
|
|
83
|
+
(prop) => prop.name === "initial"
|
|
84
|
+
);
|
|
85
|
+
if (!propertyToRemove) {
|
|
86
|
+
throw new Error("Property to remove not found");
|
|
87
|
+
}
|
|
88
|
+
act(() => {
|
|
89
|
+
SchemaEditor.removeProperty(propertyToRemove.id);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const newCurrentSchema = SchemaEditor.schemaOutput();
|
|
93
|
+
const isPropertyRemoved = newCurrentSchema.properties.every(
|
|
94
|
+
(prop) => prop.name !== "initial"
|
|
95
|
+
);
|
|
96
|
+
expect(isPropertyRemoved).toBeTruthy();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("changes a property type and name", () => {
|
|
100
|
+
console.log("changes a property type and name");
|
|
101
|
+
render(<SchemaEditor initialData={initialSchema} />);
|
|
102
|
+
|
|
103
|
+
const currentSchemaWithIDs = SchemaEditor.schemaOutputWithIDs();
|
|
104
|
+
|
|
105
|
+
const propertyToChange = currentSchemaWithIDs.properties.find(
|
|
106
|
+
(prop) => prop.name === "initial"
|
|
107
|
+
);
|
|
108
|
+
if (!propertyToChange) {
|
|
109
|
+
throw new Error("Property to change not found");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const change = {
|
|
113
|
+
name: "initial2",
|
|
114
|
+
type: "integer",
|
|
115
|
+
};
|
|
116
|
+
act(() => {
|
|
117
|
+
SchemaEditor.changeProperty(propertyToChange.id, change);
|
|
118
|
+
});
|
|
119
|
+
const updatedSchemaWithIDs = SchemaEditor.schemaOutputWithIDs();
|
|
120
|
+
|
|
121
|
+
const changedProperty = updatedSchemaWithIDs.properties.find(
|
|
122
|
+
(prop) => prop.id === propertyToChange.id
|
|
123
|
+
);
|
|
124
|
+
expect(changedProperty).toBeDefined();
|
|
125
|
+
expect(changedProperty.name).toBe(change.name);
|
|
126
|
+
expect(changedProperty.type).toBe(change.type);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test("adds a nested object and a property to it", () => {
|
|
130
|
+
console.log("adds a nested object and a property to it");
|
|
131
|
+
render(<SchemaEditor initialData={initialSchema} />);
|
|
132
|
+
|
|
133
|
+
act(() => {
|
|
134
|
+
SchemaEditor.addProperty(null);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
let updatedSchemaWithIDs = SchemaEditor.schemaOutputWithIDs();
|
|
138
|
+
const newNestedObjectId = updatedSchemaWithIDs.properties.find(
|
|
139
|
+
(prop) => prop.name === "prop4"
|
|
140
|
+
).id;
|
|
141
|
+
|
|
142
|
+
act(() => {
|
|
143
|
+
SchemaEditor.addProperty(newNestedObjectId);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
updatedSchemaWithIDs = SchemaEditor.schemaOutputWithIDs();
|
|
147
|
+
const updatedNestedObject = updatedSchemaWithIDs.properties.find(
|
|
148
|
+
(prop) => prop.id === newNestedObjectId
|
|
149
|
+
);
|
|
150
|
+
console.log("updatedNestedObject: ", updatedNestedObject);
|
|
151
|
+
expect(updatedNestedObject).toBeDefined();
|
|
152
|
+
expect(updatedNestedObject.name).toBe("prop4");
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test("changes a property to custom type", () => {
|
|
156
|
+
console.log("changes a property to custom type");
|
|
157
|
+
const customTypes = [
|
|
158
|
+
{
|
|
159
|
+
name: "Item",
|
|
160
|
+
schema: {
|
|
161
|
+
type: "object",
|
|
162
|
+
properties: [
|
|
163
|
+
{ type: "string", name: "id" },
|
|
164
|
+
{ type: "string", name: "name" },
|
|
165
|
+
{ type: "string", name: "barcode" },
|
|
166
|
+
],
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
];
|
|
170
|
+
|
|
171
|
+
render(
|
|
172
|
+
<SchemaEditor initialData={initialSchema} customTypes={customTypes} />
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
const currentSchemaWithIDs = SchemaEditor.schemaOutputWithIDs();
|
|
176
|
+
const propertyToChange = currentSchemaWithIDs.properties[0];
|
|
177
|
+
|
|
178
|
+
const change = {
|
|
179
|
+
type: "Item",
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
act(() => {
|
|
183
|
+
SchemaEditor.changeProperty(propertyToChange.id, change);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
const updatedSchemaWithIDs = SchemaEditor.schemaOutputWithIDs();
|
|
187
|
+
const updatedProperty = updatedSchemaWithIDs.properties.find(
|
|
188
|
+
(prop) => prop.id === propertyToChange.id
|
|
189
|
+
);
|
|
190
|
+
expect(updatedProperty).toBeDefined();
|
|
191
|
+
expect(updatedProperty.type).toBe("Item");
|
|
192
|
+
});
|
|
193
|
+
});
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { Box, Input, MenuItem, Select, Typography } from "@mui/material";
|
|
2
|
+
import React, { useState } from "react";
|
|
3
|
+
|
|
4
|
+
const SchemaPropertyEditor = ({
|
|
5
|
+
node,
|
|
6
|
+
onNameChange,
|
|
7
|
+
disableNameChange,
|
|
8
|
+
onTypeChange,
|
|
9
|
+
customTypes,
|
|
10
|
+
}) => {
|
|
11
|
+
const [editMode, setEditMode] = useState(null);
|
|
12
|
+
const [name, setName] = useState(node.name || "");
|
|
13
|
+
const [type, setType] = useState(node.type);
|
|
14
|
+
const [isSelectOpen, setIsSelectOpen] = useState(false);
|
|
15
|
+
|
|
16
|
+
const handleNameChange = (newName) => {
|
|
17
|
+
setName(newName);
|
|
18
|
+
onNameChange(newName);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const handleTypeChange = (newType) => {
|
|
22
|
+
setType(newType);
|
|
23
|
+
onTypeChange(newType);
|
|
24
|
+
setEditMode(null);
|
|
25
|
+
setIsSelectOpen(false);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const isRootNode = node.level === 0;
|
|
29
|
+
|
|
30
|
+
const propertyTypes = isRootNode
|
|
31
|
+
? ["object", "array", ...customTypes.map((type) => type.name)]
|
|
32
|
+
: [
|
|
33
|
+
"string",
|
|
34
|
+
"number",
|
|
35
|
+
"boolean",
|
|
36
|
+
"object",
|
|
37
|
+
"array",
|
|
38
|
+
...customTypes.map((type) => type.name),
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<Box
|
|
43
|
+
sx={{
|
|
44
|
+
display: "flex",
|
|
45
|
+
justifyContent: "space-between",
|
|
46
|
+
width: "100%",
|
|
47
|
+
gap: "4px",
|
|
48
|
+
}}
|
|
49
|
+
>
|
|
50
|
+
{!disableNameChange ? (
|
|
51
|
+
<Box
|
|
52
|
+
sx={{
|
|
53
|
+
display: "flex",
|
|
54
|
+
justifyContent: "space-between",
|
|
55
|
+
width: "100%",
|
|
56
|
+
gap: "4px",
|
|
57
|
+
}}
|
|
58
|
+
onClick={() => {
|
|
59
|
+
setEditMode("name");
|
|
60
|
+
}}
|
|
61
|
+
>
|
|
62
|
+
<Input
|
|
63
|
+
value={name}
|
|
64
|
+
onChange={(e) => handleNameChange(e.target.value)}
|
|
65
|
+
disableUnderline
|
|
66
|
+
fullWidth
|
|
67
|
+
sx={{
|
|
68
|
+
borderBottom: "2px solid transparent",
|
|
69
|
+
"&:hover": {
|
|
70
|
+
borderBottom: "2px solid gray",
|
|
71
|
+
},
|
|
72
|
+
"&:focus": {
|
|
73
|
+
borderBottom: "2px solid blue",
|
|
74
|
+
},
|
|
75
|
+
}}
|
|
76
|
+
data-cy={`property-name-field-${node.id}`}
|
|
77
|
+
/>
|
|
78
|
+
</Box>
|
|
79
|
+
) : (
|
|
80
|
+
<Box
|
|
81
|
+
sx={{
|
|
82
|
+
width: "100%",
|
|
83
|
+
display: "flex",
|
|
84
|
+
alignItems: "center",
|
|
85
|
+
}}
|
|
86
|
+
></Box>
|
|
87
|
+
)}
|
|
88
|
+
|
|
89
|
+
{editMode === "type" ? (
|
|
90
|
+
<Select
|
|
91
|
+
open={isSelectOpen}
|
|
92
|
+
value={type}
|
|
93
|
+
onChange={(e) => handleTypeChange(e.target.value)}
|
|
94
|
+
onClose={() => {
|
|
95
|
+
setEditMode(null);
|
|
96
|
+
setIsSelectOpen(false);
|
|
97
|
+
}}
|
|
98
|
+
onOpen={() => setIsSelectOpen(true)}
|
|
99
|
+
>
|
|
100
|
+
{propertyTypes.map((typeOption) => (
|
|
101
|
+
<MenuItem
|
|
102
|
+
value={typeOption}
|
|
103
|
+
key={typeOption}
|
|
104
|
+
data-cy={`property-type-option-${typeOption}`}
|
|
105
|
+
>
|
|
106
|
+
{typeOption}
|
|
107
|
+
</MenuItem>
|
|
108
|
+
))}
|
|
109
|
+
</Select>
|
|
110
|
+
) : (
|
|
111
|
+
<Box sx={{ display: "flex", alignItems: "center", cursor: "pointer" }}>
|
|
112
|
+
<Typography
|
|
113
|
+
variant="body2"
|
|
114
|
+
onClick={() => {
|
|
115
|
+
setEditMode("type");
|
|
116
|
+
setIsSelectOpen(true);
|
|
117
|
+
}}
|
|
118
|
+
sx={{
|
|
119
|
+
cursor: "pointer",
|
|
120
|
+
borderRadius: "4px",
|
|
121
|
+
"&:hover": {
|
|
122
|
+
backgroundColor: (theme) => theme.palette.grey[600],
|
|
123
|
+
},
|
|
124
|
+
}}
|
|
125
|
+
data-cy={`property-type-select-${node.id}`}
|
|
126
|
+
>
|
|
127
|
+
{node.type}
|
|
128
|
+
</Typography>
|
|
129
|
+
</Box>
|
|
130
|
+
)}
|
|
131
|
+
</Box>
|
|
132
|
+
);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export default SchemaPropertyEditor;
|