|
@@ -35,9 +35,20 @@ import {
|
|
useModule,
|
|
useModule,
|
|
} from "taipy-gui";
|
|
} from "taipy-gui";
|
|
|
|
|
|
-import { FlagSx, Property, ScFProps, ScenarioFull, ScenarioFullLength, useClassNames } from "./utils";
|
|
|
|
|
|
+import { FlagSx, ScFProps, ScenarioFull, ScenarioFullLength, useClassNames } from "./utils";
|
|
import ConfirmDialog from "./utils/ConfirmDialog";
|
|
import ConfirmDialog from "./utils/ConfirmDialog";
|
|
|
|
|
|
|
|
+type Property = {
|
|
|
|
+ id: string;
|
|
|
|
+ key: string;
|
|
|
|
+ value: string;
|
|
|
|
+};
|
|
|
|
+type ScenarioEditPayload = {
|
|
|
|
+ id: string;
|
|
|
|
+ properties?: Property[];
|
|
|
|
+ deleted_properties?: Array<Partial<Property>>;
|
|
|
|
+};
|
|
|
|
+
|
|
interface ScenarioViewerProps {
|
|
interface ScenarioViewerProps {
|
|
id?: string;
|
|
id?: string;
|
|
expandable?: boolean;
|
|
expandable?: boolean;
|
|
@@ -353,14 +364,7 @@ const ScenarioViewer = (props: ScenarioViewerProps) => {
|
|
const { id = "", name = "" } = e.currentTarget.parentElement?.parentElement?.dataset || {};
|
|
const { id = "", name = "" } = e.currentTarget.parentElement?.parentElement?.dataset || {};
|
|
if (name) {
|
|
if (name) {
|
|
if (id) {
|
|
if (id) {
|
|
- setProperties((ps) =>
|
|
|
|
- ps.map((p) => {
|
|
|
|
- if (id == p.id) {
|
|
|
|
- p[name as keyof Property] = e.target.value;
|
|
|
|
- }
|
|
|
|
- return p;
|
|
|
|
- })
|
|
|
|
- );
|
|
|
|
|
|
+ setProperties((ps) => ps.map((p) => (id === p.id ? { ...p, [name]: e.target.value } : p)));
|
|
} else {
|
|
} else {
|
|
setNewProp((np) => ({ ...np, [name]: e.target.value }));
|
|
setNewProp((np) => ({ ...np, [name]: e.target.value }));
|
|
}
|
|
}
|
|
@@ -373,10 +377,14 @@ const ScenarioViewer = (props: ScenarioViewerProps) => {
|
|
if (isScenario) {
|
|
if (isScenario) {
|
|
const { id: propId = "" } = e.currentTarget.dataset || {};
|
|
const { id: propId = "" } = e.currentTarget.dataset || {};
|
|
const property = propId ? properties.find((p) => p.id === propId) : newProp;
|
|
const property = propId ? properties.find((p) => p.id === propId) : newProp;
|
|
- property &&
|
|
|
|
- dispatch(
|
|
|
|
- createSendActionNameAction(id, module, props.onEdit, { id: scId, properties: [property] })
|
|
|
|
- );
|
|
|
|
|
|
+ if (property) {
|
|
|
|
+ const oldId = property.id;
|
|
|
|
+ const payload: ScenarioEditPayload = { id: scId, properties: [property] };
|
|
|
|
+ if (oldId && oldId != property.key) {
|
|
|
|
+ payload.deleted_properties = [{ key: oldId }];
|
|
|
|
+ }
|
|
|
|
+ dispatch(createSendActionNameAction(id, module, props.onEdit, payload));
|
|
|
|
+ }
|
|
setNewProp((np) => ({ ...np, key: "", value: "" }));
|
|
setNewProp((np) => ({ ...np, key: "", value: "" }));
|
|
setFocusName("");
|
|
setFocusName("");
|
|
}
|
|
}
|
|
@@ -388,24 +396,21 @@ const ScenarioViewer = (props: ScenarioViewerProps) => {
|
|
e.stopPropagation();
|
|
e.stopPropagation();
|
|
if (isScenario) {
|
|
if (isScenario) {
|
|
const { id: propId = "" } = e.currentTarget.dataset || {};
|
|
const { id: propId = "" } = e.currentTarget.dataset || {};
|
|
- const propertyIdx = properties.findIndex((p) => p.id === propId);
|
|
|
|
- propertyIdx > -1 &&
|
|
|
|
- propertyIdx < scProperties.length &&
|
|
|
|
|
|
+ const property = scProperties.find(([key]) => key === propId);
|
|
|
|
+ property &&
|
|
setProperties((ps) =>
|
|
setProperties((ps) =>
|
|
- ps.map((p, idx) =>
|
|
|
|
- idx == propertyIdx ? { ...p, key: scProperties[idx][0], value: scProperties[idx][1] } : p
|
|
|
|
- )
|
|
|
|
|
|
+ ps.map((p) => (p.id === property[0] ? { ...p, key: property[0], value: property[1] } : p))
|
|
);
|
|
);
|
|
setFocusName("");
|
|
setFocusName("");
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- [isScenario, properties, scProperties]
|
|
|
|
|
|
+ [isScenario, scProperties]
|
|
);
|
|
);
|
|
|
|
|
|
const deleteProperty = useCallback(
|
|
const deleteProperty = useCallback(
|
|
(e: React.MouseEvent<HTMLElement>) => {
|
|
(e: React.MouseEvent<HTMLElement>) => {
|
|
e.stopPropagation();
|
|
e.stopPropagation();
|
|
- const { id: propId = "-1" } = e.currentTarget.dataset;
|
|
|
|
|
|
+ const { id: propId = "" } = e.currentTarget.dataset;
|
|
setProperties((ps) => ps.filter((item) => item.id !== propId));
|
|
setProperties((ps) => ps.filter((item) => item.id !== propId));
|
|
const property = properties.find((p) => p.id === propId);
|
|
const property = properties.find((p) => p.id === propId);
|
|
property &&
|
|
property &&
|
|
@@ -436,8 +441,8 @@ const ScenarioViewer = (props: ScenarioViewerProps) => {
|
|
showTags && setTags(scTags);
|
|
showTags && setTags(scTags);
|
|
showProperties &&
|
|
showProperties &&
|
|
setProperties(
|
|
setProperties(
|
|
- scProperties.map(([k, v], i) => ({
|
|
|
|
- id: i + "",
|
|
|
|
|
|
+ scProperties.map(([k, v]) => ({
|
|
|
|
+ id: k,
|
|
key: k,
|
|
key: k,
|
|
value: v,
|
|
value: v,
|
|
}))
|
|
}))
|
|
@@ -654,7 +659,7 @@ const ScenarioViewer = (props: ScenarioViewerProps) => {
|
|
spacing={1}
|
|
spacing={1}
|
|
container
|
|
container
|
|
justifyContent="space-between"
|
|
justifyContent="space-between"
|
|
- key={property.key}
|
|
|
|
|
|
+ key={property.id}
|
|
data-focus={propName}
|
|
data-focus={propName}
|
|
onClick={onFocus}
|
|
onClick={onFocus}
|
|
sx={hoverSx}
|
|
sx={hoverSx}
|
|
@@ -757,11 +762,11 @@ const ScenarioViewer = (props: ScenarioViewerProps) => {
|
|
spacing={1}
|
|
spacing={1}
|
|
container
|
|
container
|
|
justifyContent="space-between"
|
|
justifyContent="space-between"
|
|
- data-focus="property-new"
|
|
|
|
|
|
+ data-focus="new-property"
|
|
onClick={onFocus}
|
|
onClick={onFocus}
|
|
sx={hoverSx}
|
|
sx={hoverSx}
|
|
>
|
|
>
|
|
- {active && focusName == "property-new" ? (
|
|
|
|
|
|
+ {active && focusName == "new-property" ? (
|
|
<>
|
|
<>
|
|
<Grid item xs={4}>
|
|
<Grid item xs={4}>
|
|
<TextField
|
|
<TextField
|