Deploy AIOS web (React glide grid + FastAPI slice)
Browse files- RELEASES.json +1 -1
- VERSION +1 -1
- api/odoo_relational.py +480 -37
- api/routes_admin.py +500 -15
- api/routes_customers.py +66 -11
- api/routes_geo.py +314 -58
- api/routes_nav.py +88 -4
- platform/aios_grid.py +371 -8
- platform/core/route_system.py +35 -0
- platform/core/schema_overlay.py +368 -0
- platform/harness/measure_filter.py +16 -9
- platform/harness/semantic.py +16 -16
- platform/model/metrics/sales.yml +149 -149
- web/src/automation/AutomationDetail.tsx +205 -69
- web/src/customer-grid/ColumnMenu.tsx +18 -1
- web/src/customer-grid/CustomerGrid.tsx +22 -25
- web/src/customer-grid/DatePicker.tsx +184 -38
- web/src/customer-grid/MapView.tsx +574 -88
- web/src/customer-grid/RouteNav.tsx +710 -49
- web/src/customer-grid/Toolbar.tsx +52 -0
- web/src/customer-grid/ViewSidebar.tsx +630 -38
- web/src/customer-grid/iconShapes.ts +28 -0
- web/src/customer-grid/mapProjection.ts +188 -0
- web/src/customer-grid/routeLinks.ts +63 -1
- web/src/customer-grid/theme.ts +15 -1
- web/src/filter-kit/FieldsHidePanel.tsx +206 -45
- web/src/filter-kit/FilterBuilderPanel.tsx +39 -1
- web/src/settings/DatabasePermsPane.tsx +74 -1
- web/src/settings/ManageDatabase.tsx +516 -0
- web/src/settings/PermsEditor.tsx +15 -0
- web/src/settings/SettingsModal.tsx +28 -0
- web/src/settings/permsModel.ts +116 -1
- web/src/shell/NavExtras.tsx +82 -34
- web/src/styles/wave46/chrome.css +72 -0
- web/src/styles/wave46/field-panels.css +439 -0
- web/src/styles/wave46/manage-database.css +111 -0
- web/src/styles/wave46/map-panels.css +475 -0
- web/src/styles/wave46/rail-select.css +271 -0
- web/src/styles/wave46/route-print.css +185 -0
- web/src/styles/wave46/schema-viewer.css +260 -0
RELEASES.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
{
|
| 2 |
-
"current": "
|
| 3 |
"releases": [
|
| 4 |
{
|
| 5 |
"version": "v59",
|
|
|
|
| 1 |
{
|
| 2 |
+
"current": "d8a1a5d",
|
| 3 |
"releases": [
|
| 4 |
{
|
| 5 |
"version": "v59",
|
VERSION
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
d8a1a5d
|
api/odoo_relational.py
CHANGED
|
@@ -24,8 +24,11 @@ wave 28 β that was the FIRST candidate and its own derivation REJECTED it for
|
|
| 24 |
budget by 0.6%; the prose was written before the number lost, and two sibling files said it too).
|
| 25 |
The four tables together are
|
| 26 |
17.81 MB in one `user_tables` document β real, bounded, and booked: the per-table row-key split
|
| 27 |
-
is D-87's next increment. β ORDER LINES REMAIN OUT
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
β THE EXCLUDED CHANNEL IS NOW A COLUMN, NOT A DELETION. `core.odoo.EXCLUDE_PARTNER_NAMES` puts
|
| 31 |
GIFTWARE DEALS (partner 6369 β the Amazon channel) outside WHOLESALE scope, and the old tables
|
|
@@ -351,24 +354,106 @@ def invoice_fields():
|
|
| 351 |
"options": ["not_paid", "partial", "in_payment", "paid", "reversed"]},
|
| 352 |
{"key": "move_type", "label": "Document", "type": "select", "source": "overlay",
|
| 353 |
"default": False, "options": ["out_invoice", "out_refund"]},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 354 |
_scope_field(),
|
| 355 |
# β THE RECIPROCAL HALF (owner item 2, 2026-08-09). DERIVED (`on` declared), exactly like
|
| 356 |
# its twin, so the engine owns the cell and no human can edit a relation Odoo decided.
|
| 357 |
-
#
|
| 358 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 359 |
#
|
| 360 |
-
#
|
| 361 |
-
#
|
| 362 |
-
#
|
| 363 |
-
#
|
| 364 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 365 |
#
|
| 366 |
-
# β THE
|
| 367 |
-
#
|
| 368 |
-
#
|
| 369 |
-
#
|
| 370 |
-
#
|
| 371 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 372 |
# β DEBT D-88, closed 2026-08-09. `invoice_origin` carries the ORDER NAME an invoice was
|
| 373 |
# raised from, and the mirror did not sync it until this wave β so order->invoice was a
|
| 374 |
# two-hop join through 963,783 `account_move_line` rows and wave 27 shipped no link at all.
|
|
@@ -456,7 +541,21 @@ def order_line_fields():
|
|
| 456 |
scope every wholesale metric in this product uses.
|
| 457 |
|
| 458 |
MEASURED on the mirror 2026-08-12: **254,189 lines in scope** of 256,810 (the 2,621 excluded
|
| 459 |
-
sit on draft/sent/cancelled orders).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 460 |
but `done` stays in the option list because it is in the SCOPE, and a filter offering only
|
| 461 |
what happens to be stored today goes stale the first time an order is marked done.
|
| 462 |
|
|
@@ -609,7 +708,9 @@ def product_fields():
|
|
| 609 |
"source": "overlay", "default": True},
|
| 610 |
# β SOURCE-BACKED (read-through) β the product-grain half of "compute all of the data in
|
| 611 |
# Odoo". It names a governed TOPIC + METRIC KEY and one grouped query answers every SKU;
|
| 612 |
-
# `sales_lines` holds
|
|
|
|
|
|
|
| 613 |
{"key": "sales_ytd", "label": "Sales YTD", "type": "rollup", "source": "overlay",
|
| 614 |
"default": True, "agg": "sum",
|
| 615 |
"rollup": {"source": {"topic": "sales_lines", "measure": "revenue",
|
|
@@ -820,6 +921,16 @@ def module_link_fields(key):
|
|
| 820 |
`ut_odoo_invoices` answers the ALL-CHANNELS question (the Amazon partner alone is 75% of the
|
| 821 |
raw balance), so the same key would carry two numbers 4x apart depending on which pass ran
|
| 822 |
last. That is the second-source-for-one-fact defect this module refuses everywhere else.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 823 |
* **NO LINK ON `product_data` AT ALL** β see `_PRODUCT_LINK_BLOCKER` below for what it would
|
| 824 |
take. Declaring one anyway is the worst available outcome: `ut_odoo_order_lines` EXISTS in
|
| 825 |
the store with zero rows, so `_resolve_table` finds it, nothing is refused, no
|
|
@@ -863,8 +974,16 @@ def module_link_fields(key):
|
|
| 863 |
#: a measurement rather than an empty function.
|
| 864 |
#:
|
| 865 |
#: WHAT ODOO SAYS (read from `ir.model.fields`, not assumed): `product.product` declares NO
|
| 866 |
-
#: relation to `res.partner`
|
| 867 |
-
#:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 868 |
#: and a product is `sale.order.line`, which carries `order_partner_id` (many2one to `res.partner`)
|
| 869 |
#: and `product_id` (many2one to `product.product`), both stored. So the relation is real, Odoo
|
| 870 |
#: does not declare it directly, and it is exactly TWO HOPS.
|
|
@@ -872,33 +991,302 @@ def module_link_fields(key):
|
|
| 872 |
#: WHY NEITHER HOP IS EXPRESSIBLE TODAY:
|
| 873 |
#: 1. `relation_cells` resolves a link with ONE index lookup β `_linked_rows_by_join(target, on)`
|
| 874 |
#: probed by the source row's single `from` value. There is no `through` leg in the bag
|
| 875 |
-
#: vocabulary (`core.user_tables._clean_link` accepts table/on/from/inverse/reciprocal/
|
| 876 |
-
#: and no two-hop branch in the
|
| 877 |
-
#:
|
| 878 |
-
#:
|
| 879 |
-
#:
|
| 880 |
-
#:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 881 |
#: 3. `inverse` cannot carry the other end either. It reads the source row's STORED cell, and a
|
| 882 |
#: registry module stores no rows here: its grid is assembled per render from the tenant pool,
|
| 883 |
#: so the reciprocal cell a pool row would need is precisely the projection being computed.
|
| 884 |
#:
|
| 885 |
-
#: WHAT IT WOULD TAKE (
|
| 886 |
#: (a) a `through` leg on the link bag, resolved as a two-hop join in `automation_engine`;
|
| 887 |
#: (b) bridge rows served from the DuckDB MIRROR rather than the `user_tables` document, because
|
| 888 |
-
#: order lines are read-through on purpose and materialising them is the thing R6 forbade
|
|
|
|
|
|
|
|
|
|
| 889 |
#: (c) a cap-and-report story for the fan-out under standing rule 1 β the widest customer's
|
| 890 |
#: basket and the widest product's buyer list both need a display cap plus a
|
| 891 |
-
#: `limit_report`-shaped account of it, never a silent truncation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 892 |
_PRODUCT_LINK_BLOCKER = {
|
| 893 |
"subject": "product_data / customer_data: Products ordered and Customers who ordered",
|
| 894 |
"effect": "unresolvable",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 895 |
"cause": "the only relation Odoo declares between a partner and a product runs through "
|
| 896 |
-
"sale.order.line (order_partner_id then product_id), which is two hops
|
| 897 |
-
"relation engine resolves
|
| 898 |
-
"
|
| 899 |
-
|
| 900 |
-
|
| 901 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 902 |
}
|
| 903 |
|
| 904 |
|
|
@@ -1002,13 +1390,62 @@ def read_invoices(cur, excluded=None, open_only=False):
|
|
| 1002 |
# reaches the operator as a bare 500. This is the exact class `columns()` was written for: the
|
| 1003 |
# link degrades to blank for one sync cycle instead of refusing the whole spawn.
|
| 1004 |
have = columns(cur, "account_move")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1005 |
sql = ("SELECT id, name, partner_id, partner_name, invoice_date, invoice_date_due, "
|
| 1006 |
" amount_untaxed_signed, amount_residual_signed, payment_state, move_type, "
|
| 1007 |
-
f" {_col(have, 'invoice_origin', chr(39) + chr(39))} "
|
| 1008 |
-
f"
|
|
|
|
|
|
|
| 1009 |
out = []
|
| 1010 |
for r in cur.execute(sql).fetchall():
|
| 1011 |
-
(mid, name, pid, pname, inv_date, due, untaxed, residual, pay_state, mtype, origin
|
|
|
|
| 1012 |
scope = _in_scope(pid, excluded)
|
| 1013 |
if open_only and not scope:
|
| 1014 |
continue
|
|
@@ -1025,6 +1462,12 @@ def read_invoices(cur, excluded=None, open_only=False):
|
|
| 1025 |
"payment_state": str(pay_state or ""),
|
| 1026 |
"move_type": str(mtype or ""),
|
| 1027 |
"origin_order": str(origin or "").strip(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1028 |
"wholesale_scope": scope,
|
| 1029 |
})
|
| 1030 |
return out
|
|
|
|
| 24 |
budget by 0.6%; the prose was written before the number lost, and two sibling files said it too).
|
| 25 |
The four tables together are
|
| 26 |
17.81 MB in one `user_tables` document β real, bounded, and booked: the per-table row-key split
|
| 27 |
+
is D-87's next increment. β ORDER LINES REMAIN OUT β 259,306 rows on the mirror
|
| 28 |
+
(2026-08-29 re-measure, of which 256,593 sit in the confirmed scope), and 63.9 MB / 2.57 s per
|
| 29 |
+
copy when the count was 256,810 on 2026-08-12. The weight is still the reason and the reason has
|
| 30 |
+
not moved; only the count has. They are answered by the read-through rollup, which never copies a
|
| 31 |
+
row.
|
| 32 |
|
| 33 |
β THE EXCLUDED CHANNEL IS NOW A COLUMN, NOT A DELETION. `core.odoo.EXCLUDE_PARTNER_NAMES` puts
|
| 34 |
GIFTWARE DEALS (partner 6369 β the Amazon channel) outside WHOLESALE scope, and the old tables
|
|
|
|
| 354 |
"options": ["not_paid", "partial", "in_payment", "paid", "reversed"]},
|
| 355 |
{"key": "move_type", "label": "Document", "type": "select", "source": "overlay",
|
| 356 |
"default": False, "options": ["out_invoice", "out_refund"]},
|
| 357 |
+
# ββ W46-T42 β THE SALES AGENT, AND IT IS AN **ID** JOIN AT THIS GRAIN. The ticket said
|
| 358 |
+
# otherwise and the correction is the load-bearing part of this block, so it is recorded
|
| 359 |
+
# here rather than left to be re-derived. `account_invoice_line_agent` (the OCA commission
|
| 360 |
+
# module's line table) carries `invoice_id`, `agent_id`, `agent_name`, `amount`, `settled`
|
| 361 |
+
# and holds 311,140 rows on this box's mirror β so an invoice's agent arrives as a real
|
| 362 |
+
# foreign key, not as a display string.
|
| 363 |
+
# β `AGENT_NAME_KEY`'s warning does NOT transfer here, and reading it as if it did is the
|
| 364 |
+
# easy mistake. That note says joining `customer_data` to the agents table through
|
| 365 |
+
# `JOIN_KEY` would "link EVERY CUSTOMER TO ITSELF" β true, because both sides of THAT join
|
| 366 |
+
# are `res.partner` rows in the partner namespace and the customer grain mirrors no agent
|
| 367 |
+
# id at all. This grain is `account.move`, its join column is `agent_id` (never
|
| 368 |
+
# `partner_id`), and the id it carries is the AGENT's, so the self-join that warning
|
| 369 |
+
# forbids is not available here to make.
|
| 370 |
+
# MEASURED 2026-08-30 over `read_invoices`' default projection (31,418 posted customer
|
| 371 |
+
# invoices): 20,849 carry at least one agent (66.4%), 10,569 carry none, and of the
|
| 372 |
+
# 20,849, exactly 20,299 carry ONE agent while 550 carry more than one. 16 distinct
|
| 373 |
+
# `agent_id` values appear and all 16 resolve to a `res_partner` row.
|
| 374 |
+
# β STANDING RULE 1 β THE 550 ARE DESCRIBED, NEVER TRUNCATED. The names are joined with
|
| 375 |
+
# ", " exactly as `modules/customers` joins a multi-agent customer's, so a second agent is
|
| 376 |
+
# visible rather than silently dropped behind the first. This is the same posture
|
| 377 |
+
# `module_link_fields`' `agent_link` already documents for the customer grain.
|
| 378 |
+
{"key": "agent", "label": "Sales agent", "type": "text", "source": "overlay",
|
| 379 |
+
"default": True,
|
| 380 |
+
"description": "The commissioned agent or agents on this invoice, from Odoo's "
|
| 381 |
+
"account.invoice.line.agent lines. Measured 2026-08-30: filled on 20,849 "
|
| 382 |
+
"of 31,418 invoices; 550 of those carry more than one agent and every "
|
| 383 |
+
"name is listed, joined with a comma, never capped to the first."},
|
| 384 |
+
# β BLANK ON THE 550 ON PURPOSE, AND THE `description` SAYS SO. A single id cannot stand
|
| 385 |
+
# for two agents, and `min(agent_id)` would render a plausible, wrong, clickable answer.
|
| 386 |
+
{"key": AGENT_JOIN_KEY, "label": "Odoo agent id", "type": "int", "source": "overlay",
|
| 387 |
+
"default": False,
|
| 388 |
+
"description": "The res.partner id of this invoice's agent. Measured 2026-08-30: filled "
|
| 389 |
+
"on the 20,299 invoices with exactly one agent, and deliberately blank on "
|
| 390 |
+
"the 550 with more than one, because one id cannot name two agents. The "
|
| 391 |
+
"Sales agent column lists all of them."},
|
| 392 |
_scope_field(),
|
| 393 |
# β THE RECIPROCAL HALF (owner item 2, 2026-08-09). DERIVED (`on` declared), exactly like
|
| 394 |
# its twin, so the engine owns the cell and no human can edit a relation Odoo decided.
|
| 395 |
+
# ββ W46-T42 β `customer_link` IS **RESTORED**, RE-POINTED AT `customer_data`, AND THE
|
| 396 |
+
# BLOCKER THAT DELETED IT IS RECORDED AS EXPIRED RATHER THAN SILENTLY OVERWRITTEN. The
|
| 397 |
+
# old note is rewritten here because leaving "DELETED, and the alternative REFUSED IN
|
| 398 |
+
# WRITING" standing beside a live field is a file asserting two opposite things at once.
|
| 399 |
+
#
|
| 400 |
+
# WHAT HAPPENED FIRST (W33-T43 / AMENDMENT A2, 2026-08-09): the column pointed at
|
| 401 |
+
# `ut_odoo_customers`, which W33-T44 retired (R2: one identity per subject). A2 ruled
|
| 402 |
+
# OPTION 2 - retire both twins, drop the three link columns, keep every data column - so
|
| 403 |
+
# the grid lost the click-through and nothing else, and A2 refused the obvious repair in
|
| 404 |
+
# writing on TWO grounds: re-pointing the bag at `customer_data` needed
|
| 405 |
+
# `core/user_tables.py::_clean_link`'s `ut_` prefix test relaxed, and even then
|
| 406 |
+
# `automation_engine::compute_relation_cells` resolved out of the `user_tables` document
|
| 407 |
+
# alone and returned `{}` - every gate green, every cell empty.
|
| 408 |
#
|
| 409 |
+
# β BOTH GROUNDS HAVE SINCE EXPIRED, verified in source at HEAD 2026-08-30:
|
| 410 |
+
# 1. `core/user_tables.py::LINKABLE_MODULE_KEYS` is `('customer_data','product_data')`
|
| 411 |
+
# and `::is_linkable_target` admits a key by EXACT MEMBERSHIP in that tuple
|
| 412 |
+
# (W41-T15 / R9 / C5, 2026-08-24). The prefix test A2 refused to relax is gone; it
|
| 413 |
+
# was replaced by an allowlist rather than widened, which is the safer shape A2
|
| 414 |
+
# wanted and could not have.
|
| 415 |
+
# 2. `automation_engine.py::_resolve_table` returns the stored document only for a key
|
| 416 |
+
# IN the store (`hit = (store or {}).get(key); if hit is not None: return hit`).
|
| 417 |
+
# `customer_data` is a registry module and not a `ut_` key, so that lookup MISSES and
|
| 418 |
+
# it falls through to `_module_table(..., want_rows=True)`, which returns real pool
|
| 419 |
+
# rows. β That is the exact OPPOSITE of the read-through case that blocks the product
|
| 420 |
+
# link two hundred lines below, and the difference is worth holding on to: a registry
|
| 421 |
+
# module has rows the engine can reach, a read-through `ut_` grain has a stored
|
| 422 |
+
# definition with none. One resolves, one blanks.
|
| 423 |
#
|
| 424 |
+
# ββ AND THE JOIN KEY IS `pid`, NOT `partner_id`. The obvious choice is the broken one and
|
| 425 |
+
# the full reasoning is at `CUSTOMER_JOIN_FROM` below - `partner_id` is declared `derived`
|
| 426 |
+
# on `customer_data`, so `modules/customer_data.pool` never puts it on the row and the
|
| 427 |
+
# relational pass reads the RAW pool dict. β THE OLD NOTE HERE CLAIMED "`customer_data`
|
| 428 |
+
# now carries `partner_id` too, so both ends of the join still exist", AND THAT SENTENCE
|
| 429 |
+
# WAS FALSE - it is deleted rather than left as a trap. MEASURED against the real pool
|
| 430 |
+
# 2026-08-30 (`customer_data.pool()`, 3,649 rows, 222 s): joining on `pid` matches 31,400
|
| 431 |
+
# of 31,418 invoices across 1,843 distinct partners; joining on `partner_id` matches
|
| 432 |
+
# ZERO, because not one pool row carries that key at all. The negative control is the
|
| 433 |
+
# whole proof: the wrong key does not resolve badly, it resolves to nothing, forever,
|
| 434 |
+
# with nothing red.
|
| 435 |
+
# β The 18 unmatched invoices are partners the pool's own population does not hold; their
|
| 436 |
+
# cell is blank, which is the honest outcome for a link and not a defect.
|
| 437 |
+
{"key": "customer_link", "label": "Customer record", "type": "link", "source": "overlay",
|
| 438 |
+
"default": False,
|
| 439 |
+
"description": "The customer record behind this invoice. Measured 2026-08-30: resolves "
|
| 440 |
+
"on 31,400 of 31,418 invoices, across 1,843 customers.",
|
| 441 |
+
"link": {"table": "customer_data", "on": CUSTOMER_JOIN_FROM, "from": JOIN_KEY}},
|
| 442 |
+
# ββ W46-T42 β THE AGENT RECORD, AND IT JOINS ON THE **ID** HERE. `module_link_fields`'
|
| 443 |
+
# `agent_link` on `customer_data` joins on the NAME because that grain mirrors no agent
|
| 444 |
+
# id; this grain does, so this is the stronger key and the bag is otherwise modelled on
|
| 445 |
+
# that one. MEASURED 2026-08-30: 16 distinct `agent_id` values appear on invoices, all 16
|
| 446 |
+
# are rows in `ut_odoo_agents` (which holds 19), so ZERO dangle - and `read_agents` is
|
| 447 |
+
# what makes that true, since its UNION leg selects `agent_id FROM
|
| 448 |
+
# account_invoice_line_agent`. The two populations degrade together as well: when the
|
| 449 |
+
# commission table is absent from the mirror both this column and that union leg fall
|
| 450 |
+
# back to blank rather than to a half-populated link.
|
| 451 |
+
{"key": "agent_link", "label": "Agent record", "type": "link", "source": "overlay",
|
| 452 |
+
"default": False,
|
| 453 |
+
"description": "The agent record for this invoice, matched on the Odoo agent id. Blank "
|
| 454 |
+
"on the 550 invoices carrying more than one agent, where the Sales agent "
|
| 455 |
+
"column lists every name instead.",
|
| 456 |
+
"link": {"table": AGENTS_KEY, "on": AGENT_JOIN_KEY, "from": AGENT_JOIN_KEY}},
|
| 457 |
# β DEBT D-88, closed 2026-08-09. `invoice_origin` carries the ORDER NAME an invoice was
|
| 458 |
# raised from, and the mirror did not sync it until this wave β so order->invoice was a
|
| 459 |
# two-hop join through 963,783 `account_move_line` rows and wave 27 shipped no link at all.
|
|
|
|
| 541 |
scope every wholesale metric in this product uses.
|
| 542 |
|
| 543 |
MEASURED on the mirror 2026-08-12: **254,189 lines in scope** of 256,810 (the 2,621 excluded
|
| 544 |
+
sit on draft/sent/cancelled orders). RE-MEASURED 2026-08-29 (W46-T41): **256,593 in scope** of
|
| 545 |
+
259,306, spread over 32,973 distinct orders, and 256,502 of the in-scope lines carry a
|
| 546 |
+
`product_id`. β THE 2026-08-12 FIGURES ARE KEPT BESIDE THE NEW ONES RATHER THAN OVERWRITTEN,
|
| 547 |
+
because every other number in this docstring was taken on that same pass β quietly restating
|
| 548 |
+
the total would leave the fractional-quantity count below reading as if it were wrong.
|
| 549 |
+
|
| 550 |
+
β AND THE MIRROR IS RECONCILED, not merely counted (standing rule 8). Live Odoo holds 258,893
|
| 551 |
+
in-scope lines today, so the mirror is 2,300 short (0.89%). That gap is SYNC LAG and not a
|
| 552 |
+
defect: `_sync_state` records the `sale_order_line` write_date cursor at 2026-08-14 22:45:25
|
| 553 |
+
and 5,966 in-scope lines have been written in Odoo since. Bounded to the recorded id watermark
|
| 554 |
+
(`last_id` = 278,926) the two populations tie β 252,006 on the mirror against 252,005 live, a
|
| 555 |
+
delta of ONE row (0.0004%). The bound is the point: an unbounded compare puts rows Odoo has and
|
| 556 |
+
the mirror has not yet seen on one side of the equals sign, which is not a like-for-like
|
| 557 |
+
population and would report a false 2,300-row hole. The machine-readable form of all of this is
|
| 558 |
+
`_ORDER_LINE_GRAIN` below. Every line in scope is on a `sale` order β zero `done` β
|
| 559 |
but `done` stays in the option list because it is in the SCOPE, and a filter offering only
|
| 560 |
what happens to be stored today goes stale the first time an order is marked done.
|
| 561 |
|
|
|
|
| 708 |
"source": "overlay", "default": True},
|
| 709 |
# β SOURCE-BACKED (read-through) β the product-grain half of "compute all of the data in
|
| 710 |
# Odoo". It names a governed TOPIC + METRIC KEY and one grouped query answers every SKU;
|
| 711 |
+
# `sales_lines` holds 259,306 rows that are never copied into this table
|
| 712 |
+
# (mirror, 2026-08-29; the count read 256,810 on 2026-08-12 and the line is dated
|
| 713 |
+
# rather than quietly restated, because the argument is the WEIGHT, not the total).
|
| 714 |
{"key": "sales_ytd", "label": "Sales YTD", "type": "rollup", "source": "overlay",
|
| 715 |
"default": True, "agg": "sum",
|
| 716 |
"rollup": {"source": {"topic": "sales_lines", "measure": "revenue",
|
|
|
|
| 921 |
`ut_odoo_invoices` answers the ALL-CHANNELS question (the Amazon partner alone is 75% of the
|
| 922 |
raw balance), so the same key would carry two numbers 4x apart depending on which pass ran
|
| 923 |
last. That is the second-source-for-one-fact defect this module refuses everywhere else.
|
| 924 |
+
* ββ **D-492, CHECKED BEFORE ANYTHING NEW WAS ADDED (W46-T42, 2026-08-30) AND IT STILL
|
| 925 |
+
HOLDS.** The register says two links a prior instruction DECLARED were never built. Read off
|
| 926 |
+
this function at HEAD, both are confirmed absent and neither was faked to close the row:
|
| 927 |
+
`customer_data` returns `invoices`, `orders` and `agent_link` and no *"Products ordered"*;
|
| 928 |
+
`product_data` returns `[]` unconditionally (the `if str(key or "") != "customer_data"`
|
| 929 |
+
guard on the first line), so *"Customers who ordered"* is never declared at all. They are
|
| 930 |
+
the SAME two-hop blocker, not two independent misses, and `_PRODUCT_LINK_BLOCKER` below is
|
| 931 |
+
their single stated reason. β A link declared to close D-492 without that blocker lifted
|
| 932 |
+
would render permanently blank with no `limit_report`, which is worse than the open row.
|
| 933 |
+
|
| 934 |
* **NO LINK ON `product_data` AT ALL** β see `_PRODUCT_LINK_BLOCKER` below for what it would
|
| 935 |
take. Declaring one anyway is the worst available outcome: `ut_odoo_order_lines` EXISTS in
|
| 936 |
the store with zero rows, so `_resolve_table` finds it, nothing is refused, no
|
|
|
|
| 974 |
#: a measurement rather than an empty function.
|
| 975 |
#:
|
| 976 |
#: WHAT ODOO SAYS (read from `ir.model.fields`, not assumed): `product.product` declares NO
|
| 977 |
+
#: COMMERCIAL relation to `res.partner`. β THE SENTENCE HERE USED TO SAY "no relation to
|
| 978 |
+
#: `res.partner` AT ALL", and D-492 is right that this was OVERSTATED β corrected 2026-08-30 in
|
| 979 |
+
#: W46-T42 rather than left standing, because a claim a reader can falsify in one grep costs the
|
| 980 |
+
#: surviving conclusion its authority. `product.product` inherits `mail.thread`, so
|
| 981 |
+
#: `message_partner_ids` (the generic FOLLOWERS relation) is a genuine many2many to `res.partner`
|
| 982 |
+
#: on this model. It is not a customer relation: a follower is whoever subscribed to the record's
|
| 983 |
+
#: chatter, it answers no question about who ORDERED the product, and joining through it would
|
| 984 |
+
#: mint a "customers who ordered" column populated by subscriptions. The other partner-shaped
|
| 985 |
+
#: field is `seller_ids`, an unstored one2many to `product.supplierinfo`, which is VENDORS. So the
|
| 986 |
+
#: evidence changes and THE CONCLUSION SURVIVES: the one declared path between a customer
|
| 987 |
#: and a product is `sale.order.line`, which carries `order_partner_id` (many2one to `res.partner`)
|
| 988 |
#: and `product_id` (many2one to `product.product`), both stored. So the relation is real, Odoo
|
| 989 |
#: does not declare it directly, and it is exactly TWO HOPS.
|
|
|
|
| 991 |
#: WHY NEITHER HOP IS EXPRESSIBLE TODAY:
|
| 992 |
#: 1. `relation_cells` resolves a link with ONE index lookup β `_linked_rows_by_join(target, on)`
|
| 993 |
#: probed by the source row's single `from` value. There is no `through` leg in the bag
|
| 994 |
+
#: vocabulary (`core.user_tables._clean_link` accepts table/on/from/inverse/reciprocal/via/
|
| 995 |
+
#: single/filter, and returns None for anything mis-shaped) and no two-hop branch in the
|
| 996 |
+
#: engine. β `via` IS NOT A TABLE HOP and reading it as one is the easy mistake here:
|
| 997 |
+
#: `_clean_via` demands topic/source_dim/target_dim/target_key/scope_key/measure and refuses
|
| 998 |
+
#: unless the dims belong to a semantic topic, and `automation_engine` reads a link bag's
|
| 999 |
+
#: `via` ZERO times.
|
| 1000 |
+
#: 2. ββ THE BRIDGE HAS ROWS. THIS ITEM SAID THE OPPOSITE UNTIL W46-T41 MEASURED IT, and the
|
| 1001 |
+
#: correction changes what the missing piece IS. `routes_odoo_tables.GRID_SOURCES` already
|
| 1002 |
+
#: serves `ut_odoo_order_lines` from the DuckDB mirror by SQL (`sale_order_line` joined to
|
| 1003 |
+
#: `sale_order` on the confirmed scope), `routes_tables._read_through_rows` renders it, and
|
| 1004 |
+
#: `routes_tables._register_mirror` publishes that reader as `core.perm_scope._MIRROR_READER`.
|
| 1005 |
+
#: MEASURED 2026-08-29: 256,593 in-scope rows, 256,502 of them carrying a `product_id`
|
| 1006 |
+
#: (`_ORDER_LINE_GRAIN` below). What is empty is the `user_tables` DOCUMENT, not the system:
|
| 1007 |
+
#: `row_limit` answers 0 and `plan()` builds zero python rows, by design and on purpose.
|
| 1008 |
+
#: So the absence is A CALLER, not data β `automation_engine._resolve_table` returns the
|
| 1009 |
+
#: stored doc first (`hit = (store or {}).get(key); if hit is not None: return hit, None`) and
|
| 1010 |
+
#: carries no mirror branch at all, while `_linked_rows_by_join` indexes only
|
| 1011 |
+
#: `(linked or {}).get("rows")`.
|
| 1012 |
+
#: 2b. ββ AND THAT IS WHY DECLARING THE LINK ANYWAY IS THE WORST AVAILABLE OUTCOME, in the
|
| 1013 |
+
#: words of the engine's own docstring. `relation_cells` says of its second return value:
|
| 1014 |
+
#: *"A link whose target cannot be reached is SKIPPED β¦ and a `limit_report`-shaped dict says
|
| 1015 |
+
#: which field, why, and what to do β¦ a link with no matching records and a link that could
|
| 1016 |
+
#: not be resolved BOTH leave the key out of `cells`, and only this list tells them apart."*
|
| 1017 |
+
#: The function was rewritten expressly to end the silent blank. For a read-through target it
|
| 1018 |
+
#: still produces one, and the reason is small and exact: the refusal predicate is
|
| 1019 |
+
#: `if linked is None`, and `_resolve_table` hands back a stored definition, which is never
|
| 1020 |
+
#: None. So this link lands in the ONE case the docstring says cannot happen β no `cells` key
|
| 1021 |
+
#: AND no `limits` entry, indistinguishable from "no matching records" by the very
|
| 1022 |
+
#: discriminator that docstring names. The guard is not missing; it is KEYED ON THE WRONG
|
| 1023 |
+
#: SENTINEL. Standing rule 1's second sentence fails on that path, which is the whole reason
|
| 1024 |
+
#: the link is refused here rather than declared.
|
| 1025 |
#: 3. `inverse` cannot carry the other end either. It reads the source row's STORED cell, and a
|
| 1026 |
#: registry module stores no rows here: its grid is assembled per render from the tenant pool,
|
| 1027 |
#: so the reciprocal cell a pool row would need is precisely the projection being computed.
|
| 1028 |
#:
|
| 1029 |
+
#: WHAT IT WOULD TAKE (four parts, one ticket, and none of them in this file):
|
| 1030 |
#: (a) a `through` leg on the link bag, resolved as a two-hop join in `automation_engine`;
|
| 1031 |
#: (b) bridge rows served from the DuckDB MIRROR rather than the `user_tables` document, because
|
| 1032 |
+
#: order lines are read-through on purpose and materialising them is the thing R6 forbade.
|
| 1033 |
+
#: β The reader for (b) ALREADY EXISTS and is already registered; what (b) needs is the door
|
| 1034 |
+
#: into it β a read-through branch in `_resolve_table`, the one symbol the other two both
|
| 1035 |
+
#: pass through;
|
| 1036 |
#: (c) a cap-and-report story for the fan-out under standing rule 1 β the widest customer's
|
| 1037 |
#: basket and the widest product's buyer list both need a display cap plus a
|
| 1038 |
+
#: `limit_report`-shaped account of it, never a silent truncation;
|
| 1039 |
+
#: (d) β THE CHEAPEST OF THE FOUR AND THE ONE THAT STOPS THE SILENT FAILURE ON ITS OWN: re-key
|
| 1040 |
+
#: `relation_cells`' refusal off `linked is None` and onto "resolved a document whose rows
|
| 1041 |
+
#: are structurally absent". The signal is already written and already durable β
|
| 1042 |
+
#: `_ensure_table_inplace` in this module stamps `readThrough: True` on exactly those
|
| 1043 |
+
#: definitions, and `core.user_tables.materialises` reads it. Landing (d) first converts
|
| 1044 |
+
#: every premature link at a read-through grain from a permanently blank column into a
|
| 1045 |
+
#: `limit_report` that names the field and the fix.
|
| 1046 |
+
#:
|
| 1047 |
+
#: ββ W46-T41 β IT IS THREE HOPS FOR AN INVOICE, NOT TWO, AND THE WAVE'S OWN DOCUMENTS SAY TWO.
|
| 1048 |
+
#: Recorded because the correction outlives the ticket. `ut_odoo_order_lines` IS `sale.order.line`,
|
| 1049 |
+
#: which hangs off `sale.order` and NOT off `account.move`, so the two readings differ:
|
| 1050 |
+
#: β’ ORDER -> LINE -> PRODUCT is genuinely two hops, and it is what C5's own wording describes
|
| 1051 |
+
#: ("keyed by `order_id` and `product_id`"). This grain can serve it the day (a)+(b) land.
|
| 1052 |
+
#: β’ INVOICE -> LINE -> PRODUCT through THIS grain is THREE hops, and the first of them is a
|
| 1053 |
+
#: free-text hint rather than a key: `invoice_fields`' existing `order_link` matches
|
| 1054 |
+
#: `origin_order` (Odoo's `invoice_origin`, a NAME) to `order_no`. MEASURED 2026-08-29:
|
| 1055 |
+
#: `invoice_origin` is filled on 10,706 of 31,418 posted customer invoices (34.1%), of which
|
| 1056 |
+
#: 10,683 match a `sale_order.name`; `_sync_state` shows the `account_move.cols.invoice_origin`
|
| 1057 |
+
#: backfill still in phase `running` at 35,000 of 236,811 rows since 2026-08-15. So the first
|
| 1058 |
+
#: hop of that route is a third populated and its own backfill is unfinished.
|
| 1059 |
+
#: β THE HONEST TWO-HOP ROUTE FOR AN INVOICE IS THE OTHER GRAIN, and it is named here rather than
|
| 1060 |
+
#: built because it is blocked by the identical engine gap. `account_move_line` carries `move_id`,
|
| 1061 |
+
#: `product_id` AND `sale_line_id`, so INVOICE -> `ut_odoo_gl_lines` -> PRODUCT is a real two hops
|
| 1062 |
+
#: (measured 2026-08-29: 477,852 of 511,167 posted customer invoice lines carry a `product_id`,
|
| 1063 |
+
#: across 30,164 of 31,418 invoices). Two things stand in the way: `ut_odoo_gl_lines` is the OTHER
|
| 1064 |
+
#: read-through grain, so items 2 and 2b above apply to it unchanged, and `gl_line_fields` does not
|
| 1065 |
+
#: expose `product_id` today. A future ticket takes that route; this one does not.
|
| 1066 |
_PRODUCT_LINK_BLOCKER = {
|
| 1067 |
"subject": "product_data / customer_data: Products ordered and Customers who ordered",
|
| 1068 |
"effect": "unresolvable",
|
| 1069 |
+
# β THE `cause` CHANGED IN W46-T41 AND THE OLD ONE WAS WRONG IN A LOAD-BEARING WAY. It read
|
| 1070 |
+
# "the bridge grain ut_odoo_order_lines is read-through by design and stores no rows to walk",
|
| 1071 |
+
# which is true of the `user_tables` DOCUMENT and false of the system: the rows are measured,
|
| 1072 |
+
# served and registered elsewhere. A blocker that blames missing DATA sends the next lane to
|
| 1073 |
+
# materialise 256,593 rows, which is the one thing R6 forbade; a blocker that names the missing
|
| 1074 |
+
# CALLER sends it to the three symbols in `blocked_by`.
|
| 1075 |
+
# β ASCII ONLY IN THESE VALUES. They travel into `plan()`'s `limits` report and can reach a
|
| 1076 |
+
# client, where standing rule 2 forbids an em dash or an en dash.
|
| 1077 |
"cause": "the only relation Odoo declares between a partner and a product runs through "
|
| 1078 |
+
"sale.order.line (order_partner_id then product_id), which is two hops, and the "
|
| 1079 |
+
"relation engine resolves ONE. The bridge rows are NOT missing: measured 2026-08-29 "
|
| 1080 |
+
"on the DuckDB mirror, ut_odoo_order_lines holds 256,593 in-scope rows of which "
|
| 1081 |
+
"256,502 carry a product_id, and they are ALREADY SERVED to the grid by "
|
| 1082 |
+
"routes_odoo_tables.GRID_SOURCES through routes_tables._read_through_rows, whose "
|
| 1083 |
+
"reader is registered as core.perm_scope._MIRROR_READER. What is absent is a caller: "
|
| 1084 |
+
"automation_engine._resolve_table returns the stored user_tables document first and "
|
| 1085 |
+
"carries no read-through branch, and the link vocabulary in "
|
| 1086 |
+
"core.user_tables._clean_link has no `through` key (its `via` is a semantic-topic "
|
| 1087 |
+
"measure route, not a table hop, and the engine never reads it). So a link declared "
|
| 1088 |
+
"today fails SILENTLY rather than loudly, and the engine's own docstring says why "
|
| 1089 |
+
"that is the worst outcome available: relation_cells promises that an unreachable "
|
| 1090 |
+
"target is skipped WITH a limit_report, because a link with no matching records and "
|
| 1091 |
+
"a link that could not be resolved both leave the key out of cells and only that "
|
| 1092 |
+
"report tells them apart. Its refusal is keyed on `linked is None`, and a stored "
|
| 1093 |
+
"definition is never None, so this link lands in the one case that docstring says "
|
| 1094 |
+
"cannot happen: no cell, no limit report, and a permanently blank column that looks "
|
| 1095 |
+
"configured. The guard is not missing, it is keyed on the wrong sentinel. That is "
|
| 1096 |
+
"why the link is refused here instead of declared",
|
| 1097 |
+
"recommendation": "four parts, one ticket, and neither file is this one. (a) "
|
| 1098 |
+
"platform/core/user_tables.py::_clean_link accepts a `through` key in the "
|
| 1099 |
+
"link vocabulary and validates its target the way it validates `table`. "
|
| 1100 |
+
"(b) aios-web/api/automation_engine.py opens the door and walks the second "
|
| 1101 |
+
"hop: give _resolve_table a read-through branch that calls the registered "
|
| 1102 |
+
"mirror reader instead of returning an empty stored document, then teach "
|
| 1103 |
+
"relation_cells to resolve table -> through -> target. (c) both halves need "
|
| 1104 |
+
"a fan-out display cap that is REPORTED through limit_report rather than "
|
| 1105 |
+
"applied silently, per standing rule 1. (d) cheapest and independently "
|
| 1106 |
+
"worth doing FIRST: re-key relation_cells' refusal from `linked is None` "
|
| 1107 |
+
"onto `the resolved document stores no rows here`, which the readThrough "
|
| 1108 |
+
"stamp already written by odoo_relational._ensure_table_inplace answers, so "
|
| 1109 |
+
"that a premature link at a read-through grain reports instead of "
|
| 1110 |
+
"blanking. Until these land, keep refusing the link: a blank configured "
|
| 1111 |
+
"column is worse than an absent one",
|
| 1112 |
+
# β THE BLOCKING SYMBOLS AS DATA, NOT PROSE, so `verify_odoo_relational.py` can read the
|
| 1113 |
+
# source of each one and go RED the day the blocking property stops holding. A refusal whose
|
| 1114 |
+
# reason has silently expired is precisely the defect that tripwire exists to prevent.
|
| 1115 |
+
# β `_resolve_table` is in the list although the prose leads with the other two, and that is
|
| 1116 |
+
# deliberate: it is the door BOTH of them go through, so a mirror branch landing there would
|
| 1117 |
+
# unblock this ticket while `relation_cells` and `_clean_link` still read exactly as today.
|
| 1118 |
+
"blocked_by": ("platform/core/user_tables.py::_clean_link",
|
| 1119 |
+
"aios-web/api/automation_engine.py::_resolve_table",
|
| 1120 |
+
"aios-web/api/automation_engine.py::relation_cells"),
|
| 1121 |
+
"rows_exist_at": "aios-web/api/routes_odoo_tables.py::GRID_SOURCES['ut_odoo_order_lines'] -> "
|
| 1122 |
+
"routes_tables._read_through_rows (the same reader is registered as "
|
| 1123 |
+
"core.perm_scope._MIRROR_READER by routes_tables._register_mirror)",
|
| 1124 |
+
}
|
| 1125 |
+
|
| 1126 |
+
#: ββ W46-T42 β THE DBA / TRADE NAME IS **REFUSED**, AND THE REFUSAL IS DATA SO IT CANNOT ROT.
|
| 1127 |
+
#: The ticket asked the invoices grid to carry "the DBA or trade name populated from Odoo".
|
| 1128 |
+
#: ββ THAT PHRASE HAS **TWO** READINGS IN THIS PRODUCT AND BOTH ARE REFUSED, WHICH IS WHY THIS
|
| 1129 |
+
#: IS RECORDED RATHER THAN SUMMARISED AS "no such field". Answering only one of them would leave
|
| 1130 |
+
#: the next reader certain the other was simply missed.
|
| 1131 |
+
#:
|
| 1132 |
+
#: READING 1 - A TRADE NAME (doing-business-as, the legal sense). It does not exist here. The
|
| 1133 |
+
#: mirror's `res_partner` columns, read from the table rather than assumed (2026-08-30), are:
|
| 1134 |
+
#: id, name, team_id, team_name, city, state_id, state_name, country_id, country_name, active,
|
| 1135 |
+
#: write_date, agent_id, agent_ids, agent, salesman_as_agent, customer_rank, street, street2,
|
| 1136 |
+
#: zip, email, phone, mobile, website, vat, ref. No `commercial_company_name`, no tenant `x_`
|
| 1137 |
+
#: field, nothing else name-shaped.
|
| 1138 |
+
#: β `ref` IS THE TRAP. It is filled on 5,333 of 5,334 partners, which is exactly the coverage a
|
| 1139 |
+
#: trade-name column would want, and it is a SEQUENCE NUMBER: measured samples ('The Floral
|
| 1140 |
+
#: Supply', '1'), ('Floral Supply', '2'), ('Administrator', '3'). Shipping it under a "Trade name"
|
| 1141 |
+
#: header is C5's non-clickable lookalike in its purest form - a column that looks populated on
|
| 1142 |
+
#: 99.98% of rows, passes every gate, and answers a different question from the one its header
|
| 1143 |
+
#: asks.
|
| 1144 |
+
#:
|
| 1145 |
+
#: READING 2 - "DBA" AS THIS PRODUCT ALREADY SPELLS IT, i.e. the BRAND. `aios_grid_fields.json`
|
| 1146 |
+
#: declares `dba` as a `select` over Fisch / Royal / Both, and `modules/customer_data._dba_attrs`
|
| 1147 |
+
#: computes it from a customer's CONFIRMED ORDERS over the pool's own 24-month window, with
|
| 1148 |
+
#: GIFTWARE DEALS deliberately excluded and blank meaning "no brand attributable in 24 months".
|
| 1149 |
+
#: That definition is not reachable at this grain and must not be approximated at it:
|
| 1150 |
+
#: * `account_move` in the mirror carries NO `team_id` at all (measured 2026-08-30 - its 13
|
| 1151 |
+
#: columns are id, name, partner_id, partner_name, invoice_date, invoice_date_due,
|
| 1152 |
+
#: amount_untaxed_signed, amount_residual_signed, payment_state, move_type, state,
|
| 1153 |
+
#: invoice_origin, write_date), so an invoice cannot state its own brand;
|
| 1154 |
+
#: * `res_partner.team_name` IS mirrored and IS filled (4,753 of 5,334 partners: Fisch 3,546,
|
| 1155 |
+
#: Royal 1,206, Giftware Deals 1, blank 581) - and it is the PARTNER'S ASSIGNED SALES TEAM,
|
| 1156 |
+
#: a single current assignment, not a 24-month order-derived attribution. Joining it in under
|
| 1157 |
+
#: the label "DBA" would put a SECOND definition of one fact under one name, which is the
|
| 1158 |
+
#: defect `module_link_fields`' own "NO ROLLUPS" note refuses for `ar_outstanding` and which
|
| 1159 |
+
#: this module refuses everywhere else.
|
| 1160 |
+
#: β ASCII ONLY IN THESE VALUES, like `_PRODUCT_LINK_BLOCKER` above: they travel into `plan()`'s
|
| 1161 |
+
#: `limits` report and can reach a client, where standing rule 2 forbids an em dash or an en dash.
|
| 1162 |
+
_DBA_NAME_BLOCKER = {
|
| 1163 |
+
"subject": "ut_odoo_invoices: the DBA or trade name",
|
| 1164 |
+
"effect": "unavailable",
|
| 1165 |
+
"measured_on": "2026-08-30",
|
| 1166 |
+
"cause": "the phrase has two readings in this product and neither is available at the "
|
| 1167 |
+
"invoice grain. (1) A TRADE NAME does not exist in the mirror: res_partner's "
|
| 1168 |
+
"columns are id, name, team_id, team_name, city, state_id, state_name, country_id, "
|
| 1169 |
+
"country_name, active, write_date, agent_id, agent_ids, agent, salesman_as_agent, "
|
| 1170 |
+
"customer_rank, street, street2, zip, email, phone, mobile, website, vat, ref, and "
|
| 1171 |
+
"none of them is a doing-business-as or commercial name. `ref` is the only column "
|
| 1172 |
+
"with the right SHAPE and it is not the right VALUE: filled on 5,333 of 5,334 "
|
| 1173 |
+
"partners and holding a sequence number, measured samples ('The Floral Supply', "
|
| 1174 |
+
"'1'), ('Floral Supply', '2'), ('Administrator', '3'), so shipping it under a Trade "
|
| 1175 |
+
"name header would look populated on 99.98% of rows while answering a different "
|
| 1176 |
+
"question from the one its label asks. (2) DBA AS THIS PRODUCT ALREADY DEFINES IT "
|
| 1177 |
+
"is the brand Fisch / Royal / Both, computed by modules/customer_data._dba_attrs "
|
| 1178 |
+
"from a customer's confirmed orders over a 24 month window with Giftware Deals "
|
| 1179 |
+
"excluded. account_move carries no team_id in the mirror at all, so an invoice "
|
| 1180 |
+
"cannot state its own brand, and res_partner.team_name (filled on 4,753 of 5,334 "
|
| 1181 |
+
"partners) is the partner's current assigned sales team rather than that 24 month "
|
| 1182 |
+
"attribution - a second definition of one fact under one name. Both readings are "
|
| 1183 |
+
"therefore REFUSED rather than approximated",
|
| 1184 |
+
"rejected_lookalike": "res_partner.ref for reading 1, res_partner.team_name for reading 2",
|
| 1185 |
+
"recommendation": "reading 1 is a CONNECTOR change and neither file is this one: "
|
| 1186 |
+
"platform/harness/datastore.py's res_partner sync adds "
|
| 1187 |
+
"commercial_company_name (Odoo's own computed commercial name) or a tenant "
|
| 1188 |
+
"x_ trade-name field to its column list and backfills it, after which "
|
| 1189 |
+
"invoice_fields can carry the column with a measured fill rate exactly as "
|
| 1190 |
+
"the agent columns beside it do. Reading 2 needs account_move.team_id "
|
| 1191 |
+
"mirrored AND a ruling on whether an invoice's brand is the order-derived "
|
| 1192 |
+
"24 month attribution or the document's own team, because those are two "
|
| 1193 |
+
"different numbers and only one may carry the name. Until then the honest "
|
| 1194 |
+
"answer on this grid is the partner's legal name, which the Customer "
|
| 1195 |
+
"column already carries, and the customer link beside it reaches the "
|
| 1196 |
+
"customer_data row where `dba` already lives",
|
| 1197 |
+
"fence": "platform/harness/datastore.py (the res_partner and account_move column lists), "
|
| 1198 |
+
"not aios-web/api/odoo_relational.py",
|
| 1199 |
+
}
|
| 1200 |
+
|
| 1201 |
+
#: ββ W46-T42 β WHAT THE FOUR NEW INVOICE COLUMNS ACTUALLY FILL, AS COUNTS, KEPT AS DATA.
|
| 1202 |
+
#: The ticket's `done-when` says each new column's fill rate is stated as a count and never as
|
| 1203 |
+
#: "populated", and `_ORDER_LINE_GRAIN` above is the shape this file already uses for exactly
|
| 1204 |
+
#: that: prose rots and cannot be asserted, a dict can be re-derived by the gate.
|
| 1205 |
+
#: β THE `customer_link` NUMBER IS THE EXPENSIVE ONE AND IT IS RECORDED RATHER THAN RE-TAKEN ON
|
| 1206 |
+
#: EVERY RUN, DELIBERATELY. Proving it needs `modules/customer_data.pool()`, measured 222 s here
|
| 1207 |
+
#: and 444 s in `verify_odoo_relational::_prove_customer_address` (the gate already pays that once
|
| 1208 |
+
#: and runs it last for the reason stated there). Paying it a second time would roughly double a
|
| 1209 |
+
#: 482 s gate to prove a number that moves with the pool, not with this file. So the gate asserts
|
| 1210 |
+
#: this record, re-derives the CHEAP half from the mirror, and the pool leg is taken by hand when
|
| 1211 |
+
#: the join key changes - which is the only thing that can invalidate it.
|
| 1212 |
+
#: β AND THE NEGATIVE CONTROL IS PART OF THE RECORD, not a footnote: the same measurement run on
|
| 1213 |
+
#: `partner_id` (the obvious, wrong key) matched ZERO of 31,418. A link that resolves and a link
|
| 1214 |
+
#: keyed on a column the pool does not carry are indistinguishable from a count alone, so both
|
| 1215 |
+
#: arms are stored.
|
| 1216 |
+
_INVOICE_COLUMN_FILL = {
|
| 1217 |
+
"subject": "ut_odoo_invoices: the four columns added by W46-T42",
|
| 1218 |
+
"measured_on": "2026-08-30",
|
| 1219 |
+
"mirror": "platform/data/store/royal.duckdb",
|
| 1220 |
+
"population": "read_invoices' default projection: state = 'posted' AND move_type IN "
|
| 1221 |
+
"('out_invoice','out_refund') AND partner_id IS NOT NULL",
|
| 1222 |
+
"invoices_total": 31418,
|
| 1223 |
+
# --- agent + agent_id, from account_invoice_line_agent (311,140 lines) -------------------
|
| 1224 |
+
"agent_named": 20849,
|
| 1225 |
+
"agent_id_filled": 20299,
|
| 1226 |
+
"agent_multi": 550,
|
| 1227 |
+
"agent_absent": 10569,
|
| 1228 |
+
"agent_distinct_ids": 16,
|
| 1229 |
+
"agent_ids_resolving_in_agents_table": 16,
|
| 1230 |
+
# --- customer_link, against the REAL customer_data pool ----------------------------------
|
| 1231 |
+
"customer_pool_rows": 3649,
|
| 1232 |
+
"customer_link_matched": 31400,
|
| 1233 |
+
"customer_link_distinct_partners": 1843,
|
| 1234 |
+
"customer_link_unmatched": 18,
|
| 1235 |
+
"customer_link_join_key": "customer_data.pid <- ut_odoo_invoices.partner_id",
|
| 1236 |
+
"customer_link_wrong_key_matched": 0,
|
| 1237 |
+
"customer_link_wrong_key": "customer_data.partner_id (declared derived, never on a pool row)",
|
| 1238 |
+
"customer_link_method": "modules.customer_data.pool() at HEAD, 222 s, joined to "
|
| 1239 |
+
"read_invoices(cur) on the raw pool dict - the same dict "
|
| 1240 |
+
"automation_engine._module_table keys its rows off",
|
| 1241 |
+
# --- agent_link, which needs no second population: its target is ut_odoo_agents ----------
|
| 1242 |
+
"agent_link_matched": 20299,
|
| 1243 |
+
"agent_link_blank_multi": 550,
|
| 1244 |
+
}
|
| 1245 |
+
|
| 1246 |
+
#: ββ THE GRAIN'S SIZE, RECONCILED TO AN INDEPENDENT ORACLE AND KEPT AS DATA (standing rule 8:
|
| 1247 |
+
#: a number that does not tie to Odoo does not ship). Prose rots and cannot be asserted; this dict
|
| 1248 |
+
#: is what `verify_odoo_relational.py` reads, and the delta below is re-derived from its own two
|
| 1249 |
+
#: operands there, so the three numbers cannot drift apart unnoticed.
|
| 1250 |
+
#:
|
| 1251 |
+
#: β THE WATERMARK BOUND IS THE MEASUREMENT, not a convenience. Compared unbounded, the mirror is
|
| 1252 |
+
#: 2,300 rows (0.89%) under live, and every one of those rows is a line Odoo has written since the
|
| 1253 |
+
#: mirror's own sync cursor β so the unbounded compare answers a question about SYNC LAG while
|
| 1254 |
+
#: appearing to answer one about correctness. Bounded to the id the mirror actually claims to have
|
| 1255 |
+
#: reached, the two are the same population and they tie to a single row.
|
| 1256 |
+
#: β The oracle is a READ-ONLY `search_count` over live Odoo XML-RPC (standing rule 4). Nothing
|
| 1257 |
+
#: here writes, creates, unlinks or posts, and re-taking these numbers must not either.
|
| 1258 |
+
_ORDER_LINE_GRAIN = {
|
| 1259 |
+
"subject": "ut_odoo_order_lines (sale.order.line) row count",
|
| 1260 |
+
"measured_on": "2026-08-29",
|
| 1261 |
+
"mirror": "platform/data/store/royal.duckdb",
|
| 1262 |
+
"oracle": "live Odoo XML-RPC search_count on sale.order.line, read-only",
|
| 1263 |
+
"scope": "sale_order.state in (sale, done), the scope every wholesale metric here uses",
|
| 1264 |
+
"mirror_rows_total": 259306,
|
| 1265 |
+
"mirror_rows_in_scope": 256593,
|
| 1266 |
+
"mirror_rows_in_scope_with_product": 256502,
|
| 1267 |
+
"mirror_orders_with_a_line": 32973,
|
| 1268 |
+
"mirror_orders_in_scope": 33093,
|
| 1269 |
+
"mirror_orphan_lines": 0,
|
| 1270 |
+
# THE TIE, and the two operands it is computed from, so the gate can re-derive it.
|
| 1271 |
+
"watermark_field": "_sync_state.sale_order_line.last_id",
|
| 1272 |
+
"watermark_last_id": 278926,
|
| 1273 |
+
"mirror_rows_at_watermark": 252006,
|
| 1274 |
+
"live_rows_at_watermark": 252005,
|
| 1275 |
+
"delta_at_watermark": 1,
|
| 1276 |
+
# THE UNBOUNDED PICTURE, reported rather than hidden, because 0.89% looks like a defect until
|
| 1277 |
+
# its cause is stated (standing rule 1: a limit is reported with its cause, never enforced or
|
| 1278 |
+
# buried in silence).
|
| 1279 |
+
"live_rows_in_scope_unbounded": 258893,
|
| 1280 |
+
"live_rows_in_scope_unbounded_with_product": 258800,
|
| 1281 |
+
"lag_rows": 2300,
|
| 1282 |
+
"lag_cause": "mirror sync lag, not a data defect: _sync_state records the sale_order_line "
|
| 1283 |
+
"write_date cursor at 2026-08-14 22:45:25 (synced 2026-08-15) and 5,966 "
|
| 1284 |
+
"in-scope lines have been written in Odoo since that cursor",
|
| 1285 |
+
"reconciliation": "bounded by the recorded id watermark 278,926, the mirror holds 252,006 "
|
| 1286 |
+
"lines and live Odoo holds 252,005, a delta of 1 row (0.0004%). The bound "
|
| 1287 |
+
"is required rather than tidy: an unbounded compare puts rows Odoo has and "
|
| 1288 |
+
"the mirror has not yet seen on one side of the equals sign, which is not a "
|
| 1289 |
+
"like-for-like population",
|
| 1290 |
}
|
| 1291 |
|
| 1292 |
|
|
|
|
| 1390 |
# reaches the operator as a bare 500. This is the exact class `columns()` was written for: the
|
| 1391 |
# link degrades to blank for one sync cycle instead of refusing the whole spawn.
|
| 1392 |
have = columns(cur, "account_move")
|
| 1393 |
+
# ββ W46-T42 β THE COMMISSION TABLE IS GUARDED AS A **TABLE**, NOT AS A COLUMN, and this is
|
| 1394 |
+
# `read_agents`' guard reused verbatim rather than a second pattern invented beside it.
|
| 1395 |
+
# `columns()` answers the missing-COLUMN case (a backfill that has not run yet);
|
| 1396 |
+
# `account_invoice_line_agent` is an OCA module entity that a mirror hydrated from an older
|
| 1397 |
+
# seed snapshot may not carry AT ALL, and a SELECT naming an absent table is a DuckDB Binder
|
| 1398 |
+
# error. This reader runs inside `plan()`, so that error would fail the WHOLE eight-table
|
| 1399 |
+
# spawn and reach the operator as a bare 500 (D-107's shape).
|
| 1400 |
+
# β DEGRADE, NEVER REFUSE: without the table the two agent columns read blank for every row,
|
| 1401 |
+
# which is an honestly empty column rather than no spawn.
|
| 1402 |
+
has_comm = bool(columns(cur, "account_invoice_line_agent"))
|
| 1403 |
+
if has_comm:
|
| 1404 |
+
# β `count(DISTINCT agent_id)` rather than `count(*)`: the commission table is a LINE
|
| 1405 |
+
# grain, so one agent on a six-line invoice appears six times and a raw count would call
|
| 1406 |
+
# every such invoice multi-agent and blank its id.
|
| 1407 |
+
# β `ORDER BY agent_name` IS NOT COSMETIC AND IT IS NOT OPTIONAL. Without it DuckDB's
|
| 1408 |
+
# `string_agg` returns the names in whatever order the group happened to arrive in, and
|
| 1409 |
+
# MEASURED on this mirror 2026-08-30 the SAME PAIR came back both ways across three
|
| 1410 |
+
# invoices: 'Anna, Martin Pasternak' twice, then 'Martin Pasternak, Anna'. `agent` is a
|
| 1411 |
+
# filterable, sortable TEXT column, so an unordered cell means a filter leaf matches on
|
| 1412 |
+
# one spawn and not the next, a view sorted on it reshuffles between refreshes, and every
|
| 1413 |
+
# re-spawn rewrites those 550 cells while nothing about the data changed. A fill-rate
|
| 1414 |
+
# count cannot see any of that, which is exactly why the ordering lives in the SQL.
|
| 1415 |
+
# β `count(DISTINCT agent_id)` rather than `count(*)`: the commission table is a LINE
|
| 1416 |
+
# grain, so one agent on a six-line invoice appears six times and a raw count would call
|
| 1417 |
+
# every such invoice multi-agent and blank its id. MEASURED: 0 of its 311,140 rows carry
|
| 1418 |
+
# a NULL `agent_id` or a blank `agent_name`, so DISTINCT's NULL-skipping cannot silently
|
| 1419 |
+
# move an invoice between the two arms here.
|
| 1420 |
+
agent_cols = " ag.n_agents, ag.one_agent, ag.agent_names "
|
| 1421 |
+
agent_join = (
|
| 1422 |
+
" LEFT JOIN (SELECT invoice_id, "
|
| 1423 |
+
" count(DISTINCT agent_id) AS n_agents, "
|
| 1424 |
+
" min(agent_id) AS one_agent, "
|
| 1425 |
+
" string_agg(DISTINCT agent_name, ', ' ORDER BY agent_name) "
|
| 1426 |
+
" AS agent_names "
|
| 1427 |
+
" FROM account_invoice_line_agent WHERE invoice_id IS NOT NULL "
|
| 1428 |
+
" GROUP BY invoice_id) ag ON ag.invoice_id = account_move.id ")
|
| 1429 |
+
else:
|
| 1430 |
+
agent_cols = " NULL AS n_agents, NULL AS one_agent, '' AS agent_names "
|
| 1431 |
+
agent_join = ""
|
| 1432 |
+
# ββ THE PROJECTION STAYS UNQUALIFIED AND THE JOIN CARRIES THE ONLY TABLE NAME, WHICH IS A
|
| 1433 |
+
# FIXTURE CONTRACT RATHER THAN A STYLE CHOICE. `verify_odoo_relational.FixtureCursor`
|
| 1434 |
+
# DISPATCHES ON THE SELECT CLAUSE (`head.startswith("SELECT id, name, partner_id")`), because
|
| 1435 |
+
# `read_bills` reads this same table with a different projection and the opposite move types.
|
| 1436 |
+
# Aliasing the columns to `am.` changes that head, the fixture recognises nothing, and the
|
| 1437 |
+
# reader returns an empty list on every box without a mirror - a CONFIDENT EMPTY, which is the
|
| 1438 |
+
# exact failure D-131 exists to prevent. Measured: it took six fixture legs red.
|
| 1439 |
sql = ("SELECT id, name, partner_id, partner_name, invoice_date, invoice_date_due, "
|
| 1440 |
" amount_untaxed_signed, amount_residual_signed, payment_state, move_type, "
|
| 1441 |
+
f" {_col(have, 'invoice_origin', chr(39) + chr(39))}, "
|
| 1442 |
+
f"{agent_cols}"
|
| 1443 |
+
f"FROM account_move {agent_join}"
|
| 1444 |
+
f"WHERE {where} AND partner_id IS NOT NULL")
|
| 1445 |
out = []
|
| 1446 |
for r in cur.execute(sql).fetchall():
|
| 1447 |
+
(mid, name, pid, pname, inv_date, due, untaxed, residual, pay_state, mtype, origin,
|
| 1448 |
+
n_agents, one_agent, agent_names) = r
|
| 1449 |
scope = _in_scope(pid, excluded)
|
| 1450 |
if open_only and not scope:
|
| 1451 |
continue
|
|
|
|
| 1462 |
"payment_state": str(pay_state or ""),
|
| 1463 |
"move_type": str(mtype or ""),
|
| 1464 |
"origin_order": str(origin or "").strip(),
|
| 1465 |
+
# β THE NAMES ARE NEVER CAPPED (standing rule 1) and the ID IS BLANK when there are
|
| 1466 |
+
# two, which is the honest pair: the text column carries everything Odoo knows and the
|
| 1467 |
+
# join column carries an answer only where one exists.
|
| 1468 |
+
"agent": str(agent_names or ""),
|
| 1469 |
+
AGENT_JOIN_KEY: (int(one_agent) if (int(n_agents or 0) == 1 and one_agent)
|
| 1470 |
+
else ""),
|
| 1471 |
"wholesale_scope": scope,
|
| 1472 |
})
|
| 1473 |
return out
|
api/routes_admin.py
CHANGED
|
@@ -35,6 +35,7 @@ from fastapi import APIRouter, Body, Depends, Response
|
|
| 35 |
|
| 36 |
import core.platform_admin as platform_admin # wave 19 R3 β the /settings chrome flag
|
| 37 |
import core.registry as registry
|
|
|
|
| 38 |
import core.store as store
|
| 39 |
|
| 40 |
from deps import Session, err, perms, require_session, users
|
|
@@ -995,16 +996,91 @@ def _metric_fields(key):
|
|
| 995 |
be a second copy of a constant two features already share
|
| 996 |
[[constant-two-features-share]], and `verify_fields_contract` gates that the client keys its
|
| 997 |
real measure columns off the same one.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 998 |
"""
|
|
|
|
|
|
|
| 999 |
try:
|
| 1000 |
import aios_grid
|
| 1001 |
import harness.semantic as semantic
|
| 1002 |
topic = semantic.topic_for_grid(key)
|
| 1003 |
if not topic:
|
| 1004 |
-
|
| 1005 |
-
|
| 1006 |
-
|
| 1007 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1008 |
out = []
|
| 1009 |
for m in offer or ():
|
| 1010 |
if not isinstance(m, dict):
|
|
@@ -1016,7 +1092,17 @@ def _metric_fields(key):
|
|
| 1016 |
# would read "Metric - Gross profit" while the grid column read "Gross margin $", and an
|
| 1017 |
# admin cannot hide what they cannot recognise. ASCII hyphen, exactly as the owner wrote
|
| 1018 |
# it β CLAUDE.md rule 2 bars a dash in copy that reaches a screen.
|
| 1019 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1020 |
mtype = m.get("type")
|
| 1021 |
out.append({"key": f"{aios_grid.MEASURE_FIELD_PREFIX}{mkey}",
|
| 1022 |
"label": f"Metric - {label}",
|
|
@@ -1025,7 +1111,47 @@ def _metric_fields(key):
|
|
| 1025 |
"shared": False,
|
| 1026 |
"filterable": False,
|
| 1027 |
"metric": True})
|
| 1028 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1029 |
|
| 1030 |
|
| 1031 |
#: The value every blank Odoo connector attribute displays as. The writer is
|
|
@@ -1039,6 +1165,25 @@ BLANK = "(none)"
|
|
| 1039 |
#: answer for the life of the worker.
|
| 1040 |
_VOCAB_CACHE = None
|
| 1041 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1042 |
|
| 1043 |
def _server_side_vocabularies(session=None):
|
| 1044 |
"""`{field key: [choice, β¦]}` for choice columns whose vocabulary is CLOSED and known here,
|
|
@@ -1098,7 +1243,10 @@ def _server_side_vocabularies(session=None):
|
|
| 1098 |
|
| 1099 |
β CACHED PER PROCESS, because `_module_fields` runs on every admin GET and on every PUT via
|
| 1100 |
`_fold_legacy_scope`. Only SUCCESSES are cached, so a transient Odoo outage cannot pin an
|
| 1101 |
-
empty answer for the life of the worker.
|
|
|
|
|
|
|
|
|
|
| 1102 |
payment term, partner tag or product category; a customer moves city, state or country; an
|
| 1103 |
agent is assigned or unassigned; a new salesperson takes their first order. None of those is
|
| 1104 |
observable from here, and the refresh is a process restart, which a deploy already does.
|
|
@@ -1145,12 +1293,23 @@ def _server_side_vocabularies(session=None):
|
|
| 1145 |
out = {}
|
| 1146 |
|
| 1147 |
def arm(fn):
|
| 1148 |
-
"""Run one source. A failure omits its keys and never touches the others.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1149 |
try:
|
| 1150 |
-
|
|
|
|
| 1151 |
clean = sorted({str(v) for v in values if str(v or "").strip()})
|
| 1152 |
if clean:
|
| 1153 |
out[key] = clean
|
|
|
|
|
|
|
| 1154 |
return True
|
| 1155 |
except Exception: # noqa: BLE001
|
| 1156 |
return False
|
|
@@ -1293,6 +1452,47 @@ def _prunable_vocabulary(key, session=None, fields=None):
|
|
| 1293 |
return {f["key"] for f in fields if isinstance(f, dict) and f.get("key")} or None
|
| 1294 |
|
| 1295 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1296 |
def _prune_stale_filters(block, session=None):
|
| 1297 |
"""`(block, {module: [dropped keys]})` β owner I16's cascade over a whole stored perms block.
|
| 1298 |
|
|
@@ -1371,8 +1571,15 @@ def _row_wall_blind_keys(key, session=None):
|
|
| 1371 |
|
| 1372 |
ββ AND THE PROPER FIX IS NOW DONE, SO THIS SET NARROWS RATHER THAN COVERING EVERY USER
|
| 1373 |
COLUMN. `perm_scope.apply_row_scope` takes a tenant handle and every door that walls these
|
| 1374 |
-
two modules passes it
|
| 1375 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1376 |
rows and declared to the evaluator before `permits` runs. What is left blind is what stays
|
| 1377 |
genuinely unanswerable HERE, and it is `perm_scope.wallable_overlay_keys` that decides,
|
| 1378 |
never a list restated in this file β one evaluator, so the write door and the wall cannot
|
|
@@ -1424,9 +1631,19 @@ def _row_wall_blind_keys(key, session=None):
|
|
| 1424 |
and f["key"] not in wallable}
|
| 1425 |
|
| 1426 |
|
| 1427 |
-
def _clean_perms(v, governed_keys=None, session=None):
|
| 1428 |
"""Validate a whole `perms` block. FAIL-CLOSED, and LOUD rather than lenient.
|
| 1429 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1430 |
β WAVE 33 (W33-T33) β `governed_keys` IS PER TENANT AND IT IS NOT OPTIONAL IN PRACTICE. It
|
| 1431 |
used to be `set(_PERM_MODULES)`, a literal, which is the same tenant-blindness owner item 11
|
| 1432 |
flagged: an admin of a tenant provisioned for neither grid module could still store a wall
|
|
@@ -1510,6 +1727,12 @@ def _clean_perms(v, governed_keys=None, session=None):
|
|
| 1510 |
# with the "unknown field" wording. It exists so the refusal can NAME THE COLUMN and give
|
| 1511 |
# the cause, which is the half of done-when the generic message cannot carry.
|
| 1512 |
admin_only_blocked = {f["key"] for f in fields_here if f.get(_FILTER_REASON_KEY)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1513 |
hidden = raw.get("hiddenFields") or []
|
| 1514 |
if not isinstance(hidden, list):
|
| 1515 |
raise err(400, "bad_perms", f"{key}: hiddenFields must be a list")
|
|
@@ -1542,6 +1765,32 @@ def _clean_perms(v, governed_keys=None, session=None):
|
|
| 1542 |
metric_ticks = {h for h in submitted
|
| 1543 |
if h.startswith(_mpre) and len(h) > len(_mpre)}
|
| 1544 |
bad = sorted(submitted - valid_keys - metric_ticks)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1545 |
if bad:
|
| 1546 |
# A hiddenFields entry naming nothing hides nothing β and reads as a restriction
|
| 1547 |
# that is not there.
|
|
@@ -1926,6 +2175,17 @@ def get_perms(username: str, session: Session = Depends(admin_gate)):
|
|
| 1926 |
# inline at the return; hoisted so the prune below reads the SAME vocabulary the payload
|
| 1927 |
# offers rather than paying a second store round-trip per database to ask again.
|
| 1928 |
fields_by_module = {k: _module_fields(k, session=session) for k in governed}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1929 |
# ββ W40-T05 / OWNER I16 β THE CASCADE, AT THE ADMIN DOOR. *"If the field is deleted, its
|
| 1930 |
# permission filter goes with it."* A stored leaf naming a column the database no longer has
|
| 1931 |
# is not ignored by the wall β `apply_row_scope` uses `permits`, which DENIES what it cannot
|
|
@@ -1947,6 +2207,18 @@ def get_perms(username: str, session: Session = Depends(admin_gate)):
|
|
| 1947 |
# STORED, and a store that took nothing must not be reported as if it had.
|
| 1948 |
rec = _registry().get(uname) or rec
|
| 1949 |
stored = rec.get("perms") or _pruned
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1950 |
perms_out = {}
|
| 1951 |
for k in governed:
|
| 1952 |
e = stored.get(k)
|
|
@@ -2011,7 +2283,23 @@ def get_perms(username: str, session: Session = Depends(admin_gate)):
|
|
| 2011 |
# item 11's *"EVERY database should be able to be toggleable by admin"*, and it is
|
| 2012 |
# the SAME resolver `_clean_perms` validates against, so the picker cannot offer a
|
| 2013 |
# column the validator will reject.
|
| 2014 |
-
"fields_by_module": fields_by_module
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2015 |
|
| 2016 |
|
| 2017 |
@router.put("/admin/users/{username}/perms")
|
|
@@ -2048,8 +2336,16 @@ def put_perms(username: str, body: dict = Body(default=None),
|
|
| 2048 |
# ββ W36-T22 / C2 β ONE key set. It was two ("listed" and "enforced") with a refusal in the
|
| 2049 |
# gap; W36-T21 closed the gap, so every database the editor shows is one whose wall the table
|
| 2050 |
# routes apply. `session` rides so a `ut_*` schema can be read for THIS tenant.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2051 |
cleaned = _clean_perms(body.get("perms"),
|
| 2052 |
-
governed_keys={m["key"] for m in _mods}, session=session
|
|
|
|
| 2053 |
cleaned = _fold_legacy_scope(reg[uname], cleaned)
|
| 2054 |
_guard_bu_widening(reg[uname], cleaned, bool(body.get("confirm_widen")))
|
| 2055 |
users.set_access(uname, perms=cleaned)
|
|
@@ -2061,7 +2357,10 @@ def put_perms(username: str, body: dict = Body(default=None),
|
|
| 2061 |
raise err(503, "store_unavailable",
|
| 2062 |
"the permissions were not saved β the account is UNCHANGED")
|
| 2063 |
return {"username": uname, "perms": rec.get("perms") or {},
|
| 2064 |
-
"perms_v": int(rec.get("perms_v") or 0)
|
|
|
|
|
|
|
|
|
|
| 2065 |
|
| 2066 |
|
| 2067 |
def _store_binding(session):
|
|
@@ -2148,3 +2447,189 @@ def settings(session: Session = Depends(require_session)):
|
|
| 2148 |
# place for one of the conditions to go missing.
|
| 2149 |
"platformAdmin": platform_admin.is_platform_admin(session.user),
|
| 2150 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
import core.platform_admin as platform_admin # wave 19 R3 β the /settings chrome flag
|
| 37 |
import core.registry as registry
|
| 38 |
+
import core.schema_overlay as schema_overlay # W46-T36 / C1 - the overlay merge + R12 wall
|
| 39 |
import core.store as store
|
| 40 |
|
| 41 |
from deps import Session, err, perms, require_session, users
|
|
|
|
| 996 |
be a second copy of a constant two features already share
|
| 997 |
[[constant-two-features-share]], and `verify_fields_contract` gates that the client keys its
|
| 998 |
real measure columns off the same one.
|
| 999 |
+
|
| 1000 |
+
ββ W46-T34 / OWNER INSTRUCTION 6 β AND IT IS A CENSUS, NOT JUST A LIST. *"Metrics is no
|
| 1001 |
+
longer populating in Odoo customer permissioning for every Manage User. It should be
|
| 1002 |
+
Metrics . Sales, Metrics . Orders, etc."* See `_metric_catalogue`, which this is now the
|
| 1003 |
+
rows-only face of: the SECOND catalogue (the customer-grain one those two labels come from)
|
| 1004 |
+
and the statement of what a database has are both stated there.
|
| 1005 |
+
"""
|
| 1006 |
+
return _metric_catalogue(key)[0]
|
| 1007 |
+
|
| 1008 |
+
|
| 1009 |
+
#: The entity topic whose measures are answered by the CUSTOMER-GRAIN catalogue rather than by
|
| 1010 |
+
#: `semantic.entity_measures`. Named as a TOPIC, never as a grid key, so `topic_for_grid` still
|
| 1011 |
+
#: derives which database it is and a grid rename cannot drift this
|
| 1012 |
+
#: (`_metric_fields`' own "THE TOPIC IS DERIVED, NEVER MAPPED").
|
| 1013 |
+
_CUSTOMER_GRAIN_TOPIC = "odoo_customers"
|
| 1014 |
+
|
| 1015 |
+
|
| 1016 |
+
def _metric_catalogue(key):
|
| 1017 |
+
"""`([row, β¦], {count, refused, status, reason})` β the metric rows for `key`, and a
|
| 1018 |
+
STATEMENT about them that an empty list cannot make on its own.
|
| 1019 |
+
|
| 1020 |
+
ββ W46-T34 / D-432 / D-478 β TWO CATALOGUES, BECAUSE THERE ARE TWO GRAINS.
|
| 1021 |
+
`semantic.entity_measures` answers for a topic that declares a `measures:` binding, which is
|
| 1022 |
+
`odoo_products` (24 offered here) and `odoo_agents` (7). **`odoo_customers` declares no
|
| 1023 |
+
binding at all**, so the customer database offered ZERO metric rows and an administrator had
|
| 1024 |
+
no vocabulary for a wall that was already built: `perm_scope._measure_bound_keys` has always
|
| 1025 |
+
joined a hidden `measure_revenue` onto every `measure_revenue_<rand>` column the customer
|
| 1026 |
+
grid mints. The offer was the only missing half.
|
| 1027 |
+
β AND IT IS NOT AN ARM THAT REFUSED. `entity_measure_bindings('odoo_customers')` returns
|
| 1028 |
+
`[]`, so `_one_binding_offer` never runs, nothing calls `refuse()`, and the `except` below
|
| 1029 |
+
never fires. There was nothing to un-refuse, which is why reading the refusal machinery for
|
| 1030 |
+
the cause finds a clean bill of health on a database serving no rows.
|
| 1031 |
+
β THE CUSTOMER-GRAIN CATALOGUE IS `measure_resolve.offer`, THE ONE THE GRID ITSELF ASKS.
|
| 1032 |
+
`routes_customers` builds its `measures` offer from it and `routes_nav` narrows the same call
|
| 1033 |
+
for the schema drawer, so this is the third reader of one list rather than a fourth list:
|
| 1034 |
+
`measure_filter.ADMITTED` is where "Sales" and "Orders" are spelled, and those are the two
|
| 1035 |
+
names the owner used. Restating them here would give an admin a checkbox whose label the grid
|
| 1036 |
+
does not use.
|
| 1037 |
+
β `team_id=None` β THE WHOLE OFFER, company-level measures included. Narrowing an
|
| 1038 |
+
ADMINISTRATOR's vocabulary by their own BU would hide `Returns $` from the wall while the
|
| 1039 |
+
scoped user it governs can still be granted it, which is a permission the editor cannot
|
| 1040 |
+
express rather than a tidier list.
|
| 1041 |
+
β NO STORE ROUND-TRIP ON THIS ARM: `measure_fields` reads `semantic.metrics()` (the
|
| 1042 |
+
`lru_cache`d model) and a literal dict. So the customer census is determinate even on the two
|
| 1043 |
+
callers that reach `_module_fields` with no session and outside any store fixture.
|
| 1044 |
+
|
| 1045 |
+
ββ AN EMPTY LIST WAS TWO DIFFERENT ANSWERS AND THE CALLER COULD NOT TELL THEM APART. The
|
| 1046 |
+
old body returned `[]` for "this database genuinely has no measures", for "the mirror has not
|
| 1047 |
+
finished syncing", and for "something raised" β silence where a red belongs
|
| 1048 |
+
[[a-red-is-a-signal-silence-is-health]], and a bare `catch` hiding a programmer error
|
| 1049 |
+
[[a-bare-catch-swallows-programmer-errors]]. The rows still degrade to `[]` and this still
|
| 1050 |
+
cannot raise (that property is load-bearing, see above), but the CENSUS now says which of the
|
| 1051 |
+
three happened:
|
| 1052 |
+
* `ok` β `count` measures are offered;
|
| 1053 |
+
* `none` β asked, answered, and this database really has no measure bound to it;
|
| 1054 |
+
* `unavailable` β could not be offered, with the cause in `reason`. A warming mirror lands
|
| 1055 |
+
here, NOT in `none`, because "I cannot say" must never render as "there
|
| 1056 |
+
are none" [[a-probe-assumes-a-shape-and-blames-the-content]].
|
| 1057 |
"""
|
| 1058 |
+
census = {"count": 0, "refused": 0, "status": "none", "reason": ""}
|
| 1059 |
+
failed = []
|
| 1060 |
try:
|
| 1061 |
import aios_grid
|
| 1062 |
import harness.semantic as semantic
|
| 1063 |
topic = semantic.topic_for_grid(key)
|
| 1064 |
if not topic:
|
| 1065 |
+
census["reason"] = ("no entity topic describes this database, so no measure can be "
|
| 1066 |
+
"bound to it")
|
| 1067 |
+
return [], census
|
| 1068 |
+
if topic == _CUSTOMER_GRAIN_TOPIC:
|
| 1069 |
+
from core import measure_resolve
|
| 1070 |
+
# `on_error` is why this arm is not a second silence: `offer` swallows its own
|
| 1071 |
+
# failure and returns `[]`, which is the exact conflation this function exists to
|
| 1072 |
+
# undo, and it already publishes the hook that undoes it.
|
| 1073 |
+
offer = measure_resolve.offer(
|
| 1074 |
+
None, on_error=lambda _what, e: failed.append(f"{type(e).__name__}: {e}"))
|
| 1075 |
+
refusals = []
|
| 1076 |
+
else:
|
| 1077 |
+
offer = semantic.entity_measures(topic)
|
| 1078 |
+
refusals = semantic.entity_measure_refusals(topic) or []
|
| 1079 |
+
except Exception as e: # noqa: BLE001
|
| 1080 |
+
census["status"] = "unavailable"
|
| 1081 |
+
census["reason"] = _plain(f"the measure catalogue could not be read: "
|
| 1082 |
+
f"{type(e).__name__}: {e}")
|
| 1083 |
+
return [], census
|
| 1084 |
out = []
|
| 1085 |
for m in offer or ():
|
| 1086 |
if not isinstance(m, dict):
|
|
|
|
| 1092 |
# would read "Metric - Gross profit" while the grid column read "Gross margin $", and an
|
| 1093 |
# admin cannot hide what they cannot recognise. ASCII hyphen, exactly as the owner wrote
|
| 1094 |
# it β CLAUDE.md rule 2 bars a dash in copy that reaches a screen.
|
| 1095 |
+
# ββ W46-T34 β AND `_plain` RUNS ON IT, because the customer-grain catalogue brings two
|
| 1096 |
+
# labels that predate CLAUDE.md rule 2: `measure_filter.ADMITTED` spells
|
| 1097 |
+
# `'Sales β fully invoiced'` and `'Orders β fully invoiced'` with EM DASHES. They already
|
| 1098 |
+
# reach the grid's own measure picker; carrying them here unchanged would put a ββ
|
| 1099 |
+
# standing-rule violation on a NEW screen, and no gate would catch it β `web_prose` reads
|
| 1100 |
+
# `aios-web/web/src/**` and never sees a label composed in Python. Every WORD survives and
|
| 1101 |
+
# the separator becomes the same ASCII hyphen `Metric - ` already uses one field over, so
|
| 1102 |
+
# the parity this function's docstring protects (an admin must recognise the name the
|
| 1103 |
+
# grid shows) holds; only the punctuation differs, and it stops differing the day
|
| 1104 |
+
# `measure_filter.py` is amended, at which point this call is a no-op.
|
| 1105 |
+
label = _plain(str(m.get("label") or mkey).strip())
|
| 1106 |
mtype = m.get("type")
|
| 1107 |
out.append({"key": f"{aios_grid.MEASURE_FIELD_PREFIX}{mkey}",
|
| 1108 |
"label": f"Metric - {label}",
|
|
|
|
| 1111 |
"shared": False,
|
| 1112 |
"filterable": False,
|
| 1113 |
"metric": True})
|
| 1114 |
+
census["count"] = len(out)
|
| 1115 |
+
census["refused"] = len(refusals)
|
| 1116 |
+
if out:
|
| 1117 |
+
census["status"] = "ok"
|
| 1118 |
+
census["reason"] = ""
|
| 1119 |
+
elif failed:
|
| 1120 |
+
census["status"] = "unavailable"
|
| 1121 |
+
census["reason"] = _plain(f"the measure catalogue could not be read: {failed[0]}")
|
| 1122 |
+
elif refusals:
|
| 1123 |
+
# β A REFUSED KEY IS NOT AN ABSENT ONE. This database DECLARES measures and the
|
| 1124 |
+
# catalogue would not stand behind any of them today β a half-synced mirror, a metric
|
| 1125 |
+
# with no `empty:` family. Reporting the first cause is standing rule 1's reporting half
|
| 1126 |
+
# applied to a catalogue: the count that could not be served says why, rather than
|
| 1127 |
+
# arriving as a zero nobody diffs.
|
| 1128 |
+
census["status"] = "unavailable"
|
| 1129 |
+
census["reason"] = _plain(
|
| 1130 |
+
f"all {len(refusals)} declared measures were refused; the first is "
|
| 1131 |
+
f"{refusals[0].get('key')!r}: {refusals[0].get('reason')}")
|
| 1132 |
+
else:
|
| 1133 |
+
census["reason"] = "this database has no measure bound to it"
|
| 1134 |
+
return out, census
|
| 1135 |
+
|
| 1136 |
+
|
| 1137 |
+
def _plain(text):
|
| 1138 |
+
"""`text` with every em or en dash rewritten, for a string that can reach a screen.
|
| 1139 |
+
|
| 1140 |
+
β CLAUDE.md RULE 2, APPLIED WHERE THE PROSE IS BORROWED. A refusal sentence is composed in
|
| 1141 |
+
`harness/semantic.py` for a LOG and legitimately carries em dashes; carrying it into a
|
| 1142 |
+
permissioning payload makes it app copy, and the rule binds on the copy rather than on the
|
| 1143 |
+
author. A separated dash becomes the comma the sentence already reads as ("would render
|
| 1144 |
+
blank or, worse, as a too-small number"), so the words survive and only the punctuation
|
| 1145 |
+
changes. β APPLIED TO A MEASURE LABEL TOO, and the parity argument does not survive contact
|
| 1146 |
+
with the rule: the label must carry the same WORDS the grid picker shows, which it does, and
|
| 1147 |
+
a ββ owner rule outranks a punctuation convention this file states about itself. The two
|
| 1148 |
+
offenders live in `measure_filter.ADMITTED` and are booked against that file, which fixes the
|
| 1149 |
+
picker as well; until that lands, this is what keeps the permission editor clean.
|
| 1150 |
+
"""
|
| 1151 |
+
s = str(text or "")
|
| 1152 |
+
for sep in ("β", "β"):
|
| 1153 |
+
s = s.replace(f" {sep} ", ", ").replace(sep, " - ")
|
| 1154 |
+
return " ".join(s.split())
|
| 1155 |
|
| 1156 |
|
| 1157 |
#: The value every blank Odoo connector attribute displays as. The writer is
|
|
|
|
| 1165 |
#: answer for the life of the worker.
|
| 1166 |
_VOCAB_CACHE = None
|
| 1167 |
|
| 1168 |
+
#: ββ W46-T35 β THE PER-ARM MEMO, AND IT EXISTS BECAUSE THE ALL-OR-NOTHING ONE ABOVE IS NEVER
|
| 1169 |
+
#: STAMPED WHEN A SINGLE ARM FAILS. `_VOCAB_CACHE` is written only `if complete`, so ONE failing
|
| 1170 |
+
#: source means the other six live Odoo reads are paid again on EVERY admin GET and every PUT.
|
| 1171 |
+
#: MEASURED in this tree on 2026-08-29: a complete build takes 34.0s cold and stamps the cache;
|
| 1172 |
+
#: with the box's Odoo TLS read failing, the build returns 2 keys of 12 in 26.5s, stamps nothing,
|
| 1173 |
+
#: and costs that again on the next request. The editor's dropdowns are empty for the whole of it.
|
| 1174 |
+
#: β SUCCESSES ONLY, EXACTLY AS BEFORE. A failed arm is not memoised, so it is retried on the
|
| 1175 |
+
#: next call and a transient outage still cannot pin a short answer for the life of the worker,
|
| 1176 |
+
#: which is the property the docstring below promises. What changes is only that a SUCCEEDING
|
| 1177 |
+
#: arm stops being punished for its neighbour's outage.
|
| 1178 |
+
#: β TENANT-BLIND ARMS ONLY. `_product_shared_choices` reads the caller's OWN workspace and is
|
| 1179 |
+
#: refused entry by name β memoising it here would leak one tenant's Product taxonomy into
|
| 1180 |
+
#: another tenant's permission editor, which is the same leak `_VOCAB_CACHE`'s stamp order avoids.
|
| 1181 |
+
_VOCAB_ARM_CACHE = {}
|
| 1182 |
+
|
| 1183 |
+
#: The one arm whose answer belongs to the CALLER's tenant, named once so both the memo and the
|
| 1184 |
+
#: stamp order can refuse it rather than each restating the rule.
|
| 1185 |
+
_TENANT_OWNED_ARM = "_product_shared_choices"
|
| 1186 |
+
|
| 1187 |
|
| 1188 |
def _server_side_vocabularies(session=None):
|
| 1189 |
"""`{field key: [choice, β¦]}` for choice columns whose vocabulary is CLOSED and known here,
|
|
|
|
| 1243 |
|
| 1244 |
β CACHED PER PROCESS, because `_module_fields` runs on every admin GET and on every PUT via
|
| 1245 |
`_fold_legacy_scope`. Only SUCCESSES are cached, so a transient Odoo outage cannot pin an
|
| 1246 |
+
empty answer for the life of the worker. ββ W46-T35 β AND THE MEMO IS NOW PER ARM AS WELL AS
|
| 1247 |
+
PER BUILD, because `if complete` meant one failing source re-bought all seven reads on every
|
| 1248 |
+
single request: 34.0s of live Odoo per admin page load, measured here, with the dropdowns
|
| 1249 |
+
empty throughout. See `_VOCAB_ARM_CACHE`. STALE WHEN: someone adds or renames a pricelist,
|
| 1250 |
payment term, partner tag or product category; a customer moves city, state or country; an
|
| 1251 |
agent is assigned or unassigned; a new salesperson takes their first order. None of those is
|
| 1252 |
observable from here, and the refresh is a process restart, which a deploy already does.
|
|
|
|
| 1293 |
out = {}
|
| 1294 |
|
| 1295 |
def arm(fn):
|
| 1296 |
+
"""Run one source. A failure omits its keys and never touches the others.
|
| 1297 |
+
|
| 1298 |
+
β W46-T35 β a tenant-blind arm that SUCCEEDED is remembered per process, so a build left
|
| 1299 |
+
incomplete by one outage does not re-buy the other six reads on the next request. The
|
| 1300 |
+
memo holds the arm's own raw answer; the cleaning below still runs on it, so there is one
|
| 1301 |
+
normalisation rather than two that can drift.
|
| 1302 |
+
"""
|
| 1303 |
+
name = getattr(fn, "__name__", "")
|
| 1304 |
+
memoable = name and name != _TENANT_OWNED_ARM
|
| 1305 |
try:
|
| 1306 |
+
got = _VOCAB_ARM_CACHE[name] if memoable and name in _VOCAB_ARM_CACHE else fn()
|
| 1307 |
+
for key, values in (got or {}).items():
|
| 1308 |
clean = sorted({str(v) for v in values if str(v or "").strip()})
|
| 1309 |
if clean:
|
| 1310 |
out[key] = clean
|
| 1311 |
+
if memoable:
|
| 1312 |
+
_VOCAB_ARM_CACHE[name] = got
|
| 1313 |
return True
|
| 1314 |
except Exception: # noqa: BLE001
|
| 1315 |
return False
|
|
|
|
| 1452 |
return {f["key"] for f in fields if isinstance(f, dict) and f.get("key")} or None
|
| 1453 |
|
| 1454 |
|
| 1455 |
+
def _stale_hidden_keys(key, hidden, session=None, fields=None):
|
| 1456 |
+
"""The `hiddenFields` entries of ONE stored module entry that name a column `key` no longer
|
| 1457 |
+
has β the hide-side twin of `_prune_stale_filters`, and REPORTING ONLY.
|
| 1458 |
+
|
| 1459 |
+
ββ W46-T35 / OWNER INSTRUCTION 6 β THE DEFECT, VERBATIM: *"product_data: hiddenFields names
|
| 1460 |
+
unknown fields ['price_fisch']"*, and the whole save of that account refused. `price_fisch`
|
| 1461 |
+
is not a typo and it is not an invention: it was a real Product column that wave 42 RETIRED
|
| 1462 |
+
(`verify_perm_scope.py`'s `retired_base` still names it beside `price_royal_1/2`), and the
|
| 1463 |
+
contract now declares `price_fisch_t1/t2/t3` and no bare key. So a wall stored before that
|
| 1464 |
+
removal carries a key the database cannot offer, and one obsolete tick made every future
|
| 1465 |
+
edit of that account impossible through the only screen that edits it.
|
| 1466 |
+
|
| 1467 |
+
ββ THE CARVE-OUT IS **NOT** WIDENED TO DO THIS, AND THAT IS THE WHOLE DESIGN. Admitting
|
| 1468 |
+
`price_*`, or any unknown key on its prefix, would silently un-hide whatever a tick gated the
|
| 1469 |
+
day a real column was renamed β the exact failure the `measure_` note above is narrow to
|
| 1470 |
+
avoid. What is admitted is not a NAME PATTERN but a HISTORY: an entry the record already
|
| 1471 |
+
HELD, which the admin never typed and cannot see. Anything else stays a 400.
|
| 1472 |
+
|
| 1473 |
+
β AND IT IS EMPTY WHEN THE VOCABULARY CANNOT BE TRUSTED. `_prunable_vocabulary` answers
|
| 1474 |
+
`None` for a degraded read (a busy DuckDB already takes `product_data` from 45 rows to 39 in
|
| 1475 |
+
this tree), and a set short by one column would report a LIVE hide as stale and let the write
|
| 1476 |
+
door drop it β silently un-hiding a real column, in the widening direction. On `None` this
|
| 1477 |
+
reports nothing, so the caller keeps the loud refusal it has always had.
|
| 1478 |
+
|
| 1479 |
+
β A `measure_` TICK IS NEVER STALE HERE. The metric catalogue answers nothing while the
|
| 1480 |
+
mirror is busy, so pruning against it would delete a live metric wall on a warm-up; the write
|
| 1481 |
+
door admits those on their prefix and this function must not contradict it.
|
| 1482 |
+
|
| 1483 |
+
β `fields` is threaded so a caller that already paid for `_module_fields` reuses that list
|
| 1484 |
+
rather than buying a second store round-trip per database.
|
| 1485 |
+
"""
|
| 1486 |
+
import aios_grid
|
| 1487 |
+
|
| 1488 |
+
vocab = _prunable_vocabulary(key, session=session, fields=fields)
|
| 1489 |
+
if vocab is None:
|
| 1490 |
+
return []
|
| 1491 |
+
_mpre = aios_grid.MEASURE_FIELD_PREFIX
|
| 1492 |
+
return sorted({str(h) for h in (hidden or ())} - vocab
|
| 1493 |
+
- {str(h) for h in (hidden or ()) if str(h).startswith(_mpre)})
|
| 1494 |
+
|
| 1495 |
+
|
| 1496 |
def _prune_stale_filters(block, session=None):
|
| 1497 |
"""`(block, {module: [dropped keys]})` β owner I16's cascade over a whole stored perms block.
|
| 1498 |
|
|
|
|
| 1571 |
|
| 1572 |
ββ AND THE PROPER FIX IS NOW DONE, SO THIS SET NARROWS RATHER THAN COVERING EVERY USER
|
| 1573 |
COLUMN. `perm_scope.apply_row_scope` takes a tenant handle and every door that walls these
|
| 1574 |
+
two modules passes it. β W46-T35 CORRECTS THE COUNT AND ONE NAME, ENUMERATED FROM THE FILES
|
| 1575 |
+
RATHER THAN FROM A GREP PATTERN, because this sentence said FIVE and undercounted by three:
|
| 1576 |
+
`perm_scope.apply_row_scope` is called at EIGHT route sites, `routes_slack.py:208`,
|
| 1577 |
+
`routes_products.py:152`, `routes_customers.py:359` and `:690`, and `routes_tables.py:416`,
|
| 1578 |
+
`:434`, `:701` and `:747` β the four table sites are the ones this paragraph never named β
|
| 1579 |
+
plus `perm_scope.py:1810` (`_scoped`) and `core/perm_migrate.py:126`. And `deps.py:310` is
|
| 1580 |
+
NOT one of them: it calls `assistant_apply_row_scope`, a different function, which reaches
|
| 1581 |
+
the same wall one level down at `perm_scope.py:1549`. With the handle, a TENANT-WIDE overlay
|
| 1582 |
+
column is merged onto the
|
| 1583 |
rows and declared to the evaluator before `permits` runs. What is left blind is what stays
|
| 1584 |
genuinely unanswerable HERE, and it is `perm_scope.wallable_overlay_keys` that decides,
|
| 1585 |
never a list restated in this file β one evaluator, so the write door and the wall cannot
|
|
|
|
| 1631 |
and f["key"] not in wallable}
|
| 1632 |
|
| 1633 |
|
| 1634 |
+
def _clean_perms(v, governed_keys=None, session=None, stored=None, stale_out=None):
|
| 1635 |
"""Validate a whole `perms` block. FAIL-CLOSED, and LOUD rather than lenient.
|
| 1636 |
|
| 1637 |
+
ββ W46-T35 β `stored` AND `stale_out` ARE OPTIONAL AND THE DEFAULT IS THE OLD BEHAVIOUR.
|
| 1638 |
+
`stored` is the block this account ALREADY holds, handed down by `put_perms` from the
|
| 1639 |
+
registry read it has already made β not a second read at a second moment, which is what the
|
| 1640 |
+
`admin_only_blocked` note below refuses. With it, a `hiddenFields` entry naming a column the
|
| 1641 |
+
database no longer has can be told apart from one an admin just invented: the first is a
|
| 1642 |
+
RETIRED column and is dropped and reported, the second is still a 400. `stale_out` is the
|
| 1643 |
+
dict that report lands in, `{module: [key, ...]}`, so the door can name it to the admin.
|
| 1644 |
+
Without either, every unknown key refuses exactly as it did before, which is what keeps
|
| 1645 |
+
`routes_slack.put_channel_agent_perms` (a caller that holds no prior block) unchanged.
|
| 1646 |
+
|
| 1647 |
β WAVE 33 (W33-T33) β `governed_keys` IS PER TENANT AND IT IS NOT OPTIONAL IN PRACTICE. It
|
| 1648 |
used to be `set(_PERM_MODULES)`, a literal, which is the same tenant-blindness owner item 11
|
| 1649 |
flagged: an admin of a tenant provisioned for neither grid module could still store a wall
|
|
|
|
| 1727 |
# with the "unknown field" wording. It exists so the refusal can NAME THE COLUMN and give
|
| 1728 |
# the cause, which is the half of done-when the generic message cannot carry.
|
| 1729 |
admin_only_blocked = {f["key"] for f in fields_here if f.get(_FILTER_REASON_KEY)}
|
| 1730 |
+
# W46-T35 β what this account ALREADY holds for this database, or an empty set when the
|
| 1731 |
+
# caller passed no prior block. Read defensively: a registry record is data, and an entry
|
| 1732 |
+
# that is not an object must not crash the door that validates it.
|
| 1733 |
+
_prior = (stored or {}).get(key)
|
| 1734 |
+
stored_hidden = ({str(h) for h in (_prior.get("hiddenFields") or ())}
|
| 1735 |
+
if isinstance(_prior, dict) else set())
|
| 1736 |
hidden = raw.get("hiddenFields") or []
|
| 1737 |
if not isinstance(hidden, list):
|
| 1738 |
raise err(400, "bad_perms", f"{key}: hiddenFields must be a list")
|
|
|
|
| 1765 |
metric_ticks = {h for h in submitted
|
| 1766 |
if h.startswith(_mpre) and len(h) > len(_mpre)}
|
| 1767 |
bad = sorted(submitted - valid_keys - metric_ticks)
|
| 1768 |
+
# ββ W46-T35 / OWNER INSTRUCTION 6 β A RETIRED COLUMN IS NOT AN UNKNOWN ONE, AND ONLY
|
| 1769 |
+
# THE RECORD CAN TELL THEM APART. See `_stale_hidden_keys` for the full argument; the
|
| 1770 |
+
# short form is that `price_fisch` was a real Product column until wave 42 retired it, so
|
| 1771 |
+
# a wall stored before that carries a key the picker can never offer again and the admin
|
| 1772 |
+
# can neither see nor untick. Refusing the WHOLE save over it locked one account out of
|
| 1773 |
+
# its own permission screen for good.
|
| 1774 |
+
# β THE DISCRIMINATOR IS HISTORY, NOT A NAME PATTERN. A key already IN the stored record
|
| 1775 |
+
# is one this administrator did not type; anything else keeps the loud refusal. Widening
|
| 1776 |
+
# the `measure_` carve-out to swallow a prefix instead would silently un-hide whatever
|
| 1777 |
+
# the tick gated the first time a live column was renamed.
|
| 1778 |
+
# β AND IT IS ORDER-SENSITIVE: `stale` comes out of `bad` BEFORE the raise, so a payload
|
| 1779 |
+
# carrying one retired key and one invented key is still refused, naming only the
|
| 1780 |
+
# invented one. Failing open on the pair would let a typo ride in beside a stale tick.
|
| 1781 |
+
stale = (sorted(set(bad) & {str(h) for h in (stored_hidden or ())})
|
| 1782 |
+
if stored_hidden else [])
|
| 1783 |
+
if stale:
|
| 1784 |
+
stale = _stale_hidden_keys(key, stale, session=session, fields=fields_here)
|
| 1785 |
+
if stale:
|
| 1786 |
+
bad = sorted(set(bad) - set(stale))
|
| 1787 |
+
# The entry is stored WITHOUT the retired keys, which changes no enforcement: a
|
| 1788 |
+
# hiddenFields entry naming nothing hides nothing, and that invariant is what makes
|
| 1789 |
+
# the drop safe rather than convenient. The report is what keeps it from being
|
| 1790 |
+
# silent, and it rides the 200 as well as the GET.
|
| 1791 |
+
submitted -= set(stale)
|
| 1792 |
+
if stale_out is not None:
|
| 1793 |
+
stale_out[key] = list(stale)
|
| 1794 |
if bad:
|
| 1795 |
# A hiddenFields entry naming nothing hides nothing β and reads as a restriction
|
| 1796 |
# that is not there.
|
|
|
|
| 2175 |
# inline at the return; hoisted so the prune below reads the SAME vocabulary the payload
|
| 2176 |
# offers rather than paying a second store round-trip per database to ask again.
|
| 2177 |
fields_by_module = {k: _module_fields(k, session=session) for k in governed}
|
| 2178 |
+
# ββ W46-T34 / OWNER INSTRUCTION 6 β THE METRIC COUNT, STATED PER DATABASE. The rows are
|
| 2179 |
+
# already inside `fields_by_module` (they are `metric: true` members of the hide vocabulary);
|
| 2180 |
+
# what could not be read off them is the DIFFERENCE between a database with no measures and
|
| 2181 |
+
# one whose catalogue could not be served, because both arrive as no rows. `_metric_catalogue`
|
| 2182 |
+
# says which, per key, so the editor can name the count and can say "none on this database"
|
| 2183 |
+
# instead of drawing an empty group.
|
| 2184 |
+
# β CHEAP TO ASK TWICE. This repeats the catalogue call `_module_fields` just made, NOT the
|
| 2185 |
+
# store round-trip beside it: `semantic._ENTITY_OFFER_CACHE` answers the entity arm and the
|
| 2186 |
+
# customer arm reads the `lru_cache`d model. The one `_module_fields` pass above is what the
|
| 2187 |
+
# comment there protects, and it is untouched.
|
| 2188 |
+
metrics_by_module = {k: _metric_catalogue(k)[1] for k in governed}
|
| 2189 |
# ββ W40-T05 / OWNER I16 β THE CASCADE, AT THE ADMIN DOOR. *"If the field is deleted, its
|
| 2190 |
# permission filter goes with it."* A stored leaf naming a column the database no longer has
|
| 2191 |
# is not ignored by the wall β `apply_row_scope` uses `permits`, which DENIES what it cannot
|
|
|
|
| 2207 |
# STORED, and a store that took nothing must not be reported as if it had.
|
| 2208 |
rec = _registry().get(uname) or rec
|
| 2209 |
stored = rec.get("perms") or _pruned
|
| 2210 |
+
# ββ W46-T35 β THE HIDE-SIDE CENSUS, off the SAME `fields_by_module` pass the picker is built
|
| 2211 |
+
# from, so the report and the offer cannot disagree about which columns exist. Only databases
|
| 2212 |
+
# that actually hold a stale entry appear, so an ordinary account sends `{}`.
|
| 2213 |
+
stale_hidden_by_module = {}
|
| 2214 |
+
for k in governed:
|
| 2215 |
+
_e = stored.get(k)
|
| 2216 |
+
if not isinstance(_e, dict) or not _e.get("hiddenFields"):
|
| 2217 |
+
continue
|
| 2218 |
+
_gone = _stale_hidden_keys(k, _e.get("hiddenFields"), session=session,
|
| 2219 |
+
fields=fields_by_module.get(k))
|
| 2220 |
+
if _gone:
|
| 2221 |
+
stale_hidden_by_module[k] = _gone
|
| 2222 |
perms_out = {}
|
| 2223 |
for k in governed:
|
| 2224 |
e = stored.get(k)
|
|
|
|
| 2283 |
# item 11's *"EVERY database should be able to be toggleable by admin"*, and it is
|
| 2284 |
# the SAME resolver `_clean_perms` validates against, so the picker cannot offer a
|
| 2285 |
# column the validator will reject.
|
| 2286 |
+
"fields_by_module": fields_by_module,
|
| 2287 |
+
# ββ W46-T35 β `{module: [key, ...]}`: the stored hides whose column the database no
|
| 2288 |
+
# longer has, NAMED so the editor can offer to clear them.
|
| 2289 |
+
# β REPORTED, NEVER WRITTEN, and the asymmetry with the filter cascade above is
|
| 2290 |
+
# deliberate. That one writes because a stale filter LEAF actively denies every row
|
| 2291 |
+
# (`permits` refuses what it cannot answer), so leaving it costs the account its
|
| 2292 |
+
# whole grid. A stale HIDE costs nothing while it sits there: it names no column, so
|
| 2293 |
+
# it hides none. The only harm it did was to refuse the save, and the write door
|
| 2294 |
+
# itself now clears it. A second `users.set_access` here would also put a GET one
|
| 2295 |
+
# `is_migrated` slip away from consuming `_fold_legacy_scope`'s one chance, which is
|
| 2296 |
+
# the BU leak the guard above exists for.
|
| 2297 |
+
"stale_hidden_by_module": stale_hidden_by_module,
|
| 2298 |
+
# ββ W46-T34 β `{module: {count, refused, status, reason}}`, the metric census
|
| 2299 |
+
# beside the field list it summarises. `status` is `ok` | `none` | `unavailable`,
|
| 2300 |
+
# and the third is the one that had no way to be said before: an empty metric list
|
| 2301 |
+
# meant "there are none here" and "I could not ask" in identical JSON.
|
| 2302 |
+
"metrics_by_module": metrics_by_module}
|
| 2303 |
|
| 2304 |
|
| 2305 |
@router.put("/admin/users/{username}/perms")
|
|
|
|
| 2336 |
# ββ W36-T22 / C2 β ONE key set. It was two ("listed" and "enforced") with a refusal in the
|
| 2337 |
# gap; W36-T21 closed the gap, so every database the editor shows is one whose wall the table
|
| 2338 |
# routes apply. `session` rides so a `ut_*` schema can be read for THIS tenant.
|
| 2339 |
+
# ββ W46-T35 β THE PRIOR BLOCK RIDES DOWN, AND THE REPORT RIDES BACK UP. `reg[uname]` is the
|
| 2340 |
+
# read this route has already made, so the validator can tell a RETIRED column from an
|
| 2341 |
+
# invented one without a second registry read at a second moment. `_stale` collects what was
|
| 2342 |
+
# dropped, per database, and is returned so the editor can name it even before it renders a
|
| 2343 |
+
# control for it: a report that lives only in a client this ticket does not own would be a
|
| 2344 |
+
# feature nobody ships [[two-lanes-one-contract-dead-feature]].
|
| 2345 |
+
_stale = {}
|
| 2346 |
cleaned = _clean_perms(body.get("perms"),
|
| 2347 |
+
governed_keys={m["key"] for m in _mods}, session=session,
|
| 2348 |
+
stored=reg[uname].get("perms"), stale_out=_stale) or {}
|
| 2349 |
cleaned = _fold_legacy_scope(reg[uname], cleaned)
|
| 2350 |
_guard_bu_widening(reg[uname], cleaned, bool(body.get("confirm_widen")))
|
| 2351 |
users.set_access(uname, perms=cleaned)
|
|
|
|
| 2357 |
raise err(503, "store_unavailable",
|
| 2358 |
"the permissions were not saved β the account is UNCHANGED")
|
| 2359 |
return {"username": uname, "perms": rec.get("perms") or {},
|
| 2360 |
+
"perms_v": int(rec.get("perms_v") or 0),
|
| 2361 |
+
# W46-T35 β `{module: [key, ...]}`, empty on an ordinary save. What the save cleared
|
| 2362 |
+
# out because the column behind it is gone, stated on the door that cleared it.
|
| 2363 |
+
"stale_hidden": _stale}
|
| 2364 |
|
| 2365 |
|
| 2366 |
def _store_binding(session):
|
|
|
|
| 2447 |
# place for one of the conditions to go missing.
|
| 2448 |
"platformAdmin": platform_admin.is_platform_admin(session.user),
|
| 2449 |
}
|
| 2450 |
+
|
| 2451 |
+
|
| 2452 |
+
# =================================================================================================
|
| 2453 |
+
# W46-T36 Β· CONTRACT C1 Β· RULINGS R5/R12 β THE PER-TENANT SCHEMA OVERLAY
|
| 2454 |
+
#
|
| 2455 |
+
# The canonical field contract (`platform/aios_grid_fields.json`) is SHARED and NEVER WRITTEN. A
|
| 2456 |
+
# tenant that wants a column hidden, relabelled or moved gets an OVERLAY document in its own
|
| 2457 |
+
# store (`ut_schema_overlay`), and every read merges contract + overlay. The merge, the R12 wall
|
| 2458 |
+
# and the store seam all live in `core/schema_overlay.py`; NOTHING of that logic is repeated here.
|
| 2459 |
+
# These two routes are the door: they resolve WHICH databases this tenant has, WHICH store handle
|
| 2460 |
+
# is this tenant's, and turn `SchemaOverlayUnsupported` into C1's 400.
|
| 2461 |
+
#
|
| 2462 |
+
# ββ R5 IS CARRIED BY ONE ARGUMENT AND NOTHING ELSE ENFORCES IT. `schema_overlay.read()` /
|
| 2463 |
+
# `write()` with no `st=` resolve through `core.store`'s module default, which is tenant #0's repo
|
| 2464 |
+
# under `hf` (`_DEFAULT = for_repo(REPO)`, bound at IMPORT from `OS_DATA_REPO`) and `AIOS_TENANT`
|
| 2465 |
+
# or a hardcoded `royal-imports` under `pg` [[pg-guard-authorises-a-tenant-not-a-database]].
|
| 2466 |
+
# Neither is the request's tenant, so a bare call here is the cross-tenant read R5 forbids β
|
| 2467 |
+
# and it would be SILENT, serving and then overwriting somebody else's document with a 200.
|
| 2468 |
+
# `session.runtime` IS the tenant's handle (`TenantRuntime.get`/`.put` namespace the key), which
|
| 2469 |
+
# is the same object `user_tables.lend_defs(session.runtime)` is handed above.
|
| 2470 |
+
# β `verify_schema_overlay.py` legs 9 and 10 fail if either call site here loses its `st=`.
|
| 2471 |
+
# =================================================================================================
|
| 2472 |
+
|
| 2473 |
+
def _overlay_marks(key, session):
|
| 2474 |
+
"""`{field_key: {"source": str, "derived": True}}` for one database, read off the RAW source.
|
| 2475 |
+
|
| 2476 |
+
β WHY THIS EXISTS AT ALL: `_module_fields` is the right ENUMERATOR (it is the one vocabulary
|
| 2477 |
+
the perms picker and the validator already share, it carries a tenant's user-generated columns
|
| 2478 |
+
and it has a `ut_*` arm) but its rows are built for the PICKER, so they keep `pinned` and drop
|
| 2479 |
+
`source` and `derived`. C1's row shape names `source`, and `locked_keys` reads `derived` β the
|
| 2480 |
+
customer contract's `partner_id` is locked by that flag alone. So the two marks are re-attached
|
| 2481 |
+
by key from the same contract `_module_fields` itself read.
|
| 2482 |
+
|
| 2483 |
+
β NO FALLBACK IS INVENTED FOR A KEY THAT HAS NO MARK. A metric pseudo-field or a
|
| 2484 |
+
user-generated column simply has no canonical stratum here, and `source: null` renders as the
|
| 2485 |
+
client's honest "unknown". Guessing `"measure"` or `"overlay"` would be a name the server
|
| 2486 |
+
never meant, which is the defect `ManageDatabase.tsx`'s own parser comment refuses.
|
| 2487 |
+
β AND THE MARKS ARE NOT PUSHED INTO `_module_fields`' OWN ROWS: that payload feeds the
|
| 2488 |
+
permission editor, and widening a shared wire for one caller is how two consumers of one
|
| 2489 |
+
contract come apart.
|
| 2490 |
+
"""
|
| 2491 |
+
raw = ()
|
| 2492 |
+
try:
|
| 2493 |
+
if str(key).startswith("ut_"):
|
| 2494 |
+
import core.user_tables as user_tables
|
| 2495 |
+
defn = user_tables.get(key, st=user_tables.lend_defs(session.runtime)) or {}
|
| 2496 |
+
raw = defn.get("fields") or ()
|
| 2497 |
+
else:
|
| 2498 |
+
provider = _static_field_providers().get(key)
|
| 2499 |
+
raw = provider() if provider else ()
|
| 2500 |
+
except Exception: # noqa: BLE001
|
| 2501 |
+
# A contract that will not open costs the DECORATION, never the list. The rows still ship
|
| 2502 |
+
# and say `None` about the stratum they could not read, which is the same polarity
|
| 2503 |
+
# `_field_provenance` above already chose.
|
| 2504 |
+
return {}
|
| 2505 |
+
out = {}
|
| 2506 |
+
for f in raw:
|
| 2507 |
+
if not isinstance(f, dict) or not f.get("key"):
|
| 2508 |
+
continue
|
| 2509 |
+
mark = {}
|
| 2510 |
+
source = f.get("source")
|
| 2511 |
+
if isinstance(source, str) and source.strip():
|
| 2512 |
+
mark["source"] = source
|
| 2513 |
+
if f.get("derived") is True:
|
| 2514 |
+
mark["derived"] = True
|
| 2515 |
+
if mark:
|
| 2516 |
+
out[f["key"]] = mark
|
| 2517 |
+
return out
|
| 2518 |
+
|
| 2519 |
+
|
| 2520 |
+
def _overlay_view(session):
|
| 2521 |
+
"""C1's merged view for EVERY database this tenant has: `(rows, skipped, ignored_hides)`.
|
| 2522 |
+
|
| 2523 |
+
ββ EVERY ROW NAMES ITS DATABASE, AND THAT IS LOAD-BEARING RATHER THAN DECORATIVE (dated C1
|
| 2524 |
+
amendment, 2026-08-29). C1 spells the GET row without a database key, but the document a PATCH
|
| 2525 |
+
carries is keyed by `<database_key>` FIRST, so a row that cannot name its database can never be
|
| 2526 |
+
written back and cannot be grouped by the pane. The shipped client (`ManageDatabase.tsx`,
|
| 2527 |
+
`parseOverlay`) accepts `database` or `database_key` and DROPS every row carrying neither, with
|
| 2528 |
+
a visible count. `database` is the camelCase this client's wires already speak; `databaseLabel`
|
| 2529 |
+
is optional and it falls back to the key.
|
| 2530 |
+
|
| 2531 |
+
β ONE UNREADABLE DATABASE MUST NOT TAKE THE PAGE DOWN. `_module_fields` raises
|
| 2532 |
+
`400 ungoverned_module` for a `ut_*` key whose definition will not open, and letting that
|
| 2533 |
+
escape would 400 the WHOLE response β the admin would lose every other database's schema to
|
| 2534 |
+
one bad one, and the pane would be back to the could-not-load line this route exists to
|
| 2535 |
+
replace. A skipped database is named in `skipped` instead, so the degrade is reported rather
|
| 2536 |
+
than silent.
|
| 2537 |
+
|
| 2538 |
+
β A SURFACE (Assistant, Agents) answers `[]` from `_module_fields` and contributes no rows.
|
| 2539 |
+
That is not a skip: it is a module with no field schema, and calling it degraded would report
|
| 2540 |
+
a failure where there is none.
|
| 2541 |
+
"""
|
| 2542 |
+
doc = schema_overlay.read(st=session.runtime) # β R5 β the tenant's own handle
|
| 2543 |
+
rows, skipped, ignored = [], [], []
|
| 2544 |
+
for db in _perm_modules(session):
|
| 2545 |
+
key = db.get("key")
|
| 2546 |
+
label = db.get("label") or key
|
| 2547 |
+
try:
|
| 2548 |
+
fields = _module_fields(key, session=session)
|
| 2549 |
+
except Exception: # noqa: BLE001
|
| 2550 |
+
skipped.append(key)
|
| 2551 |
+
continue
|
| 2552 |
+
if not fields:
|
| 2553 |
+
continue
|
| 2554 |
+
marks = _overlay_marks(key, session)
|
| 2555 |
+
# β NEW DICTS. `_module_fields` already returns fresh rows, but the mark merge is written
|
| 2556 |
+
# as a copy anyway so this can never become a mutation of a cached contract β the failure
|
| 2557 |
+
# `schema_overlay`'s own header is built around (`aios_grid.FIELDS` is a module global).
|
| 2558 |
+
contract = [dict(f, **marks.get(f.get("key"), {})) for f in fields if isinstance(f, dict)]
|
| 2559 |
+
# β THE FLAT LIST IS THE `locked` SOURCE, KNOWINGLY. `_module_fields` hands back a LIST,
|
| 2560 |
+
# so the product contract's `{identity, business_key}` metadata is not reachable from it
|
| 2561 |
+
# and `locked_keys` resolves `{code}` (the business key, via `pinned`) rather than
|
| 2562 |
+
# `{code, pid}`. `pid` is contract METADATA and not a member of `product_data.fields` at
|
| 2563 |
+
# all, so it can never BE a row here and therefore can never be hidden β the narrower set
|
| 2564 |
+
# locks everything that exists. `verify_schema_overlay` legs 6j to 6l pin exactly that.
|
| 2565 |
+
locked = schema_overlay.locked_keys(key, contract)
|
| 2566 |
+
for row in schema_overlay.merged_view(key, contract, doc, locked=locked):
|
| 2567 |
+
rows.append(dict(row, database=key, databaseLabel=label))
|
| 2568 |
+
for f_key in schema_overlay.ignored_hides(key, contract, doc, locked=locked):
|
| 2569 |
+
ignored.append({"database": key, "field": f_key})
|
| 2570 |
+
return rows, skipped, ignored
|
| 2571 |
+
|
| 2572 |
+
|
| 2573 |
+
def _overlay_refusal(exc):
|
| 2574 |
+
"""R12's refusal as C1's HTTP shape: `400 schema_overlay_unsupported`, NAMING the key.
|
| 2575 |
+
|
| 2576 |
+
β The sentence reaches an administrator's screen, so it is written as prose and carries no
|
| 2577 |
+
dash. `.database_key` / `.field_key` locate the offending property, because "unsupported key"
|
| 2578 |
+
without a location is a refusal an admin cannot act on when a PATCH carries several fields.
|
| 2579 |
+
"""
|
| 2580 |
+
where = ".".join(str(p) for p in (exc.database_key, exc.field_key) if p)
|
| 2581 |
+
detail = f"The schema overlay cannot carry {exc.key!r}"
|
| 2582 |
+
if where:
|
| 2583 |
+
detail += f" (at {where})"
|
| 2584 |
+
if exc.reason:
|
| 2585 |
+
detail += ". " + str(exc.reason).rstrip(".")
|
| 2586 |
+
detail += ". A database view may hide, relabel and reorder a field, and nothing else."
|
| 2587 |
+
return err(400, "schema_overlay_unsupported", detail)
|
| 2588 |
+
|
| 2589 |
+
|
| 2590 |
+
@router.get("/admin/schema-overlay")
|
| 2591 |
+
def get_schema_overlay(session: Session = Depends(admin_gate)):
|
| 2592 |
+
"""C1: the merged contract-plus-overlay field list for every database this tenant has.
|
| 2593 |
+
|
| 2594 |
+
A 503 BEFORE THE READ, and it is this file's own standing rule rather than a flourish: the
|
| 2595 |
+
module header's "a store outage is a 503, never an empty list". `schema_overlay.read`
|
| 2596 |
+
resolves a failed read to `{}` one level down, so without this an outage would serve 200 with
|
| 2597 |
+
the pure canonical contract, and an administrator would see every hidden column back and
|
| 2598 |
+
every relabel gone, reported as the truth. Same polarity as the PATCH below, which cannot be
|
| 2599 |
+
allowed to write an empty document over a real one for the same reason.
|
| 2600 |
+
"""
|
| 2601 |
+
_require_store()
|
| 2602 |
+
try:
|
| 2603 |
+
rows, skipped, ignored = _overlay_view(session)
|
| 2604 |
+
except schema_overlay.SchemaOverlayUnsupported as exc:
|
| 2605 |
+
raise _overlay_refusal(exc)
|
| 2606 |
+
return {"fields": rows, "skipped": skipped, "ignoredHides": ignored}
|
| 2607 |
+
|
| 2608 |
+
|
| 2609 |
+
@router.patch("/admin/schema-overlay")
|
| 2610 |
+
def patch_schema_overlay(body: dict = Body(default=None),
|
| 2611 |
+
session: Session = Depends(admin_gate)):
|
| 2612 |
+
"""C1: persist `hidden` / `label` / `order` for THIS tenant, then return the merged view.
|
| 2613 |
+
|
| 2614 |
+
β READ, MERGE, WRITE β never write the patch itself. `write()` takes the WHOLE document, so
|
| 2615 |
+
a PATCH addressed to one database would otherwise delete every other database's overlay;
|
| 2616 |
+
`apply_patch` is the one merge and it runs `clean_patch` (R12's only wall) on the way in.
|
| 2617 |
+
|
| 2618 |
+
β A 503 BEFORE THE WRITE, for the reason the module header states: `store.get` answers `{}` on
|
| 2619 |
+
a failed read, so a read-modify-write against an unavailable store would persist an EMPTY
|
| 2620 |
+
document over a real one and report 200.
|
| 2621 |
+
|
| 2622 |
+
β A DATABASE KEY THIS TENANT DOES NOT HAVE IS KEPT, NOT REFUSED. C1 names exactly one refusal
|
| 2623 |
+
and inventing a second wall here could refuse correct work (a database the picker filters out
|
| 2624 |
+
but the overlay legitimately covers). An unaddressed key is inert: `merged_view` only ever
|
| 2625 |
+
indexes the keys it has fields for.
|
| 2626 |
+
"""
|
| 2627 |
+
_require_store()
|
| 2628 |
+
try:
|
| 2629 |
+
doc = schema_overlay.apply_patch(
|
| 2630 |
+
schema_overlay.read(st=session.runtime), body) # β R5 β the tenant's own handle
|
| 2631 |
+
schema_overlay.write(doc, st=session.runtime) # β R5 β and again on the write
|
| 2632 |
+
rows, skipped, ignored = _overlay_view(session)
|
| 2633 |
+
except schema_overlay.SchemaOverlayUnsupported as exc:
|
| 2634 |
+
raise _overlay_refusal(exc)
|
| 2635 |
+
return {"fields": rows, "skipped": skipped, "ignoredHides": ignored}
|
api/routes_customers.py
CHANGED
|
@@ -98,8 +98,8 @@ def _pool_for(rt, team_id, agent):
|
|
| 98 |
rt.pool_cache[key] = snap # seed, so the memo stamps stay coherent
|
| 99 |
return snap[1]
|
| 100 |
raise err(503, "connector_paused",
|
| 101 |
-
"this data source is paused and no snapshot exists for your scope
|
| 102 |
-
"
|
| 103 |
|
| 104 |
def _build():
|
| 105 |
# β THE SCOPE GOES INTO THE BUILDER. `pool(agent_name, team_id)` is the same reconciled
|
|
@@ -1650,7 +1650,7 @@ def patch_customer(pid: int, body: dict = Body(default=None),
|
|
| 1650 |
"pid": pid, "updates": updates}, ctx)
|
| 1651 |
except grid_events.StoreUnavailable:
|
| 1652 |
raise err(503, "store_unavailable",
|
| 1653 |
-
"the tenant store is unavailable
|
| 1654 |
|
| 1655 |
route_accepted, route_swaps, route_taken = ({}, [], set())
|
| 1656 |
if route_updates:
|
|
@@ -2326,7 +2326,9 @@ def route_order_delete(field_key: str,
|
|
| 2326 |
@router.patch("/customers/route-order/{field_key}")
|
| 2327 |
def route_order_rename(field_key: str, body: dict = Body(default=None),
|
| 2328 |
session: Session = Depends(module_gate(MODULE))):
|
| 2329 |
-
"""Rename a route order column, or write its description
|
|
|
|
|
|
|
| 2330 |
|
| 2331 |
ββ OWNER ITEM 6 (2026-08-23) β "Edit field" MUST BE ABLE TO RENAME THIS COLUMN.
|
| 2332 |
|
|
@@ -2358,6 +2360,31 @@ def route_order_rename(field_key: str, body: dict = Body(default=None),
|
|
| 2358 |
they typed the description, and a later rename through this door is invisible to them.
|
| 2359 |
Pre-existing, and unreachable enough to have gone unnoticed; owner item 6 makes that pane the
|
| 2360 |
place people go for route columns, so it stops being unreachable on the same day.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2361 |
"""
|
| 2362 |
from core import shared_overlay
|
| 2363 |
import core.perm_scope as perm_scope
|
|
@@ -2369,7 +2396,11 @@ def route_order_rename(field_key: str, body: dict = Body(default=None),
|
|
| 2369 |
# β `"note" in body` AND NOT a truthiness test: an empty string is how a description is
|
| 2370 |
# CLEARED, and a door that read it as "unchanged" would leave one nobody can delete.
|
| 2371 |
note = str(body.get("note") or "")[:2000] if "note" in body else None
|
| 2372 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2373 |
raise err(400, "bad_request", "a route order column needs a name")
|
| 2374 |
if "label" in body and not label:
|
| 2375 |
raise err(400, "bad_request", "a route order column needs a name")
|
|
@@ -2411,9 +2442,22 @@ def route_order_rename(field_key: str, body: dict = Body(default=None),
|
|
| 2411 |
patch["label"] = label
|
| 2412 |
if note is not None:
|
| 2413 |
patch["note"] = note
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2414 |
shared_overlay.put_field(_shared_key(), key, patch, st=session.runtime)
|
| 2415 |
return {"ok": True, "field": key, "label": patch.get("label") or key,
|
| 2416 |
-
"note": patch.get("note") or ""
|
|
|
|
| 2417 |
|
| 2418 |
|
| 2419 |
# ---------------------------------------------------------------------------
|
|
@@ -2455,10 +2499,13 @@ def _route_delivery_recipient_or_400(session, raw, directory=None):
|
|
| 2455 |
``session`` is intentionally part of the seam even though the ordinary registry does not
|
| 2456 |
consume it yet. Staging-only identities can extend this one helper without leaking fixture
|
| 2457 |
logic into Route persistence or falling through to a different account plane.
|
|
|
|
|
|
|
|
|
|
| 2458 |
"""
|
| 2459 |
return _route_assignee_or_400(
|
| 2460 |
session, raw, directory=directory, code="unknown_route_recipient",
|
| 2461 |
-
message="
|
| 2462 |
|
| 2463 |
|
| 2464 |
def _route_view_revision(view_id, config):
|
|
@@ -2478,16 +2525,24 @@ def _route_delivery_snapshot_for_route_or_400(
|
|
| 2478 |
session, route, body, *, source_views=None, permitted=None, recipient_directory=None):
|
| 2479 |
"""Build the immutable delivery exclusively from a normalized Route and server reads.
|
| 2480 |
|
| 2481 |
-
The browser may choose the
|
| 2482 |
-
View configuration, revision, Route name, or stop ids: all of those are resolved
|
| 2483 |
-
from the saved Route and its real source View at the moment the schedule is created.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2484 |
"""
|
| 2485 |
from core import route_system
|
| 2486 |
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
|
| 2487 |
|
| 2488 |
body = body if isinstance(body, dict) else {}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2489 |
recipient = _route_delivery_recipient_or_400(
|
| 2490 |
-
session,
|
| 2491 |
source_view_id = str(route.get("sourceViewId") or "").strip()
|
| 2492 |
if not source_view_id:
|
| 2493 |
raise err(409, "route_source_view_missing",
|
|
|
|
| 98 |
rt.pool_cache[key] = snap # seed, so the memo stamps stay coherent
|
| 99 |
return snap[1]
|
| 100 |
raise err(503, "connector_paused",
|
| 101 |
+
"this data source is paused and no snapshot exists for your scope. "
|
| 102 |
+
"An admin can resume it under Settings β Connectors")
|
| 103 |
|
| 104 |
def _build():
|
| 105 |
# β THE SCOPE GOES INTO THE BUILDER. `pool(agent_name, team_id)` is the same reconciled
|
|
|
|
| 1650 |
"pid": pid, "updates": updates}, ctx)
|
| 1651 |
except grid_events.StoreUnavailable:
|
| 1652 |
raise err(503, "store_unavailable",
|
| 1653 |
+
"the tenant store is unavailable. Your change was not saved")
|
| 1654 |
|
| 1655 |
route_accepted, route_swaps, route_taken = ({}, [], set())
|
| 1656 |
if route_updates:
|
|
|
|
| 2326 |
@router.patch("/customers/route-order/{field_key}")
|
| 2327 |
def route_order_rename(field_key: str, body: dict = Body(default=None),
|
| 2328 |
session: Session = Depends(module_gate(MODULE))):
|
| 2329 |
+
"""Rename a route order column, or write its description, format or summary.
|
| 2330 |
+
|
| 2331 |
+
Body: `{label?, note?, format?, agg?}`.
|
| 2332 |
|
| 2333 |
ββ OWNER ITEM 6 (2026-08-23) β "Edit field" MUST BE ABLE TO RENAME THIS COLUMN.
|
| 2334 |
|
|
|
|
| 2360 |
they typed the description, and a later rename through this door is invisible to them.
|
| 2361 |
Pre-existing, and unreachable enough to have gone unnoticed; owner item 6 makes that pane the
|
| 2362 |
place people go for route columns, so it stops being unreachable on the same day.
|
| 2363 |
+
|
| 2364 |
+
ββ D-468 / W46-T22 β **FORMAT AND SUMMARY RIDE THIS DOOR FOR THE SAME REASON THE
|
| 2365 |
+
DESCRIPTION DOES, AND THEY ARE THE LAST TWO.** Owner item 6 closed `onNote` and `onRename`.
|
| 2366 |
+
Two rows of the same pane were left calling `saveField`, which is the per-user `field_upsert`
|
| 2367 |
+
traced above: the **Format** row (`onFormat`, unconditional) and the **Summary** row
|
| 2368 |
+
(`onAggregate`, whose `isUserTable` arm is false on this registry topic). Both therefore land
|
| 2369 |
+
in `grid_events`'s `key in field_by_key` branch, which writes `format` and `agg` into THAT
|
| 2370 |
+
reader's private definitions, `_merge_shared_fields` yields to the fork, and setting a Format
|
| 2371 |
+
on a tenant-wide route column silently privatises it for the person who set it, frozen at the
|
| 2372 |
+
label it wore that day. This door writes both into the SHARED definition instead, so every
|
| 2373 |
+
account keeps reading one column.
|
| 2374 |
+
|
| 2375 |
+
β THE VOCABULARY IS BORROWED, NEVER RE-AUTHORED. `format` goes through
|
| 2376 |
+
`aios_grid._clean_format` against the column's own stored type, and `agg` must be a member of
|
| 2377 |
+
`aios_grid.FIELD_AGGS`. An unbounded blob on a tenant-wide stratum is a widening, and a second
|
| 2378 |
+
copy of these bounds is a second thing to keep in step with `grid_events`.
|
| 2379 |
+
|
| 2380 |
+
β PRESENCE, NOT TRUTHINESS, and a cleared value POPS the key. That is `note`'s rule for
|
| 2381 |
+
`note`'s reason: clearing a Format has to be expressible, and a definition with no Format is
|
| 2382 |
+
one with no `format` key, which is what every reader of the merged contract already assumes.
|
| 2383 |
+
|
| 2384 |
+
β THE CLIENT HALF IS NOT HERE. `ColumnMenu.tsx::onFormat` and `::onAggregate` still call
|
| 2385 |
+
`saveField` for a `kind: route_order` column; they belong to another fence and are booked as
|
| 2386 |
+
an amendment. Until they route here the fork is still reachable from the pane, and this door
|
| 2387 |
+
is the destination waiting for them, exercised by nothing else.
|
| 2388 |
"""
|
| 2389 |
from core import shared_overlay
|
| 2390 |
import core.perm_scope as perm_scope
|
|
|
|
| 2396 |
# β `"note" in body` AND NOT a truthiness test: an empty string is how a description is
|
| 2397 |
# CLEARED, and a door that read it as "unchanged" would leave one nobody can delete.
|
| 2398 |
note = str(body.get("note") or "")[:2000] if "note" in body else None
|
| 2399 |
+
# β D-468: the guard below used to read `not label and note is None`, which answered 400 to a
|
| 2400 |
+
# format-only or summary-only body and would have left the new door unreachable from the one
|
| 2401 |
+
# pane that needs it. Presence of ANY writable key is what makes this a request.
|
| 2402 |
+
wants_format, wants_agg = "format" in body, "agg" in body
|
| 2403 |
+
if not label and note is None and not wants_format and not wants_agg:
|
| 2404 |
raise err(400, "bad_request", "a route order column needs a name")
|
| 2405 |
if "label" in body and not label:
|
| 2406 |
raise err(400, "bad_request", "a route order column needs a name")
|
|
|
|
| 2442 |
patch["label"] = label
|
| 2443 |
if note is not None:
|
| 2444 |
patch["note"] = note
|
| 2445 |
+
if wants_format:
|
| 2446 |
+
cleaned = aios_grid._clean_format(body.get("format"), defn.get("type"))
|
| 2447 |
+
if cleaned:
|
| 2448 |
+
patch["format"] = cleaned
|
| 2449 |
+
else:
|
| 2450 |
+
patch.pop("format", None)
|
| 2451 |
+
if wants_agg:
|
| 2452 |
+
summary = body.get("agg")
|
| 2453 |
+
if summary in aios_grid.FIELD_AGGS:
|
| 2454 |
+
patch["agg"] = summary
|
| 2455 |
+
else:
|
| 2456 |
+
patch.pop("agg", None)
|
| 2457 |
shared_overlay.put_field(_shared_key(), key, patch, st=session.runtime)
|
| 2458 |
return {"ok": True, "field": key, "label": patch.get("label") or key,
|
| 2459 |
+
"note": patch.get("note") or "",
|
| 2460 |
+
"format": patch.get("format"), "agg": patch.get("agg")}
|
| 2461 |
|
| 2462 |
|
| 2463 |
# ---------------------------------------------------------------------------
|
|
|
|
| 2499 |
``session`` is intentionally part of the seam even though the ordinary registry does not
|
| 2500 |
consume it yet. Staging-only identities can extend this one helper without leaking fixture
|
| 2501 |
logic into Route persistence or falling through to a different account plane.
|
| 2502 |
+
|
| 2503 |
+
Since W46-T27 the ``raw`` value is the Route's saved assignee, so a refusal here means that
|
| 2504 |
+
account is no longer permitted or active, and the fix is to reassign the Route.
|
| 2505 |
"""
|
| 2506 |
return _route_assignee_or_400(
|
| 2507 |
session, raw, directory=directory, code="unknown_route_recipient",
|
| 2508 |
+
message="reassign this Route to a currently permitted person, then schedule it again")
|
| 2509 |
|
| 2510 |
|
| 2511 |
def _route_view_revision(view_id, config):
|
|
|
|
| 2525 |
session, route, body, *, source_views=None, permitted=None, recipient_directory=None):
|
| 2526 |
"""Build the immutable delivery exclusively from a normalized Route and server reads.
|
| 2527 |
|
| 2528 |
+
The browser may choose the timezone and the bounded Maps chunk size. It cannot send the
|
| 2529 |
+
recipient, View configuration, revision, Route name, or stop ids: all of those are resolved
|
| 2530 |
+
again here from the saved Route and its real source View at the moment the schedule is created.
|
| 2531 |
+
|
| 2532 |
+
W46-T27: the recipient is the Route's own saved assignee, which is already a resolved account,
|
| 2533 |
+
rather than a free-text username typed into the browser. A ``recipient`` key in the body is
|
| 2534 |
+
ignored so an older client keeps working; the stored ``config.recipient`` shape is unchanged.
|
| 2535 |
"""
|
| 2536 |
from core import route_system
|
| 2537 |
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
|
| 2538 |
|
| 2539 |
body = body if isinstance(body, dict) else {}
|
| 2540 |
+
assignee = str(route.get("assignee") or "").strip()
|
| 2541 |
+
if not assignee:
|
| 2542 |
+
raise err(400, "route_assignee_required",
|
| 2543 |
+
"assign this Route to a person first, then schedule its daily delivery")
|
| 2544 |
recipient = _route_delivery_recipient_or_400(
|
| 2545 |
+
session, assignee, directory=recipient_directory)
|
| 2546 |
source_view_id = str(route.get("sourceViewId") or "").strip()
|
| 2547 |
if not source_view_id:
|
| 2548 |
raise err(409, "route_source_view_missing",
|
api/routes_geo.py
CHANGED
|
@@ -38,6 +38,7 @@ is what every OSM client does and what the tile policy expects. Proxying them th
|
|
| 38 |
would put a free tier in the path of every pan and would breach the same policy it looks like it is
|
| 39 |
respecting. This door serves the tile URL, never the tile.
|
| 40 |
"""
|
|
|
|
| 41 |
import os
|
| 42 |
import re
|
| 43 |
import threading
|
|
@@ -651,95 +652,350 @@ def geo_geocode(body: dict = Body(...), session: Session = Depends(require_sessi
|
|
| 651 |
"attribution": provider_config()["geocode"]["attribution"]}
|
| 652 |
|
| 653 |
|
| 654 |
-
|
| 655 |
-
|
| 656 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 657 |
|
| 658 |
-
β THE ORDERING IS NOT DONE HERE. `mapProjection.planRoute` sequences the stops on the client,
|
| 659 |
-
for free, and keeps working when this service does not answer. This door adds the half that
|
| 660 |
-
arithmetic cannot produce: what the ROADS actually cost. Splitting it that way is why the Start
|
| 661 |
-
picker and the round-trip toggle keep working with no network at all."""
|
| 662 |
-
stops = body.get("stops")
|
| 663 |
-
if not isinstance(stops, list) or len(stops) < 2:
|
| 664 |
-
raise err(400, "too_few_stops", "A route needs at least two stops with a location.")
|
| 665 |
-
if len(stops) > MAX_ROUTE_STOPS:
|
| 666 |
-
raise err(400, "too_many_stops",
|
| 667 |
-
f"Route at most {MAX_ROUTE_STOPS} stops at once. Narrow the selection and try again.")
|
| 668 |
-
pairs = []
|
| 669 |
-
for s in stops:
|
| 670 |
-
try:
|
| 671 |
-
lat, lon = float(s["lat"]), float(s["lon"])
|
| 672 |
-
except (TypeError, ValueError, KeyError, IndexError):
|
| 673 |
-
raise err(400, "bad_stop", "Every stop needs a numeric latitude and longitude.")
|
| 674 |
-
if not (-90 <= lat <= 90) or not (-180 <= lon <= 180):
|
| 675 |
-
raise err(400, "bad_stop", "Every stop needs a latitude and longitude on the globe.")
|
| 676 |
-
pairs.append(f"{lon:.6f},{lat:.6f}")
|
| 677 |
|
| 678 |
-
|
| 679 |
-
|
| 680 |
-
|
| 681 |
-
|
| 682 |
-
|
| 683 |
-
|
| 684 |
-
|
| 685 |
-
|
| 686 |
-
|
| 687 |
-
|
| 688 |
-
|
| 689 |
-
|
| 690 |
-
|
| 691 |
-
# the toggle. That is the safe direction for a courtesy limit on a free shared service, and it
|
| 692 |
-
# keeps the single-timestamp invariant the module header argues for.
|
| 693 |
_throttle(_env_int("AIOS_GEOCODE_MIN_INTERVAL_MS", _MIN_INTERVAL_MS_DEFAULT))
|
| 694 |
try:
|
| 695 |
r = requests.get(
|
| 696 |
-
base.rstrip("/") + "/" +
|
| 697 |
params={"overview": "simplified", "geometries": "geojson", "steps": "false"},
|
| 698 |
headers={"User-Agent": _env("AIOS_GEO_USER_AGENT", _UA_DEFAULT)},
|
| 699 |
-
timeout=
|
| 700 |
)
|
| 701 |
r.raise_for_status()
|
| 702 |
data = r.json()
|
| 703 |
except requests.Timeout:
|
|
|
|
|
|
|
| 704 |
raise err(504, "route_service_timeout",
|
| 705 |
-
|
| 706 |
-
|
| 707 |
except requests.HTTPError as exc:
|
|
|
|
|
|
|
| 708 |
status = getattr(exc.response, "status_code", None)
|
| 709 |
suffix = f" (HTTP {status})" if status else ""
|
| 710 |
raise err(502, "route_service_http_error",
|
| 711 |
-
|
| 712 |
-
|
| 713 |
except (TypeError, ValueError):
|
|
|
|
|
|
|
| 714 |
raise err(502, "route_service_invalid_response",
|
| 715 |
-
|
| 716 |
-
|
| 717 |
except requests.RequestException:
|
|
|
|
|
|
|
| 718 |
raise err(502, "route_service_unavailable",
|
| 719 |
-
|
| 720 |
-
|
| 721 |
routes = (data or {}).get("routes") or []
|
| 722 |
if not routes:
|
| 723 |
-
|
| 724 |
-
|
| 725 |
-
|
| 726 |
-
|
| 727 |
-
|
| 728 |
-
|
|
|
|
| 729 |
top = routes[0]
|
| 730 |
-
|
|
|
|
| 731 |
line = []
|
| 732 |
-
for c in
|
| 733 |
try:
|
| 734 |
line.append([float(c[0]), float(c[1])])
|
| 735 |
except (TypeError, ValueError, IndexError):
|
| 736 |
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 737 |
return {
|
| 738 |
-
|
| 739 |
-
"
|
| 740 |
-
"
|
|
|
|
| 741 |
# The mode rides the answer so the client cannot label a driving route as a walk when a
|
| 742 |
# request is in flight and the toggle moves underneath it.
|
| 743 |
"mode": mode,
|
| 744 |
"attribution": credit,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 745 |
}
|
|
|
|
| 38 |
would put a free tier in the path of every pan and would breach the same policy it looks like it is
|
| 39 |
respecting. This door serves the tile URL, never the tile.
|
| 40 |
"""
|
| 41 |
+
import math
|
| 42 |
import os
|
| 43 |
import re
|
| 44 |
import threading
|
|
|
|
| 652 |
"attribution": provider_config()["geocode"]["attribution"]}
|
| 653 |
|
| 654 |
|
| 655 |
+
# ------------------------------------------------- W46-T18 / C2: the road answer, twice
|
| 656 |
+
#
|
| 657 |
+
# ββ WHY THIS DOOR NOW MEASURES TWO ORDERS AND NOT ONE.
|
| 658 |
+
# Instruction 9 asks how much time is SAVED by switching the stops around. A saving is a
|
| 659 |
+
# difference, and a difference is only honest when both halves were measured the same way. The
|
| 660 |
+
# old door answered one order, so the only way to quote a saving was to estimate one side and
|
| 661 |
+
# compare it against a measurement, which is an estimate of an estimate wearing a road number's
|
| 662 |
+
# clothes. `geo_route` therefore routes the order it was GIVEN and the order this file works
|
| 663 |
+
# out, and hands both back under C2's shape.
|
| 664 |
+
#
|
| 665 |
+
# β AND IT DOES NOT COST A SECOND REQUEST WHEN THERE IS NOTHING TO COMPARE. When the derived
|
| 666 |
+
# order equals the submitted one, which is the normal case for the map (its caller already
|
| 667 |
+
# sequences with `mapProjection.planRoute`), the one measurement is reused for both halves and
|
| 668 |
+
# the saving is a true zero. Only a hand-arranged order that really differs spends the second
|
| 669 |
+
# call, and the process-wide `_throttle` then serialises the two at 2.2 s or more. That is
|
| 670 |
+
# affordable ONCE on a drop, and it is exactly why a drag preview must stay on the client's
|
| 671 |
+
# arithmetic and never touch this door.
|
| 672 |
+
|
| 673 |
+
#: Assumed average road speed when nothing but arithmetic answered, and the factor that turns a
|
| 674 |
+
#: straight line into a plausible road length.
|
| 675 |
+
#: β MIRRORED in `aios-web/web/src/customer-grid/mapProjection.ts` as `ROUTE_ESTIMATE_KMH` and
|
| 676 |
+
#: `ROUTE_ROAD_DETOUR`, so a drag preview and a fallback answer cannot disagree about the same
|
| 677 |
+
#: stops. Change one and change the other.
|
| 678 |
+
ROUTE_ESTIMATE_KMH = 40.0
|
| 679 |
+
ROUTE_ROAD_DETOUR = 1.25
|
| 680 |
+
|
| 681 |
+
#: Above this implied speed a WALKING answer is not walking. See `_ROUTE_URL_WALKING_DEFAULT`:
|
| 682 |
+
#: the public demo server serves car numbers for every profile in the path, with HTTP 200. The
|
| 683 |
+
#: numbers are then real, they are simply about a car, and `caveat` is where that gets said.
|
| 684 |
+
_WALK_MAX_KMH = 9.0
|
| 685 |
+
|
| 686 |
+
_ROUTE_TIMEOUT_S = 20
|
| 687 |
+
#: The comparison call is the second of two and always has a fallback under it, so it waits less.
|
| 688 |
+
#: 2.2 s of throttle plus two 20 s timeouts is 42 s, which is longer than several proxies allow.
|
| 689 |
+
_ROUTE_COMPARE_TIMEOUT_S = 12
|
| 690 |
+
|
| 691 |
+
_FALLBACK_CAVEAT = ("Estimated from straight line distances because the routing service did not "
|
| 692 |
+
"answer, so treat these times as approximate.")
|
| 693 |
+
|
| 694 |
+
|
| 695 |
+
def _haversine_m(a, b):
|
| 696 |
+
"""Great circle metres between two `(lat, lon)` pairs."""
|
| 697 |
+
d_lat = math.radians(b[0] - a[0])
|
| 698 |
+
d_lon = math.radians(b[1] - a[1])
|
| 699 |
+
h = (math.sin(d_lat / 2) ** 2
|
| 700 |
+
+ math.cos(math.radians(a[0])) * math.cos(math.radians(b[0])) * math.sin(d_lon / 2) ** 2)
|
| 701 |
+
return 2 * 6371008.8 * math.asin(min(1.0, math.sqrt(h)))
|
| 702 |
+
|
| 703 |
+
|
| 704 |
+
def optimize_order(points, closed=False):
|
| 705 |
+
"""Nearest neighbour then 2-opt over straight line distance, index 0 PINNED.
|
| 706 |
+
|
| 707 |
+
β The same algorithm the client runs in `mapProjection.planRoute`, and index 0 is pinned here
|
| 708 |
+
for the reason it is pinned there: the first stop is where the person actually starts their
|
| 709 |
+
day, and quietly re-rooting their route would be a worse answer than a slightly longer one.
|
| 710 |
+
Only strictly improving swaps are taken, so the result is never longer than the order it was
|
| 711 |
+
handed, which is what makes a negative saving a fact about the ROADS rather than a bug.
|
| 712 |
+
|
| 713 |
+
ββ `closed` IS NOT A REFINEMENT, IT IS THE OTHER HALF OF THE ARITHMETIC. Reversing the tail
|
| 714 |
+
of an OPEN path only re-hangs the entry edge, because there is nothing after the last stop to
|
| 715 |
+
pay for; a day that drives HOME has a closing edge, and a swap that shortens the outward leg
|
| 716 |
+
can lengthen the way back by more. Solving a round trip with the open formula answers a
|
| 717 |
+
different question with an entirely plausible order, and it does something worse here than
|
| 718 |
+
return a slightly long route: the caller's own plan was solved CLOSED, so the two disagree,
|
| 719 |
+
`changed` goes true on a route nobody reordered, and every round trip spends a second provider
|
| 720 |
+
call to compare an order against a worse one. `mapProjection.twoOptOrder` carries this same
|
| 721 |
+
arm under the name `roundTrip`."""
|
| 722 |
+
n = len(points)
|
| 723 |
+
if n < 2:
|
| 724 |
+
return list(range(n))
|
| 725 |
+
seen = [False] * n
|
| 726 |
+
order = [0]
|
| 727 |
+
seen[0] = True
|
| 728 |
+
for _ in range(1, n):
|
| 729 |
+
last = order[-1]
|
| 730 |
+
best, best_d = -1, float("inf")
|
| 731 |
+
for i in range(n):
|
| 732 |
+
if seen[i]:
|
| 733 |
+
continue
|
| 734 |
+
d = _haversine_m(points[last], points[i])
|
| 735 |
+
if d < best_d:
|
| 736 |
+
best, best_d = i, d
|
| 737 |
+
if best < 0:
|
| 738 |
+
break
|
| 739 |
+
seen[best] = True
|
| 740 |
+
order.append(best)
|
| 741 |
+
if len(order) < 4:
|
| 742 |
+
return order
|
| 743 |
+
for _ in range(24):
|
| 744 |
+
improved = False
|
| 745 |
+
for i in range(1, len(order) - 1):
|
| 746 |
+
for j in range(i + 1, len(order)):
|
| 747 |
+
a, b, c = order[i - 1], order[i], order[j]
|
| 748 |
+
if j == len(order) - 1 and not closed:
|
| 749 |
+
delta = _haversine_m(points[a], points[c]) - _haversine_m(points[a], points[b])
|
| 750 |
+
else:
|
| 751 |
+
d = order[(j + 1) % len(order)]
|
| 752 |
+
delta = (_haversine_m(points[a], points[c])
|
| 753 |
+
+ _haversine_m(points[b], points[d])
|
| 754 |
+
- _haversine_m(points[a], points[b])
|
| 755 |
+
- _haversine_m(points[c], points[d]))
|
| 756 |
+
if delta < -1e-9:
|
| 757 |
+
order[i:j + 1] = order[i:j + 1][::-1]
|
| 758 |
+
improved = True
|
| 759 |
+
if not improved:
|
| 760 |
+
break
|
| 761 |
+
return order
|
| 762 |
+
|
| 763 |
+
|
| 764 |
+
def tour_metres(points, order, closed=False):
|
| 765 |
+
"""Straight line length of one visit order, closing the loop when the day drives home."""
|
| 766 |
+
if len(order) < 2:
|
| 767 |
+
return 0.0
|
| 768 |
+
total = sum(_haversine_m(points[order[i - 1]], points[order[i]]) for i in range(1, len(order)))
|
| 769 |
+
if closed:
|
| 770 |
+
total += _haversine_m(points[order[-1]], points[order[0]])
|
| 771 |
+
return total
|
| 772 |
+
|
| 773 |
+
|
| 774 |
+
def _straight_line_leg(points, caveat):
|
| 775 |
+
"""The arithmetic answer: what C2 calls `source: "haversine"`."""
|
| 776 |
+
metres = sum(_haversine_m(points[i - 1], points[i]) for i in range(1, len(points)))
|
| 777 |
+
metres *= ROUTE_ROAD_DETOUR
|
| 778 |
+
return {
|
| 779 |
+
"meters": int(round(metres)),
|
| 780 |
+
"seconds": int(round(metres / 1000.0 / ROUTE_ESTIMATE_KMH * 3600.0)),
|
| 781 |
+
"line": [[round(p[1], 6), round(p[0], 6)] for p in points],
|
| 782 |
+
"source": "haversine",
|
| 783 |
+
"caveat": caveat,
|
| 784 |
+
}
|
| 785 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 786 |
|
| 787 |
+
def _osrm_leg(points, mode, base, timeout, allow_fallback):
|
| 788 |
+
"""One measured leg under C2: `{meters, seconds, line, source, caveat}`.
|
| 789 |
+
|
| 790 |
+
β `source` REPORTS WHO ANSWERED, and `caveat` reports why the answer may not be what was
|
| 791 |
+
asked for. They are two different facts, and collapsing them loses the one that matters: an
|
| 792 |
+
OSRM reply is still `source: "osrm"` when the walking profile handed back car speeds, because
|
| 793 |
+
OSRM really did answer. What the caveat carries is that nobody walks at 39 km/h.
|
| 794 |
+
|
| 795 |
+
`allow_fallback` decides what a provider failure MEANS. False keeps every error this door has
|
| 796 |
+
always raised, so the callers that read a 502 and keep their own straight line on the map are
|
| 797 |
+
untouched. True turns the same failure into C2's other `source`, which is the only way that
|
| 798 |
+
half of the union is ever reachable."""
|
| 799 |
+
pairs = ";".join(f"{p[1]:.6f},{p[0]:.6f}" for p in points)
|
|
|
|
|
|
|
| 800 |
_throttle(_env_int("AIOS_GEOCODE_MIN_INTERVAL_MS", _MIN_INTERVAL_MS_DEFAULT))
|
| 801 |
try:
|
| 802 |
r = requests.get(
|
| 803 |
+
base.rstrip("/") + "/" + pairs,
|
| 804 |
params={"overview": "simplified", "geometries": "geojson", "steps": "false"},
|
| 805 |
headers={"User-Agent": _env("AIOS_GEO_USER_AGENT", _UA_DEFAULT)},
|
| 806 |
+
timeout=timeout,
|
| 807 |
)
|
| 808 |
r.raise_for_status()
|
| 809 |
data = r.json()
|
| 810 |
except requests.Timeout:
|
| 811 |
+
if allow_fallback:
|
| 812 |
+
return _straight_line_leg(points, _FALLBACK_CAVEAT)
|
| 813 |
raise err(504, "route_service_timeout",
|
| 814 |
+
f"OSRM routing timed out after {int(timeout)} seconds. The stop order and the "
|
| 815 |
+
"straight-line estimate are still on the map; try Driving route again.")
|
| 816 |
except requests.HTTPError as exc:
|
| 817 |
+
if allow_fallback:
|
| 818 |
+
return _straight_line_leg(points, _FALLBACK_CAVEAT)
|
| 819 |
status = getattr(exc.response, "status_code", None)
|
| 820 |
suffix = f" (HTTP {status})" if status else ""
|
| 821 |
raise err(502, "route_service_http_error",
|
| 822 |
+
f"OSRM routing returned an upstream error{suffix}. The stop order and the "
|
| 823 |
+
"straight-line estimate are still on the map; try again shortly.")
|
| 824 |
except (TypeError, ValueError):
|
| 825 |
+
if allow_fallback:
|
| 826 |
+
return _straight_line_leg(points, _FALLBACK_CAVEAT)
|
| 827 |
raise err(502, "route_service_invalid_response",
|
| 828 |
+
"OSRM routing returned an invalid answer. The stop order and the straight-line "
|
| 829 |
+
"estimate are still on the map; try again shortly.")
|
| 830 |
except requests.RequestException:
|
| 831 |
+
if allow_fallback:
|
| 832 |
+
return _straight_line_leg(points, _FALLBACK_CAVEAT)
|
| 833 |
raise err(502, "route_service_unavailable",
|
| 834 |
+
"OSRM routing could not be reached. The stop order and the straight-line "
|
| 835 |
+
"estimate are still on the map; try again shortly.")
|
| 836 |
routes = (data or {}).get("routes") or []
|
| 837 |
if not routes:
|
| 838 |
+
if allow_fallback:
|
| 839 |
+
return _straight_line_leg(
|
| 840 |
+
points,
|
| 841 |
+
"No road route connects these stops, so the time shown is a straight line estimate.")
|
| 842 |
+
raise err(502, "no_route",
|
| 843 |
+
"No road route connects these stops. They may be on different land masses, or "
|
| 844 |
+
"one of them may be far from any road.")
|
| 845 |
top = routes[0]
|
| 846 |
+
metres = float(top.get("distance") or 0.0)
|
| 847 |
+
seconds = float(top.get("duration") or 0.0)
|
| 848 |
line = []
|
| 849 |
+
for c in ((top.get("geometry") or {}).get("coordinates")) or []:
|
| 850 |
try:
|
| 851 |
line.append([float(c[0]), float(c[1])])
|
| 852 |
except (TypeError, ValueError, IndexError):
|
| 853 |
continue
|
| 854 |
+
caveat = None
|
| 855 |
+
if mode == "walking" and seconds > 0:
|
| 856 |
+
kmh = (metres / 1000.0) / (seconds / 3600.0)
|
| 857 |
+
if kmh > _WALK_MAX_KMH:
|
| 858 |
+
caveat = (f"This deployment answered the walking request at about {int(round(kmh))} "
|
| 859 |
+
"km/h, which is a driving profile rather than a walking one, so treat the "
|
| 860 |
+
"walking time as a rough guide.")
|
| 861 |
+
return {"meters": int(round(metres)), "seconds": int(round(seconds)), "line": line,
|
| 862 |
+
"source": "osrm", "caveat": caveat}
|
| 863 |
+
|
| 864 |
+
|
| 865 |
+
@router.post("/geo/route")
|
| 866 |
+
def geo_route(body: dict = Body(...), session: Session = Depends(require_session)):
|
| 867 |
+
"""Road distance, duration and the drawn line, for the order given AND for a better one.
|
| 868 |
+
|
| 869 |
+
β THE ORDERING IS STILL THE CLIENT'S. `mapProjection.planRoute` sequences the stops for free
|
| 870 |
+
and keeps working when this service does not answer, and the map keeps calling this door with
|
| 871 |
+
stops already in the order it drew. What W46-T18 adds is the COMPARISON: this door also works
|
| 872 |
+
out the order it would choose and, when that differs from the one it was handed, measures it
|
| 873 |
+
too. The saving is then the difference of two measured numbers rather than an estimate held
|
| 874 |
+
up against a measurement.
|
| 875 |
+
|
| 876 |
+
β THE ANSWER IS A SUPERSET, on purpose. `km`, `minutes`, `line`, `mode` and `attribution` are
|
| 877 |
+
what the map has read since wave 37 and they still mean exactly what they meant. C2's
|
| 878 |
+
`ordered`, `meters`, `seconds`, `source` and `caveat` sit beside them: `meters` and `seconds`
|
| 879 |
+
are the precise integers, `km` and `minutes` the rounded pair a caption uses.
|
| 880 |
+
|
| 881 |
+
Request body:
|
| 882 |
+
`stops` [{lat, lon, pid?}] the order to measure, at least two.
|
| 883 |
+
`roundTrip` bool, informational. A caller that wants to come home appends a copy of the
|
| 884 |
+
first stop, and that closing duplicate is detected and kept out of the
|
| 885 |
+
optimizer rather than being treated as a real place to visit.
|
| 886 |
+
`mode` "driving" | "walking".
|
| 887 |
+
`fallback` bool, default FALSE, and the default is the whole point. Every error this door
|
| 888 |
+
raised before it is still raised, so the map's existing 502 handling, which
|
| 889 |
+
leaves the client's own straight line on screen, is untouched. A caller that
|
| 890 |
+
would rather have an approximate number than an error asks for it explicitly
|
| 891 |
+
and is told through `source` and `caveat` exactly what it got.
|
| 892 |
+
"""
|
| 893 |
+
stops = body.get("stops")
|
| 894 |
+
if not isinstance(stops, list) or len(stops) < 2:
|
| 895 |
+
raise err(400, "too_few_stops", "A route needs at least two stops with a location.")
|
| 896 |
+
if len(stops) > MAX_ROUTE_STOPS:
|
| 897 |
+
raise err(400, "too_many_stops",
|
| 898 |
+
f"Route at most {MAX_ROUTE_STOPS} stops at once. Narrow the selection and try again.")
|
| 899 |
+
points, pids = [], []
|
| 900 |
+
for i, s in enumerate(stops):
|
| 901 |
+
try:
|
| 902 |
+
lat, lon = float(s["lat"]), float(s["lon"])
|
| 903 |
+
except (TypeError, ValueError, KeyError, IndexError):
|
| 904 |
+
raise err(400, "bad_stop", "Every stop needs a numeric latitude and longitude.")
|
| 905 |
+
if not (-90 <= lat <= 90) or not (-180 <= lon <= 180):
|
| 906 |
+
raise err(400, "bad_stop", "Every stop needs a latitude and longitude on the globe.")
|
| 907 |
+
points.append((lat, lon))
|
| 908 |
+
try:
|
| 909 |
+
pids.append(int(s.get("pid")) if isinstance(s, dict) and s.get("pid") is not None else i)
|
| 910 |
+
except (TypeError, ValueError):
|
| 911 |
+
pids.append(i)
|
| 912 |
+
|
| 913 |
+
# β THE MODE PICKS THE SERVER. See `_ROUTE_URL_WALKING_DEFAULT` for why it is not a path
|
| 914 |
+
# segment: the demo car server answers `/foot/` with car numbers, so substituting the profile
|
| 915 |
+
# would have shipped a walking label over driving minutes.
|
| 916 |
+
mode = _route_mode(body.get("mode"))
|
| 917 |
+
base, credit = route_mode_config(mode)
|
| 918 |
+
if not base:
|
| 919 |
+
raise err(400, "route_mode_unavailable",
|
| 920 |
+
f"This deployment has no {'walking' if mode == 'walking' else 'driving'} "
|
| 921 |
+
f"routing service configured, so a {'walking' if mode == 'walking' else 'driving'} "
|
| 922 |
+
f"time cannot be worked out. The stop order and the straight-line estimate are "
|
| 923 |
+
f"still on the map.")
|
| 924 |
+
|
| 925 |
+
# ββ THE CLOSING STOP IS NOT A PLACE TO VISIT. A round trip arrives here as N+1 coordinates
|
| 926 |
+
# whose last one is a copy of the first, because that is how the caller asks for the drive
|
| 927 |
+
# home. Handing that list to the optimizer would let it treat the duplicate as an ordinary
|
| 928 |
+
# stop and return a plausible, wrong order, so the closing leg is taken off before solving
|
| 929 |
+
# and put back on afterwards.
|
| 930 |
+
closed = len(points) >= 3 and points[0] == points[-1]
|
| 931 |
+
core = points[:-1] if closed else points
|
| 932 |
+
core_pids = pids[:-1] if closed else pids
|
| 933 |
+
|
| 934 |
+
# β SOLVED THE WAY THE CALLER SOLVED IT. `closed` is passed on, or a round trip is compared
|
| 935 |
+
# against an open-path optimum: a different question, answered confidently, that also makes
|
| 936 |
+
# every round trip look reordered and spend a second provider call for nothing.
|
| 937 |
+
best = optimize_order(core, closed)
|
| 938 |
+
# ββ A REORDER IS ONLY OFFERED WHEN IT IS SHORTER BY THE MEASURE THAT CHOSE IT.
|
| 939 |
+
# A different permutation is not the same fact as a better route. The caller's order usually
|
| 940 |
+
# already came from `mapProjection.planRoute`, which is this same construct-then-improve pass,
|
| 941 |
+
# so anything the solver hands back for it is at best a tie; without this clause a tie would
|
| 942 |
+
# read as a reorder, spend the second provider call, and quote the person a saving that is
|
| 943 |
+
# really the difference between two runs of the same algorithm. One metre, not zero, because
|
| 944 |
+
# the comparison is floating point and a tie does not land exactly on it.
|
| 945 |
+
gain = tour_metres(core, list(range(len(core))), closed) - tour_metres(core, best, closed)
|
| 946 |
+
changed = best != list(range(len(core))) and gain > 1.0
|
| 947 |
+
|
| 948 |
+
allow_fallback = bool(body.get("fallback"))
|
| 949 |
+
current = _osrm_leg(points, mode, base, _ROUTE_TIMEOUT_S, allow_fallback)
|
| 950 |
+
|
| 951 |
+
if changed:
|
| 952 |
+
moved = [core[i] for i in best]
|
| 953 |
+
if closed:
|
| 954 |
+
moved = moved + [moved[0]]
|
| 955 |
+
# β THE COMPARISON LEG ALWAYS HAS ARITHMETIC UNDER IT. A new key must never be able to
|
| 956 |
+
# turn a request that answers 200 today into a 502, so a provider failure on the second
|
| 957 |
+
# call degrades that HALF to `source: "haversine"` and says so, whatever `fallback` said.
|
| 958 |
+
optimized = _osrm_leg(moved, mode, base, _ROUTE_COMPARE_TIMEOUT_S, True)
|
| 959 |
+
optimized_pids = [core_pids[i] for i in best]
|
| 960 |
+
else:
|
| 961 |
+
# β NOTHING TO COMPARE, SO NOTHING IS SPENT. The order already is the one this door would
|
| 962 |
+
# choose, which is the normal case for the map, so the single measurement answers both
|
| 963 |
+
# halves and the saving is a true zero rather than the noise of two calls.
|
| 964 |
+
optimized = dict(current)
|
| 965 |
+
optimized_pids = list(core_pids)
|
| 966 |
+
|
| 967 |
+
# β NOT CLAMPED AT ZERO. A negative saving is a real thing to learn: the order is chosen on
|
| 968 |
+
# straight lines and the roads can disagree, and hiding that would quietly recommend a swap
|
| 969 |
+
# that costs time. `comparable` says whether the two halves came from the same answerer, and
|
| 970 |
+
# a saving across two different sources is arithmetic between different units.
|
| 971 |
+
comparable = current["source"] == optimized["source"]
|
| 972 |
return {
|
| 973 |
+
# ---- what the map has read since wave 37, unchanged in name and meaning
|
| 974 |
+
"km": round(current["meters"] / 1000.0, 1),
|
| 975 |
+
"minutes": int(round(current["seconds"] / 60.0)),
|
| 976 |
+
"line": current["line"],
|
| 977 |
# The mode rides the answer so the client cannot label a driving route as a walk when a
|
| 978 |
# request is in flight and the toggle moves underneath it.
|
| 979 |
"mode": mode,
|
| 980 |
"attribution": credit,
|
| 981 |
+
# ---- C2, for the order as submitted
|
| 982 |
+
"ordered": core_pids,
|
| 983 |
+
"meters": current["meters"],
|
| 984 |
+
"seconds": current["seconds"],
|
| 985 |
+
"source": current["source"],
|
| 986 |
+
"caveat": current["caveat"],
|
| 987 |
+
# ---- C2, for the order this door would choose
|
| 988 |
+
"optimized": {
|
| 989 |
+
"ordered": optimized_pids,
|
| 990 |
+
"meters": optimized["meters"],
|
| 991 |
+
"seconds": optimized["seconds"],
|
| 992 |
+
"source": optimized["source"],
|
| 993 |
+
"caveat": optimized["caveat"],
|
| 994 |
+
"line": optimized["line"],
|
| 995 |
+
"changed": changed,
|
| 996 |
+
},
|
| 997 |
+
"savedSeconds": current["seconds"] - optimized["seconds"],
|
| 998 |
+
"savedMeters": current["meters"] - optimized["meters"],
|
| 999 |
+
"savingComparable": comparable,
|
| 1000 |
+
"roundTrip": bool(body.get("roundTrip")) or closed,
|
| 1001 |
}
|
api/routes_nav.py
CHANGED
|
@@ -877,6 +877,49 @@ def save_nav_prefs(body: dict = Body(default=None),
|
|
| 877 |
return {"prefs": clean}
|
| 878 |
|
| 879 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 880 |
@router.get("/nav/schema/{key}")
|
| 881 |
def nav_schema(key: str, session: Session = Depends(require_session)):
|
| 882 |
"""The database's schema drawer payload: its field contract + the semantic measures this
|
|
@@ -933,13 +976,18 @@ def nav_schema(key: str, session: Session = Depends(require_session)):
|
|
| 933 |
# WAVE 19 (R8) β the drawer wears the RENAMED name. A rail that says one thing and a
|
| 934 |
# schema panel opened from it that says another is the drift a rename is supposed to
|
| 935 |
# remove, not create.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 936 |
return {"key": key,
|
| 937 |
"label": (_read_nav_meta(session.runtime).get(key, {}).get("name")
|
| 938 |
or defn.get("label") or key),
|
| 939 |
"source": defn.get("source") or "Blank",
|
| 940 |
"fields": [{"key": f["key"], "label": f["label"], "type": f["type"],
|
| 941 |
"source": f.get("source") or "overlay",
|
| 942 |
-
"description": str(f.get("description") or "")
|
|
|
|
| 943 |
for f in base if f.get("key") not in hidden],
|
| 944 |
"measures": []}
|
| 945 |
session.require(key)
|
|
@@ -948,6 +996,13 @@ def nav_schema(key: str, session: Session = Depends(require_session)):
|
|
| 948 |
if page is None:
|
| 949 |
raise err(404, "unknown_page", f"{key!r} is not a database this session can see")
|
| 950 |
fields = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 951 |
if key in ("customer_data", "cohort", "customers"):
|
| 952 |
try:
|
| 953 |
import aios_grid
|
|
@@ -968,17 +1023,29 @@ def nav_schema(key: str, session: Session = Depends(require_session)):
|
|
| 968 |
# direction a schema door may fail, and the gate's ADMIN control is what stops that
|
| 969 |
# silent empty being mistaken for a wall that worked.
|
| 970 |
hidden = _rc._hidden_for(session)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 971 |
for f in aios_grid.FIELDS:
|
| 972 |
if f["key"] in hidden:
|
| 973 |
continue
|
| 974 |
entry = {"key": f["key"], "label": f["label"], "type": f["type"],
|
| 975 |
"source": f["source"],
|
| 976 |
-
"description": str(f.get("description") or "")
|
|
|
|
| 977 |
if f.get("options"):
|
| 978 |
entry["options"] = list(f["options"])
|
| 979 |
fields.append(entry)
|
| 980 |
except Exception:
|
| 981 |
fields = []
|
|
|
|
| 982 |
measures = []
|
| 983 |
try:
|
| 984 |
from core import measure_resolve
|
|
@@ -1003,6 +1070,23 @@ def nav_schema(key: str, session: Session = Depends(require_session)):
|
|
| 1003 |
out = {"key": key, "label": page.get("label") or key,
|
| 1004 |
"source": page.get("source") or "", "fields": fields, "measures": measures}
|
| 1005 |
if not fields:
|
| 1006 |
-
#
|
| 1007 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1008 |
return out
|
|
|
|
| 877 |
return {"prefs": clean}
|
| 878 |
|
| 879 |
|
| 880 |
+
def _schema_means(key: str) -> dict:
|
| 881 |
+
"""`{field_key: the agent's semantic definition}` for a database, or `{}` when there is none.
|
| 882 |
+
|
| 883 |
+
β W46-T45 (owner instruction 23) β THE `means:` LINES IN `platform/model/topics/*.yml`,
|
| 884 |
+
READ THROUGH THE MODEL LOADER AND NEVER PARSED BY HAND. `semantic.topic_for_grid` is the one
|
| 885 |
+
function that knows which topic a grid key maps to, and `semantic_fields` is the one that
|
| 886 |
+
knows a field's `purpose`; a second reader of that yml here would be a second idea of what a
|
| 887 |
+
field means, drifting from the one the agent itself is briefed with.
|
| 888 |
+
|
| 889 |
+
β NO TOPIC NAME IS HARDCODED, and that is what makes the `ut_*` branch correct rather than
|
| 890 |
+
merely harmless. `topic_for_grid` answers None for every user table today, so that branch
|
| 891 |
+
emits empty strings; the day a user table earns a topic, this returns its definitions with no
|
| 892 |
+
edit here. A name typed in this file would have to be found and changed instead.
|
| 893 |
+
|
| 894 |
+
β FAIL SOFT, THE OPPOSITE DIRECTION FROM THE FIELD WALL ABOVE. A wall that cannot compute
|
| 895 |
+
must narrow (fail closed); a DEFINITION that cannot be read is decoration, and 500ing the
|
| 896 |
+
whole drawer because the model did not load would be a worse answer than a panel with one
|
| 897 |
+
column blank. `routes_admin.py`'s semantic import is the house pattern this follows.
|
| 898 |
+
"""
|
| 899 |
+
try:
|
| 900 |
+
import harness.semantic as semantic
|
| 901 |
+
from routes_query import _no_dashes
|
| 902 |
+
topic = semantic.topic_for_grid(key)
|
| 903 |
+
if not topic:
|
| 904 |
+
return {}
|
| 905 |
+
out = {}
|
| 906 |
+
for fkey, meta in (semantic.semantic_fields(topic) or {}).items():
|
| 907 |
+
if not isinstance(meta, dict):
|
| 908 |
+
continue
|
| 909 |
+
# ββ STANDING RULE 2 AT THE DOOR, WHICH IS THE ONLY PLACE IT CAN BE APPLIED, AND THE
|
| 910 |
+
# FOURTH DOOR OF ONE BEHAVIOUR (wave 36; `routes_query._no_dashes`). `verify_prose`
|
| 911 |
+
# scans `aios-web/api`, `platform/core` and `platform/modules` β NOT
|
| 912 |
+
# `platform/model/topics/*.yml` and NOT `platform/harness` β so the dashes the model's
|
| 913 |
+
# own prose carries are invisible to it and would reach the panel with the gate green.
|
| 914 |
+
# β IMPORTED, NOT COPIED: `routes_automation._draft_no_dashes` is already a second
|
| 915 |
+
# copy and its own comment regrets it. The helper also knows the edge a naive sweep
|
| 916 |
+
# gets wrong, a digit range becoming "10 to 20" rather than "10, 20".
|
| 917 |
+
out[str(fkey)] = _no_dashes(str(meta.get("purpose") or ""))
|
| 918 |
+
return out
|
| 919 |
+
except Exception: # noqa: BLE001
|
| 920 |
+
return {}
|
| 921 |
+
|
| 922 |
+
|
| 923 |
@router.get("/nav/schema/{key}")
|
| 924 |
def nav_schema(key: str, session: Session = Depends(require_session)):
|
| 925 |
"""The database's schema drawer payload: its field contract + the semantic measures this
|
|
|
|
| 976 |
# WAVE 19 (R8) β the drawer wears the RENAMED name. A rail that says one thing and a
|
| 977 |
# schema panel opened from it that says another is the drift a rename is supposed to
|
| 978 |
# remove, not create.
|
| 979 |
+
# β W46-T45 β the semantic definitions ride BOTH branches. `{}` today for every `ut_*`
|
| 980 |
+
# key, because no user table maps to a topic; see `_schema_means` for why that is written
|
| 981 |
+
# as a lookup rather than a special case.
|
| 982 |
+
ut_means = _schema_means(key)
|
| 983 |
return {"key": key,
|
| 984 |
"label": (_read_nav_meta(session.runtime).get(key, {}).get("name")
|
| 985 |
or defn.get("label") or key),
|
| 986 |
"source": defn.get("source") or "Blank",
|
| 987 |
"fields": [{"key": f["key"], "label": f["label"], "type": f["type"],
|
| 988 |
"source": f.get("source") or "overlay",
|
| 989 |
+
"description": str(f.get("description") or ""),
|
| 990 |
+
"means": ut_means.get(f["key"], "")}
|
| 991 |
for f in base if f.get("key") not in hidden],
|
| 992 |
"measures": []}
|
| 993 |
session.require(key)
|
|
|
|
| 996 |
if page is None:
|
| 997 |
raise err(404, "unknown_page", f"{key!r} is not a database this session can see")
|
| 998 |
fields = []
|
| 999 |
+
# β W46-T45 (D-447) β THREE SITUATIONS PRODUCED ONE SENTENCE, AND ONLY ONE OF THEM WAS TRUE.
|
| 1000 |
+
# `if not fields` is reached by (a) a key outside the customer family, where no contract was
|
| 1001 |
+
# ever assembled; (b) the `except` below firing, so the contract could not be read; and (c)
|
| 1002 |
+
# the field wall stripping every column, i.e. the reader is WALLED. These two flags are the
|
| 1003 |
+
# only way the note can tell them apart, because by then the list looks identical.
|
| 1004 |
+
contract_seen = False
|
| 1005 |
+
contract_failed = False
|
| 1006 |
if key in ("customer_data", "cohort", "customers"):
|
| 1007 |
try:
|
| 1008 |
import aios_grid
|
|
|
|
| 1023 |
# direction a schema door may fail, and the gate's ADMIN control is what stops that
|
| 1024 |
# silent empty being mistaken for a wall that worked.
|
| 1025 |
hidden = _rc._hidden_for(session)
|
| 1026 |
+
# β SET BEFORE THE LOOP, NEVER INSIDE IT. The question this answers is "does a
|
| 1027 |
+
# contract EXIST for this database", which is true whether or not a single field
|
| 1028 |
+
# survives the wall β and a flag raised inside the loop would say False in exactly
|
| 1029 |
+
# the walled case the note exists to describe.
|
| 1030 |
+
contract_seen = bool(aios_grid.FIELDS)
|
| 1031 |
+
# β W46-T45 β the agent's own definition of the field, beside the authored one.
|
| 1032 |
+
# β IT DOES NOT REPLACE `description`. They are two authored strings, near-identical
|
| 1033 |
+
# today for the Odoo customer contract and free to diverge; instruction 23 asks the
|
| 1034 |
+
# panel to show MORE, not to swap one for its twin.
|
| 1035 |
+
means = _schema_means(key)
|
| 1036 |
for f in aios_grid.FIELDS:
|
| 1037 |
if f["key"] in hidden:
|
| 1038 |
continue
|
| 1039 |
entry = {"key": f["key"], "label": f["label"], "type": f["type"],
|
| 1040 |
"source": f["source"],
|
| 1041 |
+
"description": str(f.get("description") or ""),
|
| 1042 |
+
"means": means.get(f["key"], "")}
|
| 1043 |
if f.get("options"):
|
| 1044 |
entry["options"] = list(f["options"])
|
| 1045 |
fields.append(entry)
|
| 1046 |
except Exception:
|
| 1047 |
fields = []
|
| 1048 |
+
contract_failed = True
|
| 1049 |
measures = []
|
| 1050 |
try:
|
| 1051 |
from core import measure_resolve
|
|
|
|
| 1070 |
out = {"key": key, "label": page.get("label") or key,
|
| 1071 |
"source": page.get("source") or "", "fields": fields, "measures": measures}
|
| 1072 |
if not fields:
|
| 1073 |
+
# ββ W46-T45 / D-447 β ONE EMPTY LIST, THREE ANSWERS, AND THE OLD SENTENCE WAS RIGHT FOR
|
| 1074 |
+
# EXACTLY ONE OF THEM. A fully walled reader was being told the database had published no
|
| 1075 |
+
# contract; it had, and the message sent them to an administrator asking for something
|
| 1076 |
+
# that already exists. Order matters: an exception can fire part-way through the loop, so
|
| 1077 |
+
# `contract_failed` is asked first and `contract_seen` may be true beside it.
|
| 1078 |
+
if contract_failed:
|
| 1079 |
+
# Honest about the instrument, not about the data: nothing was learned either way.
|
| 1080 |
+
out["note"] = "The field contract could not be read just now."
|
| 1081 |
+
elif contract_seen:
|
| 1082 |
+
# β NO COUNT, AND NO NAMES. The reader must learn that fields exist and that their
|
| 1083 |
+
# permissions are what hide them; how MANY is itself a fact about the contract, and
|
| 1084 |
+
# this route's W38-T18 comment is the argument for why a walled door does not leak
|
| 1085 |
+
# the shape of what it refused.
|
| 1086 |
+
out["note"] = "Your permissions hide every field in this database."
|
| 1087 |
+
else:
|
| 1088 |
+
# Honest, never a mock: a database whose contract is not yet published says so. This
|
| 1089 |
+
# is the sentence's ORIGINAL and still correct case, a key for which no field
|
| 1090 |
+
# contract was ever assembled.
|
| 1091 |
+
out["note"] = "This database has not published a field contract yet."
|
| 1092 |
return out
|
platform/aios_grid.py
CHANGED
|
@@ -685,9 +685,35 @@ def _clean_geocode(raw):
|
|
| 685 |
_RECURRENCE_KINDS = frozenset({'daily', 'weekly', 'monthly', 'yearly', 'holiday'})
|
| 686 |
# A calendar appears here only when the server really evaluates it. The Date picker reads this
|
| 687 |
# same registry, so a selector cannot promise a country whose recurrence becomes a no-op later.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 688 |
PUBLIC_HOLIDAY_CALENDARS = (
|
| 689 |
-
{'code': 'US', 'label': 'United States federal holidays'},
|
| 690 |
-
{'code': 'CA', 'label': 'Canada federal public holidays'},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 691 |
)
|
| 692 |
_PUBLIC_HOLIDAY_CALENDARS = frozenset(item['code'] for item in PUBLIC_HOLIDAY_CALENDARS)
|
| 693 |
_HOLIDAY_RELATIONS = {'day_before': -1, 'day_on': 0, 'day_after': 1}
|
|
@@ -745,6 +771,128 @@ def _easter_sunday(year):
|
|
| 745 |
return _dt.date(year, month, day)
|
| 746 |
|
| 747 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 748 |
def _canada_public_holidays(year):
|
| 749 |
"""Canada's federal public-service holiday schedule, deterministically calculated.
|
| 750 |
|
|
@@ -773,6 +921,20 @@ def _canada_public_holidays(year):
|
|
| 773 |
return frozenset(days)
|
| 774 |
|
| 775 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 776 |
def public_holidays(calendar, year):
|
| 777 |
"""A supported public holiday calendar, returned as deterministic ISO-day objects.
|
| 778 |
|
|
@@ -784,8 +946,18 @@ def public_holidays(calendar, year):
|
|
| 784 |
calendar = str(calendar or '').upper()
|
| 785 |
if calendar not in _PUBLIC_HOLIDAY_CALENDARS:
|
| 786 |
return frozenset()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 787 |
if calendar == 'CA':
|
| 788 |
-
return _canada_public_holidays(year)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 789 |
days = {
|
| 790 |
_observed(_dt.date(year, 1, 1)),
|
| 791 |
_nth_weekday(year, 1, 0, 3), # Martin Luther King Jr. Day
|
|
@@ -802,7 +974,32 @@ def public_holidays(calendar, year):
|
|
| 802 |
# retroactively invent it.
|
| 803 |
if year >= 2021:
|
| 804 |
days.add(_observed(_dt.date(year, 6, 19)))
|
| 805 |
-
return frozenset(days)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 806 |
|
| 807 |
|
| 808 |
def clean_date_recurrence(raw, condition_fields=None):
|
|
@@ -901,6 +1098,12 @@ def clean_date_recurrence(raw, condition_fields=None):
|
|
| 901 |
str(key) for key in admitted_conditions or () if str(key)})
|
| 902 |
if conditions:
|
| 903 |
out['conditions'] = conditions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 904 |
return out
|
| 905 |
|
| 906 |
|
|
@@ -939,14 +1142,26 @@ def recurrence_preview(raw, today=None, count=None, condition_fields=None):
|
|
| 939 |
if start is None:
|
| 940 |
return []
|
| 941 |
want = config['previewCount'] if count is None else max(1, min(int(count), 50))
|
| 942 |
-
|
| 943 |
# A preview of at most fifty values needs no unbounded search. Ten years also makes an
|
| 944 |
# unavailable public calendar visibly empty instead of spinning a request forever.
|
| 945 |
-
horizon =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 946 |
found, day = set(), lower
|
| 947 |
holiday_rules = [rule for rule in config['rules'] if rule['kind'] == 'holiday']
|
| 948 |
ordinary_rules = [rule for rule in config['rules'] if rule['kind'] != 'holiday']
|
| 949 |
-
while day <= horizon and len(found) <
|
| 950 |
if any(_recurrence_matches(day, start, rule) for rule in ordinary_rules):
|
| 951 |
found.add(day)
|
| 952 |
for rule in holiday_rules:
|
|
@@ -960,7 +1175,8 @@ def recurrence_preview(raw, today=None, count=None, condition_fields=None):
|
|
| 960 |
if occurrence == day and occurrence >= start:
|
| 961 |
found.add(day)
|
| 962 |
day += _dt.timedelta(days=1)
|
| 963 |
-
|
|
|
|
| 964 |
|
| 965 |
|
| 966 |
def recurrence_payload(raw, today=None, condition_fields=None):
|
|
@@ -3418,3 +3634,150 @@ def scope_counts(shown, matched, total):
|
|
| 3418 |
# bundle), `build_embed.py` that produced them, and `deploy_hf.py`'s embed-staleness guard. The
|
| 3419 |
# React app is now served directly by the FastAPI container β there is no twin to keep fresh, so
|
| 3420 |
# the entire class of "the code shipped but the bundle did not" is retired rather than guarded.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 685 |
_RECURRENCE_KINDS = frozenset({'daily', 'weekly', 'monthly', 'yearly', 'holiday'})
|
| 686 |
# A calendar appears here only when the server really evaluates it. The Date picker reads this
|
| 687 |
# same registry, so a selector cannot promise a country whose recurrence becomes a no-op later.
|
| 688 |
+
#
|
| 689 |
+
# ββ W46-T33 (owner instruction 13, ruling R11: fixed-date plus floating "plus religious
|
| 690 |
+
# holidays too including jewish holidays"). A recurrence may now name ONE holiday instead of a
|
| 691 |
+
# whole national calendar, and the before/on/after offset already modelled in
|
| 692 |
+
# `_HOLIDAY_RELATIONS` applies to it unchanged. The granular codes live in THIS registry rather
|
| 693 |
+
# than a second one, so `_PUBLIC_HOLIDAY_CALENDARS` admits them at the field door, the Date
|
| 694 |
+
# picker reads them off the same wire, and `recurrence_preview`'s holiday loop needed no change.
|
| 695 |
+
# `group` is what lets the picker head its two option groups without a client-side copy of the
|
| 696 |
+
# list; it is additive, so an older client that ignores it still renders a flat, correct list.
|
| 697 |
PUBLIC_HOLIDAY_CALENDARS = (
|
| 698 |
+
{'code': 'US', 'label': 'United States federal holidays', 'group': 'calendar'},
|
| 699 |
+
{'code': 'CA', 'label': 'Canada federal public holidays', 'group': 'calendar'},
|
| 700 |
+
{'code': 'NEW_YEARS', 'label': "New Year's Day", 'group': 'holiday'},
|
| 701 |
+
{'code': 'VALENTINES', 'label': "Valentine's Day", 'group': 'holiday'},
|
| 702 |
+
{'code': 'EASTER', 'label': 'Easter Sunday', 'group': 'holiday'},
|
| 703 |
+
{'code': 'MOTHERS_DAY', 'label': "Mother's Day", 'group': 'holiday'},
|
| 704 |
+
{'code': 'MEMORIAL_DAY', 'label': 'Memorial Day', 'group': 'holiday'},
|
| 705 |
+
{'code': 'FATHERS_DAY', 'label': "Father's Day", 'group': 'holiday'},
|
| 706 |
+
{'code': 'INDEPENDENCE_DAY', 'label': 'Independence Day', 'group': 'holiday'},
|
| 707 |
+
{'code': 'LABOR_DAY', 'label': 'Labor Day', 'group': 'holiday'},
|
| 708 |
+
{'code': 'ROSH_HASHANAH', 'label': 'Rosh Hashanah', 'group': 'holiday'},
|
| 709 |
+
{'code': 'YOM_KIPPUR', 'label': 'Yom Kippur', 'group': 'holiday'},
|
| 710 |
+
{'code': 'HALLOWEEN', 'label': 'Halloween', 'group': 'holiday'},
|
| 711 |
+
{'code': 'THANKSGIVING', 'label': 'Thanksgiving', 'group': 'holiday'},
|
| 712 |
+
{'code': 'HANUKKAH', 'label': 'Hanukkah', 'group': 'holiday'},
|
| 713 |
+
{'code': 'CHRISTMAS_EVE', 'label': 'Christmas Eve', 'group': 'holiday'},
|
| 714 |
+
{'code': 'CHRISTMAS', 'label': 'Christmas Day', 'group': 'holiday'},
|
| 715 |
+
{'code': 'NEW_YEARS_EVE', 'label': "New Year's Eve", 'group': 'holiday'},
|
| 716 |
+
{'code': 'PASSOVER', 'label': 'Passover', 'group': 'holiday'},
|
| 717 |
)
|
| 718 |
_PUBLIC_HOLIDAY_CALENDARS = frozenset(item['code'] for item in PUBLIC_HOLIDAY_CALENDARS)
|
| 719 |
_HOLIDAY_RELATIONS = {'day_before': -1, 'day_on': 0, 'day_after': 1}
|
|
|
|
| 771 |
return _dt.date(year, month, day)
|
| 772 |
|
| 773 |
|
| 774 |
+
# ββ THE HEBREW CALENDAR, kept local for the same reason the computus is βββββββββββββββββββββββ
|
| 775 |
+
# R11 asks for Jewish holidays, and those are lunisolar: a hardcoded month and day would be wrong
|
| 776 |
+
# every year. So they are COMPUTED, with the arithmetic of Dershowitz & Reingold, and the answer
|
| 777 |
+
# stays available during an outage exactly like `_easter_sunday`'s.
|
| 778 |
+
#
|
| 779 |
+
# β `_HEBREW_EPOCH` IS -1373427, NOT -1373429. The off-by-two value returns every anchor exactly
|
| 780 |
+
# two days early across five Hebrew years and four Hebrew months, which reads as a broken
|
| 781 |
+
# algorithm rather than a wrong constant. RD 1 == 0001-01-01 proleptic Gregorian, which is
|
| 782 |
+
# precisely `datetime.date.fromordinal`'s origin, so no epoch shim is needed.
|
| 783 |
+
_HEBREW_EPOCH = -1373427
|
| 784 |
+
# Hebrew months are 1=Nisan .. 7=Tishrei .. 13=Adar II, and the YEAR begins at Tishrei (7).
|
| 785 |
+
_HEBREW_TISHREI, _HEBREW_NISAN, _HEBREW_KISLEV = 7, 1, 9
|
| 786 |
+
_HEBREW_YEAR_CACHE = {}
|
| 787 |
+
|
| 788 |
+
|
| 789 |
+
def _hebrew_leap(year):
|
| 790 |
+
return ((year * 7 + 1) % 19) < 7
|
| 791 |
+
|
| 792 |
+
|
| 793 |
+
def _hebrew_last_month(year):
|
| 794 |
+
return 13 if _hebrew_leap(year) else 12
|
| 795 |
+
|
| 796 |
+
|
| 797 |
+
def _hebrew_elapsed_days(year):
|
| 798 |
+
months = (235 * ((year - 1) // 19)
|
| 799 |
+
+ 12 * ((year - 1) % 19)
|
| 800 |
+
+ (7 * ((year - 1) % 19) + 1) // 19)
|
| 801 |
+
day = months * 29 + (12084 + 13753 * months) // 25920
|
| 802 |
+
return day + 1 if (3 * (day + 1)) % 7 < 3 else day
|
| 803 |
+
|
| 804 |
+
|
| 805 |
+
def _hebrew_new_year(year):
|
| 806 |
+
"""The fixed day number of 1 Tishrei, including the three postponement rules."""
|
| 807 |
+
cached = _HEBREW_YEAR_CACHE.get(year)
|
| 808 |
+
if cached is not None:
|
| 809 |
+
return cached
|
| 810 |
+
before, this, after = (_hebrew_elapsed_days(year - 1), _hebrew_elapsed_days(year),
|
| 811 |
+
_hebrew_elapsed_days(year + 1))
|
| 812 |
+
delay = 2 if after - this == 356 else (1 if this - before == 382 else 0)
|
| 813 |
+
value = _HEBREW_EPOCH + this + delay
|
| 814 |
+
if len(_HEBREW_YEAR_CACHE) > 2048:
|
| 815 |
+
_HEBREW_YEAR_CACHE.clear()
|
| 816 |
+
_HEBREW_YEAR_CACHE[year] = value
|
| 817 |
+
return value
|
| 818 |
+
|
| 819 |
+
|
| 820 |
+
def _hebrew_year_days(year):
|
| 821 |
+
return _hebrew_new_year(year + 1) - _hebrew_new_year(year)
|
| 822 |
+
|
| 823 |
+
|
| 824 |
+
def _hebrew_month_days(year, month):
|
| 825 |
+
if month in (2, 4, 6, 10, 13):
|
| 826 |
+
return 29
|
| 827 |
+
if month == 12 and not _hebrew_leap(year):
|
| 828 |
+
return 29
|
| 829 |
+
# Marheshvan (8) is long only in a 355 or 385 day year; Kislev (9) is short only in a 353 or
|
| 830 |
+
# 383 day one. Those two variable months are what keep the festivals off a fixed offset.
|
| 831 |
+
if month == 8 and _hebrew_year_days(year) % 10 != 5:
|
| 832 |
+
return 29
|
| 833 |
+
if month == 9 and _hebrew_year_days(year) % 10 == 3:
|
| 834 |
+
return 29
|
| 835 |
+
return 30
|
| 836 |
+
|
| 837 |
+
|
| 838 |
+
def _hebrew_date(year, month, day):
|
| 839 |
+
"""The Gregorian DAYTIME date of a Hebrew year/month/day.
|
| 840 |
+
|
| 841 |
+
β Hebcal's holiday LISTING pages print the preceding SUNSET, one day earlier than this; its
|
| 842 |
+
converter prints the daytime date, which is what a calendar cell means.
|
| 843 |
+
"""
|
| 844 |
+
if month < _HEBREW_TISHREI:
|
| 845 |
+
span = (sum(_hebrew_month_days(year, item)
|
| 846 |
+
for item in range(_HEBREW_TISHREI, _hebrew_last_month(year) + 1))
|
| 847 |
+
+ sum(_hebrew_month_days(year, item) for item in range(1, month)))
|
| 848 |
+
else:
|
| 849 |
+
span = sum(_hebrew_month_days(year, item) for item in range(_HEBREW_TISHREI, month))
|
| 850 |
+
return _dt.date.fromordinal(_hebrew_new_year(year) + span + day - 1)
|
| 851 |
+
|
| 852 |
+
|
| 853 |
+
def _hebrew_in_gregorian(month, day, year):
|
| 854 |
+
"""Every occurrence of one Hebrew month/day landing inside Gregorian `year`.
|
| 855 |
+
|
| 856 |
+
β ONE HEBREW YEAR STRADDLES TWO GREGORIAN YEARS β Hebrew 5788 puts Rosh Hashanah in 2027 and
|
| 857 |
+
Passover in 2028 β so this scans a WINDOW of Hebrew years and filters on the result, and never
|
| 858 |
+
assumes `hebrew_year = gregorian_year + 3760`.
|
| 859 |
+
"""
|
| 860 |
+
out = set()
|
| 861 |
+
for hebrew_year in range(year + 3759, year + 3763):
|
| 862 |
+
try:
|
| 863 |
+
got = _hebrew_date(hebrew_year, month, day)
|
| 864 |
+
except (ValueError, OverflowError):
|
| 865 |
+
continue
|
| 866 |
+
if got.year == year:
|
| 867 |
+
out.add(got)
|
| 868 |
+
return out
|
| 869 |
+
|
| 870 |
+
|
| 871 |
+
# β A NAMED holiday is the TRUE date and is NEVER weekend-shifted. `_observed()` belongs to the
|
| 872 |
+
# federal CALENDARS above, where a Saturday holiday really is taken on the Friday. Christmas 2027
|
| 873 |
+
# falls on a Saturday and must stay 2027-12-25: shifting it would land it on Christmas Eve, which
|
| 874 |
+
# is its own separately selectable holiday here.
|
| 875 |
+
_GRANULAR_HOLIDAYS = {
|
| 876 |
+
'NEW_YEARS': lambda year: {_dt.date(year, 1, 1)},
|
| 877 |
+
'VALENTINES': lambda year: {_dt.date(year, 2, 14)},
|
| 878 |
+
'INDEPENDENCE_DAY': lambda year: {_dt.date(year, 7, 4)},
|
| 879 |
+
'HALLOWEEN': lambda year: {_dt.date(year, 10, 31)},
|
| 880 |
+
'CHRISTMAS_EVE': lambda year: {_dt.date(year, 12, 24)},
|
| 881 |
+
'CHRISTMAS': lambda year: {_dt.date(year, 12, 25)},
|
| 882 |
+
'NEW_YEARS_EVE': lambda year: {_dt.date(year, 12, 31)},
|
| 883 |
+
'MOTHERS_DAY': lambda year: {_nth_weekday(year, 5, 6, 2)}, # second Sunday of May
|
| 884 |
+
'FATHERS_DAY': lambda year: {_nth_weekday(year, 6, 6, 3)}, # third Sunday of June
|
| 885 |
+
'MEMORIAL_DAY': lambda year: {_last_weekday(year, 5, 0)}, # last Monday of May
|
| 886 |
+
'LABOR_DAY': lambda year: {_nth_weekday(year, 9, 0, 1)}, # first Monday of September
|
| 887 |
+
'THANKSGIVING': lambda year: {_nth_weekday(year, 11, 3, 4)}, # fourth Thursday of November
|
| 888 |
+
'EASTER': lambda year: {_easter_sunday(year)},
|
| 889 |
+
'ROSH_HASHANAH': lambda year: _hebrew_in_gregorian(_HEBREW_TISHREI, 1, year),
|
| 890 |
+
'YOM_KIPPUR': lambda year: _hebrew_in_gregorian(_HEBREW_TISHREI, 10, year),
|
| 891 |
+
'HANUKKAH': lambda year: _hebrew_in_gregorian(_HEBREW_KISLEV, 25, year),
|
| 892 |
+
'PASSOVER': lambda year: _hebrew_in_gregorian(_HEBREW_NISAN, 15, year),
|
| 893 |
+
}
|
| 894 |
+
|
| 895 |
+
|
| 896 |
def _canada_public_holidays(year):
|
| 897 |
"""Canada's federal public-service holiday schedule, deterministically calculated.
|
| 898 |
|
|
|
|
| 921 |
return frozenset(days)
|
| 922 |
|
| 923 |
|
| 924 |
+
# A preview walks up to ten years of days and asks for the holiday set of three adjacent years on
|
| 925 |
+
# every one of them, so an uncached lunisolar computation would be re-run some eleven thousand
|
| 926 |
+
# times for a single dropdown. The values are immutable frozensets of a pure function of
|
| 927 |
+
# (code, year), so remembering them cannot change an answer.
|
| 928 |
+
_HOLIDAY_CACHE = {}
|
| 929 |
+
|
| 930 |
+
|
| 931 |
+
def _remember_holidays(key, days):
|
| 932 |
+
if len(_HOLIDAY_CACHE) > 4096:
|
| 933 |
+
_HOLIDAY_CACHE.clear()
|
| 934 |
+
_HOLIDAY_CACHE[key] = days
|
| 935 |
+
return days
|
| 936 |
+
|
| 937 |
+
|
| 938 |
def public_holidays(calendar, year):
|
| 939 |
"""A supported public holiday calendar, returned as deterministic ISO-day objects.
|
| 940 |
|
|
|
|
| 946 |
calendar = str(calendar or '').upper()
|
| 947 |
if calendar not in _PUBLIC_HOLIDAY_CALENDARS:
|
| 948 |
return frozenset()
|
| 949 |
+
key = (calendar, year)
|
| 950 |
+
cached = _HOLIDAY_CACHE.get(key)
|
| 951 |
+
if cached is not None:
|
| 952 |
+
return cached
|
| 953 |
if calendar == 'CA':
|
| 954 |
+
return _remember_holidays(key, _canada_public_holidays(year))
|
| 955 |
+
# β THIS GUARD IS LOAD-BEARING. Without it every granular code admitted above falls straight
|
| 956 |
+
# through to the US federal body below and previews as the whole United States calendar β
|
| 957 |
+
# a wrong answer that no gate would go red on.
|
| 958 |
+
if calendar != 'US':
|
| 959 |
+
builder = _GRANULAR_HOLIDAYS.get(calendar)
|
| 960 |
+
return _remember_holidays(key, frozenset(builder(year) if builder else ()))
|
| 961 |
days = {
|
| 962 |
_observed(_dt.date(year, 1, 1)),
|
| 963 |
_nth_weekday(year, 1, 0, 3), # Martin Luther King Jr. Day
|
|
|
|
| 974 |
# retroactively invent it.
|
| 975 |
if year >= 2021:
|
| 976 |
days.add(_observed(_dt.date(year, 6, 19)))
|
| 977 |
+
return _remember_holidays(key, frozenset(days))
|
| 978 |
+
|
| 979 |
+
|
| 980 |
+
def clean_ends(raw):
|
| 981 |
+
"""One recurrence's stopping condition, normalised. Never raises.
|
| 982 |
+
|
| 983 |
+
W46-T32 shipped the Ends control on the client and `clean_date_recurrence` builds a fresh
|
| 984 |
+
allowlist dict, so `ends` round-tripped as ABSENT and a rule asking for three occurrences
|
| 985 |
+
still previewed ten. This is the server half of that control.
|
| 986 |
+
|
| 987 |
+
Anything malformed degrades to ``never`` rather than refusing the whole recurrence: a
|
| 988 |
+
stopping condition nobody can read is a reason to keep repeating, not a reason to lose the
|
| 989 |
+
schedule.
|
| 990 |
+
"""
|
| 991 |
+
if not isinstance(raw, dict):
|
| 992 |
+
return {'kind': 'never'}
|
| 993 |
+
kind = str(raw.get('kind') or 'never').strip().lower()
|
| 994 |
+
if kind == 'on':
|
| 995 |
+
day = _iso_day(raw.get('date'))
|
| 996 |
+
return {'kind': 'on', 'date': day.isoformat()} if day else {'kind': 'never'}
|
| 997 |
+
if kind == 'after':
|
| 998 |
+
count = raw.get('count')
|
| 999 |
+
if isinstance(count, bool) or not isinstance(count, int) or not 1 <= count <= 999:
|
| 1000 |
+
return {'kind': 'never'}
|
| 1001 |
+
return {'kind': 'after', 'count': count}
|
| 1002 |
+
return {'kind': 'never'}
|
| 1003 |
|
| 1004 |
|
| 1005 |
def clean_date_recurrence(raw, condition_fields=None):
|
|
|
|
| 1098 |
str(key) for key in admitted_conditions or () if str(key)})
|
| 1099 |
if conditions:
|
| 1100 |
out['conditions'] = conditions
|
| 1101 |
+
ends = clean_ends(raw.get('ends'))
|
| 1102 |
+
# Emitted only when it says something, exactly like `conditions`, so no previously saved
|
| 1103 |
+
# config grows a key it never had. `clean_ends` is idempotent on its own output, which is
|
| 1104 |
+
# what lets `recurrence_payload` re-clean an already-clean dict.
|
| 1105 |
+
if ends['kind'] != 'never':
|
| 1106 |
+
out['ends'] = ends
|
| 1107 |
return out
|
| 1108 |
|
| 1109 |
|
|
|
|
| 1142 |
if start is None:
|
| 1143 |
return []
|
| 1144 |
want = config['previewCount'] if count is None else max(1, min(int(count), 50))
|
| 1145 |
+
ends = config.get('ends') or {'kind': 'never'}
|
| 1146 |
# A preview of at most fifty values needs no unbounded search. Ten years also makes an
|
| 1147 |
# unavailable public calendar visibly empty instead of spinning a request forever.
|
| 1148 |
+
horizon = max(start, now) + _dt.timedelta(days=3660)
|
| 1149 |
+
# β "After N occurrences" COUNTS FROM `startDate`, NOT FROM TODAY: occurrences already in the
|
| 1150 |
+
# past have spent the allowance. Counting from today is the obvious implementation and it is
|
| 1151 |
+
# wrong in a way that looks perfectly reasonable β a weekly Monday schedule begun 2026-01-01
|
| 1152 |
+
# with `after 3`, viewed on 2026-01-13, has exactly ONE occurrence left, not three. So the
|
| 1153 |
+
# scan starts at the START for that case, and the visible window is trimmed afterwards.
|
| 1154 |
+
limit = want
|
| 1155 |
+
if ends['kind'] == 'after':
|
| 1156 |
+
lower, limit = start, ends['count']
|
| 1157 |
+
else:
|
| 1158 |
+
lower = max(start, now)
|
| 1159 |
+
if ends['kind'] == 'on':
|
| 1160 |
+
horizon = min(horizon, _iso_day(ends.get('date')) or horizon)
|
| 1161 |
found, day = set(), lower
|
| 1162 |
holiday_rules = [rule for rule in config['rules'] if rule['kind'] == 'holiday']
|
| 1163 |
ordinary_rules = [rule for rule in config['rules'] if rule['kind'] != 'holiday']
|
| 1164 |
+
while day <= horizon and len(found) < limit:
|
| 1165 |
if any(_recurrence_matches(day, start, rule) for rule in ordinary_rules):
|
| 1166 |
found.add(day)
|
| 1167 |
for rule in holiday_rules:
|
|
|
|
| 1175 |
if occurrence == day and occurrence >= start:
|
| 1176 |
found.add(day)
|
| 1177 |
day += _dt.timedelta(days=1)
|
| 1178 |
+
allowed = sorted(found)[:limit]
|
| 1179 |
+
return [item.isoformat() for item in allowed if item >= now][:want]
|
| 1180 |
|
| 1181 |
|
| 1182 |
def recurrence_payload(raw, today=None, condition_fields=None):
|
|
|
|
| 3634 |
# bundle), `build_embed.py` that produced them, and `deploy_hf.py`'s embed-staleness guard. The
|
| 3635 |
# React app is now served directly by the FastAPI container β there is no twin to keep fresh, so
|
| 3636 |
# the entire class of "the code shipped but the bundle did not" is retired rather than guarded.
|
| 3637 |
+
|
| 3638 |
+
|
| 3639 |
+
# -- W46-T33's SELF-CHECK ---------------------------------------------------------------------
|
| 3640 |
+
# The done-when asks that "each computed date is checked against a known correct year in a test".
|
| 3641 |
+
# There is no `test_*.py` anywhere in this repository and the `verify_*.py` gates are outside this
|
| 3642 |
+
# ticket's fence, so the check lives HERE, beside the arithmetic it checks, and runs with
|
| 3643 |
+
# `python aios_grid.py` (no store, no network, no fixture).
|
| 3644 |
+
#
|
| 3645 |
+
# β EVERY EXPECTED VALUE BELOW IS AN INDEPENDENT FACT, never a value produced by running the code
|
| 3646 |
+
# above it: a test whose expectations came from its own implementation is a tautology. The
|
| 3647 |
+
# Jewish anchors each carry the hebcal CONVERTER url they were fetched from, one fetch per row.
|
| 3648 |
+
# β Hebcal's holiday LISTING pages print the preceding SUNSET, one day earlier than the
|
| 3649 |
+
# converter; an expectation taken from a listing page is off by one for every Jewish holiday.
|
| 3650 |
+
_SELFCHECK_HOLIDAYS = (
|
| 3651 |
+
# code, gregorian year, expected ISO dates
|
| 3652 |
+
('NEW_YEARS', 2027, ['2027-01-01']),
|
| 3653 |
+
('VALENTINES', 2027, ['2027-02-14']),
|
| 3654 |
+
('INDEPENDENCE_DAY', 2027, ['2027-07-04']),
|
| 3655 |
+
('HALLOWEEN', 2027, ['2027-10-31']),
|
| 3656 |
+
('CHRISTMAS_EVE', 2027, ['2027-12-24']),
|
| 3657 |
+
# Christmas 2027 is a SATURDAY. A named holiday is the true date and must NOT shift to the
|
| 3658 |
+
# Friday, which is already Christmas Eve above. The US federal CALENDAR does shift it, and
|
| 3659 |
+
# that difference is checked as a negative control further down.
|
| 3660 |
+
('CHRISTMAS', 2027, ['2027-12-25']),
|
| 3661 |
+
('NEW_YEARS_EVE', 2027, ['2027-12-31']),
|
| 3662 |
+
('MOTHERS_DAY', 2026, ['2026-05-10']), # second Sunday of May 2026
|
| 3663 |
+
('FATHERS_DAY', 2026, ['2026-06-21']), # third Sunday of June 2026
|
| 3664 |
+
('MEMORIAL_DAY', 2026, ['2026-05-25']), # last Monday of May 2026
|
| 3665 |
+
('LABOR_DAY', 2026, ['2026-09-07']), # first Monday of September 2026
|
| 3666 |
+
('THANKSGIVING', 2026, ['2026-11-26']), # fourth Thursday of November 2026
|
| 3667 |
+
('EASTER', 2026, ['2026-04-05']),
|
| 3668 |
+
('EASTER', 2027, ['2027-03-28']),
|
| 3669 |
+
# hebcal.com/converter?gy=2026&gm=9&gd=12&g2h=1 -> 1 Tishrei 5787
|
| 3670 |
+
('ROSH_HASHANAH', 2026, ['2026-09-12']),
|
| 3671 |
+
# hebcal.com/converter?gy=2027&gm=10&gd=2&g2h=1 -> 1 Tishrei 5788
|
| 3672 |
+
('ROSH_HASHANAH', 2027, ['2027-10-02']),
|
| 3673 |
+
# hebcal.com/converter?gy=2030&gm=9&gd=28&g2h=1 -> 1 Tishrei 5791
|
| 3674 |
+
('ROSH_HASHANAH', 2030, ['2030-09-28']),
|
| 3675 |
+
# hebcal.com/converter?gy=2027&gm=10&gd=11&g2h=1 -> 10 Tishrei 5788
|
| 3676 |
+
('YOM_KIPPUR', 2027, ['2027-10-11']),
|
| 3677 |
+
# hebcal.com/converter?gy=2027&gm=12&gd=25&g2h=1 -> 25 Kislev 5788
|
| 3678 |
+
('HANUKKAH', 2027, ['2027-12-25']),
|
| 3679 |
+
# hebcal.com/converter?gy=2026&gm=4&gd=2&g2h=1 -> 15 Nisan 5786
|
| 3680 |
+
('PASSOVER', 2026, ['2026-04-02']),
|
| 3681 |
+
# hebcal.com/converter?gy=2028&gm=4&gd=11&g2h=1 -> 15 Nisan 5788. Together with Rosh
|
| 3682 |
+
# Hashanah 2027 above this is the STRADDLE control: both come from Hebrew year 5788, which
|
| 3683 |
+
# sits in two different Gregorian years.
|
| 3684 |
+
('PASSOVER', 2028, ['2028-04-11']),
|
| 3685 |
+
)
|
| 3686 |
+
|
| 3687 |
+
_SELFCHECK_ENDS = (
|
| 3688 |
+
# name, ends config, viewing day, expected preview of a weekly-Monday rule from 2026-01-01
|
| 3689 |
+
('never', {'kind': 'never'}, '2026-01-01',
|
| 3690 |
+
['2026-01-05', '2026-01-12', '2026-01-19', '2026-01-26', '2026-02-02']),
|
| 3691 |
+
('on cuts the tail', {'kind': 'on', 'date': '2026-01-26'}, '2026-01-01',
|
| 3692 |
+
['2026-01-05', '2026-01-12', '2026-01-19', '2026-01-26']),
|
| 3693 |
+
('after 3 from the start', {'kind': 'after', 'count': 3}, '2026-01-01',
|
| 3694 |
+
['2026-01-05', '2026-01-12', '2026-01-19']),
|
| 3695 |
+
# A count already spent by past occurrences is the case that catches the wrong reading.
|
| 3696 |
+
('after 3 seen later', {'kind': 'after', 'count': 3}, '2026-01-13', ['2026-01-19']),
|
| 3697 |
+
('after 3 seen past the end', {'kind': 'after', 'count': 3}, '2026-02-01', []),
|
| 3698 |
+
('a malformed count degrades to never', {'kind': 'after', 'count': 0}, '2026-01-01',
|
| 3699 |
+
['2026-01-05', '2026-01-12', '2026-01-19', '2026-01-26', '2026-02-02']),
|
| 3700 |
+
('a garbage ends object degrades to never', 'not-an-object', '2026-01-01',
|
| 3701 |
+
['2026-01-05', '2026-01-12', '2026-01-19', '2026-01-26', '2026-02-02']),
|
| 3702 |
+
)
|
| 3703 |
+
|
| 3704 |
+
_SELFCHECK_WEEKLY = {'startDate': '2026-01-01',
|
| 3705 |
+
'anchorField': {'table': 'same', 'field': 'due'},
|
| 3706 |
+
'rules': [{'kind': 'weekly', 'interval': 1, 'weekdays': [0]}],
|
| 3707 |
+
'previewCount': 10}
|
| 3708 |
+
|
| 3709 |
+
|
| 3710 |
+
def selfcheck_recurrence():
|
| 3711 |
+
"""Return (failures, lines) for the granular holidays and the `ends` stopping condition."""
|
| 3712 |
+
state = {'bad': 0}
|
| 3713 |
+
lines = []
|
| 3714 |
+
|
| 3715 |
+
def check(ok, text):
|
| 3716 |
+
state['bad'] += 0 if ok else 1
|
| 3717 |
+
lines.append(('ok ' if ok else 'FAIL ') + text)
|
| 3718 |
+
|
| 3719 |
+
for code, year, want in _SELFCHECK_HOLIDAYS:
|
| 3720 |
+
got = sorted(day.isoformat() for day in public_holidays(code, year))
|
| 3721 |
+
check(got == sorted(want), '%-17s %d want %s got %s' % (code, year, want, got))
|
| 3722 |
+
|
| 3723 |
+
# Every selectable code must produce a date in every year of a decade, or the selector
|
| 3724 |
+
# promises a recurrence that is silently a no-op.
|
| 3725 |
+
empty = [(item['code'], year) for item in PUBLIC_HOLIDAY_CALENDARS
|
| 3726 |
+
for year in range(2026, 2036) if not public_holidays(item['code'], year)]
|
| 3727 |
+
check(not empty, 'every code yields a date for 2026..2035 (%d empty)' % len(empty))
|
| 3728 |
+
# The registry and the computation table must not drift apart.
|
| 3729 |
+
declared = set(item['code'] for item in PUBLIC_HOLIDAY_CALENDARS
|
| 3730 |
+
if item['group'] == 'holiday')
|
| 3731 |
+
check(declared == set(_GRANULAR_HOLIDAYS),
|
| 3732 |
+
'registry and computation table agree on %d granular codes' % len(declared))
|
| 3733 |
+
check(all(item.get('group') in ('calendar', 'holiday')
|
| 3734 |
+
for item in PUBLIC_HOLIDAY_CALENDARS),
|
| 3735 |
+
'every registry entry carries a group')
|
| 3736 |
+
check(not [item for item in PUBLIC_HOLIDAY_CALENDARS
|
| 3737 |
+
if 'β' in item['label'] or 'β' in item['label']],
|
| 3738 |
+
'no label carries an em dash or an en dash')
|
| 3739 |
+
|
| 3740 |
+
# NEGATIVE CONTROLS.
|
| 3741 |
+
check(public_holidays('NOT_A_HOLIDAY', 2026) == frozenset(),
|
| 3742 |
+
'NC an unknown code still returns an empty set')
|
| 3743 |
+
check(public_holidays('CHRISTMAS', 2027) != public_holidays('US', 2027),
|
| 3744 |
+
'NC a granular code does not fall through to the US federal set')
|
| 3745 |
+
check(_dt.date(2027, 12, 25) in public_holidays('CHRISTMAS', 2027)
|
| 3746 |
+
and _dt.date(2027, 12, 25) not in public_holidays('US', 2027),
|
| 3747 |
+
'NC Christmas 2027 is a Saturday: the named day stays, the federal calendar shifts')
|
| 3748 |
+
check(_hebrew_date(5788, _HEBREW_TISHREI, 1).year == 2027
|
| 3749 |
+
and _hebrew_date(5788, _HEBREW_NISAN, 15).year == 2028,
|
| 3750 |
+
'NC Hebrew 5788 straddles Gregorian 2027 and 2028')
|
| 3751 |
+
jewish = ('ROSH_HASHANAH', 'YOM_KIPPUR', 'HANUKKAH', 'PASSOVER')
|
| 3752 |
+
saved_cache = dict(_HOLIDAY_CACHE)
|
| 3753 |
+
globals()['_HOLIDAY_CACHE'] = {}
|
| 3754 |
+
globals()['_HEBREW_YEAR_CACHE'] = {}
|
| 3755 |
+
globals()['_HEBREW_EPOCH'] = _HEBREW_EPOCH + 1
|
| 3756 |
+
broken = sum(1 for code, year, want in _SELFCHECK_HOLIDAYS if code in jewish
|
| 3757 |
+
and sorted(day.isoformat()
|
| 3758 |
+
for day in public_holidays(code, year)) != sorted(want))
|
| 3759 |
+
globals()['_HEBREW_EPOCH'] = _HEBREW_EPOCH - 1
|
| 3760 |
+
globals()['_HEBREW_YEAR_CACHE'] = {}
|
| 3761 |
+
globals()['_HOLIDAY_CACHE'] = saved_cache
|
| 3762 |
+
expected_jewish = len([1 for code, _, _ in _SELFCHECK_HOLIDAYS if code in jewish])
|
| 3763 |
+
check(broken == expected_jewish,
|
| 3764 |
+
'NC a one day epoch shift breaks all %d Jewish anchors (broke %d)'
|
| 3765 |
+
% (expected_jewish, broken))
|
| 3766 |
+
|
| 3767 |
+
for name, ends, today, want in _SELFCHECK_ENDS:
|
| 3768 |
+
got = recurrence_preview(dict(_SELFCHECK_WEEKLY, ends=ends), today=today)
|
| 3769 |
+
got = got[:len(want)] if want else got
|
| 3770 |
+
check(got == want, '%-42s want %s got %s' % (name, want, got))
|
| 3771 |
+
once = clean_date_recurrence(dict(_SELFCHECK_WEEKLY, ends={'kind': 'after', 'count': 3}))
|
| 3772 |
+
check(once.get('ends') == {'kind': 'after', 'count': 3}, 'ends survives the field cleaner')
|
| 3773 |
+
check(clean_date_recurrence(once) == once, 'clean_date_recurrence is idempotent over ends')
|
| 3774 |
+
check('ends' not in (clean_date_recurrence(_SELFCHECK_WEEKLY) or {}),
|
| 3775 |
+
'a recurrence with no ends grows no ends key')
|
| 3776 |
+
return state['bad'], lines
|
| 3777 |
+
|
| 3778 |
+
|
| 3779 |
+
if __name__ == '__main__':
|
| 3780 |
+
failures, report = selfcheck_recurrence()
|
| 3781 |
+
print('\n'.join(report))
|
| 3782 |
+
print('\nRESULT: %d/%d checks passed' % (len(report) - failures, len(report)))
|
| 3783 |
+
raise SystemExit(1 if failures else 0)
|
platform/core/route_system.py
CHANGED
|
@@ -1078,6 +1078,41 @@ def legacy_route_plan(fields, cells, *, tenant_id, created_by, ordinal_offset=0)
|
|
| 1078 |
return plans
|
| 1079 |
|
| 1080 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1081 |
def compatible_routes(routes, fields, cells, *, tenant_id, created_by):
|
| 1082 |
"""Read-through view of normalized Routes plus still-live legacy route-order fields.
|
| 1083 |
|
|
|
|
| 1078 |
return plans
|
| 1079 |
|
| 1080 |
|
| 1081 |
+
def record_legacy_field_deletion(st, field_keys, *, deleted_by=""):
|
| 1082 |
+
"""Stamp the deletion of a legacy route column onto its OWN verified receipt (W46-T25, R2).
|
| 1083 |
+
|
| 1084 |
+
ββ A KEY WITH NO VERIFIED RECEIPT IS NEVER STAMPED, and the caller is told which ones were
|
| 1085 |
+
skipped rather than being handed a total. This is the last lock in the chain, and it is here
|
| 1086 |
+
rather than in the ops pass on purpose: the receipt map is this module's own state, so a
|
| 1087 |
+
second caller that learns to delete columns cannot invent a receipt by writing the map itself.
|
| 1088 |
+
The stamp is additive, so ``verified`` stays true and the display filters that read it keep
|
| 1089 |
+
hiding a key that no longer exists.
|
| 1090 |
+
"""
|
| 1091 |
+
keys = [str(key) for key in (field_keys or ()) if str(key or "").strip()]
|
| 1092 |
+
|
| 1093 |
+
def mutate(state):
|
| 1094 |
+
migrations = dict(state.get("legacyMigrations") or {})
|
| 1095 |
+
stamped, refused = [], []
|
| 1096 |
+
for key in keys:
|
| 1097 |
+
receipt = migrations.get(key)
|
| 1098 |
+
if not (isinstance(receipt, dict) and receipt.get("verified") is True):
|
| 1099 |
+
refused.append(key)
|
| 1100 |
+
continue
|
| 1101 |
+
migrations[key] = {**receipt, "legacyFieldDeleted": True, "deletedAt": _now(),
|
| 1102 |
+
"deletedBy": str(deleted_by or "")}
|
| 1103 |
+
stamped.append(key)
|
| 1104 |
+
state["legacyMigrations"] = migrations
|
| 1105 |
+
return state, {"stamped": sorted(stamped), "refused": sorted(refused)}
|
| 1106 |
+
|
| 1107 |
+
return _persist(st, mutate)
|
| 1108 |
+
|
| 1109 |
+
|
| 1110 |
+
def legacy_field_deleted(st, field_key):
|
| 1111 |
+
"""True when this legacy column's receipt records that the column itself is gone."""
|
| 1112 |
+
receipt = (read(st).get("legacyMigrations") or {}).get(str(field_key))
|
| 1113 |
+
return bool(isinstance(receipt, dict) and receipt.get("legacyFieldDeleted") is True)
|
| 1114 |
+
|
| 1115 |
+
|
| 1116 |
def compatible_routes(routes, fields, cells, *, tenant_id, created_by):
|
| 1117 |
"""Read-through view of normalized Routes plus still-live legacy route-order fields.
|
| 1118 |
|
platform/core/schema_overlay.py
ADDED
|
@@ -0,0 +1,368 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""schema_overlay.py β THE per-tenant schema overlay (wave 46, W46-T36; contract C1, R5/R12).
|
| 2 |
+
|
| 3 |
+
WHAT THIS IS, stated before anything else: `platform/aios_grid_fields.json` is the CANONICAL field
|
| 4 |
+
contract and it is NEVER written. A tenant that wants a column hidden, relabelled or moved gets an
|
| 5 |
+
OVERLAY document in its own store, and every read merges contract + overlay. That is what makes a
|
| 6 |
+
tenant's Manage Database changes survive a redeploy while being unable to touch another tenant:
|
| 7 |
+
the canonical file is shared and read-only, the overlay is per tenant and the only writable half.
|
| 8 |
+
|
| 9 |
+
THE DOCUMENT SHAPE (C1, verbatim)::
|
| 10 |
+
|
| 11 |
+
{ "<database_key>": { "<field_key>": {"hidden": bool, "label": str|null, "order": int|null} } }
|
| 12 |
+
|
| 13 |
+
An ABSENT key means "inherit the canonical contract". That is load-bearing in both directions: an
|
| 14 |
+
empty overlay must reproduce the contract byte-for-byte, and nothing here may ever write a dense
|
| 15 |
+
`order` for every field, because a UI that PATCHes back what it read would then pin every column
|
| 16 |
+
forever and "absent means inherit" would be gone permanently.
|
| 17 |
+
|
| 18 |
+
R12 β v1 is SHOW/HIDE, RELABEL, REORDER ONLY. No field typing, no hard delete, no endpoint
|
| 19 |
+
browser. That wall lives in `clean_patch()` and NOWHERE else, so there is exactly one place to
|
| 20 |
+
read when the question is "what may an overlay do".
|
| 21 |
+
|
| 22 |
+
β TENANCY IS CARRIED BY THE STORE HANDLE, NOT BY THIS MODULE. Nothing here resolves a tenant, and
|
| 23 |
+
that is deliberate: under `pg` the TENANT decides where a write lands, not `OS_DATA_REPO`
|
| 24 |
+
([[pg-guard-authorises-a-tenant-not-a-database]]). `read`/`write` take an injectable handle `st`;
|
| 25 |
+
the caller (the route, which already holds the request's tenant runtime) passes the tenant's store
|
| 26 |
+
and gets that tenant's document. A gate passes a fake handle and touches no real store at all.
|
| 27 |
+
|
| 28 |
+
β NO FUNCTION HERE MUTATES ITS INPUT. The field list callers hand in is `aios_grid.FIELDS` β a
|
| 29 |
+
MODULE GLOBAL, alive for the life of the process and shared by every request. Relabelling in place
|
| 30 |
+
would leak one tenant's label into another tenant's response with no error anywhere. Every merge
|
| 31 |
+
returns fresh dicts.
|
| 32 |
+
|
| 33 |
+
The gate is `aios-web/api/verify_schema_overlay.py`.
|
| 34 |
+
"""
|
| 35 |
+
|
| 36 |
+
#: The store key holding one tenant's overlay document.
|
| 37 |
+
STORE_KEY = "ut_schema_overlay"
|
| 38 |
+
|
| 39 |
+
#: The ONLY per-field properties an overlay may carry (R12). Anything else is refused.
|
| 40 |
+
ALLOWED_FIELD_PROPS = ("hidden", "label", "order")
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
class SchemaOverlayUnsupported(Exception):
|
| 44 |
+
"""R12's refusal. Carries `.key` β the offending name β so the caller can put it in the body.
|
| 45 |
+
|
| 46 |
+
The HTTP shape (pass 2, `routes_admin.py`) is `400 schema_overlay_unsupported` with `.key`
|
| 47 |
+
named in the detail. One exception type for both failure kinds (an unsupported key, and a
|
| 48 |
+
supported key carrying the wrong type) so the route needs exactly one `except` clause; `.key`
|
| 49 |
+
tells them apart at the point of use, and the message says which happened.
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
+
def __init__(self, key, reason=None, database_key=None, field_key=None):
|
| 53 |
+
self.key = key
|
| 54 |
+
self.reason = reason
|
| 55 |
+
self.database_key = database_key
|
| 56 |
+
self.field_key = field_key
|
| 57 |
+
if reason:
|
| 58 |
+
msg = f"Schema overlay refused {key!r}: {reason}"
|
| 59 |
+
else:
|
| 60 |
+
msg = (f"Schema overlay does not support {key!r}. Version 1 can hide, relabel and "
|
| 61 |
+
f"reorder a field, and nothing else.")
|
| 62 |
+
where = ".".join(str(p) for p in (database_key, field_key) if p)
|
| 63 |
+
if where:
|
| 64 |
+
msg = f"{msg} (at {where})"
|
| 65 |
+
super().__init__(msg)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
# =================================================================================================
|
| 69 |
+
# THE WALL β R12, and it is the only copy
|
| 70 |
+
# =================================================================================================
|
| 71 |
+
|
| 72 |
+
def clean_patch(patch):
|
| 73 |
+
"""Validate a PATCH body against C1's document shape and R12's allowed properties.
|
| 74 |
+
|
| 75 |
+
Returns a NEW normalised document (never the caller's object). Raises
|
| 76 |
+
`SchemaOverlayUnsupported` naming the FIRST offending key, so the client is told which of its
|
| 77 |
+
keys was the problem rather than being handed a generic rejection.
|
| 78 |
+
|
| 79 |
+
Accepts a PARTIAL of the document shape: only the databases and fields the client is changing
|
| 80 |
+
need appear. `{}` is valid and means "change nothing".
|
| 81 |
+
"""
|
| 82 |
+
if patch is None:
|
| 83 |
+
return {}
|
| 84 |
+
if not isinstance(patch, dict):
|
| 85 |
+
raise SchemaOverlayUnsupported(
|
| 86 |
+
type(patch).__name__,
|
| 87 |
+
reason="the body must be an object keyed by database, then by field.")
|
| 88 |
+
|
| 89 |
+
out = {}
|
| 90 |
+
for db_key, per_db in patch.items():
|
| 91 |
+
if not isinstance(db_key, str) or not db_key.strip():
|
| 92 |
+
raise SchemaOverlayUnsupported(str(db_key), reason="a database key must be a name.")
|
| 93 |
+
if not isinstance(per_db, dict):
|
| 94 |
+
raise SchemaOverlayUnsupported(
|
| 95 |
+
db_key, reason="each database maps to an object of fields.", database_key=db_key)
|
| 96 |
+
clean_db = {}
|
| 97 |
+
for f_key, props in per_db.items():
|
| 98 |
+
if not isinstance(f_key, str) or not f_key.strip():
|
| 99 |
+
raise SchemaOverlayUnsupported(
|
| 100 |
+
str(f_key), reason="a field key must be a name.", database_key=db_key)
|
| 101 |
+
if not isinstance(props, dict):
|
| 102 |
+
raise SchemaOverlayUnsupported(
|
| 103 |
+
f_key, reason="each field maps to an object of overlay properties.",
|
| 104 |
+
database_key=db_key, field_key=f_key)
|
| 105 |
+
clean_props = {}
|
| 106 |
+
for prop, value in props.items():
|
| 107 |
+
if prop not in ALLOWED_FIELD_PROPS:
|
| 108 |
+
# R12. This is the refusal the contract names, and the key travels with it.
|
| 109 |
+
raise SchemaOverlayUnsupported(prop, database_key=db_key, field_key=f_key)
|
| 110 |
+
if prop == "hidden":
|
| 111 |
+
if not isinstance(value, bool):
|
| 112 |
+
raise SchemaOverlayUnsupported(
|
| 113 |
+
prop, reason=f"expected true or false, got {type(value).__name__}.",
|
| 114 |
+
database_key=db_key, field_key=f_key)
|
| 115 |
+
elif prop == "label":
|
| 116 |
+
if value is not None and not isinstance(value, str):
|
| 117 |
+
raise SchemaOverlayUnsupported(
|
| 118 |
+
prop, reason=f"expected text or null, got {type(value).__name__}.",
|
| 119 |
+
database_key=db_key, field_key=f_key)
|
| 120 |
+
elif prop == "order":
|
| 121 |
+
# bool is an int in Python; a boolean order is a mistake, not a position.
|
| 122 |
+
if value is not None and (isinstance(value, bool) or not isinstance(value, int)):
|
| 123 |
+
raise SchemaOverlayUnsupported(
|
| 124 |
+
prop, reason=f"expected a whole number or null, got "
|
| 125 |
+
f"{type(value).__name__}.",
|
| 126 |
+
database_key=db_key, field_key=f_key)
|
| 127 |
+
clean_props[prop] = value
|
| 128 |
+
clean_db[f_key] = clean_props
|
| 129 |
+
out[db_key] = clean_db
|
| 130 |
+
return out
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
def apply_patch(doc, patch):
|
| 134 |
+
"""Deep-merge a cleaned partial into a whole overlay document, returning a NEW document.
|
| 135 |
+
|
| 136 |
+
β This exists so a PATCH to one database cannot clobber another's overlay. `write()` takes the
|
| 137 |
+
WHOLE document, so without a merge here every caller would hand-roll one and the first one to
|
| 138 |
+
get it wrong would silently drop a tenant's other databases. Merge depth is three: database,
|
| 139 |
+
then field, then property.
|
| 140 |
+
"""
|
| 141 |
+
patch = clean_patch(patch)
|
| 142 |
+
out = {db: {f: dict(p) for f, p in fields.items()}
|
| 143 |
+
for db, fields in (doc or {}).items() if isinstance(fields, dict)}
|
| 144 |
+
for db_key, per_db in patch.items():
|
| 145 |
+
target_db = out.setdefault(db_key, {})
|
| 146 |
+
for f_key, props in per_db.items():
|
| 147 |
+
target_field = dict(target_db.get(f_key) or {})
|
| 148 |
+
target_field.update(props)
|
| 149 |
+
target_db[f_key] = target_field
|
| 150 |
+
return out
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
# =================================================================================================
|
| 154 |
+
# LOCKED FIELDS β derived, because the contract carries no `locked` flag
|
| 155 |
+
# =================================================================================================
|
| 156 |
+
|
| 157 |
+
def locked_keys(database_key, contract):
|
| 158 |
+
"""The fields an overlay may NOT hide: the join keys and the record id.
|
| 159 |
+
|
| 160 |
+
β THERE IS NO `locked` KEY IN `aios_grid_fields.json`. It is DERIVED here, and this is the
|
| 161 |
+
predicate, per contract kind:
|
| 162 |
+
|
| 163 |
+
* a PRODUCT-shaped contract (a dict carrying `identity` / `business_key`): those two values.
|
| 164 |
+
Measured on the shipped contract: `identity='pid'`, `business_key='code'`.
|
| 165 |
+
* a CUSTOMER-shaped contract (a flat list of fields): every field with `derived: true`, plus
|
| 166 |
+
every field with `pinned: true`. Measured: `partner_id` (derived, and its own description
|
| 167 |
+
says this row's pid IS the partner id) and `customer` (pinned).
|
| 168 |
+
|
| 169 |
+
The two arms are UNIONED rather than switched on `database_key`, because they do not overlap
|
| 170 |
+
destructively and a contract that grows the other shape's marks should be honoured. On the
|
| 171 |
+
shipped contract this yields `{pid, code}` for products and `{customer, partner_id}` for
|
| 172 |
+
customers.
|
| 173 |
+
|
| 174 |
+
β NOT `source == "odoo"`. That is 36 of the 37 customer fields and all six price columns a
|
| 175 |
+
later ticket must be able to hide, so it would lock nearly everything.
|
| 176 |
+
β NOT `preset`. `preset` is the PRE-SET FIELD lock, a DIFFERENT one of the three locks in
|
| 177 |
+
DESIGN.md section 4: it governs REDEFINING a column, not hiding it. Nine product fields carry
|
| 178 |
+
it, and conflating the two would refuse work the owner is explicitly allowed to do.
|
| 179 |
+
|
| 180 |
+
β `identity` may name something that is not a member of the field list at all (`pid` is not),
|
| 181 |
+
so the returned set is not guaranteed to be a subset of the field keys. It is a set of names
|
| 182 |
+
the overlay may not hide, which is the right thing whether or not the name is displayed.
|
| 183 |
+
"""
|
| 184 |
+
_ = database_key # kept in the signature: the caller's key is the natural audit trail
|
| 185 |
+
fields, meta = _split_contract(contract)
|
| 186 |
+
out = set()
|
| 187 |
+
for name in ("identity", "business_key"):
|
| 188 |
+
value = meta.get(name)
|
| 189 |
+
if isinstance(value, str) and value.strip():
|
| 190 |
+
out.add(value)
|
| 191 |
+
for f in fields:
|
| 192 |
+
if not isinstance(f, dict):
|
| 193 |
+
continue
|
| 194 |
+
key = f.get("key")
|
| 195 |
+
if isinstance(key, str) and (f.get("derived") is True or f.get("pinned") is True):
|
| 196 |
+
out.add(key)
|
| 197 |
+
return frozenset(out)
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
def _split_contract(contract):
|
| 201 |
+
"""`contract` may be a flat list of fields or a `{identity, business_key, fields}` dict."""
|
| 202 |
+
if isinstance(contract, dict):
|
| 203 |
+
fields = contract.get("fields")
|
| 204 |
+
return (fields if isinstance(fields, list) else []), contract
|
| 205 |
+
if isinstance(contract, list):
|
| 206 |
+
return contract, {}
|
| 207 |
+
return [], {}
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
# =================================================================================================
|
| 211 |
+
# THE READ PATH β one merge, two shapes
|
| 212 |
+
# =================================================================================================
|
| 213 |
+
|
| 214 |
+
def _sort_key(index, order):
|
| 215 |
+
"""THE ORDER TIEBREAK, written down because a partial reorder is not a total order.
|
| 216 |
+
|
| 217 |
+
`(0, order, contract_index)` for a field carrying an explicit order, `(1, 0, contract_index)`
|
| 218 |
+
for one that does not. So: ordered fields first, ascending; unordered fields after them in
|
| 219 |
+
their canonical contract order; and the contract index breaks every remaining tie, which makes
|
| 220 |
+
the sort TOTAL and STABLE even when two fields are given the same order number.
|
| 221 |
+
"""
|
| 222 |
+
if isinstance(order, bool) or not isinstance(order, int):
|
| 223 |
+
return (1, 0, index)
|
| 224 |
+
return (0, order, index)
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
def merge(fields, overlay_for_db, database_key=None, locked=None):
|
| 228 |
+
"""THE grid/workspace read (C1): contract + one database's overlay, hidden fields REMOVED.
|
| 229 |
+
|
| 230 |
+
`overlay_for_db` is `overlay_doc[database_key]`, i.e. `{field_key: {hidden,label,order}}`.
|
| 231 |
+
`locked` may be supplied by a caller that holds the full contract dict (product-shaped); when
|
| 232 |
+
omitted it is derived from `fields` alone.
|
| 233 |
+
|
| 234 |
+
Rules:
|
| 235 |
+
* an absent field key inherits the contract unchanged;
|
| 236 |
+
* `hidden: true` drops the field, UNLESS it is locked, in which case it stays. That is not
|
| 237 |
+
an error and it is not silent-wrong: it is the guard holding, and `ignored_hides()` names
|
| 238 |
+
every such field for anything that wants to report it;
|
| 239 |
+
* `label` replaces the label; `label: null` (or absent, or blank) inherits;
|
| 240 |
+
* `order` sorts, per `_sort_key` above.
|
| 241 |
+
|
| 242 |
+
Returns NEW dicts. The input list and its members are never touched.
|
| 243 |
+
"""
|
| 244 |
+
locked = frozenset(locked) if locked is not None else locked_keys(database_key, fields)
|
| 245 |
+
ov = overlay_for_db if isinstance(overlay_for_db, dict) else {}
|
| 246 |
+
field_list, _meta = _split_contract(fields)
|
| 247 |
+
|
| 248 |
+
decorated = []
|
| 249 |
+
for index, f in enumerate(field_list):
|
| 250 |
+
if not isinstance(f, dict):
|
| 251 |
+
continue
|
| 252 |
+
key = f.get("key")
|
| 253 |
+
props = ov.get(key) if isinstance(key, str) else None
|
| 254 |
+
props = props if isinstance(props, dict) else {}
|
| 255 |
+
if props.get("hidden") is True and key not in locked:
|
| 256 |
+
continue
|
| 257 |
+
out = dict(f)
|
| 258 |
+
label = props.get("label")
|
| 259 |
+
if isinstance(label, str) and label.strip():
|
| 260 |
+
out["label"] = label
|
| 261 |
+
decorated.append((_sort_key(index, props.get("order")), out))
|
| 262 |
+
|
| 263 |
+
decorated.sort(key=lambda pair: pair[0])
|
| 264 |
+
return [item for _k, item in decorated]
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
def merged_view(database_key, fields, overlay_doc, locked=None):
|
| 268 |
+
"""THE Manage Database read (C1): every field PRESENT, wearing its overlay state.
|
| 269 |
+
|
| 270 |
+
β TWO DIFFERENT SHAPES, and serving one from the other is the mistake to avoid:
|
| 271 |
+
the grid/workspace read wants a hidden field GONE -> `merge()`
|
| 272 |
+
Manage Database wants it PRESENT wearing `hidden: true` -> this function
|
| 273 |
+
The admin screen must SEE a hidden field in order to offer unhiding it.
|
| 274 |
+
|
| 275 |
+
Element shape is C1's, exactly: `{key,label,type,source,hidden,order,locked}`.
|
| 276 |
+
|
| 277 |
+
`hidden` is the EFFECTIVE state, so a locked field reports `hidden: false` even when the
|
| 278 |
+
overlay asks to hide it. The admin surface and the grid then agree about what is visible;
|
| 279 |
+
reporting `hidden: true` for a field the grid still shows would be a screen contradicting
|
| 280 |
+
itself. What the overlay asked for is recoverable from `ignored_hides()`.
|
| 281 |
+
|
| 282 |
+
`order` is the overlay's own value or `None`. β It is NEVER densified to `0..N`: a UI that
|
| 283 |
+
PATCHed back what it read would give every field an explicit order and destroy C1's
|
| 284 |
+
"an absent key means inherit".
|
| 285 |
+
"""
|
| 286 |
+
field_list, _meta = _split_contract(fields)
|
| 287 |
+
locked_set = frozenset(locked) if locked is not None else locked_keys(database_key, fields)
|
| 288 |
+
ov = (overlay_doc or {}).get(database_key) if isinstance(overlay_doc, dict) else None
|
| 289 |
+
ov = ov if isinstance(ov, dict) else {}
|
| 290 |
+
|
| 291 |
+
decorated = []
|
| 292 |
+
for index, f in enumerate(field_list):
|
| 293 |
+
if not isinstance(f, dict):
|
| 294 |
+
continue
|
| 295 |
+
key = f.get("key")
|
| 296 |
+
props = ov.get(key) if isinstance(key, str) else None
|
| 297 |
+
props = props if isinstance(props, dict) else {}
|
| 298 |
+
is_locked = key in locked_set
|
| 299 |
+
label = props.get("label")
|
| 300 |
+
order = props.get("order")
|
| 301 |
+
order = None if (isinstance(order, bool) or not isinstance(order, int)) else order
|
| 302 |
+
row = {
|
| 303 |
+
"key": key,
|
| 304 |
+
"label": (label if isinstance(label, str) and label.strip() else f.get("label")),
|
| 305 |
+
"type": f.get("type"),
|
| 306 |
+
"source": f.get("source"),
|
| 307 |
+
"hidden": bool(props.get("hidden") is True and not is_locked),
|
| 308 |
+
"order": order,
|
| 309 |
+
"locked": is_locked,
|
| 310 |
+
}
|
| 311 |
+
decorated.append((_sort_key(index, props.get("order")), row))
|
| 312 |
+
|
| 313 |
+
decorated.sort(key=lambda pair: pair[0])
|
| 314 |
+
return [row for _k, row in decorated]
|
| 315 |
+
|
| 316 |
+
|
| 317 |
+
def ignored_hides(database_key, fields, overlay_doc, locked=None):
|
| 318 |
+
"""The locked field keys whose `hidden: true` the read path refused to honour.
|
| 319 |
+
|
| 320 |
+
Exists so the guard is OBSERVABLE. A guard that holds silently and a guard that is not there
|
| 321 |
+
look identical from the outside, and only one of them is health.
|
| 322 |
+
"""
|
| 323 |
+
locked_set = frozenset(locked) if locked is not None else locked_keys(database_key, fields)
|
| 324 |
+
ov = (overlay_doc or {}).get(database_key) if isinstance(overlay_doc, dict) else None
|
| 325 |
+
ov = ov if isinstance(ov, dict) else {}
|
| 326 |
+
field_list, _meta = _split_contract(fields)
|
| 327 |
+
present = [f.get("key") for f in field_list if isinstance(f, dict)]
|
| 328 |
+
return [k for k in present
|
| 329 |
+
if k in locked_set and isinstance(ov.get(k), dict) and ov[k].get("hidden") is True]
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
# =================================================================================================
|
| 333 |
+
# THE STORE SEAM β injectable, so nothing here has to reach a real store
|
| 334 |
+
# =================================================================================================
|
| 335 |
+
|
| 336 |
+
def _store():
|
| 337 |
+
"""Lazy, per call. `core.store` resolves the backend PER CALL by design and builds its default
|
| 338 |
+
handle at import; binding it at module scope here would freeze the backend at import time and
|
| 339 |
+
drag a store into the gate's import graph."""
|
| 340 |
+
import core.store as _st # noqa: PLC0415 - lazy on purpose, see above
|
| 341 |
+
return _st
|
| 342 |
+
|
| 343 |
+
|
| 344 |
+
def read(st=None):
|
| 345 |
+
"""This tenant's whole overlay document, or `{}` when it has none.
|
| 346 |
+
|
| 347 |
+
β `st` IS THE TENANT'S STORE HANDLE AND A REQUEST PATH MUST PASS IT. The default is NOT the
|
| 348 |
+
active tenant: `core.store`'s module functions go through `_d()`, which under `hf` is
|
| 349 |
+
`_DEFAULT = for_repo(REPO)` - tenant #0's repo, bound at import from `OS_DATA_REPO` - and
|
| 350 |
+
under `pg` is `AIOS_TENANT` or the hardcoded `royal-imports` fallback. Neither is the request's
|
| 351 |
+
tenant. The default exists only for single-tenant tooling; a bare `read()` inside a route is
|
| 352 |
+
the cross-tenant read R5 forbids. A gate injects a fake and touches no real store.
|
| 353 |
+
"""
|
| 354 |
+
doc = (st or _store()).get(STORE_KEY)
|
| 355 |
+
return doc if isinstance(doc, dict) else {}
|
| 356 |
+
|
| 357 |
+
|
| 358 |
+
def write(doc, st=None):
|
| 359 |
+
"""Persist the whole overlay document for this tenant. Returns what was stored.
|
| 360 |
+
|
| 361 |
+
β Same handle rule as `read()`: a route MUST pass the request's tenant store. The default
|
| 362 |
+
lands on tenant #0 under `hf` and on `AIOS_TENANT` under `pg`.
|
| 363 |
+
"""
|
| 364 |
+
if not isinstance(doc, dict):
|
| 365 |
+
raise SchemaOverlayUnsupported(
|
| 366 |
+
type(doc).__name__, reason="the overlay document must be an object.")
|
| 367 |
+
(st or _store()).put(STORE_KEY, doc)
|
| 368 |
+
return doc
|
platform/harness/measure_filter.py
CHANGED
|
@@ -93,8 +93,15 @@ ADMITTED = {
|
|
| 93 |
# basis dropdown). Labels follow the picker's existing vocabulary ('Sales', not 'Revenue').
|
| 94 |
# Both carry the full contract: store_filter_sql on the store path, live_domain on the live
|
| 95 |
# path, and membership in PARITY_CHECKED + store_parity's loop β added in the same change.
|
| 96 |
-
|
| 97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
}
|
| 99 |
|
| 100 |
#: The metrics `semantic.store_parity()` actually exercises against live Odoo. ADMITTED must be
|
|
@@ -227,7 +234,7 @@ def topic_for(key):
|
|
| 227 |
spec = ADMITTED.get(key)
|
| 228 |
if not spec:
|
| 229 |
raise _sem.ModelError(
|
| 230 |
-
f"{key!r} is not an admitted measure. Offered: {sorted(ADMITTED)}
|
| 231 |
f"without an independent validation contract is not filterable (see this module's "
|
| 232 |
f"docstring).")
|
| 233 |
return spec['topic']
|
|
@@ -286,7 +293,7 @@ def _query_parts(key, window, today, team_id):
|
|
| 286 |
bounds = _win.resolve(window, today)
|
| 287 |
if bounds is None:
|
| 288 |
raise _sem.ModelError(
|
| 289 |
-
f"unresolvable window {window!r}
|
| 290 |
f"time, which would widen the condition while the count still looked authoritative")
|
| 291 |
date_from, date_to = bounds
|
| 292 |
|
|
@@ -308,7 +315,7 @@ def _query_parts(key, window, today, team_id):
|
|
| 308 |
params.append(f"{date_to} 23:59:59")
|
| 309 |
if team_id:
|
| 310 |
if not s.get('team_col'):
|
| 311 |
-
raise _sem.ModelError(f"topic {topic!r} is company-level
|
| 312 |
f"filter, so a BU-scoped caller cannot be answered safely")
|
| 313 |
where.append(f"{s['team_col']} = ?")
|
| 314 |
params.append(int(team_id))
|
|
@@ -346,8 +353,8 @@ def resolve_stat(rule, today, team_id=None, allowed_pids=None):
|
|
| 346 |
pool = _pool_of(allowed_pids)
|
| 347 |
if pool is None:
|
| 348 |
raise _sem.ModelError(
|
| 349 |
-
"a statistic needs a population to be computed over, and none was supplied
|
| 350 |
-
"
|
| 351 |
"which would be a different question with an authoritative-looking answer")
|
| 352 |
con = _sem._store_con()
|
| 353 |
try:
|
|
@@ -438,7 +445,7 @@ def resolve_rule(rule, today, team_id=None, allowed_pids=None):
|
|
| 438 |
# authoritative-looking count β the same failure class as defaulting a missing window
|
| 439 |
# to all time, caught by the same principle: refuse, never guess.
|
| 440 |
raise _sem.ModelError(
|
| 441 |
-
'incomplete measure condition
|
| 442 |
'refusing to answer a question that has not been fully asked')
|
| 443 |
rhs = rule.get('rhs')
|
| 444 |
if isinstance(rhs, dict) and rhs.get('kind') == 'measure':
|
|
@@ -603,7 +610,7 @@ def resolve_values(key, window, today, team_id=None, allowed_pids=None):
|
|
| 603 |
# deeper with a less useful message.
|
| 604 |
if _win.resolve(window, today) is None:
|
| 605 |
raise _sem.ModelError(
|
| 606 |
-
f"unresolvable window {window!r} for the {key!r} column
|
| 607 |
f"defaulting to all time")
|
| 608 |
pool = _pool_of(allowed_pids)
|
| 609 |
con = _sem._store_con()
|
|
|
|
| 93 |
# basis dropdown). Labels follow the picker's existing vocabulary ('Sales', not 'Revenue').
|
| 94 |
# Both carry the full contract: store_filter_sql on the store path, live_domain on the live
|
| 95 |
# path, and membership in PARITY_CHECKED + store_parity's loop β added in the same change.
|
| 96 |
+
# β W46 β THE COMMA IS THE RULE, NOT A STYLE CHOICE. These two labels shipped with real EM
|
| 97 |
+
# DASHES ('Sales β fully invoiced') and they reach a screen through the grid's own measure
|
| 98 |
+
# picker, which CLAUDE.md STANDING RULE 2 forbids. `web_prose` never sees them: it scans
|
| 99 |
+
# `aios-web/web/src/**` and a label composed in Python is invisible to it. Rewritten rather
|
| 100 |
+
# than stripped, so the phrase still reads as a sentence. Two mirrors carry the old spelling
|
| 101 |
+
# and are OWED the same edit: `platform/model/metrics/sales.yml` (the metric's own label) and
|
| 102 |
+
# `platform/verify_measure_filter.py`'s label-contract check, which asserts the exact strings.
|
| 103 |
+
'revenue_invoiced': {'label': 'Sales, fully invoiced', 'topic': 'sales_lines'},
|
| 104 |
+
'orders_invoiced': {'label': 'Orders, fully invoiced', 'topic': 'sales_orders'},
|
| 105 |
}
|
| 106 |
|
| 107 |
#: The metrics `semantic.store_parity()` actually exercises against live Odoo. ADMITTED must be
|
|
|
|
| 234 |
spec = ADMITTED.get(key)
|
| 235 |
if not spec:
|
| 236 |
raise _sem.ModelError(
|
| 237 |
+
f"{key!r} is not an admitted measure. Offered: {sorted(ADMITTED)}. A measure "
|
| 238 |
f"without an independent validation contract is not filterable (see this module's "
|
| 239 |
f"docstring).")
|
| 240 |
return spec['topic']
|
|
|
|
| 293 |
bounds = _win.resolve(window, today)
|
| 294 |
if bounds is None:
|
| 295 |
raise _sem.ModelError(
|
| 296 |
+
f"unresolvable window {window!r}: refusing rather than defaulting to all "
|
| 297 |
f"time, which would widen the condition while the count still looked authoritative")
|
| 298 |
date_from, date_to = bounds
|
| 299 |
|
|
|
|
| 315 |
params.append(f"{date_to} 23:59:59")
|
| 316 |
if team_id:
|
| 317 |
if not s.get('team_col'):
|
| 318 |
+
raise _sem.ModelError(f"topic {topic!r} is company-level: it has no business-unit "
|
| 319 |
f"filter, so a BU-scoped caller cannot be answered safely")
|
| 320 |
where.append(f"{s['team_col']} = ?")
|
| 321 |
params.append(int(team_id))
|
|
|
|
| 353 |
pool = _pool_of(allowed_pids)
|
| 354 |
if pool is None:
|
| 355 |
raise _sem.ModelError(
|
| 356 |
+
"a statistic needs a population to be computed over, and none was supplied. "
|
| 357 |
+
"Refusing rather than taking it over whichever customers happen to have rows, "
|
| 358 |
"which would be a different question with an authoritative-looking answer")
|
| 359 |
con = _sem._store_con()
|
| 360 |
try:
|
|
|
|
| 445 |
# authoritative-looking count β the same failure class as defaulting a missing window
|
| 446 |
# to all time, caught by the same principle: refuse, never guess.
|
| 447 |
raise _sem.ModelError(
|
| 448 |
+
'incomplete measure condition: its window, statistic or value is not present; '
|
| 449 |
'refusing to answer a question that has not been fully asked')
|
| 450 |
rhs = rule.get('rhs')
|
| 451 |
if isinstance(rhs, dict) and rhs.get('kind') == 'measure':
|
|
|
|
| 610 |
# deeper with a less useful message.
|
| 611 |
if _win.resolve(window, today) is None:
|
| 612 |
raise _sem.ModelError(
|
| 613 |
+
f"unresolvable window {window!r} for the {key!r} column: refusing rather than "
|
| 614 |
f"defaulting to all time")
|
| 615 |
pool = _pool_of(allowed_pids)
|
| 616 |
con = _sem._store_con()
|
platform/harness/semantic.py
CHANGED
|
@@ -47,7 +47,7 @@ def _customer_move_domain(move_type):
|
|
| 47 |
def build(date_from=None, date_to=None, team_id=None, **kw):
|
| 48 |
if team_id:
|
| 49 |
raise ModelError(
|
| 50 |
-
f"customer {move_type} documents are COMPANY-LEVEL
|
| 51 |
f"carry no trustworthy business-unit tag, so a team-scoped total cannot be "
|
| 52 |
f"produced. Refusing rather than returning the company number.")
|
| 53 |
dom = [("move_type", "=", move_type), ("state", "=", "posted")]
|
|
@@ -211,8 +211,8 @@ def describe(key):
|
|
| 211 |
def _domain(topic_def, date_from, date_to, team_id):
|
| 212 |
b = topic_def.get("domain_builder")
|
| 213 |
if not b:
|
| 214 |
-
raise ModelError(f"topic {topic_def['key']!r} is store-only
|
| 215 |
-
f"
|
| 216 |
return _BUILDERS[b](date_from, date_to, team_id=team_id)
|
| 217 |
|
| 218 |
|
|
@@ -437,7 +437,7 @@ def _store_con():
|
|
| 437 |
import harness.datastore as DS
|
| 438 |
if not DS.ready(): # a mid-backfill store returns PARTIAL totals silently
|
| 439 |
raise ModelError("the data cache is still warming up after a restart (a one-time first "
|
| 440 |
-
"sync)
|
| 441 |
"moment and I'll have it")
|
| 442 |
return DS.ro_cursor() # cursor on the shared instance β no sync-writer contention
|
| 443 |
|
|
@@ -585,13 +585,13 @@ def _clean_tree(tree, cols, tolerate=()):
|
|
| 585 |
# it here, the fix is to pass the membership in, not to let it fall through.
|
| 586 |
if cohorts:
|
| 587 |
raise ModelError(
|
| 588 |
-
f"filter tree carries cohort-membership condition(s) {sorted(set(cohorts))}
|
| 589 |
-
f"
|
| 590 |
f"dropping it, which would silently widen the result under an authoritative count.")
|
| 591 |
if windowed:
|
| 592 |
raise ModelError(
|
| 593 |
f"filter tree carries measure condition(s) over a date window {sorted(set(windowed))}"
|
| 594 |
-
f"
|
| 595 |
f"this query. Refusing rather than dropping or mis-compiling them, either of which "
|
| 596 |
f"would silently answer a different question under an authoritative count.")
|
| 597 |
# The UI cleaner drops unknown columns/operators for stale saved views. On a server query
|
|
@@ -785,7 +785,7 @@ def _channel_sql(channel):
|
|
| 785 |
tid = names.get(channel)
|
| 786 |
if tid is None:
|
| 787 |
raise ModelError(
|
| 788 |
-
f"channel {channel!r} is not a team this tenant names
|
| 789 |
f"carries {sorted(names)}, so the channel cannot be resolved to a team id")
|
| 790 |
return f"o.team_id = {int(tid)} AND l.order_partner_id NOT IN " \
|
| 791 |
f"(SELECT id FROM res_partner WHERE name LIKE {_sql_value(excl)})"
|
|
@@ -863,7 +863,7 @@ def store_query(topic, measures, group_by=None, grain=None, date_from=None, date
|
|
| 863 |
# never count(*) on the wrong table); in a GROUPED query they are refused (split the request).
|
| 864 |
foreign = [k for k in base_keys if _model()["metrics"][k]["topic"] != topic]
|
| 865 |
if foreign and (group_by or grain):
|
| 866 |
-
raise ModelError(f"metrics {foreign} belong to another topic
|
| 867 |
f"scalar-only; run them against their own topic when grouping")
|
| 868 |
base_keys = [k for k in base_keys if k not in foreign]
|
| 869 |
foreign_vals = {}
|
|
@@ -913,7 +913,7 @@ def store_query(topic, measures, group_by=None, grain=None, date_from=None, date
|
|
| 913 |
# cell that reads as "this SKU sold nothing on Amazon" β a FALSE number, not a narrower one.
|
| 914 |
if team_id and scope_variant is None:
|
| 915 |
if not s.get("team_col"):
|
| 916 |
-
raise ModelError(f"topic {topic!r} is company-level
|
| 917 |
where.append(f"{s['team_col']} = ?"); params.append(int(team_id))
|
| 918 |
if exclude_services and s.get("service_filter"):
|
| 919 |
where.append(render_scope(s["service_filter"]))
|
|
@@ -946,7 +946,7 @@ def store_query(topic, measures, group_by=None, grain=None, date_from=None, date
|
|
| 946 |
if pred.uses_aggregate:
|
| 947 |
bad = sorted(c for c in pred.columns_used if cols[c].get("aggregate"))
|
| 948 |
raise ModelError(
|
| 949 |
-
f"filter_tree references measure(s) {bad}
|
| 950 |
f"HAVING, and that path is deliberately NOT built: CG-1 ships the WHERE path "
|
| 951 |
f"because its consumer (CG-2, the line-grain sales table) does not aggregate. "
|
| 952 |
f"Filter on dims, or aggregate first and filter the result.")
|
|
@@ -1044,7 +1044,7 @@ def store_rows(topic, date_from=None, date_to=None, team_id=None, filter_tree=No
|
|
| 1044 |
scope_params.append(f"{date_to} 23:59:59")
|
| 1045 |
if team_id:
|
| 1046 |
if not s.get("team_col"):
|
| 1047 |
-
raise ModelError(f"topic {topic!r} is company-level
|
| 1048 |
scope.append(f"{s['team_col']} = ?")
|
| 1049 |
scope_params.append(int(team_id))
|
| 1050 |
if exclude_services and s.get("service_filter"):
|
|
@@ -1403,7 +1403,7 @@ def _one_binding_offer(topic, b, strict=False, ready=None):
|
|
| 1403 |
# THIS question cannot answer the grouped query either, so offering the column would mint
|
| 1404 |
# exactly the permanently-blank field the check exists to prevent. Fail closed.
|
| 1405 |
why = ((f"the mirror has not finished syncing `{_tbl}`, so every key from {b['source']!r} "
|
| 1406 |
-
f"would render blank or
|
| 1407 |
f"run `datastore.sync_entity('{_tbl}')` until its phase is `live`")
|
| 1408 |
if _rdy is False else
|
| 1409 |
(f"the tenant store could not be read, so whether `{_tbl}` can answer is UNKNOWN; "
|
|
@@ -1421,7 +1421,7 @@ def _one_binding_offer(topic, b, strict=False, ready=None):
|
|
| 1421 |
# user did not get rather than a base metric they never asked for.
|
| 1422 |
key = key + _suffix
|
| 1423 |
if strict:
|
| 1424 |
-
raise _EntityMeasureError(f"{topic}: measure {key!r} refused
|
| 1425 |
refused.append({"key": key, "reason": reason})
|
| 1426 |
|
| 1427 |
for key in b["keys"]:
|
|
@@ -1439,7 +1439,7 @@ def _one_binding_offer(topic, b, strict=False, ready=None):
|
|
| 1439 |
continue
|
| 1440 |
foreign = sorted({k for k in base if mts[k].get("topic", b["source"]) != b["source"]})
|
| 1441 |
if foreign:
|
| 1442 |
-
refuse(key, f"base measure(s) {foreign} live on another topic
|
| 1443 |
f"are scalar-only and are refused under a group_by")
|
| 1444 |
continue
|
| 1445 |
empty = m.get("empty")
|
|
@@ -1573,7 +1573,7 @@ def entity_measure_values(topic, keys, date_from=None, date_to=None, team_id=Non
|
|
| 1573 |
# `rollup_sql.group_values` makes, for the same reason. Never write cells from one.
|
| 1574 |
if res.get("truncated"):
|
| 1575 |
raise _EntityMeasureError(
|
| 1576 |
-
f"{topic}: {src} grouped by {dim} exceeded {MAX_GROUPS} groups
|
| 1577 |
f"cells from a truncated result")
|
| 1578 |
# `store_query` emits the bare dim name when the dim has no `name_col`, `<dim>_id` when it
|
| 1579 |
# does. Both shapes are live in the model, so read whichever arrived.
|
|
|
|
| 47 |
def build(date_from=None, date_to=None, team_id=None, **kw):
|
| 48 |
if team_id:
|
| 49 |
raise ModelError(
|
| 50 |
+
f"customer {move_type} documents are COMPANY-LEVEL. Credit notes and invoices "
|
| 51 |
f"carry no trustworthy business-unit tag, so a team-scoped total cannot be "
|
| 52 |
f"produced. Refusing rather than returning the company number.")
|
| 53 |
dom = [("move_type", "=", move_type), ("state", "=", "posted")]
|
|
|
|
| 211 |
def _domain(topic_def, date_from, date_to, team_id):
|
| 212 |
b = topic_def.get("domain_builder")
|
| 213 |
if not b:
|
| 214 |
+
raise ModelError(f"topic {topic_def['key']!r} is store-only: use store_query(). "
|
| 215 |
+
f"No live-path domain builder is bound yet.")
|
| 216 |
return _BUILDERS[b](date_from, date_to, team_id=team_id)
|
| 217 |
|
| 218 |
|
|
|
|
| 437 |
import harness.datastore as DS
|
| 438 |
if not DS.ready(): # a mid-backfill store returns PARTIAL totals silently
|
| 439 |
raise ModelError("the data cache is still warming up after a restart (a one-time first "
|
| 440 |
+
"sync). The dashboards work now from live data; ask me again in a "
|
| 441 |
"moment and I'll have it")
|
| 442 |
return DS.ro_cursor() # cursor on the shared instance β no sync-writer contention
|
| 443 |
|
|
|
|
| 585 |
# it here, the fix is to pass the membership in, not to let it fall through.
|
| 586 |
if cohorts:
|
| 587 |
raise ModelError(
|
| 588 |
+
f"filter tree carries cohort-membership condition(s) {sorted(set(cohorts))}. "
|
| 589 |
+
f"Cohort membership is host state, not a column of this topic. Refusing rather than "
|
| 590 |
f"dropping it, which would silently widen the result under an authoritative count.")
|
| 591 |
if windowed:
|
| 592 |
raise ModelError(
|
| 593 |
f"filter tree carries measure condition(s) over a date window {sorted(set(windowed))}"
|
| 594 |
+
f". Those are resolved to a set of ids by harness.measure_filter, not compiled into "
|
| 595 |
f"this query. Refusing rather than dropping or mis-compiling them, either of which "
|
| 596 |
f"would silently answer a different question under an authoritative count.")
|
| 597 |
# The UI cleaner drops unknown columns/operators for stale saved views. On a server query
|
|
|
|
| 785 |
tid = names.get(channel)
|
| 786 |
if tid is None:
|
| 787 |
raise ModelError(
|
| 788 |
+
f"channel {channel!r} is not a team this tenant names. `tenant.yml::team_names` "
|
| 789 |
f"carries {sorted(names)}, so the channel cannot be resolved to a team id")
|
| 790 |
return f"o.team_id = {int(tid)} AND l.order_partner_id NOT IN " \
|
| 791 |
f"(SELECT id FROM res_partner WHERE name LIKE {_sql_value(excl)})"
|
|
|
|
| 863 |
# never count(*) on the wrong table); in a GROUPED query they are refused (split the request).
|
| 864 |
foreign = [k for k in base_keys if _model()["metrics"][k]["topic"] != topic]
|
| 865 |
if foreign and (group_by or grain):
|
| 866 |
+
raise ModelError(f"metrics {foreign} belong to another topic. Cross-topic measures are "
|
| 867 |
f"scalar-only; run them against their own topic when grouping")
|
| 868 |
base_keys = [k for k in base_keys if k not in foreign]
|
| 869 |
foreign_vals = {}
|
|
|
|
| 913 |
# cell that reads as "this SKU sold nothing on Amazon" β a FALSE number, not a narrower one.
|
| 914 |
if team_id and scope_variant is None:
|
| 915 |
if not s.get("team_col"):
|
| 916 |
+
raise ModelError(f"topic {topic!r} is company-level: it has no business-unit filter")
|
| 917 |
where.append(f"{s['team_col']} = ?"); params.append(int(team_id))
|
| 918 |
if exclude_services and s.get("service_filter"):
|
| 919 |
where.append(render_scope(s["service_filter"]))
|
|
|
|
| 946 |
if pred.uses_aggregate:
|
| 947 |
bad = sorted(c for c in pred.columns_used if cols[c].get("aggregate"))
|
| 948 |
raise ModelError(
|
| 949 |
+
f"filter_tree references measure(s) {bad}. A measure filter has to land in "
|
| 950 |
f"HAVING, and that path is deliberately NOT built: CG-1 ships the WHERE path "
|
| 951 |
f"because its consumer (CG-2, the line-grain sales table) does not aggregate. "
|
| 952 |
f"Filter on dims, or aggregate first and filter the result.")
|
|
|
|
| 1044 |
scope_params.append(f"{date_to} 23:59:59")
|
| 1045 |
if team_id:
|
| 1046 |
if not s.get("team_col"):
|
| 1047 |
+
raise ModelError(f"topic {topic!r} is company-level: it has no business-unit filter")
|
| 1048 |
scope.append(f"{s['team_col']} = ?")
|
| 1049 |
scope_params.append(int(team_id))
|
| 1050 |
if exclude_services and s.get("service_filter"):
|
|
|
|
| 1403 |
# THIS question cannot answer the grouped query either, so offering the column would mint
|
| 1404 |
# exactly the permanently-blank field the check exists to prevent. Fail closed.
|
| 1405 |
why = ((f"the mirror has not finished syncing `{_tbl}`, so every key from {b['source']!r} "
|
| 1406 |
+
f"would render blank, or worse, as a too-small number from a half-filled table; "
|
| 1407 |
f"run `datastore.sync_entity('{_tbl}')` until its phase is `live`")
|
| 1408 |
if _rdy is False else
|
| 1409 |
(f"the tenant store could not be read, so whether `{_tbl}` can answer is UNKNOWN; "
|
|
|
|
| 1421 |
# user did not get rather than a base metric they never asked for.
|
| 1422 |
key = key + _suffix
|
| 1423 |
if strict:
|
| 1424 |
+
raise _EntityMeasureError(f"{topic}: measure {key!r} refused: {reason}")
|
| 1425 |
refused.append({"key": key, "reason": reason})
|
| 1426 |
|
| 1427 |
for key in b["keys"]:
|
|
|
|
| 1439 |
continue
|
| 1440 |
foreign = sorted({k for k in base if mts[k].get("topic", b["source"]) != b["source"]})
|
| 1441 |
if foreign:
|
| 1442 |
+
refuse(key, f"base measure(s) {foreign} live on another topic. Cross-topic measures "
|
| 1443 |
f"are scalar-only and are refused under a group_by")
|
| 1444 |
continue
|
| 1445 |
empty = m.get("empty")
|
|
|
|
| 1573 |
# `rollup_sql.group_values` makes, for the same reason. Never write cells from one.
|
| 1574 |
if res.get("truncated"):
|
| 1575 |
raise _EntityMeasureError(
|
| 1576 |
+
f"{topic}: {src} grouped by {dim} exceeded {MAX_GROUPS} groups, so refusing to write "
|
| 1577 |
f"cells from a truncated result")
|
| 1578 |
# `store_query` emits the bare dim name when the dim has no `name_col`, `<dim>_id` when it
|
| 1579 |
# does. Both shapes are live in the model, so read whichever arrived.
|
platform/model/metrics/sales.yml
CHANGED
|
@@ -1,149 +1,149 @@
|
|
| 1 |
-
# Metrics: sales β the core wholesale metrics, defined ONCE (OM-0). Every surface (pages, the
|
| 2 |
-
# metric dictionary, the Analyst, MCP) resolves these by key through harness/semantic.py.
|
| 3 |
-
# Fields per metric:
|
| 4 |
-
# key/label/description β identity + the human definition (visibility = trust)
|
| 5 |
-
# agg + field β sum | count_distinct over the topic's entity
|
| 6 |
-
# agg: ratio β numerator/denominator are metric KEYS (resolved recursively)
|
| 7 |
-
# agg: derived + expr β arithmetic over metric keys (safe parser; +,-,*,/ and parens only)
|
| 8 |
-
# format β usd | int | pct (rendering hint for surfaces)
|
| 9 |
-
# ai_context β what a small model must know to use the metric correctly
|
| 10 |
-
# validate β the INDEPENDENT Odoo cross-check contract (named method implemented in
|
| 11 |
-
# harness/semantic.py _VALIDATORS; a metric that can't tie out says so)
|
| 12 |
-
# empty β W37 C1's EMPTY-WINDOW FAMILY. See below; a metric an ENTITY topic
|
| 13 |
-
# offers as a lookback column MUST declare one.
|
| 14 |
-
#
|
| 15 |
-
# ββ `empty:` β WHAT A ROW WITH NO ACTIVITY IN THE WINDOW RENDERS AS (wave 37, contract C1).
|
| 16 |
-
# Measured and load-bearing: only 1,646 of 5,836 active products sold in the last 90 days, so a
|
| 17 |
-
# per-SKU lookback metric has NO GROUP for 72% of the catalogue. Get the default wrong and every
|
| 18 |
-
# product grid reads as broken. Two values, and the difference is whether the blank cell would be
|
| 19 |
-
# a TRUE STATEMENT:
|
| 20 |
-
# empty: zero ADDITIVE β units, revenue, margin $, COGS. "It sold nothing" is a real
|
| 21 |
-
# measurement, so 0 is the honest cell and a blank would hide a fact.
|
| 22 |
-
# empty: blank RATIO / DERIVED-FROM-A-RATIO β GM %, ASP. A 0% margin on zero sales is a
|
| 23 |
-
# FALSE statement, not a missing one. β AND THE GUARD IS THE DENOMINATOR, NOT
|
| 24 |
-
# THE MISSING GROUP: `semantic._post_compute` returns 0.0 for `num/0`, so a SKU
|
| 25 |
-
# that DID sell at $0 would print "0.0%" with a group behind it. The resolver
|
| 26 |
-
# blanks on a zero denominator, which is the only reading that is never a lie.
|
| 27 |
-
# β A metric with no `empty:` is REFUSED by `entity_measures()` rather than defaulted β a
|
| 28 |
-
# defaulted family is a guess about truth, and C1 says a metric that cannot say which family it
|
| 29 |
-
# is in does not ship.
|
| 30 |
-
topic: sales_lines
|
| 31 |
-
metrics:
|
| 32 |
-
- key: revenue
|
| 33 |
-
label: Revenue
|
| 34 |
-
agg: sum
|
| 35 |
-
field: price_subtotal
|
| 36 |
-
format: usd
|
| 37 |
-
empty: zero
|
| 38 |
-
description: "Untaxed revenue of confirmed wholesale order lines (the owner's 'sales' number)."
|
| 39 |
-
ai_context: "Always untaxed; excludes Amazon (GIFTWARE DEALS) and unconfirmed orders. Filter one BU via team_id (Fisch=5, Royal=6)."
|
| 40 |
-
validate:
|
| 41 |
-
method: order_level_revenue
|
| 42 |
-
note: "Ξ£ line price_subtotal must equal Ξ£ parent-order amount_untaxed under the same scope, to the cent (line vs order basis β the built-in cross-check)."
|
| 43 |
-
|
| 44 |
-
- key: units
|
| 45 |
-
label: Units sold
|
| 46 |
-
agg: sum
|
| 47 |
-
field: product_uom_qty
|
| 48 |
-
format: int
|
| 49 |
-
empty: zero
|
| 50 |
-
description: "Total quantity across confirmed wholesale order lines."
|
| 51 |
-
ai_context: "Mixed UoMs are summed as ordered quantity; for weight/case analysis convert per product UoM first."
|
| 52 |
-
|
| 53 |
-
- key: margin
|
| 54 |
-
label: Gross margin $
|
| 55 |
-
agg: sum
|
| 56 |
-
field: margin
|
| 57 |
-
format: usd
|
| 58 |
-
empty: zero
|
| 59 |
-
description: "Line revenue minus line cost (Odoo Margin module), summed."
|
| 60 |
-
ai_context: "margin is read_group-aggregatable (Margin module installed). COGS = revenue - margin. purchase_price is per-UNIT cost β never sum it as a total."
|
| 61 |
-
|
| 62 |
-
- key: cogs
|
| 63 |
-
label: COGS
|
| 64 |
-
agg: derived
|
| 65 |
-
expr: "revenue - margin"
|
| 66 |
-
format: usd
|
| 67 |
-
empty: zero
|
| 68 |
-
description: "Cost of goods sold, derived: revenue minus gross margin."
|
| 69 |
-
ai_context: "Derived, not pulled β Odoo carries cost on lines as margin; COGS is the difference."
|
| 70 |
-
|
| 71 |
-
- key: margin_pct
|
| 72 |
-
label: Gross margin %
|
| 73 |
-
agg: ratio
|
| 74 |
-
numerator: margin
|
| 75 |
-
denominator: revenue
|
| 76 |
-
format: pct
|
| 77 |
-
empty: blank
|
| 78 |
-
description: "Gross margin as a share of revenue."
|
| 79 |
-
ai_context: "Compare across BUs/categories at the same scope only. β TWO ZERO-REVENUE BEHAVIOURS, deliberately: the scalar/analyst path returns 0 (semantic._post_compute's guard), while an ENTITY LOOKBACK COLUMN renders BLANK (empty: blank) β on a grid, a printed 0.0% beside 5,836 products would assert a margin nobody measured."
|
| 80 |
-
|
| 81 |
-
# β W37-T10 β ASP, the fifth SHIP-FIRST per-SKU metric (proto/P3). Blended $18.76 over 1,646
|
| 82 |
-
# SKUs in the 90 days to 2026-08-19. A RATIO of two same-topic base measures, so it survives a
|
| 83 |
-
# GROUPED store_query (only a CROSS-TOPIC component is refused β that is what stops `aov`,
|
| 84 |
-
# whose denominator `orders` lives on sales_orders).
|
| 85 |
-
# β UNITS ARE AS-ORDERED, mixed UoM. `units` says so and this inherits it: a SKU sold in cases
|
| 86 |
-
# and in singles has an ASP blended across both, which is the true average selling price of a
|
| 87 |
-
# line unit and NOT a per-piece price.
|
| 88 |
-
- key: asp
|
| 89 |
-
label: Average selling price
|
| 90 |
-
agg: ratio
|
| 91 |
-
numerator: revenue
|
| 92 |
-
denominator: units
|
| 93 |
-
format: usd
|
| 94 |
-
empty: blank
|
| 95 |
-
description: "Revenue per unit sold β the blended average selling price."
|
| 96 |
-
ai_context: "revenue Γ· units at identical scope. Mixed units of measure are summed as ordered quantity, so this is per ordered unit, not per piece. Blank when nothing sold: an ASP of $0 on zero units is a false statement, not a missing one."
|
| 97 |
-
|
| 98 |
-
- key: orders
|
| 99 |
-
label: Orders
|
| 100 |
-
topic: sales_orders
|
| 101 |
-
agg: count
|
| 102 |
-
format: int
|
| 103 |
-
description: "Confirmed wholesale orders in the window (order-header count β what the scorecards show)."
|
| 104 |
-
ai_context: "Order-level count; slightly higher than distinct-orders-from-lines because a few confirmed orders carry zero lines (a data-health artifact the reconciliation contract counts exactly)."
|
| 105 |
-
validate:
|
| 106 |
-
method: order_count
|
| 107 |
-
note: "Order-level count must equal distinct line-parent orders + line-less orders, exactly (surfaces empty orders instead of hiding them in a tolerance)."
|
| 108 |
-
|
| 109 |
-
- key: customers
|
| 110 |
-
label: Active customers
|
| 111 |
-
agg: count_distinct
|
| 112 |
-
field: order_partner_id
|
| 113 |
-
format: int
|
| 114 |
-
empty: zero
|
| 115 |
-
description: "Distinct customers with at least one confirmed wholesale order line in the window."
|
| 116 |
-
ai_context: "Customer = the order's partner. Agent attribution uses res.partner.agent_ids, NOT the order user_id."
|
| 117 |
-
|
| 118 |
-
- key: aov
|
| 119 |
-
label: Average order value
|
| 120 |
-
agg: ratio
|
| 121 |
-
numerator: revenue
|
| 122 |
-
denominator: orders
|
| 123 |
-
format: usd
|
| 124 |
-
description: "Revenue per distinct order."
|
| 125 |
-
ai_context: "Ratio of two registered metrics at identical scope; never average per-order averages."
|
| 126 |
-
|
| 127 |
-
# β Wave 21 R2 β the FULLY-INVOICED basis, as separate metrics (owner ruling: picker entries,
|
| 128 |
-
# not a basis dropdown). Same topics, same scope, ONE predicate narrower: the order's Odoo
|
| 129 |
-
# invoice_status = 'invoiced'. `store_filter_sql` filters the store path (sum/count CASE);
|
| 130 |
-
# `live_domain` filters the live path β BOTH or store_parity compares two different questions.
|
| 131 |
-
- key: revenue_invoiced
|
| 132 |
-
label: Sales
|
| 133 |
-
agg: sum
|
| 134 |
-
field: price_subtotal
|
| 135 |
-
store_filter_sql: "o.invoice_status = 'invoiced'"
|
| 136 |
-
live_domain: [["order_id.invoice_status", "=", "invoiced"]]
|
| 137 |
-
format: usd
|
| 138 |
-
description: "Untaxed revenue of confirmed wholesale order lines whose parent order Odoo marks fully invoiced (invoice_status = invoiced)."
|
| 139 |
-
ai_context: "Same scope as revenue, narrowed by the ORDER-level fully-invoiced flag. This is NOT posted-invoice-line revenue: a partially invoiced order is excluded entirely until Odoo flips the flag. Reconciled store-vs-live per BU by store_parity."
|
| 140 |
-
|
| 141 |
-
- key: orders_invoiced
|
| 142 |
-
label: Orders
|
| 143 |
-
topic: sales_orders
|
| 144 |
-
agg: count
|
| 145 |
-
store_filter_sql: "o.invoice_status = 'invoiced'"
|
| 146 |
-
live_domain: [["invoice_status", "=", "invoiced"]]
|
| 147 |
-
format: int
|
| 148 |
-
description: "Confirmed wholesale orders Odoo marks fully invoiced (invoice_status = invoiced)."
|
| 149 |
-
ai_context: "Order-header count under the orders scope plus the fully-invoiced flag; partially invoiced and not-yet-invoiced orders are excluded. Reconciled store-vs-live per BU by store_parity."
|
|
|
|
| 1 |
+
# Metrics: sales β the core wholesale metrics, defined ONCE (OM-0). Every surface (pages, the
|
| 2 |
+
# metric dictionary, the Analyst, MCP) resolves these by key through harness/semantic.py.
|
| 3 |
+
# Fields per metric:
|
| 4 |
+
# key/label/description β identity + the human definition (visibility = trust)
|
| 5 |
+
# agg + field β sum | count_distinct over the topic's entity
|
| 6 |
+
# agg: ratio β numerator/denominator are metric KEYS (resolved recursively)
|
| 7 |
+
# agg: derived + expr β arithmetic over metric keys (safe parser; +,-,*,/ and parens only)
|
| 8 |
+
# format β usd | int | pct (rendering hint for surfaces)
|
| 9 |
+
# ai_context β what a small model must know to use the metric correctly
|
| 10 |
+
# validate β the INDEPENDENT Odoo cross-check contract (named method implemented in
|
| 11 |
+
# harness/semantic.py _VALIDATORS; a metric that can't tie out says so)
|
| 12 |
+
# empty β W37 C1's EMPTY-WINDOW FAMILY. See below; a metric an ENTITY topic
|
| 13 |
+
# offers as a lookback column MUST declare one.
|
| 14 |
+
#
|
| 15 |
+
# ββ `empty:` β WHAT A ROW WITH NO ACTIVITY IN THE WINDOW RENDERS AS (wave 37, contract C1).
|
| 16 |
+
# Measured and load-bearing: only 1,646 of 5,836 active products sold in the last 90 days, so a
|
| 17 |
+
# per-SKU lookback metric has NO GROUP for 72% of the catalogue. Get the default wrong and every
|
| 18 |
+
# product grid reads as broken. Two values, and the difference is whether the blank cell would be
|
| 19 |
+
# a TRUE STATEMENT:
|
| 20 |
+
# empty: zero ADDITIVE β units, revenue, margin $, COGS. "It sold nothing" is a real
|
| 21 |
+
# measurement, so 0 is the honest cell and a blank would hide a fact.
|
| 22 |
+
# empty: blank RATIO / DERIVED-FROM-A-RATIO β GM %, ASP. A 0% margin on zero sales is a
|
| 23 |
+
# FALSE statement, not a missing one. β AND THE GUARD IS THE DENOMINATOR, NOT
|
| 24 |
+
# THE MISSING GROUP: `semantic._post_compute` returns 0.0 for `num/0`, so a SKU
|
| 25 |
+
# that DID sell at $0 would print "0.0%" with a group behind it. The resolver
|
| 26 |
+
# blanks on a zero denominator, which is the only reading that is never a lie.
|
| 27 |
+
# β A metric with no `empty:` is REFUSED by `entity_measures()` rather than defaulted β a
|
| 28 |
+
# defaulted family is a guess about truth, and C1 says a metric that cannot say which family it
|
| 29 |
+
# is in does not ship.
|
| 30 |
+
topic: sales_lines
|
| 31 |
+
metrics:
|
| 32 |
+
- key: revenue
|
| 33 |
+
label: Revenue
|
| 34 |
+
agg: sum
|
| 35 |
+
field: price_subtotal
|
| 36 |
+
format: usd
|
| 37 |
+
empty: zero
|
| 38 |
+
description: "Untaxed revenue of confirmed wholesale order lines (the owner's 'sales' number)."
|
| 39 |
+
ai_context: "Always untaxed; excludes Amazon (GIFTWARE DEALS) and unconfirmed orders. Filter one BU via team_id (Fisch=5, Royal=6)."
|
| 40 |
+
validate:
|
| 41 |
+
method: order_level_revenue
|
| 42 |
+
note: "Ξ£ line price_subtotal must equal Ξ£ parent-order amount_untaxed under the same scope, to the cent (line vs order basis β the built-in cross-check)."
|
| 43 |
+
|
| 44 |
+
- key: units
|
| 45 |
+
label: Units sold
|
| 46 |
+
agg: sum
|
| 47 |
+
field: product_uom_qty
|
| 48 |
+
format: int
|
| 49 |
+
empty: zero
|
| 50 |
+
description: "Total quantity across confirmed wholesale order lines."
|
| 51 |
+
ai_context: "Mixed UoMs are summed as ordered quantity; for weight/case analysis convert per product UoM first."
|
| 52 |
+
|
| 53 |
+
- key: margin
|
| 54 |
+
label: Gross margin $
|
| 55 |
+
agg: sum
|
| 56 |
+
field: margin
|
| 57 |
+
format: usd
|
| 58 |
+
empty: zero
|
| 59 |
+
description: "Line revenue minus line cost (Odoo Margin module), summed."
|
| 60 |
+
ai_context: "margin is read_group-aggregatable (Margin module installed). COGS = revenue - margin. purchase_price is per-UNIT cost β never sum it as a total."
|
| 61 |
+
|
| 62 |
+
- key: cogs
|
| 63 |
+
label: COGS
|
| 64 |
+
agg: derived
|
| 65 |
+
expr: "revenue - margin"
|
| 66 |
+
format: usd
|
| 67 |
+
empty: zero
|
| 68 |
+
description: "Cost of goods sold, derived: revenue minus gross margin."
|
| 69 |
+
ai_context: "Derived, not pulled β Odoo carries cost on lines as margin; COGS is the difference."
|
| 70 |
+
|
| 71 |
+
- key: margin_pct
|
| 72 |
+
label: Gross margin %
|
| 73 |
+
agg: ratio
|
| 74 |
+
numerator: margin
|
| 75 |
+
denominator: revenue
|
| 76 |
+
format: pct
|
| 77 |
+
empty: blank
|
| 78 |
+
description: "Gross margin as a share of revenue."
|
| 79 |
+
ai_context: "Compare across BUs/categories at the same scope only. β TWO ZERO-REVENUE BEHAVIOURS, deliberately: the scalar/analyst path returns 0 (semantic._post_compute's guard), while an ENTITY LOOKBACK COLUMN renders BLANK (empty: blank) β on a grid, a printed 0.0% beside 5,836 products would assert a margin nobody measured."
|
| 80 |
+
|
| 81 |
+
# β W37-T10 β ASP, the fifth SHIP-FIRST per-SKU metric (proto/P3). Blended $18.76 over 1,646
|
| 82 |
+
# SKUs in the 90 days to 2026-08-19. A RATIO of two same-topic base measures, so it survives a
|
| 83 |
+
# GROUPED store_query (only a CROSS-TOPIC component is refused β that is what stops `aov`,
|
| 84 |
+
# whose denominator `orders` lives on sales_orders).
|
| 85 |
+
# β UNITS ARE AS-ORDERED, mixed UoM. `units` says so and this inherits it: a SKU sold in cases
|
| 86 |
+
# and in singles has an ASP blended across both, which is the true average selling price of a
|
| 87 |
+
# line unit and NOT a per-piece price.
|
| 88 |
+
- key: asp
|
| 89 |
+
label: Average selling price
|
| 90 |
+
agg: ratio
|
| 91 |
+
numerator: revenue
|
| 92 |
+
denominator: units
|
| 93 |
+
format: usd
|
| 94 |
+
empty: blank
|
| 95 |
+
description: "Revenue per unit sold β the blended average selling price."
|
| 96 |
+
ai_context: "revenue Γ· units at identical scope. Mixed units of measure are summed as ordered quantity, so this is per ordered unit, not per piece. Blank when nothing sold: an ASP of $0 on zero units is a false statement, not a missing one."
|
| 97 |
+
|
| 98 |
+
- key: orders
|
| 99 |
+
label: Orders
|
| 100 |
+
topic: sales_orders
|
| 101 |
+
agg: count
|
| 102 |
+
format: int
|
| 103 |
+
description: "Confirmed wholesale orders in the window (order-header count β what the scorecards show)."
|
| 104 |
+
ai_context: "Order-level count; slightly higher than distinct-orders-from-lines because a few confirmed orders carry zero lines (a data-health artifact the reconciliation contract counts exactly)."
|
| 105 |
+
validate:
|
| 106 |
+
method: order_count
|
| 107 |
+
note: "Order-level count must equal distinct line-parent orders + line-less orders, exactly (surfaces empty orders instead of hiding them in a tolerance)."
|
| 108 |
+
|
| 109 |
+
- key: customers
|
| 110 |
+
label: Active customers
|
| 111 |
+
agg: count_distinct
|
| 112 |
+
field: order_partner_id
|
| 113 |
+
format: int
|
| 114 |
+
empty: zero
|
| 115 |
+
description: "Distinct customers with at least one confirmed wholesale order line in the window."
|
| 116 |
+
ai_context: "Customer = the order's partner. Agent attribution uses res.partner.agent_ids, NOT the order user_id."
|
| 117 |
+
|
| 118 |
+
- key: aov
|
| 119 |
+
label: Average order value
|
| 120 |
+
agg: ratio
|
| 121 |
+
numerator: revenue
|
| 122 |
+
denominator: orders
|
| 123 |
+
format: usd
|
| 124 |
+
description: "Revenue per distinct order."
|
| 125 |
+
ai_context: "Ratio of two registered metrics at identical scope; never average per-order averages."
|
| 126 |
+
|
| 127 |
+
# β Wave 21 R2 β the FULLY-INVOICED basis, as separate metrics (owner ruling: picker entries,
|
| 128 |
+
# not a basis dropdown). Same topics, same scope, ONE predicate narrower: the order's Odoo
|
| 129 |
+
# invoice_status = 'invoiced'. `store_filter_sql` filters the store path (sum/count CASE);
|
| 130 |
+
# `live_domain` filters the live path β BOTH or store_parity compares two different questions.
|
| 131 |
+
- key: revenue_invoiced
|
| 132 |
+
label: Sales, fully invoiced
|
| 133 |
+
agg: sum
|
| 134 |
+
field: price_subtotal
|
| 135 |
+
store_filter_sql: "o.invoice_status = 'invoiced'"
|
| 136 |
+
live_domain: [["order_id.invoice_status", "=", "invoiced"]]
|
| 137 |
+
format: usd
|
| 138 |
+
description: "Untaxed revenue of confirmed wholesale order lines whose parent order Odoo marks fully invoiced (invoice_status = invoiced)."
|
| 139 |
+
ai_context: "Same scope as revenue, narrowed by the ORDER-level fully-invoiced flag. This is NOT posted-invoice-line revenue: a partially invoiced order is excluded entirely until Odoo flips the flag. Reconciled store-vs-live per BU by store_parity."
|
| 140 |
+
|
| 141 |
+
- key: orders_invoiced
|
| 142 |
+
label: Orders, fully invoiced
|
| 143 |
+
topic: sales_orders
|
| 144 |
+
agg: count
|
| 145 |
+
store_filter_sql: "o.invoice_status = 'invoiced'"
|
| 146 |
+
live_domain: [["invoice_status", "=", "invoiced"]]
|
| 147 |
+
format: int
|
| 148 |
+
description: "Confirmed wholesale orders Odoo marks fully invoiced (invoice_status = invoiced)."
|
| 149 |
+
ai_context: "Order-header count under the orders scope plus the fully-invoiced flag; partially invoiced and not-yet-invoiced orders are excluded. Reconciled store-vs-live per BU by store_parity."
|
web/src/automation/AutomationDetail.tsx
CHANGED
|
@@ -83,6 +83,19 @@ import {
|
|
| 83 |
updateAgentGovernance,
|
| 84 |
} from "./automationApi";
|
| 85 |
import "../styles/wave45/agent-operator.css";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
interface Props {
|
| 88 |
automation: Automation;
|
|
@@ -417,22 +430,93 @@ export default function AutomationDetail({
|
|
| 417 |
DEFAULT, not a memory: opening any agent should start in the conversation. Remembering
|
| 418 |
"you were last on Canvas" would quietly restore the behaviour this line exists to change,
|
| 419 |
for exactly the people who used the Canvas once.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 420 |
*/
|
| 421 |
-
const [view, setView] = useState<"canvas" | "chat">("chat");
|
| 422 |
const [agentContract, setAgentContract] = useState<AgentContract | null>(null);
|
| 423 |
const workflows: AgentWorkflowSummary[] = agentContract?.workflows ?? [];
|
| 424 |
const [activeWorkflow, setActiveWorkflow] = useState("");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 425 |
const [governanceDatabase, setGovernanceDatabase] = useState("");
|
| 426 |
useEffect(() => {
|
| 427 |
if (automation.system) { setAgentContract(null); return; }
|
| 428 |
const controller = new AbortController();
|
| 429 |
void getAgentContract(automation.id, controller.signal).then(({ agent }) => {
|
| 430 |
setAgentContract(agent);
|
| 431 |
-
|
| 432 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 433 |
}).catch((error) => setProblem(error instanceof Error ? error.message : "Agent contract unavailable."));
|
| 434 |
return () => controller.abort();
|
| 435 |
}, [automation.id, automation.system]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 436 |
useEffect(() => {
|
| 437 |
const offered = tables.map((table) => table.key);
|
| 438 |
setGovernanceDatabase((current) => offered.includes(current)
|
|
@@ -1754,66 +1838,96 @@ export default function AutomationDetail({
|
|
| 1754 |
other. `.autod-folded .auto-panel { display: none }` does the hiding, which also takes the
|
| 1755 |
panels out of the accessibility tree exactly as `hidden` does.
|
| 1756 |
*/}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1757 |
<div className={"auto-work" + (railShut ? " autod-folded" : "")}>
|
| 1758 |
-
{view === "canvas" ? (
|
| 1759 |
-
<div className="w45-workflow-bar" aria-label="Workflow selection">
|
| 1760 |
-
<label htmlFor="agent-workflow">Workflow</label>
|
| 1761 |
-
<select
|
| 1762 |
-
id="agent-workflow"
|
| 1763 |
-
value={activeWorkflow}
|
| 1764 |
-
onChange={(event) => setActiveWorkflow(event.currentTarget.value)}
|
| 1765 |
-
>
|
| 1766 |
-
{workflows.map((workflow) => (
|
| 1767 |
-
<option key={workflow.id} value={workflow.id}>{workflow.name}</option>
|
| 1768 |
-
))}
|
| 1769 |
-
</select>
|
| 1770 |
-
<button type="button" className="w45-quiet" onClick={() => void addWorkflow()}>Add workflow</button>
|
| 1771 |
-
{agentContract ? (
|
| 1772 |
-
<>
|
| 1773 |
-
<button type="button" className="w45-quiet" onClick={async () => {
|
| 1774 |
-
const visibility = agentContract.sharing.visibility === "private" ? "shared" : "private";
|
| 1775 |
-
const recipient = visibility === "shared" ? window.prompt("Tenant username to share with", "")?.trim() : "";
|
| 1776 |
-
if (visibility === "shared" && !recipient) return;
|
| 1777 |
-
try {
|
| 1778 |
-
const { agent } = await updateAgentGovernance(automation.id, {
|
| 1779 |
-
visibility, sharedWith: visibility === "shared"
|
| 1780 |
-
? Array.from(new Set([...agentContract.sharing.sharedWith, recipient!])) : [],
|
| 1781 |
-
workflows: agentContract.capabilities.workflows,
|
| 1782 |
-
}); setAgentContract(agent);
|
| 1783 |
-
} catch (error) { setProblem(error instanceof Error ? error.message : "Sharing could not be saved."); }
|
| 1784 |
-
}}>{agentContract.sharing.visibility === "private" ? "Share agent" : "Make private"}</button>
|
| 1785 |
-
</>
|
| 1786 |
-
) : null}
|
| 1787 |
-
{agentContract && activeWorkflow ? (() => {
|
| 1788 |
-
const grant = agentContract.capabilities.workflows[activeWorkflow]?.[governanceDatabase];
|
| 1789 |
-
const editable = grant || { mode: agentContract.capabilities.defaultMode, read: true,
|
| 1790 |
-
create: [], update: [], overwrite: [], delete: [] } as AgentDatabaseGrant;
|
| 1791 |
-
const fields = tables.find((table) => table.key === governanceDatabase)?.fields || [];
|
| 1792 |
-
const operations = ["create", "update", "overwrite", "delete"] as const;
|
| 1793 |
-
return <fieldset className="w45-governance" aria-label="Workflow database capabilities">
|
| 1794 |
-
<legend>Capabilities</legend>
|
| 1795 |
-
<label>Database<select value={governanceDatabase} onChange={(event) => setGovernanceDatabase(event.currentTarget.value)}>
|
| 1796 |
-
{tables.map((table) => <option key={table.key} value={table.key}>{table.label}</option>)}
|
| 1797 |
-
</select></label>
|
| 1798 |
-
<span className={"w45-chip " + (grant ? "is-on" : "is-off")}>{grant ? `Read ${String(grant.read)} Β· ${grant.mode}` : "Not granted"}</span>
|
| 1799 |
-
<div className="w45-chip-row" aria-label="Execution mode">
|
| 1800 |
-
{(["preview", "autonomous"] as const).map((mode) => <button type="button" className="w45-quiet" key={mode}
|
| 1801 |
-
aria-pressed={grant?.mode === mode} onClick={() => void saveGovernance({ ...editable, mode })}>{mode}</button>)}
|
| 1802 |
-
</div>
|
| 1803 |
-
{operations.map((operation) => <div className="w45-field-grants" key={operation}>
|
| 1804 |
-
<strong>{operation}</strong>
|
| 1805 |
-
{fields.map((field) => <label key={field.key}><input type="checkbox" checked={editable[operation].includes(field.key)}
|
| 1806 |
-
onChange={(event) => {
|
| 1807 |
-
const selected = event.currentTarget.checked
|
| 1808 |
-
? Array.from(new Set([...editable[operation], field.key]))
|
| 1809 |
-
: editable[operation].filter((key) => key !== field.key);
|
| 1810 |
-
void saveGovernance({ ...editable, [operation]: selected });
|
| 1811 |
-
}} />{field.label}</label>)}
|
| 1812 |
-
</div>)}
|
| 1813 |
-
</fieldset>;
|
| 1814 |
-
})() : null}
|
| 1815 |
-
</div>
|
| 1816 |
-
) : null}
|
| 1817 |
{/*
|
| 1818 |
β THE VIEW IS CHOSEN, NEVER INFERRED (C14 leg 1). This block used to be
|
| 1819 |
`{board ? <Board/> : <Steps/>}` β the page's SHAPE decided by whether a fetch had
|
|
@@ -1864,17 +1978,38 @@ export default function AutomationDetail({
|
|
| 1864 |
/>
|
| 1865 |
) : null}
|
| 1866 |
{/*
|
| 1867 |
-
ββ
|
| 1868 |
-
|
| 1869 |
-
|
| 1870 |
-
|
| 1871 |
-
|
| 1872 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1873 |
*/}
|
|
|
|
| 1874 |
<>
|
| 1875 |
<AutomationBuilder
|
| 1876 |
agentContract={agentContract}
|
| 1877 |
-
flowHidden={view === "chat"}
|
| 1878 |
/* β W36-T69 / R9 β straight off the payload, never re-derived. */
|
| 1879 |
{...(automation.agentActions ? { agentMarks: automation.agentActions } : {})}
|
| 1880 |
automation={automation}
|
|
@@ -2101,6 +2236,7 @@ export default function AutomationDetail({
|
|
| 2101 |
</aside>
|
| 2102 |
) : null}
|
| 2103 |
</>
|
|
|
|
| 2104 |
</div>
|
| 2105 |
</div>
|
| 2106 |
);
|
|
|
|
| 83 |
updateAgentGovernance,
|
| 84 |
} from "./automationApi";
|
| 85 |
import "../styles/wave45/agent-operator.css";
|
| 86 |
+
/*
|
| 87 |
+
β W46-T46 / C6 β IMPORTED AFTER `agent-operator.css`, ON PURPOSE AND NOT ALPHABETICALLY.
|
| 88 |
+
This sheet finishes the Workflows strip and the detail header, and every rule in it is an
|
| 89 |
+
OVERRIDE of one declared above. Vite emits imported CSS in import order, so moving this line
|
| 90 |
+
up would put the override before the thing it overrides and the strip would silently go back
|
| 91 |
+
to its shipped geometry with nothing red anywhere.
|
| 92 |
+
β AND IT IS NOT IN `index.css`. The sheet belongs to the surfaces that use it; the shell's own
|
| 93 |
+
W46 surface imports it separately, which is why one file can serve both without either lane
|
| 94 |
+
reaching into the other's stylesheet.
|
| 95 |
+
β EVERY SELECTOR HERE IS ANCHORED (`.auto-detail > β¦`), so it also wins on specificity rather
|
| 96 |
+
than relying on order alone. See [[a-lane-stylesheet-cannot-override-index-css]].
|
| 97 |
+
*/
|
| 98 |
+
import "../styles/wave46/schema-viewer.css";
|
| 99 |
|
| 100 |
interface Props {
|
| 101 |
automation: Automation;
|
|
|
|
| 430 |
DEFAULT, not a memory: opening any agent should start in the conversation. Remembering
|
| 431 |
"you were last on Canvas" would quietly restore the behaviour this line exists to change,
|
| 432 |
for exactly the people who used the Canvas once.
|
| 433 |
+
ββ W46-T44 ADDED THE ONE EXCEPTION, and it is a coupling this wave created rather than a
|
| 434 |
+
second opinion about the default. `openTab` is the inbox's one-shot request for a right-hand
|
| 435 |
+
pane, and that rail now mounts only in the Workflows view. Left alone, a notification asking
|
| 436 |
+
for Run history would land the reader in Chat with no rail at all and the request would
|
| 437 |
+
evaporate with nothing red anywhere. So a NON-EMPTY `openTab`, and only that, opens on the
|
| 438 |
+
canvas; every ordinary open still starts in the conversation.
|
| 439 |
+
β STILL NOT PERSISTED. This reads a prop the caller sent for this one open, which is the
|
| 440 |
+
opposite of remembering where the reader was last.
|
| 441 |
*/
|
| 442 |
+
const [view, setView] = useState<"canvas" | "chat">(openTab ? "canvas" : "chat");
|
| 443 |
const [agentContract, setAgentContract] = useState<AgentContract | null>(null);
|
| 444 |
const workflows: AgentWorkflowSummary[] = agentContract?.workflows ?? [];
|
| 445 |
const [activeWorkflow, setActiveWorkflow] = useState("");
|
| 446 |
+
/*
|
| 447 |
+
ββ W46-T46 β THE SELECTED WORKFLOW SURVIVES A RELOAD, PER AUTOMATION.
|
| 448 |
+
β WHAT ACTUALLY FAILED, because half of this clause already passed: the workflow LIST is
|
| 449 |
+
server-held (`agentContract.workflows`), so a workflow created with Add workflow was already
|
| 450 |
+
coming back after a reload. The SELECTION was the missing half. `activeWorkflow` started at
|
| 451 |
+
`""` on every mount, so the fallback below read "not in the list" and snapped the reader onto
|
| 452 |
+
workflow one, no matter which one they had been working in.
|
| 453 |
+
|
| 454 |
+
β THE PRECEDENT IS `railShut` FURTHER DOWN, and the reasoning transfers exactly: which
|
| 455 |
+
workflow you are working in IS a preference, so it is remembered. β `view` is NOT, and its
|
| 456 |
+
own comment above says why; nothing here touches it.
|
| 457 |
+
|
| 458 |
+
β KEYED PER AUTOMATION. One agent's workflow ids mean nothing on another agent, so a single
|
| 459 |
+
shared key would restore a stale id on every open and fall through to the same first-workflow
|
| 460 |
+
snap it exists to prevent.
|
| 461 |
+
|
| 462 |
+
β READ INSIDE THIS EFFECT, NOT IN A `useState` INITIALIZER, AND THE REASON IS NOT THE OBVIOUS
|
| 463 |
+
ONE. The first draft of this comment claimed the component is not remounted when
|
| 464 |
+
`automation.id` changes; that was inferred and it is FALSE β `AutomationSurface.tsx` mounts it
|
| 465 |
+
as `<AutomationDetail key={active.id} β¦>`, so opening another agent tears this whole component
|
| 466 |
+
down. An initializer would in fact re-read per agent. β IT WOULD STILL BE WRONG, for a
|
| 467 |
+
different reason: a remembered id is only usable once it has been checked against a list that
|
| 468 |
+
arrives with the CONTRACT, several hundred milliseconds after mount. Setting it at mount would
|
| 469 |
+
seat the reader on a workflow that may not exist, and the resolver below would then have to
|
| 470 |
+
unpick it. Reading it where the list lands means the id is validated in the same breath it is
|
| 471 |
+
used. The `key` is also what makes the write effect below safe; see its note.
|
| 472 |
+
|
| 473 |
+
β A STORED ID THAT IS NOT IN THE LIST IS IGNORED RATHER THAN RESTORED: a workflow can be
|
| 474 |
+
deleted, or the key can outlive the agent, and the existing "keep current, else first" rule
|
| 475 |
+
takes over completely unchanged.
|
| 476 |
+
*/
|
| 477 |
+
const workflowStorageKey = (id: string) => `aios-agent-workflow-${id}`;
|
| 478 |
const [governanceDatabase, setGovernanceDatabase] = useState("");
|
| 479 |
useEffect(() => {
|
| 480 |
if (automation.system) { setAgentContract(null); return; }
|
| 481 |
const controller = new AbortController();
|
| 482 |
void getAgentContract(automation.id, controller.signal).then(({ agent }) => {
|
| 483 |
setAgentContract(agent);
|
| 484 |
+
let remembered = "";
|
| 485 |
+
try {
|
| 486 |
+
remembered = localStorage.getItem(workflowStorageKey(automation.id)) || "";
|
| 487 |
+
} catch {
|
| 488 |
+
// storage can be blocked; the selection still works for this session
|
| 489 |
+
}
|
| 490 |
+
setActiveWorkflow((current) => {
|
| 491 |
+
if (remembered && agent.workflows.some((row) => row.id === remembered)) return remembered;
|
| 492 |
+
return agent.workflows.some((row) => row.id === current)
|
| 493 |
+
? current : agent.workflows[0]?.id || "";
|
| 494 |
+
});
|
| 495 |
}).catch((error) => setProblem(error instanceof Error ? error.message : "Agent contract unavailable."));
|
| 496 |
return () => controller.abort();
|
| 497 |
}, [automation.id, automation.system]);
|
| 498 |
+
/*
|
| 499 |
+
β THE WRITE IS GUARDED ON A NON-EMPTY ID. `activeWorkflow` is `""` for the whole window
|
| 500 |
+
between mount and the contract landing, and for an agent that has no workflows at all;
|
| 501 |
+
writing that would erase a good remembered id on every single open, which is the failure this
|
| 502 |
+
effect exists to avoid rather than a tidiness point.
|
| 503 |
+
β THE CROSS-AGENT HAZARD IS CLOSED BY THE `key`, NOT BY THIS GUARD, and it is worth naming
|
| 504 |
+
because it is invisible: without `key={active.id}` on the mount, switching from agent A to
|
| 505 |
+
agent B would re-render with `automation.id === B` while `activeWorkflow` still held A's id,
|
| 506 |
+
and this effect would write A's workflow under B's key. The read above would then reject it
|
| 507 |
+
and fall through to workflow one, so B would simply appear to have forgotten β a defect that
|
| 508 |
+
passes any single-agent reload test. The `key` remounts instead, so `activeWorkflow` is `""`
|
| 509 |
+
and the guard holds. β If that `key` is ever removed, this effect needs an explicit
|
| 510 |
+
"the contract in hand belongs to this automation" check.
|
| 511 |
+
*/
|
| 512 |
+
useEffect(() => {
|
| 513 |
+
if (!activeWorkflow) return;
|
| 514 |
+
try {
|
| 515 |
+
localStorage.setItem(workflowStorageKey(automation.id), activeWorkflow);
|
| 516 |
+
} catch {
|
| 517 |
+
// storage can be blocked; the selection still works for this session
|
| 518 |
+
}
|
| 519 |
+
}, [automation.id, activeWorkflow]);
|
| 520 |
useEffect(() => {
|
| 521 |
const offered = tables.map((table) => table.key);
|
| 522 |
setGovernanceDatabase((current) => offered.includes(current)
|
|
|
|
| 1838 |
other. `.autod-folded .auto-panel { display: none }` does the hiding, which also takes the
|
| 1839 |
panels out of the accessibility tree exactly as `hidden` does.
|
| 1840 |
*/}
|
| 1841 |
+
{/*
|
| 1842 |
+
ββ W46-T46 (owner instruction 22) β THE ROOT CAUSE: A BAR THAT WAS A COLUMN.
|
| 1843 |
+
Owner: *"The workflow button under Agents module is all mangled up."*
|
| 1844 |
+
|
| 1845 |
+
β THE STRIP WAS A DIRECT CHILD OF `.auto-work`, AND `.auto-work` IS A FLEX ROW. So a
|
| 1846 |
+
thing declared `.w45-workflow-bar` was laid out as a full-height sibling COLUMN of the
|
| 1847 |
+
builder: measured at 769x772 on the shipped build at 1440x900, which is why it read as a
|
| 1848 |
+
control floating in the vertical middle of an empty pane. It also took 769 of that row's
|
| 1849 |
+
864px and squeezed the Properties rail to roughly 40px.
|
| 1850 |
+
β AND NOTHING COULD SEE IT. `document.scrollWidth` stayed equal to `clientWidth` at both
|
| 1851 |
+
required viewports, so an overflow check reports a clean page while a rail is unusable β
|
| 1852 |
+
this is INNER overflow, and it is the RAIL's width that has to be judged, not the
|
| 1853 |
+
document's. [[a-probe-assumes-a-shape-and-blames-the-content]]
|
| 1854 |
+
|
| 1855 |
+
β NO AMOUNT OF WORK ON `.w45-workflow-bar`'s OWN RULES FIXES THIS, which is the trap the
|
| 1856 |
+
ticket warns about: `padding`, `height` and `align-items` all describe a box that is in
|
| 1857 |
+
the wrong PARENT. The bar had to stop being a sibling of the builder, so it moved out
|
| 1858 |
+
here, one level up, into the flex-COLUMN `.auto-detail`.
|
| 1859 |
+
|
| 1860 |
+
β THE PLACE IS NOT INVENTED. `.auto-batch` directly above is the same shape for the same
|
| 1861 |
+
reason β a full-width band that sits above the work area because it belongs to the whole
|
| 1862 |
+
surface rather than to one of its columns. The strip joins it instead of introducing a
|
| 1863 |
+
fourth idea about where a band lives.
|
| 1864 |
+
|
| 1865 |
+
β THE `view === "canvas"` GATE IS UNCHANGED and so is every class, label and handler
|
| 1866 |
+
inside; this is a move, not a rewrite. `verify_automation_ui`'s E1 section reasons about
|
| 1867 |
+
source order INSIDE `AutomationBuilder.tsx`, not this file, and asserts its premise
|
| 1868 |
+
(`.auto-work` is a flex row) rather than assuming it β that premise is still true, because
|
| 1869 |
+
the fix was to stop putting a strip in a row, not to turn the row into a column.
|
| 1870 |
+
*/}
|
| 1871 |
+
{view === "canvas" ? (
|
| 1872 |
+
<div className="w45-workflow-bar" aria-label="Workflow selection">
|
| 1873 |
+
<label htmlFor="agent-workflow">Workflow</label>
|
| 1874 |
+
<select
|
| 1875 |
+
id="agent-workflow"
|
| 1876 |
+
value={activeWorkflow}
|
| 1877 |
+
onChange={(event) => setActiveWorkflow(event.currentTarget.value)}
|
| 1878 |
+
>
|
| 1879 |
+
{workflows.map((workflow) => (
|
| 1880 |
+
<option key={workflow.id} value={workflow.id}>{workflow.name}</option>
|
| 1881 |
+
))}
|
| 1882 |
+
</select>
|
| 1883 |
+
<button type="button" className="w45-quiet" onClick={() => void addWorkflow()}>Add workflow</button>
|
| 1884 |
+
{agentContract ? (
|
| 1885 |
+
<>
|
| 1886 |
+
<button type="button" className="w45-quiet" onClick={async () => {
|
| 1887 |
+
const visibility = agentContract.sharing.visibility === "private" ? "shared" : "private";
|
| 1888 |
+
const recipient = visibility === "shared" ? window.prompt("Tenant username to share with", "")?.trim() : "";
|
| 1889 |
+
if (visibility === "shared" && !recipient) return;
|
| 1890 |
+
try {
|
| 1891 |
+
const { agent } = await updateAgentGovernance(automation.id, {
|
| 1892 |
+
visibility, sharedWith: visibility === "shared"
|
| 1893 |
+
? Array.from(new Set([...agentContract.sharing.sharedWith, recipient!])) : [],
|
| 1894 |
+
workflows: agentContract.capabilities.workflows,
|
| 1895 |
+
}); setAgentContract(agent);
|
| 1896 |
+
} catch (error) { setProblem(error instanceof Error ? error.message : "Sharing could not be saved."); }
|
| 1897 |
+
}}>{agentContract.sharing.visibility === "private" ? "Share agent" : "Make private"}</button>
|
| 1898 |
+
</>
|
| 1899 |
+
) : null}
|
| 1900 |
+
{agentContract && activeWorkflow ? (() => {
|
| 1901 |
+
const grant = agentContract.capabilities.workflows[activeWorkflow]?.[governanceDatabase];
|
| 1902 |
+
const editable = grant || { mode: agentContract.capabilities.defaultMode, read: true,
|
| 1903 |
+
create: [], update: [], overwrite: [], delete: [] } as AgentDatabaseGrant;
|
| 1904 |
+
const fields = tables.find((table) => table.key === governanceDatabase)?.fields || [];
|
| 1905 |
+
const operations = ["create", "update", "overwrite", "delete"] as const;
|
| 1906 |
+
return <fieldset className="w45-governance" aria-label="Workflow database capabilities">
|
| 1907 |
+
<legend>Capabilities</legend>
|
| 1908 |
+
<label>Database<select value={governanceDatabase} onChange={(event) => setGovernanceDatabase(event.currentTarget.value)}>
|
| 1909 |
+
{tables.map((table) => <option key={table.key} value={table.key}>{table.label}</option>)}
|
| 1910 |
+
</select></label>
|
| 1911 |
+
<span className={"w45-chip " + (grant ? "is-on" : "is-off")}>{grant ? `Read ${String(grant.read)} Β· ${grant.mode}` : "Not granted"}</span>
|
| 1912 |
+
<div className="w45-chip-row" aria-label="Execution mode">
|
| 1913 |
+
{(["preview", "autonomous"] as const).map((mode) => <button type="button" className="w45-quiet" key={mode}
|
| 1914 |
+
aria-pressed={grant?.mode === mode} onClick={() => void saveGovernance({ ...editable, mode })}>{mode}</button>)}
|
| 1915 |
+
</div>
|
| 1916 |
+
{operations.map((operation) => <div className="w45-field-grants" key={operation}>
|
| 1917 |
+
<strong>{operation}</strong>
|
| 1918 |
+
{fields.map((field) => <label key={field.key}><input type="checkbox" checked={editable[operation].includes(field.key)}
|
| 1919 |
+
onChange={(event) => {
|
| 1920 |
+
const selected = event.currentTarget.checked
|
| 1921 |
+
? Array.from(new Set([...editable[operation], field.key]))
|
| 1922 |
+
: editable[operation].filter((key) => key !== field.key);
|
| 1923 |
+
void saveGovernance({ ...editable, [operation]: selected });
|
| 1924 |
+
}} />{field.label}</label>)}
|
| 1925 |
+
</div>)}
|
| 1926 |
+
</fieldset>;
|
| 1927 |
+
})() : null}
|
| 1928 |
+
</div>
|
| 1929 |
+
) : null}
|
| 1930 |
<div className={"auto-work" + (railShut ? " autod-folded" : "")}>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1931 |
{/*
|
| 1932 |
β THE VIEW IS CHOSEN, NEVER INFERRED (C14 leg 1). This block used to be
|
| 1933 |
`{board ? <Board/> : <Steps/>}` β the page's SHAPE decided by whether a fetch had
|
|
|
|
| 1978 |
/>
|
| 1979 |
) : null}
|
| 1980 |
{/*
|
| 1981 |
+
ββ WAVE 46 Β· W46-T44 (owner instruction 22) REVERSES W36-T32 / R7 β THE RIGHT RAIL
|
| 1982 |
+
BELONGS TO WORKFLOWS ONLY. Two rulings contradict here and the NEWER one wins, so read
|
| 1983 |
+
both before "fixing" this back:
|
| 1984 |
+
Β· W36-T32 / R7 (wave 36, SUPERSEDED): *"even when the Chat is shown first, we still
|
| 1985 |
+
need to be able to see the Properties/the new module/Run history tab on the right
|
| 1986 |
+
side."* That built the builder and both asides into BOTH views, with only the flow
|
| 1987 |
+
column swapping via `flowHidden`.
|
| 1988 |
+
Β· W46 instruction 22 (2026-08-29, CURRENT): *"Under agents module, the navigation for
|
| 1989 |
+
'Properites/Harness/Run history' etc should be hidden until a user click Workflows.
|
| 1990 |
+
I mean there is no point for the chat function to see this settings right?"*
|
| 1991 |
+
So the whole rail β the builder, Properties, Harness, Run history, the fold control and
|
| 1992 |
+
the collapsed strip β mounts only in the Workflows view, and Chat is the conversation
|
| 1993 |
+
alone. This is the [[two-gates-can-assert-opposite-things]] shape: the old comment is
|
| 1994 |
+
rewritten rather than deleted precisely so the next reader finds the reversal instead of
|
| 1995 |
+
the ruling it reversed.
|
| 1996 |
+
β ONE CONDITION IN ONE PLACE, this ternary, for the reason W36-T32 recorded one level
|
| 1997 |
+
up: written per panel it would state one idea four times, and a fifth panel would have
|
| 1998 |
+
to remember to join in.
|
| 1999 |
+
β `flowHidden={view === "chat"}` WENT WITH IT, and not as tidying: inside this branch TS
|
| 2000 |
+
narrows `view` to `"canvas"`, so that comparison is a compile error (TS2367), not merely
|
| 2001 |
+
dead. The flow column is simply always shown now, because the only view that mounts the
|
| 2002 |
+
builder is the one the flow belongs to. `AutomationBuilder.flowHidden` stays optional for
|
| 2003 |
+
a third view that may want it again.
|
| 2004 |
+
β `railShut` still means "is the rail folded" and `aside` still means "which pane";
|
| 2005 |
+
neither learns about `view`, so a fold survives a trip through Chat untouched, and the
|
| 2006 |
+
fold's own control still ships with the rail it folds (the strip at the end of this
|
| 2007 |
+
branch) so W36-T32's "the fold must survive the fold" holds inside Workflows.
|
| 2008 |
*/}
|
| 2009 |
+
{view === "canvas" ? (
|
| 2010 |
<>
|
| 2011 |
<AutomationBuilder
|
| 2012 |
agentContract={agentContract}
|
|
|
|
| 2013 |
/* β W36-T69 / R9 β straight off the payload, never re-derived. */
|
| 2014 |
{...(automation.agentActions ? { agentMarks: automation.agentActions } : {})}
|
| 2015 |
automation={automation}
|
|
|
|
| 2236 |
</aside>
|
| 2237 |
) : null}
|
| 2238 |
</>
|
| 2239 |
+
) : null}
|
| 2240 |
</div>
|
| 2241 |
</div>
|
| 2242 |
);
|
web/src/customer-grid/ColumnMenu.tsx
CHANGED
|
@@ -1,4 +1,8 @@
|
|
| 1 |
import { Fragment, useMemo, useRef, useState } from "react";
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
// β W36-T07 (owner item 10) β the field agent. Its own module for `ColumnMenu`'s own reason:
|
| 3 |
// this file pulls the whole grid and cannot load under a node gate, so the chat had to sit
|
| 4 |
// where a test can render it.
|
|
@@ -1134,7 +1138,20 @@ function TypePicker({
|
|
| 1134 |
title={TYPE_DESCRIPTIONS[r.value]}
|
| 1135 |
onClick={() => setDescribedKind((current) => current === r.value ? null : r.value)}
|
| 1136 |
>
|
| 1137 |
-
(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1138 |
</button>
|
| 1139 |
{describedKind === r.value && (
|
| 1140 |
<div className="cg-type-description" role="status">
|
|
|
|
| 1 |
import { Fragment, useMemo, useRef, useState } from "react";
|
| 2 |
+
// ββ W46-T31 (contract C6) β the lane's sheet, imported from the COMPONENT rather than added to
|
| 3 |
+
// `index.css`. An @imported sheet is inlined at the top of the cascade and loses every
|
| 4 |
+
// equal-specificity fight below it. [[a-lane-stylesheet-cannot-override-index-css]]
|
| 5 |
+
import "../styles/wave46/field-panels.css";
|
| 6 |
// β W36-T07 (owner item 10) β the field agent. Its own module for `ColumnMenu`'s own reason:
|
| 7 |
// this file pulls the whole grid and cannot load under a node gate, so the chat had to sit
|
| 8 |
// where a test can render it.
|
|
|
|
| 1138 |
title={TYPE_DESCRIPTIONS[r.value]}
|
| 1139 |
onClick={() => setDescribedKind((current) => current === r.value ? null : r.value)}
|
| 1140 |
>
|
| 1141 |
+
{/* ββ W46-T31 (owner instruction 27) β THE ADD-FIELD INFO MARK JOINS THE HOUSE
|
| 1142 |
+
ICON VOCABULARY. It was the literal characters `(i)`, the one glyph in this
|
| 1143 |
+
menu drawn in text while every mark beside it is a 16-viewBox stroked SVG:
|
| 1144 |
+
it inherited the row's font rather than the icon size, could not take the
|
| 1145 |
+
hairline weight, and rendered differently on every platform's font stack.
|
| 1146 |
+
β THE BUTTON IS UNCHANGED β `type`, `className`, `aria-label`,
|
| 1147 |
+
`aria-expanded`, `title` and `onClick` all stay exactly as they were. Only
|
| 1148 |
+
the visible glyph moved from text to a mark, and `aria-hidden` on the svg
|
| 1149 |
+
is what keeps the `aria-label` the single spoken name. */}
|
| 1150 |
+
<svg width="12" height="12" viewBox="0 0 16 16" fill="none" aria-hidden focusable="false" stroke="currentColor" strokeWidth={1.25} strokeLinecap="round" strokeLinejoin="round">
|
| 1151 |
+
<circle cx="8" cy="8" r="5.7" />
|
| 1152 |
+
<path d="M8 7.4v3.4" />
|
| 1153 |
+
<path d="M8 5.2v.1" />
|
| 1154 |
+
</svg>
|
| 1155 |
</button>
|
| 1156 |
{describedKind === r.value && (
|
| 1157 |
<div className="cg-type-description" role="status">
|
web/src/customer-grid/CustomerGrid.tsx
CHANGED
|
@@ -112,6 +112,9 @@ import { dataPathHash, readDataPath } from "./dataPath";
|
|
| 112 |
import type { DataDatabase, DataDatabaseFolder, DataPath } from "./dataPath";
|
| 113 |
import "../styles/wave44/data-workspace.css";
|
| 114 |
import "../styles/wave45/data-applications.css";
|
|
|
|
|
|
|
|
|
|
| 115 |
// owner item 3 (2026-08-03) β a time-series view exports its SHEET, not the rows under it.
|
| 116 |
import { buildTsCsv, tsSheetToTable } from "./timeSeriesData";
|
| 117 |
import type { TsSheet } from "./timeSeriesData";
|
|
@@ -1578,7 +1581,6 @@ function CustomerGridSurface({
|
|
| 1578 |
// independently so editing one registry asset updates every View that points at it.
|
| 1579 |
const applicationDatabase = activeDatabaseKey ?? dataPath?.database ?? topic.key;
|
| 1580 |
const [resolvedApplication, setResolvedApplication] = useState<SavedApplication | null>(null);
|
| 1581 |
-
const [applicationError, setApplicationError] = useState("");
|
| 1582 |
const applicationRef = cleanApplicationRef(config.application);
|
| 1583 |
const applicationRefKey = applicationRef
|
| 1584 |
? `${applicationDatabase}::${applicationRef.type}::${applicationRef.id}`
|
|
@@ -1604,14 +1606,13 @@ function CustomerGridSurface({
|
|
| 1604 |
(candidate.openTarget?.database === applicationDatabase ||
|
| 1605 |
candidate.compatibleDatabases?.includes(applicationDatabase) === true));
|
| 1606 |
if (!application) throw new Error("This View's Application is no longer available.");
|
| 1607 |
-
if (!controller.signal.aborted)
|
| 1608 |
-
setResolvedApplication(application);
|
| 1609 |
-
setApplicationError("");
|
| 1610 |
-
}
|
| 1611 |
}).catch((error: unknown) => {
|
| 1612 |
if (!controller.signal.aborted) {
|
| 1613 |
setResolvedApplication(null);
|
| 1614 |
-
|
|
|
|
|
|
|
| 1615 |
}
|
| 1616 |
});
|
| 1617 |
return () => controller.abort();
|
|
@@ -3494,8 +3495,6 @@ function CustomerGridSurface({
|
|
| 3494 |
const embeddedSelectedKey = [...embeddedSelectedIds].sort((a, b) => a - b).join(",");
|
| 3495 |
const selectedPidKey = [...selectedPids].sort((a, b) => a - b).join(",");
|
| 3496 |
const [workspaceDrawer, setWorkspaceDrawer] = useState<"notes" | "history" | null>(null);
|
| 3497 |
-
const [applicationRailOpen, setApplicationRailOpen] = useState(false);
|
| 3498 |
-
const [applications, setApplications] = useState<SavedApplication[]>([]);
|
| 3499 |
const applicationKind = displayMode === "chart" ? "chart" : displayMode === "timeseries" ? "timeseries" : displayMode === "map" ? "map" : null;
|
| 3500 |
const applySavedApplication = useCallback((application: SavedApplication): boolean => {
|
| 3501 |
const reference = cleanApplicationRef({
|
|
@@ -3510,21 +3509,6 @@ function CustomerGridSurface({
|
|
| 3510 |
updateConfig(next);
|
| 3511 |
return true;
|
| 3512 |
}, [config, updateConfig]);
|
| 3513 |
-
const loadApplications = useCallback(async (signal?: AbortSignal) => {
|
| 3514 |
-
if (!applicationRailOpen) return;
|
| 3515 |
-
try {
|
| 3516 |
-
const response = await fetch(`${API_V1}/applications?database=${encodeURIComponent(applicationDatabase)}${applicationKind ? `&type=${applicationKind}` : ""}`, { credentials: CREDENTIALS, signal });
|
| 3517 |
-
const body = await response.json().catch(() => ({}));
|
| 3518 |
-
if (!response.ok) throw new Error(String(body?.detail?.message ?? body?.detail ?? "Could not load Applications"));
|
| 3519 |
-
if (!signal?.aborted) { setApplications(Array.isArray(body?.applications) ? body.applications : []); setApplicationError(""); }
|
| 3520 |
-
} catch (error) { if (!signal?.aborted) setApplicationError(error instanceof Error ? error.message : "Could not load Applications"); }
|
| 3521 |
-
}, [applicationDatabase, applicationKind, applicationRailOpen]);
|
| 3522 |
-
useEffect(() => {
|
| 3523 |
-
const controller = new AbortController();
|
| 3524 |
-
void loadApplications(controller.signal);
|
| 3525 |
-
return () => controller.abort();
|
| 3526 |
-
}, [loadApplications]);
|
| 3527 |
-
|
| 3528 |
const applicationOpenSeq = useRef(0);
|
| 3529 |
const appliedApplicationPath = useRef("");
|
| 3530 |
useEffect(() => {
|
|
@@ -5294,6 +5278,15 @@ function CustomerGridSurface({
|
|
| 5294 |
? current.map((item) => (item.id === view.id ? view : item))
|
| 5295 |
: [...current, view];
|
| 5296 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5297 |
// ββ WAVE 35 QA β THE SAME RE-IDENTIFICATION THE AUTOSAVE NEEDS, AND THIS IS THE CALL SITE
|
| 5298 |
// THE TOOLBAR ACTUALLY USES. `persistView` is what Rows / Sort / Group / Hide fields go
|
| 5299 |
// through, so fixing only the autosave left every one of them still refused: measured on the
|
|
@@ -8727,7 +8720,6 @@ function CustomerGridSurface({
|
|
| 8727 |
the rail. `.cg-shell` is a horizontal flex row, so this needs no positioning of its own.
|
| 8728 |
β NOT on an embedded or Query surface: neither has a database of its own for the chat to
|
| 8729 |
be about, which is the same condition the script projections already carry. */}
|
| 8730 |
-
{applicationRailOpen && <aside className="cg-application-rail" aria-label="Applications"><header><strong>Applications</strong><button type="button" className="cg-icon-button" aria-label="Close Applications" onClick={() => setApplicationRailOpen(false)}>Γ</button></header><p className="cg-application-context">Reusable {applicationKind ?? "Chart, Route, Map, and Time Series"} assets for this database</p>{applicationError && <p role="alert">{applicationError}</p>}<div className="cg-application-list">{applications.map((application) => <article key={application.id} className="cg-application-card"><button type="button" className="cg-application-open" onClick={() => { const roles = Object.entries(application.semanticRoleBindings ?? {}); if (roles.length && !window.confirm(`Use ${application.name} with these semantic roles?\n${roles.map(([role, mappedField]) => `${role}: ${String(mappedField)}`).join("\n")}`)) return; applySavedApplication(application); }}><span>{application.name}</span><small>{application.type}</small></button><div className="cg-application-actions">{application.capabilities?.star === true && <button type="button" className="cg-icon-button" aria-label={`${application.starred ? "Unstar" : "Star"} ${application.name}`} onClick={async () => { await fetch(`${API_V1}/applications/${encodeURIComponent(application.id)}`, { method: "PATCH", credentials: CREDENTIALS, headers: { "Content-Type": "application/json" }, body: JSON.stringify({ starred: !application.starred }) }); void loadApplications(); }}>{application.starred ? "β
" : "β"}</button>}<button type="button" className="cg-link-btn" onClick={async () => { await fetch(`${API_V1}/applications/defaults/${encodeURIComponent(applicationDatabase)}/${application.type}`, { method: "PUT", credentials: CREDENTIALS, headers: { "Content-Type": "application/json" }, body: JSON.stringify({ applicationId: application.id }) }); }}>Make default</button>{application.capabilities?.delete === true && <button type="button" className="cg-link-btn is-danger" onClick={async () => { if (!window.confirm(`Delete Application β${application.name}β? Views using it will no longer display that Application.`)) return; await fetch(`${API_V1}/applications/${encodeURIComponent(application.id)}`, { method: "DELETE", credentials: CREDENTIALS }); if (cleanApplicationRef(config.application)?.id === application.id) setResolvedApplication(null); void loadApplications(); }}>Deleteβ¦</button>}</div></article>)}{!applicationError && applications.length === 0 && <p>No compatible saved Applications yet.</p>}</div></aside>}
|
| 8731 |
{!embedded && !queryBinding && (
|
| 8732 |
chatOpen ? (
|
| 8733 |
<div className="cg-chat-dock">
|
|
@@ -8757,7 +8749,7 @@ function CustomerGridSurface({
|
|
| 8757 |
</div>
|
| 8758 |
) : (
|
| 8759 |
<>
|
| 8760 |
-
<div className="cg-drawer-launchers" aria-label="Workspace details">
|
| 8761 |
<Toolbar
|
| 8762 |
manager={true}
|
| 8763 |
nouns={topic.nouns}
|
|
@@ -8910,6 +8902,11 @@ function CustomerGridSurface({
|
|
| 8910 |
onViewActions={setViewActionsAnchor}
|
| 8911 |
fullscreen={!!config.fullscreen}
|
| 8912 |
onFullscreen={() => updateConfig({ ...config, fullscreen: !config.fullscreen })}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8913 |
/>
|
| 8914 |
{/* β R11's SECOND ROW β live, on the pivoted database. It renders only once the pivot has
|
| 8915 |
actually been SERVED, which is the house posture for a control whose other half may
|
|
|
|
| 112 |
import type { DataDatabase, DataDatabaseFolder, DataPath } from "./dataPath";
|
| 113 |
import "../styles/wave44/data-workspace.css";
|
| 114 |
import "../styles/wave45/data-applications.css";
|
| 115 |
+
// C6 β W46-T09 orders the toolbar's right-hand run (Related, Notes, Full screen). It is
|
| 116 |
+
// imported AFTER the Wave 44 sheet on purpose: at equal specificity the later sheet wins.
|
| 117 |
+
import "../styles/wave46/chrome.css";
|
| 118 |
// owner item 3 (2026-08-03) β a time-series view exports its SHEET, not the rows under it.
|
| 119 |
import { buildTsCsv, tsSheetToTable } from "./timeSeriesData";
|
| 120 |
import type { TsSheet } from "./timeSeriesData";
|
|
|
|
| 1581 |
// independently so editing one registry asset updates every View that points at it.
|
| 1582 |
const applicationDatabase = activeDatabaseKey ?? dataPath?.database ?? topic.key;
|
| 1583 |
const [resolvedApplication, setResolvedApplication] = useState<SavedApplication | null>(null);
|
|
|
|
| 1584 |
const applicationRef = cleanApplicationRef(config.application);
|
| 1585 |
const applicationRefKey = applicationRef
|
| 1586 |
? `${applicationDatabase}::${applicationRef.type}::${applicationRef.id}`
|
|
|
|
| 1606 |
(candidate.openTarget?.database === applicationDatabase ||
|
| 1607 |
candidate.compatibleDatabases?.includes(applicationDatabase) === true));
|
| 1608 |
if (!application) throw new Error("This View's Application is no longer available.");
|
| 1609 |
+
if (!controller.signal.aborted) setResolvedApplication(application);
|
|
|
|
|
|
|
|
|
|
| 1610 |
}).catch((error: unknown) => {
|
| 1611 |
if (!controller.signal.aborted) {
|
| 1612 |
setResolvedApplication(null);
|
| 1613 |
+
// W46-T10: the Applications rail owned the only reader of the old error cell. The failure
|
| 1614 |
+
// still has to be told, so it goes to the workspace toast every other refusal here uses.
|
| 1615 |
+
signal(TOAST_EVENT, error instanceof Error ? error.message : "Could not resolve this Application");
|
| 1616 |
}
|
| 1617 |
});
|
| 1618 |
return () => controller.abort();
|
|
|
|
| 3495 |
const embeddedSelectedKey = [...embeddedSelectedIds].sort((a, b) => a - b).join(",");
|
| 3496 |
const selectedPidKey = [...selectedPids].sort((a, b) => a - b).join(",");
|
| 3497 |
const [workspaceDrawer, setWorkspaceDrawer] = useState<"notes" | "history" | null>(null);
|
|
|
|
|
|
|
| 3498 |
const applicationKind = displayMode === "chart" ? "chart" : displayMode === "timeseries" ? "timeseries" : displayMode === "map" ? "map" : null;
|
| 3499 |
const applySavedApplication = useCallback((application: SavedApplication): boolean => {
|
| 3500 |
const reference = cleanApplicationRef({
|
|
|
|
| 3509 |
updateConfig(next);
|
| 3510 |
return true;
|
| 3511 |
}, [config, updateConfig]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3512 |
const applicationOpenSeq = useRef(0);
|
| 3513 |
const appliedApplicationPath = useRef("");
|
| 3514 |
useEffect(() => {
|
|
|
|
| 5278 |
? current.map((item) => (item.id === view.id ? view : item))
|
| 5279 |
: [...current, view];
|
| 5280 |
});
|
| 5281 |
+
// β W46-T13 (instruction 14) β STAMP THE ECHO WINDOW HERE, BECAUSE THE IDENTITY BELONGS TO
|
| 5282 |
+
// THE WRITE. `seedLocalViews`' second guard exists to keep a view THIS BROWSER just wrote
|
| 5283 |
+
// through a database cross or a fast reload, and nothing ever fed it: every optimistic view
|
| 5284 |
+
// write β create, rename, star, lock, note, duplicate β comes through here, and none of them
|
| 5285 |
+
// stamped. So the reconciler read them as views the host had never heard of and dropped them
|
| 5286 |
+
// (the blink), or merged the host's stale copy back over them and lost `config.important`
|
| 5287 |
+
// (the vanishing rail count). One stamp at the write fixes both; stamping at the nine call
|
| 5288 |
+
// sites instead would be the same drift the comment below already argues against.
|
| 5289 |
+
viewWritesRef.current = stampTombstone(viewWritesRef.current, view.id, Date.now());
|
| 5290 |
// ββ WAVE 35 QA β THE SAME RE-IDENTIFICATION THE AUTOSAVE NEEDS, AND THIS IS THE CALL SITE
|
| 5291 |
// THE TOOLBAR ACTUALLY USES. `persistView` is what Rows / Sort / Group / Hide fields go
|
| 5292 |
// through, so fixing only the autosave left every one of them still refused: measured on the
|
|
|
|
| 8720 |
the rail. `.cg-shell` is a horizontal flex row, so this needs no positioning of its own.
|
| 8721 |
β NOT on an embedded or Query surface: neither has a database of its own for the chat to
|
| 8722 |
be about, which is the same condition the script projections already carry. */}
|
|
|
|
| 8723 |
{!embedded && !queryBinding && (
|
| 8724 |
chatOpen ? (
|
| 8725 |
<div className="cg-chat-dock">
|
|
|
|
| 8749 |
</div>
|
| 8750 |
) : (
|
| 8751 |
<>
|
| 8752 |
+
<div className="cg-drawer-launchers" aria-label="Workspace details">{isUserTable && <button type="button" className="cg-btn" aria-expanded={workspaceDrawer === "history"} onClick={() => setWorkspaceDrawer((open) => open === "history" ? null : "history")}>History</button>}</div>
|
| 8753 |
<Toolbar
|
| 8754 |
manager={true}
|
| 8755 |
nouns={topic.nouns}
|
|
|
|
| 8902 |
onViewActions={setViewActionsAnchor}
|
| 8903 |
fullscreen={!!config.fullscreen}
|
| 8904 |
onFullscreen={() => updateConfig({ ...config, fullscreen: !config.fullscreen })}
|
| 8905 |
+
// W46-T09 (owner instructions 2 and 30) β the SAME workspaceDrawer state the launcher
|
| 8906 |
+
// row drove, moved to the toolbar so Related, Notes and Full screen read as one run.
|
| 8907 |
+
// Only this render supplies it, so the pivot toolbar shows no Notes button at all.
|
| 8908 |
+
notesOpen={workspaceDrawer === "notes"}
|
| 8909 |
+
onNotes={() => setWorkspaceDrawer((open) => (open === "notes" ? null : "notes"))}
|
| 8910 |
/>
|
| 8911 |
{/* β R11's SECOND ROW β live, on the pivoted database. It renders only once the pivot has
|
| 8912 |
actually been SERVED, which is the house posture for a control whose other half may
|
web/src/customer-grid/DatePicker.tsx
CHANGED
|
@@ -1,15 +1,33 @@
|
|
| 1 |
-
import { useEffect, useMemo, useState } from "react";
|
| 2 |
import { API_V1, CREDENTIALS } from "../apiContract";
|
| 3 |
import type { DateRecurrence, DateRecurrenceRule, Field } from "./types";
|
| 4 |
import { AnchoredOverlay } from "./OverlaySurface";
|
| 5 |
import type { AnchorRect } from "./OverlaySurface";
|
|
|
|
| 6 |
|
| 7 |
const MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
| 8 |
const WEEKDAYS = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
|
|
|
|
| 9 |
const ORDINALS: ReadonlyArray<readonly [DateRecurrenceRule["ordinal"], string]> = [[1, "First"], [2, "Second"], [3, "Third"], [4, "Fourth"], [5, "Fifth"], [-1, "Last"]];
|
| 10 |
-
const
|
| 11 |
type RuleKind = DateRecurrenceRule["kind"] | "monthly_ordinal";
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
function parseIso(value: unknown): Date | null {
|
| 15 |
if (typeof value !== "string" || !/^\d{4}-\d{2}-\d{2}$/.test(value)) return null;
|
|
@@ -29,7 +47,9 @@ function newRule(kind: RuleKind, selected: Date): DateRecurrenceRule {
|
|
| 29 |
if (kind === "holiday") return { kind, interval: 1, calendar: "US", offset: 0 };
|
| 30 |
return { kind, interval: 1 };
|
| 31 |
}
|
| 32 |
-
|
|
|
|
|
|
|
| 33 |
|
| 34 |
type RecurrenceCondition = {
|
| 35 |
colId: string;
|
|
@@ -37,11 +57,49 @@ type RecurrenceCondition = {
|
|
| 37 |
value: string;
|
| 38 |
value2?: string;
|
| 39 |
};
|
|
|
|
|
|
|
|
|
|
| 40 |
type LinkedRecurrence = DateRecurrence & {
|
| 41 |
anchorField?: { table: "same" | string; field: string; linkedVia?: string };
|
| 42 |
conditions?: RecurrenceCondition[];
|
|
|
|
| 43 |
};
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
export function DatePicker({ anchor, field, fields, scopeKey, value, today, onChange, onRecurrence, onClose }: {
|
| 46 |
anchor: AnchorRect; field: Field; fields: Field[]; scopeKey: string; value: unknown; today?: string; onChange: (value: string) => void;
|
| 47 |
onRecurrence: (recurrence: DateRecurrence | null) => void; onClose: () => void;
|
|
@@ -60,6 +118,12 @@ export function DatePicker({ anchor, field, fields, scopeKey, value, today, onCh
|
|
| 60 |
const [anchorField, setAnchorField] = useState(() => storedRecurrence?.anchorField?.field ?? "");
|
| 61 |
const [linkedVia, setLinkedVia] = useState(() => storedRecurrence?.anchorField?.linkedVia ?? "");
|
| 62 |
const [conditions, setConditions] = useState<RecurrenceCondition[]>(() => storedRecurrence?.conditions ?? []);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
const dateFields = useMemo(() => fields.filter((candidate) => candidate.type === "date"), [fields]);
|
| 64 |
const linkedFields = useMemo(() => fields.filter((candidate) => candidate.type === "link" && candidate.link?.table), [fields]);
|
| 65 |
const recurrence = useMemo<LinkedRecurrence | null>(() => rules.length ? ({
|
|
@@ -72,7 +136,8 @@ export function DatePicker({ anchor, field, fields, scopeKey, value, today, onCh
|
|
| 72 |
...(anchorTable !== "same" && linkedVia ? { linkedVia } : {}),
|
| 73 |
} } : {}),
|
| 74 |
...(conditions.length ? { conditions } : {}),
|
| 75 |
-
|
|
|
|
| 76 |
|
| 77 |
// Server-evaluated preview: the exact payload saved below is sent here, so edited previews
|
| 78 |
// cannot differ from the default next date after refresh because of timezone/holiday drift.
|
|
@@ -102,49 +167,130 @@ export function DatePicker({ anchor, field, fields, scopeKey, value, today, onCh
|
|
| 102 |
const weekdays = checked ? [...new Set([...existing, weekday])].sort() : existing.filter((day) => day !== weekday);
|
| 103 |
return { ...rule, weekdays: weekdays.length ? weekdays : existing };
|
| 104 |
}));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
const monthStart = new Date(Date.UTC(cursor.getUTCFullYear(), cursor.getUTCMonth(), 1));
|
| 106 |
const leading = (monthStart.getUTCDay() + 6) % 7;
|
| 107 |
const days = new Date(Date.UTC(cursor.getUTCFullYear(), cursor.getUTCMonth() + 1, 0)).getUTCDate();
|
| 108 |
const cells = Array.from({ length: Math.ceil((leading + days) / 7) * 7 }, (_, index) => index - leading + 1);
|
|
|
|
| 109 |
|
| 110 |
// This is a body-portal overlay, so `cg-date-picker` alone only supplies its width and padding.
|
| 111 |
// Keep the shared `cg-pop` contract on the same element: it supplies the opaque surface, border,
|
| 112 |
// elevation, and readable ink that every anchored editor needs over Glide's canvas.
|
| 113 |
return <AnchoredOverlay anchor={anchor} className="cg-pop cg-date-picker" placement="bottom-start" onDismiss={onClose} role="dialog" ariaLabel={`Choose a date for ${field.label}`} dataKind="date-picker">
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
<div className="
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
else setLinkedVia(linkedFields.find((candidate) => candidate.link?.table === table)?.key ?? "");
|
| 129 |
-
setAnchorField("");
|
| 130 |
-
}}><option value="same">This database</option>{linkedFields.map((candidate) => <option value={candidate.link!.table} key={candidate.key}>{candidate.label} Β· {candidate.link!.table}</option>)}</select></label>
|
| 131 |
-
{anchorTable === "same" ? <label>Date field<select className="cg-select" value={anchorField} onChange={(event) => setAnchorField(event.target.value)}><option value="">This date</option>{dateFields.map((candidate) => <option value={candidate.key} key={candidate.key}>{candidate.label}</option>)}</select></label>
|
| 132 |
-
: <><label>Linked through<select className="cg-select" value={linkedVia} onChange={(event) => setLinkedVia(event.target.value)}>{linkedFields.filter((candidate) => candidate.link?.table === anchorTable).map((candidate) => <option value={candidate.key} key={candidate.key}>{candidate.label}</option>)}</select></label><label>Linked date field key<input className="cg-input" value={anchorField} onChange={(event) => setAnchorField(event.target.value)} placeholder="due_date" /></label></>}
|
| 133 |
</div>
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
<
|
| 137 |
-
<
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
</div>)}
|
| 145 |
-
<button type="button" className="
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
</AnchoredOverlay>;
|
| 150 |
}
|
|
|
|
| 1 |
+
import { useEffect, useId, useMemo, useState } from "react";
|
| 2 |
import { API_V1, CREDENTIALS } from "../apiContract";
|
| 3 |
import type { DateRecurrence, DateRecurrenceRule, Field } from "./types";
|
| 4 |
import { AnchoredOverlay } from "./OverlaySurface";
|
| 5 |
import type { AnchorRect } from "./OverlaySurface";
|
| 6 |
+
import "../styles/wave46/field-panels.css";
|
| 7 |
|
| 8 |
const MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
| 9 |
const WEEKDAYS = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
|
| 10 |
+
const WEEKDAY_INITIALS = ["M", "T", "W", "T", "F", "S", "S"];
|
| 11 |
const ORDINALS: ReadonlyArray<readonly [DateRecurrenceRule["ordinal"], string]> = [[1, "First"], [2, "Second"], [3, "Third"], [4, "Fourth"], [5, "Fifth"], [-1, "Last"]];
|
| 12 |
+
const RULE_KINDS = ["daily", "weekly", "monthly", "monthly_ordinal", "yearly", "holiday"] as const;
|
| 13 |
type RuleKind = DateRecurrenceRule["kind"] | "monthly_ordinal";
|
| 14 |
+
// W46-T33: a holiday rule may now name ONE holiday instead of a whole national calendar, so the
|
| 15 |
+
// code is any string the server's registry admits and `group` says which heading it belongs
|
| 16 |
+
// under. This LOCAL type widens; `types.ts` does not, because the granular id rides the existing
|
| 17 |
+
// `calendar` field, `clean_date_recurrence` is what validates it, and widening the shared shape
|
| 18 |
+
// would ask three parity gates to agree about a value only the server can judge.
|
| 19 |
+
type CalendarOption = { code: string; label: string; group?: "calendar" | "holiday" };
|
| 20 |
+
// The two entries the server is certain to send, so the first paint before the preview call
|
| 21 |
+
// returns is never an empty dropdown. The seventeen single holidays are NOT copied here: the
|
| 22 |
+
// list is the server's, and a second copy would go stale the day one is added.
|
| 23 |
+
const DEFAULT_CALENDARS: CalendarOption[] = [
|
| 24 |
+
{ code: "US", label: "United States federal holidays", group: "calendar" },
|
| 25 |
+
{ code: "CA", label: "Canada federal public holidays", group: "calendar" },
|
| 26 |
+
];
|
| 27 |
+
const CALENDAR_GROUPS: ReadonlyArray<readonly [CalendarOption["group"], string]> = [
|
| 28 |
+
["calendar", "Whole calendars"],
|
| 29 |
+
["holiday", "Single holidays"],
|
| 30 |
+
];
|
| 31 |
|
| 32 |
function parseIso(value: unknown): Date | null {
|
| 33 |
if (typeof value !== "string" || !/^\d{4}-\d{2}-\d{2}$/.test(value)) return null;
|
|
|
|
| 47 |
if (kind === "holiday") return { kind, interval: 1, calendar: "US", offset: 0 };
|
| 48 |
return { kind, interval: 1 };
|
| 49 |
}
|
| 50 |
+
// The unit words that finish the "Repeat every N ..." sentence, so the control reads as one
|
| 51 |
+
// phrase instead of restating the whole rule inside its own dropdown.
|
| 52 |
+
function labelForKind(kind: RuleKind): string { return ({ daily: "day", weekly: "week", monthly: "month", monthly_ordinal: "month on a weekday", yearly: "year", holiday: "holiday" } as Record<RuleKind, string>)[kind]; }
|
| 53 |
|
| 54 |
type RecurrenceCondition = {
|
| 55 |
colId: string;
|
|
|
|
| 57 |
value: string;
|
| 58 |
value2?: string;
|
| 59 |
};
|
| 60 |
+
// `anchorField` and `conditions` are persisted by the server and absent from `DateRecurrence`;
|
| 61 |
+
// they have ridden this local intersection since wave 43. `ends` joins them the same way.
|
| 62 |
+
type RecurrenceEnds = { kind: "never" } | { kind: "on"; date: string } | { kind: "after"; count: number };
|
| 63 |
type LinkedRecurrence = DateRecurrence & {
|
| 64 |
anchorField?: { table: "same" | string; field: string; linkedVia?: string };
|
| 65 |
conditions?: RecurrenceCondition[];
|
| 66 |
+
ends?: RecurrenceEnds;
|
| 67 |
};
|
| 68 |
|
| 69 |
+
// The plain-language line the closed picker shows, so a person reads the schedule without
|
| 70 |
+
// reopening the editor. Commas and full stops only, and never a dash character.
|
| 71 |
+
function ruleSentence(rule: DateRecurrenceRule, calendars: CalendarOption[]): string {
|
| 72 |
+
const every = bounded(rule.interval ?? 1, 1, 366, 1);
|
| 73 |
+
const unit = (word: string) => (every === 1 ? word : `${every} ${word}s`);
|
| 74 |
+
const kind = ruleKind(rule);
|
| 75 |
+
if (kind === "weekly") {
|
| 76 |
+
const days = (rule.weekdays ?? []).map((day) => WEEKDAYS[day]).filter(Boolean).join(", ");
|
| 77 |
+
return `every ${unit("week")}${days ? ` on ${days}` : ""}`;
|
| 78 |
+
}
|
| 79 |
+
if (kind === "monthly_ordinal") {
|
| 80 |
+
const ordinal = ORDINALS.find(([value]) => value === rule.ordinal)?.[1] ?? "First";
|
| 81 |
+
return `every ${unit("month")} on the ${ordinal.toLowerCase()} ${WEEKDAYS[rule.weekday ?? 0]}`;
|
| 82 |
+
}
|
| 83 |
+
if (kind === "monthly") return `every ${unit("month")} on day ${rule.day ?? 1}`;
|
| 84 |
+
if (kind === "yearly") return `every ${unit("year")} on ${MONTHS[bounded(rule.month ?? 1, 1, 12, 1) - 1]} ${rule.day ?? 1}`;
|
| 85 |
+
if (kind === "holiday") {
|
| 86 |
+
const option = calendars.find((item) => item.code === (rule.calendar ?? "US"));
|
| 87 |
+
const relation = ["the day before", "the day of", "the day after"][bounded(rule.offset ?? 0, -1, 1, 0) + 1];
|
| 88 |
+
// A single holiday reads as itself. "each holiday in Christmas Day" is what the calendar
|
| 89 |
+
// phrasing becomes once a rule can name one day, and it is not a sentence anybody wrote.
|
| 90 |
+
if (option?.group === "holiday") return `on ${relation} ${option.label}`;
|
| 91 |
+
return `on ${relation} each holiday in ${option?.label ?? "public holidays"}`;
|
| 92 |
+
}
|
| 93 |
+
return `every ${unit("day")}`;
|
| 94 |
+
}
|
| 95 |
+
function recurrenceSentence(rules: DateRecurrenceRule[], ends: RecurrenceEnds, calendars: CalendarOption[]): string {
|
| 96 |
+
if (!rules.length) return "";
|
| 97 |
+
const body = rules.map((rule) => ruleSentence(rule, calendars)).join(", and ");
|
| 98 |
+
if (ends.kind === "on") return `Repeats ${body}, until ${ends.date}.`;
|
| 99 |
+
if (ends.kind === "after") return `Repeats ${body}, ${ends.count} times.`;
|
| 100 |
+
return `Repeats ${body}.`;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
export function DatePicker({ anchor, field, fields, scopeKey, value, today, onChange, onRecurrence, onClose }: {
|
| 104 |
anchor: AnchorRect; field: Field; fields: Field[]; scopeKey: string; value: unknown; today?: string; onChange: (value: string) => void;
|
| 105 |
onRecurrence: (recurrence: DateRecurrence | null) => void; onClose: () => void;
|
|
|
|
| 118 |
const [anchorField, setAnchorField] = useState(() => storedRecurrence?.anchorField?.field ?? "");
|
| 119 |
const [linkedVia, setLinkedVia] = useState(() => storedRecurrence?.anchorField?.linkedVia ?? "");
|
| 120 |
const [conditions, setConditions] = useState<RecurrenceCondition[]>(() => storedRecurrence?.conditions ?? []);
|
| 121 |
+
const [ends, setEnds] = useState<RecurrenceEnds>(() => storedRecurrence?.ends ?? { kind: "never" });
|
| 122 |
+
// Step 1 is a plain date. The repeat editor is a second step in the SAME overlay, so the
|
| 123 |
+
// anchor block, the conditions and the rule rows leave the default path entirely.
|
| 124 |
+
const [step, setStep] = useState<"date" | "repeat">("date");
|
| 125 |
+
const [restorePoint, setRestorePoint] = useState<null | { rules: DateRecurrenceRule[]; ends: RecurrenceEnds; anchorTable: string; anchorField: string; linkedVia: string; conditions: RecurrenceCondition[]; previewCount: number }>(null);
|
| 126 |
+
const endsName = useId();
|
| 127 |
const dateFields = useMemo(() => fields.filter((candidate) => candidate.type === "date"), [fields]);
|
| 128 |
const linkedFields = useMemo(() => fields.filter((candidate) => candidate.type === "link" && candidate.link?.table), [fields]);
|
| 129 |
const recurrence = useMemo<LinkedRecurrence | null>(() => rules.length ? ({
|
|
|
|
| 136 |
...(anchorTable !== "same" && linkedVia ? { linkedVia } : {}),
|
| 137 |
} } : {}),
|
| 138 |
...(conditions.length ? { conditions } : {}),
|
| 139 |
+
...(ends.kind !== "never" ? { ends } : {}),
|
| 140 |
+
}) : null, [anchorField, anchorTable, conditions, ends, linkedVia, previewCount, rules, selectedIso]);
|
| 141 |
|
| 142 |
// Server-evaluated preview: the exact payload saved below is sent here, so edited previews
|
| 143 |
// cannot differ from the default next date after refresh because of timezone/holiday drift.
|
|
|
|
| 167 |
const weekdays = checked ? [...new Set([...existing, weekday])].sort() : existing.filter((day) => day !== weekday);
|
| 168 |
return { ...rule, weekdays: weekdays.length ? weekdays : existing };
|
| 169 |
}));
|
| 170 |
+
const openEditor = () => {
|
| 171 |
+
setRestorePoint({ rules, ends, anchorTable, anchorField, linkedVia, conditions, previewCount });
|
| 172 |
+
if (!rules.length) setRules([newRule("weekly", selected)]);
|
| 173 |
+
setStep("repeat");
|
| 174 |
+
};
|
| 175 |
+
const cancelEditor = () => {
|
| 176 |
+
if (restorePoint) {
|
| 177 |
+
setRules(restorePoint.rules); setEnds(restorePoint.ends); setAnchorTable(restorePoint.anchorTable);
|
| 178 |
+
setAnchorField(restorePoint.anchorField); setLinkedVia(restorePoint.linkedVia);
|
| 179 |
+
setConditions(restorePoint.conditions); setPreviewCount(restorePoint.previewCount);
|
| 180 |
+
}
|
| 181 |
+
setRestorePoint(null);
|
| 182 |
+
setStep("date");
|
| 183 |
+
};
|
| 184 |
+
const saveEditor = () => { onRecurrence(recurrence); setRestorePoint(null); setStep("date"); };
|
| 185 |
+
const removeRepeat = () => { setRules([]); setEnds({ kind: "never" }); setConditions([]); onRecurrence(null); setRestorePoint(null); setStep("date"); };
|
| 186 |
const monthStart = new Date(Date.UTC(cursor.getUTCFullYear(), cursor.getUTCMonth(), 1));
|
| 187 |
const leading = (monthStart.getUTCDay() + 6) % 7;
|
| 188 |
const days = new Date(Date.UTC(cursor.getUTCFullYear(), cursor.getUTCMonth() + 1, 0)).getUTCDate();
|
| 189 |
const cells = Array.from({ length: Math.ceil((leading + days) / 7) * 7 }, (_, index) => index - leading + 1);
|
| 190 |
+
const summary = recurrenceSentence(rules, ends, calendars);
|
| 191 |
|
| 192 |
// This is a body-portal overlay, so `cg-date-picker` alone only supplies its width and padding.
|
| 193 |
// Keep the shared `cg-pop` contract on the same element: it supplies the opaque surface, border,
|
| 194 |
// elevation, and readable ink that every anchored editor needs over Glide's canvas.
|
| 195 |
return <AnchoredOverlay anchor={anchor} className="cg-pop cg-date-picker" placement="bottom-start" onDismiss={onClose} role="dialog" ariaLabel={`Choose a date for ${field.label}`} dataKind="date-picker">
|
| 196 |
+
{step === "date" ? <>
|
| 197 |
+
<label className="cg-date-boundary">Date<input className="cg-input" type="date" value={selectedIso} aria-label={`Date value for ${field.label}`} onChange={(event) => onChange(event.target.value)} /></label>
|
| 198 |
+
<div className="cg-date-picker-head"><button type="button" className="cg-icon-button" aria-label="Previous month" onClick={() => setCursor(addMonths(cursor, -1))}>βΉ</button><strong>{MONTHS[cursor.getUTCMonth()]} {cursor.getUTCFullYear()}</strong><button type="button" className="cg-icon-button" aria-label="Next month" onClick={() => setCursor(addMonths(cursor, 1))}>βΊ</button></div>
|
| 199 |
+
<div className="cg-date-weekdays">{WEEKDAYS.map((day) => <span key={day}>{day}</span>)}</div>
|
| 200 |
+
<div className="cg-date-grid">{cells.map((day, index) => {
|
| 201 |
+
if (day < 1 || day > days) return <span key={`blank-${index}`} aria-hidden />;
|
| 202 |
+
const dateIso = iso(new Date(Date.UTC(cursor.getUTCFullYear(), cursor.getUTCMonth(), day)));
|
| 203 |
+
return <button key={dateIso} type="button" className={"cg-date-day" + (dateIso === selectedIso ? " is-selected" : "")} aria-pressed={dateIso === selectedIso} onClick={() => onChange(dateIso)}>{day}</button>;
|
| 204 |
+
})}</div>
|
| 205 |
+
<div className="w46-date-footer">
|
| 206 |
+
{rules.length ? <>
|
| 207 |
+
<span className="w46-date-summary">{summary}</span>
|
| 208 |
+
<button type="button" className="w46-date-repeat is-set" onClick={openEditor}>Edit repeat</button>
|
| 209 |
+
</> : <button type="button" className="w46-date-repeat" onClick={openEditor}>Repeat</button>}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
</div>
|
| 211 |
+
</> : <div className="w46-recur">
|
| 212 |
+
<div className="w46-recur-head">
|
| 213 |
+
<button type="button" className="w46-recur-back" aria-label="Back to the calendar" onClick={cancelEditor}>βΉ</button>
|
| 214 |
+
<div className="cg-pop-title">Custom repeat</div>
|
| 215 |
+
</div>
|
| 216 |
+
{rules.map((rule, index) => <div className="w46-recur-card" key={`${rule.kind}-${index}`}>
|
| 217 |
+
<div className="w46-recur-row">
|
| 218 |
+
<span className="w46-recur-label">Repeat every</span>
|
| 219 |
+
<div className="w46-recur-controls">
|
| 220 |
+
<input className="cg-input w46-recur-count" min="1" max="366" type="number" aria-label={`Repeat interval ${index + 1}`} value={rule.interval ?? 1} onChange={(event) => updateRule(index, { interval: bounded(event.target.value, 1, 366, 1) })} />
|
| 221 |
+
<select className="cg-select" value={ruleKind(rule)} aria-label={`Repeat unit ${index + 1}`} onChange={(event) => replaceKind(index, event.target.value as RuleKind)}>{RULE_KINDS.map((kind) => <option key={kind} value={kind}>{labelForKind(kind)}</option>)}</select>
|
| 222 |
+
</div>
|
| 223 |
+
</div>
|
| 224 |
+
{rule.kind === "weekly" && <div className="w46-recur-row">
|
| 225 |
+
<span className="w46-recur-label" id={`${endsName}-days-${index}`}>Repeat on</span>
|
| 226 |
+
<div className="w46-recur-pills" role="group" aria-labelledby={`${endsName}-days-${index}`}>{WEEKDAY_INITIALS.map((initial, weekday) => {
|
| 227 |
+
const on = (rule.weekdays ?? []).includes(weekday);
|
| 228 |
+
return <button key={WEEKDAYS[weekday]} type="button" className={"w46-recur-pill" + (on ? " is-on" : "")} aria-pressed={on} aria-label={WEEKDAYS[weekday]} onClick={() => toggleWeekday(index, weekday, !on)}>{initial}</button>;
|
| 229 |
+
})}</div>
|
| 230 |
+
</div>}
|
| 231 |
+
{rule.kind === "monthly" && rule.ordinal === undefined && <div className="w46-recur-row">
|
| 232 |
+
<span className="w46-recur-label">Repeat on</span>
|
| 233 |
+
<div className="w46-recur-controls"><span className="w46-recur-word">day</span><input className="cg-input w46-recur-count" min="1" max="31" type="number" aria-label={`Day of the month ${index + 1}`} value={rule.day ?? 1} onChange={(event) => updateRule(index, { day: bounded(event.target.value, 1, 31, 1) })} /></div>
|
| 234 |
+
</div>}
|
| 235 |
+
{rule.kind === "monthly" && rule.ordinal !== undefined && <div className="w46-recur-row">
|
| 236 |
+
<span className="w46-recur-label">Repeat on</span>
|
| 237 |
+
<div className="w46-recur-controls">
|
| 238 |
+
<select className="cg-select" value={rule.ordinal} aria-label="Month ordinal" onChange={(event) => updateRule(index, { ordinal: Number(event.target.value) as DateRecurrenceRule["ordinal"] })}>{ORDINALS.map(([value, label]) => <option key={value} value={value}>{label}</option>)}</select>
|
| 239 |
+
<select className="cg-select" value={rule.weekday ?? 0} aria-label="Month weekday" onChange={(event) => updateRule(index, { weekday: Number(event.target.value) })}>{WEEKDAYS.map((day, weekday) => <option key={day} value={weekday}>{day}</option>)}</select>
|
| 240 |
+
</div>
|
| 241 |
+
</div>}
|
| 242 |
+
{rule.kind === "yearly" && <div className="w46-recur-row">
|
| 243 |
+
<span className="w46-recur-label">Repeat on</span>
|
| 244 |
+
<div className="w46-recur-controls">
|
| 245 |
+
<select className="cg-select" value={bounded(rule.month ?? 1, 1, 12, 1)} aria-label="Month of the year" onChange={(event) => updateRule(index, { month: bounded(event.target.value, 1, 12, 1) })}>{MONTHS.map((month, offset) => <option key={month} value={offset + 1}>{month}</option>)}</select>
|
| 246 |
+
<input className="cg-input w46-recur-count" min="1" max="31" type="number" aria-label="Day of the month" value={rule.day ?? 1} onChange={(event) => updateRule(index, { day: bounded(event.target.value, 1, 31, 1) })} />
|
| 247 |
+
</div>
|
| 248 |
+
</div>}
|
| 249 |
+
{rule.kind === "holiday" && <div className="w46-recur-row">
|
| 250 |
+
<span className="w46-recur-label">Repeat on</span>
|
| 251 |
+
<div className="w46-recur-controls">
|
| 252 |
+
<select className="cg-select" value={rule.calendar ?? "US"} aria-label="Public calendar" onChange={(event) => updateRule(index, { calendar: event.target.value as "US" | "CA" })}>{CALENDAR_GROUPS.map(([group, heading]) => {
|
| 253 |
+
const members = calendars.filter((calendar) => (calendar.group ?? "calendar") === group);
|
| 254 |
+
return members.length ? <optgroup key={heading} label={heading}>{members.map((calendar) => <option key={calendar.code} value={calendar.code}>{calendar.label}</option>)}</optgroup> : null;
|
| 255 |
+
})}</select>
|
| 256 |
+
<select className="cg-select" value={rule.offset ?? 0} aria-label="Holiday relation" onChange={(event) => updateRule(index, { offset: Number(event.target.value) as -1 | 0 | 1 })}><option value={-1}>Day before</option><option value={0}>Day on</option><option value={1}>Day after</option></select>
|
| 257 |
+
</div>
|
| 258 |
+
</div>}
|
| 259 |
+
{rules.length > 1 && <div className="w46-recur-card-foot"><button type="button" className="w46-recur-quiet" onClick={() => setRules((current) => current.filter((_, item) => item !== index))}>Remove rule</button></div>}
|
| 260 |
</div>)}
|
| 261 |
+
<button type="button" className="w46-recur-add" onClick={() => setRules((current) => [...current, newRule("daily", selected)])}>Add another rule</button>
|
| 262 |
+
<div className="w46-recur-row">
|
| 263 |
+
<span className="w46-recur-label" id={`${endsName}-label`}>Ends</span>
|
| 264 |
+
<div className="w46-recur-ends" role="group" aria-labelledby={`${endsName}-label`}>
|
| 265 |
+
<label className="w46-recur-radio"><input type="radio" name={endsName} checked={ends.kind === "never"} onChange={() => setEnds({ kind: "never" })} /><span>Never</span></label>
|
| 266 |
+
<label className="w46-recur-radio"><input type="radio" name={endsName} checked={ends.kind === "on"} onChange={() => setEnds({ kind: "on", date: selectedIso })} /><span>On</span>
|
| 267 |
+
<input className="cg-input w46-recur-date" type="date" aria-label="Repeat until this date" disabled={ends.kind !== "on"} value={ends.kind === "on" ? ends.date : ""} onChange={(event) => setEnds({ kind: "on", date: event.target.value })} /></label>
|
| 268 |
+
<label className="w46-recur-radio"><input type="radio" name={endsName} checked={ends.kind === "after"} onChange={() => setEnds({ kind: "after", count: 13 })} /><span>After</span>
|
| 269 |
+
<input className="cg-input w46-recur-count" type="number" min="1" max="365" aria-label="Number of occurrences" disabled={ends.kind !== "after"} value={ends.kind === "after" ? ends.count : ""} onChange={(event) => setEnds({ kind: "after", count: bounded(event.target.value, 1, 365, 13) })} /><span className="w46-recur-word">occurrences</span></label>
|
| 270 |
+
</div>
|
| 271 |
+
</div>
|
| 272 |
+
<details className="w46-recur-more">
|
| 273 |
+
<summary>More options</summary>
|
| 274 |
+
<div className="cg-date-boundary" aria-label="Recurrence anchor">
|
| 275 |
+
<label>Anchor database<select className="cg-select" value={anchorTable} onChange={(event) => {
|
| 276 |
+
const table = event.target.value;
|
| 277 |
+
setAnchorTable(table);
|
| 278 |
+
if (table === "same") setLinkedVia("");
|
| 279 |
+
else setLinkedVia(linkedFields.find((candidate) => candidate.link?.table === table)?.key ?? "");
|
| 280 |
+
setAnchorField("");
|
| 281 |
+
}}><option value="same">This database</option>{linkedFields.map((candidate) => <option value={candidate.link!.table} key={candidate.key}>{candidate.label} Β· {candidate.link!.table}</option>)}</select></label>
|
| 282 |
+
{anchorTable === "same" ? <label>Date field<select className="cg-select" value={anchorField} onChange={(event) => setAnchorField(event.target.value)}><option value="">This date</option>{dateFields.map((candidate) => <option value={candidate.key} key={candidate.key}>{candidate.label}</option>)}</select></label>
|
| 283 |
+
: <><label>Linked through<select className="cg-select" value={linkedVia} onChange={(event) => setLinkedVia(event.target.value)}>{linkedFields.filter((candidate) => candidate.link?.table === anchorTable).map((candidate) => <option value={candidate.key} key={candidate.key}>{candidate.label}</option>)}</select></label><label>Linked date field key<input className="cg-input" value={anchorField} onChange={(event) => setAnchorField(event.target.value)} placeholder="due_date" /></label></>}
|
| 284 |
+
</div>
|
| 285 |
+
<div className="cg-date-boundary" aria-label="Recurrence conditions"><div className="cg-pop-title">Only when</div>{conditions.map((condition, index) => <div className="cg-date-holidays" key={`${condition.colId}-${index}`}><select className="cg-select" aria-label={`Condition field ${index + 1}`} value={condition.colId} onChange={(event) => setConditions((current) => current.map((item, itemIndex) => itemIndex === index ? { ...item, colId: event.target.value } : item))}>{fields.map((candidate) => <option key={candidate.key} value={candidate.key}>{candidate.label}</option>)}</select><select className="cg-select" aria-label={`Condition operator ${index + 1}`} value={condition.op} onChange={(event) => setConditions((current) => current.map((item, itemIndex) => itemIndex === index ? { ...item, op: event.target.value as RecurrenceCondition["op"], ...(event.target.value === "between" ? {} : { value2: undefined }) } : item))}><option value="eq">is</option><option value="neq">is not</option><option value="not_empty">is not empty</option><option value="between">is between</option></select>{condition.op !== "not_empty" && <input className="cg-input" aria-label={`Condition value ${index + 1}`} value={condition.value} onChange={(event) => setConditions((current) => current.map((item, itemIndex) => itemIndex === index ? { ...item, value: event.target.value } : item))} />}{condition.op === "between" && <input className="cg-input" aria-label={`Condition second value ${index + 1}`} value={condition.value2 ?? ""} onChange={(event) => setConditions((current) => current.map((item, itemIndex) => itemIndex === index ? { ...item, value2: event.target.value } : item))} />}<button type="button" className="cg-link-btn" onClick={() => setConditions((current) => current.filter((_, itemIndex) => itemIndex !== index))}>Remove</button></div>)}<button type="button" className="cg-link-btn" disabled={!fields.length} onClick={() => setConditions((current) => [...current, { colId: fields[0]?.key ?? "", op: "eq", value: "" }])}>+ Add condition</button></div>
|
| 286 |
+
<label className="w46-recur-preview-count">Show next <select className="cg-select" value={previewCount} aria-label="Number of preview dates" onChange={(event) => setPreviewCount(bounded(event.target.value, 1, 50, 10))}>{[3, 5, 10, 20, 50].map((count) => <option key={count} value={count}>{count}</option>)}</select> dates</label>
|
| 287 |
+
</details>
|
| 288 |
+
<div className="cg-date-preview" aria-live="polite"><div className="cg-pop-title">Next dates{nextDate ? ` Β· next ${nextDate}` : ""}</div>{preview.map((date) => <span key={date}>{date}</span>)}{rules.length > 0 && !preview.length && !previewError && <span>Calculating the server previewβ¦</span>}{previewError && <span role="status">{previewError}</span>}</div>
|
| 289 |
+
<div className="w46-recur-foot">
|
| 290 |
+
{storedRecurrence?.rules?.length ? <button type="button" className="w46-recur-quiet is-danger" onClick={removeRepeat}>Remove repeat</button> : null}
|
| 291 |
+
<button type="button" className="w46-recur-quiet" onClick={cancelEditor}>Cancel</button>
|
| 292 |
+
<button type="button" className="w46-recur-save" onClick={saveEditor}>Save</button>
|
| 293 |
+
</div>
|
| 294 |
+
</div>}
|
| 295 |
</AnchoredOverlay>;
|
| 296 |
}
|
web/src/customer-grid/MapView.tsx
CHANGED
|
@@ -92,7 +92,7 @@ import {
|
|
| 92 |
zoomLimits,
|
| 93 |
} from "./mapProjection";
|
| 94 |
import type { GeoStop, Pt, RouteStamp, View } from "./mapProjection";
|
| 95 |
-
import { LP_INK, LP_MAP_SELECTED, LP_PURPLE, LP_PURPLE_DEEP } from "./theme";
|
| 96 |
import { RouteNav } from "./RouteNav";
|
| 97 |
import { normalizedRouteMapLinks } from "./routeLinks";
|
| 98 |
import {
|
|
@@ -112,6 +112,7 @@ import type {
|
|
| 112 |
ZoneGeometry,
|
| 113 |
} from "./routeZoneTypes";
|
| 114 |
import "./map.css";
|
|
|
|
| 115 |
|
| 116 |
/**
|
| 117 |
* W37-T35 β THE PROVIDER SEAM, client side.
|
|
@@ -361,6 +362,57 @@ export function translateZoneGeometry(
|
|
| 361 |
.map((polygon) => polygon.map((ring) => ring.map(point))) };
|
| 362 |
}
|
| 363 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 364 |
/** C3's durable map-domain DTO. Zones are not generic fields: geometry, visibility and the
|
| 365 |
* membership snapshot only make sense to this projection. */
|
| 366 |
type MapZone = MapZoneDto;
|
|
@@ -371,6 +423,13 @@ interface ZoneMove {
|
|
| 371 |
start: Pt;
|
| 372 |
}
|
| 373 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 374 |
/** Immutable provenance supplied by the host grid for a scheduled route snapshot. */
|
| 375 |
export interface RouteSourceView {
|
| 376 |
id: string;
|
|
@@ -410,6 +469,23 @@ function numOrNull(v: Row[keyof Row]): number | null {
|
|
| 410 |
return Number.isFinite(n) ? n : null;
|
| 411 |
}
|
| 412 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 413 |
export function MapView({
|
| 414 |
rows,
|
| 415 |
field,
|
|
@@ -576,6 +652,7 @@ export function MapView({
|
|
| 576 |
} | null>(null);
|
| 577 |
const mapFrameRef = useRef<HTMLDivElement | null>(null);
|
| 578 |
const [zoneMove, setZoneMove] = useState<ZoneMove | null>(null);
|
|
|
|
| 579 |
const [zoneGeometryDraft, setZoneGeometryDraft] = useState<{ id: string; geometry: ZoneGeometry } | null>(null);
|
| 580 |
const [zoneBusy, setZoneBusy] = useState(false);
|
| 581 |
const [zoneErr, setZoneErr] = useState<string | null>(null);
|
|
@@ -870,6 +947,62 @@ export function MapView({
|
|
| 870 |
}, [mapRows, field.key, coordField, colorField, sizeField]);
|
| 871 |
const noCoords = mapRows.length - points.length;
|
| 872 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 873 |
const loadZones = useCallback(async () => {
|
| 874 |
zoneRequestRef.current.controller?.abort();
|
| 875 |
const controller = new AbortController();
|
|
@@ -1336,14 +1469,30 @@ export function MapView({
|
|
| 1336 |
: geometry.type === "MultiPolygon"
|
| 1337 |
? geometry.coordinates as number[][][][]
|
| 1338 |
: [];
|
| 1339 |
-
return polygons.flatMap((polygon, polygonIndex) => polygon.map((ring, ringIndex) =>
|
| 1340 |
-
|
| 1341 |
-
|
| 1342 |
-
|
| 1343 |
-
|
| 1344 |
-
|
| 1345 |
-
.map((pair) =>
|
| 1346 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1347 |
}), [activeZones, zoneGeometryDraft]);
|
| 1348 |
const zoneCircles = useMemo(() => activeZones.flatMap((zone) => {
|
| 1349 |
const geometry = zoneGeometryDraft?.id === zone.id ? zoneGeometryDraft.geometry : zone.geometryGeoJson;
|
|
@@ -1355,8 +1504,14 @@ export function MapView({
|
|
| 1355 |
return [{ zone, geometry, center, radius: Math.abs(edge.x - center.x) }];
|
| 1356 |
}), [activeZones, zoneGeometryDraft]);
|
| 1357 |
|
| 1358 |
-
|
| 1359 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1360 |
const name = zoneName.trim() || existing?.name || "";
|
| 1361 |
if (!name || !geometryGeoJson) {
|
| 1362 |
setZoneErr("Name a Zone and draw its boundary on the map.");
|
|
@@ -1823,6 +1978,34 @@ export function MapView({
|
|
| 1823 |
...order.filter((i) => !seen.has(i) && (!depotPoint || i !== 0)),
|
| 1824 |
];
|
| 1825 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1826 |
const ordered = seq.map((i) => routable[i]);
|
| 1827 |
// ββ THE PERMUTATION IS NOT THE RANK (A25 / A44). `seq[i]` is WHICH STOP is visited i-th;
|
| 1828 |
// the number a record carries is the other way round, and `routeRanks` is the one inversion.
|
|
@@ -1850,7 +2033,8 @@ export function MapView({
|
|
| 1850 |
// default applies, so keying on it would report STALE the moment somebody explicitly
|
| 1851 |
// selects the stop that was ALREADY the origin β the numbers unchanged, the marker on.
|
| 1852 |
// What the answer depends on is which stop the planner was actually given.
|
| 1853 |
-
{ roundTrip, startPid: depotPoint ? null : routable[start].pid,
|
|
|
|
| 1854 |
),
|
| 1855 |
/** The origin the planner was given, so the saved column records the same one the
|
| 1856 |
* fingerprint was taken over. */
|
|
@@ -2137,6 +2321,61 @@ export function MapView({
|
|
| 2137 |
onRouteFieldCreated?.(key);
|
| 2138 |
}, [allRows, rows, onSelectPids, routeCols, onRouteFieldCreated]);
|
| 2139 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2140 |
/**
|
| 2141 |
* Write the visit numbers on screen into a tenant-wide column.
|
| 2142 |
*
|
|
@@ -2535,6 +2774,62 @@ export function MapView({
|
|
| 2535 |
setView((v) => (v ? { ...v, tx: v.tx + dx, ty: v.ty + dy } : v));
|
| 2536 |
}, []);
|
| 2537 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2538 |
/** The camera had NO keyboard path at all before wave 9 β scroll wheel only,
|
| 2539 |
* which is unusable without a mouse and unreachable for anyone driving the
|
| 2540 |
* page from the keyboard. */
|
|
@@ -2557,34 +2852,9 @@ export function MapView({
|
|
| 2557 |
return;
|
| 2558 |
} else if (e.key === "Enter") {
|
| 2559 |
if (!view) return;
|
| 2560 |
-
|
| 2561 |
-
|
| 2562 |
-
|
| 2563 |
-
e.preventDefault();
|
| 2564 |
-
return;
|
| 2565 |
-
}
|
| 2566 |
-
const coordinates = zoneKeyboardDraft.points
|
| 2567 |
-
.map((screen) => unproject(fromScreen(screen, view)))
|
| 2568 |
-
.map(({ lon, lat }) => [lon, lat]);
|
| 2569 |
-
setDrawnZoneGeometry({ type: "Polygon", coordinates: [[...coordinates, coordinates[0]]] });
|
| 2570 |
-
} else {
|
| 2571 |
-
if (!zoneKeyboardDraft.center) {
|
| 2572 |
-
setZoneErr("Press Space to place the circle center, move to its edge, then press Enter.");
|
| 2573 |
-
e.preventDefault();
|
| 2574 |
-
return;
|
| 2575 |
-
}
|
| 2576 |
-
const center = unproject(fromScreen(zoneKeyboardDraft.center, view));
|
| 2577 |
-
const edge = unproject(fromScreen(zoneKeyboardDraft.cursor, view));
|
| 2578 |
-
setDrawnZoneGeometry({
|
| 2579 |
-
type: "Circle",
|
| 2580 |
-
center: [center.lon, center.lat],
|
| 2581 |
-
radiusMeters: Math.max(1, Math.round(haversineKm(
|
| 2582 |
-
{ lat: center.lat, lon: center.lon }, { lat: edge.lat, lon: edge.lon }
|
| 2583 |
-
) * 1000)),
|
| 2584 |
-
});
|
| 2585 |
-
}
|
| 2586 |
-
setZoneKeyboardDraft(null);
|
| 2587 |
-
setZoneErr(null);
|
| 2588 |
e.preventDefault();
|
| 2589 |
return;
|
| 2590 |
} else if (e.key === "Escape") {
|
|
@@ -2617,7 +2887,7 @@ export function MapView({
|
|
| 2617 |
}
|
| 2618 |
e.preventDefault();
|
| 2619 |
},
|
| 2620 |
-
[panBy, zoomBy, rotateBy, doFit, drag, view, zoneKeyboardDraft]
|
| 2621 |
);
|
| 2622 |
|
| 2623 |
const startKeyboardZoneDrawing = useCallback(() => {
|
|
@@ -2630,6 +2900,23 @@ export function MapView({
|
|
| 2630 |
requestAnimationFrame(() => mapFrameRef.current?.focus());
|
| 2631 |
}, [zoneDrawShape]);
|
| 2632 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2633 |
const onPointerDown = useCallback(
|
| 2634 |
(e: ReactPointerEvent<SVGSVGElement>) => {
|
| 2635 |
if (e.button !== 0 || !view) return;
|
|
@@ -2666,6 +2953,31 @@ export function MapView({
|
|
| 2666 |
const onPointerMove = useCallback(
|
| 2667 |
(e: ReactPointerEvent<SVGSVGElement>) => {
|
| 2668 |
const { x, y } = localPoint(e.clientX, e.clientY);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2669 |
if (zoneMove && view) {
|
| 2670 |
if (Math.abs(x - zoneMove.start.x) + Math.abs(y - zoneMove.start.y) <= 2) return;
|
| 2671 |
movedRef.current = true;
|
|
@@ -2725,7 +3037,7 @@ export function MapView({
|
|
| 2725 |
touchedRef.current = true;
|
| 2726 |
setView((v) => (v ? { ...v, tx: pan.tx + (x - pan.x), ty: pan.ty + (y - pan.y) } : v));
|
| 2727 |
},
|
| 2728 |
-
[drag, localPoint, zoneMove, view]
|
| 2729 |
);
|
| 2730 |
|
| 2731 |
/**
|
|
@@ -2793,6 +3105,20 @@ export function MapView({
|
|
| 2793 |
|
| 2794 |
const onPointerUp = useCallback(
|
| 2795 |
(e: ReactPointerEvent<SVGSVGElement>) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2796 |
if (zoneMove) {
|
| 2797 |
const geometry = zoneGeometryDraft?.id === zoneMove.zone.id
|
| 2798 |
? zoneGeometryDraft.geometry
|
|
@@ -2804,6 +3130,23 @@ export function MapView({
|
|
| 2804 |
e.currentTarget.releasePointerCapture(e.pointerId);
|
| 2805 |
return;
|
| 2806 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2807 |
if (drag && view) {
|
| 2808 |
// A gesture smaller than a few px is a mis-click, not a selection β
|
| 2809 |
// clearing the user's set on a stray shift-click would be its own bug.
|
|
@@ -2860,8 +3203,8 @@ export function MapView({
|
|
| 2860 |
if (e.currentTarget.hasPointerCapture(e.pointerId))
|
| 2861 |
e.currentTarget.releasePointerCapture(e.pointerId);
|
| 2862 |
},
|
| 2863 |
-
[drag, view, points, onSelectPids, zoneMove, zoneGeometryDraft, persistZoneGeometry,
|
| 2864 |
-
zoneDrawShape, zoneEditorOpen]
|
| 2865 |
);
|
| 2866 |
|
| 2867 |
/**
|
|
@@ -3052,6 +3395,8 @@ export function MapView({
|
|
| 3052 |
onToggle={(route) => void toggleNamedRoute(route)}
|
| 3053 |
onActiveRouteChange={setActiveRouteId}
|
| 3054 |
onOpenRecord={onOpen}
|
|
|
|
|
|
|
| 3055 |
onCreate={createNamedRoute}
|
| 3056 |
onMoveToOrder={moveNamedRouteStop}
|
| 3057 |
onUpdate={updateNamedRoute}
|
|
@@ -3145,6 +3490,13 @@ export function MapView({
|
|
| 3145 |
))}
|
| 3146 |
</div>
|
| 3147 |
<button type="button" className="cg-btn cg-btn--primary" onClick={beginNewZone}>New Zone</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3148 |
</div>
|
| 3149 |
</aside>
|
| 3150 |
)}
|
|
@@ -3164,22 +3516,36 @@ export function MapView({
|
|
| 3164 |
<button type="button" aria-pressed={zoneDrawShape === "circle"}
|
| 3165 |
onClick={() => setZoneDrawShape("circle")}>Circle</button>
|
| 3166 |
</div>
|
| 3167 |
-
<span>Choose a shape, then drag on the map or
|
| 3168 |
{!zoneKeyboardDraft ? (
|
| 3169 |
-
<button type="button" className="cg-link-btn" onClick={startKeyboardZoneDrawing}>
|
| 3170 |
-
|
|
|
|
| 3171 |
</button>
|
| 3172 |
) : (
|
| 3173 |
<>
|
| 3174 |
-
|
| 3175 |
-
|
| 3176 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3177 |
<span role="status" aria-live="polite">
|
| 3178 |
{zoneKeyboardDraft.shape === "polygon"
|
| 3179 |
-
? `${zoneKeyboardDraft.points.length}
|
| 3180 |
: zoneKeyboardDraft.center
|
| 3181 |
-
? "
|
| 3182 |
-
: "
|
| 3183 |
</span>
|
| 3184 |
</>
|
| 3185 |
)}
|
|
@@ -3211,13 +3577,32 @@ export function MapView({
|
|
| 3211 |
{ZONE_COLOR_CHOICES.map((choice) => <option key={choice.value} value={choice.value}>{choice.label}</option>)}
|
| 3212 |
</select>
|
| 3213 |
</label>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3214 |
<button
|
| 3215 |
type="button"
|
| 3216 |
className="cg-btn cg-btn--primary"
|
| 3217 |
-
disabled={zoneBusy ||
|
| 3218 |
-
|
| 3219 |
-
|
| 3220 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3221 |
? (zoneEditor ? "Replace this Zone boundary with the drawn shape" : "Save the drawn Zone")
|
| 3222 |
: zoneEditor ? "Save Zone details" : "Draw a boundary before saving"}
|
| 3223 |
>
|
|
@@ -3257,7 +3642,7 @@ export function MapView({
|
|
| 3257 |
tabIndex={0}
|
| 3258 |
role="group"
|
| 3259 |
aria-label={zoneKeyboardDraft
|
| 3260 |
-
? `
|
| 3261 |
: "Map canvas. Arrow keys pan, plus and minus zoom, square brackets rotate, zero fits to data and faces north."}
|
| 3262 |
onKeyDown={onFrameKeyDown}
|
| 3263 |
onPointerDown={() => { if (!routePanelOpen) signal(NAV_MINIMIZE_EVENT); }}
|
|
@@ -3275,32 +3660,6 @@ export function MapView({
|
|
| 3275 |
onPointerCancel={onPointerUp}
|
| 3276 |
>
|
| 3277 |
<rect className="cg-map-water" x={0} y={0} width={VIEW_W} height={VIEW_H} />
|
| 3278 |
-
{zoneKeyboardDraft && (
|
| 3279 |
-
<g className="cg-zone-keyboard-draft" aria-hidden="true">
|
| 3280 |
-
{zoneKeyboardDraft.shape === "polygon" && zoneKeyboardDraft.points.length > 0 && (
|
| 3281 |
-
<polyline
|
| 3282 |
-
points={[...zoneKeyboardDraft.points, zoneKeyboardDraft.cursor]
|
| 3283 |
-
.map((point) => `${point.x},${point.y}`).join(" ")}
|
| 3284 |
-
fill="none" stroke={zoneColor} strokeWidth="3" strokeDasharray="6 4"
|
| 3285 |
-
/>
|
| 3286 |
-
)}
|
| 3287 |
-
{zoneKeyboardDraft.shape === "circle" && zoneKeyboardDraft.center && (
|
| 3288 |
-
<circle
|
| 3289 |
-
cx={zoneKeyboardDraft.center.x} cy={zoneKeyboardDraft.center.y}
|
| 3290 |
-
r={Math.hypot(
|
| 3291 |
-
zoneKeyboardDraft.cursor.x - zoneKeyboardDraft.center.x,
|
| 3292 |
-
zoneKeyboardDraft.cursor.y - zoneKeyboardDraft.center.y
|
| 3293 |
-
)}
|
| 3294 |
-
fill={zoneColor} fillOpacity="0.12" stroke={zoneColor}
|
| 3295 |
-
strokeWidth="3" strokeDasharray="6 4"
|
| 3296 |
-
/>
|
| 3297 |
-
)}
|
| 3298 |
-
{zoneKeyboardDraft.points.map((point, index) => (
|
| 3299 |
-
<circle key={`${point.x}:${point.y}:${index}`} cx={point.x} cy={point.y} r="4" fill={zoneColor} />
|
| 3300 |
-
))}
|
| 3301 |
-
<circle cx={zoneKeyboardDraft.cursor.x} cy={zoneKeyboardDraft.cursor.y} r="6" fill={zoneColor} stroke="white" strokeWidth="2" />
|
| 3302 |
-
</g>
|
| 3303 |
-
)}
|
| 3304 |
<g transform={tf}>
|
| 3305 |
{/* --- W37-T35: the raster basemap, UNDER everything, inside the same transform.
|
| 3306 |
β AND THE VENDORED GEOMETRY BELOW IS HIDDEN WHILE IT PAINTS. Drawing a
|
|
@@ -3389,7 +3748,9 @@ export function MapView({
|
|
| 3389 |
event.preventDefault(); void persistZoneGeometry(ring.zone, translateZoneGeometry(ring.geometry, delta));
|
| 3390 |
}}
|
| 3391 |
onPointerDown={(event) => {
|
| 3392 |
-
|
|
|
|
|
|
|
| 3393 |
event.stopPropagation();
|
| 3394 |
movedRef.current = false;
|
| 3395 |
const svg = event.currentTarget.ownerSVGElement;
|
|
@@ -3401,6 +3762,7 @@ export function MapView({
|
|
| 3401 |
});
|
| 3402 |
}}
|
| 3403 |
onClick={(event) => {
|
|
|
|
| 3404 |
event.stopPropagation();
|
| 3405 |
if (movedRef.current) {
|
| 3406 |
movedRef.current = false;
|
|
@@ -3417,12 +3779,86 @@ export function MapView({
|
|
| 3417 |
<circle key={zone.id} className="cg-map-zone" cx={center.x} cy={center.y} r={radius}
|
| 3418 |
fill={zone.color} stroke={zone.color} strokeWidth={hair(1.4)} tabIndex={0} role="button"
|
| 3419 |
aria-label={`${zone.name} Circle Zone. Enter selects records; arrow keys move the boundary.`}
|
| 3420 |
-
onPointerDown={(event) => { if (event.button !== 0 || !view) return; event.stopPropagation(); movedRef.current = false; event.currentTarget.ownerSVGElement?.setPointerCapture(event.pointerId); setZoneMove({ zone, geometry, start: localPoint(event.clientX, event.clientY) }); }}
|
| 3421 |
-
onClick={(event) => { event.stopPropagation(); if (movedRef.current) { movedRef.current = false; return; } onSelectPids(zone.memberships, "replace"); }}
|
| 3422 |
onKeyDown={(event) => { if (event.key === "Enter" || event.key === " ") { event.preventDefault(); onSelectPids(zone.memberships, "replace"); return; } const delta = event.key === "ArrowLeft" ? { lon: -0.0005, lat: 0 } : event.key === "ArrowRight" ? { lon: 0.0005, lat: 0 } : event.key === "ArrowUp" ? { lon: 0, lat: 0.0005 } : event.key === "ArrowDown" ? { lon: 0, lat: -0.0005 } : null; if (delta) { event.preventDefault(); void persistZoneGeometry(zone, translateZoneGeometry(geometry, delta)); } }}>
|
| 3423 |
<title>{`${zone.name}: circle radius ${Math.round(geometry.radiusMeters)} metres`}</title>
|
| 3424 |
</circle>
|
| 3425 |
))}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3426 |
{/* The planned path, UNDER the pins so it never hides a stop. Inside
|
| 3427 |
the zoomed group, so it pans and scales with the geography; the
|
| 3428 |
stroke is pre-divided by k like every other line here. */}
|
|
@@ -3486,7 +3922,15 @@ export function MapView({
|
|
| 3486 |
strokeWidth={hair(on ? 2 : 1)}
|
| 3487 |
role="button"
|
| 3488 |
tabIndex={0}
|
| 3489 |
-
aria-pressed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3490 |
// β THE ACCESSIBLE NAME IS THE ONLY CHANNEL A NON-SIGHTED USER HAS FOR A PIN'S
|
| 3491 |
// gesture: a `<circle>` carries no tooltip, no hover card and no glyph, and the
|
| 3492 |
// hint bar above is the SIGHTED half of this same disclosure. It said "Click to
|
|
@@ -3498,6 +3942,11 @@ export function MapView({
|
|
| 3498 |
onFocus={() => setHoverPid(p.pid)}
|
| 3499 |
onBlur={() => setHoverPid((h) => (h === p.pid ? null : h))}
|
| 3500 |
onClick={(e) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3501 |
// β NO LONGER MERELY "a finished pan is not a click" (R10): a drag that ends
|
| 3502 |
// on a pin would now OPEN a drawer, not just move the selection. See the
|
| 3503 |
// `pinSelect` doc comment above before touching this line.
|
|
@@ -3657,6 +4106,43 @@ export function MapView({
|
|
| 3657 |
points={lassoPts.map((p) => `${p.x.toFixed(1)},${p.y.toFixed(1)}`).join(" ")}
|
| 3658 |
/>
|
| 3659 |
)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3660 |
</svg>
|
| 3661 |
|
| 3662 |
{/* --- I18 β the camera controls. Zoom in / zoom out / fit to data, the
|
|
|
|
| 92 |
zoomLimits,
|
| 93 |
} from "./mapProjection";
|
| 94 |
import type { GeoStop, Pt, RouteStamp, View } from "./mapProjection";
|
| 95 |
+
import { LP_INK, LP_MAP_SELECTED, LP_PURPLE, LP_PURPLE_DEEP, LP_ZONE_FILL_OPACITY } from "./theme";
|
| 96 |
import { RouteNav } from "./RouteNav";
|
| 97 |
import { normalizedRouteMapLinks } from "./routeLinks";
|
| 98 |
import {
|
|
|
|
| 112 |
ZoneGeometry,
|
| 113 |
} from "./routeZoneTypes";
|
| 114 |
import "./map.css";
|
| 115 |
+
import "../styles/wave46/map-panels.css";
|
| 116 |
|
| 117 |
/**
|
| 118 |
* W37-T35 β THE PROVIDER SEAM, client side.
|
|
|
|
| 362 |
.map((polygon) => polygon.map((ring) => ring.map(point))) };
|
| 363 |
}
|
| 364 |
|
| 365 |
+
/** How many draggable corners one boundary ring may show. A shape a person DREW has a handful;
|
| 366 |
+
* anything past this was traced by the lasso, one coordinate per pointermove, and its dots
|
| 367 |
+
* would obscure the Zone rather than let anyone reshape it. See the render site. */
|
| 368 |
+
const ZONE_VERTEX_HANDLE_MAX = 24;
|
| 369 |
+
|
| 370 |
+
/** Where a single vertex lives inside a boundary. `polygonIndex` is meaningless for a plain
|
| 371 |
+
* Polygon (it is always 0) and load-bearing for a MultiPolygon; both are carried so one
|
| 372 |
+
* address works for either shape. */
|
| 373 |
+
interface ZoneVertexAddress {
|
| 374 |
+
polygonIndex: number;
|
| 375 |
+
ringIndex: number;
|
| 376 |
+
vertexIndex: number;
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
/**
|
| 380 |
+
* β W46-T28 β MOVE ONE VERTEX, leaving every other point where it was. Owner instruction 16:
|
| 381 |
+
* *"the zone vertices should be a dot that is draggable so I can minimize or expand a zone."*
|
| 382 |
+
* `translateZoneGeometry` above is the whole-boundary sibling; this is the reshape.
|
| 383 |
+
*
|
| 384 |
+
* β A GeoJSON RING IS CLOSED: its first and last coordinate are THE SAME POINT stored twice.
|
| 385 |
+
* Writing only the index that was grabbed tears the ring open at that seam, and the polygon then
|
| 386 |
+
* renders with a slit that no gate can see. Vertex 0 and the closing vertex always move
|
| 387 |
+
* together, which is the one rule this function exists to hold.
|
| 388 |
+
*/
|
| 389 |
+
export function moveZoneVertex(
|
| 390 |
+
geometry: ZoneGeometry, at: ZoneVertexAddress, to: { lon: number; lat: number }
|
| 391 |
+
): ZoneGeometry {
|
| 392 |
+
if (geometry.type === "Circle") return geometry;
|
| 393 |
+
const moved = [
|
| 394 |
+
Math.max(-180, Math.min(180, to.lon)),
|
| 395 |
+
Math.max(-90, Math.min(90, to.lat)),
|
| 396 |
+
];
|
| 397 |
+
const editRing = (ring: number[][]) => {
|
| 398 |
+
if (at.vertexIndex < 0 || at.vertexIndex >= ring.length) return ring;
|
| 399 |
+
const next = ring.map((pair) => [...pair]);
|
| 400 |
+
const last = next.length - 1;
|
| 401 |
+
const closed = last > 0 && next[0][0] === next[last][0] && next[0][1] === next[last][1];
|
| 402 |
+
next[at.vertexIndex] = [...moved];
|
| 403 |
+
if (closed && at.vertexIndex === 0) next[last] = [...moved];
|
| 404 |
+
if (closed && at.vertexIndex === last) next[0] = [...moved];
|
| 405 |
+
return next;
|
| 406 |
+
};
|
| 407 |
+
if (geometry.type === "Polygon") {
|
| 408 |
+
return { type: "Polygon", coordinates: (geometry.coordinates as number[][][])
|
| 409 |
+
.map((ring, ringIndex) => (ringIndex === at.ringIndex ? editRing(ring) : ring)) };
|
| 410 |
+
}
|
| 411 |
+
return { type: "MultiPolygon", coordinates: (geometry.coordinates as number[][][][])
|
| 412 |
+
.map((polygon, polygonIndex) => (polygonIndex !== at.polygonIndex ? polygon
|
| 413 |
+
: polygon.map((ring, ringIndex) => (ringIndex === at.ringIndex ? editRing(ring) : ring)))) };
|
| 414 |
+
}
|
| 415 |
+
|
| 416 |
/** C3's durable map-domain DTO. Zones are not generic fields: geometry, visibility and the
|
| 417 |
* membership snapshot only make sense to this projection. */
|
| 418 |
type MapZone = MapZoneDto;
|
|
|
|
| 423 |
start: Pt;
|
| 424 |
}
|
| 425 |
|
| 426 |
+
/** An in-flight vertex drag. It carries the geometry it started from, so every pointermove
|
| 427 |
+
* recomputes from the ORIGINAL rather than compounding its own previous answer. */
|
| 428 |
+
interface ZoneVertexDrag extends ZoneVertexAddress {
|
| 429 |
+
zone: MapZone;
|
| 430 |
+
geometry: ZoneGeometry;
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
/** Immutable provenance supplied by the host grid for a scheduled route snapshot. */
|
| 434 |
export interface RouteSourceView {
|
| 435 |
id: string;
|
|
|
|
| 469 |
return Number.isFinite(n) ? n : null;
|
| 470 |
}
|
| 471 |
|
| 472 |
+
/** W46-T17 β the draw glyph for the Zone arming button. A pen over a dotted
|
| 473 |
+
* outline: what the button does, in the same 16x16 box and the same
|
| 474 |
+
* `currentColor`/`fill="none"` idiom as the camera controls below.
|
| 475 |
+
* β It lives here rather than in `iconShapes.ts` only because that shared
|
| 476 |
+
* vocabulary belongs to another lane this wave. Its home there is owed. */
|
| 477 |
+
function DrawZoneIcon() {
|
| 478 |
+
return (
|
| 479 |
+
<svg className="cg-zone-draw-ico" viewBox="0 0 16 16" aria-hidden="true"
|
| 480 |
+
fill="none" stroke="currentColor" strokeWidth="1.4"
|
| 481 |
+
strokeLinecap="round" strokeLinejoin="round">
|
| 482 |
+
<path d="M2.4 9.6V3.2h5.2" strokeDasharray="2 1.6" />
|
| 483 |
+
<path d="M2.4 12.8h4.2" strokeDasharray="2 1.6" />
|
| 484 |
+
<path d="M13.6 3.1 8.2 8.5l-.7 2.5 2.5-.7 5.4-5.4z" />
|
| 485 |
+
</svg>
|
| 486 |
+
);
|
| 487 |
+
}
|
| 488 |
+
|
| 489 |
export function MapView({
|
| 490 |
rows,
|
| 491 |
field,
|
|
|
|
| 652 |
} | null>(null);
|
| 653 |
const mapFrameRef = useRef<HTMLDivElement | null>(null);
|
| 654 |
const [zoneMove, setZoneMove] = useState<ZoneMove | null>(null);
|
| 655 |
+
const [zoneVertex, setZoneVertex] = useState<ZoneVertexDrag | null>(null);
|
| 656 |
const [zoneGeometryDraft, setZoneGeometryDraft] = useState<{ id: string; geometry: ZoneGeometry } | null>(null);
|
| 657 |
const [zoneBusy, setZoneBusy] = useState(false);
|
| 658 |
const [zoneErr, setZoneErr] = useState<string | null>(null);
|
|
|
|
| 947 |
}, [mapRows, field.key, coordField, colorField, sizeField]);
|
| 948 |
const noCoords = mapRows.length - points.length;
|
| 949 |
|
| 950 |
+
/**
|
| 951 |
+
* W46-T26 β WHAT EACH STOP IS CALLED. The Route panel used to print a bare ordinal, so the
|
| 952 |
+
* list said nothing about who the driver is visiting. The name lives on the row, not on the
|
| 953 |
+
* route DTO (`visibleStopIds` is a bare `number[]`), so it is carried down from here.
|
| 954 |
+
*
|
| 955 |
+
* β BUILT FROM THE ROW BOOK, NOT FROM `points`. `points` holds only rows that survived
|
| 956 |
+
* coordinate validation, so a customer who has never been geocoded is ABSENT from it β and
|
| 957 |
+
* that is precisely the stop the address fallback exists to name. `allRows` leads for the same
|
| 958 |
+
* reason the saved-route row resolution takes it: a saved stop may sit outside the current
|
| 959 |
+
* View's filter and must still read as itself rather than as a placeholder.
|
| 960 |
+
*
|
| 961 |
+
* Name and address stay SEPARATE fields rather than one pre-picked string, because the printed
|
| 962 |
+
* route sheet needs both on the same line.
|
| 963 |
+
*/
|
| 964 |
+
const routeStopLabels = useMemo(() => {
|
| 965 |
+
const addrKey = coordField?.geocode?.addressField;
|
| 966 |
+
const out: Record<number, { name: string; address: string }> = {};
|
| 967 |
+
const book = allRows && allRows.length ? [...allRows, ...mapRows] : mapRows;
|
| 968 |
+
for (const r of book) {
|
| 969 |
+
if (out[r.pid]) continue;
|
| 970 |
+
out[r.pid] = {
|
| 971 |
+
name: String(r[field.key] ?? "").trim(),
|
| 972 |
+
address: addrKey ? String(r[addrKey] ?? "").trim() : "",
|
| 973 |
+
};
|
| 974 |
+
}
|
| 975 |
+
return out;
|
| 976 |
+
}, [allRows, mapRows, field.key, coordField]);
|
| 977 |
+
|
| 978 |
+
/**
|
| 979 |
+
* W46-T19 / CONTRACT C2 β the coordinates the Route timer measures from.
|
| 980 |
+
*
|
| 981 |
+
* β ROUTENAV CANNOT REACH THESE ON ITS OWN. `stopLabels` carries name and address only, and
|
| 982 |
+
* `NormalizedRouteMapLink` carries `{url,index,start,end,stopIds}` with no lat/lon, so without
|
| 983 |
+
* this prop the timer renders "No drive time yet" forever and C2's whole client half is dead.
|
| 984 |
+
*
|
| 985 |
+
* β THE SAME DERIVATION AS `activeRouteMaps` (below), deliberately: one rule for what counts as
|
| 986 |
+
* a located stop, so the Maps hand-off and the drive time can never disagree about which stops
|
| 987 |
+
* have a position. Built over the ROW BOOK rather than `points`, because `points` drops every
|
| 988 |
+
* row that failed coordinate validation and a saved stop can sit outside the current filter.
|
| 989 |
+
*/
|
| 990 |
+
const routeStopCoords = useMemo(() => {
|
| 991 |
+
const out: Record<number, { lat: number; lon: number }> = {};
|
| 992 |
+
for (const row of (allRows?.length ? allRows : mapRows)) {
|
| 993 |
+
if (out[row.pid]) continue;
|
| 994 |
+
const at = coordField
|
| 995 |
+
? parseLatLon(row[coordField.key])
|
| 996 |
+
: (() => {
|
| 997 |
+
const lat = coord(row.lat);
|
| 998 |
+
const lon = coord(row.lon);
|
| 999 |
+
return lat == null || lon == null || !isPlottable(lat, lon) ? null : { lat, lon };
|
| 1000 |
+
})();
|
| 1001 |
+
if (at) out[row.pid] = { lat: at.lat, lon: at.lon };
|
| 1002 |
+
}
|
| 1003 |
+
return out;
|
| 1004 |
+
}, [allRows, mapRows, coordField]);
|
| 1005 |
+
|
| 1006 |
const loadZones = useCallback(async () => {
|
| 1007 |
zoneRequestRef.current.controller?.abort();
|
| 1008 |
const controller = new AbortController();
|
|
|
|
| 1469 |
: geometry.type === "MultiPolygon"
|
| 1470 |
? geometry.coordinates as number[][][][]
|
| 1471 |
: [];
|
| 1472 |
+
return polygons.flatMap((polygon, polygonIndex) => polygon.map((ring, ringIndex) => {
|
| 1473 |
+
// β W46-T28 β THE SOURCE INDEX TRAVELS WITH THE POINT. The filter below drops any pair
|
| 1474 |
+
// that is not two finite numbers, so a rendered point's position in this array is NOT its
|
| 1475 |
+
// position in the stored ring. A vertex drag writes back BY INDEX, and reading the screen
|
| 1476 |
+
// index would silently move a different corner the moment one bad pair existed.
|
| 1477 |
+
const points = ring
|
| 1478 |
+
.map((pair, vertexIndex) => ({ pair, vertexIndex }))
|
| 1479 |
+
.filter(({ pair }) => Array.isArray(pair) && Number.isFinite(pair[0]) && Number.isFinite(pair[1]))
|
| 1480 |
+
.map(({ pair, vertexIndex }) => ({ ...project(pair[0], pair[1]), vertexIndex }));
|
| 1481 |
+
const last = points.length - 1;
|
| 1482 |
+
const closed = last > 0 && points[0].x === points[last].x && points[0].y === points[last].y;
|
| 1483 |
+
return {
|
| 1484 |
+
key: `${zone.id}:${polygonIndex}:${ringIndex}`,
|
| 1485 |
+
zone,
|
| 1486 |
+
geometry,
|
| 1487 |
+
polygonIndex,
|
| 1488 |
+
ringIndex,
|
| 1489 |
+
points,
|
| 1490 |
+
// One dot per CORNER. The closing coordinate is the opening one stored twice, so
|
| 1491 |
+
// drawing it too would stack two handles on the same pixel and the top one would
|
| 1492 |
+
// shadow the other's drag.
|
| 1493 |
+
handles: closed ? points.slice(0, last) : points,
|
| 1494 |
+
};
|
| 1495 |
+
}).filter((ring) => ring.points.length >= 4));
|
| 1496 |
}), [activeZones, zoneGeometryDraft]);
|
| 1497 |
const zoneCircles = useMemo(() => activeZones.flatMap((zone) => {
|
| 1498 |
const geometry = zoneGeometryDraft?.id === zone.id ? zoneGeometryDraft.geometry : zone.geometryGeoJson;
|
|
|
|
| 1504 |
return [{ zone, geometry, center, radius: Math.abs(edge.x - center.x) }];
|
| 1505 |
}), [activeZones, zoneGeometryDraft]);
|
| 1506 |
|
| 1507 |
+
/**
|
| 1508 |
+
* ββ W46-T28 β `pendingGeometry` IS THE FIX FOR "IT WON'T EVEN LET ME SAVE", and it is here
|
| 1509 |
+
* rather than in a `useEffect` because React state set in the same tick is not readable from
|
| 1510 |
+
* this closure. The Save button commits a still-open click-drawn outline and hands the
|
| 1511 |
+
* geometry straight down, so the save does not have to wait a render for `drawnZoneGeometry`.
|
| 1512 |
+
*/
|
| 1513 |
+
const saveZone = useCallback(async (existing?: MapZone, pendingGeometry?: ZoneGeometry) => {
|
| 1514 |
+
const geometryGeoJson = pendingGeometry || drawnZoneGeometry || existing?.geometryGeoJson;
|
| 1515 |
const name = zoneName.trim() || existing?.name || "";
|
| 1516 |
if (!name || !geometryGeoJson) {
|
| 1517 |
setZoneErr("Name a Zone and draw its boundary on the map.");
|
|
|
|
| 1978 |
...order.filter((i) => !seen.has(i) && (!depotPoint || i !== 0)),
|
| 1979 |
];
|
| 1980 |
}
|
| 1981 |
+
/**
|
| 1982 |
+
* ββ W46-T21 / D-469 β WHY THE HAND ORDER IS CANONICALISED BEFORE IT IS HASHED.
|
| 1983 |
+
*
|
| 1984 |
+
* `routeFingerprint`'s canon carries an `h:<handOrder>` term, and the two sides of the
|
| 1985 |
+
* staleness comparison disagreed about it STRUCTURALLY, not because anything changed:
|
| 1986 |
+
* at SAVE the planner had solved the order, so `routeOrder` was null and the stored hash
|
| 1987 |
+
* carried `h:` EMPTY; on REOPEN the arming effect sets `routeOrder` to the saved sequence,
|
| 1988 |
+
* so the live hash carried `h:6534,...`. They can never be equal, so EVERY saved route read
|
| 1989 |
+
* Stale forever, including one saved seconds earlier. That is D-469, and the "third term"
|
| 1990 |
+
* it could not isolate is this: the same term, present on one side and absent on the other.
|
| 1991 |
+
*
|
| 1992 |
+
* β THE `h:` TERM IS NOT DELETED, because D-429 depends on it: a genuine HAND edit must still
|
| 1993 |
+
* read as not-freshly-solved. Instead it contributes NOTHING when the applied sequence IS the
|
| 1994 |
+
* planner's own answer, which is the only case where a hand order carries no information.
|
| 1995 |
+
* A real hand edit differs from `order` and keeps its `h:`.
|
| 1996 |
+
*
|
| 1997 |
+
* β NO MIGRATION. Shape (ii) - re-hashing at save time with the order actually saved - would
|
| 1998 |
+
* have left every already-stored hash permanently mismatched, including the 52 routes stamped
|
| 1999 |
+
* 2026-08-23 that D-469 measured.
|
| 2000 |
+
*
|
| 2001 |
+
* β TWO OTHER TERMS ARE STILL ASYMMETRIC and this does NOT reach them: the column stores
|
| 2002 |
+
* `roundTrip` and `startPid`, and neither reopen path restores them, so a route saved
|
| 2003 |
+
* round-trip, or with an explicitly picked origin, still mismatches. Restoring them would
|
| 2004 |
+
* flip the map's own round-trip toggle when a route opens, which is a visible behaviour change
|
| 2005 |
+
* for a marker that currently renders NOWHERE (`orderStale` is computed and discarded). Left
|
| 2006 |
+
* deliberately, and recorded, for whoever next puts a staleness mark on screen.
|
| 2007 |
+
*/
|
| 2008 |
+
const seqEqualsOrder = seq.length === order.length && seq.every((v, i) => v === order[i]);
|
| 2009 |
const ordered = seq.map((i) => routable[i]);
|
| 2010 |
// ββ THE PERMUTATION IS NOT THE RANK (A25 / A44). `seq[i]` is WHICH STOP is visited i-th;
|
| 2011 |
// the number a record carries is the other way round, and `routeRanks` is the one inversion.
|
|
|
|
| 2033 |
// default applies, so keying on it would report STALE the moment somebody explicitly
|
| 2034 |
// selects the stop that was ALREADY the origin β the numbers unchanged, the marker on.
|
| 2035 |
// What the answer depends on is which stop the planner was actually given.
|
| 2036 |
+
{ roundTrip, startPid: depotPoint ? null : routable[start].pid,
|
| 2037 |
+
handOrder: seqEqualsOrder ? null : routeOrder }
|
| 2038 |
),
|
| 2039 |
/** The origin the planner was given, so the saved column records the same one the
|
| 2040 |
* fingerprint was taken over. */
|
|
|
|
| 2321 |
onRouteFieldCreated?.(key);
|
| 2322 |
}, [allRows, rows, onSelectPids, routeCols, onRouteFieldCreated]);
|
| 2323 |
|
| 2324 |
+
/**
|
| 2325 |
+
* OWNER INSTRUCTION 8 (W46-T16) - CLICKING A SAVED ROUTE DRAWS ITS PATH AGAIN.
|
| 2326 |
+
*
|
| 2327 |
+
* The polyline is gated on `plan`, and `plan` is null until `routeOn` is armed over two
|
| 2328 |
+
* routable stops. Wave 44 (`cc429a0`, "unify map route and zone navigation") retired the
|
| 2329 |
+
* route-order navigator, and `openSavedRoute` - the ONLY writer of `routeOrder` + `routeOn`
|
| 2330 |
+
* for a saved route - lost its surface with it. It survives only in the compatibility
|
| 2331 |
+
* `void [...]` list below and is reachable from no click. Since that commit every door a
|
| 2332 |
+
* person can take to a saved Route (`RouteNav`'s `.cg-w44-route-open` button, and the
|
| 2333 |
+
* `aios:route-open` event) sets `activeRouteId` and nothing else, so `plan` stays null and
|
| 2334 |
+
* the map draws nothing while erroring nothing. That is the regression, and it predates
|
| 2335 |
+
* wave 45 rather than arriving with it.
|
| 2336 |
+
*
|
| 2337 |
+
* Opening a named Route now arms exactly what the retired picker armed: the stops join
|
| 2338 |
+
* `addedPids` (so a stop outside the current View still earns a pin through `mapRows`), the
|
| 2339 |
+
* selection is REPLACED by the route's stop order, `routeOrder` takes that order verbatim so
|
| 2340 |
+
* `plan.ordered` follows the SAVED sequence rather than the solver's, and the origin picker
|
| 2341 |
+
* is cleared. It is one path for both kinds of route: a legacy-compatible projection and a
|
| 2342 |
+
* normalized record both reach the client as `visibleStopIds` ordered by `ordered_stops`.
|
| 2343 |
+
*
|
| 2344 |
+
* NO ROAD REQUEST (R3). This is the local straight-line plan only; the provider is asked when
|
| 2345 |
+
* somebody presses Driving route, exactly as `openSavedRoute` had it.
|
| 2346 |
+
*
|
| 2347 |
+
* ONCE PER OPENED ROUTE, VIA A REF KEYED ON THE ROUTE'S OWN STOP SEQUENCE. Keying on the id
|
| 2348 |
+
* alone would be spent on the pass where the `aios:route-open` listener has set an id that
|
| 2349 |
+
* `namedRoutes` does not carry yet, and would leave `routeOrder` stale after a stop is moved.
|
| 2350 |
+
* The sequence key re-arms when the SAVED route changes and never fights a hand reorder made
|
| 2351 |
+
* on the map, which does not touch `visibleStopIds`. Closing the detail clears the key so
|
| 2352 |
+
* reopening the same route arms it again.
|
| 2353 |
+
*
|
| 2354 |
+
* A ROUTE WITH FEWER THAN TWO VISIBLE STOPS IS LEFT ALONE rather than armed into the
|
| 2355 |
+
* `customerRoutable < 2` teardown effect above.
|
| 2356 |
+
*/
|
| 2357 |
+
const armedRouteRef = useRef<string>("");
|
| 2358 |
+
useEffect(() => {
|
| 2359 |
+
if (!activeNamedRoute) {
|
| 2360 |
+
armedRouteRef.current = "";
|
| 2361 |
+
return;
|
| 2362 |
+
}
|
| 2363 |
+
const stops = activeNamedRoute.visibleStopIds;
|
| 2364 |
+
if (stops.length < 2) return;
|
| 2365 |
+
const signature = `${activeNamedRoute.id}:${stops.join(",")}`;
|
| 2366 |
+
if (armedRouteRef.current === signature) return;
|
| 2367 |
+
armedRouteRef.current = signature;
|
| 2368 |
+
setAddedPids((prev) => {
|
| 2369 |
+
const next = new Set(prev);
|
| 2370 |
+
for (const pid of stops) next.add(pid);
|
| 2371 |
+
return next;
|
| 2372 |
+
});
|
| 2373 |
+
onSelectPids([...stops], "replace");
|
| 2374 |
+
setRouteOrder([...stops]);
|
| 2375 |
+
setRouteStartPid(null);
|
| 2376 |
+
setRouteOn(true);
|
| 2377 |
+
}, [activeNamedRoute, onSelectPids]);
|
| 2378 |
+
|
| 2379 |
/**
|
| 2380 |
* Write the visit numbers on screen into a tenant-wide column.
|
| 2381 |
*
|
|
|
|
| 2774 |
setView((v) => (v ? { ...v, tx: v.tx + dx, ty: v.ty + dy } : v));
|
| 2775 |
}, []);
|
| 2776 |
|
| 2777 |
+
/**
|
| 2778 |
+
* ββ W46-T28 β THE ONE PLACE A CLICK-DRAWN OUTLINE BECOMES A SAVEABLE BOUNDARY, and the
|
| 2779 |
+
* reason the owner could not save. Before this, that conversion lived ONLY in the `Enter`
|
| 2780 |
+
* branch of `onFrameKeyDown`, which fires only while `.cg-map-frame` itself holds focus. The
|
| 2781 |
+
* shape a user draws by clicking is drawn on the map and then NAMED in the panel, so by the
|
| 2782 |
+
* time they are done the focus is in a text input and `Enter` never reaches the map. The
|
| 2783 |
+
* panel's only draft control was "Stop drawing", which DISCARDS the points. So the outline
|
| 2784 |
+
* never reached `drawnZoneGeometry`, the Save button stayed `disabled`, and a disabled button
|
| 2785 |
+
* cannot explain itself: the refusal was real and completely silent.
|
| 2786 |
+
*
|
| 2787 |
+
* β It returns the geometry as well as storing it, because a caller in the same tick cannot
|
| 2788 |
+
* read the state it just set. `null` means it refused, and it has already said why in
|
| 2789 |
+
* `zoneErr` β a caller must not then report a second, vaguer reason over the top.
|
| 2790 |
+
*/
|
| 2791 |
+
const finishZoneDraft = useCallback((): ZoneGeometry | null => {
|
| 2792 |
+
const draft = zoneKeyboardDraft;
|
| 2793 |
+
if (!draft || !view) return null;
|
| 2794 |
+
let geometry: ZoneGeometry;
|
| 2795 |
+
if (draft.shape === "polygon") {
|
| 2796 |
+
if (draft.points.length < 3) {
|
| 2797 |
+
setZoneErr("Add at least three vertices, then finish the shape.");
|
| 2798 |
+
return null;
|
| 2799 |
+
}
|
| 2800 |
+
const coordinates = draft.points
|
| 2801 |
+
.map((screen) => unproject(fromScreen(screen, view)))
|
| 2802 |
+
.map(({ lon, lat }) => [lon, lat]);
|
| 2803 |
+
geometry = { type: "Polygon", coordinates: [[...coordinates, coordinates[0]]] };
|
| 2804 |
+
} else {
|
| 2805 |
+
if (!draft.center) {
|
| 2806 |
+
setZoneErr("Place the circle center first, then its edge.");
|
| 2807 |
+
return null;
|
| 2808 |
+
}
|
| 2809 |
+
// β W46-T28 β A CIRCLE WITH NO EDGE CLICK IS A ONE METRE ZONE. `cursor` still sits on
|
| 2810 |
+
// `center` until the second click, and `Math.max(1, 0)` below would happily mint a Zone
|
| 2811 |
+
// too small to see and holding no records: instruction 16's own complaint, saved. The
|
| 2812 |
+
// panel button puts that one click away, so the refusal is stated rather than shipped.
|
| 2813 |
+
if (draft.center.x === draft.cursor.x && draft.center.y === draft.cursor.y) {
|
| 2814 |
+
setZoneErr("Click the circle edge to give the Zone a size, then finish the shape.");
|
| 2815 |
+
return null;
|
| 2816 |
+
}
|
| 2817 |
+
const center = unproject(fromScreen(draft.center, view));
|
| 2818 |
+
const edge = unproject(fromScreen(draft.cursor, view));
|
| 2819 |
+
geometry = {
|
| 2820 |
+
type: "Circle",
|
| 2821 |
+
center: [center.lon, center.lat],
|
| 2822 |
+
radiusMeters: Math.max(1, Math.round(haversineKm(
|
| 2823 |
+
{ lat: center.lat, lon: center.lon }, { lat: edge.lat, lon: edge.lon }
|
| 2824 |
+
) * 1000)),
|
| 2825 |
+
};
|
| 2826 |
+
}
|
| 2827 |
+
setDrawnZoneGeometry(geometry);
|
| 2828 |
+
setZoneKeyboardDraft(null);
|
| 2829 |
+
setZoneErr(null);
|
| 2830 |
+
return geometry;
|
| 2831 |
+
}, [zoneKeyboardDraft, view]);
|
| 2832 |
+
|
| 2833 |
/** The camera had NO keyboard path at all before wave 9 β scroll wheel only,
|
| 2834 |
* which is unusable without a mouse and unreachable for anyone driving the
|
| 2835 |
* page from the keyboard. */
|
|
|
|
| 2852 |
return;
|
| 2853 |
} else if (e.key === "Enter") {
|
| 2854 |
if (!view) return;
|
| 2855 |
+
// W46-T28 β the same commit the panel's "Finish shape" button calls. Two controls,
|
| 2856 |
+
// one conversion: a second copy is how the two endings drift apart.
|
| 2857 |
+
finishZoneDraft();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2858 |
e.preventDefault();
|
| 2859 |
return;
|
| 2860 |
} else if (e.key === "Escape") {
|
|
|
|
| 2887 |
}
|
| 2888 |
e.preventDefault();
|
| 2889 |
},
|
| 2890 |
+
[panBy, zoomBy, rotateBy, doFit, drag, view, zoneKeyboardDraft, finishZoneDraft]
|
| 2891 |
);
|
| 2892 |
|
| 2893 |
const startKeyboardZoneDrawing = useCallback(() => {
|
|
|
|
| 2900 |
requestAnimationFrame(() => mapFrameRef.current?.focus());
|
| 2901 |
}, [zoneDrawShape]);
|
| 2902 |
|
| 2903 |
+
/** W46-T17 β A CLICK ON THE MAP IS THE PRIMARY WAY TO DRAW A ZONE. The arrow
|
| 2904 |
+
* keys and Space in `onFrameKeyDown` still work and are still the only path
|
| 2905 |
+
* for someone with no pointer, so that handler stays; what changed is that
|
| 2906 |
+
* nobody has to be TOLD about it to draw a shape. The cursor moves to the
|
| 2907 |
+
* click as well as the point being kept, so the rubber band that follows the
|
| 2908 |
+
* pointer starts from where the user just clicked. */
|
| 2909 |
+
const addZoneDraftVertex = useCallback((at: Pt) => {
|
| 2910 |
+
setZoneKeyboardDraft((draft) => {
|
| 2911 |
+
if (!draft) return draft;
|
| 2912 |
+
if (draft.shape === "polygon")
|
| 2913 |
+
return { ...draft, cursor: at, points: [...draft.points, at] };
|
| 2914 |
+
if (!draft.center) return { ...draft, cursor: at, center: at };
|
| 2915 |
+
return { ...draft, cursor: at };
|
| 2916 |
+
});
|
| 2917 |
+
setZoneErr(null);
|
| 2918 |
+
}, []);
|
| 2919 |
+
|
| 2920 |
const onPointerDown = useCallback(
|
| 2921 |
(e: ReactPointerEvent<SVGSVGElement>) => {
|
| 2922 |
if (e.button !== 0 || !view) return;
|
|
|
|
| 2953 |
const onPointerMove = useCallback(
|
| 2954 |
(e: ReactPointerEvent<SVGSVGElement>) => {
|
| 2955 |
const { x, y } = localPoint(e.clientX, e.clientY);
|
| 2956 |
+
// β W46-T17 β the in-progress outline TRACKS THE POINTER while drawing is
|
| 2957 |
+
// armed. Without this the first click leaves `points` and `cursor` on the
|
| 2958 |
+
// same coordinate, so the polyline has zero length and the shape reads as
|
| 2959 |
+
// invisible all over again. A pan or a marquee owns the pointer instead.
|
| 2960 |
+
if (zoneKeyboardDraft && !drag && !zoneMove && !zoneVertex && !panRef.current)
|
| 2961 |
+
setZoneKeyboardDraft((draft) =>
|
| 2962 |
+
draft && (draft.cursor.x !== x || draft.cursor.y !== y)
|
| 2963 |
+
? { ...draft, cursor: { x, y } }
|
| 2964 |
+
: draft);
|
| 2965 |
+
// β W46-T28 β ONE VERTEX FOLLOWS THE POINTER. It sits above the whole-boundary branch
|
| 2966 |
+
// because a handle is a smaller, more specific target sitting ON the boundary: without
|
| 2967 |
+
// this order, grabbing a corner would translate the entire Zone instead of reshaping it.
|
| 2968 |
+
// β Every move recomputes from `zoneVertex.geometry`, the shape as it was when the drag
|
| 2969 |
+
// STARTED, so the answer is a function of where the pointer is now and not of how it got
|
| 2970 |
+
// there. There is no travel threshold here on purpose: a corner nudged two pixels is a
|
| 2971 |
+
// deliberate adjustment, where the same two pixels on a whole boundary is a mis-click.
|
| 2972 |
+
if (zoneVertex && view) {
|
| 2973 |
+
movedRef.current = true;
|
| 2974 |
+
const at = unproject(fromScreen({ x, y }, view));
|
| 2975 |
+
setZoneGeometryDraft({
|
| 2976 |
+
id: zoneVertex.zone.id,
|
| 2977 |
+
geometry: moveZoneVertex(zoneVertex.geometry, zoneVertex, { lon: at.lon, lat: at.lat }),
|
| 2978 |
+
});
|
| 2979 |
+
return;
|
| 2980 |
+
}
|
| 2981 |
if (zoneMove && view) {
|
| 2982 |
if (Math.abs(x - zoneMove.start.x) + Math.abs(y - zoneMove.start.y) <= 2) return;
|
| 2983 |
movedRef.current = true;
|
|
|
|
| 3037 |
touchedRef.current = true;
|
| 3038 |
setView((v) => (v ? { ...v, tx: pan.tx + (x - pan.x), ty: pan.ty + (y - pan.y) } : v));
|
| 3039 |
},
|
| 3040 |
+
[drag, localPoint, zoneMove, zoneVertex, view, zoneKeyboardDraft]
|
| 3041 |
);
|
| 3042 |
|
| 3043 |
/**
|
|
|
|
| 3105 |
|
| 3106 |
const onPointerUp = useCallback(
|
| 3107 |
(e: ReactPointerEvent<SVGSVGElement>) => {
|
| 3108 |
+
// W46-T28 β the reshape lands the same way a boundary move does: the draft geometry the
|
| 3109 |
+
// pointer built is what gets persisted, and the draft is cleared either way so a failed
|
| 3110 |
+
// save cannot leave the map showing a shape the server never accepted.
|
| 3111 |
+
if (zoneVertex) {
|
| 3112 |
+
const geometry = zoneGeometryDraft?.id === zoneVertex.zone.id
|
| 3113 |
+
? zoneGeometryDraft.geometry
|
| 3114 |
+
: null;
|
| 3115 |
+
setZoneVertex(null);
|
| 3116 |
+
setZoneGeometryDraft(null);
|
| 3117 |
+
if (geometry) void persistZoneGeometry(zoneVertex.zone, geometry);
|
| 3118 |
+
if (e.currentTarget.hasPointerCapture(e.pointerId))
|
| 3119 |
+
e.currentTarget.releasePointerCapture(e.pointerId);
|
| 3120 |
+
return;
|
| 3121 |
+
}
|
| 3122 |
if (zoneMove) {
|
| 3123 |
const geometry = zoneGeometryDraft?.id === zoneMove.zone.id
|
| 3124 |
? zoneGeometryDraft.geometry
|
|
|
|
| 3130 |
e.currentTarget.releasePointerCapture(e.pointerId);
|
| 3131 |
return;
|
| 3132 |
}
|
| 3133 |
+
// β W46-T17 β a click that did not travel places a vertex. It sits above
|
| 3134 |
+
// the marquee branch so an armed drawing owns the plain click, and below
|
| 3135 |
+
// `zoneMove` so dragging an existing Zone still wins. `movedRef` is the
|
| 3136 |
+
// same "this was a drag, not a click" rule the pins use, so a pan while
|
| 3137 |
+
// armed still pans and drops nothing.
|
| 3138 |
+
// β `zoneKeyboardDraft` IS IN THIS CALLBACK'S DEPENDENCY ARRAY and must
|
| 3139 |
+
// stay there: without it, arming the tool changes no dependency, the
|
| 3140 |
+
// memoized closure keeps reading `null`, and the first clicks after
|
| 3141 |
+
// arming silently do nothing until some other dependency happens to
|
| 3142 |
+
// change. That intermittency is exactly what the bug reported.
|
| 3143 |
+
if (zoneKeyboardDraft && view && !drag && !movedRef.current) {
|
| 3144 |
+
addZoneDraftVertex(localPoint(e.clientX, e.clientY));
|
| 3145 |
+
panRef.current = null;
|
| 3146 |
+
if (e.currentTarget.hasPointerCapture(e.pointerId))
|
| 3147 |
+
e.currentTarget.releasePointerCapture(e.pointerId);
|
| 3148 |
+
return;
|
| 3149 |
+
}
|
| 3150 |
if (drag && view) {
|
| 3151 |
// A gesture smaller than a few px is a mis-click, not a selection β
|
| 3152 |
// clearing the user's set on a stray shift-click would be its own bug.
|
|
|
|
| 3203 |
if (e.currentTarget.hasPointerCapture(e.pointerId))
|
| 3204 |
e.currentTarget.releasePointerCapture(e.pointerId);
|
| 3205 |
},
|
| 3206 |
+
[drag, view, points, onSelectPids, zoneMove, zoneVertex, zoneGeometryDraft, persistZoneGeometry,
|
| 3207 |
+
zoneDrawShape, zoneEditorOpen, zoneKeyboardDraft, addZoneDraftVertex, localPoint]
|
| 3208 |
);
|
| 3209 |
|
| 3210 |
/**
|
|
|
|
| 3395 |
onToggle={(route) => void toggleNamedRoute(route)}
|
| 3396 |
onActiveRouteChange={setActiveRouteId}
|
| 3397 |
onOpenRecord={onOpen}
|
| 3398 |
+
stopLabels={routeStopLabels}
|
| 3399 |
+
stopCoords={routeStopCoords}
|
| 3400 |
onCreate={createNamedRoute}
|
| 3401 |
onMoveToOrder={moveNamedRouteStop}
|
| 3402 |
onUpdate={updateNamedRoute}
|
|
|
|
| 3490 |
))}
|
| 3491 |
</div>
|
| 3492 |
<button type="button" className="cg-btn cg-btn--primary" onClick={beginNewZone}>New Zone</button>
|
| 3493 |
+
{/* β W46-T28 β `zoneErr` USED TO RENDER IN THE EDITOR PANEL ONLY, and half the
|
| 3494 |
+
things that set it happen with the editor closed: `persistZoneGeometry` fires
|
| 3495 |
+
from a boundary drag and now from a vertex drag, both of which happen right
|
| 3496 |
+
here on the map with this list open. A rejected reshape would have failed in
|
| 3497 |
+
silence, the shape snapping back with no reason given. Standing rule 1: a
|
| 3498 |
+
refusal is reported, never silently enforced. */}
|
| 3499 |
+
{zoneErr && <span className="cg-cal-nodate" role="status">{zoneErr}</span>}
|
| 3500 |
</div>
|
| 3501 |
</aside>
|
| 3502 |
)}
|
|
|
|
| 3516 |
<button type="button" aria-pressed={zoneDrawShape === "circle"}
|
| 3517 |
onClick={() => setZoneDrawShape("circle")}>Circle</button>
|
| 3518 |
</div>
|
| 3519 |
+
<span>Choose a shape, then drag on the map, or draw it by clicking.</span>
|
| 3520 |
{!zoneKeyboardDraft ? (
|
| 3521 |
+
<button type="button" className="cg-link-btn cg-zone-draw-btn" onClick={startKeyboardZoneDrawing}>
|
| 3522 |
+
<DrawZoneIcon />
|
| 3523 |
+
Draw by clicking
|
| 3524 |
</button>
|
| 3525 |
) : (
|
| 3526 |
<>
|
| 3527 |
+
{/* ββ W46-T28 β "FINISH SHAPE" IS THE MISSING CONTROL, not a convenience.
|
| 3528 |
+
Pressing Enter only commits the outline while the MAP holds focus, and
|
| 3529 |
+
naming the Zone moves focus into the input beside this. Without a button
|
| 3530 |
+
in the panel, the only ending on offer was "Stop drawing", which throws
|
| 3531 |
+
the points away, so a drawn shape could never reach the Save button. */}
|
| 3532 |
+
<div className="cg-zone-draw-actions">
|
| 3533 |
+
<button type="button" className="cg-link-btn cg-zone-draw-btn is-armed"
|
| 3534 |
+
onClick={() => { finishZoneDraft(); }}>
|
| 3535 |
+
<DrawZoneIcon />
|
| 3536 |
+
Finish shape
|
| 3537 |
+
</button>
|
| 3538 |
+
<button type="button" className="cg-link-btn cg-zone-draw-btn"
|
| 3539 |
+
onClick={() => { setZoneKeyboardDraft(null); setZoneErr(null); }}>
|
| 3540 |
+
Stop drawing
|
| 3541 |
+
</button>
|
| 3542 |
+
</div>
|
| 3543 |
<span role="status" aria-live="polite">
|
| 3544 |
{zoneKeyboardDraft.shape === "polygon"
|
| 3545 |
+
? `${zoneKeyboardDraft.points.length} ${zoneKeyboardDraft.points.length === 1 ? "vertex" : "vertices"}. Click the map to add one, then choose Finish shape, or press Enter on the map.`
|
| 3546 |
: zoneKeyboardDraft.center
|
| 3547 |
+
? "Center placed. Click its edge, then choose Finish shape."
|
| 3548 |
+
: "Click the map to place the circle center, then click its edge."}
|
| 3549 |
</span>
|
| 3550 |
</>
|
| 3551 |
)}
|
|
|
|
| 3577 |
{ZONE_COLOR_CHOICES.map((choice) => <option key={choice.value} value={choice.value}>{choice.label}</option>)}
|
| 3578 |
</select>
|
| 3579 |
</label>
|
| 3580 |
+
{/* ββ W46-T28 β A MISSING NAME OR BOUNDARY NO LONGER DISABLES THIS BUTTON, and
|
| 3581 |
+
that is the point rather than a loosening. A disabled control cannot say why it
|
| 3582 |
+
is disabled, so the owner's "it won't even let me save" arrived with no reason
|
| 3583 |
+
on screen at all. `saveZone` already has the message for both cases ("Name a
|
| 3584 |
+
Zone and draw its boundary on the map.") and `zoneErr` renders at the foot of
|
| 3585 |
+
this panel, so letting the click through turns a silent refusal into a stated
|
| 3586 |
+
one. Permission and in-flight state still disable it: those are not the user's
|
| 3587 |
+
mistake to correct. */}
|
| 3588 |
<button
|
| 3589 |
type="button"
|
| 3590 |
className="cg-btn cg-btn--primary"
|
| 3591 |
+
disabled={zoneBusy || (normalizedCustomerZones && !!zoneEditor && !zoneEditor.permission?.canEdit)}
|
| 3592 |
+
onClick={() => {
|
| 3593 |
+
// An outline still being drawn is committed first, and its geometry handed
|
| 3594 |
+
// straight down: state set in this tick is not readable from `saveZone`.
|
| 3595 |
+
if (zoneKeyboardDraft) {
|
| 3596 |
+
const pending = finishZoneDraft();
|
| 3597 |
+
// `finishZoneDraft` has already put the real reason in `zoneErr`. Falling
|
| 3598 |
+
// through would overwrite it with a vaguer one.
|
| 3599 |
+
if (!pending) return;
|
| 3600 |
+
void saveZone(zoneEditor || undefined, pending);
|
| 3601 |
+
return;
|
| 3602 |
+
}
|
| 3603 |
+
void saveZone(zoneEditor || undefined);
|
| 3604 |
+
}}
|
| 3605 |
+
title={drawnZoneGeometry || zoneKeyboardDraft
|
| 3606 |
? (zoneEditor ? "Replace this Zone boundary with the drawn shape" : "Save the drawn Zone")
|
| 3607 |
: zoneEditor ? "Save Zone details" : "Draw a boundary before saving"}
|
| 3608 |
>
|
|
|
|
| 3642 |
tabIndex={0}
|
| 3643 |
role="group"
|
| 3644 |
aria-label={zoneKeyboardDraft
|
| 3645 |
+
? `Zone ${zoneKeyboardDraft.shape} drawing canvas. Click the map to add points, then press Enter to finish.`
|
| 3646 |
: "Map canvas. Arrow keys pan, plus and minus zoom, square brackets rotate, zero fits to data and faces north."}
|
| 3647 |
onKeyDown={onFrameKeyDown}
|
| 3648 |
onPointerDown={() => { if (!routePanelOpen) signal(NAV_MINIMIZE_EVENT); }}
|
|
|
|
| 3660 |
onPointerCancel={onPointerUp}
|
| 3661 |
>
|
| 3662 |
<rect className="cg-map-water" x={0} y={0} width={VIEW_W} height={VIEW_H} />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3663 |
<g transform={tf}>
|
| 3664 |
{/* --- W37-T35: the raster basemap, UNDER everything, inside the same transform.
|
| 3665 |
β AND THE VENDORED GEOMETRY BELOW IS HIDDEN WHILE IT PAINTS. Drawing a
|
|
|
|
| 3748 |
event.preventDefault(); void persistZoneGeometry(ring.zone, translateZoneGeometry(ring.geometry, delta));
|
| 3749 |
}}
|
| 3750 |
onPointerDown={(event) => {
|
| 3751 |
+
// W46-T17 β an armed drawing owns the pointer; dragging a saved
|
| 3752 |
+
// boundary would otherwise eat the click meant for a vertex.
|
| 3753 |
+
if (event.button !== 0 || !view || zoneKeyboardDraft) return;
|
| 3754 |
event.stopPropagation();
|
| 3755 |
movedRef.current = false;
|
| 3756 |
const svg = event.currentTarget.ownerSVGElement;
|
|
|
|
| 3762 |
});
|
| 3763 |
}}
|
| 3764 |
onClick={(event) => {
|
| 3765 |
+
if (zoneKeyboardDraft) return;
|
| 3766 |
event.stopPropagation();
|
| 3767 |
if (movedRef.current) {
|
| 3768 |
movedRef.current = false;
|
|
|
|
| 3779 |
<circle key={zone.id} className="cg-map-zone" cx={center.x} cy={center.y} r={radius}
|
| 3780 |
fill={zone.color} stroke={zone.color} strokeWidth={hair(1.4)} tabIndex={0} role="button"
|
| 3781 |
aria-label={`${zone.name} Circle Zone. Enter selects records; arrow keys move the boundary.`}
|
| 3782 |
+
onPointerDown={(event) => { if (event.button !== 0 || !view || zoneKeyboardDraft) return; event.stopPropagation(); movedRef.current = false; event.currentTarget.ownerSVGElement?.setPointerCapture(event.pointerId); setZoneMove({ zone, geometry, start: localPoint(event.clientX, event.clientY) }); }}
|
| 3783 |
+
onClick={(event) => { if (zoneKeyboardDraft) return; event.stopPropagation(); if (movedRef.current) { movedRef.current = false; return; } onSelectPids(zone.memberships, "replace"); }}
|
| 3784 |
onKeyDown={(event) => { if (event.key === "Enter" || event.key === " ") { event.preventDefault(); onSelectPids(zone.memberships, "replace"); return; } const delta = event.key === "ArrowLeft" ? { lon: -0.0005, lat: 0 } : event.key === "ArrowRight" ? { lon: 0.0005, lat: 0 } : event.key === "ArrowUp" ? { lon: 0, lat: 0.0005 } : event.key === "ArrowDown" ? { lon: 0, lat: -0.0005 } : null; if (delta) { event.preventDefault(); void persistZoneGeometry(zone, translateZoneGeometry(geometry, delta)); } }}>
|
| 3785 |
<title>{`${zone.name}: circle radius ${Math.round(geometry.radiusMeters)} metres`}</title>
|
| 3786 |
</circle>
|
| 3787 |
))}
|
| 3788 |
+
{/* ββ W46-T28 β THE VERTEX HANDLES. Owner instruction 16: *"the zone vertices
|
| 3789 |
+
should be a dot that is draggable so I can minimize or expand a zone."* Dragging
|
| 3790 |
+
the boundary itself already MOVED a Zone; nothing could change its SHAPE.
|
| 3791 |
+
β THEY MOUNT HERE, INSIDE `<g transform={tf}>`, AND NOT IN THE DRAFT GROUP.
|
| 3792 |
+
`.cg-zone-keyboard-draft` is `pointer-events: none` (map-panels.css, W46-T17) so
|
| 3793 |
+
the in-progress outline cannot swallow the clicks that extend it. A dot placed in
|
| 3794 |
+
there would be equally unhittable, which is the whole feature. Living inside the
|
| 3795 |
+
camera transform also means a handle stays on its corner through every pan,
|
| 3796 |
+
zoom and rotation for free.
|
| 3797 |
+
β AND THEY ARE HIDDEN WHILE DRAWING IS ARMED. T17 made a plain click add a
|
| 3798 |
+
vertex to the NEW shape; leaving old handles on top of that would eat those
|
| 3799 |
+
clicks and re-break the bug that ticket just fixed.
|
| 3800 |
+
Only polygons: a circle has no vertices, and resizing one is its own control. */}
|
| 3801 |
+
{!zoneKeyboardDraft && zonePolygons.flatMap((ring) => (
|
| 3802 |
+
normalizedCustomerZones && !ring.zone.permission?.canEdit ? [] :
|
| 3803 |
+
// ββ AND A LASSO-DRAWN BOUNDARY GETS NO HANDLES, DELIBERATELY. A rectangle
|
| 3804 |
+
// marquee stores 4 corners, a clicked outline stores what the user clicked, but
|
| 3805 |
+
// the lasso stores EVERY SAMPLED POINTERMOVE: hundreds of coordinates. A dot on
|
| 3806 |
+
// each would be a solid ring of dots hiding the very fill this ticket exists to
|
| 3807 |
+
// make legible, and hundreds of tab stops rebuilt on every pointermove. A corner
|
| 3808 |
+
// you cannot tell apart from its neighbour is not a handle anyway.
|
| 3809 |
+
// β REPORTED, NOT SILENT (standing rule 1): the limit is named here and in the
|
| 3810 |
+
// ticket handoff, and the whole-boundary drag and the arrow keys still reach
|
| 3811 |
+
// those Zones. Lifting it needs vertex simplification, which is its own ticket.
|
| 3812 |
+
ring.handles.length > ZONE_VERTEX_HANDLE_MAX ? [] :
|
| 3813 |
+
ring.handles.map((point) => (
|
| 3814 |
+
<circle
|
| 3815 |
+
key={`${ring.key}:v${point.vertexIndex}`}
|
| 3816 |
+
className="cg-map-zone-vertex"
|
| 3817 |
+
cx={point.x}
|
| 3818 |
+
cy={point.y}
|
| 3819 |
+
r={hair(5)}
|
| 3820 |
+
fill={ring.zone.color}
|
| 3821 |
+
stroke={LP_INK}
|
| 3822 |
+
strokeWidth={hair(1.4)}
|
| 3823 |
+
tabIndex={0}
|
| 3824 |
+
role="button"
|
| 3825 |
+
aria-label={`${ring.zone.name} boundary point ${point.vertexIndex + 1}. Drag it, or use the arrow keys, to reshape the Zone.`}
|
| 3826 |
+
onPointerDown={(event) => {
|
| 3827 |
+
if (event.button !== 0 || !view) return;
|
| 3828 |
+
// The boundary under this dot has its own drag. Stopping here is what makes
|
| 3829 |
+
// the handle the more specific target rather than a decoration on top of it.
|
| 3830 |
+
event.stopPropagation();
|
| 3831 |
+
movedRef.current = false;
|
| 3832 |
+
event.currentTarget.ownerSVGElement?.setPointerCapture(event.pointerId);
|
| 3833 |
+
setZoneVertex({
|
| 3834 |
+
zone: ring.zone,
|
| 3835 |
+
geometry: ring.geometry,
|
| 3836 |
+
polygonIndex: ring.polygonIndex,
|
| 3837 |
+
ringIndex: ring.ringIndex,
|
| 3838 |
+
vertexIndex: point.vertexIndex,
|
| 3839 |
+
});
|
| 3840 |
+
}}
|
| 3841 |
+
onClick={(event) => { event.stopPropagation(); movedRef.current = false; }}
|
| 3842 |
+
onKeyDown={(event) => {
|
| 3843 |
+
const delta = event.key === "ArrowLeft" ? { lon: -0.0005, lat: 0 }
|
| 3844 |
+
: event.key === "ArrowRight" ? { lon: 0.0005, lat: 0 }
|
| 3845 |
+
: event.key === "ArrowUp" ? { lon: 0, lat: 0.0005 }
|
| 3846 |
+
: event.key === "ArrowDown" ? { lon: 0, lat: -0.0005 } : null;
|
| 3847 |
+
if (!delta || !view) return;
|
| 3848 |
+
event.preventDefault();
|
| 3849 |
+
event.stopPropagation();
|
| 3850 |
+
const source = unproject(fromScreen(point, view));
|
| 3851 |
+
void persistZoneGeometry(ring.zone, moveZoneVertex(ring.geometry, {
|
| 3852 |
+
polygonIndex: ring.polygonIndex,
|
| 3853 |
+
ringIndex: ring.ringIndex,
|
| 3854 |
+
vertexIndex: point.vertexIndex,
|
| 3855 |
+
}, { lon: source.lon + delta.lon, lat: source.lat + delta.lat }));
|
| 3856 |
+
}}
|
| 3857 |
+
>
|
| 3858 |
+
<title>{`${ring.zone.name}: drag this point to reshape the Zone`}</title>
|
| 3859 |
+
</circle>
|
| 3860 |
+
))
|
| 3861 |
+
))}
|
| 3862 |
{/* The planned path, UNDER the pins so it never hides a stop. Inside
|
| 3863 |
the zoomed group, so it pans and scales with the geography; the
|
| 3864 |
stroke is pre-divided by k like every other line here. */}
|
|
|
|
| 3922 |
strokeWidth={hair(on ? 2 : 1)}
|
| 3923 |
role="button"
|
| 3924 |
tabIndex={0}
|
| 3925 |
+
// ββ NO `aria-pressed` HERE, AND THE ABSENCE IS THE FIX (W46-T14 / D-419).
|
| 3926 |
+
// Do not "restore" it in an a11y sweep. `aria-pressed` declares a TOGGLE
|
| 3927 |
+
// button, whose default activation flips a state. After R10 (W38-T09) a
|
| 3928 |
+
// plain click on a pin OPENS THE RECORD; only a modifier click or Space
|
| 3929 |
+
// moves the selection. So the pressed state, while it tracked selection
|
| 3930 |
+
// correctly, told a screen reader the wrong thing about the one gesture it
|
| 3931 |
+
// would try. The selected/unselected fact is not lost: `pinAriaLabel` below
|
| 3932 |
+
// states it in words, along with both gestures, which is the channel that
|
| 3933 |
+
// matches what the control actually does.
|
| 3934 |
// β THE ACCESSIBLE NAME IS THE ONLY CHANNEL A NON-SIGHTED USER HAS FOR A PIN'S
|
| 3935 |
// gesture: a `<circle>` carries no tooltip, no hover card and no glyph, and the
|
| 3936 |
// hint bar above is the SIGHTED half of this same disclosure. It said "Click to
|
|
|
|
| 3942 |
onFocus={() => setHoverPid(p.pid)}
|
| 3943 |
onBlur={() => setHoverPid((h) => (h === p.pid ? null : h))}
|
| 3944 |
onClick={(e) => {
|
| 3945 |
+
// β W46-T17 β while Zone drawing is armed the map is a drawing
|
| 3946 |
+
// surface, so a click that lands on a pin places a vertex and does
|
| 3947 |
+
// NOT open a drawer over the shape being drawn. The SVG's own
|
| 3948 |
+
// `onPointerUp` still sees the gesture and adds the point.
|
| 3949 |
+
if (zoneKeyboardDraft) return;
|
| 3950 |
// β NO LONGER MERELY "a finished pan is not a click" (R10): a drag that ends
|
| 3951 |
// on a pin would now OPEN a drawer, not just move the selection. See the
|
| 3952 |
// `pinSelect` doc comment above before touching this line.
|
|
|
|
| 4106 |
points={lassoPts.map((p) => `${p.x.toFixed(1)},${p.y.toFixed(1)}`).join(" ")}
|
| 4107 |
/>
|
| 4108 |
)}
|
| 4109 |
+
{/* ββ W46-T17. THIS GROUP IS LAST ON PURPOSE, AND THAT IS THE WHOLE
|
| 4110 |
+
INVISIBLE-ZONE BUG. It used to sit directly under the water rect,
|
| 4111 |
+
ABOVE `<g transform={tf}>` in document order. SVG has no z-index:
|
| 4112 |
+
it paints in document order, so the opaque tile bed and every
|
| 4113 |
+
raster tile in that group painted straight OVER the draft. The
|
| 4114 |
+
draft was rendering correctly and being buried, which is why the
|
| 4115 |
+
vertex count went up while the screen showed nothing. Moved here,
|
| 4116 |
+
after the marquee, it is on top of everything.
|
| 4117 |
+
β It is still OUTSIDE the transform, exactly as before, because
|
| 4118 |
+
`cursor`, `points` and `center` are SCREEN coordinates; putting it
|
| 4119 |
+
inside `tf` would double-apply the camera. --- */}
|
| 4120 |
+
{zoneKeyboardDraft && (
|
| 4121 |
+
<g className="cg-zone-keyboard-draft" aria-hidden="true">
|
| 4122 |
+
{zoneKeyboardDraft.shape === "polygon" && zoneKeyboardDraft.points.length > 0 && (
|
| 4123 |
+
<polyline
|
| 4124 |
+
points={[...zoneKeyboardDraft.points, zoneKeyboardDraft.cursor]
|
| 4125 |
+
.map((point) => `${point.x},${point.y}`).join(" ")}
|
| 4126 |
+
fill="none" stroke={zoneColor} strokeWidth="3" strokeDasharray="6 4"
|
| 4127 |
+
/>
|
| 4128 |
+
)}
|
| 4129 |
+
{zoneKeyboardDraft.shape === "circle" && zoneKeyboardDraft.center && (
|
| 4130 |
+
<circle
|
| 4131 |
+
cx={zoneKeyboardDraft.center.x} cy={zoneKeyboardDraft.center.y}
|
| 4132 |
+
r={Math.hypot(
|
| 4133 |
+
zoneKeyboardDraft.cursor.x - zoneKeyboardDraft.center.x,
|
| 4134 |
+
zoneKeyboardDraft.cursor.y - zoneKeyboardDraft.center.y
|
| 4135 |
+
)}
|
| 4136 |
+
fill={zoneColor} fillOpacity={LP_ZONE_FILL_OPACITY} stroke={zoneColor}
|
| 4137 |
+
strokeWidth="3" strokeDasharray="6 4"
|
| 4138 |
+
/>
|
| 4139 |
+
)}
|
| 4140 |
+
{zoneKeyboardDraft.points.map((point, index) => (
|
| 4141 |
+
<circle key={`${point.x}:${point.y}:${index}`} cx={point.x} cy={point.y} r="4" fill={zoneColor} />
|
| 4142 |
+
))}
|
| 4143 |
+
<circle cx={zoneKeyboardDraft.cursor.x} cy={zoneKeyboardDraft.cursor.y} r="6" fill={zoneColor} stroke="white" strokeWidth="2" />
|
| 4144 |
+
</g>
|
| 4145 |
+
)}
|
| 4146 |
</svg>
|
| 4147 |
|
| 4148 |
{/* --- I18 β the camera controls. Zoom in / zoom out / fit to data, the
|
web/src/customer-grid/RouteNav.tsx
CHANGED
|
@@ -1,5 +1,12 @@
|
|
| 1 |
-
import { useEffect, useMemo, useState } from "react";
|
|
|
|
| 2 |
import { folderPath, levelAt, resolveStoredPath } from "./dataPath";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import type { NormalizedRouteMapLink } from "./routeLinks";
|
| 4 |
import { submitRouteStopMove } from "./routeStopMove";
|
| 5 |
import { boundedGoogleMapsUrl } from "./routeZoneTypes";
|
|
@@ -8,18 +15,93 @@ import type {
|
|
| 8 |
RouteAssignee, RouteDeliveryDto, RouteDeliveryRequest,
|
| 9 |
} from "./routeZoneTypes";
|
| 10 |
import "../styles/wave42/route-nav.css";
|
|
|
|
| 11 |
|
| 12 |
type Result = Promise<string | null>;
|
| 13 |
|
| 14 |
type RouteAction = "rename" | "duplicate" | "star" | "share" | "delete";
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
function mayRouteAction(route: MapRouteDto, action: RouteAction): boolean {
|
| 17 |
return route.compatibility !== "legacy-route-order" && route.capabilities?.[action] === true;
|
| 18 |
}
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
export function RouteNav({ routes, folders, selectedIds, activeRouteId, sources, storageKey,
|
| 21 |
createdRoute, onCreatedDismiss, onToggle, onActiveRouteChange, onOpenRecord, onCreate,
|
| 22 |
-
onMoveToOrder, onUpdate, onDuplicate, onDelete, onShare, onRouteMove, onRouteReorder,
|
|
|
|
| 23 |
onFolderCreate, onFolderUpdate, onFolderDelete, onFolderReorder, filteredRecordCount,
|
| 24 |
onSelectFiltered, onCreateStart, mapLinks, mapLinkRefusal, deliveries, onSchedule,
|
| 25 |
onDeleteDelivery, assignees, routeToday, assigneeError }: {
|
|
@@ -34,6 +116,19 @@ export function RouteNav({ routes, folders, selectedIds, activeRouteId, sources,
|
|
| 34 |
onToggle: (route: MapRouteDto) => void;
|
| 35 |
onActiveRouteChange: (routeId: string | null) => void;
|
| 36 |
onOpenRecord: (pid: number) => void;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
onCreate: (name: string, source: MapRouteSource) => Result;
|
| 38 |
onMoveToOrder: (route: MapRouteDto, customerPid: number, order: number) => Result;
|
| 39 |
onUpdate: (route: MapRouteDto, patch: MapRouteUpdate) => Result;
|
|
@@ -71,7 +166,7 @@ export function RouteNav({ routes, folders, selectedIds, activeRouteId, sources,
|
|
| 71 |
const [error, setError] = useState<string | null>(null);
|
| 72 |
const [orderDrafts, setOrderDrafts] = useState<Record<number, string>>({});
|
| 73 |
const [orderErrors, setOrderErrors] = useState<Record<number, string>>({});
|
| 74 |
-
const [
|
| 75 |
const [editMapsUrl, setEditMapsUrl] = useState("");
|
| 76 |
const [assignmentAssignee, setAssignmentAssignee] = useState("");
|
| 77 |
const [assignmentDate, setAssignmentDate] = useState("");
|
|
@@ -83,7 +178,6 @@ export function RouteNav({ routes, folders, selectedIds, activeRouteId, sources,
|
|
| 83 |
const [renameId, setRenameId] = useState<string | null>(null);
|
| 84 |
const [renameDraft, setRenameDraft] = useState("");
|
| 85 |
const [busy, setBusy] = useState(false);
|
| 86 |
-
const [deliveryRecipient, setDeliveryRecipient] = useState("");
|
| 87 |
const [deliveryMapsPerLink, setDeliveryMapsPerLink] = useState(10);
|
| 88 |
const [deliveryNotice, setDeliveryNotice] = useState<string | null>(null);
|
| 89 |
const [deliveryError, setDeliveryError] = useState<string | null>(null);
|
|
@@ -93,6 +187,38 @@ export function RouteNav({ routes, folders, selectedIds, activeRouteId, sources,
|
|
| 93 |
const route = activeRouteId ? routes.find((item) => item.id === activeRouteId) : null;
|
| 94 |
const source = sources.find((item) => item.id === sourceId) || sources[0];
|
| 95 |
const mapsUrl = boundedGoogleMapsUrl(route?.mapsUrl);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
const assigneeNames = useMemo(
|
| 97 |
() => new Set((assignees || []).map((person) => person.username)),
|
| 98 |
[assignees]
|
|
@@ -128,7 +254,7 @@ export function RouteNav({ routes, folders, selectedIds, activeRouteId, sources,
|
|
| 128 |
// eslint-disable-next-line react-hooks/exhaustive-deps
|
| 129 |
}, [at, validAt]);
|
| 130 |
useEffect(() => {
|
| 131 |
-
|
| 132 |
setEditMapsUrl(route?.mapsUrl || "");
|
| 133 |
setOrderDrafts({});
|
| 134 |
setOrderErrors({});
|
|
@@ -152,21 +278,24 @@ export function RouteNav({ routes, folders, selectedIds, activeRouteId, sources,
|
|
| 152 |
setMapCopyNotice(null);
|
| 153 |
setMapCopyError(null);
|
| 154 |
const clipboard = typeof navigator === "undefined" ? null : navigator.clipboard;
|
| 155 |
-
if (!
|
| 156 |
setMapCopyError("Maps links could not be copied in this browser.");
|
| 157 |
return;
|
| 158 |
}
|
| 159 |
-
void clipboard.writeText(
|
| 160 |
.then(() => setMapCopyNotice(
|
| 161 |
-
`${
|
| 162 |
))
|
| 163 |
.catch(() => setMapCopyError("Maps links could not be copied. Open each link instead."));
|
| 164 |
};
|
| 165 |
|
| 166 |
const scheduleDelivery = (target: MapRouteDto) => {
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
| 168 |
if (!recipient) {
|
| 169 |
-
setDeliveryError("
|
| 170 |
return;
|
| 171 |
}
|
| 172 |
setDeliveryBusy(true);
|
|
@@ -250,6 +379,45 @@ export function RouteNav({ routes, folders, selectedIds, activeRouteId, sources,
|
|
| 250 |
});
|
| 251 |
}).finally(() => setBusy(false));
|
| 252 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
const swap = (ids: string[], id: string, delta: number) => {
|
| 254 |
const index = ids.indexOf(id);
|
| 255 |
const other = index + delta;
|
|
@@ -259,33 +427,460 @@ export function RouteNav({ routes, folders, selectedIds, activeRouteId, sources,
|
|
| 259 |
return next;
|
| 260 |
};
|
| 261 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
if (route) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
const canEdit = route.permission.canEdit && route.compatibility !== "legacy-route-order";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
return (
|
| 265 |
<section className="cg-w44-route-nav" aria-label={`${route.name} route`}>
|
| 266 |
<button type="button" className="cg-w44-route-back" onClick={() => onActiveRouteChange(null)}>
|
| 267 |
Back to routes
|
| 268 |
</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
<div className="cg-w44-route-title">
|
| 270 |
<i style={{ backgroundColor: route.color }} aria-hidden="true" />
|
| 271 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
</div>
|
| 273 |
<p className="cg-w44-route-meta">
|
| 274 |
{route.shared ? `Shared by ${route.owner || "another user"}` : route.sharedOut ? "Shared with others" : "Private"}
|
| 275 |
</p>
|
| 276 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 277 |
<ol className="cg-w44-route-stops">
|
| 278 |
-
{
|
| 279 |
-
<li key={pid}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
<button type="button" className="cg-w44-route-stop-open"
|
| 281 |
-
aria-label={`Open stop ${index + 1} record`}
|
| 282 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
</button>
|
| 284 |
{canEdit && (
|
| 285 |
<span className="cg-w44-route-stop-actions">
|
| 286 |
<button type="button" className="cg-w44-route-step" disabled={busy || index === 0}
|
| 287 |
aria-label={`Move stop ${index + 1} earlier`}
|
| 288 |
-
title="Move earlier" onClick={() => commitStopMove(
|
| 289 |
<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M10 3 5 8l5 5" /></svg>
|
| 290 |
</button>
|
| 291 |
<label className="cg-w44-route-position"><span>Position</span>
|
|
@@ -307,7 +902,7 @@ export function RouteNav({ routes, folders, selectedIds, activeRouteId, sources,
|
|
| 307 |
onKeyDown={(event) => {
|
| 308 |
if (event.key === "Enter") {
|
| 309 |
event.preventDefault();
|
| 310 |
-
commitStopMove(
|
| 311 |
} else if (event.key === "Escape") {
|
| 312 |
event.preventDefault();
|
| 313 |
setOrderDrafts((current) => {
|
|
@@ -324,15 +919,20 @@ export function RouteNav({ routes, folders, selectedIds, activeRouteId, sources,
|
|
| 324 |
}} />
|
| 325 |
</label>
|
| 326 |
<button type="button" className="cg-w44-route-position-apply" disabled={busy}
|
| 327 |
-
onClick={() => commitStopMove(
|
| 328 |
Move
|
| 329 |
</button>
|
| 330 |
<button type="button" className="cg-w44-route-step"
|
| 331 |
-
disabled={busy || index ===
|
| 332 |
aria-label={`Move stop ${index + 1} later`}
|
| 333 |
-
title="Move later" onClick={() => commitStopMove(
|
| 334 |
<svg viewBox="0 0 16 16" aria-hidden="true"><path d="m6 3 5 5-5 5" /></svg>
|
| 335 |
</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 336 |
</span>
|
| 337 |
)}
|
| 338 |
{orderErrors[pid] && <span id={`cg-route-order-error-${pid}`}
|
|
@@ -348,11 +948,11 @@ export function RouteNav({ routes, folders, selectedIds, activeRouteId, sources,
|
|
| 348 |
<h3 id="cg-route-map-links-title">Google Maps</h3>
|
| 349 |
<p>Current ordered Route stops, split into links of at most 10 stops.</p>
|
| 350 |
</div>
|
| 351 |
-
{
|
| 352 |
-
<span className="cg-w44-route-warning" role="alert">{
|
| 353 |
-
) :
|
| 354 |
<ol>
|
| 355 |
-
{
|
| 356 |
<li key={`${link.index}:${link.start}:${link.end}`}>
|
| 357 |
<a href={link.url} target="_blank" rel="noopener noreferrer">
|
| 358 |
Link {link.index} - Stops {link.start + 1} to {link.end}
|
|
@@ -370,18 +970,80 @@ export function RouteNav({ routes, folders, selectedIds, activeRouteId, sources,
|
|
| 370 |
{mapCopyNotice && <span className="cg-w44-route-empty" role="status">{mapCopyNotice}</span>}
|
| 371 |
{mapCopyError && <span className="cg-w44-route-warning" role="alert">{mapCopyError}</span>}
|
| 372 |
</section>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 373 |
{canEdit ? (
|
| 374 |
<div className="cg-w44-route-edit" aria-label="Edit Route">
|
| 375 |
-
<label className="cg-w44-route-label">Route name
|
| 376 |
-
<input className="cg-input" value={editName} maxLength={120} onChange={(event) => setEditName(event.target.value)} />
|
| 377 |
-
</label>
|
| 378 |
<label className="cg-w44-route-label">Google Maps URL
|
| 379 |
<input className="cg-input" type="url" value={editMapsUrl} maxLength={2048}
|
| 380 |
placeholder="https://www.google.com/maps/..." onChange={(event) => setEditMapsUrl(event.target.value)} />
|
| 381 |
</label>
|
| 382 |
<div className="cg-form-actions">
|
| 383 |
-
<button type="button" className="cg-btn cg-btn--primary" disabled={busy
|
| 384 |
-
onClick={() => finish(onUpdate(route, {
|
| 385 |
Save Route
|
| 386 |
</button>
|
| 387 |
<button type="button" className="cg-btn" disabled={busy} onClick={() => finish(onShare(route))}>Share</button>
|
|
@@ -401,7 +1063,8 @@ export function RouteNav({ routes, folders, selectedIds, activeRouteId, sources,
|
|
| 401 |
)}
|
| 402 |
</div>
|
| 403 |
) : <p className="cg-w44-route-empty">{route.compatibility === "legacy-route-order"
|
| 404 |
-
? "
|
|
|
|
| 405 |
{canEdit && (
|
| 406 |
<section className="cg-w44-route-delivery cg-w45-route-assignment"
|
| 407 |
aria-labelledby="cg-route-assignment-title">
|
|
@@ -460,12 +1123,8 @@ export function RouteNav({ routes, folders, selectedIds, activeRouteId, sources,
|
|
| 460 |
<section className="cg-w44-route-delivery" aria-labelledby="cg-route-delivery-title">
|
| 461 |
<div>
|
| 462 |
<h3 id="cg-route-delivery-title">Daily delivery</h3>
|
| 463 |
-
<p>Freeze this Route now and send it to Inbox each day at 08:00 ({deliveryTimezone}).</p>
|
| 464 |
</div>
|
| 465 |
-
<label className="cg-w44-route-label">Inbox recipient
|
| 466 |
-
<input className="cg-input" value={deliveryRecipient} autoComplete="username"
|
| 467 |
-
placeholder="Account username" onChange={(event) => setDeliveryRecipient(event.target.value)} />
|
| 468 |
-
</label>
|
| 469 |
<label className="cg-w44-route-label">Stops per Maps link
|
| 470 |
<input className="cg-input" type="number" min={2} max={10} value={deliveryMapsPerLink}
|
| 471 |
onChange={(event) => setDeliveryMapsPerLink(
|
|
@@ -473,13 +1132,23 @@ export function RouteNav({ routes, folders, selectedIds, activeRouteId, sources,
|
|
| 473 |
)} />
|
| 474 |
</label>
|
| 475 |
<button type="button" className="cg-btn cg-btn--primary"
|
| 476 |
-
disabled={deliveryBusy ||
|
| 477 |
onClick={() => scheduleDelivery(route)}>
|
| 478 |
{deliveryBusy ? "Scheduling" : "Schedule delivery"}
|
| 479 |
</button>
|
| 480 |
-
{
|
| 481 |
<span className="cg-w44-route-empty">Add at least two stops before scheduling.</span>
|
| 482 |
)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 483 |
<div className="cg-w44-route-delivery-list" aria-label="Existing Route deliveries">
|
| 484 |
{deliveries === null ? (
|
| 485 |
<span className="cg-w44-route-empty">Loading deliveries.</span>
|
|
@@ -612,16 +1281,10 @@ export function RouteNav({ routes, folders, selectedIds, activeRouteId, sources,
|
|
| 612 |
<button type="button" className="cg-w44-route-toggle" aria-pressed={selectedIds.has(item.id)}
|
| 613 |
aria-label={`${selectedIds.has(item.id) ? "Remove" : "Include"} ${item.name}`}
|
| 614 |
onClick={() => onToggle(item)}><i style={{ backgroundColor: item.color }} aria-hidden="true" /></button>
|
| 615 |
-
{
|
| 616 |
-
|
| 617 |
-
onChange={(event) => setRenameDraft(event.target.value)} />
|
| 618 |
-
<button type="button" disabled={!renameDraft.trim() || busy}
|
| 619 |
-
onClick={() => { setBusy(true); void onUpdate(item, { name: renameDraft.trim(), mapsUrl: item.mapsUrl }).then((message) => {
|
| 620 |
-
setError(message); if (!message) setRenameId(null);
|
| 621 |
-
}).finally(() => setBusy(false)); }}>Save</button>
|
| 622 |
-
</> : <button type="button" className="cg-w44-route-open" onClick={() => {
|
| 623 |
setError(null); setCreating(false); onActiveRouteChange(item.id);
|
| 624 |
-
}}>{item.number}. {item.name}</button>
|
| 625 |
{(item.shared || item.sharedOut) && <span className="cg-w44-route-share-mark">
|
| 626 |
{item.shared ? `Shared by ${item.owner || "another user"}` : "Shared"}
|
| 627 |
</span>}
|
|
@@ -629,8 +1292,6 @@ export function RouteNav({ routes, folders, selectedIds, activeRouteId, sources,
|
|
| 629 |
<button type="button" className="cg-w44-route-more" aria-label={`Actions for ${item.name}`}
|
| 630 |
aria-expanded={menuId === item.id} onClick={() => setMenuId(menuId === item.id ? null : item.id)}>...</button>
|
| 631 |
{menuId === item.id && <div className="cg-w44-route-menu" role="menu">
|
| 632 |
-
<button type="button" role="menuitem" disabled={!mayRouteAction(item, "rename")}
|
| 633 |
-
onClick={() => { setRenameId(item.id); setRenameDraft(item.name); setMenuId(null); }}>Rename</button>
|
| 634 |
<button type="button" role="menuitem" disabled={!mayRouteAction(item, "duplicate")}
|
| 635 |
onClick={() => { setMenuId(null); finish(onDuplicate(item)); }}>Duplicate</button>
|
| 636 |
<button type="button" role="menuitem" disabled={!mayRouteAction(item, "star")}
|
|
|
|
| 1 |
+
import { useEffect, useMemo, useRef, useState } from "react";
|
| 2 |
+
import { createPortal } from "react-dom";
|
| 3 |
import { folderPath, levelAt, resolveStoredPath } from "./dataPath";
|
| 4 |
+
import {
|
| 5 |
+
formatSeconds, haversineKm, isPlottable, parseRouteAnswer, previewSeconds,
|
| 6 |
+
routeCaveats, routeSaving, routeTimeLabel, routeTimeTone,
|
| 7 |
+
} from "./mapProjection";
|
| 8 |
+
import type { GeoStop, RouteAnswer } from "./mapProjection";
|
| 9 |
+
import { normalizedRouteMapLinks, routePrintStops } from "./routeLinks";
|
| 10 |
import type { NormalizedRouteMapLink } from "./routeLinks";
|
| 11 |
import { submitRouteStopMove } from "./routeStopMove";
|
| 12 |
import { boundedGoogleMapsUrl } from "./routeZoneTypes";
|
|
|
|
| 15 |
RouteAssignee, RouteDeliveryDto, RouteDeliveryRequest,
|
| 16 |
} from "./routeZoneTypes";
|
| 17 |
import "../styles/wave42/route-nav.css";
|
| 18 |
+
import "../styles/wave46/route-print.css";
|
| 19 |
|
| 20 |
type Result = Promise<string | null>;
|
| 21 |
|
| 22 |
type RouteAction = "rename" | "duplicate" | "star" | "share" | "delete";
|
| 23 |
|
| 24 |
+
/* βββββββββββββββββββββββββββββ W46-T19 / INSTRUCTION 9 / R9 / C2 βββββββββββββββββββββββββββββ
|
| 25 |
+
*
|
| 26 |
+
* The drive time at the top of the Route, the saving a reorder would win, and the number that
|
| 27 |
+
* moves while a stop is being dragged.
|
| 28 |
+
*
|
| 29 |
+
* ββ THE DEBOUNCE IS A COURTESY LIMIT, NOT A NICETY. The door behind `ROUTE_DOOR` calls a free,
|
| 30 |
+
* unauthenticated public routing service, twice per request (the order as it stands, then the
|
| 31 |
+
* order it would choose), behind a process-wide 1100 ms throttle. One settled figure therefore
|
| 32 |
+
* costs at least 2.2 s of that service's time. A drag emits dozens of events a second, so the
|
| 33 |
+
* only safe wiring is the one C2 names: arithmetic during the drag, ONE request on drop, and
|
| 34 |
+
* every earlier request cancelled the moment a new drag starts, or a slow answer lands on an
|
| 35 |
+
* order nobody is looking at any more.
|
| 36 |
+
*/
|
| 37 |
+
/* βββββββββββββββββββββββββββββ W46-T20 / INSTRUCTION 10 / R6 / C6 ββββββββββββββββββββββββ
|
| 38 |
+
*
|
| 39 |
+
* "ADD an export button for routes regardless to give to the sales team", plus R6's addition:
|
| 40 |
+
* "i also want the google map link clickable in that PDF."
|
| 41 |
+
*
|
| 42 |
+
* The export is the browser's own Save as PDF behind a print stylesheet, which is the pattern
|
| 43 |
+
* the catalog export already proves here. Set on `<html>` for the duration of one print and
|
| 44 |
+
* taken off again however the dialog ends; `styles/wave46/route-print.css` carries the
|
| 45 |
+
* isolation keyed off it.
|
| 46 |
+
*
|
| 47 |
+
* β A NAME OF ITS OWN, NEVER `cg-cat-printing`. The catalog's print block un-hides exactly
|
| 48 |
+
* `.cg-cat-print-portal` and hides every other child of `<body>`, so borrowing its class would
|
| 49 |
+
* print a blank sheet with nothing anywhere reporting a fault.
|
| 50 |
+
*/
|
| 51 |
+
const ROUTE_PRINTING_CLASS = "cg-w46-route-printing";
|
| 52 |
+
/** The honest backstop when neither `afterprint` nor the print media query reports an end. */
|
| 53 |
+
const PRINT_RELEASE_MS = 120_000;
|
| 54 |
+
|
| 55 |
+
const ROUTE_DOOR = "/api/v1/geo/route";
|
| 56 |
+
const SETTLE_DEBOUNCE_MS = 400;
|
| 57 |
+
/** Both halves of the figure must ask the same question, or the number jumps on drop by the size
|
| 58 |
+
* of a closing edge and the reorder gets blamed for it. These two travel together, into
|
| 59 |
+
* `previewSeconds` during the drag and into the request body on drop. */
|
| 60 |
+
const ROUTE_ROUND_TRIP = false;
|
| 61 |
+
const ROUTE_MODE = "driving";
|
| 62 |
+
|
| 63 |
+
/**
|
| 64 |
+
* The order a drag would leave behind: `moved` taken out and put back where `over` sits now.
|
| 65 |
+
*
|
| 66 |
+
* β PURE, AND DELIBERATELY OUTSIDE THE COMPONENT. It is the only thing the drag path computes,
|
| 67 |
+
* so keeping it here makes "the drag calls no network" a property of a function that has no
|
| 68 |
+
* closure to hide one in.
|
| 69 |
+
*/
|
| 70 |
+
function orderAfterMove(pids: number[], moved: number, over: number): number[] {
|
| 71 |
+
const from = pids.indexOf(moved);
|
| 72 |
+
const to = pids.indexOf(over);
|
| 73 |
+
if (from < 0 || to < 0 || from === to) return pids;
|
| 74 |
+
const next = [...pids];
|
| 75 |
+
next.splice(to, 0, next.splice(from, 1)[0]);
|
| 76 |
+
return next;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
function mayRouteAction(route: MapRouteDto, action: RouteAction): boolean {
|
| 80 |
return route.compatibility !== "legacy-route-order" && route.capabilities?.[action] === true;
|
| 81 |
}
|
| 82 |
|
| 83 |
+
/**
|
| 84 |
+
* W46-T26 β a stop reads as its customer, never as a bare ordinal.
|
| 85 |
+
*
|
| 86 |
+
* The order of preference is the order a person needs it in: the name they know the account by,
|
| 87 |
+
* then the address they would drive to when the account was never named, then the honest
|
| 88 |
+
* statement that the record has neither. Returning an empty string at any of those three steps
|
| 89 |
+
* would render a blank line that looks like a rendering bug rather than like missing data, and
|
| 90 |
+
* the "record N" wording is the one this app already uses for a nameless row in the map's own
|
| 91 |
+
* add-a-record search.
|
| 92 |
+
*/
|
| 93 |
+
function stopIdentity(label: { name: string; address: string } | undefined, pid: number): string {
|
| 94 |
+
const name = (label?.name || "").trim();
|
| 95 |
+
if (name) return name;
|
| 96 |
+
const address = (label?.address || "").trim();
|
| 97 |
+
if (address) return address;
|
| 98 |
+
return `Unnamed record ${pid}`;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
export function RouteNav({ routes, folders, selectedIds, activeRouteId, sources, storageKey,
|
| 102 |
createdRoute, onCreatedDismiss, onToggle, onActiveRouteChange, onOpenRecord, onCreate,
|
| 103 |
+
onMoveToOrder, onUpdate, onDuplicate, onDelete, onShare, onRouteMove, onRouteReorder, stopLabels = {},
|
| 104 |
+
stopCoords = {},
|
| 105 |
onFolderCreate, onFolderUpdate, onFolderDelete, onFolderReorder, filteredRecordCount,
|
| 106 |
onSelectFiltered, onCreateStart, mapLinks, mapLinkRefusal, deliveries, onSchedule,
|
| 107 |
onDeleteDelivery, assignees, routeToday, assigneeError }: {
|
|
|
|
| 116 |
onToggle: (route: MapRouteDto) => void;
|
| 117 |
onActiveRouteChange: (routeId: string | null) => void;
|
| 118 |
onOpenRecord: (pid: number) => void;
|
| 119 |
+
/** Row-derived identity for every stop the host can name. Keyed by pid; both fields may be
|
| 120 |
+
* empty, and `stopIdentity` owns what is shown when they are.
|
| 121 |
+
* β OPTIONAL because this component also mounts in a render harness with no host grid behind
|
| 122 |
+
* it; MapView always supplies it. The default is `{}`, which routes every stop through
|
| 123 |
+
* `stopIdentity`'s final arm rather than rendering a blank. */
|
| 124 |
+
stopLabels?: Record<number, { name: string; address: string }>;
|
| 125 |
+
/** W46-T19 β where each stop IS, keyed by pid, in the coordinates the host already geocoded.
|
| 126 |
+
* The drive time, the drag preview and the reorder offer all need a position rather than a
|
| 127 |
+
* name, and `stopLabels` deliberately carries neither.
|
| 128 |
+
* β OPTIONAL for the same reason `stopLabels` is: this component mounts in a render harness
|
| 129 |
+
* with no host grid behind it. An absent or partial map is stated on screen, never rounded
|
| 130 |
+
* down to a confident zero. */
|
| 131 |
+
stopCoords?: Record<number, { lat: number; lon: number }>;
|
| 132 |
onCreate: (name: string, source: MapRouteSource) => Result;
|
| 133 |
onMoveToOrder: (route: MapRouteDto, customerPid: number, order: number) => Result;
|
| 134 |
onUpdate: (route: MapRouteDto, patch: MapRouteUpdate) => Result;
|
|
|
|
| 166 |
const [error, setError] = useState<string | null>(null);
|
| 167 |
const [orderDrafts, setOrderDrafts] = useState<Record<number, string>>({});
|
| 168 |
const [orderErrors, setOrderErrors] = useState<Record<number, string>>({});
|
| 169 |
+
const [titleDraft, setTitleDraft] = useState<string | null>(null);
|
| 170 |
const [editMapsUrl, setEditMapsUrl] = useState("");
|
| 171 |
const [assignmentAssignee, setAssignmentAssignee] = useState("");
|
| 172 |
const [assignmentDate, setAssignmentDate] = useState("");
|
|
|
|
| 178 |
const [renameId, setRenameId] = useState<string | null>(null);
|
| 179 |
const [renameDraft, setRenameDraft] = useState("");
|
| 180 |
const [busy, setBusy] = useState(false);
|
|
|
|
| 181 |
const [deliveryMapsPerLink, setDeliveryMapsPerLink] = useState(10);
|
| 182 |
const [deliveryNotice, setDeliveryNotice] = useState<string | null>(null);
|
| 183 |
const [deliveryError, setDeliveryError] = useState<string | null>(null);
|
|
|
|
| 187 |
const route = activeRouteId ? routes.find((item) => item.id === activeRouteId) : null;
|
| 188 |
const source = sources.find((item) => item.id === sourceId) || sources[0];
|
| 189 |
const mapsUrl = boundedGoogleMapsUrl(route?.mapsUrl);
|
| 190 |
+
/**
|
| 191 |
+
* W46-T22 / INSTRUCTION 19 β a stop can be taken OFF a Route from the Route itself.
|
| 192 |
+
*
|
| 193 |
+
* β THE WHOLE STOP LIST IS NEVER SUBMITTED. `visibleStopIds` is permission filtered on the
|
| 194 |
+
* server, so PATCHing it back as this Route's `stops` would silently drop every stop outside
|
| 195 |
+
* the reader's customer book. The membership door removes exactly one pid and re-densifies the
|
| 196 |
+
* rest, which is why it exists; it is the same endpoint the map pin toggle already uses.
|
| 197 |
+
*
|
| 198 |
+
* β THE HOST OWNS `namedRoutes` AND THIS COMPONENT HAS NO CALLBACK INTO IT, so a confirmed
|
| 199 |
+
* removal is held here until the host refetches. The set self-heals rather than going stale:
|
| 200 |
+
* it is keyed to one Route id, and any pid the host no longer reports is pruned, so a stop
|
| 201 |
+
* re-added through the map pin toggle reappears instead of staying invisible.
|
| 202 |
+
*/
|
| 203 |
+
const [removedStops, setRemovedStops] = useState<{ routeId: string; pids: number[] }>(
|
| 204 |
+
{ routeId: "", pids: [] }
|
| 205 |
+
);
|
| 206 |
+
const activeStopIds = route?.visibleStopIds;
|
| 207 |
+
const activeStopRouteId = route?.id || "";
|
| 208 |
+
useEffect(() => {
|
| 209 |
+
const present = new Set(activeStopIds || []);
|
| 210 |
+
setRemovedStops((current) => {
|
| 211 |
+
if (current.routeId !== activeStopRouteId) return { routeId: activeStopRouteId, pids: [] };
|
| 212 |
+
const pids = current.pids.filter((pid) => present.has(pid));
|
| 213 |
+
return pids.length === current.pids.length ? current : { routeId: activeStopRouteId, pids };
|
| 214 |
+
});
|
| 215 |
+
}, [activeStopIds, activeStopRouteId]);
|
| 216 |
+
const stopIds = useMemo(
|
| 217 |
+
() => (activeStopIds || []).filter(
|
| 218 |
+
(pid) => !(removedStops.routeId === activeStopRouteId && removedStops.pids.includes(pid))
|
| 219 |
+
),
|
| 220 |
+
[activeStopIds, activeStopRouteId, removedStops]
|
| 221 |
+
);
|
| 222 |
const assigneeNames = useMemo(
|
| 223 |
() => new Set((assignees || []).map((person) => person.username)),
|
| 224 |
[assignees]
|
|
|
|
| 254 |
// eslint-disable-next-line react-hooks/exhaustive-deps
|
| 255 |
}, [at, validAt]);
|
| 256 |
useEffect(() => {
|
| 257 |
+
setTitleDraft(null);
|
| 258 |
setEditMapsUrl(route?.mapsUrl || "");
|
| 259 |
setOrderDrafts({});
|
| 260 |
setOrderErrors({});
|
|
|
|
| 278 |
setMapCopyNotice(null);
|
| 279 |
setMapCopyError(null);
|
| 280 |
const clipboard = typeof navigator === "undefined" ? null : navigator.clipboard;
|
| 281 |
+
if (!shownMapLinks.length || !clipboard?.writeText) {
|
| 282 |
setMapCopyError("Maps links could not be copied in this browser.");
|
| 283 |
return;
|
| 284 |
}
|
| 285 |
+
void clipboard.writeText(shownMapLinks.map((link) => link.url).join("\n"))
|
| 286 |
.then(() => setMapCopyNotice(
|
| 287 |
+
`${shownMapLinks.length.toLocaleString()} Maps link${shownMapLinks.length === 1 ? "" : "s"} copied.`
|
| 288 |
))
|
| 289 |
.catch(() => setMapCopyError("Maps links could not be copied. Open each link instead."));
|
| 290 |
};
|
| 291 |
|
| 292 |
const scheduleDelivery = (target: MapRouteDto) => {
|
| 293 |
+
// W46-T27: the server derives the delivery target from the Route saved assignee, so there is
|
| 294 |
+
// no recipient to type. The request field is still sent to satisfy the shared DTO, and the
|
| 295 |
+
// server ignores it.
|
| 296 |
+
const recipient = target.assignee || "";
|
| 297 |
if (!recipient) {
|
| 298 |
+
setDeliveryError("Assign this Route to a person first, then schedule its daily delivery.");
|
| 299 |
return;
|
| 300 |
}
|
| 301 |
setDeliveryBusy(true);
|
|
|
|
| 379 |
});
|
| 380 |
}).finally(() => setBusy(false));
|
| 381 |
};
|
| 382 |
+
const commitStopRemove = (target: MapRouteDto, pid: number) => {
|
| 383 |
+
setBusy(true);
|
| 384 |
+
setOrderErrors((current) => {
|
| 385 |
+
const next = { ...current };
|
| 386 |
+
delete next[pid];
|
| 387 |
+
return next;
|
| 388 |
+
});
|
| 389 |
+
void (async () => {
|
| 390 |
+
try {
|
| 391 |
+
const res = await fetch(
|
| 392 |
+
`/api/v1/customers/routes/${encodeURIComponent(target.id)}/stops/membership`,
|
| 393 |
+
{
|
| 394 |
+
method: "POST", credentials: "same-origin",
|
| 395 |
+
headers: { "Content-Type": "application/json" },
|
| 396 |
+
body: JSON.stringify({ customerPid: pid, present: false }),
|
| 397 |
+
}
|
| 398 |
+
);
|
| 399 |
+
const payload = await res.json().catch(() => null);
|
| 400 |
+
if (!res.ok) {
|
| 401 |
+
const message = payload?.error?.message || payload?.detail?.message
|
| 402 |
+
|| "This stop could not be removed.";
|
| 403 |
+
setOrderErrors((current) => ({ ...current, [pid]: message }));
|
| 404 |
+
return;
|
| 405 |
+
}
|
| 406 |
+
setOrderDrafts((current) => {
|
| 407 |
+
const next = { ...current };
|
| 408 |
+
delete next[pid];
|
| 409 |
+
return next;
|
| 410 |
+
});
|
| 411 |
+
setRemovedStops((current) => current.routeId === target.id
|
| 412 |
+
? (current.pids.includes(pid) ? current : { routeId: target.id, pids: [...current.pids, pid] })
|
| 413 |
+
: { routeId: target.id, pids: [pid] });
|
| 414 |
+
} catch {
|
| 415 |
+
setOrderErrors((current) => ({ ...current, [pid]: "This stop could not be removed." }));
|
| 416 |
+
} finally {
|
| 417 |
+
setBusy(false);
|
| 418 |
+
}
|
| 419 |
+
})();
|
| 420 |
+
};
|
| 421 |
const swap = (ids: string[], id: string, delta: number) => {
|
| 422 |
const index = ids.indexOf(id);
|
| 423 |
const other = index + delta;
|
|
|
|
| 427 |
return next;
|
| 428 |
};
|
| 429 |
|
| 430 |
+
/* ββ W46-T19: the drive time, the saving, and the number that moves during a drag βββββββββ
|
| 431 |
+
The whole feature is state and arithmetic here, and exactly one request, so that the two
|
| 432 |
+
numbers on screen can never come from two different questions. */
|
| 433 |
+
const [routeAnswer, setRouteAnswer] = useState<RouteAnswer | null>(null);
|
| 434 |
+
const [timerError, setTimerError] = useState<string | null>(null);
|
| 435 |
+
const [timerBusy, setTimerBusy] = useState(false);
|
| 436 |
+
const [applyBusy, setApplyBusy] = useState(false);
|
| 437 |
+
const [dragPid, setDragPid] = useState<number | null>(null);
|
| 438 |
+
const [dragOrder, setDragOrder] = useState<number[] | null>(null);
|
| 439 |
+
const [dragSeconds, setDragSeconds] = useState<number | null>(null);
|
| 440 |
+
/** W46-T20 β true only while one print is in flight. The printed sheet is mounted on
|
| 441 |
+
* `document.body` for exactly that long, so it costs nothing the rest of the time and can
|
| 442 |
+
* never be a second copy of the Route sitting invisibly in the panel. */
|
| 443 |
+
const [printing, setPrinting] = useState(false);
|
| 444 |
+
/** β A LATCH, BECAUSE `window.print()` MUST HAPPEN ONCE. React's development strict mode
|
| 445 |
+
* invokes an effect twice; without this the dialog opens, closes, and opens again. */
|
| 446 |
+
const printLatch = useRef(false);
|
| 447 |
+
/** The in-flight print's own release, held so an unmount can take the printing class back
|
| 448 |
+
* off `<html>` without the effect needing a teardown of its own (see below). */
|
| 449 |
+
const releasePrint = useRef<(() => void) | null>(null);
|
| 450 |
+
useEffect(() => () => { releasePrint.current?.(); }, []);
|
| 451 |
+
|
| 452 |
+
/**
|
| 453 |
+
* W46-T20 β open the print dialog once the printed sheet is in the document, and give the
|
| 454 |
+
* app back to the person however the dialog ends.
|
| 455 |
+
*
|
| 456 |
+
* THREE WAYS OUT, because none of them is reliable alone: `afterprint` (which does not fire
|
| 457 |
+
* on a cancelled dialog in every engine), the `print` media query going false (Safari's
|
| 458 |
+
* route), and a timeout (the honest backstop). `finish` is idempotent, so whichever arrives
|
| 459 |
+
* first wins. Leaving the class on would hide the entire app behind a print rule.
|
| 460 |
+
*
|
| 461 |
+
* ββ THIS EFFECT DELIBERATELY RETURNS NO TEARDOWN, AND THAT IS THE WHOLE FIX. A cleanup
|
| 462 |
+
* that cancelled the queued frame would run IMMEDIATELY under development strict mode, which
|
| 463 |
+
* mounts, tears down and mounts again: the frame would be cancelled before it ever fired and
|
| 464 |
+
* the Export button would silently do nothing in dev while working in production, which is
|
| 465 |
+
* the worst shape a defect can take. The latch above makes the second invocation a no-op
|
| 466 |
+
* instead, `finish` is the only teardown there is, and `releasePrint` above hands an unmount
|
| 467 |
+
* the same exit so the printing class can never be left behind.
|
| 468 |
+
*/
|
| 469 |
+
useEffect(() => {
|
| 470 |
+
if (!printing || printLatch.current) return;
|
| 471 |
+
printLatch.current = true;
|
| 472 |
+
const root = document.documentElement;
|
| 473 |
+
const media = window.matchMedia ? window.matchMedia("print") : null;
|
| 474 |
+
let done = false;
|
| 475 |
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
| 476 |
+
function finish() {
|
| 477 |
+
if (done) return;
|
| 478 |
+
done = true;
|
| 479 |
+
root.classList.remove(ROUTE_PRINTING_CLASS);
|
| 480 |
+
window.removeEventListener("afterprint", finish);
|
| 481 |
+
media?.removeEventListener?.("change", onMedia);
|
| 482 |
+
if (timer !== undefined) clearTimeout(timer);
|
| 483 |
+
printLatch.current = false;
|
| 484 |
+
releasePrint.current = null;
|
| 485 |
+
setPrinting(false);
|
| 486 |
+
}
|
| 487 |
+
function onMedia(event: MediaQueryListEvent) {
|
| 488 |
+
if (!event.matches) finish();
|
| 489 |
+
}
|
| 490 |
+
releasePrint.current = finish;
|
| 491 |
+
root.classList.add(ROUTE_PRINTING_CLASS);
|
| 492 |
+
window.addEventListener("afterprint", finish);
|
| 493 |
+
media?.addEventListener?.("change", onMedia);
|
| 494 |
+
timer = setTimeout(finish, PRINT_RELEASE_MS);
|
| 495 |
+
// One frame, so the sheet has been laid out under the print rules before the engine
|
| 496 |
+
// snapshots it. Chrome blocks inside `print()` until the dialog closes; Firefox returns
|
| 497 |
+
// immediately. Both ends are handled above. `done` is re-read here because an unmount in
|
| 498 |
+
// that one frame has already released the print, and a dialog opened after the sheet was
|
| 499 |
+
// removed would print a blank page.
|
| 500 |
+
window.requestAnimationFrame(() => {
|
| 501 |
+
if (done) return;
|
| 502 |
+
try { window.print(); } catch { finish(); }
|
| 503 |
+
});
|
| 504 |
+
}, [printing]);
|
| 505 |
+
const settleTimer = useRef<number | null>(null);
|
| 506 |
+
const settleAbort = useRef<AbortController | null>(null);
|
| 507 |
+
const settleGeneration = useRef(0);
|
| 508 |
+
|
| 509 |
+
/** Every stop that can be placed on the earth, in the order it is driven. A stop with no
|
| 510 |
+
* coordinate is COUNTED rather than dropped silently: the figure below then says what it
|
| 511 |
+
* covers instead of quietly timing a shorter day than the one being driven. */
|
| 512 |
+
const locatedStops = useMemo(() => {
|
| 513 |
+
const out: { pid: number; lat: number; lon: number }[] = [];
|
| 514 |
+
for (const pid of stopIds) {
|
| 515 |
+
const at = stopCoords[pid];
|
| 516 |
+
if (at && isPlottable(at.lat, at.lon)) out.push({ pid, lat: at.lat, lon: at.lon });
|
| 517 |
+
}
|
| 518 |
+
return out;
|
| 519 |
+
}, [stopIds, stopCoords]);
|
| 520 |
+
const locatedPids = useMemo(() => locatedStops.map((stop) => stop.pid), [locatedStops]);
|
| 521 |
+
|
| 522 |
+
/**
|
| 523 |
+
* ββ W46-T22 / W46-T20 β THE MAPS LINKS MUST NOT OUTLIVE A REMOVED STOP.
|
| 524 |
+
*
|
| 525 |
+
* `mapLinks` and `mapLinkRefusal` are computed by MapView from the route's SERVER stop list, and
|
| 526 |
+
* removing a stop writes only `removedStops` here: the host is never told, so until
|
| 527 |
+
* `loadNamedRoutes` next fires the Google Maps section would still list, and Copy Maps links
|
| 528 |
+
* would still copy, a customer the person has just removed. The printed PDF is already safe
|
| 529 |
+
* because `routePrintStops` reads the pruned `stopIds`, and that is exactly why this one is
|
| 530 |
+
* worth closing: the two hand-offs a rep actually leaves the building with would otherwise
|
| 531 |
+
* DISAGREE about who is on the route.
|
| 532 |
+
*
|
| 533 |
+
* β Recomputed ONLY while a removal is pending. With none pending the host's own value is used
|
| 534 |
+
* verbatim, so the normal path keeps MapView's `coarsePointer` and this cannot drift from it.
|
| 535 |
+
*/
|
| 536 |
+
const removalPending = removedStops.routeId === activeStopRouteId && removedStops.pids.length > 0;
|
| 537 |
+
const prunedMapLinks = useMemo(
|
| 538 |
+
() => (removalPending ? normalizedRouteMapLinks(stopIds, locatedStops) : null),
|
| 539 |
+
[removalPending, stopIds, locatedStops]
|
| 540 |
+
);
|
| 541 |
+
const shownMapLinks = prunedMapLinks ? prunedMapLinks.links : mapLinks;
|
| 542 |
+
const shownMapLinkRefusal = prunedMapLinks ? prunedMapLinks.refusal : mapLinkRefusal;
|
| 543 |
+
const unlocatedCount = stopIds.length - locatedStops.length;
|
| 544 |
+
const timerKey = `${activeStopRouteId}:${locatedPids.join(",")}`;
|
| 545 |
+
|
| 546 |
+
/**
|
| 547 |
+
* The number a drag moves. β ARITHMETIC ONLY: `previewSeconds` is `tourLength` over
|
| 548 |
+
* coordinates already on screen, so this runs at pointer speed and costs nothing. Nothing in
|
| 549 |
+
* this function, or in the two handlers that call it, may reach the network.
|
| 550 |
+
*/
|
| 551 |
+
const dragPreviewSeconds = (pids: number[]): number | null => {
|
| 552 |
+
if (locatedStops.length < 2) return null;
|
| 553 |
+
const seat = new Map(locatedStops.map((stop, index) => [stop.pid, index]));
|
| 554 |
+
const order: number[] = [];
|
| 555 |
+
for (const pid of pids) {
|
| 556 |
+
const index = seat.get(pid);
|
| 557 |
+
if (index !== undefined) order.push(index);
|
| 558 |
+
}
|
| 559 |
+
if (order.length < 2) return null;
|
| 560 |
+
const geo: GeoStop[] = locatedStops.map((stop) => ({ lat: stop.lat, lon: stop.lon }));
|
| 561 |
+
return previewSeconds(order, geo, haversineKm, ROUTE_ROUND_TRIP);
|
| 562 |
+
};
|
| 563 |
+
|
| 564 |
+
const cancelSettle = () => {
|
| 565 |
+
if (settleTimer.current !== null) {
|
| 566 |
+
window.clearTimeout(settleTimer.current);
|
| 567 |
+
settleTimer.current = null;
|
| 568 |
+
}
|
| 569 |
+
settleAbort.current?.abort();
|
| 570 |
+
settleAbort.current = null;
|
| 571 |
+
};
|
| 572 |
+
|
| 573 |
+
/** The one request. It is never called from a drag; only from the debounced timer below. */
|
| 574 |
+
const settleRoute = async (pids: number[]) => {
|
| 575 |
+
const byPid = new Map(locatedStops.map((stop) => [stop.pid, stop]));
|
| 576 |
+
const stops = pids.map((pid) => byPid.get(pid)).filter(Boolean)
|
| 577 |
+
.map((stop) => ({ lat: stop!.lat, lon: stop!.lon, pid: stop!.pid }));
|
| 578 |
+
if (stops.length < 2) {
|
| 579 |
+
setRouteAnswer(null);
|
| 580 |
+
return;
|
| 581 |
+
}
|
| 582 |
+
const controller = new AbortController();
|
| 583 |
+
settleAbort.current = controller;
|
| 584 |
+
const generation = settleGeneration.current + 1;
|
| 585 |
+
settleGeneration.current = generation;
|
| 586 |
+
setTimerBusy(true);
|
| 587 |
+
setTimerError(null);
|
| 588 |
+
try {
|
| 589 |
+
const res = await fetch(ROUTE_DOOR, {
|
| 590 |
+
method: "POST", credentials: "same-origin",
|
| 591 |
+
headers: { "Content-Type": "application/json" },
|
| 592 |
+
signal: controller.signal,
|
| 593 |
+
// β `pid` PER STOP IS LOAD-BEARING: without it the door answers with seat indices and
|
| 594 |
+
// the one-click apply has no record to move. `fallback: true` is what makes an
|
| 595 |
+
// arithmetic answer come back as `source: "haversine"` instead of an error.
|
| 596 |
+
body: JSON.stringify({
|
| 597 |
+
stops, mode: ROUTE_MODE, roundTrip: ROUTE_ROUND_TRIP, fallback: true,
|
| 598 |
+
}),
|
| 599 |
+
});
|
| 600 |
+
const payload = await res.json().catch(() => null);
|
| 601 |
+
if (settleGeneration.current !== generation) return;
|
| 602 |
+
const answer = res.ok ? parseRouteAnswer(payload) : null;
|
| 603 |
+
if (!answer) {
|
| 604 |
+
setRouteAnswer(null);
|
| 605 |
+
setTimerError(payload?.error?.message || "This Route could not be timed just now.");
|
| 606 |
+
return;
|
| 607 |
+
}
|
| 608 |
+
setRouteAnswer(answer);
|
| 609 |
+
} catch (failure) {
|
| 610 |
+
if ((failure as { name?: string } | null)?.name === "AbortError") return;
|
| 611 |
+
if (settleGeneration.current !== generation) return;
|
| 612 |
+
setRouteAnswer(null);
|
| 613 |
+
setTimerError("This Route could not be timed just now.");
|
| 614 |
+
} finally {
|
| 615 |
+
if (settleGeneration.current === generation) setTimerBusy(false);
|
| 616 |
+
}
|
| 617 |
+
};
|
| 618 |
+
|
| 619 |
+
const scheduleSettle = (pids: number[]) => {
|
| 620 |
+
cancelSettle();
|
| 621 |
+
settleTimer.current = window.setTimeout(() => {
|
| 622 |
+
settleTimer.current = null;
|
| 623 |
+
void settleRoute(pids);
|
| 624 |
+
}, SETTLE_DEBOUNCE_MS);
|
| 625 |
+
};
|
| 626 |
+
|
| 627 |
+
useEffect(() => {
|
| 628 |
+
setRouteAnswer(null);
|
| 629 |
+
setTimerError(null);
|
| 630 |
+
if (locatedPids.length < 2) {
|
| 631 |
+
cancelSettle();
|
| 632 |
+
return;
|
| 633 |
+
}
|
| 634 |
+
scheduleSettle(locatedPids);
|
| 635 |
+
return () => cancelSettle();
|
| 636 |
+
// The key already carries the Route and its located stops in order; the callbacks below are
|
| 637 |
+
// recreated every render and would restart the request on every keystroke elsewhere.
|
| 638 |
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
| 639 |
+
}, [timerKey]);
|
| 640 |
+
|
| 641 |
+
const beginStopDrag = (pid: number) => {
|
| 642 |
+
cancelSettle();
|
| 643 |
+
setDragPid(pid);
|
| 644 |
+
setDragOrder(stopIds);
|
| 645 |
+
setDragSeconds(dragPreviewSeconds(stopIds));
|
| 646 |
+
};
|
| 647 |
+
|
| 648 |
+
const previewStopDrag = (overPid: number) => {
|
| 649 |
+
const moved = dragPid;
|
| 650 |
+
if (moved === null || moved === overPid) return;
|
| 651 |
+
const base = dragOrder || stopIds;
|
| 652 |
+
const next = orderAfterMove(base, moved, overPid);
|
| 653 |
+
if (next === base) return;
|
| 654 |
+
setDragOrder(next);
|
| 655 |
+
setDragSeconds(dragPreviewSeconds(next));
|
| 656 |
+
};
|
| 657 |
+
|
| 658 |
+
const endStopDrag = () => {
|
| 659 |
+
setDragPid(null);
|
| 660 |
+
setDragOrder(null);
|
| 661 |
+
setDragSeconds(null);
|
| 662 |
+
};
|
| 663 |
+
|
| 664 |
+
const dropStopDrag = (target: MapRouteDto, overPid: number) => {
|
| 665 |
+
const moved = dragPid;
|
| 666 |
+
const order = moved === null ? null : orderAfterMove(dragOrder || stopIds, moved, overPid);
|
| 667 |
+
endStopDrag();
|
| 668 |
+
if (moved === null || !order) return;
|
| 669 |
+
const seat = order.indexOf(moved);
|
| 670 |
+
if (seat < 0 || stopIds[seat] === moved) return;
|
| 671 |
+
commitStopMove(target, moved, String(seat + 1));
|
| 672 |
+
scheduleSettle(order.filter((pid) => locatedPids.includes(pid)));
|
| 673 |
+
};
|
| 674 |
+
|
| 675 |
+
/**
|
| 676 |
+
* One click puts the Route in the order the door would drive it.
|
| 677 |
+
*
|
| 678 |
+
* β IT COSTS ONE REQUEST PER STOP THAT ACTUALLY MOVES, through the same validated move door
|
| 679 |
+
* the arrows use, because there is no bulk reorder endpoint. Moving `wanted[i]` to position
|
| 680 |
+
* `i + 1` for ascending `i` leaves exactly the wanted order behind. It refuses outright while
|
| 681 |
+
* any stop has no coordinate, since the answer was then measured over a subset.
|
| 682 |
+
*/
|
| 683 |
+
const applyOptimizedOrder = (target: MapRouteDto) => {
|
| 684 |
+
const answer = routeAnswer;
|
| 685 |
+
if (!answer || unlocatedCount > 0 || applyBusy) return;
|
| 686 |
+
const wanted = answer.optimized.ordered.filter((pid) => stopIds.includes(pid));
|
| 687 |
+
if (wanted.length !== stopIds.length) {
|
| 688 |
+
setTimerError("The faster order no longer matches this Route's stops.");
|
| 689 |
+
return;
|
| 690 |
+
}
|
| 691 |
+
setApplyBusy(true);
|
| 692 |
+
setTimerError(null);
|
| 693 |
+
void (async () => {
|
| 694 |
+
for (let i = 0; i < wanted.length; i++) {
|
| 695 |
+
const message = await onMoveToOrder(target, wanted[i], i + 1);
|
| 696 |
+
if (message) {
|
| 697 |
+
setTimerError(message);
|
| 698 |
+
break;
|
| 699 |
+
}
|
| 700 |
+
}
|
| 701 |
+
setApplyBusy(false);
|
| 702 |
+
scheduleSettle(wanted);
|
| 703 |
+
})();
|
| 704 |
+
};
|
| 705 |
+
|
| 706 |
+
const dragging = dragOrder !== null;
|
| 707 |
+
const timerSaving = routeAnswer ? routeSaving(routeAnswer) : null;
|
| 708 |
+
const timerCaveats = routeAnswer ? routeCaveats(routeAnswer) : [];
|
| 709 |
+
const shownSeconds = dragging ? dragSeconds : dragPreviewSeconds(stopIds);
|
| 710 |
+
const settledLabel = routeAnswer ? routeTimeLabel(routeAnswer.current) : null;
|
| 711 |
+
const estimateLabel = shownSeconds === null ? null : `${formatSeconds(shownSeconds)} estimated`;
|
| 712 |
+
const timerLabel = !dragging && settledLabel ? settledLabel : estimateLabel;
|
| 713 |
+
const timerTone = !dragging && routeAnswer ? routeTimeTone(routeAnswer.current) : "estimated";
|
| 714 |
+
|
| 715 |
if (route) {
|
| 716 |
+
// ββ W46-T25 / RULING R2 - THE GUARD STAYS, AND MIGRATION IS WHAT UNLOCKS A ROUTE.
|
| 717 |
+
// Measured on a synthetic store: after `ops/migrate_legacy_routes.py --apply`, the normalized
|
| 718 |
+
// record wins in `route_system.compatible_routes` on the same stable `legacy_<field>` id, so
|
| 719 |
+
// the projection never appends its marker; `compatibility` comes back undefined and
|
| 720 |
+
// `route_capabilities` returns every action true. A previously legacy Route therefore edits
|
| 721 |
+
// through THIS interface, unchanged, with no guard removed. Dropping the arm instead would
|
| 722 |
+
// unlock the routes that have NOT been migrated, and those still have a live legacy column
|
| 723 |
+
// behind them: two divergent copies, which is the one outcome R2 forbids. The refusal copy
|
| 724 |
+
// below says what actually unblocks it.
|
| 725 |
const canEdit = route.permission.canEdit && route.compatibility !== "legacy-route-order";
|
| 726 |
+
// β POSITIONS ARE READ OFF THE LIST THE PERSON IS LOOKING AT. Earlier, Later and the typed
|
| 727 |
+
// Position box are all ordinal, and `routeStopMovePlan` validates against the ids it is
|
| 728 |
+
// handed, so a just-removed stop still counted here would make every arrow below it move the
|
| 729 |
+
// wrong stop for as long as the host had not refetched.
|
| 730 |
+
const stopView: MapRouteDto = { ...route, visibleStopIds: stopIds };
|
| 731 |
+
// β THE LIST SHOWS THE DRAG, THE ROUTE STILL HOLDS THE SAVED ORDER. `stopView` above is
|
| 732 |
+
// built from `stopIds` on purpose: a drop is validated against the order the server last
|
| 733 |
+
// confirmed, never against the arrangement being previewed on screen.
|
| 734 |
+
const displayIds = dragOrder || stopIds;
|
| 735 |
+
// β THE SAVED ORDER, NOT THE DRAG PREVIEW. A sheet handed to a rep states what the Route
|
| 736 |
+
// IS, and `stopIds` is the order the server last confirmed. `stopIdentity` is passed in so
|
| 737 |
+
// the name on paper is the same function as the name on screen, and every stop is on the
|
| 738 |
+
// page whether or not it has a coordinate.
|
| 739 |
+
const printStops = routePrintStops(stopIds, stopLabels, stopCoords, stopIdentity);
|
| 740 |
+
// β THE NAME HAS EXACTLY ONE WRITER NOW. `Save Route` below sends only the Maps URL, so an
|
| 741 |
+
// abandoned draft in the title can never be committed by a control that says nothing about
|
| 742 |
+
// names, and a saved rename can never be overwritten by a stale copy of the old one.
|
| 743 |
+
const commitRouteRename = () => {
|
| 744 |
+
const next = (titleDraft || "").trim();
|
| 745 |
+
if (!next || busy) return;
|
| 746 |
+
if (next === route.name) { setTitleDraft(null); return; }
|
| 747 |
+
setBusy(true);
|
| 748 |
+
void onUpdate(route, { name: next }).then((message) => {
|
| 749 |
+
setError(message);
|
| 750 |
+
if (!message) setTitleDraft(null);
|
| 751 |
+
}).finally(() => setBusy(false));
|
| 752 |
+
};
|
| 753 |
return (
|
| 754 |
<section className="cg-w44-route-nav" aria-label={`${route.name} route`}>
|
| 755 |
<button type="button" className="cg-w44-route-back" onClick={() => onActiveRouteChange(null)}>
|
| 756 |
Back to routes
|
| 757 |
</button>
|
| 758 |
+
{/* ββ W46-T23 / INSTRUCTION 19: THE ONE PLACE A ROUTE IS RENAMED. ββββββββββββββ
|
| 759 |
+
It used to be two: the row menu on the list, and a "Route name" box buried in the
|
| 760 |
+
edit block far below. Both are gone. The title itself turns into the field, so what
|
| 761 |
+
a person reads when they are not renaming is still a title. */}
|
| 762 |
<div className="cg-w44-route-title">
|
| 763 |
<i style={{ backgroundColor: route.color }} aria-hidden="true" />
|
| 764 |
+
{titleDraft === null ? <>
|
| 765 |
+
<span className="cg-w46-route-name">{route.number}. {route.name}</span>
|
| 766 |
+
{mayRouteAction(route, "rename") && (
|
| 767 |
+
<button type="button" className="cg-w46-route-rename" aria-label={`Rename ${route.name}`}
|
| 768 |
+
onClick={() => { setError(null); setTitleDraft(route.name); }}>Rename</button>
|
| 769 |
+
)}
|
| 770 |
+
</> : <span className="cg-w46-route-rename-edit">
|
| 771 |
+
<input className="cg-input cg-w46-route-name-input" autoFocus value={titleDraft} maxLength={120}
|
| 772 |
+
aria-label={`Rename ${route.name}`}
|
| 773 |
+
onChange={(event) => setTitleDraft(event.target.value)}
|
| 774 |
+
onKeyDown={(event) => {
|
| 775 |
+
if (event.key === "Enter") { event.preventDefault(); commitRouteRename(); }
|
| 776 |
+
else if (event.key === "Escape") { event.preventDefault(); setTitleDraft(null); }
|
| 777 |
+
}} />
|
| 778 |
+
<button type="button" className="cg-w46-route-rename" disabled={busy || !titleDraft.trim()}
|
| 779 |
+
onClick={commitRouteRename}>Save name</button>
|
| 780 |
+
<button type="button" className="cg-w46-route-rename" disabled={busy}
|
| 781 |
+
onClick={() => setTitleDraft(null)}>Cancel</button>
|
| 782 |
+
</span>}
|
| 783 |
</div>
|
| 784 |
<p className="cg-w44-route-meta">
|
| 785 |
{route.shared ? `Shared by ${route.owner || "another user"}` : route.sharedOut ? "Shared with others" : "Private"}
|
| 786 |
</p>
|
| 787 |
+
{/* ββ W46-T19 / R9: the timer sits at the TOP, above the stops it is about. βββββββββ
|
| 788 |
+
The figure is muted and says "estimated" until a road answer settles, per C2, and
|
| 789 |
+
every caveat the answer carries is placed here rather than dropped. */}
|
| 790 |
+
<section className="cg-w46-route-timer" aria-label="Route drive time">
|
| 791 |
+
<div className="cg-w46-timer-head">
|
| 792 |
+
<span className={`cg-w46-timer-time${timerTone === "estimated" ? " is-estimated" : ""}`}>
|
| 793 |
+
{timerLabel || "No drive time yet"}
|
| 794 |
+
</span>
|
| 795 |
+
<span className="cg-w46-timer-caption">
|
| 796 |
+
{dragging ? "While this stop moves"
|
| 797 |
+
: timerBusy ? "Measuring the drive"
|
| 798 |
+
: timerLabel ? "Drive time" : "Add two located stops"}
|
| 799 |
+
</span>
|
| 800 |
+
</div>
|
| 801 |
+
{unlocatedCount > 0 && (
|
| 802 |
+
<p className="cg-w46-timer-note">
|
| 803 |
+
{unlocatedCount.toLocaleString()} stop{unlocatedCount === 1 ? " has" : "s have"} no
|
| 804 |
+
map location, so this time covers the rest of the Route.
|
| 805 |
+
</p>
|
| 806 |
+
)}
|
| 807 |
+
{!dragging && timerSaving?.offer && (
|
| 808 |
+
<div className="cg-w46-timer-saving">
|
| 809 |
+
<p>
|
| 810 |
+
Reordering saves {formatSeconds(timerSaving.seconds)}, about{" "}
|
| 811 |
+
{Math.abs(timerSaving.percent)}% of the drive.
|
| 812 |
+
</p>
|
| 813 |
+
{canEdit && unlocatedCount === 0 && (
|
| 814 |
+
<button type="button" className="cg-w46-timer-apply" disabled={busy || applyBusy}
|
| 815 |
+
onClick={() => applyOptimizedOrder(stopView)}>
|
| 816 |
+
{applyBusy ? "Applying the faster order" : "Apply the faster order"}
|
| 817 |
+
</button>
|
| 818 |
+
)}
|
| 819 |
+
</div>
|
| 820 |
+
)}
|
| 821 |
+
{!dragging && timerSaving?.costs && (
|
| 822 |
+
<p className="cg-w46-timer-note">
|
| 823 |
+
Reordering these stops would add {formatSeconds(timerSaving.seconds)} on the road,
|
| 824 |
+
so the current order is the faster one.
|
| 825 |
+
</p>
|
| 826 |
+
)}
|
| 827 |
+
{timerCaveats.map((caveat) => (
|
| 828 |
+
<p className="cg-w46-timer-caveat" key={caveat}>{caveat}</p>
|
| 829 |
+
))}
|
| 830 |
+
{timerError && <p className="cg-w46-timer-error" role="alert">{timerError}</p>}
|
| 831 |
+
</section>
|
| 832 |
+
{stopIds.length ? (
|
| 833 |
<ol className="cg-w44-route-stops">
|
| 834 |
+
{displayIds.map((pid, index) => (
|
| 835 |
+
<li key={pid}
|
| 836 |
+
className={dragPid === pid ? "cg-w46-stop-dragging" : undefined}
|
| 837 |
+
onDragOver={(event) => {
|
| 838 |
+
if (dragPid === null) return;
|
| 839 |
+
event.preventDefault();
|
| 840 |
+
previewStopDrag(pid);
|
| 841 |
+
}}
|
| 842 |
+
onDrop={(event) => {
|
| 843 |
+
if (dragPid === null) return;
|
| 844 |
+
event.preventDefault();
|
| 845 |
+
dropStopDrag(stopView, pid);
|
| 846 |
+
}}>
|
| 847 |
+
{/* The grip is POINTER ONLY and hidden from assistive technology on purpose:
|
| 848 |
+
Move earlier, Position and Move later already reorder this list from the
|
| 849 |
+
keyboard, and a focusable duplicate of them would be a second tab stop that
|
| 850 |
+
announces nothing a keyboard user can act on. */}
|
| 851 |
+
{canEdit && (
|
| 852 |
+
<span className="cg-w46-stop-grip" draggable aria-hidden="true"
|
| 853 |
+
title="Drag to reorder this stop"
|
| 854 |
+
onDragStart={(event) => {
|
| 855 |
+
event.dataTransfer.effectAllowed = "move";
|
| 856 |
+
try { event.dataTransfer.setData("text/plain", String(pid)); }
|
| 857 |
+
catch { /* Some browsers refuse a payload; the drag still works. */ }
|
| 858 |
+
beginStopDrag(pid);
|
| 859 |
+
}}
|
| 860 |
+
onDragEnd={() => endStopDrag()}>
|
| 861 |
+
<svg viewBox="0 0 16 16" aria-hidden="true">
|
| 862 |
+
<circle cx="6" cy="4" r="1" /><circle cx="10" cy="4" r="1" />
|
| 863 |
+
<circle cx="6" cy="8" r="1" /><circle cx="10" cy="8" r="1" />
|
| 864 |
+
<circle cx="6" cy="12" r="1" /><circle cx="10" cy="12" r="1" />
|
| 865 |
+
</svg>
|
| 866 |
+
</span>
|
| 867 |
+
)}
|
| 868 |
<button type="button" className="cg-w44-route-stop-open"
|
| 869 |
+
aria-label={`Open stop ${index + 1} record`}
|
| 870 |
+
aria-describedby={`cg-route-stop-name-${pid}`} onClick={() => onOpenRecord(pid)}>
|
| 871 |
+
{/* The ordinal is furniture: it says where in the drive this falls, and the
|
| 872 |
+
accessible name above already carries it, so it is hidden from the reader
|
| 873 |
+
rather than announced twice. */}
|
| 874 |
+
<span className="cg-w46-stop-index" aria-hidden="true">{index + 1}</span>
|
| 875 |
+
<span className="cg-w46-stop-name" id={`cg-route-stop-name-${pid}`}>
|
| 876 |
+
{stopIdentity(stopLabels[pid], pid)}
|
| 877 |
+
</span>
|
| 878 |
</button>
|
| 879 |
{canEdit && (
|
| 880 |
<span className="cg-w44-route-stop-actions">
|
| 881 |
<button type="button" className="cg-w44-route-step" disabled={busy || index === 0}
|
| 882 |
aria-label={`Move stop ${index + 1} earlier`}
|
| 883 |
+
title="Move earlier" onClick={() => commitStopMove(stopView, pid, String(index))}>
|
| 884 |
<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M10 3 5 8l5 5" /></svg>
|
| 885 |
</button>
|
| 886 |
<label className="cg-w44-route-position"><span>Position</span>
|
|
|
|
| 902 |
onKeyDown={(event) => {
|
| 903 |
if (event.key === "Enter") {
|
| 904 |
event.preventDefault();
|
| 905 |
+
commitStopMove(stopView, pid, event.currentTarget.value);
|
| 906 |
} else if (event.key === "Escape") {
|
| 907 |
event.preventDefault();
|
| 908 |
setOrderDrafts((current) => {
|
|
|
|
| 919 |
}} />
|
| 920 |
</label>
|
| 921 |
<button type="button" className="cg-w44-route-position-apply" disabled={busy}
|
| 922 |
+
onClick={() => commitStopMove(stopView, pid, orderDrafts[pid] ?? String(index + 1))}>
|
| 923 |
Move
|
| 924 |
</button>
|
| 925 |
<button type="button" className="cg-w44-route-step"
|
| 926 |
+
disabled={busy || index === displayIds.length - 1}
|
| 927 |
aria-label={`Move stop ${index + 1} later`}
|
| 928 |
+
title="Move later" onClick={() => commitStopMove(stopView, pid, String(index + 2))}>
|
| 929 |
<svg viewBox="0 0 16 16" aria-hidden="true"><path d="m6 3 5 5-5 5" /></svg>
|
| 930 |
</button>
|
| 931 |
+
<button type="button" className="cg-w44-route-step" disabled={busy}
|
| 932 |
+
aria-label={`Remove stop ${index + 1} from this route`}
|
| 933 |
+
title="Remove stop" onClick={() => commitStopRemove(route, pid)}>
|
| 934 |
+
<svg viewBox="0 0 16 16" aria-hidden="true"><path d="m4 4 8 8M12 4l-8 8" /></svg>
|
| 935 |
+
</button>
|
| 936 |
</span>
|
| 937 |
)}
|
| 938 |
{orderErrors[pid] && <span id={`cg-route-order-error-${pid}`}
|
|
|
|
| 948 |
<h3 id="cg-route-map-links-title">Google Maps</h3>
|
| 949 |
<p>Current ordered Route stops, split into links of at most 10 stops.</p>
|
| 950 |
</div>
|
| 951 |
+
{shownMapLinkRefusal ? (
|
| 952 |
+
<span className="cg-w44-route-warning" role="alert">{shownMapLinkRefusal}</span>
|
| 953 |
+
) : shownMapLinks.length ? <>
|
| 954 |
<ol>
|
| 955 |
+
{shownMapLinks.map((link) => (
|
| 956 |
<li key={`${link.index}:${link.start}:${link.end}`}>
|
| 957 |
<a href={link.url} target="_blank" rel="noopener noreferrer">
|
| 958 |
Link {link.index} - Stops {link.start + 1} to {link.end}
|
|
|
|
| 970 |
{mapCopyNotice && <span className="cg-w44-route-empty" role="status">{mapCopyNotice}</span>}
|
| 971 |
{mapCopyError && <span className="cg-w44-route-warning" role="alert">{mapCopyError}</span>}
|
| 972 |
</section>
|
| 973 |
+
{/* ββ W46-T20 / INSTRUCTION 10 / R6: the sheet the sales team is handed. βββββββββββ
|
| 974 |
+
A plain print, so the person keeps their browser's own Save as PDF, its paper
|
| 975 |
+
size and its margins. A div, and deliberately neither a section nor an outer
|
| 976 |
+
complementary landmark element: this panel's structure is pinned by
|
| 977 |
+
verify_grid_ux, which counts the one and forbids the other outright, and the
|
| 978 |
+
export is a control on the Route rather than a region of it. */}
|
| 979 |
+
<div className="cg-w46-route-export">
|
| 980 |
+
<h3>Export</h3>
|
| 981 |
+
<p>A printable stop list with a Google Maps link on every stop. Choose Save as PDF
|
| 982 |
+
in the print dialog.</p>
|
| 983 |
+
<button type="button" className="cg-w46-route-export-open"
|
| 984 |
+
disabled={printing || !stopIds.length}
|
| 985 |
+
onClick={() => { setError(null); setPrinting(true); }}>
|
| 986 |
+
Export to PDF
|
| 987 |
+
</button>
|
| 988 |
+
{!stopIds.length && (
|
| 989 |
+
<span className="cg-w44-route-empty">Add a stop before exporting this route.</span>
|
| 990 |
+
)}
|
| 991 |
+
</div>
|
| 992 |
+
{printing && createPortal(
|
| 993 |
+
/* β MOUNTED ON `document.body`, WHICH IS THE POINT. The isolation rule hides every
|
| 994 |
+
child of `<body>` and reveals this one, so the shell, the grid, the map and this
|
| 995 |
+
very panel stay off the paper. Inside the Route panel it would inherit that
|
| 996 |
+
panel's scroll and overflow, and a long Route would print its first page only.
|
| 997 |
+
β EVERY MAP LINK IS A REAL `<a href>` WITH VISIBLE TEXT: that is what makes a
|
| 998 |
+
browser emit a clickable link annotation into the saved PDF. A CSS `content:`
|
| 999 |
+
string, or a URL printed as text, is not one. */
|
| 1000 |
+
<div className="cg-w46-route-print-portal">
|
| 1001 |
+
<div className="cg-w46-route-print-sheet">
|
| 1002 |
+
<h1 className="cg-w46-route-print-title">{route.number}. {route.name}</h1>
|
| 1003 |
+
<p className="cg-w46-route-print-meta">
|
| 1004 |
+
{printStops.length.toLocaleString()} stops, in driving order.
|
| 1005 |
+
</p>
|
| 1006 |
+
<ol className="cg-w46-route-print-stops">
|
| 1007 |
+
{printStops.map((stop) => (
|
| 1008 |
+
<li key={stop.pid} className="cg-w46-route-print-stop">
|
| 1009 |
+
<span className="cg-w46-print-pos">{stop.position}</span>
|
| 1010 |
+
<span className="cg-w46-print-body">
|
| 1011 |
+
<span className="cg-w46-print-name">{stop.name}</span>
|
| 1012 |
+
{/* The address line is ALWAYS printed, because a rep drives to an
|
| 1013 |
+
address. When the record has no name at all the line above already
|
| 1014 |
+
IS the address, and saying so beats printing it twice. */}
|
| 1015 |
+
<span className="cg-w46-print-address">
|
| 1016 |
+
{stop.nameIsAddress
|
| 1017 |
+
? "No name on record. The line above is the address."
|
| 1018 |
+
: stop.address || "No address on record."}
|
| 1019 |
+
</span>
|
| 1020 |
+
{stop.mapsUrl ? (
|
| 1021 |
+
<a className="cg-w46-print-link" href={stop.mapsUrl}
|
| 1022 |
+
rel="noopener noreferrer">
|
| 1023 |
+
Open {stop.name} in Google Maps
|
| 1024 |
+
</a>
|
| 1025 |
+
) : (
|
| 1026 |
+
<span className="cg-w46-print-nolink">
|
| 1027 |
+
No map pin for this stop. Drive to the address above.
|
| 1028 |
+
</span>
|
| 1029 |
+
)}
|
| 1030 |
+
</span>
|
| 1031 |
+
</li>
|
| 1032 |
+
))}
|
| 1033 |
+
</ol>
|
| 1034 |
+
</div>
|
| 1035 |
+
</div>,
|
| 1036 |
+
document.body,
|
| 1037 |
+
)}
|
| 1038 |
{canEdit ? (
|
| 1039 |
<div className="cg-w44-route-edit" aria-label="Edit Route">
|
|
|
|
|
|
|
|
|
|
| 1040 |
<label className="cg-w44-route-label">Google Maps URL
|
| 1041 |
<input className="cg-input" type="url" value={editMapsUrl} maxLength={2048}
|
| 1042 |
placeholder="https://www.google.com/maps/..." onChange={(event) => setEditMapsUrl(event.target.value)} />
|
| 1043 |
</label>
|
| 1044 |
<div className="cg-form-actions">
|
| 1045 |
+
<button type="button" className="cg-btn cg-btn--primary" disabled={busy}
|
| 1046 |
+
onClick={() => finish(onUpdate(route, { mapsUrl: editMapsUrl.trim() }))}>
|
| 1047 |
Save Route
|
| 1048 |
</button>
|
| 1049 |
<button type="button" className="cg-btn" disabled={busy} onClick={() => finish(onShare(route))}>Share</button>
|
|
|
|
| 1063 |
)}
|
| 1064 |
</div>
|
| 1065 |
) : <p className="cg-w44-route-empty">{route.compatibility === "legacy-route-order"
|
| 1066 |
+
? "Ask an administrator to move this Route into central storage, then it edits like any other."
|
| 1067 |
+
: "Only the owner and an editor of the source View can change this Route."}</p>}
|
| 1068 |
{canEdit && (
|
| 1069 |
<section className="cg-w44-route-delivery cg-w45-route-assignment"
|
| 1070 |
aria-labelledby="cg-route-assignment-title">
|
|
|
|
| 1123 |
<section className="cg-w44-route-delivery" aria-labelledby="cg-route-delivery-title">
|
| 1124 |
<div>
|
| 1125 |
<h3 id="cg-route-delivery-title">Daily delivery</h3>
|
| 1126 |
+
<p>Freeze this Route now and send it to the assignee's Inbox each day at 08:00 ({deliveryTimezone}).</p>
|
| 1127 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1128 |
<label className="cg-w44-route-label">Stops per Maps link
|
| 1129 |
<input className="cg-input" type="number" min={2} max={10} value={deliveryMapsPerLink}
|
| 1130 |
onChange={(event) => setDeliveryMapsPerLink(
|
|
|
|
| 1132 |
)} />
|
| 1133 |
</label>
|
| 1134 |
<button type="button" className="cg-btn cg-btn--primary"
|
| 1135 |
+
disabled={deliveryBusy || stopIds.length < 2 || !route.assignee || savedAssigneeUnavailable}
|
| 1136 |
onClick={() => scheduleDelivery(route)}>
|
| 1137 |
{deliveryBusy ? "Scheduling" : "Schedule delivery"}
|
| 1138 |
</button>
|
| 1139 |
+
{stopIds.length < 2 && (
|
| 1140 |
<span className="cg-w44-route-empty">Add at least two stops before scheduling.</span>
|
| 1141 |
)}
|
| 1142 |
+
{!route.assignee && (
|
| 1143 |
+
<span className="cg-w44-route-empty">
|
| 1144 |
+
Pick an assignee above to choose who receives this Route in Inbox.
|
| 1145 |
+
</span>
|
| 1146 |
+
)}
|
| 1147 |
+
{Boolean(route.assignee) && savedAssigneeUnavailable && (
|
| 1148 |
+
<span className="cg-w44-route-warning" role="alert">
|
| 1149 |
+
This Route's assignee is no longer available. Reassign it, then schedule the delivery.
|
| 1150 |
+
</span>
|
| 1151 |
+
)}
|
| 1152 |
<div className="cg-w44-route-delivery-list" aria-label="Existing Route deliveries">
|
| 1153 |
{deliveries === null ? (
|
| 1154 |
<span className="cg-w44-route-empty">Loading deliveries.</span>
|
|
|
|
| 1281 |
<button type="button" className="cg-w44-route-toggle" aria-pressed={selectedIds.has(item.id)}
|
| 1282 |
aria-label={`${selectedIds.has(item.id) ? "Remove" : "Include"} ${item.name}`}
|
| 1283 |
onClick={() => onToggle(item)}><i style={{ backgroundColor: item.color }} aria-hidden="true" /></button>
|
| 1284 |
+
{/* A Route is renamed at the top of its own panel (W46-T23), never from this row. */}
|
| 1285 |
+
<button type="button" className="cg-w44-route-open" onClick={() => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1286 |
setError(null); setCreating(false); onActiveRouteChange(item.id);
|
| 1287 |
+
}}>{item.number}. {item.name}</button>
|
| 1288 |
{(item.shared || item.sharedOut) && <span className="cg-w44-route-share-mark">
|
| 1289 |
{item.shared ? `Shared by ${item.owner || "another user"}` : "Shared"}
|
| 1290 |
</span>}
|
|
|
|
| 1292 |
<button type="button" className="cg-w44-route-more" aria-label={`Actions for ${item.name}`}
|
| 1293 |
aria-expanded={menuId === item.id} onClick={() => setMenuId(menuId === item.id ? null : item.id)}>...</button>
|
| 1294 |
{menuId === item.id && <div className="cg-w44-route-menu" role="menu">
|
|
|
|
|
|
|
| 1295 |
<button type="button" role="menuitem" disabled={!mayRouteAction(item, "duplicate")}
|
| 1296 |
onClick={() => { setMenuId(null); finish(onDuplicate(item)); }}>Duplicate</button>
|
| 1297 |
<button type="button" role="menuitem" disabled={!mayRouteAction(item, "star")}
|
web/src/customer-grid/Toolbar.tsx
CHANGED
|
@@ -265,6 +265,11 @@ interface ToolbarBaseProps {
|
|
| 265 |
/** The active view's fullscreen door belongs beside Edit, not below the whole toolbar. */
|
| 266 |
fullscreen?: boolean;
|
| 267 |
onFullscreen?: () => void;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
}
|
| 269 |
|
| 270 |
export interface ToolbarManagerProps extends ToolbarBaseProps {
|
|
@@ -353,6 +358,19 @@ function IconFullScreen() {
|
|
| 353 |
</svg>
|
| 354 |
);
|
| 355 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 356 |
function IconRelational() {
|
| 357 |
return (
|
| 358 |
<svg {...ic} aria-hidden>
|
|
@@ -781,6 +799,8 @@ export default function Toolbar({
|
|
| 781 |
onViewActions,
|
| 782 |
fullscreen = false,
|
| 783 |
onFullscreen,
|
|
|
|
|
|
|
| 784 |
}: ToolbarProps) {
|
| 785 |
const shownCount = fields.filter((f) => visible.has(f.key)).length;
|
| 786 |
const fullscreenLabel = fullscreen ? "Exit full screen" : "Full screen";
|
|
@@ -1247,6 +1267,38 @@ export default function Toolbar({
|
|
| 1247 |
</button>
|
| 1248 |
)}
|
| 1249 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1250 |
{onFullscreen && (
|
| 1251 |
<button
|
| 1252 |
type="button"
|
|
|
|
| 265 |
/** The active view's fullscreen door belongs beside Edit, not below the whole toolbar. */
|
| 266 |
fullscreen?: boolean;
|
| 267 |
onFullscreen?: () => void;
|
| 268 |
+
/** β W46-T09 (owner instructions 2 + 30) β the workspace Notes drawer, opened from the
|
| 269 |
+
* toolbar so that Related, Notes and Full screen are one contiguous run. Supplied only by
|
| 270 |
+
* the main grid render, which is the only place a workspace drawer exists. */
|
| 271 |
+
notesOpen?: boolean;
|
| 272 |
+
onNotes?: () => void;
|
| 273 |
}
|
| 274 |
|
| 275 |
export interface ToolbarManagerProps extends ToolbarBaseProps {
|
|
|
|
| 358 |
</svg>
|
| 359 |
);
|
| 360 |
}
|
| 361 |
+
// W46-T09 β a page with two written lines: the rect is `IconColumns`' frame and the lines are
|
| 362 |
+
// `IconRows`' rules, at the same 14px box and 1.5 stroke every other mark in this strip wears.
|
| 363 |
+
// Nothing in the vocabulary said "a note" yet, and a borrowed glyph would name the wrong thing
|
| 364 |
+
// every time the strip is read.
|
| 365 |
+
function IconNote() {
|
| 366 |
+
return (
|
| 367 |
+
<svg {...ic} aria-hidden>
|
| 368 |
+
<rect x="3" y="2.5" width="10" height="11" rx="1.5" {...stroke} />
|
| 369 |
+
<line x1="5.5" y1="6" x2="10.5" y2="6" {...stroke} />
|
| 370 |
+
<line x1="5.5" y1="9.5" x2="9" y2="9.5" {...stroke} />
|
| 371 |
+
</svg>
|
| 372 |
+
);
|
| 373 |
+
}
|
| 374 |
function IconRelational() {
|
| 375 |
return (
|
| 376 |
<svg {...ic} aria-hidden>
|
|
|
|
| 799 |
onViewActions,
|
| 800 |
fullscreen = false,
|
| 801 |
onFullscreen,
|
| 802 |
+
notesOpen = false,
|
| 803 |
+
onNotes,
|
| 804 |
}: ToolbarProps) {
|
| 805 |
const shownCount = fields.filter((f) => visible.has(f.key)).length;
|
| 806 |
const fullscreenLabel = fullscreen ? "Exit full screen" : "Full screen";
|
|
|
|
| 1267 |
</button>
|
| 1268 |
)}
|
| 1269 |
|
| 1270 |
+
{/* ββ W46-T09 (owner instructions 2 and 30) β NOTES JOINED THE STRIP.
|
| 1271 |
+
It used to hang in its own `.cg-drawer-launchers` row above the toolbar, which made
|
| 1272 |
+
"Notes sits just left of Full screen" impossible: two containers cannot put three
|
| 1273 |
+
controls in one run. It renders only where a workspace drawer exists, so the pivot
|
| 1274 |
+
toolbar is untouched.
|
| 1275 |
+
β IT SITS HERE IN THE DOM, IMMEDIATELY BEFORE Full screen, so that the tab
|
| 1276 |
+
sequence and the painted sequence agree about this pair: `order:` moves pixels and
|
| 1277 |
+
never moves focus, and a keyboard user reaching Full screen before Notes while the
|
| 1278 |
+
screen shows the opposite is a real defect, not a nitpick.
|
| 1279 |
+
The cost is priced and paid: inserting a sibling into this run breaks the Wave 44
|
| 1280 |
+
ADJACENCY chains hanging off `.cg-tb-related`, and here it breaks the Full screen one,
|
| 1281 |
+
which would drop that button to the catch-all order and send it past Related. This
|
| 1282 |
+
ticket's sheet reassigns all five controls explicitly, so nothing is left resting on a
|
| 1283 |
+
chain. The reading order is declared in `src/styles/wave46/chrome.css`. */}
|
| 1284 |
+
{onNotes && (
|
| 1285 |
+
<button
|
| 1286 |
+
type="button"
|
| 1287 |
+
className={"cg-tb-btn cg-notes-toggle" + (notesOpen ? " is-active" : "")}
|
| 1288 |
+
/* A DISCLOSURE, NOT A TOGGLE: this opens the workspace drawer, which is exactly what
|
| 1289 |
+
the launcher button it replaces announced. Carrying `aria-pressed` as well would
|
| 1290 |
+
say "toggle button, not pressed" and "collapsed" in one breath. Full screen next
|
| 1291 |
+
door is genuinely a pressed state, so the two attributes differ on purpose. */
|
| 1292 |
+
aria-expanded={notesOpen}
|
| 1293 |
+
aria-label="Notes"
|
| 1294 |
+
title="Notes"
|
| 1295 |
+
onClick={onNotes}
|
| 1296 |
+
>
|
| 1297 |
+
<IconNote />
|
| 1298 |
+
<span className="cg-tb-label">Notes</span>
|
| 1299 |
+
</button>
|
| 1300 |
+
)}
|
| 1301 |
+
|
| 1302 |
{onFullscreen && (
|
| 1303 |
<button
|
| 1304 |
type="button"
|
web/src/customer-grid/ViewSidebar.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
-
import
|
|
|
|
| 2 |
import type { ReactNode } from "react";
|
| 3 |
import type { KeyboardEvent as ReactKeyboardEvent } from "react";
|
| 4 |
import { AnchoredOverlay } from "./OverlaySurface";
|
|
@@ -21,6 +22,9 @@ import {
|
|
| 21 |
} from "./types";
|
| 22 |
import {
|
| 23 |
CREATABLE_MODES,
|
|
|
|
|
|
|
|
|
|
| 24 |
MODE_LABELS,
|
| 25 |
MODE_TONE,
|
| 26 |
SHARE_SHAPE,
|
|
@@ -131,6 +135,46 @@ function ShareMark({ size = 13 }: { size?: number }) {
|
|
| 131 |
);
|
| 132 |
}
|
| 133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
/** What the rail's share mark says, once it has been decided that there is one to show. */
|
| 135 |
export interface ViewShareMark {
|
| 136 |
title: string;
|
|
@@ -468,6 +512,86 @@ function PathBackButton({
|
|
| 468 |
);
|
| 469 |
}
|
| 470 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 471 |
type DataNavigatorLevel =
|
| 472 |
| { kind: "root" }
|
| 473 |
| { kind: "origin"; label: string }
|
|
@@ -500,6 +624,11 @@ function DataDatabaseNavigator({
|
|
| 500 |
);
|
| 501 |
const [renamingFolder, setRenamingFolder] = useState<string | null>(null);
|
| 502 |
const [folderName, setFolderName] = useState("");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 503 |
|
| 504 |
const dropDatabase = (event: React.DragEvent<HTMLElement>, folderId: string | null) => {
|
| 505 |
if (!onMove) return;
|
|
@@ -556,6 +685,10 @@ function DataDatabaseNavigator({
|
|
| 556 |
}
|
| 557 |
const dataLevel = dataPathState.levels[dataPathState.at] ?? { kind: "root" as const };
|
| 558 |
const canDataBack = dataPathState.at > 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 559 |
const pushDataLevel = (level: DataNavigatorLevel) => {
|
| 560 |
setDataPathState((current) => ({
|
| 561 |
levels: [...current.levels.slice(0, current.at + 1), level],
|
|
@@ -574,6 +707,30 @@ function DataDatabaseNavigator({
|
|
| 574 |
if (dataNavigatorLevelKey(level) === dataNavigatorLevelKey(dataLevel)) return;
|
| 575 |
pushDataLevel(level);
|
| 576 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 577 |
const openDatabase = (database: DataDatabase) => {
|
| 578 |
if (database.externalHref) return;
|
| 579 |
visitDataLevel({ kind: "database", key: database.key });
|
|
@@ -584,7 +741,7 @@ function DataDatabaseNavigator({
|
|
| 584 |
const draggable = !!onMove && !database.protected && database.managedBy !== "loopable";
|
| 585 |
const content = (
|
| 586 |
<>
|
| 587 |
-
<
|
| 588 |
<span className="cg-fold-name">{database.label}</span>
|
| 589 |
{database.locked ? (
|
| 590 |
<span
|
|
@@ -648,12 +805,18 @@ function DataDatabaseNavigator({
|
|
| 648 |
return <>{children({ canBack: false, back: () => undefined })}</>;
|
| 649 |
}
|
| 650 |
|
| 651 |
-
const
|
|
|
|
|
|
|
|
|
|
| 652 |
dataLevel.kind === "origin"
|
| 653 |
? sourceGroups.find((group) => group.label === dataLevel.label)?.databases ?? []
|
| 654 |
: dataLevel.kind === "folder"
|
| 655 |
? databases.filter((database) => database.folderId === dataLevel.id)
|
| 656 |
-
: []
|
|
|
|
|
|
|
|
|
|
| 657 |
|
| 658 |
return (
|
| 659 |
<div className="cg-data-tree" data-data-path-tree>
|
|
@@ -664,12 +827,66 @@ function DataDatabaseNavigator({
|
|
| 664 |
aria-label="Data location"
|
| 665 |
>
|
| 666 |
<PathBackButton disabled={!canDataBack} onClick={() => stepDataLevel(-1)} />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 667 |
</nav>
|
| 668 |
) : null}
|
| 669 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 670 |
{dataLevel.kind === "root" ? (
|
| 671 |
<div className="cg-data-path-level" data-data-level="root">
|
| 672 |
-
{
|
| 673 |
<div key={group.label} className="cg-fold cg-data-origin" {...dropProps(null)}>
|
| 674 |
<div className="cg-fold-head">
|
| 675 |
<button
|
|
@@ -685,7 +902,7 @@ function DataDatabaseNavigator({
|
|
| 685 |
</div>
|
| 686 |
</div>
|
| 687 |
))}
|
| 688 |
-
{
|
| 689 |
const members = databases.filter((database) => database.folderId === folder.id);
|
| 690 |
return (
|
| 691 |
<div
|
|
@@ -723,6 +940,9 @@ function DataDatabaseNavigator({
|
|
| 723 |
</div>
|
| 724 |
);
|
| 725 |
})}
|
|
|
|
|
|
|
|
|
|
| 726 |
</div>
|
| 727 |
) : dataLevel.kind === "database" ? (
|
| 728 |
<div className="cg-data-database-views" data-data-level="database">
|
|
@@ -731,15 +951,17 @@ function DataDatabaseNavigator({
|
|
| 731 |
) : (
|
| 732 |
<div className="cg-data-path-level" data-data-level={dataLevel.kind} {...dropProps(null)}>
|
| 733 |
{levelDatabases.map(pathDatabaseRow)}
|
|
|
|
|
|
|
|
|
|
| 734 |
{levelDatabases.length === 0 ? (
|
| 735 |
-
<div className="cg-fold-empty">
|
|
|
|
|
|
|
| 736 |
) : null}
|
| 737 |
</div>
|
| 738 |
)}
|
| 739 |
|
| 740 |
-
{dataLevel.kind === "root" && createControl ? (
|
| 741 |
-
<div className="cg-data-create">{createControl}</div>
|
| 742 |
-
) : null}
|
| 743 |
{folderMenu ? (
|
| 744 |
<AnchoredOverlay
|
| 745 |
anchor={folderMenu.anchor}
|
|
@@ -947,6 +1169,17 @@ export default function ViewSidebar({
|
|
| 947 |
/** C3 begins with the View whose menu opened this pane; later picks are explicit. */
|
| 948 |
const [exportViewIds, setExportViewIds] = useState<string[]>([]);
|
| 949 |
const [exportBulk, setExportBulk] = useState(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 950 |
const xlsxExportViews = useMemo(() => {
|
| 951 |
const allowed = new Set(exportableViewIds ?? []);
|
| 952 |
return views.filter((view) => allowed.has(view.id));
|
|
@@ -1000,12 +1233,45 @@ export default function ViewSidebar({
|
|
| 1000 |
* preference that survives a reload is a folder that is open when the user next logs in.
|
| 1001 |
*/
|
| 1002 |
// Recovered from 7f6a1c0 (W42-T43): one location replaces the old expand/collapse tree.
|
| 1003 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1004 |
const railDatabaseRef = useRef(activeDatabaseKey);
|
| 1005 |
if (railDatabaseRef.current !== activeDatabaseKey) {
|
| 1006 |
railDatabaseRef.current = activeDatabaseKey;
|
| 1007 |
const restored = readRailPath(activeDatabaseKey);
|
| 1008 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1009 |
}
|
| 1010 |
const [folderMenu, setFolderMenu] = useState<{ id: string; anchor: HTMLElement } | null>(null);
|
| 1011 |
const [renamingFolder, setRenamingFolder] = useState<string | null>(null);
|
|
@@ -1309,6 +1575,26 @@ export default function ViewSidebar({
|
|
| 1309 |
),
|
| 1310 |
[atId, foldersOn, folders, shownViews, folderIdOf]
|
| 1311 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1312 |
const levelGroups = useMemo(() => {
|
| 1313 |
const pin: typeof groups = [];
|
| 1314 |
const heads: typeof groups = [];
|
|
@@ -1340,8 +1626,96 @@ export default function ViewSidebar({
|
|
| 1340 |
}
|
| 1341 |
if (childIds.has(groupId)) heads.push(group);
|
| 1342 |
}
|
| 1343 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1344 |
}, [groups, level, atId, viewNeedle]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1345 |
const folderMenuF = folderMenu ? folders?.find((f) => f.id === folderMenu.id) : undefined;
|
| 1346 |
/**
|
| 1347 |
* ββ WAVE 41 Β· T33 (instruction 12, R1) β MAY THE OPEN FOLDER TAKE ANOTHER FOLDER INSIDE IT?
|
|
@@ -1461,12 +1835,83 @@ export default function ViewSidebar({
|
|
| 1461 |
* free (contract C3). Nothing about it is now stated in two places.
|
| 1462 |
*/
|
| 1463 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1464 |
const create = () => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1465 |
const value = name.trim();
|
| 1466 |
if (!value || !creating) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1467 |
// Views start private. The Share view dialog is the single place where people choose the
|
| 1468 |
// audience and whether each recipient can view or edit, so creation and sharing cannot drift.
|
| 1469 |
onCreate(value, creating, { edit: "personal" });
|
|
|
|
|
|
|
|
|
|
| 1470 |
setName("");
|
| 1471 |
setCreating(null);
|
| 1472 |
// WAVE 20 item 20 β the two steps share ONE panel, so the anchor outlives step 1 and
|
|
@@ -1532,8 +1977,19 @@ export default function ViewSidebar({
|
|
| 1532 |
* The FOLDER door still closes it: that path is a single step and has no second panel
|
| 1533 |
* to disagree with. Moving it too would be a change the ruling does not ask for.
|
| 1534 |
*/
|
| 1535 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1536 |
setCreatingFolder(false);
|
|
|
|
| 1537 |
setCreating(mode);
|
| 1538 |
};
|
| 1539 |
/**
|
|
@@ -1713,6 +2169,56 @@ export default function ViewSidebar({
|
|
| 1713 |
{({ canBack: canDataBack, back: stepDataBack }) => (
|
| 1714 |
<>
|
| 1715 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1716 |
{/* I14 β "+ Create newβ¦", left-aligned, opening a flyout to the RIGHT of the rail that
|
| 1717 |
lists every creatable view type AND "Folder".
|
| 1718 |
|
|
@@ -1776,10 +2282,14 @@ export default function ViewSidebar({
|
|
| 1776 |
strokeLinecap="round"
|
| 1777 |
/>
|
| 1778 |
</svg>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1779 |
<input
|
| 1780 |
type="text"
|
| 1781 |
value={viewQuery}
|
| 1782 |
-
placeholder="Find
|
| 1783 |
aria-label="Find a view"
|
| 1784 |
onChange={(event) => setViewQuery(event.target.value)}
|
| 1785 |
onKeyDown={(event) => {
|
|
@@ -1966,26 +2476,6 @@ export default function ViewSidebar({
|
|
| 1966 |
</AnchoredOverlay>
|
| 1967 |
)}
|
| 1968 |
|
| 1969 |
-
{viewNeedle ? (
|
| 1970 |
-
<div className="cg-fold-empty" data-view-folder-path>
|
| 1971 |
-
Showing matches in every folder
|
| 1972 |
-
</div>
|
| 1973 |
-
) : (
|
| 1974 |
-
<nav
|
| 1975 |
-
className="cg-fold-head cg-view-path cg-segmented-path"
|
| 1976 |
-
data-view-folder-path
|
| 1977 |
-
aria-label="View folder location"
|
| 1978 |
-
>
|
| 1979 |
-
<PathBackButton
|
| 1980 |
-
disabled={atId === null && !canDataBack}
|
| 1981 |
-
onClick={() => {
|
| 1982 |
-
if (atId !== null) setAt(level.parent);
|
| 1983 |
-
else stepDataBack();
|
| 1984 |
-
}}
|
| 1985 |
-
/>
|
| 1986 |
-
</nav>
|
| 1987 |
-
)}
|
| 1988 |
-
|
| 1989 |
<div className="cg-view-list cg-views-scroll">
|
| 1990 |
{levelGroups.rows.map((group) => {
|
| 1991 |
const gid = group.folder?.id ?? null;
|
|
@@ -1998,7 +2488,7 @@ export default function ViewSidebar({
|
|
| 1998 |
* fall to level 1 and to "not hidden" β which is exactly where they rendered before this
|
| 1999 |
* ticket. The same is true of both `folder: null` groups.
|
| 2000 |
*/
|
| 2001 |
-
const asLeaves =
|
| 2002 |
/**
|
| 2003 |
* ββ WAVE 40 Β· T28 (owner instruction 30) β THE PIN GROUP: the unfiled default views,
|
| 2004 |
* rendered above every folder.
|
|
@@ -2262,6 +2752,9 @@ export default function ViewSidebar({
|
|
| 2262 |
className={
|
| 2263 |
"cg-view-row" +
|
| 2264 |
(active ? " is-active" : "") +
|
|
|
|
|
|
|
|
|
|
| 2265 |
(view.config?.cohortLock ? " cg-view-lockset" : "") +
|
| 2266 |
// β ITEM 5 (C7) β the same two marks the folder drag uses: the row being
|
| 2267 |
// carried fades, and the row it would land ABOVE draws an insertion rule.
|
|
@@ -2325,7 +2818,32 @@ export default function ViewSidebar({
|
|
| 2325 |
<button
|
| 2326 |
type="button"
|
| 2327 |
className="cg-view-main"
|
| 2328 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2329 |
// Item 9 kept this tooltip rather than dropping it as redundant: BOTH lines
|
| 2330 |
// ellipsis at 188px, so the hover is now the only way to read either one in
|
| 2331 |
// full. It used to show the note INSTEAD of the name, which meant a
|
|
@@ -2570,6 +3088,76 @@ export default function ViewSidebar({
|
|
| 2570 |
)}
|
| 2571 |
</DataDatabaseNavigator>
|
| 2572 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2573 |
{/* I11c β the folder "β¦" menu. Rename Β· Add to cohort Β· Duplicate Β· Delete.
|
| 2574 |
WAVE 20 item 22 β every row now carries the SAME icon vocabulary the view row's
|
| 2575 |
menu uses (`MenuLabel` over `MENU_ICONS`), and Delete is red AT REST rather than
|
|
@@ -3317,7 +3905,11 @@ export default function ViewSidebar({
|
|
| 3317 |
{xlsxExportViews.map((view) => {
|
| 3318 |
const selected = exportViewIds.includes(view.id);
|
| 3319 |
return (
|
| 3320 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3321 |
<input
|
| 3322 |
type="checkbox"
|
| 3323 |
checked={selected}
|
|
|
|
| 1 |
+
import "../styles/wave46/rail-select.css";
|
| 2 |
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
| 3 |
import type { ReactNode } from "react";
|
| 4 |
import type { KeyboardEvent as ReactKeyboardEvent } from "react";
|
| 5 |
import { AnchoredOverlay } from "./OverlaySurface";
|
|
|
|
| 22 |
} from "./types";
|
| 23 |
import {
|
| 24 |
CREATABLE_MODES,
|
| 25 |
+
DATABASE_MARK_TONE,
|
| 26 |
+
DATABASE_SHAPE_PATHS,
|
| 27 |
+
folderTonePaint,
|
| 28 |
MODE_LABELS,
|
| 29 |
MODE_TONE,
|
| 30 |
SHARE_SHAPE,
|
|
|
|
| 135 |
);
|
| 136 |
}
|
| 137 |
|
| 138 |
+
/**
|
| 139 |
+
* β W46-T05 (owner instruction 12) - a DATABASE wears the database mark, not the folder glyph.
|
| 140 |
+
*
|
| 141 |
+
* Drawn from `DATABASE_SHAPE_PATHS` rather than from a second copy of the paths, same rule as
|
| 142 |
+
* `ShareMark` above: one idea, one drawing. Same `size` prop shape and the same 16x16 box as
|
| 143 |
+
* `FolderMark`, so a database row and a folder row keep identical metrics in the rail and the
|
| 144 |
+
* only thing that changes between them is the picture.
|
| 145 |
+
*
|
| 146 |
+
* β IT IS NOT IN `icons.tsx` AND IT IS NOT A `FolderShape`. A folder's mark is user-chosen and
|
| 147 |
+
* stored; this one is what the row IS, so it is local to the rail that draws it.
|
| 148 |
+
*
|
| 149 |
+
* Outline only, and it takes its paint from `folderTonePaint` exactly as `FolderMark` does. Both
|
| 150 |
+
* halves matter: a filled mark sitting directly above outlined view rows would make the rail read
|
| 151 |
+
* as two icon vocabularies, and a second source of colour would let the two marks drift apart.
|
| 152 |
+
*/
|
| 153 |
+
function DatabaseMark({ size = 16 }: { size?: number }) {
|
| 154 |
+
const paint = folderTonePaint(DATABASE_MARK_TONE);
|
| 155 |
+
return (
|
| 156 |
+
<svg
|
| 157 |
+
className="cg-folder-mark"
|
| 158 |
+
width={size}
|
| 159 |
+
height={size}
|
| 160 |
+
viewBox="0 0 16 16"
|
| 161 |
+
aria-hidden
|
| 162 |
+
>
|
| 163 |
+
{DATABASE_SHAPE_PATHS.map((s) => (
|
| 164 |
+
<path
|
| 165 |
+
key={s.d}
|
| 166 |
+
d={s.d}
|
| 167 |
+
fill="none"
|
| 168 |
+
stroke={paint.stroke}
|
| 169 |
+
strokeWidth={1.35}
|
| 170 |
+
strokeLinecap="round"
|
| 171 |
+
strokeLinejoin="round"
|
| 172 |
+
/>
|
| 173 |
+
))}
|
| 174 |
+
</svg>
|
| 175 |
+
);
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
/** What the rail's share mark says, once it has been decided that there is one to show. */
|
| 179 |
export interface ViewShareMark {
|
| 180 |
title: string;
|
|
|
|
| 512 |
);
|
| 513 |
}
|
| 514 |
|
| 515 |
+
/** β W46-T08 (owner instruction 26) - THE FORWARD TWIN, drawn beside `PathBackButton` and never
|
| 516 |
+
* apart from it, so the two halves of one history control cannot grow different shapes.
|
| 517 |
+
* β ITS LABEL IS "Forward", NEVER A SECOND "Back": `verify_w45_data_applications.py` counts the
|
| 518 |
+
* Back control's exact label literal and expects exactly one, so duplicating it is not a
|
| 519 |
+
* cosmetic slip. Two controls one pixel apart answering to the same name is also, plainly, wrong
|
| 520 |
+
* for anyone listening rather than looking.
|
| 521 |
+
* A disabled forward keeps `.cg-path-history-button:disabled`, which dims it rather than merely
|
| 522 |
+
* refusing the click: nothing ahead has to READ as nothing ahead. */
|
| 523 |
+
function PathForwardButton({
|
| 524 |
+
disabled,
|
| 525 |
+
onClick,
|
| 526 |
+
}: {
|
| 527 |
+
disabled: boolean;
|
| 528 |
+
onClick: () => void;
|
| 529 |
+
}) {
|
| 530 |
+
return (
|
| 531 |
+
<button
|
| 532 |
+
type="button"
|
| 533 |
+
className="cg-path-history-button"
|
| 534 |
+
aria-label="Forward"
|
| 535 |
+
title="Forward"
|
| 536 |
+
disabled={disabled}
|
| 537 |
+
onClick={onClick}
|
| 538 |
+
>
|
| 539 |
+
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true">
|
| 540 |
+
<path
|
| 541 |
+
d="M6.2 3.6 10.6 8l-4.4 4.4"
|
| 542 |
+
stroke="currentColor"
|
| 543 |
+
strokeWidth="1.35"
|
| 544 |
+
strokeLinecap="round"
|
| 545 |
+
strokeLinejoin="round"
|
| 546 |
+
/>
|
| 547 |
+
</svg>
|
| 548 |
+
</button>
|
| 549 |
+
);
|
| 550 |
+
}
|
| 551 |
+
|
| 552 |
+
/** β W46-T08 - ONE breadcrumb drawing for both layers, for the same reason the Back button is one
|
| 553 |
+
* component: a path the person reads constantly must look identical whichever half of the rail
|
| 554 |
+
* drew it. A segment is a DESTINATION, so every ancestor is a real button that jumps straight
|
| 555 |
+
* there and the current one is marked `aria-current` and inert.
|
| 556 |
+
* β The separator is an ASCII slash. No dash of any width reaches this row (standing rule 2), and
|
| 557 |
+
* `folderPath` is already joined with " / " elsewhere in this file. */
|
| 558 |
+
function PathCrumbs({
|
| 559 |
+
layer,
|
| 560 |
+
segments,
|
| 561 |
+
}: {
|
| 562 |
+
layer: "data" | "view";
|
| 563 |
+
segments: readonly { key: string; label: string; go: () => void }[];
|
| 564 |
+
}) {
|
| 565 |
+
return (
|
| 566 |
+
<div className="cg-path-segments">
|
| 567 |
+
{segments.map((segment, index) => {
|
| 568 |
+
const last = index === segments.length - 1;
|
| 569 |
+
return (
|
| 570 |
+
<span className="cg-path-segment-wrap" key={segment.key}>
|
| 571 |
+
{index > 0 ? (
|
| 572 |
+
<span className="cg-path-separator" aria-hidden="true">
|
| 573 |
+
/
|
| 574 |
+
</span>
|
| 575 |
+
) : null}
|
| 576 |
+
<button
|
| 577 |
+
type="button"
|
| 578 |
+
className="cg-path-segment"
|
| 579 |
+
data-data-path-segment={layer === "data" ? "" : undefined}
|
| 580 |
+
data-view-path-segment={layer === "view" ? "" : undefined}
|
| 581 |
+
title={segment.label}
|
| 582 |
+
aria-current={last ? "page" : undefined}
|
| 583 |
+
disabled={last}
|
| 584 |
+
onClick={segment.go}
|
| 585 |
+
>
|
| 586 |
+
{segment.label}
|
| 587 |
+
</button>
|
| 588 |
+
</span>
|
| 589 |
+
);
|
| 590 |
+
})}
|
| 591 |
+
</div>
|
| 592 |
+
);
|
| 593 |
+
}
|
| 594 |
+
|
| 595 |
type DataNavigatorLevel =
|
| 596 |
| { kind: "root" }
|
| 597 |
| { kind: "origin"; label: string }
|
|
|
|
| 624 |
);
|
| 625 |
const [renamingFolder, setRenamingFolder] = useState<string | null>(null);
|
| 626 |
const [folderName, setFolderName] = useState("");
|
| 627 |
+
// W46-T04 - the data layer's find box, the twin of the view layer's `viewQuery`. Local and
|
| 628 |
+
// never persisted, for the same reason: a search is a moment, not a setting. It filters the
|
| 629 |
+
// rows of the CURRENT level only (source groups and user folders at the root, databases
|
| 630 |
+
// inside one), so a query never changes where you are standing.
|
| 631 |
+
const [dataQuery, setDataQuery] = useState("");
|
| 632 |
|
| 633 |
const dropDatabase = (event: React.DragEvent<HTMLElement>, folderId: string | null) => {
|
| 634 |
if (!onMove) return;
|
|
|
|
| 685 |
}
|
| 686 |
const dataLevel = dataPathState.levels[dataPathState.at] ?? { kind: "root" as const };
|
| 687 |
const canDataBack = dataPathState.at > 0;
|
| 688 |
+
/** W46-T08: the levels array was ALREADY an index into history and `pushDataLevel` already
|
| 689 |
+
* truncates anything ahead, so Forward here is one derived boolean, not a second state
|
| 690 |
+
* machine beside this one. */
|
| 691 |
+
const canDataForward = dataPathState.at < dataPathState.levels.length - 1;
|
| 692 |
const pushDataLevel = (level: DataNavigatorLevel) => {
|
| 693 |
setDataPathState((current) => ({
|
| 694 |
levels: [...current.levels.slice(0, current.at + 1), level],
|
|
|
|
| 707 |
if (dataNavigatorLevelKey(level) === dataNavigatorLevelKey(dataLevel)) return;
|
| 708 |
pushDataLevel(level);
|
| 709 |
};
|
| 710 |
+
/** W46-T08 - the Data breadcrumb is derived from the CURRENT LEVEL, not from `levels`: that
|
| 711 |
+
* array is history (where the person has been), and a path bar answers a different question
|
| 712 |
+
* (where the person IS). A `DataDatabaseFolder` carries no parent, so this side of the rail is
|
| 713 |
+
* exactly two deep and the walk `folderPath` does for View folders has nothing to walk. */
|
| 714 |
+
const dataLevelLabel = (level: DataNavigatorLevel): string => {
|
| 715 |
+
if (level.kind === "root") return "All databases";
|
| 716 |
+
if (level.kind === "origin") return level.label;
|
| 717 |
+
if (level.kind === "folder")
|
| 718 |
+
return folders.find((folder) => folder.id === level.id)?.name ?? "Folder";
|
| 719 |
+
return databases.find((database) => database.key === level.key)?.label ?? "Database";
|
| 720 |
+
};
|
| 721 |
+
const dataRootLevel: DataNavigatorLevel = { kind: "root" };
|
| 722 |
+
const dataPathSegments: { key: string; label: string; level: DataNavigatorLevel }[] = [
|
| 723 |
+
{ key: "root", label: dataLevelLabel(dataRootLevel), level: dataRootLevel },
|
| 724 |
+
...(dataLevel.kind === "root"
|
| 725 |
+
? []
|
| 726 |
+
: [
|
| 727 |
+
{
|
| 728 |
+
key: dataNavigatorLevelKey(dataLevel),
|
| 729 |
+
label: dataLevelLabel(dataLevel),
|
| 730 |
+
level: dataLevel as DataNavigatorLevel,
|
| 731 |
+
},
|
| 732 |
+
]),
|
| 733 |
+
];
|
| 734 |
const openDatabase = (database: DataDatabase) => {
|
| 735 |
if (database.externalHref) return;
|
| 736 |
visitDataLevel({ kind: "database", key: database.key });
|
|
|
|
| 741 |
const draggable = !!onMove && !database.protected && database.managedBy !== "loopable";
|
| 742 |
const content = (
|
| 743 |
<>
|
| 744 |
+
<DatabaseMark size={16} />
|
| 745 |
<span className="cg-fold-name">{database.label}</span>
|
| 746 |
{database.locked ? (
|
| 747 |
<span
|
|
|
|
| 805 |
return <>{children({ canBack: false, back: () => undefined })}</>;
|
| 806 |
}
|
| 807 |
|
| 808 |
+
const dataNeedle = dataQuery.trim().toLowerCase();
|
| 809 |
+
const matchesNeedle = (label: string) =>
|
| 810 |
+
!dataNeedle || label.toLowerCase().includes(dataNeedle);
|
| 811 |
+
const levelDatabases = (
|
| 812 |
dataLevel.kind === "origin"
|
| 813 |
? sourceGroups.find((group) => group.label === dataLevel.label)?.databases ?? []
|
| 814 |
: dataLevel.kind === "folder"
|
| 815 |
? databases.filter((database) => database.folderId === dataLevel.id)
|
| 816 |
+
: []
|
| 817 |
+
).filter((database) => matchesNeedle(database.label));
|
| 818 |
+
const levelSourceGroups = sourceGroups.filter((group) => matchesNeedle(group.label));
|
| 819 |
+
const levelFolders = folders.filter((folder) => matchesNeedle(folder.name));
|
| 820 |
|
| 821 |
return (
|
| 822 |
<div className="cg-data-tree" data-data-path-tree>
|
|
|
|
| 827 |
aria-label="Data location"
|
| 828 |
>
|
| 829 |
<PathBackButton disabled={!canDataBack} onClick={() => stepDataLevel(-1)} />
|
| 830 |
+
<PathForwardButton disabled={!canDataForward} onClick={() => stepDataLevel(1)} />
|
| 831 |
+
<PathCrumbs
|
| 832 |
+
layer="data"
|
| 833 |
+
segments={dataPathSegments.map((segment) => ({
|
| 834 |
+
key: segment.key,
|
| 835 |
+
label: segment.label,
|
| 836 |
+
go: () => visitDataLevel(segment.level),
|
| 837 |
+
}))}
|
| 838 |
+
/>
|
| 839 |
</nav>
|
| 840 |
) : null}
|
| 841 |
|
| 842 |
+
{/* β W46-T04 (owner instruction 12) - THE CREATE DOOR AND THE FIND BOX BELONG TO EVERY
|
| 843 |
+
DATA LEVEL, not to the root alone. The door used to render under
|
| 844 |
+
`dataLevel.kind === "root"`, so drilling into a source group or a user folder left the
|
| 845 |
+
rail with rows and nothing else; the person could see two databases and had no way to
|
| 846 |
+
make a third without walking back out.
|
| 847 |
+
β THE GUARD IS `!== "database"`, NOT "always": at the database level this component
|
| 848 |
+
hands off to the view layer through `children`, and that layer draws its OWN
|
| 849 |
+
"+ Create newβ¦" and find box. Rendering here as well would put two of each on one
|
| 850 |
+
screen. Same classes as the view layer's pair (`cg-data-create` wraps the host's
|
| 851 |
+
control; `cg-find-view` is the view layer's own box) because the two layers must be
|
| 852 |
+
indistinguishable in this row, and lookalike classes drift apart. */}
|
| 853 |
+
{dataLevel.kind !== "database" && createControl ? (
|
| 854 |
+
<div className="cg-data-create">{createControl}</div>
|
| 855 |
+
) : null}
|
| 856 |
+
{dataLevel.kind !== "database" ? (
|
| 857 |
+
<div className="cg-find-view">
|
| 858 |
+
<svg
|
| 859 |
+
className="cg-find-view-icon"
|
| 860 |
+
width="14"
|
| 861 |
+
height="14"
|
| 862 |
+
viewBox="0 0 16 16"
|
| 863 |
+
fill="none"
|
| 864 |
+
aria-hidden="true"
|
| 865 |
+
>
|
| 866 |
+
<circle cx="7" cy="7" r="4.4" stroke="currentColor" strokeWidth="1.35" />
|
| 867 |
+
<path
|
| 868 |
+
d="m10.4 10.4 3.1 3.1"
|
| 869 |
+
stroke="currentColor"
|
| 870 |
+
strokeWidth="1.35"
|
| 871 |
+
strokeLinecap="round"
|
| 872 |
+
/>
|
| 873 |
+
</svg>
|
| 874 |
+
<input
|
| 875 |
+
type="text"
|
| 876 |
+
value={dataQuery}
|
| 877 |
+
placeholder="Findβ¦"
|
| 878 |
+
aria-label="Find a database"
|
| 879 |
+
onChange={(event) => setDataQuery(event.target.value)}
|
| 880 |
+
onKeyDown={(event) => {
|
| 881 |
+
if (event.key === "Escape") setDataQuery("");
|
| 882 |
+
}}
|
| 883 |
+
/>
|
| 884 |
+
</div>
|
| 885 |
+
) : null}
|
| 886 |
+
|
| 887 |
{dataLevel.kind === "root" ? (
|
| 888 |
<div className="cg-data-path-level" data-data-level="root">
|
| 889 |
+
{levelSourceGroups.map((group) => (
|
| 890 |
<div key={group.label} className="cg-fold cg-data-origin" {...dropProps(null)}>
|
| 891 |
<div className="cg-fold-head">
|
| 892 |
<button
|
|
|
|
| 902 |
</div>
|
| 903 |
</div>
|
| 904 |
))}
|
| 905 |
+
{levelFolders.map((folder) => {
|
| 906 |
const members = databases.filter((database) => database.folderId === folder.id);
|
| 907 |
return (
|
| 908 |
<div
|
|
|
|
| 940 |
</div>
|
| 941 |
);
|
| 942 |
})}
|
| 943 |
+
{dataNeedle && levelSourceGroups.length === 0 && levelFolders.length === 0 ? (
|
| 944 |
+
<div className="cg-fold-empty">No matches.</div>
|
| 945 |
+
) : null}
|
| 946 |
</div>
|
| 947 |
) : dataLevel.kind === "database" ? (
|
| 948 |
<div className="cg-data-database-views" data-data-level="database">
|
|
|
|
| 951 |
) : (
|
| 952 |
<div className="cg-data-path-level" data-data-level={dataLevel.kind} {...dropProps(null)}>
|
| 953 |
{levelDatabases.map(pathDatabaseRow)}
|
| 954 |
+
{/* The empty line must say WHY it is empty: under a live query "No databases in this
|
| 955 |
+
folder" is simply false, and a wrong empty state on the control this ticket just
|
| 956 |
+
un-hid is what QA reopens. */}
|
| 957 |
{levelDatabases.length === 0 ? (
|
| 958 |
+
<div className="cg-fold-empty">
|
| 959 |
+
{dataNeedle ? "No matches." : "No databases in this folder."}
|
| 960 |
+
</div>
|
| 961 |
) : null}
|
| 962 |
</div>
|
| 963 |
)}
|
| 964 |
|
|
|
|
|
|
|
|
|
|
| 965 |
{folderMenu ? (
|
| 966 |
<AnchoredOverlay
|
| 967 |
anchor={folderMenu.anchor}
|
|
|
|
| 1169 |
/** C3 begins with the View whose menu opened this pane; later picks are explicit. */
|
| 1170 |
const [exportViewIds, setExportViewIds] = useState<string[]>([]);
|
| 1171 |
const [exportBulk, setExportBulk] = useState(false);
|
| 1172 |
+
/**
|
| 1173 |
+
* W46-T02 - THE RAIL'S MULTI-SELECT. Three pieces, and the split is load-bearing.
|
| 1174 |
+
*
|
| 1175 |
+
* `railSel` is the selected set. `railAnchorId` is the last PLAINLY clicked row, which is what
|
| 1176 |
+
* a shift-click measures its range from; folding the two together would make every shift-click
|
| 1177 |
+
* re-anchor and the range would creep. `railDeleteArmed` is the one confirm step: deleting a
|
| 1178 |
+
* view has no store history to undo it, so nothing calls `onDelete` until this is true.
|
| 1179 |
+
*/
|
| 1180 |
+
const [railSel, setRailSel] = useState<readonly string[]>([]);
|
| 1181 |
+
const [railAnchorId, setRailAnchorId] = useState<string | null>(null);
|
| 1182 |
+
const [railDeleteArmed, setRailDeleteArmed] = useState(false);
|
| 1183 |
const xlsxExportViews = useMemo(() => {
|
| 1184 |
const allowed = new Set(exportableViewIds ?? []);
|
| 1185 |
return views.filter((view) => allowed.has(view.id));
|
|
|
|
| 1233 |
* preference that survives a reload is a folder that is open when the user next logs in.
|
| 1234 |
*/
|
| 1235 |
// Recovered from 7f6a1c0 (W42-T43): one location replaces the old expand/collapse tree.
|
| 1236 |
+
/**
|
| 1237 |
+
* ββ W46-T08 (owner instruction 26) - THE VIEW LAYER'S LOCATION IS NOW AN INDEX INTO HISTORY,
|
| 1238 |
+
* modelled on `dataPathState` one layer down so the two halves of one rail cannot disagree
|
| 1239 |
+
* about what Back and Forward mean.
|
| 1240 |
+
*
|
| 1241 |
+
* β `at` AND `setAt` STAY, deliberately, as a derived value and a derived setter. `setAt` has
|
| 1242 |
+
* five call sites (the database switch, both create-into-a-folder paths, the Back control and
|
| 1243 |
+
* the folder rows), and w44's gate pins three of those literals. Adding a SECOND history array
|
| 1244 |
+
* beside `at` would leave the folder rows advancing the location without truncating, so Forward
|
| 1245 |
+
* would walk into a folder nobody just left. Routing every existing caller through one
|
| 1246 |
+
* push-and-truncate is the whole point.
|
| 1247 |
+
*/
|
| 1248 |
+
const [viewPath, setViewPath] = useState<{ ids: (string | null)[]; at: number }>(() => {
|
| 1249 |
+
const restored = readRailPath(activeDatabaseKey);
|
| 1250 |
+
return restored ? { ids: [null, restored], at: 1 } : { ids: [null], at: 0 };
|
| 1251 |
+
});
|
| 1252 |
+
const at = viewPath.ids[viewPath.at] ?? null;
|
| 1253 |
+
const setAt = (next: string | null) =>
|
| 1254 |
+
setViewPath((current) =>
|
| 1255 |
+
(current.ids[current.at] ?? null) === next
|
| 1256 |
+
? current
|
| 1257 |
+
: { ids: [...current.ids.slice(0, current.at + 1), next], at: current.at + 1 }
|
| 1258 |
+
);
|
| 1259 |
+
const stepViewLevel = (delta: number) =>
|
| 1260 |
+
setViewPath((current) => {
|
| 1261 |
+
const index = current.at + delta;
|
| 1262 |
+
return index < 0 || index >= current.ids.length ? current : { ...current, at: index };
|
| 1263 |
+
});
|
| 1264 |
+
const canViewBack = viewPath.at > 0;
|
| 1265 |
+
const canViewForward = viewPath.at < viewPath.ids.length - 1;
|
| 1266 |
const railDatabaseRef = useRef(activeDatabaseKey);
|
| 1267 |
if (railDatabaseRef.current !== activeDatabaseKey) {
|
| 1268 |
railDatabaseRef.current = activeDatabaseKey;
|
| 1269 |
const restored = readRailPath(activeDatabaseKey);
|
| 1270 |
+
// β A DATABASE CHANGE RESTORES A LOCATION, IT DOES NOT TRAVEL TO ONE. Pushing here would
|
| 1271 |
+
// carry the previous database's folders into this one's history, and Forward would then point
|
| 1272 |
+
// at a folder that does not exist on the database now on screen. The Data navigator resets
|
| 1273 |
+
// its own `levels` on the same signal for the same reason.
|
| 1274 |
+
setViewPath(restored ? { ids: [null, restored], at: 1 } : { ids: [null], at: 0 });
|
| 1275 |
}
|
| 1276 |
const [folderMenu, setFolderMenu] = useState<{ id: string; anchor: HTMLElement } | null>(null);
|
| 1277 |
const [renamingFolder, setRenamingFolder] = useState<string | null>(null);
|
|
|
|
| 1575 |
),
|
| 1576 |
[atId, foldersOn, folders, shownViews, folderIdOf]
|
| 1577 |
);
|
| 1578 |
+
/**
|
| 1579 |
+
* β W46-T08 - the View breadcrumb. The root segment is the DATABASE, not a generic word: at
|
| 1580 |
+
* this level the Data path row has handed the rail over and its own crumbs are off screen, so
|
| 1581 |
+
* without the database name the person is reading a path with no beginning. Clicking it returns
|
| 1582 |
+
* to the database's unfiled level, which is what `at === null` already means here.
|
| 1583 |
+
*/
|
| 1584 |
+
const viewPathSegments = useMemo(
|
| 1585 |
+
() => [
|
| 1586 |
+
{
|
| 1587 |
+
id: null as string | null,
|
| 1588 |
+
name:
|
| 1589 |
+
databases.find((database) => database.key === activeDatabaseKey)?.label ?? "All views",
|
| 1590 |
+
},
|
| 1591 |
+
...folderPath(atId, foldersOn ? (folders as GridFolder[]) : []).map((folder) => ({
|
| 1592 |
+
id: folder.id as string | null,
|
| 1593 |
+
name: folder.name,
|
| 1594 |
+
})),
|
| 1595 |
+
],
|
| 1596 |
+
[activeDatabaseKey, atId, databases, folders, foldersOn]
|
| 1597 |
+
);
|
| 1598 |
const levelGroups = useMemo(() => {
|
| 1599 |
const pin: typeof groups = [];
|
| 1600 |
const heads: typeof groups = [];
|
|
|
|
| 1626 |
}
|
| 1627 |
if (childIds.has(groupId)) heads.push(group);
|
| 1628 |
}
|
| 1629 |
+
/**
|
| 1630 |
+
* ββ W46-T07 (owner instruction 25) - THE DEFAULT VIEW SORTS BELOW FOLDERS.
|
| 1631 |
+
* The pinned group (`pin`) carries the unfiled default view; `heads` are the folder heads and
|
| 1632 |
+
* `leaves` the loose ungrouped views. The pin now falls AFTER every folder head.
|
| 1633 |
+
*
|
| 1634 |
+
* β THIS REVERSES WAVE 40 Β· T28, whose comment in `folders.ts` quotes owner instruction 30
|
| 1635 |
+
* verbatim: "when it is not in a folder it must sit at the very top above all folders unless
|
| 1636 |
+
* the user moves it down". Instruction 25 is the NEWER instruction and it wins. Do not
|
| 1637 |
+
* "restore" the old order on sight - an unexplained swap is exactly what invites that, which
|
| 1638 |
+
* is why this note exists.
|
| 1639 |
+
*
|
| 1640 |
+
* The reorder is done HERE, at the render site, and NOT in `folders.ts::groupByFolder`:
|
| 1641 |
+
* that pure function is shared by more than this rail, and its test
|
| 1642 |
+
* (`_test/folders.test.ts`, run by `verify_folders.py`) asserts `railGroups[0].pinned === true`.
|
| 1643 |
+
* The test asserts what the FUNCTION RETURNS; this line changes only what the RAIL PAINTS,
|
| 1644 |
+
* so the contract and the test both stay true and green.
|
| 1645 |
+
*
|
| 1646 |
+
* `rows` is both what the row loop paints and what `renderedViewIds` flattens for the
|
| 1647 |
+
* shift-click range, so one swap here keeps painted order and selection order identical.
|
| 1648 |
+
*/
|
| 1649 |
+
return { heads, rows: [...heads, ...pin, ...leaves] };
|
| 1650 |
}, [groups, level, atId, viewNeedle]);
|
| 1651 |
+
/**
|
| 1652 |
+
* W46-T02 - DOES THIS GROUP RENDER ITS VIEWS AS ROWS? One arrow, read by the row loop below
|
| 1653 |
+
* AND by the order the shift-range is measured in. Written twice, the two copies drift and the
|
| 1654 |
+
* range stops matching what the person sees, which is the only thing a shift-click means.
|
| 1655 |
+
*/
|
| 1656 |
+
const isLeafGroup = useCallback(
|
| 1657 |
+
(group: { folder?: { id: string } | null }) =>
|
| 1658 |
+
!group.folder || (group.folder.id ?? null) === atId || !!viewNeedle,
|
| 1659 |
+
[atId, viewNeedle]
|
| 1660 |
+
);
|
| 1661 |
+
/** The ids in RENDER order: pinned, then folder heads, then leaves, flattened as drawn. */
|
| 1662 |
+
const renderedViewIds = useMemo(
|
| 1663 |
+
() =>
|
| 1664 |
+
levelGroups.rows.flatMap((group) =>
|
| 1665 |
+
isLeafGroup(group) ? group.items.map((view) => view.id) : []
|
| 1666 |
+
),
|
| 1667 |
+
[levelGroups, isLeafGroup]
|
| 1668 |
+
);
|
| 1669 |
+
/**
|
| 1670 |
+
* The selection INTERSECTED with what is on screen, in render order. A search or a step into a
|
| 1671 |
+
* folder can take a selected row out of view while the set still holds its id; counting those
|
| 1672 |
+
* would make the bar say "3 views" over two rows and, worse, would let the confirm delete a
|
| 1673 |
+
* view the person can no longer see.
|
| 1674 |
+
*/
|
| 1675 |
+
const railSelected = useMemo(() => {
|
| 1676 |
+
const chosen = new Set(railSel);
|
| 1677 |
+
return renderedViewIds.filter((id) => chosen.has(id));
|
| 1678 |
+
}, [railSel, renderedViewIds]);
|
| 1679 |
+
const railSelectedSet = useMemo(() => new Set(railSelected), [railSelected]);
|
| 1680 |
+
/** Only views this viewer may edit, and never a default/system view. */
|
| 1681 |
+
const railDeletable = useMemo(() => {
|
| 1682 |
+
const byId = new Map(views.map((view) => [view.id, view]));
|
| 1683 |
+
return railSelected
|
| 1684 |
+
.map((id) => byId.get(id))
|
| 1685 |
+
.filter((view): view is SavedView =>
|
| 1686 |
+
!!view && !isUndeletableView(view) && mayEditView(view, viewer));
|
| 1687 |
+
}, [railSelected, views, viewer]);
|
| 1688 |
+
/** The bulk-export path caps a pick at 20 checkboxes; the bar hands it the same 20. */
|
| 1689 |
+
const railExportIds = useMemo(() => {
|
| 1690 |
+
const allowed = new Set(exportableViewIds ?? []);
|
| 1691 |
+
return railSelected.filter((id) => allowed.has(id)).slice(0, 20);
|
| 1692 |
+
}, [railSelected, exportableViewIds]);
|
| 1693 |
+
const clearRailSel = useCallback(() => {
|
| 1694 |
+
setRailSel([]);
|
| 1695 |
+
setRailAnchorId(null);
|
| 1696 |
+
setRailDeleteArmed(false);
|
| 1697 |
+
}, []);
|
| 1698 |
+
/**
|
| 1699 |
+
* ESCAPE CLEARS THE SELECTION, AND NOTHING ELSE.
|
| 1700 |
+
*
|
| 1701 |
+
* Scoped three ways so it cannot close something the person did not ask to close. It is only
|
| 1702 |
+
* bound while a selection exists; `AnchoredOverlay` already takes Escape on a DOCUMENT CAPTURE
|
| 1703 |
+
* listener and stops propagation, so no open menu, export pane or picker ever reaches this
|
| 1704 |
+
* bubble-phase handler; and a rename box in flight keeps its own Escape.
|
| 1705 |
+
*/
|
| 1706 |
+
useEffect(() => {
|
| 1707 |
+
if (railSel.length === 0) return;
|
| 1708 |
+
const onKey = (event: KeyboardEvent) => {
|
| 1709 |
+
if (event.key !== "Escape") return;
|
| 1710 |
+
if (renamingId || renamingFolder) return;
|
| 1711 |
+
const target = event.target as HTMLElement | null;
|
| 1712 |
+
const tag = target?.tagName;
|
| 1713 |
+
if (tag === "INPUT" || tag === "TEXTAREA" || target?.isContentEditable) return;
|
| 1714 |
+
clearRailSel();
|
| 1715 |
+
};
|
| 1716 |
+
document.addEventListener("keydown", onKey);
|
| 1717 |
+
return () => document.removeEventListener("keydown", onKey);
|
| 1718 |
+
}, [railSel.length, renamingId, renamingFolder, clearRailSel]);
|
| 1719 |
const folderMenuF = folderMenu ? folders?.find((f) => f.id === folderMenu.id) : undefined;
|
| 1720 |
/**
|
| 1721 |
* ββ WAVE 41 Β· T33 (instruction 12, R1) β MAY THE OPEN FOLDER TAKE ANOTHER FOLDER INSIDE IT?
|
|
|
|
| 1835 |
* free (contract C3). Nothing about it is now stated in two places.
|
| 1836 |
*/
|
| 1837 |
|
| 1838 |
+
/**
|
| 1839 |
+
* ββ W46-T01 β A VIEW CREATED INSIDE A FOLDER LANDS IN THAT FOLDER. Filed on arrival.
|
| 1840 |
+
*
|
| 1841 |
+
* β THE PLACEMENT IS NOT PASSED THROUGH `onCreate`, and that is the whole design of this
|
| 1842 |
+
* ticket. `onCreate` is `(name, mode, permissions)` and its ONE consumer is the grid's
|
| 1843 |
+
* `createView`; widening it with a fourth `parent` argument would declare a contract nothing
|
| 1844 |
+
* reads, which is a defect class in this repo rather than a fix. So the destination is applied
|
| 1845 |
+
* from here through `onItemMove` β the SAME channel the drag drop and the Move-to menu already
|
| 1846 |
+
* use, so a view has one way of being filed and not two that can drift apart.
|
| 1847 |
+
*
|
| 1848 |
+
* β A REF, NOT STATE. It must not cause a render of its own, and it must survive the render
|
| 1849 |
+
* that `onCreate` itself causes. It holds the destination, the ids that existed at the moment
|
| 1850 |
+
* Create was pressed, and the typed name, so the arrival can be identified exactly rather than
|
| 1851 |
+
* guessed at as "whichever view is new".
|
| 1852 |
+
*/
|
| 1853 |
+
const pendingFileRef = useRef<
|
| 1854 |
+
{ into: string; before: Set<string>; name: string } | null
|
| 1855 |
+
>(null);
|
| 1856 |
+
useEffect(() => {
|
| 1857 |
+
const pending = pendingFileRef.current;
|
| 1858 |
+
if (!pending) return;
|
| 1859 |
+
const arrivals = views.filter((view) => !pending.before.has(view.id));
|
| 1860 |
+
if (arrivals.length === 0) return;
|
| 1861 |
+
// Normally exactly one view arrives. If two land in the same window (a concurrent tab, a
|
| 1862 |
+
// refetch), the typed name is the discriminator; with no match this files nothing at all,
|
| 1863 |
+
// because moving the wrong view is worse than leaving the new one at the top level.
|
| 1864 |
+
const arrived =
|
| 1865 |
+
arrivals.length === 1
|
| 1866 |
+
? arrivals[0]
|
| 1867 |
+
: arrivals.find((view) => viewDisplayName(view) === pending.name);
|
| 1868 |
+
/*
|
| 1869 |
+
* β CLEARED WHETHER OR NOT IT FILES, and before the guard below can return. A destination
|
| 1870 |
+
* that outlived its own attempt would fire again on the next unrelated change to `views` and
|
| 1871 |
+
* move a view nobody asked to move.
|
| 1872 |
+
*/
|
| 1873 |
+
pendingFileRef.current = null;
|
| 1874 |
+
if (!arrived) return;
|
| 1875 |
+
// The same verdict the drag site asks (`mayFileView` over `mayEditView`, W34-T22), so a view
|
| 1876 |
+
// that could not be filed by dragging cannot be filed by being born here either.
|
| 1877 |
+
if (!mayFileView(arrived, mayEditView(arrived, viewer))) return;
|
| 1878 |
+
onItemMove?.(arrived.id, pending.into);
|
| 1879 |
+
}, [views, viewer, onItemMove]);
|
| 1880 |
+
|
| 1881 |
const create = () => {
|
| 1882 |
+
/*
|
| 1883 |
+
* β CLEARED FIRST, on every attempt. If an earlier create never produced a view (the host
|
| 1884 |
+
* refused it, or the pane was abandoned mid-flight), its destination must not survive to
|
| 1885 |
+
* catch some unrelated view that arrives later.
|
| 1886 |
+
*/
|
| 1887 |
+
pendingFileRef.current = null;
|
| 1888 |
const value = name.trim();
|
| 1889 |
if (!value || !creating) return;
|
| 1890 |
+
/*
|
| 1891 |
+
* The destination is re-checked HERE, at the commit, exactly as `createFolder` re-checks its
|
| 1892 |
+
* own parent below: the pane outlives the click that opened it, and the folder it was pointed
|
| 1893 |
+
* at can be deleted or arrive a level deeper from another tab while the name is being typed.
|
| 1894 |
+
* A refused destination leaves the view at the top level, which is where a view can always go.
|
| 1895 |
+
*
|
| 1896 |
+
* β TWO SOURCES, IN THIS ORDER. `folderParent` is the explicit destination a door set when it
|
| 1897 |
+
* opened the pane; `atId` is the folder the rail is currently standing in, which is what the
|
| 1898 |
+
* ordinary "+ Create new" door means by "here". Root is `null` from both, and then the effect
|
| 1899 |
+
* above is inert and the view is created at the root as before.
|
| 1900 |
+
*/
|
| 1901 |
+
const wanted = folderParent ?? atId;
|
| 1902 |
+
const into = wanted && mayNestFolder(nesting, wanted).ok ? wanted : null;
|
| 1903 |
+
if (into)
|
| 1904 |
+
pendingFileRef.current = {
|
| 1905 |
+
into,
|
| 1906 |
+
before: new Set(views.map((view) => view.id)),
|
| 1907 |
+
name: value,
|
| 1908 |
+
};
|
| 1909 |
// Views start private. The Share view dialog is the single place where people choose the
|
| 1910 |
// audience and whether each recipient can view or edit, so creation and sharing cannot drift.
|
| 1911 |
onCreate(value, creating, { edit: "personal" });
|
| 1912 |
+
// Filing into a folder the rail is not standing in has to OPEN it, or the view is created
|
| 1913 |
+
// invisibly β the same regression T34 recorded for folders, one surface over.
|
| 1914 |
+
if (into && into !== atId) setAt(into);
|
| 1915 |
setName("");
|
| 1916 |
setCreating(null);
|
| 1917 |
// WAVE 20 item 20 β the two steps share ONE panel, so the anchor outlives step 1 and
|
|
|
|
| 1977 |
* The FOLDER door still closes it: that path is a single step and has no second panel
|
| 1978 |
* to disagree with. Moving it too would be a change the ruling does not ask for.
|
| 1979 |
*/
|
| 1980 |
+
/**
|
| 1981 |
+
* β W46-T01 β IT TAKES A PARENT, exactly as its sibling `startFolder` already does, and the
|
| 1982 |
+
* default is the same `null`.
|
| 1983 |
+
*
|
| 1984 |
+
* β THE `setFolderParent` IS LOAD-BEARING EVEN THOUGH EVERY CALLER TAKES THE DEFAULT.
|
| 1985 |
+
* `startFolder(folderMenuF.id)` sets `folderParent` and nothing clears it when that pane is
|
| 1986 |
+
* abandoned, so opening the create menu afterwards would find a stale folder id sitting there
|
| 1987 |
+
* and `create` would file the new view into a folder the user walked away from. Setting it here
|
| 1988 |
+
* makes "+ Create new" mean the level the rail is actually standing in, every time.
|
| 1989 |
+
*/
|
| 1990 |
+
const startView = (mode: DisplayMode, parent: string | null = null) => {
|
| 1991 |
setCreatingFolder(false);
|
| 1992 |
+
setFolderParent(parent);
|
| 1993 |
setCreating(mode);
|
| 1994 |
};
|
| 1995 |
/**
|
|
|
|
| 2169 |
{({ canBack: canDataBack, back: stepDataBack }) => (
|
| 2170 |
<>
|
| 2171 |
|
| 2172 |
+
{/* ββ W46-T08 (owner instruction 26) - THE PATH ROW, MOVED. Owner, verbatim: *"this path
|
| 2173 |
+
navigation should be right under the button of 'Minimize views' and above the 'Create
|
| 2174 |
+
new...' button, i think that's where it should live."* It used to sit below the create
|
| 2175 |
+
door and the find box; it is a navigation row a person reads constantly, so it belongs
|
| 2176 |
+
at the top of what it navigates.
|
| 2177 |
+
β IT IS OUTSIDE `.cg-views-top`, AND THAT IS THE POINT. That row is the minimize strip
|
| 2178 |
+
and `verify_grid_ux.py` caps its source slice at 3,000 characters (2,599 in use). This
|
| 2179 |
+
is a different row, one the owner describes as sitting UNDER that button, so it renders
|
| 2180 |
+
after the live-region div and inside the Data navigator's database level, where it can
|
| 2181 |
+
reach both halves of the history. */}
|
| 2182 |
+
{viewNeedle ? (
|
| 2183 |
+
<div className="cg-fold-empty" data-view-folder-path>
|
| 2184 |
+
Showing matches in every folder
|
| 2185 |
+
</div>
|
| 2186 |
+
) : (
|
| 2187 |
+
<nav
|
| 2188 |
+
className="cg-fold-head cg-view-path cg-segmented-path"
|
| 2189 |
+
data-view-folder-path
|
| 2190 |
+
aria-label="View folder location"
|
| 2191 |
+
>
|
| 2192 |
+
<PathBackButton
|
| 2193 |
+
disabled={!canViewBack && atId === null && !canDataBack}
|
| 2194 |
+
onClick={() => {
|
| 2195 |
+
// β HISTORY FIRST, and the parent walk below is now UNREACHABLE, deliberately
|
| 2196 |
+
// left in place. `ids[0]` is always null, so `at === 0` implies `atId === null`
|
| 2197 |
+
// and the middle branch cannot run. It is kept because `setAt(level.parent)` would
|
| 2198 |
+
// PUSH the parent as a new location, which is the one thing Back must never do:
|
| 2199 |
+
// Forward would then have nothing to return to. Deleting the line would also drop
|
| 2200 |
+
// a literal two gates read, and re-deriving it later is how the push creeps back.
|
| 2201 |
+
// β CONSEQUENCE, and it is a real behaviour change: Back from a folder restored
|
| 2202 |
+
// out of storage now returns to the database root rather than to that folder's
|
| 2203 |
+
// parent, because history holds no ancestor for a location nobody walked to. Back
|
| 2204 |
+
// and Up are different controls, and this one is Back.
|
| 2205 |
+
if (canViewBack) stepViewLevel(-1);
|
| 2206 |
+
else if (atId !== null) setAt(level.parent);
|
| 2207 |
+
else stepDataBack();
|
| 2208 |
+
}}
|
| 2209 |
+
/>
|
| 2210 |
+
<PathForwardButton disabled={!canViewForward} onClick={() => stepViewLevel(1)} />
|
| 2211 |
+
<PathCrumbs
|
| 2212 |
+
layer="view"
|
| 2213 |
+
segments={viewPathSegments.map((segment) => ({
|
| 2214 |
+
key: segment.id ?? "__root__",
|
| 2215 |
+
label: segment.name,
|
| 2216 |
+
go: () => setAt(segment.id),
|
| 2217 |
+
}))}
|
| 2218 |
+
/>
|
| 2219 |
+
</nav>
|
| 2220 |
+
)}
|
| 2221 |
+
|
| 2222 |
{/* I14 β "+ Create newβ¦", left-aligned, opening a flyout to the RIGHT of the rail that
|
| 2223 |
lists every creatable view type AND "Folder".
|
| 2224 |
|
|
|
|
| 2282 |
strokeLinecap="round"
|
| 2283 |
/>
|
| 2284 |
</svg>
|
| 2285 |
+
{/* W46-T04 - the PLACEHOLDER reads "Findβ¦" so this box and the data layer's twin are
|
| 2286 |
+
the same control to the eye; the ACCESSIBLE NAME stays "Find a view", because a
|
| 2287 |
+
screen reader gets no layer context from three dots and because
|
| 2288 |
+
`verify_w45_data_applications.py` indexes on that exact literal. */}
|
| 2289 |
<input
|
| 2290 |
type="text"
|
| 2291 |
value={viewQuery}
|
| 2292 |
+
placeholder="Findβ¦"
|
| 2293 |
aria-label="Find a view"
|
| 2294 |
onChange={(event) => setViewQuery(event.target.value)}
|
| 2295 |
onKeyDown={(event) => {
|
|
|
|
| 2476 |
</AnchoredOverlay>
|
| 2477 |
)}
|
| 2478 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2479 |
<div className="cg-view-list cg-views-scroll">
|
| 2480 |
{levelGroups.rows.map((group) => {
|
| 2481 |
const gid = group.folder?.id ?? null;
|
|
|
|
| 2488 |
* fall to level 1 and to "not hidden" β which is exactly where they rendered before this
|
| 2489 |
* ticket. The same is true of both `folder: null` groups.
|
| 2490 |
*/
|
| 2491 |
+
const asLeaves = isLeafGroup(group);
|
| 2492 |
/**
|
| 2493 |
* ββ WAVE 40 Β· T28 (owner instruction 30) β THE PIN GROUP: the unfiled default views,
|
| 2494 |
* rendered above every folder.
|
|
|
|
| 2752 |
className={
|
| 2753 |
"cg-view-row" +
|
| 2754 |
(active ? " is-active" : "") +
|
| 2755 |
+
// W46-T02 - in the shift-selected range. Distinct from `is-active`, which says
|
| 2756 |
+
// "this is the table you are looking at" and can be true at the same time.
|
| 2757 |
+
(railSelectedSet.has(view.id) ? " is-railsel" : "") +
|
| 2758 |
(view.config?.cohortLock ? " cg-view-lockset" : "") +
|
| 2759 |
// β ITEM 5 (C7) β the same two marks the folder drag uses: the row being
|
| 2760 |
// carried fades, and the row it would land ABOVE draws an insertion rule.
|
|
|
|
| 2818 |
<button
|
| 2819 |
type="button"
|
| 2820 |
className="cg-view-main"
|
| 2821 |
+
/**
|
| 2822 |
+
* W46-T02 - PLAIN CLICK IS EXACTLY WHAT IT WAS; SHIFT EXTENDS A RANGE.
|
| 2823 |
+
*
|
| 2824 |
+
* A shift-click must NOT call `onSelect`: selecting rows to export or delete is
|
| 2825 |
+
* not a request to open a different table, and switching the person's open view
|
| 2826 |
+
* as a side effect of a selection gesture is the surprise this branch avoids.
|
| 2827 |
+
* With no anchor yet it falls through to the plain path, so the first click of
|
| 2828 |
+
* any gesture behaves the way every click did before this ticket.
|
| 2829 |
+
*/
|
| 2830 |
+
onClick={(event) => {
|
| 2831 |
+
if (event.shiftKey && railAnchorId && railAnchorId !== view.id) {
|
| 2832 |
+
const from = renderedViewIds.indexOf(railAnchorId);
|
| 2833 |
+
const to = renderedViewIds.indexOf(view.id);
|
| 2834 |
+
if (from >= 0 && to >= 0) {
|
| 2835 |
+
const lo = Math.min(from, to);
|
| 2836 |
+
const hi = Math.max(from, to);
|
| 2837 |
+
setRailSel(renderedViewIds.slice(lo, hi + 1));
|
| 2838 |
+
setRailDeleteArmed(false);
|
| 2839 |
+
return;
|
| 2840 |
+
}
|
| 2841 |
+
}
|
| 2842 |
+
setRailSel([]);
|
| 2843 |
+
setRailDeleteArmed(false);
|
| 2844 |
+
setRailAnchorId(view.id);
|
| 2845 |
+
onSelect(view.id);
|
| 2846 |
+
}}
|
| 2847 |
// Item 9 kept this tooltip rather than dropping it as redundant: BOTH lines
|
| 2848 |
// ellipsis at 188px, so the hover is now the only way to read either one in
|
| 2849 |
// full. It used to show the note INSTEAD of the name, which meant a
|
|
|
|
| 3088 |
)}
|
| 3089 |
</DataDatabaseNavigator>
|
| 3090 |
|
| 3091 |
+
{/* W46-T02 - THE SELECTION BAR. It exists only while rows are selected, it names the count,
|
| 3092 |
+
and it offers the two things a set of views is selected FOR.
|
| 3093 |
+
β DELETE ASKS ONCE, AND THE ASK IS NOT DECORATION: there is no store history behind a
|
| 3094 |
+
deleted view, so the confirm is the only thing standing between a mis-shift and work
|
| 3095 |
+
that cannot be brought back. `onDelete` is called from the armed branch alone. */}
|
| 3096 |
+
{railSelected.length > 0 && (
|
| 3097 |
+
<div className="cg-railsel" role="group" aria-label="Selected views">
|
| 3098 |
+
{railDeleteArmed ? (
|
| 3099 |
+
<>
|
| 3100 |
+
<span className="cg-railsel-ask">
|
| 3101 |
+
{railDeletable.length === 1
|
| 3102 |
+
? "Delete 1 view? This cannot be undone."
|
| 3103 |
+
: `Delete ${railDeletable.length} views? This cannot be undone.`}
|
| 3104 |
+
{railSelected.length > railDeletable.length
|
| 3105 |
+
&& ` ${railSelected.length - railDeletable.length} of them cannot be deleted `
|
| 3106 |
+
+ `and will stay.`}
|
| 3107 |
+
</span>
|
| 3108 |
+
<button
|
| 3109 |
+
type="button"
|
| 3110 |
+
className="is-danger"
|
| 3111 |
+
onClick={() => {
|
| 3112 |
+
for (const view of railDeletable) onDelete(view.id);
|
| 3113 |
+
clearRailSel();
|
| 3114 |
+
}}
|
| 3115 |
+
>
|
| 3116 |
+
Delete
|
| 3117 |
+
</button>
|
| 3118 |
+
<button type="button" onClick={() => setRailDeleteArmed(false)}>
|
| 3119 |
+
Keep them
|
| 3120 |
+
</button>
|
| 3121 |
+
</>
|
| 3122 |
+
) : (
|
| 3123 |
+
<>
|
| 3124 |
+
<span className="cg-railsel-count">
|
| 3125 |
+
{railSelected.length === 1
|
| 3126 |
+
? "1 view selected"
|
| 3127 |
+
: `${railSelected.length} views selected`}
|
| 3128 |
+
</span>
|
| 3129 |
+
{onExportXlsxViews && (
|
| 3130 |
+
<button
|
| 3131 |
+
type="button"
|
| 3132 |
+
disabled={railExportIds.length === 0}
|
| 3133 |
+
onClick={(event) => {
|
| 3134 |
+
// β HOISTED BEFORE THE setState, the scar the folder menu records above:
|
| 3135 |
+
// React nulls `currentTarget` once the handler returns.
|
| 3136 |
+
const anchor = event.currentTarget;
|
| 3137 |
+
// ONE export panel, not two: this opens the existing bulk pane with the
|
| 3138 |
+
// selection already ticked, so the formats, the 20-view cap and the tab
|
| 3139 |
+
// rule all stay where they were written.
|
| 3140 |
+
setExportViewIds([...railExportIds]);
|
| 3141 |
+
setExportBulk(true);
|
| 3142 |
+
setExportFor({ viewId: railExportIds[0], anchor });
|
| 3143 |
+
}}
|
| 3144 |
+
>
|
| 3145 |
+
Export
|
| 3146 |
+
</button>
|
| 3147 |
+
)}
|
| 3148 |
+
<button
|
| 3149 |
+
type="button"
|
| 3150 |
+
className="is-danger"
|
| 3151 |
+
disabled={railDeletable.length === 0}
|
| 3152 |
+
onClick={() => setRailDeleteArmed(true)}
|
| 3153 |
+
>
|
| 3154 |
+
Delete
|
| 3155 |
+
</button>
|
| 3156 |
+
</>
|
| 3157 |
+
)}
|
| 3158 |
+
</div>
|
| 3159 |
+
)}
|
| 3160 |
+
|
| 3161 |
{/* I11c β the folder "β¦" menu. Rename Β· Add to cohort Β· Duplicate Β· Delete.
|
| 3162 |
WAVE 20 item 22 β every row now carries the SAME icon vocabulary the view row's
|
| 3163 |
menu uses (`MenuLabel` over `MENU_ICONS`), and Delete is red AT REST rather than
|
|
|
|
| 3905 |
{xlsxExportViews.map((view) => {
|
| 3906 |
const selected = exportViewIds.includes(view.id);
|
| 3907 |
return (
|
| 3908 |
+
/* W46-T03: its OWN class, not `cg-radio-row`. These are checkboxes, and the
|
| 3909 |
+
radio class carries no font-size at all, so the rows were inheriting the
|
| 3910 |
+
17px root while `.cg-pop-title` and `.cg-pop-note` beside them sit at
|
| 3911 |
+
`--lp-fs-2xs`. `rail-select.css` puts the whole panel on one step. */
|
| 3912 |
+
<label key={view.id} className="cg-export-view-row">
|
| 3913 |
<input
|
| 3914 |
type="checkbox"
|
| 3915 |
checked={selected}
|
web/src/customer-grid/iconShapes.ts
CHANGED
|
@@ -347,6 +347,34 @@ export const FOLDER_SHAPE_PATHS: Record<FolderShape, IconShape[]> = {
|
|
| 347 |
bolt: [{ d: "M9.1 2.4L4.2 9.1h3.3l-.6 4.5 4.9-6.7H8.5z" }],
|
| 348 |
};
|
| 349 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 350 |
/**
|
| 351 |
* Tone key β the pastel it FILLS with, and the -d weight it STROKES with.
|
| 352 |
*
|
|
|
|
| 347 |
bolt: [{ d: "M9.1 2.4L4.2 9.1h3.3l-.6 4.5 4.9-6.7H8.5z" }],
|
| 348 |
};
|
| 349 |
|
| 350 |
+
/**
|
| 351 |
+
* W46-T05 (owner instruction 12) - the DATABASE mark for the data rail.
|
| 352 |
+
*
|
| 353 |
+
* A database row in the rail used to wear the folder glyph, so a database and the folder
|
| 354 |
+
* holding it were one picture. This is the conventional cylinder, in the same 16x16 stroke
|
| 355 |
+
* vocabulary as `FOLDER_SHAPE_PATHS` above so the two sit in one family: the top rim as a
|
| 356 |
+
* full ellipse, the two side walls closing into a lower rim, and one mid band.
|
| 357 |
+
*
|
| 358 |
+
* It is NOT a `FolderShape` key. A folder's shape is user-chosen and stored in nav prefs;
|
| 359 |
+
* this mark is what a database IS, so it stays outside that vocabulary and nothing offers
|
| 360 |
+
* it in the shape picker.
|
| 361 |
+
*
|
| 362 |
+
* β THE RIM DEPTH IS THE WHOLE POINT. This renders at 16px, and a rim flattened toward a
|
| 363 |
+
* straight line reads as a rectangle, which at that size is indistinguishable from the
|
| 364 |
+
* folder body it has to be told apart from. `ry` is 1.9 against `rx` 4.5, and the box is
|
| 365 |
+
* narrower than the folder's, so the silhouette differs as well as the curvature.
|
| 366 |
+
*/
|
| 367 |
+
export const DATABASE_SHAPE_PATHS: IconShape[] = [
|
| 368 |
+
{ d: "M3.5 3.9a4.5 1.9 0 1 0 9 0a4.5 1.9 0 1 0-9 0" },
|
| 369 |
+
{ d: "M3.5 3.9v8.2a4.5 1.9 0 0 0 9 0V3.9" },
|
| 370 |
+
{ d: "M3.5 8a4.5 1.9 0 0 0 9 0" },
|
| 371 |
+
];
|
| 372 |
+
|
| 373 |
+
/** The tone the database mark paints in: the same neutral every un-decorated folder row
|
| 374 |
+
* falls back to, so the rail keeps one paint and the DIFFERENCE the eye catches is the
|
| 375 |
+
* drawing rather than a colour. */
|
| 376 |
+
export const DATABASE_MARK_TONE: FolderTone = "neutral";
|
| 377 |
+
|
| 378 |
/**
|
| 379 |
* Tone key β the pastel it FILLS with, and the -d weight it STROKES with.
|
| 380 |
*
|
web/src/customer-grid/mapProjection.ts
CHANGED
|
@@ -960,3 +960,191 @@ export function formatDuration(minutes: number): string {
|
|
| 960 |
const rest = m % 60;
|
| 961 |
return rest === 0 ? `${h} h` : `${h} h ${rest} min`;
|
| 962 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 960 |
const rest = m % 60;
|
| 961 |
return rest === 0 ? `${h} h` : `${h} h ${rest} min`;
|
| 962 |
}
|
| 963 |
+
|
| 964 |
+
// βββββββββββββββββββββββββββββββββ W46-T18 / C2: the route timer's arithmetic βββββββββββββββββ
|
| 965 |
+
//
|
| 966 |
+
// ββ WHY THE PREVIEW AND THE ANSWER ARE DIFFERENT FUNCTIONS, AND MUST STAY SO.
|
| 967 |
+
// R9 asks for two things that pull in opposite directions: a drive time worth planning a day
|
| 968 |
+
// from, and a number that moves WHILE a stop is being dragged. The first can only come from a
|
| 969 |
+
// routing service; the second can only come from arithmetic, because the service behind it is a
|
| 970 |
+
// free unauthenticated endpoint with a courtesy rate limit of about one request per second, and
|
| 971 |
+
// a drag emits dozens of events a second. Wiring the drag to the network would not be slow, it
|
| 972 |
+
// would get the tenant blocked.
|
| 973 |
+
//
|
| 974 |
+
// So the drag reads `previewSeconds`, which is `tourLength` and nothing else, and one request
|
| 975 |
+
// fires on DROP. Everything in this section is pure: no `fetch`, no timer, no import. That is
|
| 976 |
+
// what `verify_route_timer.py` asserts, and it asserts it about this file rather than about a
|
| 977 |
+
// comment.
|
| 978 |
+
|
| 979 |
+
/**
|
| 980 |
+
* The speed and the detour factor a straight line is turned into a drive time with.
|
| 981 |
+
*
|
| 982 |
+
* β MIRRORED from `aios-web/api/routes_geo.py`, which carries the same two constants under the
|
| 983 |
+
* same names for its `source: "haversine"` answer. They are one number in two languages: if the
|
| 984 |
+
* drag preview and the server's fallback disagreed, a stop would appear to change the route by
|
| 985 |
+
* the size of the disagreement the moment the drag ended, and the route would not have changed
|
| 986 |
+
* at all. Change one and change the other.
|
| 987 |
+
*/
|
| 988 |
+
export const ROUTE_ESTIMATE_KMH = 40;
|
| 989 |
+
export const ROUTE_ROAD_DETOUR = 1.25;
|
| 990 |
+
|
| 991 |
+
/** Straight line kilometres as an approximate drive time in seconds. */
|
| 992 |
+
export function estimateSeconds(km: number): number {
|
| 993 |
+
const road = Math.max(0, km) * ROUTE_ROAD_DETOUR;
|
| 994 |
+
return Math.round((road / ROUTE_ESTIMATE_KMH) * 3600);
|
| 995 |
+
}
|
| 996 |
+
|
| 997 |
+
/**
|
| 998 |
+
* The number a drag moves: an approximate drive time for a candidate order, in seconds.
|
| 999 |
+
*
|
| 1000 |
+
* β NETWORK FREE BY CONSTRUCTION. It calls `tourLength` and `estimateSeconds`, both of which are
|
| 1001 |
+
* arithmetic over coordinates already on screen, so dragging a stop across a list of a hundred
|
| 1002 |
+
* costs microseconds and zero requests. It is an ESTIMATE and every surface that shows it has to
|
| 1003 |
+
* say so, which is what `routeTimeTone` is for.
|
| 1004 |
+
*/
|
| 1005 |
+
export function previewSeconds(
|
| 1006 |
+
order: number[], stops: GeoStop[], dist: StopDistance, roundTrip = false
|
| 1007 |
+
): number {
|
| 1008 |
+
return estimateSeconds(tourLength(order, stops, dist, roundTrip));
|
| 1009 |
+
}
|
| 1010 |
+
|
| 1011 |
+
/** One measured order, exactly as `POST /api/v1/geo/route` returns it under C2. */
|
| 1012 |
+
export interface RouteLeg {
|
| 1013 |
+
/** Record ids in visit order. A round trip does not repeat its first stop here. */
|
| 1014 |
+
ordered: number[];
|
| 1015 |
+
meters: number;
|
| 1016 |
+
seconds: number;
|
| 1017 |
+
/** WHO ANSWERED. Never whether the answer is trustworthy; that is `caveat`. */
|
| 1018 |
+
source: "osrm" | "haversine";
|
| 1019 |
+
/** Why the answer may not be what was asked for, in a sentence a person can read. */
|
| 1020 |
+
caveat: string | null;
|
| 1021 |
+
}
|
| 1022 |
+
|
| 1023 |
+
/** The whole answer: the order as it stands, the order the door would choose, and the gap. */
|
| 1024 |
+
export interface RouteAnswer {
|
| 1025 |
+
current: RouteLeg;
|
| 1026 |
+
optimized: RouteLeg;
|
| 1027 |
+
/** `current.seconds - optimized.seconds`. NEGATIVE when reordering would cost time. */
|
| 1028 |
+
savedSeconds: number;
|
| 1029 |
+
savedMeters: number;
|
| 1030 |
+
/** False when the two halves came from different answerers, so the gap is not a like for like
|
| 1031 |
+
* comparison and must not be offered as a saving. */
|
| 1032 |
+
savingComparable: boolean;
|
| 1033 |
+
/** False when the door had nothing to reorder, so both halves are the same measurement. */
|
| 1034 |
+
changed: boolean;
|
| 1035 |
+
mode: "driving" | "walking";
|
| 1036 |
+
attribution: string;
|
| 1037 |
+
/** The drawn road line for the order as it stands, `[lon, lat]` pairs. */
|
| 1038 |
+
line: number[][];
|
| 1039 |
+
}
|
| 1040 |
+
|
| 1041 |
+
function _leg(raw: unknown, fallbackOrdered: number[]): RouteLeg {
|
| 1042 |
+
const o = (raw || {}) as Record<string, unknown>;
|
| 1043 |
+
const ordered = Array.isArray(o.ordered)
|
| 1044 |
+
? (o.ordered as unknown[]).map((p) => Math.trunc(Number(p))).filter((p) => Number.isFinite(p))
|
| 1045 |
+
: fallbackOrdered;
|
| 1046 |
+
return {
|
| 1047 |
+
ordered,
|
| 1048 |
+
meters: Math.max(0, Math.round(Number(o.meters) || 0)),
|
| 1049 |
+
seconds: Math.max(0, Math.round(Number(o.seconds) || 0)),
|
| 1050 |
+
// β ANYTHING UNRECOGNISED IS AN ESTIMATE. The two values mean different confidences, and the
|
| 1051 |
+
// safe direction for an unknown third one is the one that gets shown with the word
|
| 1052 |
+
// "estimated" rather than the one presented as settled.
|
| 1053 |
+
source: o.source === "osrm" ? "osrm" : "haversine",
|
| 1054 |
+
caveat: typeof o.caveat === "string" && o.caveat.trim() ? o.caveat : null,
|
| 1055 |
+
};
|
| 1056 |
+
}
|
| 1057 |
+
|
| 1058 |
+
/**
|
| 1059 |
+
* Read the door's answer without trusting it.
|
| 1060 |
+
*
|
| 1061 |
+
* β ONE PARSER, so the timer and anything that grows beside it cannot disagree about what
|
| 1062 |
+
* `source` or a missing `optimized` block means. Returns null only when the body carries no
|
| 1063 |
+
* usable duration at all, which is the case a caller must render as an error rather than as a
|
| 1064 |
+
* zero: a route that takes no time is a very confident lie.
|
| 1065 |
+
*/
|
| 1066 |
+
export function parseRouteAnswer(body: unknown): RouteAnswer | null {
|
| 1067 |
+
if (!body || typeof body !== "object") return null;
|
| 1068 |
+
const b = body as Record<string, unknown>;
|
| 1069 |
+
if (!Number.isFinite(Number(b.seconds))) return null;
|
| 1070 |
+
const current = _leg(b, []);
|
| 1071 |
+
const optimized = b.optimized ? _leg(b.optimized, current.ordered) : { ...current };
|
| 1072 |
+
return {
|
| 1073 |
+
current,
|
| 1074 |
+
optimized,
|
| 1075 |
+
savedSeconds: Number.isFinite(Number(b.savedSeconds))
|
| 1076 |
+
? Math.round(Number(b.savedSeconds))
|
| 1077 |
+
: current.seconds - optimized.seconds,
|
| 1078 |
+
savedMeters: Number.isFinite(Number(b.savedMeters))
|
| 1079 |
+
? Math.round(Number(b.savedMeters))
|
| 1080 |
+
: current.meters - optimized.meters,
|
| 1081 |
+
savingComparable: b.savingComparable !== false && current.source === optimized.source,
|
| 1082 |
+
changed: !!(b.optimized && (b.optimized as Record<string, unknown>).changed),
|
| 1083 |
+
mode: b.mode === "walking" ? "walking" : "driving",
|
| 1084 |
+
attribution: typeof b.attribution === "string" ? b.attribution : "",
|
| 1085 |
+
line: Array.isArray(b.line) ? (b.line as number[][]) : [],
|
| 1086 |
+
};
|
| 1087 |
+
}
|
| 1088 |
+
|
| 1089 |
+
/**
|
| 1090 |
+
* The saving, as a surface should state it.
|
| 1091 |
+
*
|
| 1092 |
+
* β A saving is offered ONLY when both halves were measured the same way and the order really
|
| 1093 |
+
* differs. Otherwise `offer` is false and the caller shows the drive time alone: subtracting a
|
| 1094 |
+
* road measurement from a straight line estimate produces a number with no unit and a great deal
|
| 1095 |
+
* of authority.
|
| 1096 |
+
*/
|
| 1097 |
+
export function routeSaving(answer: RouteAnswer): {
|
| 1098 |
+
seconds: number; percent: number; offer: boolean; costs: boolean;
|
| 1099 |
+
} {
|
| 1100 |
+
const seconds = answer.savedSeconds;
|
| 1101 |
+
const base = Math.max(1, answer.current.seconds);
|
| 1102 |
+
return {
|
| 1103 |
+
seconds,
|
| 1104 |
+
percent: Math.round((seconds / base) * 100),
|
| 1105 |
+
offer: answer.changed && answer.savingComparable && seconds > 0,
|
| 1106 |
+
costs: answer.changed && answer.savingComparable && seconds < 0,
|
| 1107 |
+
};
|
| 1108 |
+
}
|
| 1109 |
+
|
| 1110 |
+
/** Seconds as a person says them, borrowing `formatDuration` so one route reads one way. */
|
| 1111 |
+
export function formatSeconds(seconds: number): string {
|
| 1112 |
+
return formatDuration(Math.abs(Math.round(seconds)) / 60);
|
| 1113 |
+
}
|
| 1114 |
+
|
| 1115 |
+
/**
|
| 1116 |
+
* How confident the number on screen is allowed to look.
|
| 1117 |
+
*
|
| 1118 |
+
* C2: a `haversine` answer is muted and carries the word "estimated"; an `osrm` answer is the
|
| 1119 |
+
* settled figure. Returned as data rather than as a class name so the component owns its own
|
| 1120 |
+
* styling, and so this is testable without a DOM.
|
| 1121 |
+
*/
|
| 1122 |
+
export function routeTimeTone(leg: RouteLeg): "settled" | "estimated" {
|
| 1123 |
+
return leg.source === "osrm" ? "settled" : "estimated";
|
| 1124 |
+
}
|
| 1125 |
+
|
| 1126 |
+
/** The caption for a leg: the duration, and the word "estimated" when it is one. */
|
| 1127 |
+
export function routeTimeLabel(leg: RouteLeg): string {
|
| 1128 |
+
const time = formatSeconds(leg.seconds);
|
| 1129 |
+
return routeTimeTone(leg) === "estimated" ? `${time} estimated` : time;
|
| 1130 |
+
}
|
| 1131 |
+
|
| 1132 |
+
/**
|
| 1133 |
+
* Every sentence this answer owes the person reading it.
|
| 1134 |
+
*
|
| 1135 |
+
* β A CAVEAT IS RENDERED, NEVER SWALLOWED (C2). Both halves can carry one and they can differ,
|
| 1136 |
+
* so they are collected here, de-duplicated, and handed over as a list the surface has to place
|
| 1137 |
+
* somewhere. A caller that shows a drive time and drops this is showing a number the server
|
| 1138 |
+
* already said not to trust.
|
| 1139 |
+
*/
|
| 1140 |
+
export function routeCaveats(answer: RouteAnswer): string[] {
|
| 1141 |
+
const out: string[] = [];
|
| 1142 |
+
for (const c of [answer.current.caveat, answer.optimized.caveat]) {
|
| 1143 |
+
if (c && !out.includes(c)) out.push(c);
|
| 1144 |
+
}
|
| 1145 |
+
if (answer.changed && !answer.savingComparable) {
|
| 1146 |
+
out.push("The reordered route was measured a different way from the current one, so the time "
|
| 1147 |
+
+ "difference between them is not a like for like comparison.");
|
| 1148 |
+
}
|
| 1149 |
+
return out;
|
| 1150 |
+
}
|
web/src/customer-grid/routeLinks.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import { googleRouteUrls, isPlottable } from "./mapProjection";
|
| 2 |
|
| 3 |
export interface LocatedRouteStop {
|
| 4 |
pid: number;
|
|
@@ -50,3 +50,65 @@ export function normalizedRouteMapLinks(
|
|
| 50 |
: { links: [], missingStopIds: [],
|
| 51 |
refusal: "The Maps links could not include every Route stop in order." };
|
| 52 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { googleDirectionsUrl, googleRouteUrls, isPlottable } from "./mapProjection";
|
| 2 |
|
| 3 |
export interface LocatedRouteStop {
|
| 4 |
pid: number;
|
|
|
|
| 50 |
: { links: [], missingStopIds: [],
|
| 51 |
refusal: "The Maps links could not include every Route stop in order." };
|
| 52 |
}
|
| 53 |
+
|
| 54 |
+
/* βββββββββββββββ W46-T20 / INSTRUCTION 10 / RULING R6 / C6 βββββββββββββββββββββββββββββββ
|
| 55 |
+
*
|
| 56 |
+
* The printed hand-off: one row per stop, for the sales team, produced by the browser's own
|
| 57 |
+
* Save as PDF.
|
| 58 |
+
*
|
| 59 |
+
* β IT DEGRADES PER STOP, WHICH IS THE ONE WAY IT DIFFERS FROM `normalizedRouteMapLinks`.
|
| 60 |
+
* That helper refuses the WHOLE Maps hand-off when any stop lacks a coordinate, and it is
|
| 61 |
+
* right to: a Google directions URL that quietly omits a customer sends a rep past a door
|
| 62 |
+
* they were meant to open. A printed sheet has no such failure. The stop is on the page
|
| 63 |
+
* either way, in its place in the order, with its name and address; only its map link is
|
| 64 |
+
* missing, and the page says so where the link would have been. Losing the whole export
|
| 65 |
+
* because one record was never geocoded would be the worse trade by far.
|
| 66 |
+
*
|
| 67 |
+
* β THE LINK IS THE GEOCODE, NEVER THE NAME. Google's documented `api=1` contract can carry
|
| 68 |
+
* a customer's NAME only alongside a place id (`destination_place_id`), and this codebase
|
| 69 |
+
* holds no place ids at all. A bare text destination is resolved by Google's own geocoder
|
| 70 |
+
* and can land at a different business with a similar name, so the first half of instruction
|
| 71 |
+
* 10 is answered by putting the customer's name in the LINK TEXT, which is what a rep reads,
|
| 72 |
+
* while the href stays the exact coordinate the map itself plotted.
|
| 73 |
+
*/
|
| 74 |
+
export interface RoutePrintStop {
|
| 75 |
+
pid: number;
|
| 76 |
+
/** 1 based, and it is the driving order, not a record id. */
|
| 77 |
+
position: number;
|
| 78 |
+
/** `stopIdentity`'s answer: the name, else the address, else the honest fallback. */
|
| 79 |
+
name: string;
|
| 80 |
+
address: string;
|
| 81 |
+
/** True when `name` IS the address, so the printed page never states one line twice. */
|
| 82 |
+
nameIsAddress: boolean;
|
| 83 |
+
/** Directions to the coordinate this app plotted, or null when there is none. */
|
| 84 |
+
mapsUrl: string | null;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
/**
|
| 88 |
+
* Build the printable rows for an ordered Route.
|
| 89 |
+
*
|
| 90 |
+
* `identify` is passed IN rather than imported: `stopIdentity` lives in RouteNav.tsx, which
|
| 91 |
+
* imports this module, and reaching back for it would close an import cycle. Passing it keeps
|
| 92 |
+
* the printed name and the on screen name provably the same function.
|
| 93 |
+
*/
|
| 94 |
+
export function routePrintStops(
|
| 95 |
+
orderedStopIds: readonly number[],
|
| 96 |
+
labels: Record<number, { name: string; address: string }>,
|
| 97 |
+
coords: Record<number, { lat: number; lon: number }>,
|
| 98 |
+
identify: (label: { name: string; address: string } | undefined, pid: number) => string,
|
| 99 |
+
): RoutePrintStop[] {
|
| 100 |
+
return orderedStopIds.map((pid, index) => {
|
| 101 |
+
const label = labels[pid];
|
| 102 |
+
const address = (label?.address || "").trim();
|
| 103 |
+
const name = identify(label, pid);
|
| 104 |
+
const at = coords[pid];
|
| 105 |
+
return {
|
| 106 |
+
pid,
|
| 107 |
+
position: index + 1,
|
| 108 |
+
name,
|
| 109 |
+
address,
|
| 110 |
+
nameIsAddress: !!address && name === address,
|
| 111 |
+
mapsUrl: at && isPlottable(at.lat, at.lon) ? googleDirectionsUrl(at.lat, at.lon) : null,
|
| 112 |
+
};
|
| 113 |
+
});
|
| 114 |
+
}
|
web/src/customer-grid/theme.ts
CHANGED
|
@@ -110,7 +110,9 @@ export const LP_BLUE_TEXT = "#4F6079";
|
|
| 110 |
/* THE SELECTED MAP PIN (wave 41 item 18). Blue is the fixed semantic for selected
|
| 111 |
(DESIGN.md, section 3), so this is a value WITHIN that hue, and it is chosen against
|
| 112 |
the map's own neighbours rather than freehand. Every `MapView.tsx` SERIES swatch, its
|
| 113 |
-
`DEFAULT_PIN` (
|
|
|
|
|
|
|
| 114 |
a fill at L* 34.4 separates from all ten on LIGHTNESS alone (worst neighbour ratio
|
| 115 |
2.63:1) and clears the nearest of them in hue too, dE 38 from #7E99C2.
|
| 116 |
β THE PRODUCT PRIMARY IS THE VALUE THAT FAILS HERE, and it is the one a later reader
|
|
@@ -122,6 +124,18 @@ export const LP_BLUE_TEXT = "#4F6079";
|
|
| 122 |
so it is edge definition (15.42:1 on white) and the FILL is what carries the blue
|
| 123 |
semantic at every radius from R_MIN to R_MAX. Mirrored as `--lp-map-selected`. */
|
| 124 |
export const LP_MAP_SELECTED = "#1B4F9C";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
export const LP_YELLOW_DEEP = "#7E6428"; // 5.11:1 on its tint
|
| 126 |
export const LP_RED_DEEP = "#A3453C"; // 5.35:1 on its tint
|
| 127 |
export const LP_GREEN_DEEP = "#35754E"; // 4.98:1 on its tint
|
|
|
|
| 110 |
/* THE SELECTED MAP PIN (wave 41 item 18). Blue is the fixed semantic for selected
|
| 111 |
(DESIGN.md, section 3), so this is a value WITHIN that hue, and it is chosen against
|
| 112 |
the map's own neighbours rather than freehand. Every `MapView.tsx` SERIES swatch, its
|
| 113 |
+
`DEFAULT_PIN` (fill `LP_PURPLE` #C3B3EE, line `LP_PURPLE_DEEP` #6B57A8, changed in wave 44
|
| 114 |
+
by cc429a0 from the #9DBFF2 this comment used to name) and the `OVERFLOW` grey (#D7DBE3)
|
| 115 |
+
sits at L* 61 or lighter, so
|
| 116 |
a fill at L* 34.4 separates from all ten on LIGHTNESS alone (worst neighbour ratio
|
| 117 |
2.63:1) and clears the nearest of them in hue too, dE 38 from #7E99C2.
|
| 118 |
β THE PRODUCT PRIMARY IS THE VALUE THAT FAILS HERE, and it is the one a later reader
|
|
|
|
| 124 |
so it is edge definition (15.42:1 on white) and the FILL is what carries the blue
|
| 125 |
semantic at every radius from R_MIN to R_MAX. Mirrored as `--lp-map-selected`. */
|
| 126 |
export const LP_MAP_SELECTED = "#1B4F9C";
|
| 127 |
+
/** β W46-T28 (owner instruction 16) β HOW SOLID A MAP ZONE READS, as a token rather than a
|
| 128 |
+
* literal per DESIGN.md section 5. Owner: *"the zone color is not strong enough its too
|
| 129 |
+
* transparent, i can't se eshit."* The saved boundary was `fill-opacity: 0.18` and the
|
| 130 |
+
* in-progress outline `fillOpacity="0.12"`, two different numbers for the same idea, over a
|
| 131 |
+
* raster basemap; the whole `ZONE_COLOR_CHOICES` palette is pastel, so a fifth of a pastel is
|
| 132 |
+
* close to nothing.
|
| 133 |
+
* β MIRRORED as `--lp-zone-fill` in `styles/wave46/map-panels.css`, which is the CSS half of
|
| 134 |
+
* this one value. Change the two together or they drift. The `index.css :root` seam was NOT
|
| 135 |
+
* used: contract C6 forbids a lane editing that file at all.
|
| 136 |
+
* β It stays below a half so a Zone still reads as a translucent overlay and the pins under it
|
| 137 |
+
* stay legible. That is the ceiling; the floor is whatever a screenshot says is visible. */
|
| 138 |
+
export const LP_ZONE_FILL_OPACITY = 0.4;
|
| 139 |
export const LP_YELLOW_DEEP = "#7E6428"; // 5.11:1 on its tint
|
| 140 |
export const LP_RED_DEEP = "#A3453C"; // 5.35:1 on its tint
|
| 141 |
export const LP_GREEN_DEEP = "#35754E"; // 4.98:1 on its tint
|
web/src/filter-kit/FieldsHidePanel.tsx
CHANGED
|
@@ -13,7 +13,12 @@
|
|
| 13 |
// happens to store the other polarity.
|
| 14 |
// ---------------------------------------------------------------------------
|
| 15 |
|
| 16 |
-
import { useMemo, useState } from "react";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
// β W40-T16 β the bare `Field` type import is GONE, not misplaced: the prop below is
|
| 18 |
// `PermsField[]` now, which extends it, so importing both would leave one unread and
|
| 19 |
// `tsconfig.app.json`'s `noUnusedLocals` reds the build on exactly that.
|
|
@@ -330,11 +335,30 @@ export function brokenFieldReason(
|
|
| 330 |
* the table. Show all / Hide all keep acting on ALL fields, not the searched subset β their
|
| 331 |
* labels say "all", and a narrowed meaning under an active search would be a quiet lie.
|
| 332 |
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
function FieldMetaIcon({ detail, kind }: { detail: string; kind: "origin" | "audience" | "owner" | "edit" | "lock" }) {
|
| 334 |
const shape = kind === "origin"
|
| 335 |
? <><path d="M8 2.5 13 8 8 13.5 3 8 8 2.5Z" /><path d="M6.3 8h3.4" /></>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 336 |
: kind === "edit"
|
| 337 |
-
? <><path d="
|
| 338 |
: kind === "lock"
|
| 339 |
? <><rect x="3.1" y="7" width="9.8" height="6.4" rx="1.5" /><path d="M5.6 7V5.2a2.4 2.4 0 0 1 4.8 0V7" /></>
|
| 340 |
: <><circle cx="8" cy="5.6" r="2.1" /><path d="M3.6 13.3c.5-2.4 2.1-3.7 4.4-3.7s3.9 1.3 4.4 3.7" /></>;
|
|
@@ -427,6 +451,75 @@ export function FieldsHidePanel({
|
|
| 427 |
* and clicking another re-arms rather than firing. */
|
| 428 |
const [confirmKey, setConfirmKey] = useState<string | null>(null);
|
| 429 |
const [deleteTargetKey, setDeleteTargetKey] = useState<string | null>(null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 430 |
/** Item 23 β the row being dragged, and the row it is currently over. Both are KEYS, never
|
| 431 |
* indices: the list re-renders on every move and an index would point at whatever slid into
|
| 432 |
* that slot. */
|
|
@@ -963,24 +1056,11 @@ export function FieldsHidePanel({
|
|
| 963 |
!
|
| 964 |
</span>
|
| 965 |
)}
|
| 966 |
-
{
|
| 967 |
-
|
| 968 |
-
|
| 969 |
-
|
| 970 |
-
|
| 971 |
-
title="Edit field"
|
| 972 |
-
onClick={(event) => {
|
| 973 |
-
event.preventDefault();
|
| 974 |
-
event.stopPropagation();
|
| 975 |
-
onEditField(f.key, event.currentTarget.getBoundingClientRect());
|
| 976 |
-
}}
|
| 977 |
-
>
|
| 978 |
-
<svg width="13" height="13" viewBox="0 0 16 16" fill="none" aria-hidden focusable="false">
|
| 979 |
-
<path d="m3.2 11.9.7-2.8 6.5-6.5 2.5 2.5-6.5 6.5-2.7.8Z" stroke="currentColor" strokeWidth="1.3" strokeLinejoin="round" />
|
| 980 |
-
<path d="m9.1 4 2.5 2.5" stroke="currentColor" strokeWidth="1.3" strokeLinecap="round" />
|
| 981 |
-
</svg>
|
| 982 |
-
</button>
|
| 983 |
-
)}
|
| 984 |
{/* β OWNER ITEM 3 (2026-08-06): *"it doesn't show pre-set when I hide fields just
|
| 985 |
like how Odoo fields are. This is always the standard label."* Right β the chip
|
| 986 |
asked `source === "odoo"`, so a column an AUTOMATION fills (source `overlay`)
|
|
@@ -1210,13 +1290,97 @@ export function FieldsHidePanel({
|
|
| 1210 |
)}
|
| 1211 |
</button>
|
| 1212 |
)}
|
| 1213 |
-
{
|
| 1214 |
-
|
| 1215 |
-
|
| 1216 |
-
|
| 1217 |
-
|
| 1218 |
-
|
| 1219 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1220 |
/* ββ W41-T29 (R6(c)) - THE ARMED STATE NAMES WHO LOSES IT. The confirmation
|
| 1221 |
is the moment the impact is worth reading, so it rides the arm rather than
|
| 1222 |
the resting row: `deleteImpactTitle` gives the OWNER plus the audience
|
|
@@ -1227,24 +1391,21 @@ export function FieldsHidePanel({
|
|
| 1227 |
named" is in the helper's own copy: a tally that reads as exhaustive beside
|
| 1228 |
a delete button is worse than no tally. Widening C8 is the fix, not a
|
| 1229 |
client-side walk this component could not do anyway. */
|
| 1230 |
-
|
| 1231 |
-
|
| 1232 |
-
|
| 1233 |
-
|
| 1234 |
-
|
| 1235 |
-
|
| 1236 |
-
|
| 1237 |
-
|
| 1238 |
-
|
| 1239 |
-
|
| 1240 |
-
|
| 1241 |
-
|
| 1242 |
-
|
| 1243 |
-
|
| 1244 |
-
|
| 1245 |
-
/>
|
| 1246 |
-
</svg>
|
| 1247 |
-
</button>
|
| 1248 |
)}
|
| 1249 |
</label>
|
| 1250 |
);
|
|
|
|
| 13 |
// happens to store the other polarity.
|
| 14 |
// ---------------------------------------------------------------------------
|
| 15 |
|
| 16 |
+
import { useEffect, useMemo, useRef, useState } from "react";
|
| 17 |
+
// ββ W46-T31 (contract C6) β the lane's own sheet, imported from the COMPONENT and never from
|
| 18 |
+
// `index.css`. An @imported sheet is inlined at the TOP of the bundle's cascade and loses every
|
| 19 |
+
// equal-specificity fight with the rules below it; a sheet a component imports lands after
|
| 20 |
+
// index.css and wins. [[a-lane-stylesheet-cannot-override-index-css]]
|
| 21 |
+
import "../styles/wave46/field-panels.css";
|
| 22 |
// β W40-T16 β the bare `Field` type import is GONE, not misplaced: the prop below is
|
| 23 |
// `PermsField[]` now, which extends it, so importing both would leave one unread and
|
| 24 |
// `tsconfig.app.json`'s `noUnusedLocals` reds the build on exactly that.
|
|
|
|
| 335 |
* the table. Show all / Hide all keep acting on ALL fields, not the searched subset β their
|
| 336 |
* labels say "all", and a narrowed meaning under an active search would be a quiet lie.
|
| 337 |
*/
|
| 338 |
+
/**
|
| 339 |
+
* W46-T31 β the field-actions menu's own geometry, stated once here and once in
|
| 340 |
+
* `styles/wave46/field-panels.css`. Two numbers rather than a measurement: the menu is
|
| 341 |
+
* positioned BEFORE it mounts (there is nothing to measure yet), and a menu of at most two
|
| 342 |
+
* short items has a fixed size. They are a placement hint only; if they drift the menu lands a
|
| 343 |
+
* few pixels off, it never lands wrong.
|
| 344 |
+
*/
|
| 345 |
+
const FIELD_MENU_WIDTH = 168;
|
| 346 |
+
const FIELD_MENU_HEIGHT = 76;
|
| 347 |
+
|
| 348 |
function FieldMetaIcon({ detail, kind }: { detail: string; kind: "origin" | "audience" | "owner" | "edit" | "lock" }) {
|
| 349 |
const shape = kind === "origin"
|
| 350 |
? <><path d="M8 2.5 13 8 8 13.5 3 8 8 2.5Z" /><path d="M6.3 8h3.4" /></>
|
| 351 |
+
// ββ W46-T31 (owner instruction 21) β THE EDIT-AUDIENCE BADGE STOPS WEARING THE EDIT PENCIL.
|
| 352 |
+
// This mark answers "who may WRITE here" (`FIELD_EDIT_BLURBS`, types.ts), which is a
|
| 353 |
+
// classification; the pencil beside it is an ACTION that opens the field editor. Byte-identical
|
| 354 |
+
// path data on the two made one row carry the same glyph twice for two unrelated meanings, and
|
| 355 |
+
// DESIGN Β§4 asks a mark to name its own restriction rather than borrow another's shape.
|
| 356 |
+
// β A WRITE LINE (a ruled line with a stroke above it), deliberately unlike all four of its
|
| 357 |
+
// neighbours: the diamond (origin), the padlock (lock), the person bust (owner/audience) and
|
| 358 |
+
// the pencil itself. The BLURB in `aria-label`/`data-meta-detail` is what still distinguishes
|
| 359 |
+
// the three edit modes; the glyph only has to stop lying about which control it is.
|
| 360 |
: kind === "edit"
|
| 361 |
+
? <><path d="M2.9 12.6h10.2" /><path d="M4.3 9.8c1.2-3 2.1 1.3 3.2-1.3s1.9 1.8 3.2-.6" /></>
|
| 362 |
: kind === "lock"
|
| 363 |
? <><rect x="3.1" y="7" width="9.8" height="6.4" rx="1.5" /><path d="M5.6 7V5.2a2.4 2.4 0 0 1 4.8 0V7" /></>
|
| 364 |
: <><circle cx="8" cy="5.6" r="2.1" /><path d="M3.6 13.3c.5-2.4 2.1-3.7 4.4-3.7s3.9 1.3 4.4 3.7" /></>;
|
|
|
|
| 451 |
* and clicking another re-arms rather than firing. */
|
| 452 |
const [confirmKey, setConfirmKey] = useState<string | null>(null);
|
| 453 |
const [deleteTargetKey, setDeleteTargetKey] = useState<string | null>(null);
|
| 454 |
+
/**
|
| 455 |
+
* ββ W46-T31 (owner instruction 21) β DELETE IS REACHED FROM INSIDE EDIT. The row used to
|
| 456 |
+
* offer two side-by-side doors of very unequal weight: a pencil that opens an editor and a
|
| 457 |
+
* trash that destroys a column on every row. One trailing control now opens both, so the
|
| 458 |
+
* destructive act costs a deliberate second click and stops sitting a few pixels from the
|
| 459 |
+
* benign one on a dense hover-reveal list.
|
| 460 |
+
*
|
| 461 |
+
* β THE CONFIRM DIALOG IS UNTOUCHED. `deleteTargetKey` above still drives
|
| 462 |
+
* `FieldDeleteImpactDialog` with its exact-name typing; this menu only replaces the button
|
| 463 |
+
* that SET it. Folding a confirmation into a menu item would have traded a real guard for
|
| 464 |
+
* the appearance of one.
|
| 465 |
+
* β `cg-check-del--remove` STAYS ITS OWN BUTTON. Remove-from-my-fields (R6(b)) is a
|
| 466 |
+
* different act on a column somebody else shared, not a gentler Delete, and the two have
|
| 467 |
+
* never been offered to the same viewer anyway (`fieldRights`: `deletable` requires
|
| 468 |
+
* `!canRemove`).
|
| 469 |
+
*
|
| 470 |
+
* β KEY, POSITION AND TRIGGER, THREE PIECES. The key says which row is open; the position is
|
| 471 |
+
* VIEWPORT coordinates because `.cg-pop-list` is a 320px `overflow-y: auto` box and an
|
| 472 |
+
* absolutely positioned menu on the last row would be clipped by it; the trigger element is
|
| 473 |
+
* what focus returns to and what `onEditField` must be anchored on. Nothing here is derived
|
| 474 |
+
* at render time from a stale rect: the Edit item re-measures the live trigger.
|
| 475 |
+
*/
|
| 476 |
+
const [menuKey, setMenuKey] = useState<string | null>(null);
|
| 477 |
+
const [menuPos, setMenuPos] = useState<{ top: number; left: number } | null>(null);
|
| 478 |
+
const menuTriggerRef = useRef<HTMLButtonElement | null>(null);
|
| 479 |
+
const menuRef = useRef<HTMLDivElement | null>(null);
|
| 480 |
+
/** One closer, so every exit route agrees on what "closed" means. `restoreFocus` is TRUE for
|
| 481 |
+
* the keyboard and menu-item routes and FALSE for an outside click or a scroll: pulling focus
|
| 482 |
+
* back to a hidden trigger under a pointer that has moved elsewhere is a jump, not a courtesy. */
|
| 483 |
+
const closeFieldMenu = (restoreFocus: boolean) => {
|
| 484 |
+
setMenuKey(null);
|
| 485 |
+
setMenuPos(null);
|
| 486 |
+
const trigger = menuTriggerRef.current;
|
| 487 |
+
menuTriggerRef.current = null;
|
| 488 |
+
if (restoreFocus) trigger?.focus();
|
| 489 |
+
};
|
| 490 |
+
useEffect(() => {
|
| 491 |
+
if (menuKey === null) return;
|
| 492 |
+
const onKey = (e: KeyboardEvent) => {
|
| 493 |
+
if (e.key !== "Escape") return;
|
| 494 |
+
// Stop the panel's own overlay layer from closing the WHOLE Fields panel on the same key.
|
| 495 |
+
e.stopPropagation();
|
| 496 |
+
closeFieldMenu(true);
|
| 497 |
+
};
|
| 498 |
+
const onDown = (e: Event) => {
|
| 499 |
+
const target = e.target as Node | null;
|
| 500 |
+
if (!target) return;
|
| 501 |
+
if (menuRef.current?.contains(target)) return;
|
| 502 |
+
if (menuTriggerRef.current?.contains(target)) return;
|
| 503 |
+
closeFieldMenu(false);
|
| 504 |
+
};
|
| 505 |
+
// β CAPTURE, AND `scroll` IS NOT OPTIONAL. The menu is viewport-positioned, so scrolling the
|
| 506 |
+
// field list would leave it hovering over an unrelated row still wired to the row it opened on.
|
| 507 |
+
const onScroll = () => closeFieldMenu(false);
|
| 508 |
+
document.addEventListener("keydown", onKey, true);
|
| 509 |
+
document.addEventListener("pointerdown", onDown, true);
|
| 510 |
+
window.addEventListener("scroll", onScroll, true);
|
| 511 |
+
return () => {
|
| 512 |
+
document.removeEventListener("keydown", onKey, true);
|
| 513 |
+
document.removeEventListener("pointerdown", onDown, true);
|
| 514 |
+
window.removeEventListener("scroll", onScroll, true);
|
| 515 |
+
};
|
| 516 |
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
| 517 |
+
}, [menuKey]);
|
| 518 |
+
/** The menu takes focus on open, which is what makes Escape and Tab reach it at all. */
|
| 519 |
+
useEffect(() => {
|
| 520 |
+
if (menuKey === null) return;
|
| 521 |
+
menuRef.current?.querySelector<HTMLButtonElement>("button")?.focus();
|
| 522 |
+
}, [menuKey]);
|
| 523 |
/** Item 23 β the row being dragged, and the row it is currently over. Both are KEYS, never
|
| 524 |
* indices: the list re-renders on every move and an index would point at whatever slid into
|
| 525 |
* that slot. */
|
|
|
|
| 1056 |
!
|
| 1057 |
</span>
|
| 1058 |
)}
|
| 1059 |
+
{/* ββ W46-T31 β the Edit trigger MOVED to the row's trailing slot, where it now
|
| 1060 |
+
opens the field-actions menu that carries both Edit field and Delete field. It
|
| 1061 |
+
is the same button, the same pencil and the same `onEditField` call; what
|
| 1062 |
+
changed is that the destructive door is behind it instead of beside it. See
|
| 1063 |
+
the trailing slot at the end of this row. */}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1064 |
{/* β OWNER ITEM 3 (2026-08-06): *"it doesn't show pre-set when I hide fields just
|
| 1065 |
like how Odoo fields are. This is always the standard label."* Right β the chip
|
| 1066 |
asked `source === "odoo"`, so a column an AUTOMATION fills (source `overlay`)
|
|
|
|
| 1290 |
)}
|
| 1291 |
</button>
|
| 1292 |
)}
|
| 1293 |
+
{/* ββ W46-T31 (owner instruction 21) β THE ONE TRAILING CONTROL. It renders when
|
| 1294 |
+
EITHER door is open to this viewer, so a delete-only mount (no `onEditField`)
|
| 1295 |
+
still has a way in and an edit-only row does not grow a second affordance.
|
| 1296 |
+
β Inside a <label>: every click here preventDefaults, or activating the label
|
| 1297 |
+
toggles the very column you came to edit. Same reason the old trash did.
|
| 1298 |
+
β The rect handed to `onEditField` is re-measured off the LIVE trigger at click
|
| 1299 |
+
time, never the one captured when the menu opened: the list can scroll between
|
| 1300 |
+
the two, and an editor anchored on a stale rect opens over the wrong row. */}
|
| 1301 |
+
{(onEditField || deletable) && (
|
| 1302 |
+
<span className={"w46-field-actions" + (menuKey === f.key ? " is-open" : "")}>
|
| 1303 |
+
<button
|
| 1304 |
+
type="button"
|
| 1305 |
+
className="cg-field-edit-trigger w46-field-actions-trigger"
|
| 1306 |
+
aria-label={deletable ? `Field actions ${rowLabel(f)}` : `Edit field ${rowLabel(f)}`}
|
| 1307 |
+
aria-haspopup={deletable ? "true" : undefined}
|
| 1308 |
+
aria-expanded={deletable ? menuKey === f.key : undefined}
|
| 1309 |
+
title={deletable ? "Field actions" : "Edit field"}
|
| 1310 |
+
onClick={(event) => {
|
| 1311 |
+
event.preventDefault();
|
| 1312 |
+
event.stopPropagation();
|
| 1313 |
+
/* ββ W46-T31 β ONE AVAILABLE ACTION IS PERFORMED, NOT LISTED. A menu of a
|
| 1314 |
+
single item is a click the person did not need: when this viewer may edit
|
| 1315 |
+
but not delete, the trigger IS the Edit button and opens the editor at
|
| 1316 |
+
once. The menu exists to put the destructive door behind a deliberate
|
| 1317 |
+
second click, so it earns its place only when there IS a second door.
|
| 1318 |
+
β THIS IS ALSO THE LIVE PATH `verify_grid_ux.py:4032` PINS. That check
|
| 1319 |
+
greps for the edit call made with the trigger's own measured rect, and the
|
| 1320 |
+
needle is a real path here rather than a decoy: `currentTarget` is THIS
|
| 1321 |
+
button, so the editor anchors on the row's own control, which is what the
|
| 1322 |
+
check means by "without unmounting itself".
|
| 1323 |
+
β DO NOT RESTATE THE PINNED CALL ANYWHERE IN A COMMENT. A grep-based
|
| 1324 |
+
gate cannot tell source from prose, so a comment quoting it verbatim keeps
|
| 1325 |
+
the check green after the real call is deleted. That very mistake was made
|
| 1326 |
+
and reverted while writing this block.
|
| 1327 |
+
The two-door path below anchors on the same element through
|
| 1328 |
+
`menuTriggerRef`, re-measured at click time because the list can scroll
|
| 1329 |
+
while the menu is open. */
|
| 1330 |
+
if (!deletable) {
|
| 1331 |
+
if (onEditField) onEditField(f.key, event.currentTarget.getBoundingClientRect());
|
| 1332 |
+
return;
|
| 1333 |
+
}
|
| 1334 |
+
if (menuKey === f.key) {
|
| 1335 |
+
closeFieldMenu(true);
|
| 1336 |
+
return;
|
| 1337 |
+
}
|
| 1338 |
+
const trigger = event.currentTarget;
|
| 1339 |
+
const rect = trigger.getBoundingClientRect();
|
| 1340 |
+
menuTriggerRef.current = trigger;
|
| 1341 |
+
// Flip upward when the viewport has no room below: the field list is a
|
| 1342 |
+
// scroll box near the bottom of a popover, so the last rows are the
|
| 1343 |
+
// ordinary case rather than the edge one.
|
| 1344 |
+
const openUp = window.innerHeight - rect.bottom < FIELD_MENU_HEIGHT + 8;
|
| 1345 |
+
setMenuPos({
|
| 1346 |
+
top: openUp ? Math.max(8, rect.top - FIELD_MENU_HEIGHT - 4) : rect.bottom + 4,
|
| 1347 |
+
left: Math.max(8, rect.right - FIELD_MENU_WIDTH),
|
| 1348 |
+
});
|
| 1349 |
+
setMenuKey(f.key);
|
| 1350 |
+
}}
|
| 1351 |
+
>
|
| 1352 |
+
<svg width="13" height="13" viewBox="0 0 16 16" fill="none" aria-hidden focusable="false">
|
| 1353 |
+
<path d="m3.2 11.9.7-2.8 6.5-6.5 2.5 2.5-6.5 6.5-2.7.8Z" stroke="currentColor" strokeWidth="1.3" strokeLinejoin="round" />
|
| 1354 |
+
<path d="m9.1 4 2.5 2.5" stroke="currentColor" strokeWidth="1.3" strokeLinecap="round" />
|
| 1355 |
+
</svg>
|
| 1356 |
+
</button>
|
| 1357 |
+
{menuKey === f.key && menuPos && (
|
| 1358 |
+
<div
|
| 1359 |
+
ref={menuRef}
|
| 1360 |
+
className="w46-field-menu"
|
| 1361 |
+
aria-label={`Field actions ${rowLabel(f)}`}
|
| 1362 |
+
style={{ top: menuPos.top, left: menuPos.left }}
|
| 1363 |
+
>
|
| 1364 |
+
{onEditField && (
|
| 1365 |
+
<button
|
| 1366 |
+
type="button"
|
| 1367 |
+
className="w46-field-menu-item"
|
| 1368 |
+
title="Edit field"
|
| 1369 |
+
onClick={(event) => {
|
| 1370 |
+
event.preventDefault();
|
| 1371 |
+
event.stopPropagation();
|
| 1372 |
+
const rect = menuTriggerRef.current?.getBoundingClientRect();
|
| 1373 |
+
closeFieldMenu(true);
|
| 1374 |
+
if (rect) onEditField(f.key, rect);
|
| 1375 |
+
}}
|
| 1376 |
+
>
|
| 1377 |
+
Edit field
|
| 1378 |
+
</button>
|
| 1379 |
+
)}
|
| 1380 |
+
{deletable && (
|
| 1381 |
+
<button
|
| 1382 |
+
type="button"
|
| 1383 |
+
className="w46-field-menu-item w46-field-menu-item--danger"
|
| 1384 |
/* ββ W41-T29 (R6(c)) - THE ARMED STATE NAMES WHO LOSES IT. The confirmation
|
| 1385 |
is the moment the impact is worth reading, so it rides the arm rather than
|
| 1386 |
the resting row: `deleteImpactTitle` gives the OWNER plus the audience
|
|
|
|
| 1391 |
named" is in the helper's own copy: a tally that reads as exhaustive beside
|
| 1392 |
a delete button is worse than no tally. Widening C8 is the fix, not a
|
| 1393 |
client-side walk this component could not do anyway. */
|
| 1394 |
+
aria-label={`Delete ${rowLabel(f)}`}
|
| 1395 |
+
title={impactTitle ?? "Removes this field and its values on every row."}
|
| 1396 |
+
onClick={(e) => {
|
| 1397 |
+
e.preventDefault();
|
| 1398 |
+
e.stopPropagation();
|
| 1399 |
+
closeFieldMenu(true);
|
| 1400 |
+
setDeleteTargetKey(f.key);
|
| 1401 |
+
}}
|
| 1402 |
+
>
|
| 1403 |
+
Delete field
|
| 1404 |
+
</button>
|
| 1405 |
+
)}
|
| 1406 |
+
</div>
|
| 1407 |
+
)}
|
| 1408 |
+
</span>
|
|
|
|
|
|
|
|
|
|
| 1409 |
)}
|
| 1410 |
</label>
|
| 1411 |
);
|
web/src/filter-kit/FilterBuilderPanel.tsx
CHANGED
|
@@ -17,6 +17,7 @@ import type { ReactNode } from "react";
|
|
| 17 |
import type {
|
| 18 |
Conjunction,
|
| 19 |
Field,
|
|
|
|
| 20 |
FilterGroup,
|
| 21 |
FilterNode,
|
| 22 |
FilterOp,
|
|
@@ -527,6 +528,27 @@ function ConditionLevel({
|
|
| 527 |
);
|
| 528 |
}
|
| 529 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 530 |
/**
|
| 531 |
* One leaf condition: field βΎ | (window βΎ) | operator βΎ | value | remove.
|
| 532 |
*
|
|
@@ -631,7 +653,23 @@ function LeafRow({
|
|
| 631 |
.map((f) => ({ key: f.key, label: f.label, type: f.type }));
|
| 632 |
const canCompareField = !isCohort && rule.op !== "within"
|
| 633 |
&& !VALUE_FREE_OPS.has(rule.op as FilterOp) && !isRankOp(rule.op)
|
| 634 |
-
&& rhsOptions.length > 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 635 |
const usingStat = rule.rhs?.kind === "stat";
|
| 636 |
const usingField = rule.rhs != null && !usingStat;
|
| 637 |
// Explicitly widened: the cohort branch contributes a DISJOINT vocabulary, and without the
|
|
|
|
| 17 |
import type {
|
| 18 |
Conjunction,
|
| 19 |
Field,
|
| 20 |
+
FieldType,
|
| 21 |
FilterGroup,
|
| 22 |
FilterNode,
|
| 23 |
FilterOp,
|
|
|
|
| 528 |
);
|
| 529 |
}
|
| 530 |
|
| 531 |
+
/**
|
| 532 |
+
* W46-T30 β the TEXT half of the CG-9 comparand, asked as an OPERATOR question.
|
| 533 |
+
*
|
| 534 |
+
* A type is text-comparable when its own operator offer is the TEXT family, which `opsForType`
|
| 535 |
+
* expresses by falling THROUGH to `["contains", β¦]`. Read off the `FieldType` union rather than
|
| 536 |
+
* remembered, that residue today is `text`, `phone`, `email`, `url`, `automation`, `link`,
|
| 537 |
+
* `image`, `code` and `ai_enrich` β every one of them a cell holding a plain STRING, each of
|
| 538 |
+
* which is already offered `contains` against a typed value, so being offered it against
|
| 539 |
+
* another column of its own type asks the same question of the same characters. Asking the
|
| 540 |
+
* operator vocabulary instead of listing those nine is what lets a type added later be admitted
|
| 541 |
+
* without this file holding a list it would then have to be kept in step with.
|
| 542 |
+
*
|
| 543 |
+
* β `multiselect` is excluded ON PURPOSE even though it also offers `contains`. Its cell is a
|
| 544 |
+
* comma-joined SET and its `contains` is membership over a value the person picked from the
|
| 545 |
+
* column's own declared options; a free column comparand there would read as "has whatever that
|
| 546 |
+
* other cell happens to say", which is not a question the control asks or the option list bounds.
|
| 547 |
+
*/
|
| 548 |
+
function isTextComparable(t: FieldType): boolean {
|
| 549 |
+
return t !== "multiselect" && opsForType(t).includes("contains");
|
| 550 |
+
}
|
| 551 |
+
|
| 552 |
/**
|
| 553 |
* One leaf condition: field βΎ | (window βΎ) | operator βΎ | value | remove.
|
| 554 |
*
|
|
|
|
| 653 |
.map((f) => ({ key: f.key, label: f.label, type: f.type }));
|
| 654 |
const canCompareField = !isCohort && rule.op !== "within"
|
| 655 |
&& !VALUE_FREE_OPS.has(rule.op as FilterOp) && !isRankOp(rule.op)
|
| 656 |
+
&& rhsOptions.length > 0
|
| 657 |
+
&& (isMeasure || isNumericType(t) || isDateFamily(t) || isTextComparable(t));
|
| 658 |
+
// β W46-T30 β the tail moved, and NOTHING ELSE DID. Everything under a text comparand was
|
| 659 |
+
// already there and already type-agnostic: the wire shape is CG-9's `FilterRhs {kind:"field",
|
| 660 |
+
// colId}`, the client evaluator's text branch already runs `cmpText(rule.op, a, other)`,
|
| 661 |
+
// `filter_sql.py` already emits `strpos(v, rhs_v) > 0` for `contains` without asking what type
|
| 662 |
+
// the two sides are, and `aios_grid.py::_clean_rhs` already keeps the reference. So the only
|
| 663 |
+
// thing standing between a text column and "contains the value of that other column" was this
|
| 664 |
+
// boolean, and a second field-reference mechanism would have duplicated CG-9 and broken the
|
| 665 |
+
// byte-identical vocabulary lock-step `verify_filter_engine.py` holds the two engines to.
|
| 666 |
+
//
|
| 667 |
+
// The comparand list needs no widening either: `rhsOptions` above already restricts a
|
| 668 |
+
// non-numeric leaf to `f.type === t`, so a text column is only ever offered other columns of
|
| 669 |
+
// its OWN type. What is deliberately NOT admitted: `checkbox` and `json` (two value-free ops,
|
| 670 |
+
// so no comparand slot exists), `status`/`select`/`user` (a closed option list, where a free
|
| 671 |
+
// comparand would compare against a vocabulary the picker does not share), and `multiselect`
|
| 672 |
+
// (see `isTextComparable`).
|
| 673 |
const usingStat = rule.rhs?.kind === "stat";
|
| 674 |
const usingField = rule.rhs != null && !usingStat;
|
| 675 |
// Explicitly widened: the cohort branch contributes a DISJOINT vocabulary, and without the
|
web/src/settings/DatabasePermsPane.tsx
CHANGED
|
@@ -34,7 +34,7 @@
|
|
| 34 |
|
| 35 |
import { FilterBuilderPanel, FieldsHidePanel } from "../filter-kit";
|
| 36 |
import type { FilterTree } from "../customer-grid/types";
|
| 37 |
-
import type { PermsModule, PermsRecord } from "./permsModel";
|
| 38 |
import { filterOf, hiddenSetFor, hideAllKeys, identityKey, showAllKeys } from "./permsModel";
|
| 39 |
import "./perms.css";
|
| 40 |
|
|
@@ -73,8 +73,35 @@ export interface DatabasePermsPaneProps {
|
|
| 73 |
*/
|
| 74 |
/** People this tenant can name in a `user` condition. Absent β the panel says so. */
|
| 75 |
userOptions?: string[];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
}
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
export function DatabasePermsPane({
|
| 79 |
module,
|
| 80 |
entries,
|
|
@@ -83,7 +110,23 @@ export function DatabasePermsPane({
|
|
| 83 |
onToggleHidden,
|
| 84 |
onSetHidden,
|
| 85 |
userOptions,
|
|
|
|
| 86 |
}: DatabasePermsPaneProps) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
return (
|
| 88 |
<div className="set-dbperm">
|
| 89 |
<div className="set-dbperm-head">
|
|
@@ -127,6 +170,36 @@ export function DatabasePermsPane({
|
|
| 127 |
/>
|
| 128 |
</div>
|
| 129 |
<div className="cg-pop set-perm-pop">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
{/* ββ W40-T16 β THIS LIST IS WHERE THE METRICS RULE NOW LIVES. `module.fields` carries
|
| 131 |
C3's `measure_`-namespaced pseudo-fields, `permsModel::parseField` marks each one,
|
| 132 |
and the panel draws it as an ordinary checkbox named "Metric - Revenue". Checking it
|
|
|
|
| 34 |
|
| 35 |
import { FilterBuilderPanel, FieldsHidePanel } from "../filter-kit";
|
| 36 |
import type { FilterTree } from "../customer-grid/types";
|
| 37 |
+
import type { MetricsCensus, PermsModule, PermsRecord } from "./permsModel";
|
| 38 |
import { filterOf, hiddenSetFor, hideAllKeys, identityKey, showAllKeys } from "./permsModel";
|
| 39 |
import "./perms.css";
|
| 40 |
|
|
|
|
| 73 |
*/
|
| 74 |
/** People this tenant can name in a `user` condition. Absent β the panel says so. */
|
| 75 |
userOptions?: string[];
|
| 76 |
+
/**
|
| 77 |
+
* ββ W46-T34 β THE METRIC CENSUS FOR *THIS* DATABASE, as `routes_admin::get_perms` ships it
|
| 78 |
+
* under `metrics_by_module[key]`. The server half landed first and nothing read it; this prop
|
| 79 |
+
* is the reader ([[a-built-validated-wall-can-have-no-caller]]).
|
| 80 |
+
*
|
| 81 |
+
* β `status` IS THREE ANSWERS, NOT TWO, AND THAT DISTINCTION IS THE WHOLE TICKET. `none` means
|
| 82 |
+
* asked and answered β this database genuinely binds no measure. `unavailable` means the offer
|
| 83 |
+
* could not be made at all (a warming mirror, say) and `reason` states why. Rendering the
|
| 84 |
+
* second as the first is exactly the conflation the server half was written to end, so the two
|
| 85 |
+
* branches below never share a sentence.
|
| 86 |
+
*/
|
| 87 |
+
metrics?: MetricsCensus;
|
| 88 |
}
|
| 89 |
|
| 90 |
+
/**
|
| 91 |
+
* ββ `MetricsCensus` MOVED TO `permsModel.ts` AND IS RE-EXPORTED HERE β AND THE DIRECTION IS A
|
| 92 |
+
* HARNESS CONSTRAINT, NOT A TIDY-UP. The first draft declared it in THIS file with a note saying
|
| 93 |
+
* the eventual parser should import it from here. Measured, that import is not free:
|
| 94 |
+
* `verify_login.py` compiles `permsModel.ts` with a bare `npx tsc` and **no `--jsx`**, so a
|
| 95 |
+
* type-only `import ... from "./DatabasePermsPane"` raises `TS6142` inside that gate's own
|
| 96 |
+
* compilation. A `.tsx` importing a `.ts` costs nothing; the reverse does. The shape therefore
|
| 97 |
+
* lives beside the parser that produces it, and there is still exactly ONE definition.
|
| 98 |
+
*
|
| 99 |
+
* β THE RE-EXPORT IS NOT DECORATION. It keeps this module's public surface exactly as W46-T34
|
| 100 |
+
* shipped it, so any importer that already reads the name from here β a test, a future pane β
|
| 101 |
+
* does not have to move in the same change.
|
| 102 |
+
*/
|
| 103 |
+
export type { MetricsCensus } from "./permsModel";
|
| 104 |
+
|
| 105 |
export function DatabasePermsPane({
|
| 106 |
module,
|
| 107 |
entries,
|
|
|
|
| 110 |
onToggleHidden,
|
| 111 |
onSetHidden,
|
| 112 |
userOptions,
|
| 113 |
+
metrics,
|
| 114 |
}: DatabasePermsPaneProps) {
|
| 115 |
+
/**
|
| 116 |
+
* ββ THE FALLBACK ANSWERS ONLY THE QUESTION IT CAN ANSWER, AND SILENCE IS THE THIRD ANSWER.
|
| 117 |
+
* Until `parsePermsPayload` carries `metrics_by_module` (out of this ticket's fence), no census
|
| 118 |
+
* reaches this pane, so the count is derived from the metric pseudo-fields already in
|
| 119 |
+
* `module.fields`. That derivation is TRUE when measures exist and a LIE when none appear:
|
| 120 |
+
* `routes_admin` builds the field list and the census from the same `_metric_catalogue` call,
|
| 121 |
+
* so a database whose offer failed ships zero metric fields β indistinguishable here from one
|
| 122 |
+
* that genuinely binds none. Saying "this database has no measures" off that would re-create
|
| 123 |
+
* the exact conflation W46-T34's server half exists to end, so the empty case renders NOTHING
|
| 124 |
+
* and waits for the census. A missing sentence is recoverable; a confident wrong one is not.
|
| 125 |
+
*/
|
| 126 |
+
const derived = module.fields.filter((f) => f.isMetric).length;
|
| 127 |
+
const census: MetricsCensus | null =
|
| 128 |
+
metrics ?? (derived > 0 ? { count: derived, status: "ok" } : null);
|
| 129 |
+
|
| 130 |
return (
|
| 131 |
<div className="set-dbperm">
|
| 132 |
<div className="set-dbperm-head">
|
|
|
|
| 170 |
/>
|
| 171 |
</div>
|
| 172 |
<div className="cg-pop set-perm-pop">
|
| 173 |
+
{/* ββ W46-T34 β THE METRICS GROUP, STATED FOR THIS DATABASE AND NOT FOR ANY OTHER.
|
| 174 |
+
It sits INSIDE the hide-fields pop rather than above the pair, because the rows it
|
| 175 |
+
heads are that panel's own checkboxes ("Metric - Sales", "Metric - Orders"): a
|
| 176 |
+
census floating above both panels would read as a fact about the filter builder too.
|
| 177 |
+
β THREE BRANCHES, NEVER TWO. `ok` counts what is offered; `none` says the database
|
| 178 |
+
binds no measure; `unavailable` says the offer could not be made and prints the
|
| 179 |
+
server's own reason. The second and third share no wording on purpose β "there are
|
| 180 |
+
none" and "I cannot say" are different answers, and merging them is the defect this
|
| 181 |
+
ticket's server half was written to fix.
|
| 182 |
+
β CLASSES ONLY, AND ONLY EXISTING ONES. `perms.css` and `index.css` are out of this
|
| 183 |
+
ticket's fence, so a minted class would render unstyled: `.set-perm-group` is the
|
| 184 |
+
muted group label instruction 8 already established, `.pg-empty` the empty-state
|
| 185 |
+
sentence `ModulePermsList` already uses for the same job one level up. */}
|
| 186 |
+
{census && (
|
| 187 |
+
<p className="set-perm-group">
|
| 188 |
+
{census.status === "ok"
|
| 189 |
+
? `Metrics: ${census.count} ${census.count === 1 ? "measure" : "measures"}`
|
| 190 |
+
: "Metrics"}
|
| 191 |
+
</p>
|
| 192 |
+
)}
|
| 193 |
+
{census && census.status === "none" && (
|
| 194 |
+
<p className="pg-empty">This database has no measures.</p>
|
| 195 |
+
)}
|
| 196 |
+
{census && census.status === "unavailable" && (
|
| 197 |
+
<p className="pg-empty">
|
| 198 |
+
{census.reason
|
| 199 |
+
? `Measures could not be listed: ${census.reason}`
|
| 200 |
+
: "Measures could not be listed, so this database's metrics are unknown."}
|
| 201 |
+
</p>
|
| 202 |
+
)}
|
| 203 |
{/* ββ W40-T16 β THIS LIST IS WHERE THE METRICS RULE NOW LIVES. `module.fields` carries
|
| 204 |
C3's `measure_`-namespaced pseudo-fields, `permsModel::parseField` marks each one,
|
| 205 |
and the panel draws it as an ordinary checkbox named "Metric - Revenue". Checking it
|
web/src/settings/ManageDatabase.tsx
ADDED
|
@@ -0,0 +1,516 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ---------------------------------------------------------------------------
|
| 2 |
+
// settings / ManageDatabase.tsx β WAVE 46 (owner instruction 31, ruling R12,
|
| 3 |
+
// contracts C1 + C6).
|
| 4 |
+
//
|
| 5 |
+
// Owner, verbatim: *"Then we need to be able to update our database schema under
|
| 6 |
+
// Settings. Create a manage database button under Setting so we can configure
|
| 7 |
+
// this. Almost exactly like Manage User, but this time we expose every end
|
| 8 |
+
// points and fields from Odoo and databases."*
|
| 9 |
+
//
|
| 10 |
+
// ββ R1 MAKES MANAGE USER THE STRUCTURAL REFERENCE, NOT AN INSPIRATION, and
|
| 11 |
+
// that decides the shape of this file over the ticket's own `how:` gloss. The
|
| 12 |
+
// gloss cites DESIGN.md Β§4's right-side entity drawer; Manage User is not a
|
| 13 |
+
// drawer. `SettingsModal.UsersPane` holds ONE state (`open`) and, when it is
|
| 14 |
+
// set, RETURNS the detail page in place of the list β a full-pane takeover, the
|
| 15 |
+
// rail staying because it is chrome rather than body (its own "WAVE 17 R7"
|
| 16 |
+
// note). This pane is that arrangement with databases where accounts were:
|
| 17 |
+
// a list of database cards, and one of them opens its fields in place.
|
| 18 |
+
//
|
| 19 |
+
// β R12 BOUNDS v1 TO THREE VERBS: show/hide, relabel, reorder. There is no
|
| 20 |
+
// field typing here, no hard delete and no Odoo endpoint browser, and the
|
| 21 |
+
// absence is the ruling rather than an omission. The owner's "expose every end
|
| 22 |
+
// points and fields" is answered by LISTING every database and every field with
|
| 23 |
+
// its key, label, type and source, which is exactly what the done-when asks for.
|
| 24 |
+
//
|
| 25 |
+
// β EVERY CONTROL HERE IS A COURTESY, NOT A CHECK β the same rule the modal's
|
| 26 |
+
// own header records. `routes_admin.admin_gate` refuses a non-admin on every
|
| 27 |
+
// `/admin/*` route, so a member who reached this component would be handed no
|
| 28 |
+
// data at all. The rail entry and `permsModel.reachableSection` keep them out of
|
| 29 |
+
// an empty room; neither is the wall.
|
| 30 |
+
//
|
| 31 |
+
// β THE ENDPOINT MAY NOT EXIST YET. `platform/core/schema_overlay.py` and its
|
| 32 |
+
// routes land in a later pass of this wave, so a 404 is an expected answer today
|
| 33 |
+
// and is drawn as an honest "could not load" state. β NEVER a fabricated row:
|
| 34 |
+
// a schema editor that invents fields would have an admin hide a column that
|
| 35 |
+
// does not exist and believe they had.
|
| 36 |
+
// ---------------------------------------------------------------------------
|
| 37 |
+
|
| 38 |
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
| 39 |
+
import { API_V1, CREDENTIALS } from "../apiContract";
|
| 40 |
+
// `.set-perm-back` β the way out of a full-pane takeover, already shipped for
|
| 41 |
+
// the Manage User one. Wearing it rather than redrawing it is half of why this
|
| 42 |
+
// pane and that one can be shot side by side and match (W46-T39).
|
| 43 |
+
import "./perms.css";
|
| 44 |
+
// β C6 β the lane sheet is imported HERE, from the component, not added to
|
| 45 |
+
// `index.css`. `index.css` `@import`s the older sheets at its top, so a sheet
|
| 46 |
+
// arriving that way loses every equal-specificity fight with the thousands of
|
| 47 |
+
// rules below it; a sheet imported from a component lands after `index.css` in
|
| 48 |
+
// the bundle and wins. `AssistantPage.tsx:17` is the shipped precedent.
|
| 49 |
+
import "../styles/wave46/manage-database.css";
|
| 50 |
+
|
| 51 |
+
// ββ the wire (contract C1) ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 52 |
+
//
|
| 53 |
+
// Store key `ut_schema_overlay`, one document per tenant, shaped
|
| 54 |
+
// { "<database_key>": { "<field_key>": {hidden, label, order} } }
|
| 55 |
+
// with an absent key meaning "inherit the canonical contract".
|
| 56 |
+
//
|
| 57 |
+
// `GET /api/v1/admin/schema-overlay` returns the MERGED view (contract plus
|
| 58 |
+
// overlay) as `{fields:[{key,label,type,source,hidden,order,locked}]}`; `PATCH`
|
| 59 |
+
// takes a partial of the document above and returns the merged view again.
|
| 60 |
+
|
| 61 |
+
/**
|
| 62 |
+
* ββ `database` IS REQUIRED HERE, AND THE PATCH SHAPE IS WHY. C1 declares the
|
| 63 |
+
* GET's rows without spelling the database key out, but the document a PATCH
|
| 64 |
+
* carries is keyed by `database_key` FIRST. A row that cannot name its database
|
| 65 |
+
* therefore cannot be written back at all β the key is load-bearing for the
|
| 66 |
+
* write path, not a grouping nicety for the list.
|
| 67 |
+
*
|
| 68 |
+
* β SO IT IS NEVER GUESSED. `source` is a FIELD property (where the column comes
|
| 69 |
+
* from) and reusing it as the database key would be the "a grep for a NAME is not
|
| 70 |
+
* a wire key" defect exactly: plausible groups the server never meant, and a
|
| 71 |
+
* PATCH addressed to a database that does not exist. A row missing the key is
|
| 72 |
+
* dropped by the parser and counted, and the pane says how many it dropped.
|
| 73 |
+
*/
|
| 74 |
+
export interface OverlayField {
|
| 75 |
+
/** The `database_key` a PATCH is addressed to. */
|
| 76 |
+
database: string;
|
| 77 |
+
/** What to call that database on screen. Absent β the key, which is honest if ugly. */
|
| 78 |
+
databaseLabel?: string;
|
| 79 |
+
field: string;
|
| 80 |
+
label: string;
|
| 81 |
+
type: string;
|
| 82 |
+
source: string;
|
| 83 |
+
hidden: boolean;
|
| 84 |
+
order: number | null;
|
| 85 |
+
/**
|
| 86 |
+
* A join key or the record id. β The overlay MAY NOT HIDE IT (C1), and that is
|
| 87 |
+
* the whole of what this flag means. It is NOT the "locked database" lock and
|
| 88 |
+
* NOT the "pre-set field" lock (DESIGN.md Β§4) β neither vocabulary is borrowed
|
| 89 |
+
* for it, because a shared word would have an admin read a guarantee about
|
| 90 |
+
* records or about editing that nothing here makes.
|
| 91 |
+
*/
|
| 92 |
+
locked: boolean;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
interface ParsedOverlay {
|
| 96 |
+
fields: OverlayField[];
|
| 97 |
+
/** Rows the server sent that carry no database key, so nothing may be written for them. */
|
| 98 |
+
dropped: number;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
function str(v: unknown, fallback = ""): string {
|
| 102 |
+
return typeof v === "string" && v ? v : fallback;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
/**
|
| 106 |
+
* The parse lives at the BOUNDARY, in one testable function, rather than being
|
| 107 |
+
* spread through the render β the same arrangement `permsModel.parsePermsPayload`
|
| 108 |
+
* uses for the permissions wire and for the same reason: a shape check half in a
|
| 109 |
+
* fetch wrapper and half in JSX is a shape check nobody can read.
|
| 110 |
+
*/
|
| 111 |
+
export function parseOverlay(body: unknown): ParsedOverlay {
|
| 112 |
+
const raw = (body as { fields?: unknown } | null)?.fields;
|
| 113 |
+
if (!Array.isArray(raw)) return { fields: [], dropped: 0 };
|
| 114 |
+
const fields: OverlayField[] = [];
|
| 115 |
+
let dropped = 0;
|
| 116 |
+
for (const item of raw) {
|
| 117 |
+
const r = item as Record<string, unknown> | null;
|
| 118 |
+
if (!r || typeof r !== "object") {
|
| 119 |
+
dropped += 1;
|
| 120 |
+
continue;
|
| 121 |
+
}
|
| 122 |
+
// β TWO SPELLINGS, NOT THREE, AND BOTH ARE EVIDENCED. `database` is the
|
| 123 |
+
// camelCase dialect this client's wires already speak (`accessSummary`,
|
| 124 |
+
// `canBusiness`, `tenantWideTypes`); `database_key` is the name the data
|
| 125 |
+
// layer itself uses (`platform/core/schema_overlay.py`, `locked_keys` and
|
| 126 |
+
// `merge`). Anything else would be a guess wearing a defensive costume β and
|
| 127 |
+
// a wrong-but-accepted spelling is worse than none, because it silently
|
| 128 |
+
// defeats the honest degrade below.
|
| 129 |
+
const database = str(r.database) || str(r.database_key);
|
| 130 |
+
const field = str(r.key);
|
| 131 |
+
if (!database || !field) {
|
| 132 |
+
dropped += 1;
|
| 133 |
+
continue;
|
| 134 |
+
}
|
| 135 |
+
fields.push({
|
| 136 |
+
database,
|
| 137 |
+
databaseLabel: str(r.databaseLabel) || undefined,
|
| 138 |
+
field,
|
| 139 |
+
label: str(r.label, field),
|
| 140 |
+
// An unknown or absent type reads as text, the house fallback the field
|
| 141 |
+
// vocabulary already uses; it is never blank, because a blank cell in a
|
| 142 |
+
// schema list reads as "this field has no type" rather than "not stated".
|
| 143 |
+
type: str(r.type, "text"),
|
| 144 |
+
source: str(r.source, "unknown"),
|
| 145 |
+
hidden: r.hidden === true,
|
| 146 |
+
order: typeof r.order === "number" ? r.order : null,
|
| 147 |
+
locked: r.locked === true,
|
| 148 |
+
});
|
| 149 |
+
}
|
| 150 |
+
return { fields, dropped };
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
/** One database's PATCH body: `{ "<field_key>": {hidden, label, order} }`. */
|
| 154 |
+
type FieldPatch = { hidden?: boolean; label?: string | null; order?: number | null };
|
| 155 |
+
|
| 156 |
+
type Result<T> = { ok: true; data: T } | { ok: false; message: string };
|
| 157 |
+
|
| 158 |
+
/**
|
| 159 |
+
* The fetch idiom is `settingsApi.call`'s, deliberately not an import of it:
|
| 160 |
+
* that module's helper is private to it, and C1's routes are this pane's, so a
|
| 161 |
+
* widening of a shared file for one caller would be a fence this ticket does not
|
| 162 |
+
* own. Same credentials word, same "never surface a 5xx verbatim" rule.
|
| 163 |
+
*/
|
| 164 |
+
async function callOverlay<T>(init?: RequestInit & { body?: string }): Promise<Result<T>> {
|
| 165 |
+
try {
|
| 166 |
+
const res = await fetch(`${API_V1}/admin/schema-overlay`, {
|
| 167 |
+
credentials: CREDENTIALS,
|
| 168 |
+
headers: init?.body ? { "Content-Type": "application/json" } : undefined,
|
| 169 |
+
...init,
|
| 170 |
+
});
|
| 171 |
+
let body: unknown = null;
|
| 172 |
+
try {
|
| 173 |
+
body = await res.json();
|
| 174 |
+
} catch {
|
| 175 |
+
/* an empty body is not fatal; the status below decides */
|
| 176 |
+
}
|
| 177 |
+
if (!res.ok) {
|
| 178 |
+
const err = (body as { error?: { message?: string } } | null)?.error;
|
| 179 |
+
const message =
|
| 180 |
+
res.status === 404
|
| 181 |
+
? "The schema service is not available on this deployment yet."
|
| 182 |
+
: res.status >= 500
|
| 183 |
+
? "Something went wrong on our side. Try again in a moment."
|
| 184 |
+
: err?.message ||
|
| 185 |
+
(res.status === 403
|
| 186 |
+
? "Administrators only."
|
| 187 |
+
: "That change could not be saved.");
|
| 188 |
+
return { ok: false, message };
|
| 189 |
+
}
|
| 190 |
+
return { ok: true, data: body as T };
|
| 191 |
+
} catch {
|
| 192 |
+
return { ok: false, message: "The server could not be reached." };
|
| 193 |
+
}
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
// ββ the pane ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 197 |
+
|
| 198 |
+
/** Sort by the overlay's order where it has one, then by label, so a database
|
| 199 |
+
* with no stored order still lists in a stable, readable sequence rather than
|
| 200 |
+
* in whatever order the server happened to serialise. */
|
| 201 |
+
function inOrder(rows: OverlayField[]): OverlayField[] {
|
| 202 |
+
return [...rows].sort((a, b) => {
|
| 203 |
+
const ao = a.order ?? Number.MAX_SAFE_INTEGER;
|
| 204 |
+
const bo = b.order ?? Number.MAX_SAFE_INTEGER;
|
| 205 |
+
if (ao !== bo) return ao - bo;
|
| 206 |
+
return a.label.localeCompare(b.label);
|
| 207 |
+
});
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
export function ManageDatabasePane() {
|
| 211 |
+
const [parsed, setParsed] = useState<ParsedOverlay | null>(null);
|
| 212 |
+
const [error, setError] = useState("");
|
| 213 |
+
const [notice, setNotice] = useState("");
|
| 214 |
+
const [saving, setSaving] = useState(false);
|
| 215 |
+
/**
|
| 216 |
+
* β ONE STATE, THE WAY `UsersPane` HOLDS ONE. Set, it means "the fields page
|
| 217 |
+
* for this database is the pane"; null, it means the list is. The takeover is
|
| 218 |
+
* a RETURN below, not a second surface layered over the first, so nothing else
|
| 219 |
+
* in the modal has to know which of the two is showing.
|
| 220 |
+
*/
|
| 221 |
+
const [open, setOpen] = useState<string | null>(null);
|
| 222 |
+
/** The unsaved relabel and reorder for the open database, keyed by field. */
|
| 223 |
+
const [draft, setDraft] = useState<Record<string, FieldPatch>>({});
|
| 224 |
+
|
| 225 |
+
const load = useCallback(() => {
|
| 226 |
+
void callOverlay<unknown>().then((r) => {
|
| 227 |
+
if (r.ok) {
|
| 228 |
+
setParsed(parseOverlay(r.data));
|
| 229 |
+
setError("");
|
| 230 |
+
} else {
|
| 231 |
+
// β NOT an empty list dressed as success. `parsed` stays null and the
|
| 232 |
+
// error is what draws, so "the endpoint is not there" can never be read
|
| 233 |
+
// off the screen as "this tenant has no databases".
|
| 234 |
+
setParsed(null);
|
| 235 |
+
setError(r.message);
|
| 236 |
+
}
|
| 237 |
+
});
|
| 238 |
+
}, []);
|
| 239 |
+
|
| 240 |
+
useEffect(load, [load]);
|
| 241 |
+
|
| 242 |
+
const databases = useMemo(() => {
|
| 243 |
+
const byKey = new Map<string, { key: string; label: string; rows: OverlayField[] }>();
|
| 244 |
+
for (const f of parsed?.fields ?? []) {
|
| 245 |
+
const entry = byKey.get(f.database) ?? {
|
| 246 |
+
key: f.database,
|
| 247 |
+
label: f.databaseLabel ?? f.database,
|
| 248 |
+
rows: [],
|
| 249 |
+
};
|
| 250 |
+
entry.rows.push(f);
|
| 251 |
+
byKey.set(f.database, entry);
|
| 252 |
+
}
|
| 253 |
+
return [...byKey.values()].sort((a, b) => a.label.localeCompare(b.label));
|
| 254 |
+
}, [parsed]);
|
| 255 |
+
|
| 256 |
+
const save = useCallback(
|
| 257 |
+
(database: string) => {
|
| 258 |
+
const patch = draft;
|
| 259 |
+
if (Object.keys(patch).length === 0) return;
|
| 260 |
+
setSaving(true);
|
| 261 |
+
void callOverlay<unknown>({
|
| 262 |
+
method: "PATCH",
|
| 263 |
+
body: JSON.stringify({ [database]: patch }),
|
| 264 |
+
}).then((r) => {
|
| 265 |
+
setSaving(false);
|
| 266 |
+
if (r.ok) {
|
| 267 |
+
setParsed(parseOverlay(r.data));
|
| 268 |
+
setDraft({});
|
| 269 |
+
setError("");
|
| 270 |
+
setNotice("Saved.");
|
| 271 |
+
} else {
|
| 272 |
+
setError(r.message);
|
| 273 |
+
setNotice("");
|
| 274 |
+
}
|
| 275 |
+
});
|
| 276 |
+
},
|
| 277 |
+
[draft],
|
| 278 |
+
);
|
| 279 |
+
|
| 280 |
+
if (parsed === null && !error)
|
| 281 |
+
return (
|
| 282 |
+
<div className="set-loading">
|
| 283 |
+
<span className="lp-spin lp-spin--lg" role="status" aria-label="Loading" />
|
| 284 |
+
</div>
|
| 285 |
+
);
|
| 286 |
+
|
| 287 |
+
// ββ the takeover: one database's fields, in place of the list ββββββββββββββ
|
| 288 |
+
if (open) {
|
| 289 |
+
const db = databases.find((d) => d.key === open);
|
| 290 |
+
// The database can vanish under an open page: a save refetches, and a
|
| 291 |
+
// connector may have been removed in between. Saying so beats a page about
|
| 292 |
+
// nothing.
|
| 293 |
+
if (!db) {
|
| 294 |
+
return (
|
| 295 |
+
<div className="set-pane">
|
| 296 |
+
<section className="set-card">
|
| 297 |
+
<h4 className="set-h4">That database is no longer listed</h4>
|
| 298 |
+
<p className="set-help">It may have been removed since this list was loaded.</p>
|
| 299 |
+
<div className="set-actions">
|
| 300 |
+
<button type="button" className="set-secondary" onClick={() => setOpen(null)}>
|
| 301 |
+
Back to databases
|
| 302 |
+
</button>
|
| 303 |
+
</div>
|
| 304 |
+
</section>
|
| 305 |
+
</div>
|
| 306 |
+
);
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
const rows = inOrder(db.rows).map((f) => ({ ...f, ...pick(draft[f.field]) }));
|
| 310 |
+
// The draft's own order wins over the server's, so a move shows immediately.
|
| 311 |
+
rows.sort((a, b) => (a.order ?? Number.MAX_SAFE_INTEGER) - (b.order ?? Number.MAX_SAFE_INTEGER));
|
| 312 |
+
|
| 313 |
+
/** Reorder writes an order for EVERY row, not only the two that swapped: a
|
| 314 |
+
* sparse order over a list that was previously unordered would leave the
|
| 315 |
+
* rest to the tiebreak and read as a random shuffle. */
|
| 316 |
+
const move = (index: number, delta: number) => {
|
| 317 |
+
const next = [...rows];
|
| 318 |
+
const to = index + delta;
|
| 319 |
+
if (to < 0 || to >= next.length) return;
|
| 320 |
+
const [row] = next.splice(index, 1);
|
| 321 |
+
next.splice(to, 0, row);
|
| 322 |
+
setDraft((d) => {
|
| 323 |
+
const out = { ...d };
|
| 324 |
+
next.forEach((r, i) => {
|
| 325 |
+
out[r.field] = { ...out[r.field], order: i };
|
| 326 |
+
});
|
| 327 |
+
return out;
|
| 328 |
+
});
|
| 329 |
+
setNotice("");
|
| 330 |
+
};
|
| 331 |
+
|
| 332 |
+
const dirty = Object.keys(draft).length > 0;
|
| 333 |
+
|
| 334 |
+
return (
|
| 335 |
+
<div className="set-pane">
|
| 336 |
+
<button type="button" className="set-perm-back" onClick={() => setOpen(null)}>
|
| 337 |
+
{/* The chevron the accounts takeover already draws, at the same
|
| 338 |
+
geometry: the house vocabulary extended rather than a second icon
|
| 339 |
+
language imported (DESIGN.md Β§4). */}
|
| 340 |
+
<svg width="14" height="14" viewBox="0 0 16 16" fill="none" aria-hidden focusable="false">
|
| 341 |
+
<path
|
| 342 |
+
d="M9.5 4 5.5 8l4 4"
|
| 343 |
+
stroke="currentColor"
|
| 344 |
+
strokeWidth={1.3}
|
| 345 |
+
strokeLinecap="round"
|
| 346 |
+
strokeLinejoin="round"
|
| 347 |
+
/>
|
| 348 |
+
</svg>
|
| 349 |
+
Back to databases
|
| 350 |
+
</button>
|
| 351 |
+
<div className="set-perm-ident">
|
| 352 |
+
<h3 className="set-h">{db.label}</h3>
|
| 353 |
+
<span className="set-username">{db.key}</span>
|
| 354 |
+
</div>
|
| 355 |
+
|
| 356 |
+
{error ? <p className="set-error">{error}</p> : null}
|
| 357 |
+
{notice ? <p className="set-notice">{notice}</p> : null}
|
| 358 |
+
|
| 359 |
+
<ul className="w46-db-fields">
|
| 360 |
+
{rows.map((f, i) => (
|
| 361 |
+
<li className="w46-db-field" key={f.field}>
|
| 362 |
+
<div className="w46-db-idline">
|
| 363 |
+
<span className="w46-db-key">{f.field}</span>
|
| 364 |
+
<span className="w46-db-meta">
|
| 365 |
+
{f.type} in {f.source}
|
| 366 |
+
</span>
|
| 367 |
+
{f.locked ? (
|
| 368 |
+
<span
|
| 369 |
+
className="set-chip"
|
| 370 |
+
title="This field is a join key or the record id, so it cannot be hidden."
|
| 371 |
+
>
|
| 372 |
+
Always shown
|
| 373 |
+
</span>
|
| 374 |
+
) : null}
|
| 375 |
+
</div>
|
| 376 |
+
<label className="w46-db-relabel">
|
| 377 |
+
<span className="set-label">Label</span>
|
| 378 |
+
<input
|
| 379 |
+
className="set-input"
|
| 380 |
+
type="text"
|
| 381 |
+
value={f.label}
|
| 382 |
+
onChange={(e) => {
|
| 383 |
+
const value = e.currentTarget.value;
|
| 384 |
+
setDraft((d) => ({ ...d, [f.field]: { ...d[f.field], label: value } }));
|
| 385 |
+
setNotice("");
|
| 386 |
+
}}
|
| 387 |
+
/>
|
| 388 |
+
</label>
|
| 389 |
+
<div className="w46-db-acts">
|
| 390 |
+
<label className="set-check">
|
| 391 |
+
<input
|
| 392 |
+
type="checkbox"
|
| 393 |
+
checked={f.hidden}
|
| 394 |
+
disabled={f.locked}
|
| 395 |
+
onChange={(e) => {
|
| 396 |
+
const value = e.currentTarget.checked;
|
| 397 |
+
setDraft((d) => ({ ...d, [f.field]: { ...d[f.field], hidden: value } }));
|
| 398 |
+
setNotice("");
|
| 399 |
+
}}
|
| 400 |
+
/>
|
| 401 |
+
Hidden
|
| 402 |
+
</label>
|
| 403 |
+
<button
|
| 404 |
+
type="button"
|
| 405 |
+
className="w46-db-move"
|
| 406 |
+
onClick={() => move(i, -1)}
|
| 407 |
+
disabled={i === 0}
|
| 408 |
+
aria-label={`Move ${f.label} up`}
|
| 409 |
+
>
|
| 410 |
+
Up
|
| 411 |
+
</button>
|
| 412 |
+
<button
|
| 413 |
+
type="button"
|
| 414 |
+
className="w46-db-move"
|
| 415 |
+
onClick={() => move(i, 1)}
|
| 416 |
+
disabled={i === rows.length - 1}
|
| 417 |
+
aria-label={`Move ${f.label} down`}
|
| 418 |
+
>
|
| 419 |
+
Down
|
| 420 |
+
</button>
|
| 421 |
+
</div>
|
| 422 |
+
</li>
|
| 423 |
+
))}
|
| 424 |
+
</ul>
|
| 425 |
+
|
| 426 |
+
<div className="set-actions">
|
| 427 |
+
<button
|
| 428 |
+
type="button"
|
| 429 |
+
className="set-primary"
|
| 430 |
+
disabled={!dirty || saving}
|
| 431 |
+
onClick={() => save(db.key)}
|
| 432 |
+
>
|
| 433 |
+
{saving ? "Saving" : "Save changes"}
|
| 434 |
+
</button>
|
| 435 |
+
<button
|
| 436 |
+
type="button"
|
| 437 |
+
className="set-secondary"
|
| 438 |
+
disabled={!dirty || saving}
|
| 439 |
+
onClick={() => {
|
| 440 |
+
setDraft({});
|
| 441 |
+
setNotice("");
|
| 442 |
+
}}
|
| 443 |
+
>
|
| 444 |
+
Discard
|
| 445 |
+
</button>
|
| 446 |
+
</div>
|
| 447 |
+
</div>
|
| 448 |
+
);
|
| 449 |
+
}
|
| 450 |
+
|
| 451 |
+
// ββ the list ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 452 |
+
return (
|
| 453 |
+
<div className="set-pane">
|
| 454 |
+
{/* The heading matches the rail entry that opens it (wave 19, owner item
|
| 455 |
+
9): a pane whose title differs from the tab clicked reads as the wrong
|
| 456 |
+
screen. */}
|
| 457 |
+
<h3 className="set-h">Manage database</h3>
|
| 458 |
+
{error ? <p className="set-error">{error}</p> : null}
|
| 459 |
+
{notice ? <p className="set-notice">{notice}</p> : null}
|
| 460 |
+
{parsed && parsed.dropped > 0 ? (
|
| 461 |
+
<p className="set-help">
|
| 462 |
+
{parsed.dropped} field rows name no database, so they cannot be configured here.
|
| 463 |
+
</p>
|
| 464 |
+
) : null}
|
| 465 |
+
|
| 466 |
+
{databases.length === 0 && !error ? (
|
| 467 |
+
<p className="pg-empty">No databases are connected yet. Add one in Connectors.</p>
|
| 468 |
+
) : (
|
| 469 |
+
/* β THE SAME CARD LIST AS MANAGE USER, WEARING ITS CLASSES rather than
|
| 470 |
+
equivalents of them. W46-T39 reads computed font size and colour off
|
| 471 |
+
both panes and requires them to match per role; the cheapest way to be
|
| 472 |
+
right is to be the same rule, not a copy of it. One `<button>` per
|
| 473 |
+
database is one control with the whole card as its hit box, focusable
|
| 474 |
+
and Enter-able for free. */
|
| 475 |
+
<ul className="set-acctlist">
|
| 476 |
+
{databases.map((d) => (
|
| 477 |
+
<li key={d.key}>
|
| 478 |
+
<button type="button" className="set-acct" onClick={() => setOpen(d.key)}>
|
| 479 |
+
<span className="set-acct-body">
|
| 480 |
+
<span className="set-acct-top">
|
| 481 |
+
<span className="set-acct-name">{d.label}</span>
|
| 482 |
+
</span>
|
| 483 |
+
<span className="set-acct-sub">{d.key}</span>
|
| 484 |
+
<span className="set-acct-access">{fieldWords(d.rows)}</span>
|
| 485 |
+
</span>
|
| 486 |
+
{/* A SPAN, NOT A BUTTON: it sits inside the card's own button, so
|
| 487 |
+
the word opens exactly what clicking the card opens. A nested
|
| 488 |
+
button is invalid markup and would put two tab stops on one
|
| 489 |
+
destination. */}
|
| 490 |
+
<span className="set-acct-go">Edit</span>
|
| 491 |
+
</button>
|
| 492 |
+
</li>
|
| 493 |
+
))}
|
| 494 |
+
</ul>
|
| 495 |
+
)}
|
| 496 |
+
</div>
|
| 497 |
+
);
|
| 498 |
+
}
|
| 499 |
+
|
| 500 |
+
/** One sentence for a database's card, in the register the accounts list uses. */
|
| 501 |
+
function fieldWords(rows: OverlayField[]): string {
|
| 502 |
+
const hidden = rows.filter((r) => r.hidden).length;
|
| 503 |
+
const fields = `${rows.length} ${rows.length === 1 ? "field" : "fields"}`;
|
| 504 |
+
return hidden ? `${fields}, ${hidden} hidden` : fields;
|
| 505 |
+
}
|
| 506 |
+
|
| 507 |
+
/** The draft merged over a server row, so the list shows unsaved edits without
|
| 508 |
+
* the draft having to carry the parts nobody touched. */
|
| 509 |
+
function pick(patch: FieldPatch | undefined): Partial<OverlayField> {
|
| 510 |
+
if (!patch) return {};
|
| 511 |
+
const out: Partial<OverlayField> = {};
|
| 512 |
+
if (typeof patch.label === "string") out.label = patch.label;
|
| 513 |
+
if (typeof patch.hidden === "boolean") out.hidden = patch.hidden;
|
| 514 |
+
if (patch.order !== undefined) out.order = patch.order;
|
| 515 |
+
return out;
|
| 516 |
+
}
|
web/src/settings/PermsEditor.tsx
CHANGED
|
@@ -763,6 +763,21 @@ export function PermsEditor({
|
|
| 763 |
onSetHidden={(keys) =>
|
| 764 |
setDraft((d) => setHidden(metricNormalized(d, editModule.key), editModule.key, keys))}
|
| 765 |
userOptions={userOptions}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 766 |
/>
|
| 767 |
</div>
|
| 768 |
);
|
|
|
|
| 763 |
onSetHidden={(keys) =>
|
| 764 |
setDraft((d) => setHidden(metricNormalized(d, editModule.key), editModule.key, keys))}
|
| 765 |
userOptions={userOptions}
|
| 766 |
+
/**
|
| 767 |
+
* ββ W46-T34 β THE METRIC CENSUS FOR THIS DATABASE, AND THIS LINE IS WHAT MAKES THE
|
| 768 |
+
* PANE'S `none` AND `unavailable` BRANCHES REACHABLE AT ALL. The server has published
|
| 769 |
+
* `metrics_by_module` since the ticket's first half; nothing read it, so the pane could
|
| 770 |
+
* only ever see its own field-count fallback and the two branches were dead code with
|
| 771 |
+
* every gate green ([[a-built-validated-wall-can-have-no-caller]]).
|
| 772 |
+
*
|
| 773 |
+
* β `undefined` FOR A DATABASE THE SERVER DID NOT REPORT ON, and that is the correct
|
| 774 |
+
* absence rather than a gap. `parsePermsPayload` keeps the map SPARSE: an older server,
|
| 775 |
+
* or an entry whose `status` is not one of the three, leaves no key here, and the pane
|
| 776 |
+
* then falls back to counting its own metric rows β the one reading that refuses to
|
| 777 |
+
* call an empty list "none". Substituting a zero census here would print the confident
|
| 778 |
+
* wrong sentence for exactly the case nobody could answer.
|
| 779 |
+
*/
|
| 780 |
+
metrics={payload?.metricsByModule?.[editModule.key]}
|
| 781 |
/>
|
| 782 |
</div>
|
| 783 |
);
|
web/src/settings/SettingsModal.tsx
CHANGED
|
@@ -60,6 +60,9 @@ import { PermsEditor } from "./PermsEditor";
|
|
| 60 |
// Wave 19 contract C2 β session D's self-contained plane; see the mount below.
|
| 61 |
import { AdminPane } from "./AdminPane";
|
| 62 |
import { ManageAgentPane } from "../manage-agent/ManageAgentPane";
|
|
|
|
|
|
|
|
|
|
| 63 |
import OperatorPage from "../operator/OperatorPage";
|
| 64 |
/* β `StatementsPane` LEFT WITH ITS RAIL ROW (wave 35 Β· T38): the file is DELETED, not merely
|
| 65 |
unmounted. An orphaned component with no importer is the shape this repo books as
|
|
@@ -139,6 +142,18 @@ const IconUsers = (
|
|
| 139 |
<path d="M10.7 4.1a2.3 2.3 0 0 1 0 4.3M11.6 9.9c1.5.4 2.5 1.5 2.5 3.3" />
|
| 140 |
</RailIcon>
|
| 141 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
/** Manage agent β a channel bot. Deliberately NOT a second person glyph: the
|
| 143 |
* principal here is a CHANNEL, and a rail that draws it as a user invites the
|
| 144 |
* per-person reading the pane's first sentence exists to correct. A speech
|
|
@@ -766,6 +781,12 @@ export function SettingsModal({
|
|
| 766 |
...(admin
|
| 767 |
? ([
|
| 768 |
["users", "Manage users", IconUsers],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 769 |
// β WAVE 33, owner item 10 β placed by the owner, verbatim: *"under a
|
| 770 |
// module called 'Manage agent' which should be under 'Manage user'"*.
|
| 771 |
// Immediately after `users`, so "under" is literal in the rail rather
|
|
@@ -850,6 +871,13 @@ export function SettingsModal({
|
|
| 850 |
fetches its own data and owns its loading/empty/error states β and
|
| 851 |
`reachableSection` has already bounced a non-admin to Account. */}
|
| 852 |
{active === "agents" ? <ManageAgentPane /> : null}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 853 |
{active === "keychains" ? <KeychainPane /> : null}
|
| 854 |
{active === "connectors" ? <ConnectorsPane /> : null}
|
| 855 |
{/* Wave 19 contract C2 β the wiring record, verified at the MOUNT SITE
|
|
|
|
| 60 |
// Wave 19 contract C2 β session D's self-contained plane; see the mount below.
|
| 61 |
import { AdminPane } from "./AdminPane";
|
| 62 |
import { ManageAgentPane } from "../manage-agent/ManageAgentPane";
|
| 63 |
+
// Wave 46 (owner instruction 31, R12 / contract C1) β the schema overlay pane, wired the way C2's
|
| 64 |
+
// lesson demands: at the MOUNT SITE below, not by an import a grep would mistake for a render.
|
| 65 |
+
import { ManageDatabasePane } from "./ManageDatabase";
|
| 66 |
import OperatorPage from "../operator/OperatorPage";
|
| 67 |
/* β `StatementsPane` LEFT WITH ITS RAIL ROW (wave 35 Β· T38): the file is DELETED, not merely
|
| 68 |
unmounted. An orphaned component with no importer is the shape this repo books as
|
|
|
|
| 142 |
<path d="M10.7 4.1a2.3 2.3 0 0 1 0 4.3M11.6 9.9c1.5.4 2.5 1.5 2.5 3.3" />
|
| 143 |
</RailIcon>
|
| 144 |
);
|
| 145 |
+
/** Manage database β a stack of records with a rule laid across it. Deliberately
|
| 146 |
+
* NOT the plates `IconTenants` wears: those mean MANY TENANTS, and two stacked
|
| 147 |
+
* glyphs meaning different scopes in one rail is the drift that makes a rail
|
| 148 |
+
* unreadable. This is one cylinder, the shape the product already means by "a
|
| 149 |
+
* database", with a line marking the schema laid over its rows. */
|
| 150 |
+
const IconDatabase = (
|
| 151 |
+
<RailIcon>
|
| 152 |
+
<ellipse cx="8" cy="4.1" rx="5.1" ry="2.2" />
|
| 153 |
+
<path d="M2.9 4.1v7.8c0 1.2 2.3 2.2 5.1 2.2s5.1-1 5.1-2.2V4.1" />
|
| 154 |
+
<path d="M2.9 8c0 1.2 2.3 2.2 5.1 2.2s5.1-1 5.1-2.2" />
|
| 155 |
+
</RailIcon>
|
| 156 |
+
);
|
| 157 |
/** Manage agent β a channel bot. Deliberately NOT a second person glyph: the
|
| 158 |
* principal here is a CHANNEL, and a rail that draws it as a user invites the
|
| 159 |
* per-person reading the pane's first sentence exists to correct. A speech
|
|
|
|
| 781 |
...(admin
|
| 782 |
? ([
|
| 783 |
["users", "Manage users", IconUsers],
|
| 784 |
+
// β WAVE 46, owner instruction 31 β placed by the owner, verbatim:
|
| 785 |
+
// *"Create a manage database button under Setting β¦ Almost exactly like
|
| 786 |
+
// Manage User"*. So it sits immediately after `users`, beside the room it
|
| 787 |
+
// is modelled on, rather than in a corner of its own. R12 bounds what is
|
| 788 |
+
// behind it to show/hide, relabel and reorder.
|
| 789 |
+
["database", "Manage database", IconDatabase],
|
| 790 |
// β WAVE 33, owner item 10 β placed by the owner, verbatim: *"under a
|
| 791 |
// module called 'Manage agent' which should be under 'Manage user'"*.
|
| 792 |
// Immediately after `users`, so "under" is literal in the rail rather
|
|
|
|
| 871 |
fetches its own data and owns its loading/empty/error states β and
|
| 872 |
`reachableSection` has already bounced a non-admin to Account. */}
|
| 873 |
{active === "agents" ? <ManageAgentPane /> : null}
|
| 874 |
+
{/* Wave 46 (owner instruction 31, R12 / contract C1). Self-contained like its
|
| 875 |
+
neighbours: it fetches the merged schema overlay itself and owns its loading,
|
| 876 |
+
empty and could-not-load states, so mounting it cannot fail on plumbing.
|
| 877 |
+
`reachableSection` has already bounced a non-admin to Account, and
|
| 878 |
+
`admin_gate` refuses the data regardless β the rail is the courtesy, the
|
| 879 |
+
server is the wall. */}
|
| 880 |
+
{active === "database" ? <ManageDatabasePane /> : null}
|
| 881 |
{active === "keychains" ? <KeychainPane /> : null}
|
| 882 |
{active === "connectors" ? <ConnectorsPane /> : null}
|
| 883 |
{/* Wave 19 contract C2 β the wiring record, verified at the MOUNT SITE
|
web/src/settings/permsModel.ts
CHANGED
|
@@ -50,6 +50,17 @@ export type SettingsSection =
|
|
| 50 |
* the same reason `users` is: every control in it 403s a member.
|
| 51 |
*/
|
| 52 |
| "agents"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
// Wave 18 (C7): the tenant's credential store and its data-source status board.
|
| 54 |
| "keychains"
|
| 55 |
| "connectors"
|
|
@@ -148,7 +159,14 @@ export function reachableSection(
|
|
| 148 |
// that the routes refuse β this list is what stops the EMPTY FRAME, and a new
|
| 149 |
// admin room added to the rail without a line here is the defect this
|
| 150 |
// function's header describes.
|
| 151 |
-
section === "agents"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
// β The cast is safe BECAUSE of the retired-section guard at the top: every value reaching here
|
| 153 |
// is either a current member of the union or has already been degraded to "account".
|
| 154 |
return adminOnly && !admin ? "account" : (section as SettingsSection);
|
|
@@ -398,6 +416,35 @@ export interface PermsModule {
|
|
| 398 |
*/
|
| 399 |
}
|
| 400 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 401 |
export interface PermsPayload {
|
| 402 |
/** In server order β the order the sections render in. */
|
| 403 |
modules: PermsModule[];
|
|
@@ -413,6 +460,16 @@ export interface PermsPayload {
|
|
| 413 |
/** This account is an ADMIN, and admins bypass `perms` entirely. Every rule
|
| 414 |
* the editor can draw for them is inert β which it has to say out loud. */
|
| 415 |
isAdmin: boolean;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 416 |
}
|
| 417 |
|
| 418 |
// --- parsing ----------------------------------------------------------------
|
|
@@ -571,6 +628,47 @@ export function parseFilter(raw: unknown): FilterTree | null {
|
|
| 571 |
};
|
| 572 |
}
|
| 573 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 574 |
/** β ABSENT ENTRY β `access: false`, matching what the server will ENFORCE for a
|
| 575 |
* migrated record (C-PERM amendment 4: `perms_v == 1` + no entry β DENY). The
|
| 576 |
* editor showing "access on" for a module the wall denies would send an admin
|
|
@@ -758,6 +856,22 @@ export function parsePermsPayload(body: unknown): PermsPayload | null {
|
|
| 758 |
const entries: PermsRecord = {};
|
| 759 |
for (const m of modules) entries[m.key] = parseEntry(rawPerms[m.key]);
|
| 760 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 761 |
return {
|
| 762 |
modules,
|
| 763 |
entries,
|
|
@@ -767,6 +881,7 @@ export function parsePermsPayload(body: unknown): PermsPayload | null {
|
|
| 767 |
// the route so the editor can SAY so instead of rendering stored rules that
|
| 768 |
// do not apply β the one misreading of that clause that could hurt.
|
| 769 |
isAdmin: b.is_admin === true,
|
|
|
|
| 770 |
};
|
| 771 |
}
|
| 772 |
|
|
|
|
| 50 |
* the same reason `users` is: every control in it 403s a member.
|
| 51 |
*/
|
| 52 |
| "agents"
|
| 53 |
+
/**
|
| 54 |
+
* β WAVE 46 (owner instruction 31, ruling R12) β MANAGE DATABASE: the tenant's
|
| 55 |
+
* schema overlay, where an admin may show/hide, relabel and reorder the fields
|
| 56 |
+
* of every connected database. The owner placed it verbatim: *"Create a manage
|
| 57 |
+
* database button under Setting β¦ Almost exactly like Manage User"* β so it is
|
| 58 |
+
* the rail entry immediately after `users`, wearing that pane's structure. R12
|
| 59 |
+
* bounds v1 to those three verbs; there is no field typing and no delete.
|
| 60 |
+
* Admin-only, and listed in `reachableSection` below for the reason `users` is:
|
| 61 |
+
* every `/admin/schema-overlay` call 403s a member.
|
| 62 |
+
*/
|
| 63 |
+
| "database"
|
| 64 |
// Wave 18 (C7): the tenant's credential store and its data-source status board.
|
| 65 |
| "keychains"
|
| 66 |
| "connectors"
|
|
|
|
| 159 |
// that the routes refuse β this list is what stops the EMPTY FRAME, and a new
|
| 160 |
// admin room added to the rail without a line here is the defect this
|
| 161 |
// function's header describes.
|
| 162 |
+
section === "agents" ||
|
| 163 |
+
// β WAVE 46 (owner instruction 31, R12) β Manage database is admin-only on
|
| 164 |
+
// the same footing: `GET`/`PATCH /admin/schema-overlay` sit behind
|
| 165 |
+
// `admin_gate`, so a member deep-linked here would meet a room that cannot
|
| 166 |
+
// even list a database. β The line is not optional decoration on the rail
|
| 167 |
+
// entry: it is what stops the EMPTY FRAME this function's header names, and
|
| 168 |
+
// a new admin room added without it is precisely that defect.
|
| 169 |
+
section === "database";
|
| 170 |
// β The cast is safe BECAUSE of the retired-section guard at the top: every value reaching here
|
| 171 |
// is either a current member of the union or has already been degraded to "account".
|
| 172 |
return adminOnly && !admin ? "account" : (section as SettingsSection);
|
|
|
|
| 416 |
*/
|
| 417 |
}
|
| 418 |
|
| 419 |
+
/**
|
| 420 |
+
* ββ W46-T34 β ONE DATABASE'S METRIC CENSUS, as `routes_admin::get_perms` ships it under
|
| 421 |
+
* `metrics_by_module[key]` (built from `_metric_catalogue(k)[1]`).
|
| 422 |
+
*
|
| 423 |
+
* β `status` IS THREE ANSWERS, NOT TWO, AND THAT IS THE WHOLE POINT OF THE SHAPE. `none` means
|
| 424 |
+
* asked and answered: this database binds no measure. `unavailable` means the offer could not be
|
| 425 |
+
* made at all (a warming mirror, a store that could not be read) and `reason` says why. The two
|
| 426 |
+
* arrived in IDENTICAL JSON before this ticket β an empty list β which is the conflation the
|
| 427 |
+
* server half was written to end. `DatabasePermsPane` renders them with no shared wording.
|
| 428 |
+
*
|
| 429 |
+
* ββ DECLARED HERE RATHER THAN IN `DatabasePermsPane.tsx`, WHICH IS THE REVERSE OF WHAT THE
|
| 430 |
+
* PANE'S FIRST DRAFT SAID, AND IT IS A HARNESS CONSTRAINT RATHER THAN A PREFERENCE.
|
| 431 |
+
* `verify_login.py` compiles THIS module with a bare `npx tsc` and **no `--jsx`**, so even a
|
| 432 |
+
* TYPE-ONLY import from a `.tsx` raises `TS6142` inside that gate's own compilation (measured:
|
| 433 |
+
* the artifacts still emit and the suites still run, but the gate then carries a standing
|
| 434 |
+
* compile error nobody put there on purpose). A `.tsx` importing a `.ts` is free; the other
|
| 435 |
+
* direction is not. The pane RE-EXPORTS this name, so there is exactly one definition and no
|
| 436 |
+
* importer of `DatabasePermsPane`'s surface had to move.
|
| 437 |
+
*/
|
| 438 |
+
export interface MetricsCensus {
|
| 439 |
+
/** How many measures this database offers. */
|
| 440 |
+
count: number;
|
| 441 |
+
/** How many were bound but could not be offered. Reported by the server; not rendered. */
|
| 442 |
+
refused?: number;
|
| 443 |
+
status: "ok" | "none" | "unavailable";
|
| 444 |
+
/** Why the offer could not be made. Only meaningful for `unavailable`. */
|
| 445 |
+
reason?: string;
|
| 446 |
+
}
|
| 447 |
+
|
| 448 |
export interface PermsPayload {
|
| 449 |
/** In server order β the order the sections render in. */
|
| 450 |
modules: PermsModule[];
|
|
|
|
| 460 |
/** This account is an ADMIN, and admins bypass `perms` entirely. Every rule
|
| 461 |
* the editor can draw for them is inert β which it has to say out loud. */
|
| 462 |
isAdmin: boolean;
|
| 463 |
+
/**
|
| 464 |
+
* ββ W46-T34 β the metric census PER DATABASE, keyed exactly as `modules[].key` is.
|
| 465 |
+
*
|
| 466 |
+
* β SPARSE ON PURPOSE, AND AN ABSENT KEY IS NOT AN EMPTY CENSUS. A module the server did not
|
| 467 |
+
* report on β an older server, a malformed entry β has NO entry here, so the pane falls back to
|
| 468 |
+
* counting its own metric rows, which is the one reading that cannot lie in the direction that
|
| 469 |
+
* matters (see `parseMetricsCensus`). Manufacturing `{count: 0, status: "none"}` for a missing
|
| 470 |
+
* key would put the confident wrong sentence on screen for exactly the case nobody asked about.
|
| 471 |
+
*/
|
| 472 |
+
metricsByModule: Record<string, MetricsCensus>;
|
| 473 |
}
|
| 474 |
|
| 475 |
// --- parsing ----------------------------------------------------------------
|
|
|
|
| 628 |
};
|
| 629 |
}
|
| 630 |
|
| 631 |
+
/**
|
| 632 |
+
* ββ W46-T34 β ONE ENTRY OF `metrics_by_module`, WHITELISTED THE WAY EVERYTHING ELSE ON THIS
|
| 633 |
+
* WIRE IS. Returns `null` for anything it cannot read, and the CALLER DROPS THE KEY rather than
|
| 634 |
+
* substituting a census.
|
| 635 |
+
*
|
| 636 |
+
* ββ THE FALLBACK IS "NO CENSUS", NEVER `none` AND NEVER `unavailable`, and this is the one
|
| 637 |
+
* decision in the function. `DatabasePermsPane` renders an absent census by counting its own
|
| 638 |
+
* metric rows and, when that count is zero, by saying NOTHING β because `routes_admin` builds the
|
| 639 |
+
* field list and the census from the SAME `_metric_catalogue` call, so a database whose offer
|
| 640 |
+
* failed ships zero metric fields and a zero count cannot tell `none` from `unavailable`.
|
| 641 |
+
* Defaulting an unreadable entry to `none` would print "this database has no measures" over a
|
| 642 |
+
* failed offer: the precise lie W46-T34 exists to end, arriving through its own reader. Defaulting
|
| 643 |
+
* to `unavailable` is the mirror-image lie and additionally has no `reason` to give.
|
| 644 |
+
*
|
| 645 |
+
* β `status` IS VALIDATED AGAINST THE THREE LITERALS rather than cast. A cast would let
|
| 646 |
+
* `status: "warming"` β or a typo β through to a render whose three branches all test equality,
|
| 647 |
+
* where it would silently match none of them and paint the group heading with no sentence under
|
| 648 |
+
* it. `count` is coerced to a finite non-negative integer for the same reason: it is printed.
|
| 649 |
+
*/
|
| 650 |
+
export function parseMetricsCensus(raw: unknown): MetricsCensus | null {
|
| 651 |
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
|
| 652 |
+
const r = raw as Record<string, unknown>;
|
| 653 |
+
const status =
|
| 654 |
+
r.status === "ok" || r.status === "none" || r.status === "unavailable" ? r.status : null;
|
| 655 |
+
if (!status) return null;
|
| 656 |
+
const count =
|
| 657 |
+
typeof r.count === "number" && Number.isFinite(r.count) && r.count >= 0
|
| 658 |
+
? Math.floor(r.count)
|
| 659 |
+
: 0;
|
| 660 |
+
return {
|
| 661 |
+
count,
|
| 662 |
+
status,
|
| 663 |
+
...(typeof r.refused === "number" && Number.isFinite(r.refused) && r.refused >= 0
|
| 664 |
+
? { refused: Math.floor(r.refused) }
|
| 665 |
+
: {}),
|
| 666 |
+
// β An EMPTY reason is no reason: the pane's `unavailable` branch has a sentence for the
|
| 667 |
+
// reasonless case, and a blank string would render "Measures could not be listed: ".
|
| 668 |
+
...(typeof r.reason === "string" && r.reason !== "" ? { reason: r.reason } : {}),
|
| 669 |
+
};
|
| 670 |
+
}
|
| 671 |
+
|
| 672 |
/** β ABSENT ENTRY β `access: false`, matching what the server will ENFORCE for a
|
| 673 |
* migrated record (C-PERM amendment 4: `perms_v == 1` + no entry β DENY). The
|
| 674 |
* editor showing "access on" for a module the wall denies would send an admin
|
|
|
|
| 856 |
const entries: PermsRecord = {};
|
| 857 |
for (const m of modules) entries[m.key] = parseEntry(rawPerms[m.key]);
|
| 858 |
|
| 859 |
+
// ββ W46-T34 β THE METRIC CENSUS, CARRIED. Without this the `none` and `unavailable` branches
|
| 860 |
+
// `DatabasePermsPane` already draws are UNREACHABLE: the pane's prop had no producer, so the
|
| 861 |
+
// pane could only ever see its own field-count fallback ([[a-built-validated-wall-can-have-no-
|
| 862 |
+
// caller]]). β Read off `modules`, not off `Object.keys` of the raw map, so a key the server
|
| 863 |
+
// reports for a database it did not declare cannot enter the payload the editor indexes.
|
| 864 |
+
const rawCensus =
|
| 865 |
+
b.metrics_by_module && typeof b.metrics_by_module === "object" &&
|
| 866 |
+
!Array.isArray(b.metrics_by_module)
|
| 867 |
+
? (b.metrics_by_module as Record<string, unknown>)
|
| 868 |
+
: {};
|
| 869 |
+
const metricsByModule: Record<string, MetricsCensus> = {};
|
| 870 |
+
for (const m of modules) {
|
| 871 |
+
const parsed = parseMetricsCensus(rawCensus[m.key]);
|
| 872 |
+
if (parsed) metricsByModule[m.key] = parsed;
|
| 873 |
+
}
|
| 874 |
+
|
| 875 |
return {
|
| 876 |
modules,
|
| 877 |
entries,
|
|
|
|
| 881 |
// the route so the editor can SAY so instead of rendering stored rules that
|
| 882 |
// do not apply β the one misreading of that clause that could hurt.
|
| 883 |
isAdmin: b.is_admin === true,
|
| 884 |
+
metricsByModule,
|
| 885 |
};
|
| 886 |
}
|
| 887 |
|
web/src/shell/NavExtras.tsx
CHANGED
|
@@ -23,6 +23,14 @@ import type { NavFolder, SchemaPayload, TableFootprint } from "./nav";
|
|
| 23 |
// nothing on screen to say why. These are READ-ONLY imports across the session
|
| 24 |
// fence: `customer-grid/**` is another session's tree this wave (HARD RULE 3).
|
| 25 |
import "./navExtras.css";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
/**
|
| 28 |
* WAVE 21 item 12 (ruling R11) β HORIZONTAL, and it is the same three dots turned
|
|
@@ -46,6 +54,38 @@ function DotsIcon() {
|
|
| 46 |
);
|
| 47 |
}
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
function FixedFolderMark() {
|
| 50 |
return (
|
| 51 |
<svg
|
|
@@ -286,6 +326,7 @@ export function RowMenu({
|
|
| 286 |
onSchema();
|
| 287 |
}}
|
| 288 |
>
|
|
|
|
| 289 |
View schema
|
| 290 |
</button>
|
| 291 |
) : null}
|
|
@@ -814,34 +855,39 @@ export function SchemaDrawer({
|
|
| 814 |
<div className="shell-schema-kicker">
|
| 815 |
Fields Β· {state.schema.fields.length}
|
| 816 |
</div>
|
| 817 |
-
|
| 818 |
-
|
| 819 |
-
|
| 820 |
-
|
| 821 |
-
|
| 822 |
-
|
| 823 |
-
|
| 824 |
-
|
| 825 |
-
|
| 826 |
-
|
| 827 |
-
<tr key={f.key}>
|
| 828 |
-
<td>
|
| 829 |
-
<div className="shell-schema-fname">{f.label}</div>
|
| 830 |
-
{f.description && (
|
| 831 |
-
<div className="shell-schema-fdesc">{f.description}</div>
|
| 832 |
-
)}
|
| 833 |
-
{f.options && (
|
| 834 |
-
<div className="shell-schema-fdesc">
|
| 835 |
-
Choices: {f.options.join(" Β· ")}
|
| 836 |
-
</div>
|
| 837 |
-
)}
|
| 838 |
-
</td>
|
| 839 |
-
<td className="shell-schema-type">{f.type}</td>
|
| 840 |
-
<td className="shell-schema-type">{f.source}</td>
|
| 841 |
</tr>
|
| 842 |
-
|
| 843 |
-
|
| 844 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 845 |
</>
|
| 846 |
)}
|
| 847 |
{state.schema.measures.length > 0 && (
|
|
@@ -849,13 +895,15 @@ export function SchemaDrawer({
|
|
| 849 |
<div className="shell-schema-kicker">
|
| 850 |
Semantic measures Β· {state.schema.measures.length}
|
| 851 |
</div>
|
| 852 |
-
<div className="shell-schema-
|
| 853 |
-
|
| 854 |
-
|
| 855 |
-
<
|
| 856 |
-
|
| 857 |
-
|
| 858 |
-
|
|
|
|
|
|
|
| 859 |
</div>
|
| 860 |
</>
|
| 861 |
)}
|
|
|
|
| 23 |
// nothing on screen to say why. These are READ-ONLY imports across the session
|
| 24 |
// fence: `customer-grid/**` is another session's tree this wave (HARD RULE 3).
|
| 25 |
import "./navExtras.css";
|
| 26 |
+
// β W46-T45 / C6 β AFTER `navExtras.css`, DELIBERATELY AND ALWAYS. The wave sheet
|
| 27 |
+
// re-shapes the schema drawer onto the Settings modal's values, so it must land
|
| 28 |
+
// LATER in the bundle than the sheet it overrides; a wave sheet is imported by
|
| 29 |
+
// the component that owns its surface and never added to `index.css`, which
|
| 30 |
+
// would give a lane-local override a global blast radius. Every selector in it
|
| 31 |
+
// is additionally anchored on `.shell-schema`, so it wins on specificity too
|
| 32 |
+
// and does not rest on import order alone.
|
| 33 |
+
import "../styles/wave46/schema-viewer.css";
|
| 34 |
|
| 35 |
/**
|
| 36 |
* WAVE 21 item 12 (ruling R11) β HORIZONTAL, and it is the same three dots turned
|
|
|
|
| 54 |
);
|
| 55 |
}
|
| 56 |
|
| 57 |
+
/**
|
| 58 |
+
* W46-T45 (owner instruction 23) β the mark on "View schema".
|
| 59 |
+
*
|
| 60 |
+
* β LOCAL, NOT `customer-grid/iconShapes.ts`. That module is the GRID's shape
|
| 61 |
+
* vocabulary (the 12 shapes a database icon may take) and belongs to another
|
| 62 |
+
* session's tree; DESIGN.md Β§4 counts shell glyphs as part of the same
|
| 63 |
+
* vocabulary but the shell draws its own, exactly as `DotsIcon`, `PlusIcon` and
|
| 64 |
+
* `FixedFolderMark` above already do. Same grammar as `PlusIcon`: a 16-square
|
| 65 |
+
* viewBox, `aria-hidden` because the row's own words are the label, no fill,
|
| 66 |
+
* `currentColor` for the stroke, and every dimension in CSS rather than an
|
| 67 |
+
* inline style.
|
| 68 |
+
*
|
| 69 |
+
* β A TABLE GRID, NOT A FOLDER. The folder mark already means "a folder in the
|
| 70 |
+
* rail" here, and a second meaning on the same picture is the drift a shared
|
| 71 |
+
* vocabulary exists to prevent. Header rule plus one column divider reads as
|
| 72 |
+
* "the shape of the data", which is what the panel behind it shows.
|
| 73 |
+
*/
|
| 74 |
+
function SchemaIcon() {
|
| 75 |
+
return (
|
| 76 |
+
<svg
|
| 77 |
+
viewBox="0 0 16 16"
|
| 78 |
+
aria-hidden="true"
|
| 79 |
+
fill="none"
|
| 80 |
+
stroke="currentColor"
|
| 81 |
+
className="shell-schema-glyph"
|
| 82 |
+
>
|
| 83 |
+
<rect x="2.4" y="3.2" width="11.2" height="9.6" rx="1.4" />
|
| 84 |
+
<path d="M2.4 6.5h11.2M2.4 9.65h11.2M6.6 6.5v6.3" />
|
| 85 |
+
</svg>
|
| 86 |
+
);
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
function FixedFolderMark() {
|
| 90 |
return (
|
| 91 |
<svg
|
|
|
|
| 326 |
onSchema();
|
| 327 |
}}
|
| 328 |
>
|
| 329 |
+
<SchemaIcon />
|
| 330 |
View schema
|
| 331 |
</button>
|
| 332 |
) : null}
|
|
|
|
| 855 |
<div className="shell-schema-kicker">
|
| 856 |
Fields Β· {state.schema.fields.length}
|
| 857 |
</div>
|
| 858 |
+
{/* W46-T45 β ONE containment layer, the `.set-card` sibling of the
|
| 859 |
+
Settings modal. The kicker stays outside it, exactly as
|
| 860 |
+
`.set-h4` sits above `.set-card`. */}
|
| 861 |
+
<div className="shell-schema-card">
|
| 862 |
+
<table className="shell-schema-table">
|
| 863 |
+
<thead>
|
| 864 |
+
<tr>
|
| 865 |
+
<th>Field</th>
|
| 866 |
+
<th>Type</th>
|
| 867 |
+
<th>Source</th>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 868 |
</tr>
|
| 869 |
+
</thead>
|
| 870 |
+
<tbody>
|
| 871 |
+
{state.schema.fields.map((f) => (
|
| 872 |
+
<tr key={f.key}>
|
| 873 |
+
<td>
|
| 874 |
+
<div className="shell-schema-fname">{f.label}</div>
|
| 875 |
+
{f.description && (
|
| 876 |
+
<div className="shell-schema-fdesc">{f.description}</div>
|
| 877 |
+
)}
|
| 878 |
+
{f.options && (
|
| 879 |
+
<div className="shell-schema-fdesc">
|
| 880 |
+
Choices: {f.options.join(" Β· ")}
|
| 881 |
+
</div>
|
| 882 |
+
)}
|
| 883 |
+
</td>
|
| 884 |
+
<td className="shell-schema-type">{f.type}</td>
|
| 885 |
+
<td className="shell-schema-type">{f.source}</td>
|
| 886 |
+
</tr>
|
| 887 |
+
))}
|
| 888 |
+
</tbody>
|
| 889 |
+
</table>
|
| 890 |
+
</div>
|
| 891 |
</>
|
| 892 |
)}
|
| 893 |
{state.schema.measures.length > 0 && (
|
|
|
|
| 895 |
<div className="shell-schema-kicker">
|
| 896 |
Semantic measures Β· {state.schema.measures.length}
|
| 897 |
</div>
|
| 898 |
+
<div className="shell-schema-card">
|
| 899 |
+
<div className="shell-schema-measures">
|
| 900 |
+
{state.schema.measures.map((m) => (
|
| 901 |
+
<div key={m.key} className="shell-schema-measure">
|
| 902 |
+
<span className="shell-schema-fname">{m.label}</span>
|
| 903 |
+
<span className="shell-schema-type">{m.type}</span>
|
| 904 |
+
</div>
|
| 905 |
+
))}
|
| 906 |
+
</div>
|
| 907 |
</div>
|
| 908 |
</>
|
| 909 |
)}
|
web/src/styles/wave46/chrome.css
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Wave 46 grid chrome. Owner instructions 2 and 30, one ticket (W46-T09):
|
| 2 |
+
reading left to right the top-right run is Related, then Notes, then Full screen.
|
| 3 |
+
|
| 4 |
+
WHY A SHEET AND NOT A DOM MOVE. The run's order has been CSS since Wave 44
|
| 5 |
+
(`styles/wave44/data-workspace.css`), which assigns `order:` off ADJACENCY chains hanging
|
| 6 |
+
from `.cg-tb-related`. Any sibling inserted into that run silently changes which of those
|
| 7 |
+
chains match, in ways no diff shows. So this sheet stops relying on them: it reassigns ALL
|
| 8 |
+
FIVE controls of the run explicitly, and the Notes button is placed in the DOM immediately
|
| 9 |
+
before Full screen so that focus order and painted order agree about that pair (`order:`
|
| 10 |
+
moves pixels, never focus).
|
| 11 |
+
|
| 12 |
+
WHICH WAVE 44 CHAINS CHANGED STATE. Inserting Notes between Edit and Full screen breaks
|
| 13 |
+
`.cg-tb-related + .cg-view-actions + .cg-fullscreen-toggle` (Full screen, was 18) and, with
|
| 14 |
+
it, the four-step chain ending `+ .cg-pop-wrap` (Rows, was 19). Both would otherwise fall to
|
| 15 |
+
the catch-all 21 and land past Related. Both are reassigned below, so nothing rests on a
|
| 16 |
+
chain that a future sibling could break again.
|
| 17 |
+
|
| 18 |
+
WHY EVERY RULE IS SCOPED BY `:has(> .cg-notes-toggle)`. There are two `<Toolbar>` renders.
|
| 19 |
+
The pivot one supplies neither Edit nor Full screen nor Notes, and its Wave 44 order is
|
| 20 |
+
Rows then Related. Unscoped rules would reorder that toolbar too, for a Notes button that
|
| 21 |
+
is not there. The `:has()` scope makes the Notes-less strip provably untouched.
|
| 22 |
+
|
| 23 |
+
β THE INTEGERS ARE NOT FREE. `.cg-toolbar > .cg-tb-related ~ *` pins search, the lock mark,
|
| 24 |
+
the spacer and the count at 21, and everything left of Related sits at the initial 0. Five
|
| 25 |
+
controls therefore have to fit in 16..20, which is why the whole run shifts down rather
|
| 26 |
+
than Notes being slotted in beside its neighbours.
|
| 27 |
+
|
| 28 |
+
Loaded from `CustomerGrid.tsx` AFTER the Wave 44 and Wave 45 sheets, so a tie on specificity
|
| 29 |
+
resolves here. Every selector below still meets or beats the Wave 44 rule it overrides, so
|
| 30 |
+
the result does not depend on import order alone. No `!important`, no literal sizes, no hex.
|
| 31 |
+
|
| 32 |
+
Effective order, left to right: Edit 16, Rows 17, Related 18, Notes 19, Full screen 20. */
|
| 33 |
+
|
| 34 |
+
/* Edit β (0,4,0), over Wave 44's `.cg-toolbar > .cg-tb-related + .cg-view-actions` (0,3,0). */
|
| 35 |
+
.cg-toolbar:has(> .cg-notes-toggle) > .cg-tb-btn.cg-view-actions {
|
| 36 |
+
order: 16;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
/* Rows β (0,6,0), which also beats Wave 44's five-class chain for this popover on the merits
|
| 40 |
+
rather than only on import order. That chain no longer matches anyway: Notes now sits inside
|
| 41 |
+
it. Rows is the only `.cg-pop-wrap` after Full screen in this strip. */
|
| 42 |
+
.cg-toolbar:has(> .cg-notes-toggle) > .cg-tb-related ~ .cg-tb-btn.cg-fullscreen-toggle ~ .cg-pop-wrap {
|
| 43 |
+
order: 17;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
/* Related β (0,3,0), over Wave 44's bare `.cg-tb-related` (0,1,0). */
|
| 47 |
+
.cg-toolbar:has(> .cg-notes-toggle) > .cg-tb-related {
|
| 48 |
+
order: 18;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
/* Notes β (0,3,0), over the catch-all `.cg-toolbar > .cg-tb-related ~ *` (0,2,0). It carries
|
| 52 |
+
`.cg-tb-btn`, so its height, padding, font size, hover and active tone are the strip's own;
|
| 53 |
+
nothing about the control's shape is declared here, only where it reads. */
|
| 54 |
+
.cg-toolbar:has(> .cg-notes-toggle) > .cg-notes-toggle {
|
| 55 |
+
order: 19;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
/* Full screen β (0,5,0), which beats Wave 44's
|
| 59 |
+
`.cg-toolbar > .cg-tb-related + .cg-view-actions + .cg-fullscreen-toggle` (0,4,0) whether or
|
| 60 |
+
not that rule still matches (it does not, now that Notes sits inside its chain). This is the
|
| 61 |
+
whole of owner instruction 2: the control keeps the `cg-fullscreen-toggle` class that is its
|
| 62 |
+
ordering hook, and only the number it is ordered by moves. */
|
| 63 |
+
.cg-toolbar:has(> .cg-notes-toggle) > .cg-tb-related ~ .cg-tb-btn.cg-fullscreen-toggle {
|
| 64 |
+
order: 20;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
/* The launcher row that Notes came from still houses History on a user table. With Notes gone
|
| 68 |
+
it renders with no children anywhere else, and an empty absolutely positioned flex row over
|
| 69 |
+
the grid is a hit target for nothing. `:empty` is (0,2,0) over the Wave 45 declaration. */
|
| 70 |
+
.cg-drawer-launchers:empty {
|
| 71 |
+
display: none;
|
| 72 |
+
}
|
web/src/styles/wave46/field-panels.css
ADDED
|
@@ -0,0 +1,439 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* ---------------------------------------------------------------------------
|
| 2 |
+
wave46 / field-panels.css β contract C6, W46-T31.
|
| 3 |
+
|
| 4 |
+
The lane's own sheet for the two FIELD surfaces: the Hide-fields row's trailing
|
| 5 |
+
actions menu (owner instruction 21) and the add-field type list's info mark
|
| 6 |
+
(owner instruction 27).
|
| 7 |
+
|
| 8 |
+
β IMPORTED FROM THE COMPONENTS, NEVER FROM index.css. `FieldsHidePanel.tsx` and
|
| 9 |
+
`ColumnMenu.tsx` each `import "../styles/wave46/field-panels.css"`, so the bundler
|
| 10 |
+
emits it AFTER index.css and these rules win their equal-specificity fights. An
|
| 11 |
+
`@import` at the top of index.css would have been inlined at the top of the cascade
|
| 12 |
+
and lost every one of them, silently.
|
| 13 |
+
[[a-lane-stylesheet-cannot-override-index-css]]
|
| 14 |
+
|
| 15 |
+
β TOKENS ONLY. No literal `font-size` (verify_ui.py's R5 sweeps every *.css under
|
| 16 |
+
src/ and reds on one), no inline hex, no shadow that is not on an overlay.
|
| 17 |
+
--------------------------------------------------------------------------- */
|
| 18 |
+
|
| 19 |
+
/* ---- the row's trailing actions slot ------------------------------------------------
|
| 20 |
+
β `margin-left: auto` IS THE TRAILING SLOT, and it moved here with the control. It
|
| 21 |
+
used to live on `.cg-check-del`, the button this menu replaced; without it the trigger
|
| 22 |
+
would sit tight against the last badge instead of at the row's end. On a row that also
|
| 23 |
+
offers Remove from my fields, that button keeps its own auto margin and takes the gap,
|
| 24 |
+
and this control follows it β which is the order the two belong in. */
|
| 25 |
+
.w46-field-actions {
|
| 26 |
+
position: relative;
|
| 27 |
+
flex: 0 0 auto;
|
| 28 |
+
display: inline-flex;
|
| 29 |
+
align-items: center;
|
| 30 |
+
margin-left: auto;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
/* The trigger is `.cg-field-edit-trigger` still, so it keeps the 18px box, the radius and
|
| 34 |
+
the hover-reveal the manager list already gives it. What this adds is the OPEN state:
|
| 35 |
+
a menu hanging off an invisible button reads as a bug, so an open row keeps its trigger
|
| 36 |
+
painted whether or not the pointer is still on the row.
|
| 37 |
+
β The four native-chrome resets are stated here in full rather than inherited, because
|
| 38 |
+
this class is also mounted OUTSIDE `.cg-fields-manager` (the grid's own Fields panel),
|
| 39 |
+
where none of wave 41's manager-scoped rules apply at all. */
|
| 40 |
+
.w46-field-actions-trigger {
|
| 41 |
+
display: inline-flex;
|
| 42 |
+
align-items: center;
|
| 43 |
+
justify-content: center;
|
| 44 |
+
width: 18px;
|
| 45 |
+
height: 18px;
|
| 46 |
+
padding: 0;
|
| 47 |
+
border: 0;
|
| 48 |
+
border-radius: var(--lp-r-sm);
|
| 49 |
+
background: transparent;
|
| 50 |
+
font: inherit;
|
| 51 |
+
color: inherit;
|
| 52 |
+
cursor: pointer;
|
| 53 |
+
}
|
| 54 |
+
.cg-fields-manager .w46-field-actions.is-open .w46-field-actions-trigger,
|
| 55 |
+
.w46-field-actions.is-open .w46-field-actions-trigger {
|
| 56 |
+
opacity: 1;
|
| 57 |
+
color: var(--lp-blue-deep);
|
| 58 |
+
}
|
| 59 |
+
.w46-field-actions-trigger:focus-visible {
|
| 60 |
+
outline: 2px solid var(--lp-primary);
|
| 61 |
+
outline-offset: 2px;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
/* ---- the menu itself ----------------------------------------------------------------
|
| 65 |
+
β VIEWPORT-POSITIONED, ON PURPOSE. `.cg-pop-list` is a 320px `overflow-y: auto` box, so
|
| 66 |
+
an absolutely positioned menu on one of the last rows would be clipped by its own
|
| 67 |
+
parent. `position: fixed` escapes that clip (no ancestor here establishes a containing
|
| 68 |
+
block: `.cg-pop` carries no transform, filter or containment), and the component closes
|
| 69 |
+
the menu on any scroll so a detached menu can never point at the wrong row.
|
| 70 |
+
β The `top`/`left` arrive as inline geometry from the trigger's measured rect. They are
|
| 71 |
+
the only inline style on this control; every colour, size and radius is below. */
|
| 72 |
+
.w46-field-menu {
|
| 73 |
+
position: fixed;
|
| 74 |
+
z-index: var(--cg-z-menu);
|
| 75 |
+
display: flex;
|
| 76 |
+
flex-direction: column;
|
| 77 |
+
gap: 2px;
|
| 78 |
+
width: 168px;
|
| 79 |
+
padding: 4px;
|
| 80 |
+
border: 1px solid var(--lp-line);
|
| 81 |
+
border-radius: var(--lp-r-md);
|
| 82 |
+
background: var(--lp-surface);
|
| 83 |
+
/* A tinted shadow, and only because this IS an overlay (DESIGN: hairlines elsewhere). */
|
| 84 |
+
box-shadow: 0 6px 18px color-mix(in srgb, var(--lp-blue-deep) 16%, transparent);
|
| 85 |
+
animation: w46-field-menu-in 140ms ease-out;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
/* Opacity and transform only: nothing here reflows the row underneath it. */
|
| 89 |
+
@keyframes w46-field-menu-in {
|
| 90 |
+
from { opacity: 0; transform: translateY(-2px); }
|
| 91 |
+
to { opacity: 1; transform: translateY(0); }
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
@media (prefers-reduced-motion: reduce) {
|
| 95 |
+
.w46-field-menu { animation: none; }
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
/* A menu item is a short label, not a sentence: the impact wording stays in `title`,
|
| 99 |
+
where W41-T29 put it, and the row's width budget is unaffected either way. */
|
| 100 |
+
.w46-field-menu-item {
|
| 101 |
+
display: flex;
|
| 102 |
+
align-items: center;
|
| 103 |
+
width: 100%;
|
| 104 |
+
padding: 6px 8px;
|
| 105 |
+
border: 0;
|
| 106 |
+
border-radius: var(--lp-r-sm);
|
| 107 |
+
background: transparent;
|
| 108 |
+
font: inherit;
|
| 109 |
+
color: inherit;
|
| 110 |
+
font-size: var(--lp-fs-xs);
|
| 111 |
+
text-align: left;
|
| 112 |
+
cursor: pointer;
|
| 113 |
+
}
|
| 114 |
+
.w46-field-menu-item:hover {
|
| 115 |
+
background: var(--lp-blue-tint);
|
| 116 |
+
color: var(--lp-blue-deep);
|
| 117 |
+
}
|
| 118 |
+
.w46-field-menu-item:focus-visible {
|
| 119 |
+
outline: 2px solid var(--lp-primary);
|
| 120 |
+
outline-offset: 2px;
|
| 121 |
+
}
|
| 122 |
+
/* β THE DESTRUCTIVE ITEM READS AS ONE, and it is the whole reason the two acts stopped
|
| 123 |
+
being neighbours: a delete that looks like an edit is a delete you reach by accident. */
|
| 124 |
+
.w46-field-menu-item--danger {
|
| 125 |
+
color: var(--lp-red-deep);
|
| 126 |
+
}
|
| 127 |
+
.w46-field-menu-item--danger:hover {
|
| 128 |
+
background: var(--lp-red-tint);
|
| 129 |
+
color: var(--lp-red-deep);
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
/* ---- the add-field type list's info mark (owner instruction 27) ----------------------
|
| 133 |
+
The glyph was the literal characters `(i)`, which a text baseline positioned; an SVG
|
| 134 |
+
needs the box centred instead. Everything else about the button (its 32px hit area, its
|
| 135 |
+
colours, its focus ring) stays exactly where wave 41 put it.
|
| 136 |
+
|
| 137 |
+
β COLOUR IS DELIBERATELY ABSENT HERE. field-ui.css already states the resting tone and
|
| 138 |
+
the hover / focus / expanded tones; restating the base one in a sheet that loads later
|
| 139 |
+
would win the resting fight and leave the three state rules to fight back at higher
|
| 140 |
+
specificity, which is how a mark ends up muted when it is meant to be lit. */
|
| 141 |
+
.cg-type-info {
|
| 142 |
+
display: inline-flex;
|
| 143 |
+
align-items: center;
|
| 144 |
+
justify-content: center;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
/* ---- the date cell: a plain date first, a repeat editor second (owner instruction 13) ----
|
| 148 |
+
W46-T32. The picker used to render the anchor block, the "Only when" conditions and every
|
| 149 |
+
rule row at all times, with the plain-vs-repeating distinction implied only by
|
| 150 |
+
`rules.length` and the way in marked by a quiet text link. Now the default state is a
|
| 151 |
+
calendar plus ONE footer affordance, and the editor is a second step in the SAME overlay
|
| 152 |
+
laid out one setting per labelled row, after reference/Google Calendar 1.png.
|
| 153 |
+
|
| 154 |
+
The editor is wider than the bare calendar, so the width pinned at index.css's
|
| 155 |
+
`.cg-date-picker` is restated here at higher specificity. This sheet is imported from the
|
| 156 |
+
component, so it is emitted AFTER index.css and wins.
|
| 157 |
+
[[a-lane-stylesheet-cannot-override-index-css]] */
|
| 158 |
+
.cg-pop.cg-date-picker {
|
| 159 |
+
width: min(360px, calc(100vw - 24px));
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
/* ---- step 1: the footer that carries the whole way in --------------------------------
|
| 163 |
+
The owner's complaint was that the way in was hard to see. It is a filled control on its
|
| 164 |
+
own strip now, not a text link sharing a row with rule editors. */
|
| 165 |
+
.w46-date-footer {
|
| 166 |
+
display: flex;
|
| 167 |
+
align-items: center;
|
| 168 |
+
gap: 8px;
|
| 169 |
+
margin-top: 10px;
|
| 170 |
+
padding-top: 8px;
|
| 171 |
+
border-top: 1px solid var(--lp-line);
|
| 172 |
+
}
|
| 173 |
+
.w46-date-summary {
|
| 174 |
+
flex: 1;
|
| 175 |
+
min-width: 0;
|
| 176 |
+
color: var(--lp-muted);
|
| 177 |
+
font-size: var(--lp-fs-3xs);
|
| 178 |
+
line-height: var(--lp-lh-tight);
|
| 179 |
+
}
|
| 180 |
+
.w46-date-repeat {
|
| 181 |
+
border: 0;
|
| 182 |
+
background: var(--lp-primary);
|
| 183 |
+
font: inherit;
|
| 184 |
+
color: var(--lp-surface);
|
| 185 |
+
padding: 6px 14px;
|
| 186 |
+
border-radius: var(--lp-r-pill);
|
| 187 |
+
font-size: var(--lp-fs-2xs);
|
| 188 |
+
cursor: pointer;
|
| 189 |
+
transition: background 140ms ease-out;
|
| 190 |
+
}
|
| 191 |
+
.w46-date-repeat:hover {
|
| 192 |
+
background: var(--lp-primary-hover);
|
| 193 |
+
}
|
| 194 |
+
.w46-date-repeat.is-set {
|
| 195 |
+
background: var(--lp-primary-tint);
|
| 196 |
+
color: var(--lp-blue-deep);
|
| 197 |
+
flex: 0 0 auto;
|
| 198 |
+
}
|
| 199 |
+
.w46-date-repeat.is-set:hover {
|
| 200 |
+
background: var(--lp-blue-tint);
|
| 201 |
+
}
|
| 202 |
+
.w46-date-repeat:focus-visible {
|
| 203 |
+
outline: 2px solid var(--lp-primary);
|
| 204 |
+
outline-offset: 2px;
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
/* ---- step 2: one setting per labelled row ------------------------------------------- */
|
| 208 |
+
.w46-recur {
|
| 209 |
+
display: flex;
|
| 210 |
+
flex-direction: column;
|
| 211 |
+
gap: 12px;
|
| 212 |
+
animation: w46-recur-in 140ms ease-out;
|
| 213 |
+
}
|
| 214 |
+
@keyframes w46-recur-in {
|
| 215 |
+
from { opacity: 0; transform: translateY(4px); }
|
| 216 |
+
to { opacity: 1; transform: translateY(0); }
|
| 217 |
+
}
|
| 218 |
+
@media (prefers-reduced-motion: reduce) {
|
| 219 |
+
.w46-recur { animation: none; }
|
| 220 |
+
.w46-date-repeat { transition: none; }
|
| 221 |
+
}
|
| 222 |
+
.w46-recur-head {
|
| 223 |
+
display: flex;
|
| 224 |
+
align-items: center;
|
| 225 |
+
gap: 6px;
|
| 226 |
+
}
|
| 227 |
+
.w46-recur-back {
|
| 228 |
+
border: 0;
|
| 229 |
+
background: transparent;
|
| 230 |
+
font: inherit;
|
| 231 |
+
color: inherit;
|
| 232 |
+
width: 24px;
|
| 233 |
+
height: 24px;
|
| 234 |
+
border-radius: var(--lp-r-sm);
|
| 235 |
+
font-size: var(--lp-fs-lg);
|
| 236 |
+
line-height: 1;
|
| 237 |
+
cursor: pointer;
|
| 238 |
+
}
|
| 239 |
+
.w46-recur-back:hover {
|
| 240 |
+
background: var(--lp-surface-2);
|
| 241 |
+
}
|
| 242 |
+
.w46-recur-back:focus-visible {
|
| 243 |
+
outline: 2px solid var(--lp-primary);
|
| 244 |
+
outline-offset: 2px;
|
| 245 |
+
}
|
| 246 |
+
.w46-recur-card {
|
| 247 |
+
display: flex;
|
| 248 |
+
flex-direction: column;
|
| 249 |
+
gap: 10px;
|
| 250 |
+
padding: 10px;
|
| 251 |
+
border: 1px solid var(--lp-line);
|
| 252 |
+
border-radius: var(--lp-r-md);
|
| 253 |
+
background: var(--lp-surface-2);
|
| 254 |
+
}
|
| 255 |
+
.w46-recur-row {
|
| 256 |
+
display: flex;
|
| 257 |
+
flex-direction: column;
|
| 258 |
+
gap: 6px;
|
| 259 |
+
}
|
| 260 |
+
.w46-recur-label {
|
| 261 |
+
color: var(--lp-muted);
|
| 262 |
+
font-size: var(--lp-fs-3xs);
|
| 263 |
+
line-height: var(--lp-lh-tight);
|
| 264 |
+
}
|
| 265 |
+
.w46-recur-controls {
|
| 266 |
+
display: flex;
|
| 267 |
+
align-items: center;
|
| 268 |
+
gap: 8px;
|
| 269 |
+
flex-wrap: wrap;
|
| 270 |
+
}
|
| 271 |
+
.w46-recur-word {
|
| 272 |
+
color: var(--lp-muted);
|
| 273 |
+
font-size: var(--lp-fs-2xs);
|
| 274 |
+
}
|
| 275 |
+
.w46-recur-count {
|
| 276 |
+
width: 64px;
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
/* ---- the seven day pills, filled when selected --------------------------------------- */
|
| 280 |
+
.w46-recur-pills {
|
| 281 |
+
display: flex;
|
| 282 |
+
gap: 6px;
|
| 283 |
+
flex-wrap: wrap;
|
| 284 |
+
}
|
| 285 |
+
.w46-recur-pill {
|
| 286 |
+
border: 0;
|
| 287 |
+
background: var(--lp-wash);
|
| 288 |
+
font: inherit;
|
| 289 |
+
color: var(--lp-ink);
|
| 290 |
+
width: 28px;
|
| 291 |
+
height: 28px;
|
| 292 |
+
border-radius: var(--lp-r-pill);
|
| 293 |
+
font-size: var(--lp-fs-3xs);
|
| 294 |
+
cursor: pointer;
|
| 295 |
+
transition: background 140ms ease-out;
|
| 296 |
+
}
|
| 297 |
+
.w46-recur-pill:hover {
|
| 298 |
+
background: var(--lp-blue-tint);
|
| 299 |
+
}
|
| 300 |
+
.w46-recur-pill.is-on {
|
| 301 |
+
background: var(--lp-primary);
|
| 302 |
+
color: var(--lp-surface);
|
| 303 |
+
}
|
| 304 |
+
.w46-recur-pill:focus-visible {
|
| 305 |
+
outline: 2px solid var(--lp-primary);
|
| 306 |
+
outline-offset: 2px;
|
| 307 |
+
}
|
| 308 |
+
@media (prefers-reduced-motion: reduce) {
|
| 309 |
+
.w46-recur-pill { transition: none; }
|
| 310 |
+
}
|
| 311 |
+
|
| 312 |
+
/* ---- ends: a radio per line, its field beside it ------------------------------------- */
|
| 313 |
+
.w46-recur-ends {
|
| 314 |
+
display: flex;
|
| 315 |
+
flex-direction: column;
|
| 316 |
+
gap: 8px;
|
| 317 |
+
}
|
| 318 |
+
.w46-recur-radio {
|
| 319 |
+
display: flex;
|
| 320 |
+
align-items: center;
|
| 321 |
+
gap: 8px;
|
| 322 |
+
font-size: var(--lp-fs-2xs);
|
| 323 |
+
cursor: pointer;
|
| 324 |
+
}
|
| 325 |
+
.w46-recur-radio input[type="radio"] {
|
| 326 |
+
accent-color: var(--lp-primary);
|
| 327 |
+
}
|
| 328 |
+
.w46-recur-radio input[type="radio"]:focus-visible {
|
| 329 |
+
outline: 2px solid var(--lp-primary);
|
| 330 |
+
outline-offset: 2px;
|
| 331 |
+
}
|
| 332 |
+
.w46-recur-radio span {
|
| 333 |
+
min-width: 44px;
|
| 334 |
+
}
|
| 335 |
+
.w46-recur-date {
|
| 336 |
+
flex: 1;
|
| 337 |
+
min-width: 0;
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
/* ---- more options: the power controls leave the default path, they do not leave ------- */
|
| 341 |
+
.w46-recur-more > summary {
|
| 342 |
+
list-style: none;
|
| 343 |
+
cursor: pointer;
|
| 344 |
+
color: var(--lp-blue-deep);
|
| 345 |
+
font-size: var(--lp-fs-2xs);
|
| 346 |
+
padding: 4px 0;
|
| 347 |
+
}
|
| 348 |
+
.w46-recur-more > summary::-webkit-details-marker {
|
| 349 |
+
display: none;
|
| 350 |
+
}
|
| 351 |
+
.w46-recur-more > summary:focus-visible {
|
| 352 |
+
outline: 2px solid var(--lp-primary);
|
| 353 |
+
outline-offset: 2px;
|
| 354 |
+
}
|
| 355 |
+
.w46-recur-more[open] > summary {
|
| 356 |
+
margin-bottom: 8px;
|
| 357 |
+
}
|
| 358 |
+
.w46-recur-preview-count {
|
| 359 |
+
display: block;
|
| 360 |
+
margin-top: 8px;
|
| 361 |
+
color: var(--lp-muted);
|
| 362 |
+
font-size: var(--lp-fs-3xs);
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
/* ---- the two secondary controls and the footer pair ---------------------------------- */
|
| 366 |
+
.w46-recur-add {
|
| 367 |
+
border: 0;
|
| 368 |
+
background: transparent;
|
| 369 |
+
font: inherit;
|
| 370 |
+
color: var(--lp-blue-deep);
|
| 371 |
+
align-self: flex-start;
|
| 372 |
+
padding: 4px 10px;
|
| 373 |
+
border-radius: var(--lp-r-pill);
|
| 374 |
+
border: 1px solid var(--lp-line);
|
| 375 |
+
font-size: var(--lp-fs-2xs);
|
| 376 |
+
cursor: pointer;
|
| 377 |
+
}
|
| 378 |
+
.w46-recur-add:hover {
|
| 379 |
+
background: var(--lp-blue-tint);
|
| 380 |
+
}
|
| 381 |
+
.w46-recur-add:focus-visible {
|
| 382 |
+
outline: 2px solid var(--lp-primary);
|
| 383 |
+
outline-offset: 2px;
|
| 384 |
+
}
|
| 385 |
+
.w46-recur-card-foot {
|
| 386 |
+
display: flex;
|
| 387 |
+
justify-content: flex-end;
|
| 388 |
+
}
|
| 389 |
+
.w46-recur-foot {
|
| 390 |
+
display: flex;
|
| 391 |
+
align-items: center;
|
| 392 |
+
justify-content: flex-end;
|
| 393 |
+
gap: 8px;
|
| 394 |
+
padding-top: 8px;
|
| 395 |
+
border-top: 1px solid var(--lp-line);
|
| 396 |
+
}
|
| 397 |
+
.w46-recur-quiet {
|
| 398 |
+
border: 0;
|
| 399 |
+
background: transparent;
|
| 400 |
+
font: inherit;
|
| 401 |
+
color: var(--lp-muted);
|
| 402 |
+
padding: 6px 8px;
|
| 403 |
+
border-radius: var(--lp-r-sm);
|
| 404 |
+
font-size: var(--lp-fs-2xs);
|
| 405 |
+
cursor: pointer;
|
| 406 |
+
}
|
| 407 |
+
.w46-recur-quiet:hover {
|
| 408 |
+
color: var(--lp-ink);
|
| 409 |
+
background: var(--lp-surface-2);
|
| 410 |
+
}
|
| 411 |
+
.w46-recur-quiet.is-danger {
|
| 412 |
+
color: var(--lp-red-deep);
|
| 413 |
+
margin-right: auto;
|
| 414 |
+
}
|
| 415 |
+
.w46-recur-quiet.is-danger:hover {
|
| 416 |
+
background: var(--lp-red-tint);
|
| 417 |
+
color: var(--lp-red-deep);
|
| 418 |
+
}
|
| 419 |
+
.w46-recur-quiet:focus-visible {
|
| 420 |
+
outline: 2px solid var(--lp-primary);
|
| 421 |
+
outline-offset: 2px;
|
| 422 |
+
}
|
| 423 |
+
.w46-recur-save {
|
| 424 |
+
border: 0;
|
| 425 |
+
background: var(--lp-primary);
|
| 426 |
+
font: inherit;
|
| 427 |
+
color: var(--lp-surface);
|
| 428 |
+
padding: 6px 16px;
|
| 429 |
+
border-radius: var(--lp-r-pill);
|
| 430 |
+
font-size: var(--lp-fs-2xs);
|
| 431 |
+
cursor: pointer;
|
| 432 |
+
}
|
| 433 |
+
.w46-recur-save:hover {
|
| 434 |
+
background: var(--lp-primary-hover);
|
| 435 |
+
}
|
| 436 |
+
.w46-recur-save:focus-visible {
|
| 437 |
+
outline: 2px solid var(--lp-primary);
|
| 438 |
+
outline-offset: 2px;
|
| 439 |
+
}
|
web/src/styles/wave46/manage-database.css
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* styles/wave46/manage-database.css β WAVE 46 (owner instruction 31, R12, contracts C1 + C6).
|
| 2 |
+
|
| 3 |
+
β IMPORTED FROM `settings/ManageDatabase.tsx`, NEVER FROM `index.css`. The root sheet
|
| 4 |
+
`@import`s the older lane sheets at its top, so anything arriving that way loses every
|
| 5 |
+
equal-specificity fight with the rules beneath it; a sheet imported from a component lands
|
| 6 |
+
after `index.css` in the bundle and wins. `AssistantPage.tsx` does the same with wave 45's.
|
| 7 |
+
|
| 8 |
+
β ONLY GENUINELY NEW STRUCTURE LIVES HERE. The database list wears Manage User's `.set-acct*`
|
| 9 |
+
classes and the way out wears `.set-perm-back`, because W46-T39 reads computed type and colour
|
| 10 |
+
off both panes and requires them to match: being the same rule is cheaper than being a copy of
|
| 11 |
+
it, and it cannot drift. What is left is one thing this product has never drawn, the per field
|
| 12 |
+
row, plus its two quiet reorder buttons.
|
| 13 |
+
|
| 14 |
+
Tokens only: no literal font-size, no inline hex, hairlines not shadows, the 4/8 spacing grid,
|
| 15 |
+
and two radii at most (`--lp-r-sm`, `--lp-r-md`). */
|
| 16 |
+
|
| 17 |
+
.w46-db-fields {
|
| 18 |
+
list-style: none;
|
| 19 |
+
margin: 4px 0 0;
|
| 20 |
+
padding: 0;
|
| 21 |
+
display: grid;
|
| 22 |
+
gap: 8px;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
/* ONE CONTAINMENT LAYER. The row is the only bordered box on this page: the pane itself is
|
| 26 |
+
unframed, so a row inside a card inside the pane would be the card in card the design
|
| 27 |
+
constitution forbids. */
|
| 28 |
+
.w46-db-field {
|
| 29 |
+
display: grid;
|
| 30 |
+
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
|
| 31 |
+
align-items: end;
|
| 32 |
+
gap: 8px;
|
| 33 |
+
padding: 8px 12px;
|
| 34 |
+
border: 1px solid var(--lp-line);
|
| 35 |
+
border-radius: var(--lp-r-md);
|
| 36 |
+
background: var(--lp-surface);
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
.w46-db-idline {
|
| 40 |
+
display: flex;
|
| 41 |
+
flex-wrap: wrap;
|
| 42 |
+
align-items: center;
|
| 43 |
+
gap: 8px;
|
| 44 |
+
min-width: 0;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
/* The field's WIRE KEY, which is the thing an admin matches against a report or a formula, so it
|
| 48 |
+
is set in the monospace stack rather than in prose type. */
|
| 49 |
+
.w46-db-key {
|
| 50 |
+
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
| 51 |
+
font-size: var(--lp-fs-2xs);
|
| 52 |
+
color: var(--lp-ink);
|
| 53 |
+
overflow-wrap: anywhere;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
/* Type and source, stated together and quietly: they are what the field IS, not what you do to
|
| 57 |
+
it, and R12 puts both beyond this version's three verbs. */
|
| 58 |
+
.w46-db-meta {
|
| 59 |
+
font-size: var(--lp-fs-3xs);
|
| 60 |
+
color: var(--lp-muted);
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
.w46-db-relabel {
|
| 64 |
+
display: block;
|
| 65 |
+
min-width: 0;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
.w46-db-acts {
|
| 69 |
+
display: flex;
|
| 70 |
+
align-items: center;
|
| 71 |
+
gap: 8px;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
/* Quiet the way `.shell-newfolder` is quiet: every native button property reset in the base rule,
|
| 75 |
+
muted ink, a wash on hover, no border and no shadow. */
|
| 76 |
+
.w46-db-move {
|
| 77 |
+
border: 0;
|
| 78 |
+
background: transparent;
|
| 79 |
+
font: inherit;
|
| 80 |
+
color: inherit;
|
| 81 |
+
font-size: var(--lp-fs-2xs);
|
| 82 |
+
color: var(--lp-muted);
|
| 83 |
+
padding: 4px 8px;
|
| 84 |
+
border-radius: var(--lp-r-sm);
|
| 85 |
+
cursor: pointer;
|
| 86 |
+
transition: background 120ms ease-out, color 120ms ease-out;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
.w46-db-move:hover:enabled {
|
| 90 |
+
background: var(--lp-wash);
|
| 91 |
+
color: var(--lp-ink);
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
.w46-db-move:focus-visible {
|
| 95 |
+
outline: 2px solid var(--lp-blue-deep);
|
| 96 |
+
outline-offset: 1px;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
.w46-db-move:disabled {
|
| 100 |
+
opacity: 0.45;
|
| 101 |
+
cursor: default;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
/* One column under a narrow modal body: three columns of controls at this width would wrap
|
| 105 |
+
mid control, which reads as a broken row rather than as a stacked one. */
|
| 106 |
+
@media (max-width: 720px) {
|
| 107 |
+
.w46-db-field {
|
| 108 |
+
grid-template-columns: minmax(0, 1fr);
|
| 109 |
+
align-items: stretch;
|
| 110 |
+
}
|
| 111 |
+
}
|
web/src/styles/wave46/map-panels.css
ADDED
|
@@ -0,0 +1,475 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Wave 46 β map panel chrome (W46-T17: the Zone drawing arming button).
|
| 2 |
+
|
| 3 |
+
β THIS SHEET IS IMPORTED FROM `customer-grid/MapView.tsx`, NOT FROM index.css, AND THAT IS
|
| 4 |
+
LOAD-BEARING. index.css @imports the wave-41/42 sheets at its TOP, so an @imported rule loses
|
| 5 |
+
every equal-specificity fight with the thousands of rules below it. A sheet imported from a
|
| 6 |
+
component lands AFTER index.css in the bundle and therefore wins its ties, which is the only
|
| 7 |
+
way `.cg-zone-draw-btn` can restate anything `.cg-link-btn` already sets.
|
| 8 |
+
|
| 9 |
+
Tokens only: no literal font sizes, no inline hex. */
|
| 10 |
+
|
| 11 |
+
/* The arming button. It was a bare word with no icon and no state, so it read as a sentence
|
| 12 |
+
fragment rather than a control, and nothing on screen said whether drawing was on.
|
| 13 |
+
Same 28px row and same radius as every other quiet control in the panel; the icon sits inside
|
| 14 |
+
the label rather than beside it so the pair moves as one target. */
|
| 15 |
+
.cg-zone-draw-btn {
|
| 16 |
+
display: inline-flex;
|
| 17 |
+
align-items: center;
|
| 18 |
+
justify-content: center;
|
| 19 |
+
gap: 6px;
|
| 20 |
+
flex: 0 0 auto;
|
| 21 |
+
padding: 0 10px;
|
| 22 |
+
border-color: var(--lp-line);
|
| 23 |
+
background: var(--lp-surface);
|
| 24 |
+
color: var(--lp-ink);
|
| 25 |
+
font: inherit;
|
| 26 |
+
font-size: var(--lp-fs-xs);
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
/* ARMED is a real state, not a label change: the map is a drawing surface for as long as this
|
| 30 |
+
is lit, and the user needs to know that before wondering why a click stopped opening records. */
|
| 31 |
+
.cg-zone-draw-btn.is-armed {
|
| 32 |
+
border-color: var(--lp-primary);
|
| 33 |
+
background: var(--lp-blue-tint);
|
| 34 |
+
/* Text takes `--lp-primary`, not `--lp-blue-deep`: that token is documented at 3.29:1 and is
|
| 35 |
+
for borders and focus rings, so a label wearing it would be under the text floor. */
|
| 36 |
+
color: var(--lp-primary);
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
.cg-zone-draw-btn:hover {
|
| 40 |
+
background: var(--lp-blue-tint);
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.cg-zone-draw-btn:focus-visible {
|
| 44 |
+
outline: 2px solid var(--lp-primary);
|
| 45 |
+
outline-offset: 2px;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
/* The glyph tracks the label's colour through `currentColor`, so the armed state recolours both
|
| 49 |
+
with one rule. `flex: 0 0 auto` keeps it square when the label wraps its container. */
|
| 50 |
+
.cg-zone-draw-ico {
|
| 51 |
+
width: 14px;
|
| 52 |
+
height: 14px;
|
| 53 |
+
flex: 0 0 auto;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
/* The in-progress outline never takes a pointer event: it is drawn LAST in the SVG, on top of
|
| 57 |
+
the pins, so without this it would swallow the very clicks that extend it. */
|
| 58 |
+
.cg-zone-keyboard-draft {
|
| 59 |
+
pointer-events: none;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
/* ββ W46-T26: a route stop is a NAME with a number beside it βββββββββββββββββββββββββββββββ
|
| 63 |
+
The list printed "Stop 1", "Stop 2" β an ordinal is not an identity, and a driver reading the
|
| 64 |
+
panel could not tell one call from the next. The name is now the content and the number is
|
| 65 |
+
furniture, which DESIGN.md Β§2 makes a weight decision rather than a size one: the ordinal drops
|
| 66 |
+
to the micro-label scale and the muted ink, the name keeps the button's own link colour.
|
| 67 |
+
|
| 68 |
+
β The number lives INSIDE the button, not beside it. `.cg-w44-route-stops li` in map.css is a
|
| 69 |
+
two-column grid (the open button, then the reorder controls); a third child would break the row.
|
| 70 |
+
β No `overflow` or `max-height` on the list itself: the Route aside owns the panel's one
|
| 71 |
+
vertical scroller and a second one inside it is the defect W43C-T09 exists to prevent. */
|
| 72 |
+
.cg-w44-route-stop-open {
|
| 73 |
+
display: flex;
|
| 74 |
+
align-items: baseline;
|
| 75 |
+
gap: 8px;
|
| 76 |
+
width: 100%;
|
| 77 |
+
min-width: 0;
|
| 78 |
+
/* Truncation moves to the name span, so the ordinal can never be the part that is clipped. */
|
| 79 |
+
overflow: visible;
|
| 80 |
+
text-overflow: clip;
|
| 81 |
+
white-space: normal;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
/* `tabular-nums` plus the floor width keeps every name starting on the same x once the route
|
| 85 |
+
passes nine stops, so the column of names reads as a column. */
|
| 86 |
+
.cg-w46-stop-index {
|
| 87 |
+
flex: 0 0 auto;
|
| 88 |
+
min-width: 14px;
|
| 89 |
+
color: var(--lp-muted);
|
| 90 |
+
font-size: var(--lp-fs-3xs);
|
| 91 |
+
font-variant-numeric: tabular-nums;
|
| 92 |
+
text-align: right;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
.cg-w46-stop-name {
|
| 96 |
+
min-width: 0;
|
| 97 |
+
overflow: hidden;
|
| 98 |
+
text-overflow: ellipsis;
|
| 99 |
+
white-space: nowrap;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
/* ββ W46-T28: a Zone you can actually see, and vertices you can grab βββββββββββββββββββββββ
|
| 103 |
+
Owner instruction 16: *"the zone color is not strong enough its too transparent, i can't se
|
| 104 |
+
eshit."* The value is a TOKEN in both seams it has, per DESIGN.md section 5.
|
| 105 |
+
|
| 106 |
+
β THE `index.css :root` SEAM IS DELIBERATELY NOT USED. Contract C6: no lane edits
|
| 107 |
+
`aios-web/web/src/index.css`. The custom property is declared here instead, and its TS twin is
|
| 108 |
+
`LP_ZONE_FILL_OPACITY` in `customer-grid/theme.ts`. Two seams, one number: change both.
|
| 109 |
+
|
| 110 |
+
β AND THE SELECTOR CARRIES A SECOND CLASS ON PURPOSE. The rule being raised is
|
| 111 |
+
`.cg-map-zone { fill-opacity: 0.18 }` in `styles/wave45/data-applications.css`, which
|
| 112 |
+
`CustomerGrid.tsx:114` imports BEFORE it imports MapView at :141 β so today this sheet does
|
| 113 |
+
land later and would win the tie on order alone. That is a fact about one importer, not about
|
| 114 |
+
the rule: a second importer of MapView, or a reordered import line, silently flips it back and
|
| 115 |
+
every gate stays green ([[a-lane-stylesheet-cannot-override-index-css]]). `.cg-map-svg
|
| 116 |
+
.cg-map-zone` wins on SPECIFICITY (0,2,0 against 0,1,0), which no import order can undo. */
|
| 117 |
+
:root {
|
| 118 |
+
--lp-zone-fill: 0.4;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
.cg-map-svg .cg-map-zone {
|
| 122 |
+
fill-opacity: var(--lp-zone-fill);
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
/* A vertex handle. It sits INSIDE the camera transform with the boundary it belongs to, and
|
| 126 |
+
deliberately OUTSIDE `.cg-zone-keyboard-draft`, which is `pointer-events: none` β a dot in
|
| 127 |
+
there could never be grabbed. `cursor: grab` is the whole affordance: nothing else on the map
|
| 128 |
+
says "this one point moves" as against the boundary drag, which moves all of them.
|
| 129 |
+
β `vector-effect: non-scaling-stroke` is NOT used here: `verify_map.py`'s
|
| 130 |
+
`map-css-no-non-scaling-stroke` leg reds on it, and the ring below is pre-divided by the zoom
|
| 131 |
+
in the component the same way every other line on this map is. */
|
| 132 |
+
.cg-map-zone-vertex {
|
| 133 |
+
cursor: grab;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
.cg-map-zone-vertex:active {
|
| 137 |
+
cursor: grabbing;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.cg-map-zone-vertex:focus-visible {
|
| 141 |
+
outline: none;
|
| 142 |
+
stroke: var(--lp-primary);
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
/* The draft controls sit on one row so "Finish shape" and "Stop drawing" read as the pair of
|
| 146 |
+
endings they are, rather than one control and one afterthought. */
|
| 147 |
+
.cg-zone-draw-actions {
|
| 148 |
+
display: flex;
|
| 149 |
+
flex-wrap: wrap;
|
| 150 |
+
gap: 6px;
|
| 151 |
+
align-items: center;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
/* == W46-T29: the map toolbar wears the toolbar's own chrome, and its panels open right ======
|
| 155 |
+
Owner instruction 29: *"The formatting for Routes and zones / Location / No size should be
|
| 156 |
+
extremely similar to Filter/sort/group etc. With the coloring when its on etc. and icons, and
|
| 157 |
+
no outline for the button. ALSO ... the navigation for routes and zones etc should popup on
|
| 158 |
+
the right side of the screen not left as it is now."*
|
| 159 |
+
R8 fixes the reading: Filter/sort/group are the STYLE REFERENCE and do not move; the positional
|
| 160 |
+
change is the panel, which anchors to the right edge of the page.
|
| 161 |
+
|
| 162 |
+
THE REFERENCE IS `.cg-tb-btn` (index.css:1508) AND IT IS COPIED, NOT APPROXIMATED. Three
|
| 163 |
+
declared values carry the whole "no outline for the button" ask:
|
| 164 |
+
border 1px solid transparent (a box that reserves its metrics and paints nothing)
|
| 165 |
+
background transparent (no white fill against the toolbar ground)
|
| 166 |
+
font-size var(--lp-fs-xs) (declared, never inherited: index.css:1508 records why)
|
| 167 |
+
plus height 30px, padding 0 9px, gap 6px, radius var(--lp-r-md), line-height 1.
|
| 168 |
+
|
| 169 |
+
TWO DELIBERATE DEVIATIONS, AND THEY ARE OUTSIDE THE PARITY CLAUSE (border, background,
|
| 170 |
+
font-size). `.cg-tb-btn svg` is a LITERAL `#5a5a66` and `.cg-tb-btn:hover` a literal `#f0f2f5`;
|
| 171 |
+
`verify_icons.semantic_chip_tokens()` reds the build over one literal hex in a new sheet, so
|
| 172 |
+
those two take `var(--lp-muted)` (#6b7280) and `var(--lp-surface-2)` (#f7f7f6). β Do not
|
| 173 |
+
"restore parity" by pasting the hexes back: the gate is the reason, not an oversight.
|
| 174 |
+
|
| 175 |
+
THE ACTIVE HUE IS BLUE, AND IT IS AN EXISTING PAIR RATHER THAN A NEW ONE. `.cg-tb-btn.is-active`
|
| 176 |
+
itself is `var(--lp-blue-tint)` + `var(--lp-ink)`; the route toggle's own hover/open state was
|
| 177 |
+
already blue-tint; `.cg-zone-draw-btn.is-armed` above uses it. Green, yellow and purple are
|
| 178 |
+
RESERVED semantics (filter, sort, group β index.css:1562-1581) and borrowing one here would
|
| 179 |
+
say "this narrows the table", which it does not. */
|
| 180 |
+
|
| 181 |
+
/* Routes and Zones. Replaces index.css:5027's `border: 1px solid var(--lp-line)` and
|
| 182 |
+
`background: #ffffff` β the outline and the fill the owner is pointing at. `.cg-map-settings >`
|
| 183 |
+
takes this to 0,2,0 so it outranks the original on SPECIFICITY, not merely on sheet order. */
|
| 184 |
+
.cg-map-settings > .cg-map-route-toggle,
|
| 185 |
+
.cg-map-settings > .cg-mode-field {
|
| 186 |
+
box-sizing: border-box;
|
| 187 |
+
display: inline-flex;
|
| 188 |
+
align-items: center;
|
| 189 |
+
gap: 6px;
|
| 190 |
+
height: 30px;
|
| 191 |
+
padding: 0 9px;
|
| 192 |
+
border: 1px solid transparent;
|
| 193 |
+
border-radius: var(--lp-r-md);
|
| 194 |
+
background: transparent;
|
| 195 |
+
color: var(--lp-ink);
|
| 196 |
+
font: inherit;
|
| 197 |
+
font-size: var(--lp-fs-xs);
|
| 198 |
+
line-height: 1;
|
| 199 |
+
cursor: pointer;
|
| 200 |
+
white-space: nowrap;
|
| 201 |
+
transition: background 0.12s ease, color 0.12s ease;
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
.cg-map-settings > .cg-map-route-toggle svg,
|
| 205 |
+
.cg-map-settings > .cg-mode-field svg {
|
| 206 |
+
color: var(--lp-muted);
|
| 207 |
+
flex: 0 0 auto;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
/* 0,3,0 and 0,4,0: `.cg-fsel:hover:not(:disabled)` (index.css:754) paints a blue border, which
|
| 211 |
+
against a transparent 1px box would put the outline back on hover alone. */
|
| 212 |
+
.cg-map-settings > .cg-map-route-toggle:hover,
|
| 213 |
+
.cg-map-settings > .cg-mode-field:hover:not(:disabled) {
|
| 214 |
+
border-color: transparent;
|
| 215 |
+
background: var(--lp-surface-2);
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
/* ON. The route toggle owns `is-open`; the two field buttons have NO state class to hang this on
|
| 219 |
+
(`.cg-fsel.is-empty` / `.is-missing` are both unreachable here, because `viewModes.tsx` passes
|
| 220 |
+
`value = field?.key ?? ""` and its own list carries a `""`-key row, so `current` always
|
| 221 |
+
resolves), so the open state is read off `aria-expanded`, which is the same fact `is-open`
|
| 222 |
+
records for the sibling. */
|
| 223 |
+
.cg-map-settings > .cg-map-route-toggle.is-open,
|
| 224 |
+
.cg-map-settings > .cg-mode-field[aria-expanded="true"] {
|
| 225 |
+
border-color: transparent;
|
| 226 |
+
background: var(--lp-blue-tint);
|
| 227 |
+
color: var(--lp-ink);
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
.cg-map-settings > .cg-map-route-toggle.is-open svg,
|
| 231 |
+
.cg-map-settings > .cg-mode-field[aria-expanded="true"] svg {
|
| 232 |
+
color: var(--lp-ink);
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
/* `.cg-select:focus` (index.css:2453) answers focus with a border colour and a 3px glow; the
|
| 236 |
+
reference answers it with an outline on focus-visible only, so the glow is retired here. */
|
| 237 |
+
.cg-map-settings > .cg-mode-field:focus {
|
| 238 |
+
border-color: transparent;
|
| 239 |
+
box-shadow: none;
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
.cg-map-settings > .cg-map-route-toggle:focus-visible,
|
| 243 |
+
.cg-map-settings > .cg-mode-field:focus-visible {
|
| 244 |
+
outline: 2px solid var(--lp-blue-deep);
|
| 245 |
+
outline-offset: 1px;
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
/* ββ The panels open on the RIGHT ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 249 |
+
β WHAT WAS ACTUALLY LEFT, MEASURED BEFORE THE EDIT. Three of the four asides in MapView carry
|
| 250 |
+
`.cg-route-nav-panel`, and `styles/wave45/data-applications.css:15` already gives those
|
| 251 |
+
`inset: 0 0 0 auto` at 0,4,0 β which beats `index.css:5048`'s `.cg-route-popover { left: 12px }`
|
| 252 |
+
at 0,1,0 whatever the sheet order. So the Routes index, the Zone chooser and the Zone editor
|
| 253 |
+
were right-flush already; the one still on the left was the BARE `.cg-route-popover`, the route
|
| 254 |
+
selection notice (MapView.tsx:3398).
|
| 255 |
+
It is restated here anyway, and that is the point: this sheet is imported from `MapView.tsx`
|
| 256 |
+
and therefore lands LAST, so the contract "these panels are right-anchored" is now written
|
| 257 |
+
where it wins its ties, instead of resting on one import line in `CustomerGrid.tsx`
|
| 258 |
+
([[a-lane-stylesheet-cannot-override-index-css]]).
|
| 259 |
+
|
| 260 |
+
β NEITHER FORM CAN CLIP, AT 1024px OR ANYWHERE ELSE, and the reason is arithmetic rather than
|
| 261 |
+
a breakpoint. The bare panel is `width: min(360px, calc(100% - 24px))` against `right: 12px`,
|
| 262 |
+
so its left edge sits at `100% - width - 12px`, which is >= 12px for every container width; the
|
| 263 |
+
nav panels are `min(360px, 100%)` against `right: 0`, so theirs is >= 0. The width is already
|
| 264 |
+
bounded by the container MINUS the offset, which is what makes the offset safe.
|
| 265 |
+
β And `@media (max-width: 1000px)` in `data-applications.css:117` (which narrows the nav panel
|
| 266 |
+
to `min(336px, calc(100% - 48px))`) does NOT fire at a 1024px window β it starts at 1000. */
|
| 267 |
+
.cg-mapview > .cg-map-bar > .cg-route-popover {
|
| 268 |
+
right: 12px;
|
| 269 |
+
left: auto;
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
/* Flush to the frame edge, not inset: these are the full-height drawers wave 45 shaped, and
|
| 273 |
+
their `border-left` is the seam that reads as an edge. Same value wave45 declares, restated
|
| 274 |
+
at 0,4,0 in the later sheet so an import reorder cannot quietly send them back left. */
|
| 275 |
+
.cg-mapview > .cg-map-bar > .cg-route-popover.cg-route-nav-panel {
|
| 276 |
+
right: 0;
|
| 277 |
+
left: auto;
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
/* βββββββββββββββββββ W46-T19 / R9 / C2 β the route timer and the drag grip βββββββββββββββββββ
|
| 281 |
+
|
| 282 |
+
THE TIMER SITS ABOVE THE STOPS IT IS ABOUT, which is what makes it readable as a property of
|
| 283 |
+
the whole drive rather than of the first stop. Two tones, and the difference between them is
|
| 284 |
+
the whole of C2's client half: a road answer is ink, an arithmetic one is muted and carries
|
| 285 |
+
the word "estimated" in its own label. Nothing here invents a colour or a size; the muted
|
| 286 |
+
token is the same one the rest of this panel's secondary copy already wears.
|
| 287 |
+
|
| 288 |
+
β THE NUMBER MUST RENDER AT POINTER SPEED. Every rule below is paint only: no layout property
|
| 289 |
+
animates, and the drag state is one opacity change over 120ms, so a stop being moved across a
|
| 290 |
+
list of a hundred never waits on a style recalculation, let alone on a request. */
|
| 291 |
+
.cg-w46-route-timer {
|
| 292 |
+
display: flex;
|
| 293 |
+
flex-direction: column;
|
| 294 |
+
gap: 4px;
|
| 295 |
+
margin: 0 0 10px;
|
| 296 |
+
padding: 8px 10px;
|
| 297 |
+
border: 1px solid var(--lp-line);
|
| 298 |
+
border-radius: 8px;
|
| 299 |
+
background: var(--lp-surface);
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
.cg-w46-timer-head {
|
| 303 |
+
display: flex;
|
| 304 |
+
align-items: baseline;
|
| 305 |
+
gap: 8px;
|
| 306 |
+
flex-wrap: wrap;
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
/* The settled figure: the number a day is planned from, so it takes the page's own ink. */
|
| 310 |
+
.cg-w46-timer-time {
|
| 311 |
+
color: var(--lp-ink);
|
| 312 |
+
font-size: var(--lp-fs-lg);
|
| 313 |
+
font-weight: 600;
|
| 314 |
+
font-variant-numeric: tabular-nums;
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
/* The estimate. Muted is the ONLY signal that separates the two, so it is stated here once and
|
| 318 |
+
the label beside it says "estimated" in words for anyone who cannot see the difference. */
|
| 319 |
+
.cg-w46-timer-time.is-estimated {
|
| 320 |
+
color: var(--lp-muted);
|
| 321 |
+
font-weight: 500;
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
.cg-w46-timer-caption {
|
| 325 |
+
color: var(--lp-muted);
|
| 326 |
+
font-size: var(--lp-fs-2xs);
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
.cg-w46-timer-saving {
|
| 330 |
+
display: flex;
|
| 331 |
+
align-items: center;
|
| 332 |
+
gap: 8px;
|
| 333 |
+
flex-wrap: wrap;
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
.cg-w46-timer-saving > p,
|
| 337 |
+
.cg-w46-timer-note,
|
| 338 |
+
.cg-w46-timer-caveat,
|
| 339 |
+
.cg-w46-timer-error {
|
| 340 |
+
margin: 0;
|
| 341 |
+
font-size: var(--lp-fs-2xs);
|
| 342 |
+
line-height: 1.4;
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
.cg-w46-timer-saving > p {
|
| 346 |
+
color: var(--lp-ink);
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
/* A caveat and a cost are both things the reader has to take on board, so neither is allowed to
|
| 350 |
+
fade into furniture: muted, but at body weight rather than as a caption aside. */
|
| 351 |
+
.cg-w46-timer-note,
|
| 352 |
+
.cg-w46-timer-caveat {
|
| 353 |
+
color: var(--lp-muted);
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
.cg-w46-timer-error {
|
| 357 |
+
color: var(--lp-red-deep);
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
.cg-w46-timer-apply {
|
| 361 |
+
flex: 0 0 auto;
|
| 362 |
+
appearance: none;
|
| 363 |
+
border: 1px solid var(--lp-primary);
|
| 364 |
+
border-radius: 6px;
|
| 365 |
+
padding: 2px 10px;
|
| 366 |
+
background: var(--lp-blue-tint);
|
| 367 |
+
color: var(--lp-primary);
|
| 368 |
+
font: inherit;
|
| 369 |
+
font-size: var(--lp-fs-2xs);
|
| 370 |
+
cursor: pointer;
|
| 371 |
+
transition: background 120ms ease-out;
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
.cg-w46-timer-apply:hover:not(:disabled) {
|
| 375 |
+
background: var(--lp-surface);
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
.cg-w46-timer-apply:focus-visible {
|
| 379 |
+
outline: 2px solid var(--lp-primary);
|
| 380 |
+
outline-offset: 2px;
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
.cg-w46-timer-apply:disabled {
|
| 384 |
+
opacity: 0.55;
|
| 385 |
+
cursor: default;
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
/* The grip. Pointer only, and it says so by never taking focus; the arrows beside it are the
|
| 389 |
+
keyboard's way through the same reorder. */
|
| 390 |
+
.cg-w46-stop-grip {
|
| 391 |
+
display: inline-flex;
|
| 392 |
+
align-items: center;
|
| 393 |
+
flex: 0 0 auto;
|
| 394 |
+
color: var(--lp-muted);
|
| 395 |
+
cursor: grab;
|
| 396 |
+
touch-action: none;
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
.cg-w46-stop-grip:active {
|
| 400 |
+
cursor: grabbing;
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
+
.cg-w46-stop-grip > svg {
|
| 404 |
+
width: 12px;
|
| 405 |
+
height: 16px;
|
| 406 |
+
fill: currentColor;
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
/* The stop under the pointer. Opacity only, so the list never reflows mid drag. */
|
| 410 |
+
.cg-w44-route-stops > li.cg-w46-stop-dragging {
|
| 411 |
+
opacity: 0.55;
|
| 412 |
+
transition: opacity 120ms ease-out;
|
| 413 |
+
}
|
| 414 |
+
|
| 415 |
+
/* ββ W46-T23 / INSTRUCTION 19 β the Route's name is edited where it is READ. βββββββββββββ
|
| 416 |
+
Rename used to live in the list row's "..." menu and again in a "Route name" box down in the
|
| 417 |
+
edit block. Both are gone; the title is the field. Resting state must still read as a title,
|
| 418 |
+
so the control beside it stays quiet until the row is hovered or the button is focused. */
|
| 419 |
+
.cg-w44-route-title {
|
| 420 |
+
display: flex;
|
| 421 |
+
align-items: center;
|
| 422 |
+
gap: 6px;
|
| 423 |
+
min-width: 0;
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
.cg-w46-route-name {
|
| 427 |
+
min-width: 0;
|
| 428 |
+
overflow: hidden;
|
| 429 |
+
text-overflow: ellipsis;
|
| 430 |
+
white-space: nowrap;
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
.cg-w46-route-rename {
|
| 434 |
+
border: 0;
|
| 435 |
+
background: transparent;
|
| 436 |
+
font: 500 var(--lp-fs-3xs)/1.4 Inter, system-ui, sans-serif;
|
| 437 |
+
color: var(--lp-muted);
|
| 438 |
+
flex: 0 0 auto;
|
| 439 |
+
padding: 2px 4px;
|
| 440 |
+
border-radius: var(--lp-r-md);
|
| 441 |
+
cursor: pointer;
|
| 442 |
+
opacity: 0.5;
|
| 443 |
+
transition: opacity 140ms ease-out, color 140ms ease-out;
|
| 444 |
+
}
|
| 445 |
+
|
| 446 |
+
.cg-w44-route-title:hover .cg-w46-route-rename,
|
| 447 |
+
.cg-w46-route-rename:focus-visible {
|
| 448 |
+
opacity: 1;
|
| 449 |
+
color: var(--lp-primary);
|
| 450 |
+
}
|
| 451 |
+
|
| 452 |
+
.cg-w46-route-rename[disabled] {
|
| 453 |
+
opacity: 0.4;
|
| 454 |
+
color: var(--lp-muted);
|
| 455 |
+
cursor: default;
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
/* Editing: the input takes the title's place, its two controls sit on the same line so the row
|
| 459 |
+
never grows taller than the title it replaced. */
|
| 460 |
+
.cg-w46-route-rename-edit {
|
| 461 |
+
display: flex;
|
| 462 |
+
align-items: center;
|
| 463 |
+
gap: 6px;
|
| 464 |
+
flex: 1 1 auto;
|
| 465 |
+
min-width: 0;
|
| 466 |
+
}
|
| 467 |
+
|
| 468 |
+
.cg-w46-route-rename-edit .cg-w46-route-rename {
|
| 469 |
+
opacity: 1;
|
| 470 |
+
}
|
| 471 |
+
|
| 472 |
+
.cg-w46-route-name-input {
|
| 473 |
+
flex: 1 1 auto;
|
| 474 |
+
min-width: 0;
|
| 475 |
+
}
|
web/src/styles/wave46/rail-select.css
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* WAVE 46 - T02. The views rail's multi-select bar and the selected-row mark.
|
| 2 |
+
*
|
| 3 |
+
* Loaded from ViewSidebar.tsx rather than from index.css (contract C6): an @imported sheet sits
|
| 4 |
+
* ABOVE index.css's own rules and loses every equal-specificity fight with them, so the
|
| 5 |
+
* selected-row background below would never beat `.cg-view-row.is-active`. A sheet imported from
|
| 6 |
+
* a component lands after index.css in the bundle and wins.
|
| 7 |
+
*
|
| 8 |
+
* Tokens only: no literal font-size, no inline hex. Blue marks the selection, red marks the one
|
| 9 |
+
* destructive control.
|
| 10 |
+
*/
|
| 11 |
+
|
| 12 |
+
.cg-railsel {
|
| 13 |
+
display: flex;
|
| 14 |
+
flex-wrap: wrap;
|
| 15 |
+
align-items: center;
|
| 16 |
+
gap: 8px;
|
| 17 |
+
padding: 8px 12px;
|
| 18 |
+
border-top: 1px solid var(--cg-line);
|
| 19 |
+
background: var(--lp-blue-tint);
|
| 20 |
+
color: var(--cg-text);
|
| 21 |
+
font-size: var(--lp-fs-2xs);
|
| 22 |
+
animation: cg-railsel-in 140ms ease-out;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
@keyframes cg-railsel-in {
|
| 26 |
+
from { opacity: 0; transform: translateY(4px); }
|
| 27 |
+
to { opacity: 1; transform: none; }
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
@media (prefers-reduced-motion: reduce) {
|
| 31 |
+
.cg-railsel { animation: none; }
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
.cg-railsel-count {
|
| 35 |
+
flex: 1 1 auto;
|
| 36 |
+
min-width: 0;
|
| 37 |
+
font-weight: 600;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
.cg-railsel-ask {
|
| 41 |
+
flex: 1 1 100%;
|
| 42 |
+
min-width: 0;
|
| 43 |
+
color: var(--cg-text);
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
/* Quiet buttons, same posture as `.shell-newfolder`: native chrome off, hairline border, no
|
| 47 |
+
* shadow. `font: inherit` keeps them on the bar's own step of the scale. */
|
| 48 |
+
.cg-railsel button {
|
| 49 |
+
border: 0;
|
| 50 |
+
background: transparent;
|
| 51 |
+
font: inherit;
|
| 52 |
+
color: inherit;
|
| 53 |
+
box-shadow: inset 0 0 0 1px var(--cg-line);
|
| 54 |
+
border-radius: 6px;
|
| 55 |
+
padding: 4px 8px;
|
| 56 |
+
cursor: pointer;
|
| 57 |
+
transition: opacity 120ms ease-out, background 120ms ease-out;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
.cg-railsel button:hover:not(:disabled) {
|
| 61 |
+
box-shadow: inset 0 0 0 1px var(--lp-blue-deep);
|
| 62 |
+
background: var(--lp-wash);
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
.cg-railsel button:focus-visible {
|
| 66 |
+
outline: 2px solid var(--lp-blue-deep);
|
| 67 |
+
outline-offset: 1px;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
.cg-railsel button:disabled {
|
| 71 |
+
opacity: 0.5;
|
| 72 |
+
cursor: default;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.cg-railsel button.is-danger {
|
| 76 |
+
color: var(--lp-red-deep);
|
| 77 |
+
box-shadow: inset 0 0 0 1px var(--lp-red-deep);
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
.cg-railsel button.is-danger:hover:not(:disabled) {
|
| 81 |
+
background: var(--lp-red-tint);
|
| 82 |
+
box-shadow: inset 0 0 0 1px var(--lp-red-deep);
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
/* The rows in the range. Kept distinct from `.is-active`, which says "this is the table you are
|
| 86 |
+
* looking at" and can be true of a selected row at the same time. */
|
| 87 |
+
.cg-view-row.is-railsel {
|
| 88 |
+
background: var(--lp-blue-tint);
|
| 89 |
+
box-shadow: inset 2px 0 0 var(--lp-blue-deep);
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
/* WAVE 46 - T03. The bulk-export list's rows, on the panel's own step of the scale.
|
| 93 |
+
*
|
| 94 |
+
* OWNER RULING 2026-08-29, and it AMENDS the ticket's literal done-when. That clause asked for
|
| 95 |
+
* "the same computed font-size as the sibling rail rows", and the rail is TWO answers, neither of
|
| 96 |
+
* them the right target: the `.cg-view-row` element itself declares nothing and computes the 17px
|
| 97 |
+
* root, while the text you actually read sits in `.cg-view-main`, which declares `--lp-fs-xs`.
|
| 98 |
+
* Chasing the first leaves these rows exactly as they were, which is the complaint. The owner
|
| 99 |
+
* chose the other target instead: the whole export PANEL reads at ONE size. So these rows take
|
| 100 |
+
* `--lp-fs-2xs`, the step `.cg-pop-title` and `.cg-pop-note` already use beside them, and they
|
| 101 |
+
* deliberately DIFFER from the rail by one step.
|
| 102 |
+
*
|
| 103 |
+
* β SO THE RULED ANSWER IS `--lp-fs-2xs` AND NOT `--lp-fs-xs`, and that is the correction a later
|
| 104 |
+
* reader will actually reach for: reading the done-when literally against `.cg-view-main` argues
|
| 105 |
+
* for `--lp-fs-xs`, which is a real and plausible-looking target one step above this one. It was
|
| 106 |
+
* considered and rejected. Matching the PANEL beat matching the rail, because the two lines this
|
| 107 |
+
* list sits directly under are `--lp-fs-2xs` and the jump inside one small panel is the whole
|
| 108 |
+
* complaint. Do not move these rows onto the rail's step.
|
| 109 |
+
*
|
| 110 |
+
* The ticket blamed `.cg-radio-row`. That was wrong on the mechanism and right on the naming:
|
| 111 |
+
* index.css's `.cg-radio-row` declares no font-size whatsoever (only display / align-items / gap /
|
| 112 |
+
* padding / border-radius / cursor, and a 15px input box), so it could not have been the source.
|
| 113 |
+
* The size was pure INHERITANCE, because `.cg-view-menu` sets no font-size either. The class is
|
| 114 |
+
* still wrong on a checkbox list, so the rows get their own name here and every layout property
|
| 115 |
+
* they used to borrow is restated below. Nothing else in the repo uses this class, so no other
|
| 116 |
+
* `.cg-radio-row` list is reached.
|
| 117 |
+
*
|
| 118 |
+
* Tokens only: `--lp-fs-2xs` is the scale step, never a literal.
|
| 119 |
+
*/
|
| 120 |
+
.cg-export-view-row {
|
| 121 |
+
display: flex;
|
| 122 |
+
align-items: center;
|
| 123 |
+
/* One step down from the radio row's 9px, onto the 4/8 rhythm: at the smaller step the old
|
| 124 |
+
gap left the box floating away from its own label. */
|
| 125 |
+
gap: 8px;
|
| 126 |
+
/* Vertical padding likewise tightens 6px to 4px so a 20-row list stays a list rather than a
|
| 127 |
+
column of buttons. Horizontal stays 8px, so the rows keep the same left edge as
|
| 128 |
+
`.cg-pop-title` and `.cg-pop-note` above them. */
|
| 129 |
+
padding: 4px 8px;
|
| 130 |
+
border-radius: var(--lp-r-md);
|
| 131 |
+
font-size: var(--lp-fs-2xs);
|
| 132 |
+
line-height: 1.45;
|
| 133 |
+
color: var(--cg-text);
|
| 134 |
+
cursor: pointer;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
.cg-export-view-row:hover {
|
| 138 |
+
background: var(--lp-surface-2);
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
/* The 15px box is unchanged: it is the same control the rest of the app ships, and centring it
|
| 142 |
+
against a single line of the smaller step is what keeps it on the text's optical baseline. */
|
| 143 |
+
.cg-export-view-row input {
|
| 144 |
+
accent-color: var(--lp-blue-deep);
|
| 145 |
+
width: 15px;
|
| 146 |
+
height: 15px;
|
| 147 |
+
flex: 0 0 auto;
|
| 148 |
+
margin: 0;
|
| 149 |
+
cursor: pointer;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
/* A View name is TENANT CONTENT inside a panel with a 260px ceiling, so it truncates rather than
|
| 153 |
+
wrapping the row to two lines. Same treatment `.cg-radio-row > span:not([class])` gave it. */
|
| 154 |
+
.cg-export-view-row > span {
|
| 155 |
+
flex: 1 1 auto;
|
| 156 |
+
min-width: 0;
|
| 157 |
+
overflow: hidden;
|
| 158 |
+
text-overflow: ellipsis;
|
| 159 |
+
white-space: nowrap;
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
/* WAVE 46 - T04. The data layer's create door now renders at every level and sits directly under
|
| 163 |
+
* the Back row, where the view layer's `.cg-create-new` sits under the shared band. That view-layer
|
| 164 |
+
* wrapper carries `margin-top: 8px` and `.cg-data-create` carried none, so the two doors would
|
| 165 |
+
* start on different rhythms once they became visible side by side across a drill-in. Same step,
|
| 166 |
+
* so the two layers read as one control in that row. */
|
| 167 |
+
.cg-data-create {
|
| 168 |
+
margin-top: 8px;
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
/* WAVE 46 - T06. The database row's "..." is a shell `.shell-dots`, not a `.cg-view-more`.
|
| 172 |
+
*
|
| 173 |
+
* It arrives through the `renderDatabaseActions` prop (Shell.tsx fills it with the shell's own
|
| 174 |
+
* `RowMenu`), so the button lands as a direct child of `.cg-fold-head` inside the views rail.
|
| 175 |
+
* Every rule in `shell/navExtras.css` is scoped to `.shell-nav-row > .shell-dots` or
|
| 176 |
+
* `.shell-nav-folder > .shell-dots`, and neither parent exists here, so NOT ONE of them matched
|
| 177 |
+
* and the button fell back to native UA chrome: a 1.78px outset black border over rgb(240,240,240)
|
| 178 |
+
* at 29.6x22.2. That is the owner's "big square outline" and the tinted fill DESIGN.md section 4
|
| 179 |
+
* forbids. The fix restores the quiet-button treatment the shell already gives this control in its
|
| 180 |
+
* own nav, sized to `.cg-view-more`'s 28x28 box so the database row's control and the view row's
|
| 181 |
+
* control are the same shape on the same baseline.
|
| 182 |
+
*
|
| 183 |
+
* β THE `button` TAG IN THE SELECTOR IS LOAD-BEARING, NOT DECORATION. `.shell-nav-row >
|
| 184 |
+
* .shell-dots` is (0,2,0); a plain `.cg-fold-head > .shell-dots` is also (0,2,0) and would only
|
| 185 |
+
* TIE, leaving the winner to whichever sheet the bundler emits last, which no lane controls and
|
| 186 |
+
* which can flip between builds. The element qualifier makes this (0,2,1), so it wins outright.
|
| 187 |
+
* Do not "simplify" it back into a coin flip.
|
| 188 |
+
*
|
| 189 |
+
* VISIBILITY: always visible, deliberately. `.cg-view-more` ships `opacity: 0` and is revealed by
|
| 190 |
+
* `.cg-view-row:hover`, but `index.css` already carries the folder-head exception
|
| 191 |
+
* (`.cg-fold-head .cg-view-more { opacity: 1 }`) because a fold head is not a view row and nothing
|
| 192 |
+
* would ever reveal it. The database rows ARE `.cg-fold-head`, so following that precedent is what
|
| 193 |
+
* "exactly the same as the view rows' control" means here. It also protects against the shell rule
|
| 194 |
+
* gaining rail reach later and painting this button at zero opacity.
|
| 195 |
+
*/
|
| 196 |
+
.cg-fold-head > button.shell-dots {
|
| 197 |
+
flex: 0 0 28px;
|
| 198 |
+
width: 28px;
|
| 199 |
+
height: 28px;
|
| 200 |
+
padding: 0;
|
| 201 |
+
margin: 0;
|
| 202 |
+
border: 0;
|
| 203 |
+
border-radius: var(--lp-r-sm);
|
| 204 |
+
background: transparent;
|
| 205 |
+
font: inherit;
|
| 206 |
+
/* `.cg-view-more` declares `color: var(--cg-muted)`, which resolves to the same `--lp-muted` the
|
| 207 |
+
* shell gives this button. Named rather than inherited so the two controls cannot drift. */
|
| 208 |
+
color: var(--cg-muted);
|
| 209 |
+
display: grid;
|
| 210 |
+
place-items: center;
|
| 211 |
+
cursor: pointer;
|
| 212 |
+
opacity: 1;
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
.cg-fold-head > button.shell-dots:hover {
|
| 216 |
+
background: var(--lp-wash);
|
| 217 |
+
color: var(--lp-ink);
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
.cg-fold-head > button.shell-dots:focus-visible {
|
| 221 |
+
outline: 2px solid var(--lp-blue-deep);
|
| 222 |
+
outline-offset: 1px;
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
/* WAVE 46 - T08 (owner instruction 26). The rail's history row: back, forward and the folder
|
| 226 |
+
* breadcrumb, seated directly under "Minimize views" and above "+ Create new...".
|
| 227 |
+
*
|
| 228 |
+
* Only the ROW is styled here. The control shapes already exist in index.css
|
| 229 |
+
* (`.cg-path-history-button`, `.cg-path-segment`, `.cg-path-separator`), and drawing a second set
|
| 230 |
+
* beside them is how one surface ends up with two button shapes. This sheet loads after index.css
|
| 231 |
+
* (contract C6), so the seating below wins the equal-specificity fight it needs to win.
|
| 232 |
+
*/
|
| 233 |
+
.cg-view-path {
|
| 234 |
+
margin: 6px 0 2px;
|
| 235 |
+
border-bottom: 1px solid var(--lp-line);
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
/* One height and one baseline across back, forward and every crumb. */
|
| 239 |
+
.cg-segmented-path {
|
| 240 |
+
align-items: center;
|
| 241 |
+
min-height: 30px;
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
/* A long path scrolls inside the row; it never wraps the rail into a second line. */
|
| 245 |
+
.cg-segmented-path .cg-path-segments {
|
| 246 |
+
gap: 1px;
|
| 247 |
+
flex-wrap: nowrap;
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
.cg-path-separator {
|
| 251 |
+
padding: 0 1px;
|
| 252 |
+
user-select: none;
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
/* The current segment is where you are, so it is inert. It must still read as text, not as a
|
| 256 |
+
* greyed-out control: `aria-current` already gives it the filled, darker treatment in index.css,
|
| 257 |
+
* and this only removes the pointer. */
|
| 258 |
+
.cg-path-segment:disabled {
|
| 259 |
+
cursor: default;
|
| 260 |
+
opacity: 1;
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
.cg-path-segment,
|
| 264 |
+
.cg-path-history-button {
|
| 265 |
+
transition: background 140ms ease-out, color 140ms ease-out, opacity 140ms ease-out;
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
@media (prefers-reduced-motion: reduce) {
|
| 269 |
+
.cg-path-segment,
|
| 270 |
+
.cg-path-history-button { transition: none; }
|
| 271 |
+
}
|
web/src/styles/wave46/route-print.css
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* ---------------------------------------------------------------------------
|
| 2 |
+
customer-grid / route print sheet (W46-T20, instruction 10, ruling R6, C6)
|
| 3 |
+
|
| 4 |
+
Route export is the browser's own Save as PDF. No new dependency, no renderer:
|
| 5 |
+
a print stylesheet plus a body level portal, which is the pattern the catalog
|
| 6 |
+
export already proves in this codebase (catalogPrint.ts plus the print block
|
| 7 |
+
in index.css keyed off `cg-cat-printing`).
|
| 8 |
+
|
| 9 |
+
THREE THINGS THIS FILE OWES, and each one is load bearing:
|
| 10 |
+
|
| 11 |
+
1. ISOLATION. When a person prints a route, the app shell, the grid, the map
|
| 12 |
+
and every panel must not print. `body > *` is hidden and the one portal is
|
| 13 |
+
revealed, exactly as the catalog block does it. Its class names are NOT
|
| 14 |
+
reused: `cg-cat-printing` un-hides only `.cg-cat-print-portal`, so
|
| 15 |
+
borrowing it would print a blank page with no error anywhere.
|
| 16 |
+
|
| 17 |
+
2. THE HEIGHT RESET. index.css sets `html, body, #root { height: 100% }`, and
|
| 18 |
+
the shell above that scrolls inside its own panes. Left alone, a flowing
|
| 19 |
+
stop list is clipped to ONE page: the stops past the fold never lay out,
|
| 20 |
+
so they are absent from the PDF and Chromium emits no link annotation for
|
| 21 |
+
them either. The reset below is the whole reason the tail of a long route
|
| 22 |
+
reaches paper.
|
| 23 |
+
|
| 24 |
+
3. VISIBLE ANCHORS. A PDF link annotation is emitted by the print engine for
|
| 25 |
+
a real `<a href>` that is VISIBLE in the print layout. Nothing here may
|
| 26 |
+
hide, collapse or zero out a stop link, and `break-inside: avoid` keeps a
|
| 27 |
+
stop from being torn across a page boundary.
|
| 28 |
+
|
| 29 |
+
β NO `@page` RULE ON PURPOSE. `@page` is global to the document and cannot be
|
| 30 |
+
scoped to a class, so a margin declared here would also reach the catalog
|
| 31 |
+
export, which sets its own `@page { margin: 0 }` from generated CSS. The
|
| 32 |
+
browser's default page margin is honest and costs nothing. That also keeps
|
| 33 |
+
this sheet free of literal lengths in the type scale sense: every size below
|
| 34 |
+
is a `--lp-fs-*` token, per DESIGN.md and the R5 font gate.
|
| 35 |
+
|
| 36 |
+
Tokens come from the `:root` block in index.css, which is where they must be
|
| 37 |
+
read from here: this portal mounts on `document.body`, OUTSIDE the grid
|
| 38 |
+
surface, so any token declared on a wrapper element would be undefined in it.
|
| 39 |
+
--------------------------------------------------------------------------- */
|
| 40 |
+
|
| 41 |
+
/* Parked off screen rather than display:none while a print is in flight, so the
|
| 42 |
+
sheet has real layout the moment the dialog opens. It is mounted only for the
|
| 43 |
+
duration of a print, so on screen this rule is all it ever is. */
|
| 44 |
+
.cg-w46-route-print-portal {
|
| 45 |
+
position: fixed;
|
| 46 |
+
left: -20000px;
|
| 47 |
+
top: 0;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
/* ββ the control itself, on screen ββββββββββββββββββββββββββββββββββββββββββ
|
| 51 |
+
It lives in the Route panel beside the Maps links, so it borrows that block's
|
| 52 |
+
vocabulary rather than inventing one. The button resets native chrome, which
|
| 53 |
+
is the house rule for every button in this app. */
|
| 54 |
+
.cg-w46-route-export {
|
| 55 |
+
display: flex;
|
| 56 |
+
flex-direction: column;
|
| 57 |
+
gap: 0.35rem;
|
| 58 |
+
padding: 0.5rem 0 0;
|
| 59 |
+
border-top: 1px solid var(--lp-line);
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
.cg-w46-route-export h3 {
|
| 63 |
+
margin: 0;
|
| 64 |
+
font-size: var(--lp-fs-2xs);
|
| 65 |
+
font-weight: 600;
|
| 66 |
+
color: var(--lp-ink);
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
.cg-w46-route-export p {
|
| 70 |
+
margin: 0;
|
| 71 |
+
font-size: var(--lp-fs-3xs);
|
| 72 |
+
color: var(--lp-muted);
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.cg-w46-route-export-open {
|
| 76 |
+
align-self: flex-start;
|
| 77 |
+
border: 0;
|
| 78 |
+
padding: 4px 7px;
|
| 79 |
+
border-radius: var(--lp-r-sm);
|
| 80 |
+
background: var(--lp-primary);
|
| 81 |
+
color: var(--cg-white);
|
| 82 |
+
font-family: inherit;
|
| 83 |
+
font-size: var(--lp-fs-3xs);
|
| 84 |
+
font-weight: 600;
|
| 85 |
+
cursor: pointer;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.cg-w46-route-export-open:hover:enabled { opacity: 0.9; }
|
| 89 |
+
.cg-w46-route-export-open:disabled { opacity: 0.55; cursor: default; }
|
| 90 |
+
.cg-w46-route-export-open:focus-visible {
|
| 91 |
+
outline: 2px solid var(--lp-blue-deep);
|
| 92 |
+
outline-offset: 2px;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
@media print {
|
| 96 |
+
html.cg-w46-route-printing,
|
| 97 |
+
html.cg-w46-route-printing body {
|
| 98 |
+
height: auto !important;
|
| 99 |
+
min-height: 0 !important;
|
| 100 |
+
max-height: none !important;
|
| 101 |
+
overflow: visible !important;
|
| 102 |
+
margin: 0;
|
| 103 |
+
padding: 0;
|
| 104 |
+
background: var(--cg-white);
|
| 105 |
+
-webkit-print-color-adjust: exact;
|
| 106 |
+
print-color-adjust: exact;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
html.cg-w46-route-printing body > * {
|
| 110 |
+
display: none !important;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
html.cg-w46-route-printing body > .cg-w46-route-print-portal {
|
| 114 |
+
display: block !important;
|
| 115 |
+
position: static !important;
|
| 116 |
+
left: auto !important;
|
| 117 |
+
top: auto !important;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
.cg-w46-route-print-sheet {
|
| 121 |
+
color: var(--lp-ink);
|
| 122 |
+
font-size: var(--lp-fs-sm);
|
| 123 |
+
line-height: 1.45;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
.cg-w46-route-print-title {
|
| 127 |
+
margin: 0;
|
| 128 |
+
font-size: var(--lp-fs-lg);
|
| 129 |
+
font-weight: 600;
|
| 130 |
+
color: var(--lp-primary);
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
.cg-w46-route-print-meta {
|
| 134 |
+
margin: 0.25rem 0 0.75rem;
|
| 135 |
+
font-size: var(--lp-fs-2xs);
|
| 136 |
+
color: var(--lp-muted);
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
.cg-w46-route-print-stops {
|
| 140 |
+
margin: 0;
|
| 141 |
+
padding: 0;
|
| 142 |
+
list-style: none;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
/* A stop torn across a page boundary is how an anchor loses its annotation. */
|
| 146 |
+
.cg-w46-route-print-stop {
|
| 147 |
+
display: flex;
|
| 148 |
+
gap: 0.6rem;
|
| 149 |
+
padding: 0.4rem 0;
|
| 150 |
+
border-top: 1px solid var(--lp-line);
|
| 151 |
+
break-inside: avoid;
|
| 152 |
+
page-break-inside: avoid;
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
.cg-w46-print-pos {
|
| 156 |
+
flex: 0 0 auto;
|
| 157 |
+
min-width: 1.6rem;
|
| 158 |
+
font-weight: 600;
|
| 159 |
+
color: var(--lp-primary);
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
.cg-w46-print-body {
|
| 163 |
+
display: flex;
|
| 164 |
+
flex-direction: column;
|
| 165 |
+
gap: 0.1rem;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.cg-w46-print-name {
|
| 169 |
+
font-weight: 600;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
.cg-w46-print-address,
|
| 173 |
+
.cg-w46-print-nolink {
|
| 174 |
+
font-size: var(--lp-fs-2xs);
|
| 175 |
+
color: var(--lp-muted);
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
/* The clickable half. Underlined and coloured so a reader can see on paper
|
| 179 |
+
that it was a link, and never hidden, so the engine emits the annotation. */
|
| 180 |
+
.cg-w46-print-link {
|
| 181 |
+
font-size: var(--lp-fs-2xs);
|
| 182 |
+
color: var(--lp-primary);
|
| 183 |
+
text-decoration: underline;
|
| 184 |
+
}
|
| 185 |
+
}
|
web/src/styles/wave46/schema-viewer.css
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* ---------------------------------------------------------------------------
|
| 2 |
+
W46-T45 (owner instruction 23, contract C6) β the schema viewer wears the
|
| 3 |
+
Settings modal's shape, and the "View schema" menu row gets a mark.
|
| 4 |
+
|
| 5 |
+
β WHY A SEPARATE SHEET, AND WHY IT IS IMPORTED FROM `NavExtras.tsx`.
|
| 6 |
+
C6: a wave sheet is imported by the component that owns the surface, AFTER
|
| 7 |
+
that component's existing stylesheet import, so the override lands later in
|
| 8 |
+
the bundle than `navExtras.css` by construction. It is NEVER added to
|
| 9 |
+
`index.css` β a global sheet gives a lane-local override a global blast
|
| 10 |
+
radius and re-opens the seam C6 exists to close.
|
| 11 |
+
|
| 12 |
+
β AND ORDER ALONE IS NOT TRUSTED. Every rule below is anchored on
|
| 13 |
+
`.shell-schema` (or, for the drawer element itself, on its backdrop parent,
|
| 14 |
+
because an element cannot be its own ancestor), so each selector outranks
|
| 15 |
+
`navExtras.css`'s single-class rule on SPECIFICITY. A bundler that reorders
|
| 16 |
+
two sheets then costs nothing instead of silently reverting the panel.
|
| 17 |
+
|
| 18 |
+
β TOKENS ONLY. No literal font-size and no inline colour: `verify_ui.py`'s
|
| 19 |
+
R5 leg scans every stylesheet under `src/` and reds on a literal.
|
| 20 |
+
|
| 21 |
+
The design target is `SettingsModal.tsx`'s chrome, read out of `index.css`:
|
| 22 |
+
`.set-modal` `.set-body` `.set-close` `.set-h` `.set-h4` `.set-label`
|
| 23 |
+
`.set-card`. Each rule below names the sibling it is matching.
|
| 24 |
+
|
| 25 |
+
β IT STAYS A RIGHT-SIDE DRAWER. DESIGN.md Β§4 puts a detail panel in a right
|
| 26 |
+
drawer; the contract asks for the Settings modal's computed TYPE and SURFACE
|
| 27 |
+
values, not its position. Only the corners facing the content are rounded,
|
| 28 |
+
because the drawer is flush to the viewport's right edge and rounding there
|
| 29 |
+
would show backdrop slivers down the seam.
|
| 30 |
+
--------------------------------------------------------------------------- */
|
| 31 |
+
|
| 32 |
+
/* ββ the menu glyph ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ */
|
| 33 |
+
|
| 34 |
+
/* `.shell-navmenu-item` is already `display:flex; align-items:center; gap:8px`,
|
| 35 |
+
so a leading glyph slots into the existing row without touching its layout.
|
| 36 |
+
Box, weight and tone live here and never in an inline style β the same shape
|
| 37 |
+
`.shell-newthing-plus` uses one file over. */
|
| 38 |
+
.shell-navmenu-item .shell-schema-glyph {
|
| 39 |
+
flex: none;
|
| 40 |
+
width: 16px;
|
| 41 |
+
height: 16px;
|
| 42 |
+
fill: none;
|
| 43 |
+
stroke: currentColor;
|
| 44 |
+
stroke-width: 1.5;
|
| 45 |
+
stroke-linecap: round;
|
| 46 |
+
stroke-linejoin: round;
|
| 47 |
+
color: var(--lp-muted);
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
.shell-navmenu-item:hover .shell-schema-glyph {
|
| 51 |
+
color: var(--lp-ink);
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
/* ββ the drawer surface: `.set-modal` ββββββββββββββββββββββββββββββββββββββββ */
|
| 55 |
+
|
| 56 |
+
.shell-schema-backdrop .shell-schema {
|
| 57 |
+
border-radius: var(--lp-r-lg) 0 0 var(--lp-r-lg);
|
| 58 |
+
/* `.set-modal` uses the named token; the literal rgba it replaces was the
|
| 59 |
+
one an anti-slop sweep never sees. */
|
| 60 |
+
box-shadow: var(--shell-shadow-overlay);
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
/* ββ the head: `.set-h` (title) and `.set-close` βββββββββββββββββββββββββββββ */
|
| 64 |
+
|
| 65 |
+
.shell-schema .shell-schema-head {
|
| 66 |
+
/* the body's horizontal rhythm, so the title sits over the content edge */
|
| 67 |
+
padding: 18px 26px 14px;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
.shell-schema .shell-schema-title {
|
| 71 |
+
font-weight: 620;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
.shell-schema .shell-schema-close {
|
| 75 |
+
flex: none;
|
| 76 |
+
display: inline-flex;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
width: 28px;
|
| 80 |
+
height: 28px;
|
| 81 |
+
padding: 0;
|
| 82 |
+
border-radius: var(--lp-r-sm);
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
/* ββ the body: `.set-body` βββββββββββββββββββββββββββββββββββββββββββββββββββ */
|
| 86 |
+
|
| 87 |
+
.shell-schema .shell-schema-body {
|
| 88 |
+
padding: 22px 26px 30px;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
.shell-schema .shell-schema-note {
|
| 92 |
+
/* the literal 6px/8px radii in this drawer are the last inline geometry in
|
| 93 |
+
it; the note is a notice, and `.set-notice` rounds on the small token. */
|
| 94 |
+
border-radius: var(--lp-r-sm);
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
/* ββ the section head: `.set-h4` βββββββββββββββββββββββββββββββββββββββββββββ */
|
| 98 |
+
|
| 99 |
+
/* `.set-h4` is `--lp-fs-sm` / 620 and takes its colour from the pane, which is
|
| 100 |
+
ink. The kicker was `--lp-fs-2xs` / 600 / muted β three roles away from the
|
| 101 |
+
sibling it is supposed to read as. */
|
| 102 |
+
.shell-schema .shell-schema-kicker {
|
| 103 |
+
margin: 20px 0 12px;
|
| 104 |
+
font-size: var(--lp-fs-sm);
|
| 105 |
+
font-weight: 620;
|
| 106 |
+
color: var(--lp-ink);
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
.shell-schema .shell-schema-body > .shell-schema-kicker:first-child {
|
| 110 |
+
margin-top: 0;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
/* ββ the containment: `.set-card` ββββββββββββββββββββββββββββββββββββββββββββ */
|
| 114 |
+
|
| 115 |
+
/* ONE layer, never a card inside a card: the two sections each sit in their own
|
| 116 |
+
`.set-card`-equivalent, which is what gives the panel the Settings modal's
|
| 117 |
+
read instead of two lists floating on the surface. */
|
| 118 |
+
.shell-schema .shell-schema-card {
|
| 119 |
+
padding: 16px 18px;
|
| 120 |
+
border: 1px solid var(--lp-line);
|
| 121 |
+
border-radius: var(--lp-r-md);
|
| 122 |
+
background: var(--lp-wash);
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
/* `.set-card--rows`' lesson: inside a bordered card the final hairline has
|
| 126 |
+
nothing under it to separate and reads as a stray underline. */
|
| 127 |
+
.shell-schema .shell-schema-card tbody tr:last-child td {
|
| 128 |
+
border-bottom: 0;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
.shell-schema .shell-schema-card .shell-schema-measure:last-child {
|
| 132 |
+
border-bottom: 0;
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
/* ββ the micro label: `.set-label` βββββββββββββββββββββββββββββββββββββββββββ */
|
| 136 |
+
|
| 137 |
+
.shell-schema .shell-schema-table th {
|
| 138 |
+
font-size: var(--lp-fs-2xs);
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
/* ============================================================================================
|
| 143 |
+
W46-T46 - the Workflows strip and the agent detail header (owner instruction 22)
|
| 144 |
+
APPENDED SECTION. Everything below this banner belongs to W46-T46 and to
|
| 145 |
+
`automation/AutomationDetail.tsx`; nothing above it was read, reordered or edited. The rest of
|
| 146 |
+
this sheet is the shell's schema viewer and is another session's work.
|
| 147 |
+
|
| 148 |
+
THE ROOT CAUSE IS NOT HERE. `.w45-workflow-bar` was a direct child of `.auto-work`, which
|
| 149 |
+
`index.css` declares `display: flex` - a ROW - so the strip was laid out as a full-height
|
| 150 |
+
sibling COLUMN of the builder (measured 769x772 at 1440x900) and squeezed the Properties rail
|
| 151 |
+
to about 40px. That is fixed structurally in the TSX, by moving the strip up one level to sit
|
| 152 |
+
beside `.auto-batch` inside the flex-COLUMN `.auto-detail`. These rules only finish the job,
|
| 153 |
+
and they are anchored on `.auto-detail >` so they win on specificity as well as on the import
|
| 154 |
+
order C6 pins, rather than depending on order alone.
|
| 155 |
+
============================================================================================ */
|
| 156 |
+
|
| 157 |
+
/* The strip is a band, so it takes its own height and never grows or shrinks with the work area.
|
| 158 |
+
β `flex-wrap` is the one addition that matters: `.w45-governance` is a `width: 100%` grid
|
| 159 |
+
sharing a nowrap row with a label, a select and three buttons, so before this it forced the
|
| 160 |
+
row far past the viewport with the browser's own overflow rules deciding what got clipped. */
|
| 161 |
+
.auto-detail > .w45-workflow-bar {
|
| 162 |
+
flex: 0 0 auto;
|
| 163 |
+
flex-wrap: wrap;
|
| 164 |
+
row-gap: 8px;
|
| 165 |
+
padding: 8px 16px;
|
| 166 |
+
background: var(--lp-surface);
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
.auto-detail > .w45-workflow-bar > label {
|
| 170 |
+
color: var(--lp-muted);
|
| 171 |
+
font-weight: 600;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
/* Native chrome reset, DESIGN.md Β§4: both selects shipped with the browser's own border,
|
| 175 |
+
background and font, which is a visible part of what "mangled" describes. `.w45-quiet` already
|
| 176 |
+
resets its buttons correctly and is left alone. */
|
| 177 |
+
.auto-detail > .w45-workflow-bar select {
|
| 178 |
+
border: 1px solid var(--lp-line);
|
| 179 |
+
background: var(--lp-surface);
|
| 180 |
+
font: inherit;
|
| 181 |
+
color: inherit;
|
| 182 |
+
padding: 4px 8px;
|
| 183 |
+
border-radius: var(--lp-r-sm);
|
| 184 |
+
max-width: 18rem;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.auto-detail > .w45-workflow-bar select:focus-visible {
|
| 188 |
+
outline: 2px solid var(--lp-blue-deep);
|
| 189 |
+
outline-offset: 1px;
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
/* The capabilities fieldset takes a row of its own once the strip wraps.
|
| 193 |
+
β THE CAP IS NOT COSMETIC. At 1024x768 the whole work area below this strip is 640px tall, and
|
| 194 |
+
the grant matrix grows with the chosen database's field count, so an uncapped fieldset pushes
|
| 195 |
+
the builder off the screen on a wide table. It scrolls inside itself instead. */
|
| 196 |
+
.auto-detail > .w45-workflow-bar > .w45-governance {
|
| 197 |
+
flex: 1 1 100%;
|
| 198 |
+
margin-top: 0;
|
| 199 |
+
max-height: 34vh;
|
| 200 |
+
overflow-y: auto;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
/* The fieldset and its legend are the last two pieces of unreset native chrome in the strip. */
|
| 204 |
+
.auto-detail > .w45-workflow-bar > .w45-governance > legend {
|
| 205 |
+
border: 0;
|
| 206 |
+
background: transparent;
|
| 207 |
+
font: inherit;
|
| 208 |
+
font-weight: 600;
|
| 209 |
+
color: var(--lp-muted);
|
| 210 |
+
padding: 0 4px;
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
.auto-detail > .w45-workflow-bar > .w45-governance select {
|
| 214 |
+
border: 1px solid var(--lp-line);
|
| 215 |
+
background: var(--lp-surface);
|
| 216 |
+
font: inherit;
|
| 217 |
+
color: inherit;
|
| 218 |
+
padding: 3px 6px;
|
| 219 |
+
border-radius: var(--lp-r-sm);
|
| 220 |
+
margin-left: 6px;
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
/* ββ the detail header: it wraps rather than overlapping ββββββββββββββββββββββββββββββββββββ
|
| 224 |
+
β THE WORKFLOWS BUTTON WAS UNCLICKABLE AT 1024x768, which is a dead control and not a
|
| 225 |
+
cosmetic complaint. `.auto-head` is `space-between` with `.auto-head-actions` at `flex: 0 0
|
| 226 |
+
auto`, while `.auto-head-title` carries `min-width: 0`; the title was therefore allotted less
|
| 227 |
+
width than the view toggle draws, the toggle overflowed its box, and the save receipt
|
| 228 |
+
("All changes saved") landed on top of the Workflows button on the same 92-120px band.
|
| 229 |
+
Playwright refused the click there, naming the receipt as the interceptor.
|
| 230 |
+
β THE HEADER ALREADY EXPECTS TO WRAP - `.auto-head-actions` is `flex-wrap: wrap` and
|
| 231 |
+
`verify_automation_ui` carries a check about the receipt and Run now staying together "when the
|
| 232 |
+
detail header wraps" - so this lets the header itself wrap instead of inventing a breakpoint,
|
| 233 |
+
and stops the title being allotted less than it draws. `.auto-head`'s `min-height` lets the band
|
| 234 |
+
grow; no height is fixed anywhere, so nothing below it is clipped. */
|
| 235 |
+
.auto-detail > .auto-head {
|
| 236 |
+
flex-wrap: wrap;
|
| 237 |
+
row-gap: 6px;
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
.auto-detail > .auto-head > .auto-head-title {
|
| 241 |
+
flex: 0 0 auto;
|
| 242 |
+
min-width: auto;
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
/* β THE ACTION ROW MAY SHRINK ONCE IT HAS ITS OWN LINE, and it must: at 1024 the receipt plus
|
| 246 |
+
Run now plus Save plus Delete is 329px against a 416px band, and a wrapped second line that
|
| 247 |
+
still refuses to shrink would simply move the clipping down a row instead of removing it.
|
| 248 |
+
β `margin-left: auto` IS NOT DECORATION EITHER. `justify-content` on `.auto-head` resolves
|
| 249 |
+
PER FLEX LINE, so once the header wraps, line two holds only this row and `space-between` puts
|
| 250 |
+
it at main-START, left-aligned under the toggle. An auto margin resolves per line and keeps it
|
| 251 |
+
on the right where it is on one line, so wrapping changes the number of rows and nothing else.
|
| 252 |
+
The `justify-content` above governs this row's OWN children and is a different question. */
|
| 253 |
+
.auto-detail > .auto-head > .auto-head-actions {
|
| 254 |
+
flex: 0 1 auto;
|
| 255 |
+
min-width: 0;
|
| 256 |
+
justify-content: flex-end;
|
| 257 |
+
margin-left: auto;
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
/* ββ end W46-T46 ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ */
|