Răsfoiți Sursa

When no cycle are used in the scenario configs ... (#1360)

* When no cycle are used in the scenario configs
do not show Cycle* and primary as column for filtering
resolves #1343

* fab's comment and fix

---------

Co-authored-by: Fred Lefévère-Laoide <Fred.Lefevere-Laoide@Taipy.io>
Fred Lefévère-Laoide 11 luni în urmă
părinte
comite
033a7c8c4c
3 a modificat fișierele cu 33 adăugiri și 30 ștergeri
  1. 2 2
      taipy/gui_core/_GuiCoreLib.py
  2. 30 27
      taipy/gui_core/_adapters.py
  3. 1 1
      taipy/gui_core/_context.py

+ 2 - 2
taipy/gui_core/_GuiCoreLib.py

@@ -75,8 +75,8 @@ class _GuiCore(ElementLibrary):
                 "show_dialog": ElementProperty(PropertyType.boolean, True),
                 __SEL_SCENARIOS_PROP: ElementProperty(PropertyType.dynamic_list),
                 "multiple": ElementProperty(PropertyType.boolean, False),
-                "filter": ElementProperty(_GuiCoreScenarioFilter, _GuiCoreScenarioFilter.DEFAULT),
-                "sort": ElementProperty(_GuiCoreScenarioSort, _GuiCoreScenarioSort.DEFAULT),
+                "filter": ElementProperty(_GuiCoreScenarioFilter, "*"),
+                "sort": ElementProperty(_GuiCoreScenarioSort, "*"),
                 "show_search": ElementProperty(PropertyType.boolean, True),
             },
             inner_properties={

+ 30 - 27
taipy/gui_core/_adapters.py

@@ -257,28 +257,21 @@ def _get_datanode_property(attr: str):
 
 
 class _GuiCoreScenarioProperties(_TaipyBase):
-    _SC_TYPES = {
-        "Config id": "string",
-        "Label": "string",
-        "Creation date": "date",
-        "Cycle label": "string",
-        "Cycle start": "date",
-        "Cycle end": "date",
-        "Primary": "boolean",
-        "Tags": "string",
+    _SC_PROPS: t.Dict[str, t.Dict[str, t.Union[str, bool]]] = {
+        "Config id": {"attr": "config_id", "type": "string"},
+        "Label": {"attr": "name", "type": "string"},
+        "Creation date": {"attr": "creation_date", "type": "date"},
+        "Cycle label": {"attr": "cycle.name", "type": "string", "for_cycle": True},
+        "Cycle start": {"attr": "cycle.start", "type": "date", "for_cycle": True},
+        "Cycle end": {"attr": "cycle.end", "type": "date", "for_cycle": True},
+        "Primary": {"attr": "is_primary", "type": "boolean", "for_cycle": True},
+        "Tags": {"attr": "tags", "type": "string"},
     }
-    __SC_LABELS = {
-        "Config id": "config_id",
-        "Creation date": "creation_date",
-        "Label": "name",
-        "Cycle label": "cycle.name",
-        "Cycle start": "cycle.start",
-        "Cycle end": "cycle.end",
-        "Primary": "is_primary",
-        "Tags": "tags",
+    __DN_PROPS = {
+        "Up to date": {"attr": "is_up_to_date", "type": "boolean"},
+        "Valid": {"attr": "is_valid", "type": "boolean"},
+        "Last edit date": {"attr": "last_edit_date", "type": "date"},
     }
-    __DN_TYPES = {"Up to date": "boolean", "Valid": "boolean", "Last edit date": "date"}
-    __DN_LABELS = {"Up to date": "is_up_to_date", "Valid": "is_valid", "Last edit date": "last_edit_date"}
     __ENUMS = None
 
     @staticmethod
@@ -288,14 +281,17 @@ class _GuiCoreScenarioProperties(_TaipyBase):
     @staticmethod
     def get_type(attr: str):
         if prop := _get_datanode_property(attr):
-            return _GuiCoreScenarioProperties.__DN_TYPES.get(prop, "any")
-        return _GuiCoreScenarioProperties._SC_TYPES.get(attr, "any")
+            return _GuiCoreScenarioProperties.__DN_PROPS.get(prop, {"type": "any"}).get("type", "any")
+        return _GuiCoreScenarioProperties._SC_PROPS.get(attr, {"type": "any"}).get("type", "any")
 
     @staticmethod
     def get_col_name(attr: str):
         if prop := _get_datanode_property(attr):
-            return f'{attr.split(".")[0]}.{_GuiCoreScenarioProperties.__DN_LABELS.get(prop, prop)}'
-        return _GuiCoreScenarioProperties.__SC_LABELS.get(attr, attr)
+            return (
+                attr.split(".")[0]
+                + f'.{_GuiCoreScenarioProperties.__DN_PROPS.get(prop, {"attr": prop}).get("attr", prop)}'
+            )
+        return _GuiCoreScenarioProperties._SC_PROPS.get(attr, {"attr": attr}).get("attr", attr)
 
     @staticmethod
     @abstractmethod
@@ -326,7 +322,9 @@ class _GuiCoreScenarioProperties(_TaipyBase):
             if _GuiCoreScenarioProperties.__ENUMS is None and self.full_desc():
                 _GuiCoreScenarioProperties.__ENUMS = {
                     "Config id": [c for c in Config.scenarios.keys() if c != "default"],
-                    "Tags": [t for s in Config.scenarios.values() for t in s.properties.get("authorized_tags", [])],
+                    "Tags": list(
+                        {t for s in Config.scenarios.values() for t in s.properties.get("authorized_tags", [])}
+                    ),
                 }
             return json.dumps(
                 [
@@ -341,7 +339,11 @@ class _GuiCoreScenarioProperties(_TaipyBase):
 
 
 class _GuiCoreScenarioFilter(_GuiCoreScenarioProperties):
-    DEFAULT = list(_GuiCoreScenarioProperties._SC_TYPES.keys())
+    DEFAULT = list(_GuiCoreScenarioProperties._SC_PROPS.keys())
+    DEFAULT_NO_CYCLE = [
+        p[0]
+        for p in filter(lambda prop: not prop[1].get("for_cycle", False), _GuiCoreScenarioProperties._SC_PROPS.items())
+    ]
 
     @staticmethod
     def full_desc():
@@ -353,7 +355,8 @@ class _GuiCoreScenarioFilter(_GuiCoreScenarioProperties):
 
     @staticmethod
     def get_default_list():
-        return _GuiCoreScenarioFilter.DEFAULT
+        has_cycle = next(filter(lambda sc: sc.frequency is not None, Config.scenarios.values()), None) is not None
+        return _GuiCoreScenarioFilter.DEFAULT if has_cycle else _GuiCoreScenarioFilter.DEFAULT_NO_CYCLE
 
 
 class _GuiCoreScenarioSort(_GuiCoreScenarioProperties):

+ 1 - 1
taipy/gui_core/_context.py

@@ -304,8 +304,8 @@ class _GuiCoreContext(CoreEventConsumerBase):
             for fd in filters:
                 col = fd.get("col", "")
                 is_datanode_prop = _get_datanode_property(col) is not None
-                col = _GuiCoreScenarioProperties.get_col_name(col)
                 col_type = _GuiCoreScenarioProperties.get_type(col)
+                col = _GuiCoreScenarioProperties.get_col_name(col)
                 val = fd.get("value")
                 action = fd.get("action", "")
                 if isinstance(val, str) and col_type == "date":