Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion frontend/taipy-gui/dom/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 8 additions & 31 deletions frontend/taipy-gui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions frontend/taipy/src/ScenarioSelector.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import "@testing-library/jest-dom";
import { createContext } from "react";

import ScenarioSelector from "./ScenarioSelector";
import { getEmptyScenario } from "./ScenarioSelector";
import { useDispatchRequestUpdateOnFirstRender } from "taipy-gui";

const TaipyContext = createContext<object>({ state: {}, dispatch: () => null });
Expand Down Expand Up @@ -114,3 +115,26 @@ describe("ScenarioSelector Component", () => {
expect(elt).toBeDisabled();
});
});

describe("getEmptyScenario", () => {
it("returns a fresh date on each call", async () => {
const first = getEmptyScenario();
// Wait a small amount to ensure timestamps differ
await new Promise((resolve) => setTimeout(resolve, 10));
const second = getEmptyScenario();

expect(first.date).not.toBe(second.date);
expect(new Date(second.date).getTime()).toBeGreaterThan(new Date(first.date).getTime());
});

it("returns default empty values", () => {
const scenario = getEmptyScenario();

expect(scenario.config).toBe("");
expect(scenario.name).toBe("");
expect(scenario.properties).toEqual([]);
expect(scenario.date).toBeTruthy();
// Verify date is a valid ISO string
expect(new Date(scenario.date).toISOString()).toBe(scenario.date);
});
});
10 changes: 5 additions & 5 deletions frontend/taipy/src/ScenarioSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ interface ScenarioEditDialogProps {
close: () => void;
}

const emptyScenario: ScenarioDict = {
export const getEmptyScenario = (): ScenarioDict => ({
config: "",
name: "",
date: new Date().toISOString(),
properties: [],
};
});

const DialogContentSx = {
maxHeight: "calc(100vh - 256px)",
Expand Down Expand Up @@ -184,12 +184,12 @@ const ScenarioEditDialog = ({ scenario, submit, open, actionEdit, configs, close
}, []);

const form = useFormik({
initialValues: emptyScenario,
initialValues: getEmptyScenario(),
onSubmit: (values: ScenarioDict) => {
values.properties = [...properties];
setProperties([]);
submit(actionEdit, false, values);
form.resetForm({ values: { ...emptyScenario, config: configs?.length === 1 ? configs[0][0] : "" } });
form.resetForm({ values: { ...getEmptyScenario(), config: configs?.length === 1 ? configs[0][0] : "" } });
close();
},
});
Expand All @@ -204,7 +204,7 @@ const ScenarioEditDialog = ({ scenario, submit, open, actionEdit, configs, close
date: scenario[ScFProps.creation_date],
properties: [],
}
: { ...emptyScenario, config: configs?.length === 1 ? configs[0][0] : "" },
: { ...getEmptyScenario(), config: configs?.length === 1 ? configs[0][0] : "" },
);
setProperties(
actionEdit && scenario ? scenario[ScFProps.properties].map(([k, v], i) => ({ id: i + "", key: k, value: v })) : [],
Expand Down
4 changes: 3 additions & 1 deletion taipy/gui_core/_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,13 @@ def _invoke_action(
try:
if col_type == "any":
# when a property is not found, return True only if action is "not equal"
if not is_dn and not hasattr(ent, "properties") or not ent.properties.get(col_fn or col):
if (not is_dn and not hasattr(ent, "properties")) or not ent.properties.get(col_fn or col):
return action == "!="
if op := _operators.get(action):
if callable(col):
cur_val = col(ent)
elif col_type == "any":
cur_val = ent.properties.get(col_fn or col)
else:
cur_val = attrgetter(col_fn or col)(ent)
cur_val = cur_val() if col_fn else cur_val
Expand Down
Loading