From 9dc842490ca0c71f1809ae83b5c3ffdb366aeaee Mon Sep 17 00:00:00 2001 From: Jhonatan Garrido-Lecca <10247583+garridolecca@users.noreply.github.com> Date: Tue, 1 Dec 2026 15:01:07 -0800 Subject: [PATCH] Registry checks: accept tab rows ("tabs") in panels RustGIS's panel.rs lists "tabs" among its panel KINDS and checks a tab row's options, default and value as a dropdown's; build.py refused it as an unknown kind. Check tabs as a choice, with a test. Co-authored-by: Isaac --- scripts/build.py | 14 ++++++++------ scripts/test_build_panel.py | 8 ++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/scripts/build.py b/scripts/build.py index ad08f7e..2b4ad51 100644 --- a/scripts/build.py +++ b/scripts/build.py @@ -76,7 +76,9 @@ PERMISSIONS = {"edit", "files", "network"} PARAM_KINDS = {"layer", "vectorLayer", "polygonLayer", "pointLayer", "field", "numericField", "number", "text", "choice", "bool", "file"} # RustGIS's (crates/plugins/src/panel.rs, KINDS): a form since #1539, a pick since #1643. -PANEL_KINDS = {"text", "checkbox", "slider", "button", "tree", "form", "choice", "date", "range", "pick"} +PANEL_KINDS = {"text", "checkbox", "slider", "button", "tree", "form", "choice", "tabs", "date", "range", "pick"} +# A tab row is a dropdown drawn as tabs (panel.rs: options, default and value as a choice's). +CHOICE_KINDS = {"choice", "tabs"} # What a pick asks for on the map: a point (when unset) or a box. PICK_SHAPES = {"point", "box"} # A dropdown's (choice's) most options, and the longest option id. @@ -524,10 +526,10 @@ def check_panel_item(item: dict, kind: str, where: str) -> None: elif kind != "tree" and item.get("search", False): problem(f"{where}: search is for trees") options = item.get("options", []) - if kind != "choice" and "options" in item: - problem(f"{where}: options are for dropdowns (choice)") + if kind not in CHOICE_KINDS and "options" in item: + problem(f"{where}: options are for dropdowns and tab rows (choice, tabs)") ids: list[str] = [] - if kind == "choice": + if kind in CHOICE_KINDS: if not isinstance(options, list) or len(options) > PANEL_CHOICES: problem(f"{where}: a dropdown's options are a list of at most {PANEL_CHOICES:,}") return @@ -548,11 +550,11 @@ def check_panel_item(item: dict, kind: str, where: str) -> None: default = item["default"] if kind == "checkbox" and not isinstance(default, bool): problem(f"{where}: a checkbox's default is true or false") - elif kind == "choice" and default not in ids: + elif kind in CHOICE_KINDS and default not in ids: problem(f"{where}: a dropdown's default is the id of one of its options") elif kind == "date" and not panel_date(default): problem(f"{where}: a date's default is a date written YYYY-MM-DD") - elif kind not in ("checkbox", "choice", "date"): + elif kind not in ("checkbox", "date") and kind not in CHOICE_KINDS: problem(f"{where}: only checkboxes, sliders, ranges, dropdowns and dates have a default") return if not isinstance(item.get("steps", False), bool): diff --git a/scripts/test_build_panel.py b/scripts/test_build_panel.py index d1f474b..420c269 100644 --- a/scripts/test_build_panel.py +++ b/scripts/test_build_panel.py @@ -45,6 +45,14 @@ def test_declared_text_boundary(self): def test_unknown_kind_still_rejected(self): self.assertTrue(self.check({"kind": "forms", "id": "config"})) + def test_tabs_are_checked_as_a_choice(self): + tabs = {"kind": "tabs", "id": "section", "command": "refresh", "default": "a", + "options": [{"id": "a", "label": "A"}, {"id": "b", "label": "B"}]} + self.assertEqual(self.check(tabs), []) + for change in ({"default": "missing"}, {"options": [{"id": "a"}, {"id": "a"}]}, {"options": "a"}): + with self.subTest(change=change): + self.assertTrue(self.check({**tabs, **change})) + def test_unknown_fields_follow_host_serde_behavior(self): # Fields are supplied in command replies, not PanelItemDecl. Serde ignores unknown # declaration keys; the 64-field/256-choice runtime limits do not apply here.