Skip to content

Commit 4da6752

Browse files
FredLL-AvaigaFred Lefévère-Laoide
andauthored
Handle auth changes on core gui data (#2812)
* Handle auth changes on core gui data Closes enterprise#724 * code indentation * from Fab --------- Co-authored-by: Fred Lefévère-Laoide <Fred.Lefevere-Laoide@Taipy.io>
1 parent 7ac40c6 commit 4da6752

File tree

11 files changed

+376
-236
lines changed

11 files changed

+376
-236
lines changed

frontend/taipy/src/CoreSelector.tsx

Lines changed: 106 additions & 91 deletions
Large diffs are not rendered by default.

frontend/taipy/src/DataNodeViewer.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ const DataNodeViewer = (props: DataNodeViewerProps) => {
288288
const dtValue = dnData[DatanodeDataProps.value] ?? (dtType == "float" || dtTypeIsNull ? null : undefined);
289289
const dtTabular = dnData[DatanodeDataProps.tabular] ?? false;
290290
const dtError = dnData[DatanodeDataProps.error];
291-
const dtIsJson = dnData[DatanodeDataProps.isJson] && (dtTypeIsNull ||dtType === "dict" || dtType === "list") ? true : false;
291+
const dtIsJson =
292+
dnData[DatanodeDataProps.isJson] && (dtTypeIsNull || dtType === "dict" || dtType === "list") ? true : false;
292293

293294
const theme = useTheme();
294295

@@ -621,7 +622,10 @@ const DataNodeViewer = (props: DataNodeViewerProps) => {
621622
[dtValue, dtType, dnId, id, dispatch, module, props.onLock, updateDnVars],
622623
);
623624
const onDataValueChange = useCallback((e: ChangeEvent<HTMLInputElement>) => setDataValue(e.target.value), []);
624-
const onDataValueSwitchChange = useCallback((e: ChangeEvent<HTMLInputElement>) => setDataValue(e.target.checked), []);
625+
const onDataValueSwitchChange = useCallback(
626+
(e: ChangeEvent<HTMLInputElement>) => setDataValue(e.target.checked),
627+
[],
628+
);
625629
const onDataValueDateChange = useCallback((d: Date | null) => d && setDataValue(d), []);
626630
useEffect(() => {
627631
if (dtValue !== undefined) {
@@ -706,6 +710,12 @@ const DataNodeViewer = (props: DataNodeViewerProps) => {
706710
}
707711
}, [coreChanged, props.updateVarName, id, module, dispatch, dnId]);
708712

713+
useEffect(() => {
714+
if (props.authChanged) {
715+
props.updateVarName && dispatch(createRequestUpdateAction(id, module, [props.updateVarName], true));
716+
}
717+
}, [props.authChanged, props.updateVarName, module, dispatch, id]);
718+
709719
return (
710720
<>
711721
<Box

frontend/taipy/src/JobSelector.tsx

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,7 @@ import {
6363
useModule,
6464
} from "taipy-gui";
6565

66-
import {
67-
disableColor,
68-
getUpdateVarNames,
69-
popoverOrigin,
70-
EllipsisSx,
71-
SecondaryEllipsisProps,
72-
CoreProps,
73-
} from "./utils";
66+
import { disableColor, getUpdateVarNames, popoverOrigin, EllipsisSx, SecondaryEllipsisProps, CoreProps } from "./utils";
7467
import StatusChip, { Status } from "./StatusChip";
7568
import JobViewer, { JobDetail } from "./JobViewer";
7669

@@ -172,10 +165,10 @@ const Filter = ({ open, anchorEl, handleFilterClose, handleApplyFilter, columns
172165
const { idx } = e.currentTarget.dataset || {};
173166
form.setFieldValue(
174167
"filters",
175-
form.values.filters.filter((_, i) => "" + i !== idx)
168+
form.values.filters.filter((_, i) => "" + i !== idx),
176169
);
177170
},
178-
[form]
171+
[form],
179172
);
180173

181174
const addFilter = useCallback(() => {
@@ -232,7 +225,7 @@ const Filter = ({ open, anchorEl, handleFilterClose, handleApplyFilter, columns
232225
.filter(
233226
(item) =>
234227
item.columnIndex >= 0 &&
235-
(item.showPrimaryLabel || item.showSecondayLabel)
228+
(item.showPrimaryLabel || item.showSecondayLabel),
236229
)
237230
.map((item) => (
238231
<MenuItem key={item.id} value={item.columnIndex}>
@@ -288,7 +281,7 @@ const Filter = ({ open, anchorEl, handleFilterClose, handleApplyFilter, columns
288281
.filter(
289282
(item) =>
290283
item.columnIndex >= 0 &&
291-
(item.showPrimaryLabel || item.showSecondayLabel)
284+
(item.showPrimaryLabel || item.showSecondayLabel),
292285
)
293286
.map((item) => (
294287
<MenuItem key={item.id} value={item.columnIndex}>
@@ -521,7 +514,7 @@ const JobSelector = (props: JobSelectorProps) => {
521514
}
522515
: {}),
523516
}),
524-
[checked]
517+
[checked],
525518
);
526519

527520
const jobSelectorColumns: JobSelectorColumns[] = useMemo(
@@ -571,7 +564,7 @@ const JobSelector = (props: JobSelectorProps) => {
571564
showSecondayLabel: showDelete,
572565
},
573566
],
574-
[showDate, showSubmittedId, showSubmittedLabel, showId, showSubmissionId, showCancel, showDelete]
567+
[showDate, showSubmittedId, showSubmittedLabel, showId, showSubmissionId, showCancel, showDelete],
575568
);
576569

577570
const handleClick = useCallback((event: React.MouseEvent<HTMLElement>) => {
@@ -604,18 +597,25 @@ const JobSelector = (props: JobSelectorProps) => {
604597
}
605598
const jobsVar = getUpdateVar(props.updateVars, "jobs");
606599
dispatch(
607-
createSendUpdateAction(props.updateVarName, newSelected, module, props.onChange, propagate, jobsVar)
600+
createSendUpdateAction(
601+
props.updateVarName,
602+
newSelected,
603+
module,
604+
props.onChange,
605+
propagate,
606+
jobsVar,
607+
),
608608
);
609609
return newSelected;
610610
});
611611
},
612-
[dispatch, module, props.onChange, props.updateVars, props.updateVarName, propagate]
612+
[dispatch, module, props.onChange, props.updateVars, props.updateVarName, propagate],
613613
);
614614

615615
const handleCheckAllClick = useCallback(
616616
(event: React.ChangeEvent<HTMLInputElement>) =>
617617
setChecked(event.target.checked ? jobRows.map((n) => n[JobProps.id]) : []),
618-
[jobRows]
618+
[jobRows],
619619
);
620620

621621
const handleCancelJobs = useCallback(
@@ -628,13 +628,13 @@ const JobSelector = (props: JobSelectorProps) => {
628628
id: multiple === false ? [id] : JSON.parse(id),
629629
action: "cancel",
630630
error_id: getUpdateVar(updateJbVars, "error_id"),
631-
})
631+
}),
632632
);
633633
} catch (e) {
634634
console.warn("Error parsing ids for cancel.", e);
635635
}
636636
},
637-
[dispatch, module, props.id, props.onJobAction, updateJbVars]
637+
[dispatch, module, props.id, props.onJobAction, updateJbVars],
638638
);
639639

640640
const handleDeleteJobs = useCallback(
@@ -647,21 +647,21 @@ const JobSelector = (props: JobSelectorProps) => {
647647
id: multiple === false ? [id] : JSON.parse(id),
648648
action: "delete",
649649
error_id: getUpdateVar(updateJbVars, "error_id"),
650-
})
650+
}),
651651
);
652652
} catch (e) {
653653
console.warn("Error parsing ids for delete.", e);
654654
}
655655
},
656-
[dispatch, module, props.id, props.onJobAction, updateJbVars]
656+
[dispatch, module, props.id, props.onJobAction, updateJbVars],
657657
);
658658

659659
const deleteJob = useCallback(
660660
(event: React.MouseEvent<HTMLElement>) => {
661661
handleDeleteJobs(event);
662662
setShowDetails(false);
663663
},
664-
[handleDeleteJobs]
664+
[handleDeleteJobs],
665665
);
666666

667667
const handleShowDetails = useCallback(
@@ -679,12 +679,12 @@ const JobSelector = (props: JobSelectorProps) => {
679679
module,
680680
getUpdateVarNames(props.updateVars, "details"),
681681
true,
682-
idVar ? { [idVar]: id } : undefined
683-
)
682+
idVar ? { [idVar]: id } : undefined,
683+
),
684684
);
685685
}
686686
},
687-
[dispatch, module, props.id, props.onDetails, props.updateVars, updateJbVars]
687+
[dispatch, module, props.id, props.onDetails, props.updateVars, updateJbVars],
688688
);
689689

690690
const closeDetails = useCallback(() => setShowDetails(false), []);
@@ -698,9 +698,9 @@ const JobSelector = (props: JobSelectorProps) => {
698698
(job) =>
699699
job[JobProps.status] === Status.SUBMITTED ||
700700
job[JobProps.status] === Status.BLOCKED ||
701-
job[JobProps.status] === Status.PENDING
701+
job[JobProps.status] === Status.PENDING,
702702
),
703-
[jobRows, checked]
703+
[jobRows, checked],
704704
);
705705

706706
const allowDeleteJobs = useMemo(
@@ -714,9 +714,9 @@ const JobSelector = (props: JobSelectorProps) => {
714714
job[JobProps.status] === Status.FAILED ||
715715
job[JobProps.status] === Status.COMPLETED ||
716716
job[JobProps.status] === Status.SKIPPED ||
717-
job[JobProps.status] === Status.ABANDONED
717+
job[JobProps.status] === Status.ABANDONED,
718718
),
719-
[jobRows, checked]
719+
[jobRows, checked],
720720
);
721721

722722
const handleFilterOpen = useCallback((event: React.MouseEvent<HTMLButtonElement>) => {
@@ -785,6 +785,13 @@ const JobSelector = (props: JobSelectorProps) => {
785785
}
786786
}, [coreChanged, props.updateVars, module, dispatch, id]);
787787

788+
useEffect(() => {
789+
if (props.authChanged) {
790+
const updateVar = getUpdateVar(props.updateVars, "jobs");
791+
updateVar && dispatch(createRequestUpdateAction(id, module, [updateVar], true));
792+
}
793+
}, [props.authChanged, props.updateVars, module, dispatch, id]);
794+
788795
const tableHeightSx = useMemo(() => ({ maxHeight: props.height || "50vh" }), [props.height]);
789796

790797
return (

frontend/taipy/src/JobViewer.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,27 @@ const JobViewer = (props: JobViewerProps) => {
7676
id: jobId,
7777
action: "delete",
7878
error_id: getUpdateVar(updateJbVars, "error_id"),
79-
})
79+
}),
8080
);
8181
} catch (e) {
8282
console.warn("Error parsing ids for delete.", e);
8383
}
8484
},
85-
[jobId, dispatch, module, props.id, props.onDelete, updateJbVars]
85+
[jobId, dispatch, module, props.id, props.onDelete, updateJbVars],
8686
);
8787

8888
useEffect(() => {
89-
if (coreChanged?.job == jobId) {
89+
if (coreChanged?.job == jobId) {
9090
updateVarName && dispatch(createRequestUpdateAction(id, module, [updateVarName], true));
9191
}
9292
}, [coreChanged, updateVarName, jobId, module, dispatch, id]);
9393

94+
useEffect(() => {
95+
if (props.authChanged) {
96+
props.updateVarName && dispatch(createRequestUpdateAction(props.id, module, [props.updateVarName], true));
97+
}
98+
}, [props.authChanged, props.updateVarName, module, dispatch, props.id]);
99+
94100
return (
95101
<Grid container className={className} sx={{ maxWidth: width }}>
96102
{inDialog ? null : (

frontend/taipy/src/ScenarioDag.tsx

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ const getValidScenario = (scenario: DisplayModel | DisplayModel[]) =>
6868
scenario.length == 3 && typeof scenario[0] === "string"
6969
? (scenario as DisplayModel)
7070
: scenario.length == 1
71-
? (scenario[0] as DisplayModel)
72-
: undefined;
71+
? (scenario[0] as DisplayModel)
72+
: undefined;
7373

7474
const preventWheel = (e: Event) => e.preventDefault();
7575

@@ -95,7 +95,7 @@ const ScenarioDag = (props: ScenarioDagProps) => {
9595
gridTemplateRows: showToolbar ? "auto 1fr" : "1fr",
9696
gridTemplateColumns: "1fr",
9797
}),
98-
[props.width, props.height, showToolbar]
98+
[props.width, props.height, showToolbar],
9999
);
100100

101101
// Refresh on broadcast
@@ -106,10 +106,16 @@ const ScenarioDag = (props: ScenarioDagProps) => {
106106
}
107107
const tasks = coreChanged?.tasks;
108108
if (tasks) {
109-
setTaskStatuses(tasks as TaskStatuses);
109+
setTaskStatuses(tasks);
110110
}
111111
}, [coreChanged, props.updateVarName, scenarioId, module, dispatch, props.id]);
112112

113+
useEffect(() => {
114+
if (props.authChanged) {
115+
props.updateVarName && dispatch(createRequestUpdateAction(props.id, module, [props.updateVarName], true));
116+
}
117+
}, [props.authChanged, props.updateVarName, module, dispatch, props.id]);
118+
113119
useEffect(() => {
114120
let dm: DisplayModel | undefined = undefined;
115121
if (Array.isArray(props.scenario)) {
@@ -130,7 +136,7 @@ const ScenarioDag = (props: ScenarioDagProps) => {
130136

131137
const onClick = useCallback(
132138
(id: string) => onAction && dispatch(createSendActionNameAction(props.id, module, onSelect, id, onAction)),
133-
[props.id, onAction, onSelect, module, dispatch]
139+
[props.id, onAction, onSelect, module, dispatch],
134140
);
135141

136142
useEffect(() => {
@@ -149,10 +155,13 @@ const ScenarioDag = (props: ScenarioDagProps) => {
149155
engine
150156
.getModel()
151157
.getNodes()
152-
.reduce((pv, nm) => {
153-
pv[nm.getID()] = nm.getPosition();
154-
return pv;
155-
}, {} as Record<string, Point>);
158+
.reduce(
159+
(pv, nm) => {
160+
pv[nm.getID()] = nm.getPosition();
161+
return pv;
162+
},
163+
{} as Record<string, Point>,
164+
);
156165
const hasPos = rects && Object.keys(rects).length;
157166
if (hasPos) {
158167
model.getNodes().forEach((nm) => rects[nm.getID()] && nm.setPosition(rects[nm.getID()]));

0 commit comments

Comments
 (0)