From ea5004829f53f406bd8a85f3c178da4b959a720f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fred=20Lef=C3=A9v=C3=A8re-Laoide?= <90181748+FredLL-Avaiga@users.noreply.github.com> Date: Mon, 26 Feb 2024 20:17:38 +0100 Subject: [PATCH] order scenarios (and cycles) so that we always get the same order on UI (by creation date) (#884) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit resolves #165 Co-authored-by: Fred Lefévère-Laoide --- taipy/gui_core/_context.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/taipy/gui_core/_context.py b/taipy/gui_core/_context.py index 0054e5b798..0abdead1aa 100644 --- a/taipy/gui_core/_context.py +++ b/taipy/gui_core/_context.py @@ -217,7 +217,9 @@ def scenario_adapter(self, scenario_or_cycle): return ( scenario_or_cycle.id, scenario_or_cycle.get_simple_label(), - self.scenario_by_cycle.get(scenario_or_cycle), + sorted( + self.scenario_by_cycle.get(scenario_or_cycle, []), key=_GuiCoreContext.sort_by_creation_date + ), _EntityType.CYCLE.value, False, ) @@ -248,7 +250,7 @@ def get_scenarios(self): cycles_scenarios.extend(scenarios) else: cycles_scenarios.append(cycle) - return cycles_scenarios + return sorted(cycles_scenarios, key=_GuiCoreContext.sort_by_creation_date) def select_scenario(self, state: State, id: str, payload: t.Dict[str, str]): args = payload.get("args") @@ -667,6 +669,10 @@ def __edit_properties(self, entity: t.Union[Scenario, Sequence, DataNode], data: if key and key not in _GuiCoreContext.__ENTITY_PROPS: ent.properties.pop(key, None) + @staticmethod + def sort_by_creation_date(entity: t.Union[Scenario, Cycle]): + return entity.creation_date + def get_scenarios_for_owner(self, owner_id: str): cycles_scenarios: t.List[t.Union[Scenario, Cycle]] = [] with self.lock: @@ -685,7 +691,7 @@ def get_scenarios_for_owner(self, owner_id: str): cycles_scenarios.extend(scenarios_cycle) elif isinstance(entity, Scenario): cycles_scenarios.append(entity) - return cycles_scenarios + return sorted(cycles_scenarios, key=_GuiCoreContext.sort_by_creation_date) def get_data_node_history(self, datanode: DataNode, id: str): if (