Skip to content

Commit b0e10d9

Browse files
authored
Feature: Sidebar parent model update (#2291)
* task: add update model component to sidebar * task: save parent model changes * task: enable deselecting parent model * task: tooltip string prop * task: fix ts error
1 parent 5defd07 commit b0e10d9

File tree

4 files changed

+80
-17
lines changed

4 files changed

+80
-17
lines changed

src/apps/schema/src/app/components/CreateModelDialogue.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ export const CreateModelDialogue = ({ onClose, modelType = "" }: Props) => {
367367
parentZUID: value,
368368
})
369369
}
370+
tooltip="Selecting a parent affects default routing and content navigation in the UI"
370371
/>
371372
<Box>
372373
<InputLabel>

src/apps/schema/src/app/components/FieldsListRight.tsx

+65-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
Typography,
99
Link,
1010
Tooltip,
11+
Select,
1112
} from "@mui/material";
1213
import SaveRoundedIcon from "@mui/icons-material/SaveRounded";
1314
import LoadingButton from "@mui/lab/LoadingButton";
@@ -16,6 +17,7 @@ import CheckIcon from "@mui/icons-material/Check";
1617
import InfoRoundedIcon from "@mui/icons-material/InfoRounded";
1718
import { ContentModel } from "../../../../../shell/services/types";
1819
import { useUpdateContentModelMutation } from "../../../../../shell/services/instance";
20+
import { SelectModelParentInput } from "./SelectModelParentInput";
1921

2022
interface Props {
2123
model: ContentModel;
@@ -24,15 +26,31 @@ interface Props {
2426
export const FieldsListRight = ({ model }: Props) => {
2527
const [description, setDescription] = useState("");
2628
const [isCopied, setIsCopied] = useState(null);
29+
const [newParentZUID, setNewParentZUID] = useState(null);
30+
const [showSaveParentModelButton, setshowSaveParentModelButton] =
31+
useState(false);
2732

28-
const [updateContentModel, { isLoading }] = useUpdateContentModelMutation();
33+
useEffect(() => {
34+
if (model?.parentZUID) {
35+
setNewParentZUID(model.parentZUID === "0" ? null : model.parentZUID);
36+
}
37+
}, [model]);
38+
39+
const [updateContentModel, { isLoading, isSuccess }] =
40+
useUpdateContentModelMutation();
2941

3042
useEffect(() => {
3143
if (model?.description) {
3244
setDescription(model?.description || "");
3345
}
3446
}, [model]);
3547

48+
useEffect(() => {
49+
if (isSuccess) {
50+
setshowSaveParentModelButton(false);
51+
}
52+
}, [isSuccess]);
53+
3654
const handleCopyClick = (data: string) => {
3755
navigator?.clipboard
3856
?.writeText(data)
@@ -47,11 +65,28 @@ export const FieldsListRight = ({ model }: Props) => {
4765
});
4866
};
4967

50-
const handleSave = () => {
51-
const body = {
52-
...model,
53-
description,
54-
};
68+
const handleSave = (type: "description" | "parentZUID") => {
69+
let body = { ...model };
70+
71+
switch (type) {
72+
case "description":
73+
body = {
74+
...body,
75+
description,
76+
};
77+
break;
78+
79+
case "parentZUID":
80+
body = {
81+
...body,
82+
parentZUID: newParentZUID ?? "0",
83+
};
84+
break;
85+
86+
default:
87+
break;
88+
}
89+
5590
updateContentModel({
5691
ZUID: model.ZUID,
5792
body,
@@ -140,6 +175,29 @@ export const FieldsListRight = ({ model }: Props) => {
140175
),
141176
}}
142177
/>
178+
<Box mt={3}>
179+
<SelectModelParentInput
180+
modelType={model?.type}
181+
value={newParentZUID}
182+
onChange={(value) => {
183+
setshowSaveParentModelButton(value !== model?.parentZUID);
184+
setNewParentZUID(value);
185+
}}
186+
label="Model Parent"
187+
/>
188+
{showSaveParentModelButton && (
189+
<LoadingButton
190+
color="primary"
191+
loading={isLoading}
192+
variant="contained"
193+
onClick={() => handleSave("parentZUID")}
194+
sx={{ mt: 1.5 }}
195+
>
196+
Save
197+
</LoadingButton>
198+
)}
199+
</Box>
200+
143201
<InputLabel sx={{ mt: 3 }}>
144202
Description
145203
<Tooltip
@@ -166,7 +224,7 @@ export const FieldsListRight = ({ model }: Props) => {
166224
startIcon={<SaveRoundedIcon />}
167225
loadingPosition="start"
168226
variant="contained"
169-
onClick={handleSave}
227+
onClick={() => handleSave("description")}
170228
sx={{ mt: 1.5 }}
171229
>
172230
Save

src/apps/schema/src/app/components/SelectModelParentInput.tsx

+13-10
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ type SelectModelParentInputProps = {
1414
value: string;
1515
onChange: (value: string) => void;
1616
modelType: ModelType;
17+
label?: string;
18+
tooltip?: string;
1719
};
1820

1921
export const SelectModelParentInput = ({
2022
value,
2123
onChange,
2224
modelType,
25+
label = "Select Model Parent",
26+
tooltip = "",
2327
}: SelectModelParentInputProps) => {
2428
const { data: navItems } = useGetContentNavItemsQuery();
2529

@@ -43,16 +47,15 @@ export const SelectModelParentInput = ({
4347
return (
4448
<Box>
4549
<InputLabel>
46-
Select Model Parent
47-
<Tooltip
48-
placement="top"
49-
title="Selecting a parent affects default routing and content navigation in the UI"
50-
>
51-
<InfoRoundedIcon
52-
sx={{ ml: 1, width: "10px", height: "10px" }}
53-
color="action"
54-
/>
55-
</Tooltip>
50+
{label}
51+
{tooltip && (
52+
<Tooltip placement="top" title={tooltip}>
53+
<InfoRoundedIcon
54+
sx={{ ml: 1, width: "10px", height: "10px" }}
55+
color="action"
56+
/>
57+
</Tooltip>
58+
)}
5659
</InputLabel>
5760
<Autocomplete
5861
fullWidth

src/apps/schema/src/app/components/UpdateParentModelDialogue.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export const UpdateParentModelDialogue = ({ onClose, model }: Props) => {
8181
modelType={model.type}
8282
value={newParentZUID}
8383
onChange={(value) => setNewParentZUID(value)}
84+
tooltip="Selecting a parent affects default routing and content navigation in the UI"
8485
/>
8586
</DialogContent>
8687
<DialogActions>

0 commit comments

Comments
 (0)