Skip to content
Merged
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
14 changes: 8 additions & 6 deletions scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down
8 changes: 8 additions & 0 deletions scripts/test_build_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading