Deploy AIOS web (React glide grid + FastAPI slice)
Browse files- RELEASES.json +1 -1
- VERSION +1 -1
- api/automation_engine.py +0 -0
- api/connectors_ig.py +0 -0
- api/main.py +35 -0
- api/odoo_relational.py +339 -0
- api/routes_automation.py +18 -0
- api/routes_keychain.py +24 -6
- api/routes_nav.py +94 -13
- api/routes_odoo_tables.py +80 -0
- api/routes_tables.py +91 -31
- platform/aios_grid.py +183 -4
- platform/core/grid_events.py +0 -0
- platform/core/table_store.py +31 -0
- platform/core/user_tables.py +56 -1
- web/src/alerts/AlertsPane.tsx +35 -2
- web/src/alerts/alertsModel.ts +25 -0
- web/src/automation/AutomationBuilder.tsx +0 -0
- web/src/automation/AutomationDetail.tsx +140 -43
- web/src/automation/AutomationFind.tsx +893 -763
- web/src/automation/automationApi.ts +24 -8
- web/src/automation/steps.ts +422 -359
- web/src/customer-grid/ColumnMenu.tsx +0 -0
- web/src/customer-grid/CustomerGrid.tsx +0 -0
- web/src/customer-grid/JsonViewer.tsx +1015 -481
- web/src/customer-grid/RecordDetail.tsx +216 -21
- web/src/customer-grid/SwipeView.tsx +476 -0
- web/src/customer-grid/ViewSidebar.tsx +0 -0
- web/src/customer-grid/cells.ts +744 -724
- web/src/customer-grid/display.ts +28 -0
- web/src/customer-grid/filterSeed.ts +152 -0
- web/src/customer-grid/folders.ts +50 -0
- web/src/customer-grid/iconShapes.ts +53 -0
- web/src/customer-grid/timeSeriesData.ts +44 -1
- web/src/customer-grid/types.ts +180 -46
- web/src/index.css +543 -39
- web/src/settings/permsModel.ts +5 -0
- web/src/shell/Shell.tsx +215 -95
- web/src/shell/nav.ts +26 -0
- web/src/viz/seriesData.ts +7 -0
- web/src/viz/types.ts +9 -1
RELEASES.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
{
|
| 2 |
-
"current": "
|
| 3 |
"releases": [
|
| 4 |
{
|
| 5 |
"version": "v14",
|
|
|
|
| 1 |
{
|
| 2 |
+
"current": "v14 (bee5eaf)",
|
| 3 |
"releases": [
|
| 4 |
{
|
| 5 |
"version": "v14",
|
VERSION
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
v14 (bee5eaf)
|
api/automation_engine.py
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
api/connectors_ig.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
api/main.py
CHANGED
|
@@ -74,6 +74,7 @@ import routes_tables # noqa: E402 (wave 18 C3-UT β user-created databases ov
|
|
| 74 |
import routes_connectors # noqa: E402 (wave 23 C11 β the connectors directory; SESSION A's router)
|
| 75 |
import routes_forms # noqa: E402 (wave 23 C9 β the PUBLIC form door; SESSION D's router)
|
| 76 |
import routes_templates # noqa: E402 (wave 23 C12 β template apply doors; SESSION E's router)
|
|
|
|
| 77 |
from core import grid_events # noqa: E402
|
| 78 |
from deps import Session, module_gate # noqa: E402
|
| 79 |
|
|
@@ -223,6 +224,11 @@ app.include_router(routes_connectors.router) # item 10 / C11 β the connectors
|
|
| 223 |
# by scanning tenants with a constant-time compare and answers a uniform 403, so a bad token cannot
|
| 224 |
# distinguish "no such form" from "not yours", and it never echoes a tenant, table or slug.
|
| 225 |
app.include_router(routes_forms.router) # item 8 / C9 β the PUBLIC form door
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
|
| 227 |
|
| 228 |
# --- DEPRECATED ALIASES (removed when S2's shell flips; kept so the current bundle keeps working)
|
|
@@ -396,6 +402,35 @@ def _store_resync_loop():
|
|
| 396 |
_ds.reconcile_deletes(log=lambda *a, **k: None)
|
| 397 |
except Exception as e: # noqa: BLE001
|
| 398 |
print(f"[aios-api] store resync failed: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 399 |
|
| 400 |
|
| 401 |
def _prewarm():
|
|
|
|
| 74 |
import routes_connectors # noqa: E402 (wave 23 C11 β the connectors directory; SESSION A's router)
|
| 75 |
import routes_forms # noqa: E402 (wave 23 C9 β the PUBLIC form door; SESSION D's router)
|
| 76 |
import routes_templates # noqa: E402 (wave 23 C12 β template apply doors; SESSION E's router)
|
| 77 |
+
import routes_odoo_tables # noqa: E402 (wave 27 item 17 β Odoo relational; SESSION E's router)
|
| 78 |
from core import grid_events # noqa: E402
|
| 79 |
from deps import Session, module_gate # noqa: E402
|
| 80 |
|
|
|
|
| 224 |
# by scanning tenants with a constant-time compare and answers a uniform 403, so a bad token cannot
|
| 225 |
# distinguish "no such form" from "not yours", and it never echoes a tenant, table or slug.
|
| 226 |
app.include_router(routes_forms.router) # item 8 / C9 β the PUBLIC form door
|
| 227 |
+
# WAVE 27 item 17 β E's Odoo relational doors. Mounted in the SAME change that E's module landed,
|
| 228 |
+
# because the wave-23 scar is exactly this: three finished routers shipped with no include_router
|
| 229 |
+
# line β complete, gated, type-clean and 404 for every caller. `verify_api.section_mounts` walks
|
| 230 |
+
# `main.app.routes` and pins these two paths by NAME, so an unmounted router now goes RED.
|
| 231 |
+
app.include_router(routes_odoo_tables.router)
|
| 232 |
|
| 233 |
|
| 234 |
# --- DEPRECATED ALIASES (removed when S2's shell flips; kept so the current bundle keeps working)
|
|
|
|
| 402 |
_ds.reconcile_deletes(log=lambda *a, **k: None)
|
| 403 |
except Exception as e: # noqa: BLE001
|
| 404 |
print(f"[aios-api] store resync failed: {e}")
|
| 405 |
+
# β WAVE 27 item 17 (E's ASK ->A, resolved): the Odoo RELATIONAL tables are rebuilt
|
| 406 |
+
# AFTER the mirror they are derived from, in the same pass and in that order β deriving
|
| 407 |
+
# from a mirror this loop is about to advance would publish a worklist one cycle stale
|
| 408 |
+
# every single time.
|
| 409 |
+
#
|
| 410 |
+
# β ITS OWN try/except, NOT the one above. Folding it in would mean a failing relational
|
| 411 |
+
# rebuild swallowed the sync's error message, and worse: a sync failure would skip a
|
| 412 |
+
# rebuild that had nothing wrong with it. Two independent failures, two independent logs.
|
| 413 |
+
#
|
| 414 |
+
# β THE REBUILD IS NOT THE FRESHNESS GUARANTEE β the rows carry a visible `_refreshed`
|
| 415 |
+
# stamp for that. This loop is a daemon thread whose failure path is a `print` (D-29), so
|
| 416 |
+
# "the wiring exists" and "the data is current" are different claims and only the stamp
|
| 417 |
+
# can tell a user which one they are looking at.
|
| 418 |
+
# β SCOPED TO ROYAL-IMPORTS, and that is CORRECT here rather than the D-29 shortcut it
|
| 419 |
+
# resembles. `sync_all()` above advances whichever DuckDB file this process currently has
|
| 420 |
+
# open β tenant #0's β so royal's is the only mirror that just moved, and it is the only
|
| 421 |
+
# one these tables derive from (R1: the sole tenant with Odoo). Iterating tenants here
|
| 422 |
+
# would walk straight into D-29's documented hazard: `harness/datastore` is a
|
| 423 |
+
# ONE-FILE-AT-A-TIME process-global, and rebinding it in a daemon thread under live
|
| 424 |
+
# readers can serve one tenant's rows to another with nothing raised.
|
| 425 |
+
# `is_royal` stays the authority on which slugs qualify β this passes the slug and lets
|
| 426 |
+
# E's own guard refuse, rather than re-deciding the rule here.
|
| 427 |
+
try:
|
| 428 |
+
import odoo_relational as _rel
|
| 429 |
+
from harness import runtime as _runtime
|
| 430 |
+
if _rel.is_royal("royal-imports"):
|
| 431 |
+
_rel.refresh(_runtime.get_runtime("royal-imports"), "royal-imports")
|
| 432 |
+
except Exception as e: # noqa: BLE001
|
| 433 |
+
print(f"[aios-api] odoo relational rebuild failed: {e}")
|
| 434 |
|
| 435 |
|
| 436 |
def _prewarm():
|
api/odoo_relational.py
ADDED
|
@@ -0,0 +1,339 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""odoo_relational.py β Odoo entities as LOCKED relational databases (wave 27 item 17, PHASE 1).
|
| 2 |
+
|
| 3 |
+
Owner ruling R1 / contract C8: spawn preset Odoo databases for Royal Imports, give them preset
|
| 4 |
+
Link + Rollup fields, and prove each rollup against the `measure_` column it will eventually
|
| 5 |
+
replace. `measure_` columns are NOT touched this wave.
|
| 6 |
+
|
| 7 |
+
β WHAT C8 ASKED FOR AND WHY TWO THIRDS OF IT IS NOT HERE (AMENDMENT E1, measured 2026-08-08).
|
| 8 |
+
C8 named three tables β orders, order lines, invoices. `core.user_tables.MAX_ROWS` is **5000**, and
|
| 9 |
+
the Royal mirror holds **32,700** confirmed orders, **254,189** order lines and **31,418** posted
|
| 10 |
+
customer invoices. Order lines are **50.8x** the cap and still **3.3x** over it at a 90-day window,
|
| 11 |
+
so no window rescues that table. Every `ut_*` table also lives in ONE JSON blob under one store key
|
| 12 |
+
that is read whole per render, so this is not a limit to raise β 318k rows there is a different
|
| 13 |
+
store, not a bigger number. C8's other half (Link/Rollup fields hosted on the Customer/Product
|
| 14 |
+
grids) is dead twice over: `aios_grid.fields_from_workspace` emits no `link`/`rollup` bag for a
|
| 15 |
+
`custom_` field, and `compute_relation_cells` reads `ut_all(rt)` exclusively while those grids have
|
| 16 |
+
no stored rows at all. Phase 2 therefore needs a READ-THROUGH binding over the DuckDB store the
|
| 17 |
+
rows already live in β not a copy. That is booked as debt, not attempted here.
|
| 18 |
+
|
| 19 |
+
β SO WHAT SHIPS IS THE POPULATION THAT FITS *AND* IS COMPLETE FOR ITS QUESTION: every OPEN customer
|
| 20 |
+
receivable (**1,228 rows / 438 partners / $591,828.54**, measured), two locked databases joined by a
|
| 21 |
+
derived link,
|
| 22 |
+
carrying the rollups that answer "what does this customer owe". A slice that is complete for a
|
| 23 |
+
question is a feature; a truncated copy of a bigger table is a number that is quietly wrong, which
|
| 24 |
+
is the one thing this repo refuses everywhere else. **This module REFUSES rather than truncates.**
|
| 25 |
+
|
| 26 |
+
THE POPULATION IS THE AR ORACLE'S, NOT ONE OF ITS OWN. `modules/ar._open_docs` selects
|
| 27 |
+
`state='posted'` AND `move_type in (out_invoice,out_refund)` AND
|
| 28 |
+
`payment_state in (not_paid,partial)`, minus `core.odoo.excluded_partner_ids()` (the GIFTWARE /
|
| 29 |
+
Amazon channel, out of wholesale scope). This module uses THAT predicate β not an equivalent one.
|
| 30 |
+
β Measured 2026-08-08: `payment_state in (not_paid,partial)` and `residual <> 0` return the
|
| 31 |
+
identical 1,238 rows / $2,347,608.49 today. They still are not the same QUESTION, and copying the
|
| 32 |
+
oracle's definition is what keeps them from drifting apart later.
|
| 33 |
+
|
| 34 |
+
β β AND THE EXCLUSION IS NOT A ROUNDING DETAIL: **GIFTWARE DEALS alone carries $1,755,779.95 of the
|
| 35 |
+
$2,347,608.49 raw open balance β 75% of it β across just 10 invoices.** So wholesale open AR is
|
| 36 |
+
$591,828.54, and anyone comparing this table against a raw `account_move` sum will see a 4x gap and
|
| 37 |
+
reasonably conclude something is broken. It is the Amazon channel being out of wholesale scope,
|
| 38 |
+
exactly as `modules/ar` and the Customer grid already have it.
|
| 39 |
+
"""
|
| 40 |
+
import datetime as _dt
|
| 41 |
+
|
| 42 |
+
#: Royal Imports only (R1). A tenant slug that is not this one gets a refusal, never a spawn:
|
| 43 |
+
#: nurilab has no Odoo mirror behind these tables and would get two empty locked databases.
|
| 44 |
+
RI_SLUGS = ("", "royal-imports")
|
| 45 |
+
|
| 46 |
+
INVOICES_KEY = "ut_odoo_invoices"
|
| 47 |
+
CUSTOMERS_KEY = "ut_odoo_customers"
|
| 48 |
+
|
| 49 |
+
#: The join column both tables carry. The derived link resolves through it (`on`/`from`).
|
| 50 |
+
JOIN_KEY = "partner_id"
|
| 51 |
+
|
| 52 |
+
#: The oracle's own predicate β see the module docstring.
|
| 53 |
+
_AR_WHERE = ("state = 'posted' AND move_type IN ('out_invoice','out_refund') "
|
| 54 |
+
"AND payment_state IN ('not_paid','partial')")
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def _ut():
|
| 58 |
+
import core.user_tables as user_tables
|
| 59 |
+
return user_tables
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def _iso_today():
|
| 63 |
+
return _dt.date.today().strftime("%Y-%m-%d")
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def _preset(field, flow="odoo_relational"):
|
| 67 |
+
"""Stamp a field as machine-owned + preset β the `ut_ensure` lock_fields convention, so the
|
| 68 |
+
grid renders it grey and the preset walls refuse a rename or a delete."""
|
| 69 |
+
field = dict(field)
|
| 70 |
+
field["automation"] = {"flowId": flow, "preset": True}
|
| 71 |
+
return field
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
# ---------------------------------------------------------------------------------------------
|
| 75 |
+
# FIELD CONTRACTS
|
| 76 |
+
# ---------------------------------------------------------------------------------------------
|
| 77 |
+
# β Every type here must be in `core.user_tables.UT_FIELD_TYPES`, and `_clean_field` returns None
|
| 78 |
+
# for an unknown one β which DELETES the column silently on the next read rather than erroring.
|
| 79 |
+
def invoice_fields():
|
| 80 |
+
return [_preset(f) for f in (
|
| 81 |
+
{"key": "invoice_no", "label": "Invoice", "type": "text", "source": "overlay",
|
| 82 |
+
"default": True, "pinned": True},
|
| 83 |
+
{"key": "customer", "label": "Customer", "type": "text", "source": "overlay",
|
| 84 |
+
"default": True},
|
| 85 |
+
{"key": JOIN_KEY, "label": "Odoo partner id", "type": "int", "source": "overlay",
|
| 86 |
+
"default": False},
|
| 87 |
+
{"key": "invoice_date", "label": "Invoice date", "type": "date", "source": "overlay",
|
| 88 |
+
"default": True},
|
| 89 |
+
{"key": "due_date", "label": "Due date", "type": "date", "source": "overlay",
|
| 90 |
+
"default": True},
|
| 91 |
+
{"key": "residual", "label": "Outstanding $", "type": "currency", "source": "overlay",
|
| 92 |
+
"default": True, "agg": "sum"},
|
| 93 |
+
{"key": "amount_untaxed", "label": "Invoiced $", "type": "currency", "source": "overlay",
|
| 94 |
+
"default": False, "agg": "sum"},
|
| 95 |
+
{"key": "payment_state", "label": "Payment state", "type": "select", "source": "overlay",
|
| 96 |
+
"default": True, "options": ["not_paid", "partial"]},
|
| 97 |
+
{"key": "move_type", "label": "Document", "type": "select", "source": "overlay",
|
| 98 |
+
"default": False, "options": ["out_invoice", "out_refund"]},
|
| 99 |
+
{"key": "refreshed", "label": "Refreshed", "type": "date", "source": "overlay",
|
| 100 |
+
"default": False},
|
| 101 |
+
)]
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def customer_fields():
|
| 105 |
+
"""β The LINK is DERIVED (`on` declared), so the engine owns the cell and a human cannot edit
|
| 106 |
+
a relation that Odoo already decided. The three rollups are C8's parity targets that this
|
| 107 |
+
substrate can actually host; the other two (order count, fully-invoiced sales) have no table to
|
| 108 |
+
roll up β they are proven in `verify_odoo_relational.py` instead, against the same fold."""
|
| 109 |
+
return [_preset(f) for f in (
|
| 110 |
+
{"key": "customer", "label": "Customer", "type": "text", "source": "overlay",
|
| 111 |
+
"default": True, "pinned": True},
|
| 112 |
+
{"key": JOIN_KEY, "label": "Odoo partner id", "type": "int", "source": "overlay",
|
| 113 |
+
"default": False},
|
| 114 |
+
{"key": "invoices", "label": "Open invoices", "type": "link", "source": "overlay",
|
| 115 |
+
"default": True,
|
| 116 |
+
"link": {"table": INVOICES_KEY, "on": JOIN_KEY, "from": JOIN_KEY}},
|
| 117 |
+
{"key": "ar_outstanding", "label": "AR outstanding $", "type": "rollup",
|
| 118 |
+
"source": "overlay", "default": True, "agg": "sum",
|
| 119 |
+
"rollup": {"link": "invoices", "field": "residual", "fn": "sum"}},
|
| 120 |
+
{"key": "open_invoices", "label": "Open invoices #", "type": "rollup",
|
| 121 |
+
"source": "overlay", "default": True,
|
| 122 |
+
"rollup": {"link": "invoices", "fn": "countall"}},
|
| 123 |
+
# β NOT `min`. `_rollup_fold`'s min/max are NUMERIC folds (`_lane_num`), so `min` over a
|
| 124 |
+
# date column finds no numbers and returns BLANK β a column that renders empty forever
|
| 125 |
+
# while looking configured. Ranking a DATE is what `latest` + `sortBy` is for: sort the
|
| 126 |
+
# linked rows ascending by due date and take the first. Caught by this module's own gate.
|
| 127 |
+
{"key": "oldest_due", "label": "Oldest due date", "type": "rollup", "source": "overlay",
|
| 128 |
+
"default": True,
|
| 129 |
+
"rollup": {"link": "invoices", "field": "due_date", "fn": "latest",
|
| 130 |
+
"sortBy": "due_date", "sortDir": "asc"}},
|
| 131 |
+
{"key": "refreshed", "label": "Refreshed", "type": "date", "source": "overlay",
|
| 132 |
+
"default": False},
|
| 133 |
+
)]
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
# ---------------------------------------------------------------------------------------------
|
| 137 |
+
# READING THE MIRROR
|
| 138 |
+
# ---------------------------------------------------------------------------------------------
|
| 139 |
+
def excluded_names():
|
| 140 |
+
"""The partner names out of wholesale scope, from the ONE place that defines them.
|
| 141 |
+
|
| 142 |
+
Read through `core.odoo` rather than re-listed here: a second literal is a second scope, and
|
| 143 |
+
the day somebody adds a channel this module would keep answering the old question.
|
| 144 |
+
"""
|
| 145 |
+
try:
|
| 146 |
+
import core.odoo as odoo
|
| 147 |
+
names = getattr(odoo, "EXCLUDE_PARTNER_NAMES", None) or set()
|
| 148 |
+
return {str(n).strip().lower() for n in names if str(n).strip()}
|
| 149 |
+
except Exception: # noqa: BLE001
|
| 150 |
+
return set()
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
def read_open_ar(cur, excluded=None):
|
| 154 |
+
"""[(row dict)] β every open customer receivable in the mirror, oracle-scoped.
|
| 155 |
+
|
| 156 |
+
Takes a CURSOR so the gate can hand it a fixture connection; no global store binding here.
|
| 157 |
+
"""
|
| 158 |
+
excluded = excluded if excluded is not None else excluded_names()
|
| 159 |
+
sql = ("SELECT id, name, partner_id, partner_name, invoice_date, invoice_date_due, "
|
| 160 |
+
" amount_untaxed_signed, amount_residual_signed, payment_state, move_type "
|
| 161 |
+
f"FROM account_move WHERE {_AR_WHERE} AND partner_id IS NOT NULL")
|
| 162 |
+
out = []
|
| 163 |
+
for r in cur.execute(sql).fetchall():
|
| 164 |
+
(mid, name, pid, pname, inv_date, due, untaxed, residual, pay_state, mtype) = r
|
| 165 |
+
if str(pname or "").strip().lower() in excluded:
|
| 166 |
+
continue
|
| 167 |
+
out.append({
|
| 168 |
+
"_id": str(mid),
|
| 169 |
+
"invoice_no": str(name or ""),
|
| 170 |
+
"customer": str(pname or ""),
|
| 171 |
+
JOIN_KEY: int(pid),
|
| 172 |
+
"invoice_date": _as_date(inv_date),
|
| 173 |
+
"due_date": _as_date(due),
|
| 174 |
+
"residual": float(residual or 0.0),
|
| 175 |
+
"amount_untaxed": float(untaxed or 0.0),
|
| 176 |
+
"payment_state": str(pay_state or ""),
|
| 177 |
+
"move_type": str(mtype or ""),
|
| 178 |
+
})
|
| 179 |
+
return out
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
def _as_date(value):
|
| 183 |
+
"""ISO date string, or ''. The grid renders `date` cells itself (W26: `Aug 5, 2026`), so the
|
| 184 |
+
STORED value stays ISO β a formatted string in the cell is a value the filters cannot sort."""
|
| 185 |
+
if not value:
|
| 186 |
+
return ""
|
| 187 |
+
text = str(value)
|
| 188 |
+
return text[:10]
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
def customers_from(invoice_rows):
|
| 192 |
+
"""The partners carrying open AR β derived from the SAME rows the invoice table holds, never
|
| 193 |
+
from a second query. Two populations built by two queries drift the moment one is edited."""
|
| 194 |
+
out = {}
|
| 195 |
+
for row in invoice_rows:
|
| 196 |
+
pid = row[JOIN_KEY]
|
| 197 |
+
entry = out.setdefault(str(pid), {"_id": str(pid), "customer": row["customer"],
|
| 198 |
+
JOIN_KEY: pid})
|
| 199 |
+
# A partner's name can differ across documents (renames land on new invoices only);
|
| 200 |
+
# the newest non-empty one wins so the locked table shows what Odoo shows today.
|
| 201 |
+
if row["customer"]:
|
| 202 |
+
entry["customer"] = row["customer"]
|
| 203 |
+
return list(out.values())
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
# ---------------------------------------------------------------------------------------------
|
| 207 |
+
# THE SPAWN
|
| 208 |
+
# ---------------------------------------------------------------------------------------------
|
| 209 |
+
class Refused(Exception):
|
| 210 |
+
"""A refusal a caller should SHOW, not swallow. Every raise names what would otherwise have
|
| 211 |
+
been written wrong."""
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
def plan(cur, rt=None):
|
| 215 |
+
"""The rows that WOULD be written, plus the refusals that apply β no store WRITE at all.
|
| 216 |
+
|
| 217 |
+
Separated from `apply_plan` so a route, a gate and a dry run all measure the same thing, and
|
| 218 |
+
so **every cap is checked before anything is committed**.
|
| 219 |
+
|
| 220 |
+
β `rt` IS WHAT MAKES THE TABLE-COUNT CHECK HONEST, and leaving it out was a real half-spawn
|
| 221 |
+
bug. This spawn writes TWO tables in two updater passes; a tenant one slot short of
|
| 222 |
+
`MAX_TABLES` would create `ut_odoo_invoices`, then refuse `ut_odoo_customers` β leaving a
|
| 223 |
+
locked invoices database with no rollup host, while the route answered 409 as though nothing
|
| 224 |
+
had happened. A partial spawn is worse than a refused one, so the count is checked against the
|
| 225 |
+
tables that ALREADY exist, before the first write.
|
| 226 |
+
"""
|
| 227 |
+
ut = _ut()
|
| 228 |
+
invoices = read_open_ar(cur)
|
| 229 |
+
customers = customers_from(invoices)
|
| 230 |
+
problems = []
|
| 231 |
+
if rt is not None:
|
| 232 |
+
try:
|
| 233 |
+
existing = dict(rt.get(ut.STORE_KEY) or {})
|
| 234 |
+
except Exception: # noqa: BLE001
|
| 235 |
+
existing = {}
|
| 236 |
+
needed = [k for k in (INVOICES_KEY, CUSTOMERS_KEY) if k not in existing]
|
| 237 |
+
if needed and len(existing) + len(needed) > ut.MAX_TABLES:
|
| 238 |
+
problems.append(
|
| 239 |
+
f"tenant holds {len(existing)} of MAX_TABLES={ut.MAX_TABLES} user tables and "
|
| 240 |
+
f"needs {len(needed)} more ({', '.join(needed)}); refusing rather than creating "
|
| 241 |
+
f"one half of a linked pair")
|
| 242 |
+
# β REFUSE, NEVER TRUNCATE. A capped AR table understates what customers owe while looking
|
| 243 |
+
# exactly like a complete one -- the failure mode this whole module is arranged against.
|
| 244 |
+
for key, rows in ((INVOICES_KEY, invoices), (CUSTOMERS_KEY, customers)):
|
| 245 |
+
if len(rows) > ut.MAX_ROWS:
|
| 246 |
+
problems.append(f"{key}: {len(rows)} rows exceeds MAX_ROWS={ut.MAX_ROWS}; refusing "
|
| 247 |
+
f"(a truncated receivables table understates the balance)")
|
| 248 |
+
return {"invoices": invoices, "customers": customers, "problems": problems}
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
def apply_plan(rt, built, username="automation", today=None):
|
| 252 |
+
"""Create-or-merge both tables and their rows. Idempotent by construction.
|
| 253 |
+
|
| 254 |
+
Row ids ARE the Odoo ids, so a re-run updates in place and never appends a second copy of the
|
| 255 |
+
same invoice. Rows that left the population (paid since the last run) are REMOVED β an AR
|
| 256 |
+
worklist that keeps settled invoices is worse than a stale one, because every total it feeds
|
| 257 |
+
is then too high.
|
| 258 |
+
"""
|
| 259 |
+
if built.get("problems"):
|
| 260 |
+
raise Refused("; ".join(built["problems"]))
|
| 261 |
+
stamp = today or _iso_today()
|
| 262 |
+
written = {}
|
| 263 |
+
for key, label, fields, rows in (
|
| 264 |
+
(INVOICES_KEY, "Odoo open invoices", invoice_fields(), built["invoices"]),
|
| 265 |
+
(CUSTOMERS_KEY, "Odoo AR customers", customer_fields(), built["customers"])):
|
| 266 |
+
written[key] = _ensure_table(rt, key, label, fields, rows, username, stamp)
|
| 267 |
+
return written
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
def _ensure_table(rt, key, label, fields, rows, username, stamp):
|
| 271 |
+
"""One table: definition merged, rows reconciled, written only when something changed."""
|
| 272 |
+
ut = _ut()
|
| 273 |
+
wanted = {r["_id"]: {k: v for k, v in r.items() if k != "_id"} for r in rows}
|
| 274 |
+
for row in wanted.values():
|
| 275 |
+
row["refreshed"] = stamp
|
| 276 |
+
counts = {"added": 0, "updated": 0, "removed": 0, "rows": len(wanted)}
|
| 277 |
+
|
| 278 |
+
def _up(cur):
|
| 279 |
+
cur = cur if isinstance(cur, dict) else {}
|
| 280 |
+
table = cur.get(key)
|
| 281 |
+
if table is None:
|
| 282 |
+
if len(cur) >= ut.MAX_TABLES:
|
| 283 |
+
# β `ut_ensure` returns silently at this cap; a silent no-op here would report a
|
| 284 |
+
# successful refresh over a table that does not exist.
|
| 285 |
+
raise Refused(f"{key}: tenant is at MAX_TABLES={ut.MAX_TABLES}; nothing created")
|
| 286 |
+
table = cur[key] = {
|
| 287 |
+
"key": key, "label": label, "source": ut.AUTOMATION_SOURCE,
|
| 288 |
+
"createdBy": username, "created": stamp, "fields": [], "rows": {},
|
| 289 |
+
# recordMode = a LOCKED database (item-3 nomenclature): no human may add or
|
| 290 |
+
# delete records, while fields stay addable. Odoo owns this population.
|
| 291 |
+
"recordMode": ut.AUTOMATION_RECORD_MODE,
|
| 292 |
+
}
|
| 293 |
+
table.setdefault("recordMode", ut.AUTOMATION_RECORD_MODE)
|
| 294 |
+
have = {str(f.get("key")) for f in (table.get("fields") or [])}
|
| 295 |
+
for field in fields:
|
| 296 |
+
if str(field.get("key")) not in have:
|
| 297 |
+
table.setdefault("fields", []).append(dict(field))
|
| 298 |
+
stored = table.setdefault("rows", {})
|
| 299 |
+
for rid, values in wanted.items():
|
| 300 |
+
current = stored.get(rid)
|
| 301 |
+
if current is None:
|
| 302 |
+
stored[rid] = dict(values)
|
| 303 |
+
counts["added"] += 1
|
| 304 |
+
elif any(str(current.get(k, "")) != str(v) for k, v in values.items()
|
| 305 |
+
if k != "refreshed"):
|
| 306 |
+
current.update(values)
|
| 307 |
+
counts["updated"] += 1
|
| 308 |
+
else:
|
| 309 |
+
current["refreshed"] = values["refreshed"]
|
| 310 |
+
for rid in [r for r in stored if r not in wanted]:
|
| 311 |
+
stored.pop(rid, None)
|
| 312 |
+
counts["removed"] += 1
|
| 313 |
+
return cur
|
| 314 |
+
|
| 315 |
+
rt.update(ut.STORE_KEY, _up, flush="sync")
|
| 316 |
+
return counts
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
def is_royal(tenant):
|
| 320 |
+
return str(tenant or "").strip().lower() in RI_SLUGS
|
| 321 |
+
|
| 322 |
+
|
| 323 |
+
def refresh(rt, tenant, username="automation", cur=None, today=None):
|
| 324 |
+
"""THE entry point β the store-resync path and the route both call this.
|
| 325 |
+
|
| 326 |
+
β It must be CALLED on resync by something outside this file (see the ASK to session A). If it
|
| 327 |
+
is not wired, every row still carries a `refreshed` stamp, so a stale worklist is at least
|
| 328 |
+
LEGIBLE rather than silently authoritative.
|
| 329 |
+
"""
|
| 330 |
+
if not is_royal(tenant):
|
| 331 |
+
raise Refused(f"tenant {tenant!r} has no Odoo mirror behind these tables (R1: Royal "
|
| 332 |
+
f"Imports only); refusing to spawn two empty locked databases")
|
| 333 |
+
if cur is None:
|
| 334 |
+
from harness import datastore
|
| 335 |
+
cur = datastore.ro_con()
|
| 336 |
+
built = plan(cur, rt=rt)
|
| 337 |
+
written = apply_plan(rt, built, username=username, today=today)
|
| 338 |
+
return {"tables": written,
|
| 339 |
+
"invoices": len(built["invoices"]), "customers": len(built["customers"])}
|
api/routes_automation.py
CHANGED
|
@@ -56,6 +56,24 @@ def _wire(defn, tenant):
|
|
| 56 |
"created": defn.get("created"), "createdBy": defn.get("createdBy"),
|
| 57 |
"nextRunAt": nxt.strftime("%Y-%m-%d %H:%M") if nxt else "",
|
| 58 |
"running": bool(live),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
# C3 (wave 22): the trigger config rides whole β the webhook token included, because
|
| 60 |
# the person configuring the external caller has to be shown the URL somewhere, and
|
| 61 |
# this payload is session-gated behind the same wall as everything else here.
|
|
|
|
| 56 |
"created": defn.get("created"), "createdBy": defn.get("createdBy"),
|
| 57 |
"nextRunAt": nxt.strftime("%Y-%m-%d %H:%M") if nxt else "",
|
| 58 |
"running": bool(live),
|
| 59 |
+
# β WAVE 27 (contract C6) β DEBT D-70: "a paid search is already outstanding at the
|
| 60 |
+
# vendor". THE MONEY GUARD, and it was INERT for a whole wave because this line was
|
| 61 |
+
# missing: the client declared `awaitingResults` REQUIRED and read it in `runBlock()`,
|
| 62 |
+
# nothing ever sent it, so `undefined` was falsy and the Run button stayed armed.
|
| 63 |
+
#
|
| 64 |
+
# β WHY IT IS NOT `running`. `running` above is PROCESS state (`engine.running`) and is
|
| 65 |
+
# FALSE for the entire 20β30 MINUTE vendor wait, which IS the hazard window: the ticks
|
| 66 |
+
# are 3 minutes apart, so between them the automation is idle and the button re-arms.
|
| 67 |
+
# MEASURED the expensive way on 2026-08-06 (~$0.025): with no snapshot outstanding a
|
| 68 |
+
# Run-now press returned 200 and started a BRAND-NEW billable corpus search.
|
| 69 |
+
#
|
| 70 |
+
# β AND NOT A PERSISTED "running" FLAG EITHER β the engine header forbids one (it
|
| 71 |
+
# outlives the process and locks the automation forever). `state.pendingSnapshot` is the
|
| 72 |
+
# field that already exists, is already persisted, is already carried untouched through
|
| 73 |
+
# `clean_definition`, and is the SAME expression `pending_collect_ids()` uses to decide
|
| 74 |
+
# what to collect. One truth, two readers.
|
| 75 |
+
"awaitingResults": bool(str((defn.get("state") or {}).get("pendingSnapshot")
|
| 76 |
+
or "").strip()),
|
| 77 |
# C3 (wave 22): the trigger config rides whole β the webhook token included, because
|
| 78 |
# the person configuring the external caller has to be shown the URL somewhere, and
|
| 79 |
# this payload is session-gated behind the same wall as everything else here.
|
api/routes_keychain.py
CHANGED
|
@@ -222,13 +222,31 @@ def connectors(session: Session = Depends(admin_gate)):
|
|
| 222 |
# different answers (a persisted snapshot, an in-process cache, a frozen mirror), and
|
| 223 |
# collapsing them into "everything freezes" would be the kind of tidy summary that
|
| 224 |
# stops being true the first time one of them changes.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
"pausedNote": ("Pausing a connector never deletes data β notes, custom fields and "
|
| 226 |
-
"views stay, and nothing reaches the source while it is paused.
|
| 227 |
-
"
|
| 228 |
-
"serves
|
| 229 |
-
"
|
| 230 |
-
"
|
| 231 |
-
"
|
|
|
|
|
|
|
| 232 |
if session.tenant == "royal-imports":
|
| 233 |
out["unsynced"] = _unsynced_customer_records(session)
|
| 234 |
return out
|
|
|
|
| 222 |
# different answers (a persisted snapshot, an in-process cache, a frozen mirror), and
|
| 223 |
# collapsing them into "everything freezes" would be the kind of tidy summary that
|
| 224 |
# stops being true the first time one of them changes.
|
| 225 |
+
# β D-62 CLOSED (wave 27) β AND THE REGISTER'S DIAGNOSIS OF IT WAS WRONG, so the
|
| 226 |
+
# correction is recorded here rather than silently applied. D-62 said this note
|
| 227 |
+
# "promises a behaviour on a dashboard measure path that has been dead since W16".
|
| 228 |
+
# MEASURED 2026-08-08, and it is not: measure COLUMNS are grid columns answered from
|
| 229 |
+
# the DuckDB mirror, and `harness/datastore.py` genuinely refuses to sync while
|
| 230 |
+
# paused (`source_paused()` at four sites), so that clause was TRUE. The dead path is
|
| 231 |
+
# `/api/v1/pages/{key}` (D-52), which this note never mentioned.
|
| 232 |
+
#
|
| 233 |
+
# β THE REAL DEFECT WAS THE OPPOSITE ONE, and it was the last sentence: "so figures
|
| 234 |
+
# stop moving rather than going blank". BOTH pool paths answer **503** when they have
|
| 235 |
+
# no copy to serve β the customer path for a scope with no snapshot
|
| 236 |
+
# (`routes_customers.py:88`) and the product path ALWAYS after a restart, because
|
| 237 |
+
# there is no product snapshot bucket at all (`routes_products.py:60-73`, which says
|
| 238 |
+
# so in as many words). So a paused connector plus a restarted server is exactly the
|
| 239 |
+
# blank screen this sentence promised could not happen. A warning that over-promises
|
| 240 |
+
# is worse than none: it is the sentence somebody quotes when the screen disagrees.
|
| 241 |
"pausedNote": ("Pausing a connector never deletes data β notes, custom fields and "
|
| 242 |
+
"views stay, and nothing reaches the source while it is paused. "
|
| 243 |
+
"Anything this server has already read keeps showing: the customer "
|
| 244 |
+
"workspace serves its pause-time snapshot, the product list serves "
|
| 245 |
+
"the last copy read since startup, and measure columns keep answering "
|
| 246 |
+
"from the mirror as it stood when you paused. What has NOT been read "
|
| 247 |
+
"cannot be shown β a scope with no snapshot, or the product list after "
|
| 248 |
+
"a restart, reports that the source is paused instead of showing "
|
| 249 |
+
"figures. Resume to start reading live again.")}
|
| 250 |
if session.tenant == "royal-imports":
|
| 251 |
out["unsynced"] = _unsynced_customer_records(session)
|
| 252 |
return out
|
api/routes_nav.py
CHANGED
|
@@ -80,12 +80,19 @@ def _now() -> int:
|
|
| 80 |
return int(time.time())
|
| 81 |
|
| 82 |
|
| 83 |
-
def _clean_nav_prefs(raw, page_keys):
|
| 84 |
"""Validated wholesale replacement, the `clean_folders` posture: prune, never invent.
|
| 85 |
|
| 86 |
`page_keys` is the set of TOP-LEVEL keys this session may see; a placement of an unknown
|
| 87 |
or invisible key is dropped (it can return when the grant does β placement is cosmetic,
|
| 88 |
so pruning is loss-free). Unknown folder refs drop the placement, not the folder.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
"""
|
| 90 |
raw = raw if isinstance(raw, dict) else {}
|
| 91 |
folders, seen = [], set()
|
|
@@ -104,15 +111,54 @@ def _clean_nav_prefs(raw, page_keys):
|
|
| 104 |
if isinstance(src, dict):
|
| 105 |
for k, v in src.items():
|
| 106 |
k, v = str(k)[:60], str(v)[:40]
|
| 107 |
-
if v
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
placement[k] = v
|
| 109 |
return {"folders": folders, "placement": placement}
|
| 110 |
|
| 111 |
|
| 112 |
-
def
|
| 113 |
-
"""
|
| 114 |
-
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
|
| 118 |
def _clean_icon(raw):
|
|
@@ -251,11 +297,17 @@ def nav(session: Session = Depends(require_session)):
|
|
| 251 |
# merging on the day that invariant changes.
|
| 252 |
meta = _read_nav_meta(session.runtime)
|
| 253 |
# Wave 21 (C3): the definitions, once β `manage`/`canDelete` below answer from `createdBy`.
|
|
|
|
| 254 |
try:
|
| 255 |
import core.user_tables as _ut_mod
|
| 256 |
_ut_defs = _ut_mod.all_tables(st=session.runtime) or {}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
except Exception:
|
| 258 |
_ut_defs = {}
|
|
|
|
| 259 |
for p in pages:
|
| 260 |
# `manage` (R14): may THIS session change this row's icon/name? Answered HERE because
|
| 261 |
# the server is the only end that knows β the client cannot see who created a user
|
|
@@ -274,6 +326,28 @@ def nav(session: Session = Depends(require_session)):
|
|
| 274 |
_mine = bool(session.admin or (_creator and _creator == session.uname))
|
| 275 |
p["manage"] = _mine
|
| 276 |
p["canDelete"] = _mine
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 277 |
elif session.admin:
|
| 278 |
p["manage"] = True
|
| 279 |
entry = meta.get(p.get("key")) if meta else None
|
|
@@ -290,11 +364,16 @@ def nav(session: Session = Depends(require_session)):
|
|
| 290 |
# for. A second round trip for a list this short, computed from a bucket this route is
|
| 291 |
# already holding the store open for, would be a request per page load for no gain.
|
| 292 |
#
|
| 293 |
-
# β `allowed` IS THE ASSEMBLED PAGE LIST
|
| 294 |
-
# `perms.nav_pages` alone
|
| 295 |
-
#
|
| 296 |
-
#
|
| 297 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 298 |
recents = _read_recents(session.runtime, session.uname,
|
| 299 |
{str(p.get("key", "")) for p in pages})
|
| 300 |
return {"pages": pages, "landing": landing, "recents": recents}
|
|
@@ -461,7 +540,8 @@ def nav_prefs(session: Session = Depends(require_session)):
|
|
| 461 |
stored = (session.runtime.get(_NAV_PREFS_KEY) or {}).get(session.uname) or {}
|
| 462 |
except Exception:
|
| 463 |
stored = {}
|
| 464 |
-
|
|
|
|
| 465 |
|
| 466 |
|
| 467 |
@router.post("/nav/prefs")
|
|
@@ -469,7 +549,8 @@ def save_nav_prefs(body: dict = Body(default=None),
|
|
| 469 |
session: Session = Depends(require_session)):
|
| 470 |
"""Wholesale replace, like the table folder stratum β the client sent its complete
|
| 471 |
picture, validated here; a partial merge would resurrect deleted folders forever."""
|
| 472 |
-
|
|
|
|
| 473 |
if not session.runtime.available():
|
| 474 |
raise err(503, "store_unavailable",
|
| 475 |
"the tenant store is unavailable β nothing was saved")
|
|
|
|
| 80 |
return int(time.time())
|
| 81 |
|
| 82 |
|
| 83 |
+
def _clean_nav_prefs(raw, page_keys, *, keep_unknown_ut=False):
|
| 84 |
"""Validated wholesale replacement, the `clean_folders` posture: prune, never invent.
|
| 85 |
|
| 86 |
`page_keys` is the set of TOP-LEVEL keys this session may see; a placement of an unknown
|
| 87 |
or invisible key is dropped (it can return when the grant does β placement is cosmetic,
|
| 88 |
so pruning is loss-free). Unknown folder refs drop the placement, not the folder.
|
| 89 |
+
|
| 90 |
+
`keep_unknown_ut` is the STORE-BLIP escape hatch β see `_placeable_top_keys`. When the
|
| 91 |
+
`ut_*` listing could not be read, a `ut_` key absent from `page_keys` is KEPT rather than
|
| 92 |
+
pruned: keeping a placement whose database may since have been deleted is cosmetically
|
| 93 |
+
harmless, while pruning a live one is the silent data loss this function just stopped
|
| 94 |
+
causing. Never widened to non-`ut_` keys β those come from the compiled registry, which
|
| 95 |
+
cannot fail to enumerate.
|
| 96 |
"""
|
| 97 |
raw = raw if isinstance(raw, dict) else {}
|
| 98 |
folders, seen = [], set()
|
|
|
|
| 111 |
if isinstance(src, dict):
|
| 112 |
for k, v in src.items():
|
| 113 |
k, v = str(k)[:60], str(v)[:40]
|
| 114 |
+
if v not in ids:
|
| 115 |
+
continue # the folder is gone; the placement goes with it
|
| 116 |
+
if page_keys is None or k in page_keys:
|
| 117 |
+
placement[k] = v
|
| 118 |
+
elif keep_unknown_ut and k.startswith("ut_"):
|
| 119 |
placement[k] = v
|
| 120 |
return {"folders": folders, "placement": placement}
|
| 121 |
|
| 122 |
|
| 123 |
+
def _placeable_top_keys(session):
|
| 124 |
+
"""`(keys, enumerated)` β the keys a placement may name, INCLUDING this tenant's databases.
|
| 125 |
+
|
| 126 |
+
β THIS IS THE ITEM-6 FIX (wave 27, contract C1), and the bug it closes was invisible by
|
| 127 |
+
construction. The old version read `perms.nav_pages` alone β the compiled REGISTRY β and
|
| 128 |
+
`perms.py` contains no `ut_` or `user_tables` reference at all, because a tenant's
|
| 129 |
+
user-created databases are merged into the nav payload by `nav()` BELOW the permission wall.
|
| 130 |
+
So every `ut_*` key was absent from this set, and `_clean_nav_prefs` pruned every placement
|
| 131 |
+
naming one β on READ and on WRITE.
|
| 132 |
+
|
| 133 |
+
The symptom was "a database I drag into a folder falls out of it later", never "it does not
|
| 134 |
+
work": the write answered **200 OK** having stored `{}`, the client kept its optimistic copy
|
| 135 |
+
(`Shell.commitPrefs` reverts only on `!ok`), and the folder held for the rest of the session.
|
| 136 |
+
The next reload served the pruned copy and the database was back at root. Built-in modules
|
| 137 |
+
(`customer_data`, `product_data`) ARE in the registry and persisted fine, which is exactly
|
| 138 |
+
why it read as intermittent rather than as a missing feature.
|
| 139 |
+
|
| 140 |
+
β THE SAME MISTAKE, ALREADY MADE AND ALREADY FIXED ONE FUNCTION AWAY. `nav()`'s recents
|
| 141 |
+
block (see its `allowed` comment) hit this in wave 23 and solved it by pruning against the
|
| 142 |
+
ASSEMBLED page list. This is that lesson applied to the second consumer, which the wave-23
|
| 143 |
+
fix did not reach.
|
| 144 |
+
|
| 145 |
+
`enumerated` is False when the `ut_` listing raised β the caller must then NOT treat this set
|
| 146 |
+
as authoritative for `ut_` keys (`keep_unknown_ut`). Pruning a person's whole arrangement
|
| 147 |
+
because the store blinked would be the original defect wearing a different cause.
|
| 148 |
+
"""
|
| 149 |
+
pages = perms.nav_pages(session.user) or []
|
| 150 |
+
keys = {p["key"] for p in pages if not p.get("parent")}
|
| 151 |
+
try:
|
| 152 |
+
import core.user_tables as user_tables
|
| 153 |
+
# The SAME listing `nav()` renders from β `may_open`-filtered, so a placement can never
|
| 154 |
+
# name a database this session cannot see, and the nav and this door agree by sharing
|
| 155 |
+
# one predicate rather than by two lists being kept in step.
|
| 156 |
+
for e in user_tables.nav_entries(viewer=session.uname, is_admin=session.admin,
|
| 157 |
+
st=session.runtime):
|
| 158 |
+
keys.add(str(e.get("key") or ""))
|
| 159 |
+
except Exception:
|
| 160 |
+
return keys, False
|
| 161 |
+
return keys, True
|
| 162 |
|
| 163 |
|
| 164 |
def _clean_icon(raw):
|
|
|
|
| 297 |
# merging on the day that invariant changes.
|
| 298 |
meta = _read_nav_meta(session.runtime)
|
| 299 |
# Wave 21 (C3): the definitions, once β `manage`/`canDelete` below answer from `createdBy`.
|
| 300 |
+
# WAVE 27 (C9): `locked` answers from `recordMode`, off the same one read.
|
| 301 |
try:
|
| 302 |
import core.user_tables as _ut_mod
|
| 303 |
_ut_defs = _ut_mod.all_tables(st=session.runtime) or {}
|
| 304 |
+
# β NEVER DEFAULT THIS TO `None`. `_ut_defs.get(k)` is `{}` for an unknown key, so its
|
| 305 |
+
# `.get("recordMode")` is None too οΏ½οΏ½οΏ½ and `None == None` would mark EVERY database locked
|
| 306 |
+
# the moment this import failed. A sentinel that can equal real data is not a sentinel.
|
| 307 |
+
_ut_locked_mode = str(_ut_mod.AUTOMATION_RECORD_MODE)
|
| 308 |
except Exception:
|
| 309 |
_ut_defs = {}
|
| 310 |
+
_ut_locked_mode = ""
|
| 311 |
for p in pages:
|
| 312 |
# `manage` (R14): may THIS session change this row's icon/name? Answered HERE because
|
| 313 |
# the server is the only end that knows β the client cannot see who created a user
|
|
|
|
| 326 |
_mine = bool(session.admin or (_creator and _creator == session.uname))
|
| 327 |
p["manage"] = _mine
|
| 328 |
p["canDelete"] = _mine
|
| 329 |
+
# β WAVE 27 item 3 (contract C9) β A LOCKED DATABASE SAYS SO IN THE RAIL.
|
| 330 |
+
#
|
| 331 |
+
# "Locked" is the owner's item-4 vocabulary and it means exactly ONE thing (DESIGN.md
|
| 332 |
+
# Β§4, THE THREE LOCKS): RECORDS cannot be added, deleted or edited β **fields still
|
| 333 |
+
# can**. The automation-owned IG child datasets (posts, comments, snapshots) are the
|
| 334 |
+
# live example; their rows arrive from the engine, so a "+" row there could only
|
| 335 |
+
# refuse, which R8 calls a fake affordance.
|
| 336 |
+
#
|
| 337 |
+
# β THE AUTHORITY IS `user_tables.records_mutable`, NOT THIS LINE. The comparison is
|
| 338 |
+
# inlined only because `_ut_defs` is already in hand β calling the predicate per row
|
| 339 |
+
# would be one store read per database on every nav request β and the VALUE comes
|
| 340 |
+
# from the module's own constant rather than a copied string, so the two cannot drift
|
| 341 |
+
# to different answers. If that predicate ever grows a second condition, this must
|
| 342 |
+
# become a call.
|
| 343 |
+
#
|
| 344 |
+
# β ABSENT READS AS UNLOCKED, and that is the safe direction here even though it is
|
| 345 |
+
# the opposite of `manage`'s fail-closed: the lock ICON is an affordance hint, while
|
| 346 |
+
# the actual refusal is `routes_tables._records_or_refuse`'s 403. A store blip costs
|
| 347 |
+
# a missing hint, never a write that should not have landed.
|
| 348 |
+
if (_ut_locked_mode
|
| 349 |
+
and (_ut_defs.get(key) or {}).get("recordMode") == _ut_locked_mode):
|
| 350 |
+
p["locked"] = True
|
| 351 |
elif session.admin:
|
| 352 |
p["manage"] = True
|
| 353 |
entry = meta.get(p.get("key")) if meta else None
|
|
|
|
| 364 |
# for. A second round trip for a list this short, computed from a bucket this route is
|
| 365 |
# already holding the store open for, would be a request per page load for no gain.
|
| 366 |
#
|
| 367 |
+
# β `allowed` IS THE ASSEMBLED PAGE LIST β the rows this route just built, `ut_*` databases
|
| 368 |
+
# included. Pruning against `perms.nav_pages` alone would silently drop every user database
|
| 369 |
+
# from Home's recents: the exact surface R7 is about, invisible, with every gate green.
|
| 370 |
+
#
|
| 371 |
+
# β WAVE 27 (item 6): the OTHER consumer of that narrower set β the folder-placement door β
|
| 372 |
+
# had the identical bug and nobody connected the two for four waves. It is fixed at the
|
| 373 |
+
# source now (`_placeable_top_keys`, which merges the same `may_open`-filtered listing), so
|
| 374 |
+
# both doors finally agree on what a placeable key is. This block keeps using the assembled
|
| 375 |
+
# list because it already holds it: re-enumerating here would be a second store read for an
|
| 376 |
+
# answer sitting in a local variable.
|
| 377 |
recents = _read_recents(session.runtime, session.uname,
|
| 378 |
{str(p.get("key", "")) for p in pages})
|
| 379 |
return {"pages": pages, "landing": landing, "recents": recents}
|
|
|
|
| 540 |
stored = (session.runtime.get(_NAV_PREFS_KEY) or {}).get(session.uname) or {}
|
| 541 |
except Exception:
|
| 542 |
stored = {}
|
| 543 |
+
keys, enumerated = _placeable_top_keys(session)
|
| 544 |
+
return {"prefs": _clean_nav_prefs(stored, keys, keep_unknown_ut=not enumerated)}
|
| 545 |
|
| 546 |
|
| 547 |
@router.post("/nav/prefs")
|
|
|
|
| 549 |
session: Session = Depends(require_session)):
|
| 550 |
"""Wholesale replace, like the table folder stratum β the client sent its complete
|
| 551 |
picture, validated here; a partial merge would resurrect deleted folders forever."""
|
| 552 |
+
keys, enumerated = _placeable_top_keys(session)
|
| 553 |
+
clean = _clean_nav_prefs(body or {}, keys, keep_unknown_ut=not enumerated)
|
| 554 |
if not session.runtime.available():
|
| 555 |
raise err(503, "store_unavailable",
|
| 556 |
"the tenant store is unavailable β nothing was saved")
|
api/routes_odoo_tables.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""routes_odoo_tables.py β the door to the Odoo relational spawn (wave 27 item 17, contract C8).
|
| 2 |
+
|
| 3 |
+
Two endpoints and no cleverness: refresh the locked Odoo databases, and report their freshness.
|
| 4 |
+
The work itself lives in `odoo_relational.py`; this file only decides WHO may ask and turns a
|
| 5 |
+
refusal into a status code.
|
| 6 |
+
|
| 7 |
+
β THIS ROUTER SHIPS DEAD UNTIL SESSION A ADDS ITS `include_router` LINE (wave-23 scar: three
|
| 8 |
+
finished routers shipped 404-dead behind entirely green gates, because a cross-fence wiring row can
|
| 9 |
+
only prove both files mention the same path SEGMENT). The pairing is a named checkpoint in the wave
|
| 10 |
+
doc, not an assumption -- and `verify_api` now enumerates `main.app.routes`, which is the control
|
| 11 |
+
that actually answers it.
|
| 12 |
+
|
| 13 |
+
ADMIN-GATED, and not for tidiness: a refresh REWRITES two locked databases for the whole tenant and
|
| 14 |
+
deletes the rows that left the population. That is an operator action.
|
| 15 |
+
"""
|
| 16 |
+
from fastapi import Depends
|
| 17 |
+
from fastapi import APIRouter
|
| 18 |
+
|
| 19 |
+
from deps import Session, err, require_session
|
| 20 |
+
|
| 21 |
+
router = APIRouter(prefix="/api/v1")
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def _rel():
|
| 25 |
+
import odoo_relational
|
| 26 |
+
return odoo_relational
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
@router.post("/odoo-tables/refresh")
|
| 30 |
+
def refresh_odoo_tables(session: Session = Depends(require_session)):
|
| 31 |
+
"""Rebuild `ut_odoo_invoices` + `ut_odoo_customers` from the tenant's Odoo mirror.
|
| 32 |
+
|
| 33 |
+
Idempotent: row ids are Odoo ids, so a re-run updates in place. Returns what MOVED, because
|
| 34 |
+
"refreshed" with no counts is indistinguishable from a no-op over an empty mirror.
|
| 35 |
+
"""
|
| 36 |
+
# β `deps.err()` RETURNS an HTTPException, it does not raise one β so it must be `raise
|
| 37 |
+
# err(...)`. `return err(...)` serialises the exception object with a **200**, which is the
|
| 38 |
+
# wave-23 shape exactly: a finished route, green everything, wrong on the wire. The house
|
| 39 |
+
# convention is 243 `raise err` against 6 strays; this file uses `raise`.
|
| 40 |
+
rel = _rel()
|
| 41 |
+
if not session.is_admin:
|
| 42 |
+
raise err(403, "forbidden", "Refreshing the Odoo databases is an admin action.")
|
| 43 |
+
if not rel.is_royal(session.tenant):
|
| 44 |
+
# A plain 400 with the reason: this tenant has no Odoo mirror, and spawning two empty
|
| 45 |
+
# locked databases it can never fill would be worse than refusing.
|
| 46 |
+
raise err(400, "not_applicable",
|
| 47 |
+
"These databases are built from the Royal Imports Odoo mirror (R1).")
|
| 48 |
+
try:
|
| 49 |
+
return {"ok": True, **rel.refresh(session.runtime, session.tenant,
|
| 50 |
+
username=session.user)}
|
| 51 |
+
except rel.Refused as e:
|
| 52 |
+
# A refusal is the ANSWER, not a crash: the caller must see WHY nothing was written.
|
| 53 |
+
raise err(409, "refused", str(e))
|
| 54 |
+
except RuntimeError as e:
|
| 55 |
+
# `datastore.ro_con()` raises this while the store is completing its first sync. Relaying
|
| 56 |
+
# it beats writing a partial table from a half-synced mirror.
|
| 57 |
+
raise err(503, "store_not_ready", str(e))
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
@router.get("/odoo-tables/status")
|
| 61 |
+
def odoo_tables_status(session: Session = Depends(require_session)):
|
| 62 |
+
"""Row counts + the newest `refreshed` stamp per table.
|
| 63 |
+
|
| 64 |
+
β The stamp is the whole point while the resync wiring is outstanding: a locked collections
|
| 65 |
+
worklist that quietly stopped updating is a worklist that lies, so its age must be readable
|
| 66 |
+
without anybody running a refresh to find out.
|
| 67 |
+
"""
|
| 68 |
+
rel, out = _rel(), {}
|
| 69 |
+
import core.user_tables as user_tables
|
| 70 |
+
for key in (rel.INVOICES_KEY, rel.CUSTOMERS_KEY):
|
| 71 |
+
table = user_tables.get(key, st=session.runtime) or {}
|
| 72 |
+
rows = (table.get("rows") or {})
|
| 73 |
+
stamps = [str((r or {}).get("refreshed") or "") for r in rows.values()]
|
| 74 |
+
out[key] = {
|
| 75 |
+
"exists": bool(table),
|
| 76 |
+
"rows": len(rows),
|
| 77 |
+
"refreshed": max([s for s in stamps if s], default=""),
|
| 78 |
+
"locked": table.get("recordMode") == user_tables.AUTOMATION_RECORD_MODE,
|
| 79 |
+
}
|
| 80 |
+
return {"ok": True, "applicable": rel.is_royal(session.tenant), "tables": out}
|
api/routes_tables.py
CHANGED
|
@@ -16,6 +16,7 @@ VISIBILITY is `user_tables.may_open` β creator or admin, fail-closed. There is
|
|
| 16 |
to check because a user table is not a module; the per-table wall is the whole wall, and it is
|
| 17 |
applied in `_defn_or_refuse` before any payload is built.
|
| 18 |
"""
|
|
|
|
| 19 |
import time
|
| 20 |
|
| 21 |
from fastapi import Body, Depends
|
|
@@ -36,15 +37,71 @@ def _ops(session, table_key):
|
|
| 36 |
return table_store.make(f"{table_key}_table_workspace", st=session.runtime)
|
| 37 |
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
def _refresh_relations(session):
|
| 40 |
-
"""
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
|
| 50 |
def _defn_or_refuse(session, table_key):
|
|
@@ -70,21 +127,31 @@ def _records_or_refuse(session, table_key):
|
|
| 70 |
return defn
|
| 71 |
|
| 72 |
|
| 73 |
-
#:
|
| 74 |
-
#:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
#:
|
| 76 |
-
#:
|
| 77 |
-
#:
|
| 78 |
-
#:
|
| 79 |
-
#: silent-disappearance defect one table wide instead of one table narrow.
|
| 80 |
#:
|
| 81 |
-
#:
|
| 82 |
-
#: written
|
| 83 |
-
#:
|
| 84 |
-
#:
|
| 85 |
-
#: owner's ask β "each user only works with their own data" β holds going forward without a
|
| 86 |
-
#: migration that guesses who found what.
|
| 87 |
-
PER_USER_TABLES = ("ut_ig_candidates",)
|
| 88 |
|
| 89 |
|
| 90 |
def scoped_pool(session: Session, table_key: str):
|
|
@@ -98,20 +165,13 @@ def scoped_pool(session: Session, table_key: str):
|
|
| 98 |
defn = _defn_or_refuse(session, table_key)
|
| 99 |
fields_base = [dict(f) for f in (defn.get("fields") or [])]
|
| 100 |
field_keys = {f["key"] for f in fields_base}
|
| 101 |
-
per_user = str(table_key) in PER_USER_TABLES and not session.admin
|
| 102 |
-
me = str(session.uname or "").strip().lower()
|
| 103 |
rows_src = []
|
| 104 |
for rid, row in (defn.get("rows") or {}).items():
|
| 105 |
if not str(rid).isdigit():
|
| 106 |
continue
|
| 107 |
-
#
|
| 108 |
-
#
|
| 109 |
-
#
|
| 110 |
-
# column, so filtering the projection would silently stop filtering anything.
|
| 111 |
-
if per_user:
|
| 112 |
-
owner = str((row or {}).get("created_by") or "").strip().lower()
|
| 113 |
-
if owner and owner != me:
|
| 114 |
-
continue
|
| 115 |
r = {k: v for k, v in (row or {}).items() if k in field_keys}
|
| 116 |
r["pid"] = int(rid)
|
| 117 |
rows_src.append(r)
|
|
|
|
| 16 |
to check because a user table is not a module; the per-table wall is the whole wall, and it is
|
| 17 |
applied in `_defn_or_refuse` before any payload is built.
|
| 18 |
"""
|
| 19 |
+
import threading
|
| 20 |
import time
|
| 21 |
|
| 22 |
from fastapi import Body, Depends
|
|
|
|
| 37 |
return table_store.make(f"{table_key}_table_workspace", st=session.runtime)
|
| 38 |
|
| 39 |
|
| 40 |
+
#: WAVE 27 item 2 (contract C2 / amendment A2) β the relation refresh is COALESCED and runs OFF
|
| 41 |
+
#: the request path. `{tenant: True}` while a pass is queued; the worker holds the lock.
|
| 42 |
+
_REL_LOCK = threading.Lock()
|
| 43 |
+
_REL_DIRTY = {}
|
| 44 |
+
_REL_RUNNING = {}
|
| 45 |
+
|
| 46 |
+
|
| 47 |
def _refresh_relations(session):
|
| 48 |
+
"""Mark this tenant's Links/Rollups stale and refresh them AFTER the response, once.
|
| 49 |
+
|
| 50 |
+
β WHY THIS IS NOT A DIRECT CALL ANY MORE, and the numbers are the argument. The owner's
|
| 51 |
+
item 2 was "adding a new record visually takes too long, I need to be able to spam it", and
|
| 52 |
+
this function was the largest single cost inside `POST /tables/{key}/rows`:
|
| 53 |
+
`engine.refresh_relations` DEEP-COPIES every table and every row in the tenant before it can
|
| 54 |
+
decide whether anything needs doing (`automation_engine.py:9383-9388`), and when something
|
| 55 |
+
does it commits with `flush="sync"` β a store round trip, i.e. an HF Dataset commit on the
|
| 56 |
+
default backend. Every added record paid a whole-tenant snapshot plus a synchronous commit
|
| 57 |
+
before the 201 came back.
|
| 58 |
+
|
| 59 |
+
β AND BACKGROUNDING ALONE WOULD HAVE BEEN A WORSE BUG. Twenty rapid adds would queue twenty
|
| 60 |
+
whole-tenant snapshots, each one re-reading a store the previous one just wrote β the spam
|
| 61 |
+
the item asks us to support is exactly the load that would melt it. So this COALESCES: at
|
| 62 |
+
most one pass runs, and at most one is queued behind it.
|
| 63 |
+
|
| 64 |
+
β THE DIRTY FLAG IS THE LOAD-BEARING PART, not the lock. A write landing WHILE a pass is in
|
| 65 |
+
flight must still get a pass afterwards, because the in-flight one snapshotted before that
|
| 66 |
+
write existed. Without the flag the LAST add in a burst is precisely the one whose rollups
|
| 67 |
+
never update β the failure nobody would notice until a total was quietly wrong.
|
| 68 |
+
|
| 69 |
+
Eventual consistency is the accepted trade and was already the documented posture: the tick
|
| 70 |
+
repairs materialised cells regardless, and answering 503 here would invite the browser to
|
| 71 |
+
repeat a mutation that already succeeded.
|
| 72 |
+
"""
|
| 73 |
+
tenant = str(getattr(session, "tenant", "") or "")
|
| 74 |
+
rt = session.runtime
|
| 75 |
+
with _REL_LOCK:
|
| 76 |
+
_REL_DIRTY[tenant] = True
|
| 77 |
+
if _REL_RUNNING.get(tenant):
|
| 78 |
+
return # a worker is live; it will see the flag and loop
|
| 79 |
+
_REL_RUNNING[tenant] = True
|
| 80 |
+
|
| 81 |
+
def _worker():
|
| 82 |
+
import automation_engine as engine
|
| 83 |
+
try:
|
| 84 |
+
while True:
|
| 85 |
+
with _REL_LOCK:
|
| 86 |
+
if not _REL_DIRTY.get(tenant):
|
| 87 |
+
_REL_RUNNING.pop(tenant, None)
|
| 88 |
+
return
|
| 89 |
+
_REL_DIRTY.pop(tenant, None)
|
| 90 |
+
try:
|
| 91 |
+
engine.refresh_relations(rt, log=lambda *_args: None)
|
| 92 |
+
except Exception as exc: # noqa: BLE001
|
| 93 |
+
# The source write already landed and the response is already sent. Log and
|
| 94 |
+
# let the tick repair it; never retry in a tight loop.
|
| 95 |
+
print(f"[tables] relation refresh deferred: {type(exc).__name__}: {exc}")
|
| 96 |
+
finally:
|
| 97 |
+
# Belt for an unexpected raise on the bookkeeping itself: a tenant left marked
|
| 98 |
+
# RUNNING would never refresh again for the life of the process.
|
| 99 |
+
with _REL_LOCK:
|
| 100 |
+
if _REL_RUNNING.get(tenant) and not _REL_DIRTY.get(tenant):
|
| 101 |
+
_REL_RUNNING.pop(tenant, None)
|
| 102 |
+
|
| 103 |
+
threading.Thread(target=_worker, daemon=True,
|
| 104 |
+
name=f"rel-refresh:{tenant or 'default'}").start()
|
| 105 |
|
| 106 |
|
| 107 |
def _defn_or_refuse(session, table_key):
|
|
|
|
| 127 |
return defn
|
| 128 |
|
| 129 |
|
| 130 |
+
#: β THE PER-USER CANDIDATE WALL IS RETIRED (WAVE 27, DEBT D-72). **THE TENANT IS THE UNIT, NOT
|
| 131 |
+
#: THE USER** β one profile is ONE row, and everyone who may open the database sees all of it.
|
| 132 |
+
#:
|
| 133 |
+
#: WHY IT HAD TO GO, and it is not a preference: wave 26's R4 made the candidate identity
|
| 134 |
+
#: `(platform, handle)` and `_merge_candidates` stamps only the FIRST finder, later finders never
|
| 135 |
+
#: overwriting. Combined with a wall that then showed a non-admin only `created_by == me`, the
|
| 136 |
+
#: two were SILENT DATA LOSS β the second finder's row was merged away into the first finder's,
|
| 137 |
+
#: and the wall then hid the survivor from the person who just found it. They searched, they
|
| 138 |
+
#: paid, and the screen said nothing arrived.
|
| 139 |
+
#:
|
| 140 |
+
#: β AND THE PAIR WAS MUTUALLY MASKING, which is why it stayed green for a wave: the wall named
|
| 141 |
+
#: `ut_ig_candidates`, and a READ-ONLY census of all four tenant stores
|
| 142 |
+
#: (`ops/w26_candidate_census.py`) proved that table exists in NO tenant β since wave 25's R2 the
|
| 143 |
+
#: write target is whatever database the user points the Create-record action at. So the wall
|
| 144 |
+
#: governed a table nobody writes, and fixing EITHER half alone would have armed the other
|
| 145 |
+
#: ([[defects-that-mask-each-other]]).
|
| 146 |
#:
|
| 147 |
+
#: The register offered two exits and R4 already implied this one. Restoring per-user visibility
|
| 148 |
+
#: instead would have required R4's merge to stop crossing users β a bigger change, against the
|
| 149 |
+
#: ruling, to bring back a wall that never governed anything real.
|
|
|
|
| 150 |
#:
|
| 151 |
+
#: β DO NOT RE-ADD THIS BY INFERRING THE RULE FROM A `created_by` COLUMN. Every
|
| 152 |
+
#: automation-written table has one (a scraped row says `automation`), so inference would hide
|
| 153 |
+
#: every scraped row from every non-admin β the same disappearance defect, one table wide instead
|
| 154 |
+
#: of one table narrow. `created_by` survives as W26/R4's informational "Found by" stamp ONLY.
|
|
|
|
|
|
|
|
|
|
| 155 |
|
| 156 |
|
| 157 |
def scoped_pool(session: Session, table_key: str):
|
|
|
|
| 165 |
defn = _defn_or_refuse(session, table_key)
|
| 166 |
fields_base = [dict(f) for f in (defn.get("fields") or [])]
|
| 167 |
field_keys = {f["key"] for f in fields_base}
|
|
|
|
|
|
|
| 168 |
rows_src = []
|
| 169 |
for rid, row in (defn.get("rows") or {}).items():
|
| 170 |
if not str(rid).isdigit():
|
| 171 |
continue
|
| 172 |
+
# WAVE 27 / D-72: no per-row owner filter. The table-level wall above
|
| 173 |
+
# (`_defn_or_refuse` -> `may_open`) is the WHOLE wall β see the retirement note on
|
| 174 |
+
# PER_USER_TABLES' former home. A row this session can reach is a row the tenant owns.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
r = {k: v for k, v in (row or {}).items() if k in field_keys}
|
| 176 |
r["pid"] = int(rid)
|
| 177 |
rows_src.append(r)
|
platform/aios_grid.py
CHANGED
|
@@ -122,7 +122,45 @@ def _round(v):
|
|
| 122 |
#: point at, so the column menu there simply never offers one.
|
| 123 |
CUSTOM_FIELD_TYPES = {"text", "select", "multiselect", "user", "int", "currency", "pct", "date",
|
| 124 |
"checkbox", "phone", "email", "url", "rating", "created_time", "formula",
|
| 125 |
-
"automation", "image", "json", "link", "rollup"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
#: User-created types whose CELLS are read-only: their values are computed (formula β client
|
| 127 |
#: side, any error degrades to BLANK) or system-owned (created_time = the row's `_created`).
|
| 128 |
#: Emitted with the cohort column's read-only mechanism β `source: 'odoo'` + `derived` β so
|
|
@@ -646,6 +684,11 @@ def fields_from_workspace(workspace=None, cohorts=False, scope_key=None, fields_
|
|
| 646 |
**({"max": _clean_rating_max(field.get("max"))} if ftype == "rating" else {}),
|
| 647 |
**({"automation": _clean_automation(field.get("automation"))}
|
| 648 |
if ftype == "automation" and _clean_automation(field.get("automation")) else {}),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 649 |
**_field_extras(field, ftype),
|
| 650 |
})
|
| 651 |
if cohorts and not any(f.get('key') == COHORT_COLUMN for f in out):
|
|
@@ -831,8 +874,20 @@ def _clean_rhs(raw, valid_keys):
|
|
| 831 |
#: views are sitting in mode:'dashboard' right now (wave 8's own close-out records one). The
|
| 832 |
#: rename is therefore a stored-value MIGRATION, not a constant rename: accept 'dashboard' on
|
| 833 |
#: READ forever, only ever WRITE 'chart'.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 834 |
DISPLAY_MODES = {'grid', 'list', 'calendar', 'kanban', 'map', 'dashboard', 'chart',
|
| 835 |
-
'timeseries', 'catalog'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 836 |
|
| 837 |
#: C-DISP (wave 2026-08-02): the time-series view's bucket vocabulary and caps, plus the
|
| 838 |
#: calendar-summary metric cap. types.ts mirrors these as TS_BUCKETS / TS_MAX_LAST_N /
|
|
@@ -1296,6 +1351,34 @@ def _clean_display(raw, valid_keys):
|
|
| 1296 |
catalogs = _clean_catalogs(raw.get('catalogs'), valid_keys)
|
| 1297 |
if catalogs:
|
| 1298 |
out['catalogs'] = catalogs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1299 |
return out
|
| 1300 |
|
| 1301 |
|
|
@@ -1584,7 +1667,63 @@ def locked_view_projection(entry, base_config):
|
|
| 1584 |
}
|
| 1585 |
|
| 1586 |
|
| 1587 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1588 |
"""Convert legacy list formulas into the shared serializable SavedView contract.
|
| 1589 |
|
| 1590 |
`system_name` (wave 16 C-TOPIC) labels the system view per TOPIC ("All products" on the
|
|
@@ -1603,6 +1742,15 @@ def views_from_defs(defs, saved_views, fields, system_name="All customers", lock
|
|
| 1603 |
"id": "all-customers", "name": system_name, "kind": "system",
|
| 1604 |
"locked": True, "config": dict(base),
|
| 1605 |
}]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1606 |
op_map = {">=": "gte", ">": "gt", "<=": "lte", "<": "lt", "=": "eq",
|
| 1607 |
"contains": "contains"}
|
| 1608 |
for name, definition in (defs or {}).items():
|
|
@@ -1664,6 +1812,31 @@ def views_from_defs(defs, saved_views, fields, system_name="All customers", lock
|
|
| 1664 |
# One thing, one name: the cohort store owns it (the rename event routes there), so
|
| 1665 |
# a stale `name` on the saved record can never fork into a second title.
|
| 1666 |
_v['name'] = _entry.get('name') or _v['id']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1667 |
return views
|
| 1668 |
|
| 1669 |
|
|
@@ -1725,7 +1898,13 @@ def workspace_wire(ws, uname, pool_pids, defs=None, scope_key='customer', storag
|
|
| 1725 |
else "All records"
|
| 1726 |
if str(scope_key or '').startswith('ut_')
|
| 1727 |
else "All customers"),
|
| 1728 |
-
locked_lists=cohort_lists
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1729 |
workspace = {'storageKey': storage_key, 'views': views, 'lists': cohort_lists}
|
| 1730 |
# Owner item 3 (2026-07-31): where this user left off. The client's own localStorage copy
|
| 1731 |
# wins when present; this is the server's answer for a FRESH browser, which used to fall
|
|
|
|
| 122 |
#: point at, so the column menu there simply never offers one.
|
| 123 |
CUSTOM_FIELD_TYPES = {"text", "select", "multiselect", "user", "int", "currency", "pct", "date",
|
| 124 |
"checkbox", "phone", "email", "url", "rating", "created_time", "formula",
|
| 125 |
+
"automation", "image", "json", "link", "rollup", "code"}
|
| 126 |
+
|
| 127 |
+
#: β WAVE-27 item 13 (owner ruling R13) β the `code` field's LANGUAGES.
|
| 128 |
+
#:
|
| 129 |
+
#: R13 is explicit that this kind is "syntax-highlighted storage + language config, NO execution
|
| 130 |
+
#: engine". So a language is a RENDERING hint and nothing else: it selects a highlighter, it never
|
| 131 |
+
#: selects an interpreter, and no value here may ever grow a run path. The list is short on
|
| 132 |
+
#: purpose β every entry costs a highlighter the client actually has to implement, and an
|
| 133 |
+
#: unimplemented language would paint plain text under a label promising colour.
|
| 134 |
+
#:
|
| 135 |
+
#: `plain` is the default and the fallback, so it is never a second way to say nothing: it is the
|
| 136 |
+
#: honest answer for a snippet whose language the user has not chosen.
|
| 137 |
+
CODE_LANGUAGES = {"plain", "json", "sql", "python", "javascript", "typescript",
|
| 138 |
+
"html", "css", "markdown", "yaml", "xml", "shell"}
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def _clean_code(raw):
|
| 142 |
+
"""The `code` field's config bag -> `{'language': ...}`, or None.
|
| 143 |
+
|
| 144 |
+
Deliberately OPTIONAL rather than required (the `automation` posture, not `link`'s): a code
|
| 145 |
+
column with no declared language is a legitimate state β it stores and highlights as plain
|
| 146 |
+
text β so refusing the FIELD over a missing bag would block the ordinary create path. An
|
| 147 |
+
unknown language falls back to `plain` rather than refusing, because the value is a rendering
|
| 148 |
+
hint: dropping the user's column to punish a typo in a highlighter name would be the
|
| 149 |
+
disproportionate half of the fail-closed rule.
|
| 150 |
+
|
| 151 |
+
β `plain` RETURNS NONE, and that is what makes the control reversible rather than one-way.
|
| 152 |
+
Absent already means plain, so storing `{'language': 'plain'}` would be the default wearing a
|
| 153 |
+
second name (the `kanbanClamp` law). But the patch path resolves an OMITTED key to the
|
| 154 |
+
previous value β so if plain were merely omitted by the client, switching a column back from
|
| 155 |
+
SQL to Plain text would keep storing SQL and read as a control that does not save. Sending
|
| 156 |
+
the bag explicitly and having it evaluate to None here means: omit = keep, plain = clear.
|
| 157 |
+
"""
|
| 158 |
+
if not isinstance(raw, dict):
|
| 159 |
+
return None
|
| 160 |
+
lang = str(raw.get('language') or 'plain').strip().lower()
|
| 161 |
+
if lang not in CODE_LANGUAGES or lang == 'plain':
|
| 162 |
+
return None
|
| 163 |
+
return {'language': lang}
|
| 164 |
#: User-created types whose CELLS are read-only: their values are computed (formula β client
|
| 165 |
#: side, any error degrades to BLANK) or system-owned (created_time = the row's `_created`).
|
| 166 |
#: Emitted with the cohort column's read-only mechanism β `source: 'odoo'` + `derived` β so
|
|
|
|
| 684 |
**({"max": _clean_rating_max(field.get("max"))} if ftype == "rating" else {}),
|
| 685 |
**({"automation": _clean_automation(field.get("automation"))}
|
| 686 |
if ftype == "automation" and _clean_automation(field.get("automation")) else {}),
|
| 687 |
+
# β WAVE-27 item 13 (R13) β the code column's language rides the wire, because the
|
| 688 |
+
# highlighter is chosen per column and the client cannot infer a language from a
|
| 689 |
+
# string. Absent = `plain`, which is what an unconfigured code column renders as.
|
| 690 |
+
**({"code": _clean_code(field.get("code"))}
|
| 691 |
+
if ftype == "code" and _clean_code(field.get("code")) else {}),
|
| 692 |
**_field_extras(field, ftype),
|
| 693 |
})
|
| 694 |
if cohorts and not any(f.get('key') == COHORT_COLUMN for f in out):
|
|
|
|
| 874 |
#: views are sitting in mode:'dashboard' right now (wave 8's own close-out records one). The
|
| 875 |
#: rename is therefore a stored-value MIGRATION, not a constant rename: accept 'dashboard' on
|
| 876 |
#: READ forever, only ever WRITE 'chart'.
|
| 877 |
+
#: β WAVE-27 item 8 (owner ruling R2, contract C3): 'swipe' β a DECK of the records whose bound
|
| 878 |
+
#: single-select is EMPTY, triaged one at a time by swiping left or right into two of that
|
| 879 |
+
#: field's options. Landed here FIRST and in the same change as the client registry, which is
|
| 880 |
+
#: the whole reason the two modes above it needed a staged hold: `_clean_display` DROPS an
|
| 881 |
+
#: unknown mode, so a client that offers a mode this set does not carry lets a user build a view
|
| 882 |
+
#: that silently reverts to a grid on the next read.
|
| 883 |
DISPLAY_MODES = {'grid', 'list', 'calendar', 'kanban', 'map', 'dashboard', 'chart',
|
| 884 |
+
'timeseries', 'catalog', 'swipe'}
|
| 885 |
+
|
| 886 |
+
#: C3 β the swipe binding's option cap. `leftOption`/`rightOption` are stored VALUES of a
|
| 887 |
+
#: single-select, and `_clean_options` trims every choice to 120 chars, so this is that same
|
| 888 |
+
#: number rather than a second opinion about it: a longer string cannot name a real option, and
|
| 889 |
+
#: a SHORTER cap here would silently refuse a binding to a legal one.
|
| 890 |
+
MAX_SWIPE_OPTION = 120
|
| 891 |
|
| 892 |
#: C-DISP (wave 2026-08-02): the time-series view's bucket vocabulary and caps, plus the
|
| 893 |
#: calendar-summary metric cap. types.ts mirrors these as TS_BUCKETS / TS_MAX_LAST_N /
|
|
|
|
| 1351 |
catalogs = _clean_catalogs(raw.get('catalogs'), valid_keys)
|
| 1352 |
if catalogs:
|
| 1353 |
out['catalogs'] = catalogs
|
| 1354 |
+
# ββ β WAVE-27 C3 (item 8 / R2): the swipe binding ββββββββββββββββββββββββββββββββββββ
|
| 1355 |
+
# `{fieldKey, leftOption, rightOption}` β WHOLE-KEY drop, never a partial one, and that
|
| 1356 |
+
# asymmetry against `charts`/`calendarMetrics` above is the point rather than an oversight.
|
| 1357 |
+
# Those are LISTS of independent cards, so losing one entry costs the user one card. This is
|
| 1358 |
+
# a single three-part BINDING: a swipe view holding a fieldKey with one option, or two
|
| 1359 |
+
# options and no field, is not a degraded swipe view β it is a deck that can never write
|
| 1360 |
+
# anything, rendered as though it were configured. Dropping the key entirely puts the view
|
| 1361 |
+
# back in its honest unconfigured state, which is the one state the client has a UI for.
|
| 1362 |
+
#
|
| 1363 |
+
# β What this CANNOT check, deliberately, and why the client must: whether `fieldKey` names
|
| 1364 |
+
# a SELECT, and whether the two options are still in that select's vocabulary. `valid_keys`
|
| 1365 |
+
# is a key set, and the docstring above draws this exact line β "what each mode MEANS ... is
|
| 1366 |
+
# the client's business". So SwipeView owns three losses this function is blind to (field
|
| 1367 |
+
# deleted, field retyped away from select, option removed) and must SHOW each one rather
|
| 1368 |
+
# than fall back to the first option, per the `viewModes.tsx` house rule.
|
| 1369 |
+
swipe = raw.get('swipe')
|
| 1370 |
+
if isinstance(swipe, dict):
|
| 1371 |
+
f_key = swipe.get('fieldKey')
|
| 1372 |
+
left, right = swipe.get('leftOption'), swipe.get('rightOption')
|
| 1373 |
+
ok = (f_key in valid_keys
|
| 1374 |
+
and isinstance(left, str) and isinstance(right, str))
|
| 1375 |
+
if ok:
|
| 1376 |
+
left, right = left.strip()[:MAX_SWIPE_OPTION], right.strip()[:MAX_SWIPE_OPTION]
|
| 1377 |
+
# Both non-empty, and DISTINCT: one option on both sides is a deck whose two
|
| 1378 |
+
# gestures do the same thing, which is two spellings of one state (the
|
| 1379 |
+
# `kanbanClamp` law) wearing a control that promises a choice.
|
| 1380 |
+
if left and right and left.casefold() != right.casefold():
|
| 1381 |
+
out['swipe'] = {'fieldKey': f_key, 'leftOption': left, 'rightOption': right}
|
| 1382 |
return out
|
| 1383 |
|
| 1384 |
|
|
|
|
| 1667 |
}
|
| 1668 |
|
| 1669 |
|
| 1670 |
+
#: β WAVE-27 item 27 (owner ruling R8) β the IG "Overview" view's CURATED COLUMNS, in the
|
| 1671 |
+
#: owner's own order: handle, followers, engagement, location, last enriched.
|
| 1672 |
+
#:
|
| 1673 |
+
#: Written as candidates rather than as a requirement. The template registry REFUSES a template
|
| 1674 |
+
#: whose columns the target lacks (`view_templates.missing_columns`) because applying one writes
|
| 1675 |
+
#: the user's own views and a filter on a missing column silently WIDENS. This view is INJECTED,
|
| 1676 |
+
#: not applied, and it filters nothing β so the proportionate rule is the opposite one: take the
|
| 1677 |
+
#: columns the table has, in this order, and skip the rest. An IG database that predates a
|
| 1678 |
+
#: column simply shows the other four.
|
| 1679 |
+
#:
|
| 1680 |
+
#: β `location_guess` is SESSION B's item-16 column and may not exist yet. That is exactly why
|
| 1681 |
+
#: this list is intersected rather than asserted: a hard requirement here would make the whole
|
| 1682 |
+
#: view vanish (or the assembly refuse) on every tenant until B lands, and then appear by
|
| 1683 |
+
#: surprise. `profile_url` closes the list as the click-through, which is what makes the view
|
| 1684 |
+
#: usable rather than merely informative.
|
| 1685 |
+
IG_OVERVIEW_COLUMNS = ('handle', 'full_name', 'followers', 'avg_engagement',
|
| 1686 |
+
'location_guess', 'enriched_at', 'profile_url')
|
| 1687 |
+
|
| 1688 |
+
#: The id is PINNED, the `view_templates` discipline: re-assembling must update the same view
|
| 1689 |
+
#: rather than mint "Overview 2". It also lets a user's own edits overlay it through the saved
|
| 1690 |
+
#: -config loop below, exactly as a cohort projection does.
|
| 1691 |
+
IG_OVERVIEW_ID = 'tpl_overview'
|
| 1692 |
+
|
| 1693 |
+
#: How this function recognises an IG preset database WITHOUT importing the engine: two of the
|
| 1694 |
+
#: profile preset columns is a stronger signal than any single one (a hand-made table could
|
| 1695 |
+
#: plausibly own a column called `followers`; owning `followers` AND `avg_engagement` AND
|
| 1696 |
+
#: `handle` is the preset set). `core/` must stay importable without the API layer, so this
|
| 1697 |
+
#: mirrors `user_tables.PROFILE_PRESET_KEYS` the way that module mirrors the engine's.
|
| 1698 |
+
_IG_SIGNATURE = ('handle', 'followers', 'avg_engagement')
|
| 1699 |
+
|
| 1700 |
+
|
| 1701 |
+
def _ig_overview_view(fields, base):
|
| 1702 |
+
"""R8's curated Overview, or None when this table is not an Instagram one."""
|
| 1703 |
+
keys = {f['key'] for f in fields}
|
| 1704 |
+
if not all(k in keys for k in _IG_SIGNATURE):
|
| 1705 |
+
return None
|
| 1706 |
+
visible = [k for k in IG_OVERVIEW_COLUMNS if k in keys]
|
| 1707 |
+
return {
|
| 1708 |
+
'id': IG_OVERVIEW_ID,
|
| 1709 |
+
'name': 'Overview',
|
| 1710 |
+
'kind': 'system',
|
| 1711 |
+
# NOT `locked`. The system view is locked because it is the identity of the table ("show
|
| 1712 |
+
# me everything"); this one is a STARTING LAYOUT, and R8 calls it curated rather than
|
| 1713 |
+
# fixed. A user who wants a sixth column should get one.
|
| 1714 |
+
'note': 'The five things worth seeing first on a creator. Sorted by reach.',
|
| 1715 |
+
'config': {
|
| 1716 |
+
**dict(base),
|
| 1717 |
+
'visible': visible,
|
| 1718 |
+
'order': visible + [k for k in (f['key'] for f in fields) if k not in visible],
|
| 1719 |
+
'sorts': ([{'colId': 'followers', 'dir': 'desc'}]
|
| 1720 |
+
if 'followers' in keys else []),
|
| 1721 |
+
},
|
| 1722 |
+
}
|
| 1723 |
+
|
| 1724 |
+
|
| 1725 |
+
def views_from_defs(defs, saved_views, fields, system_name="All customers", locked_lists=None,
|
| 1726 |
+
view_order=None):
|
| 1727 |
"""Convert legacy list formulas into the shared serializable SavedView contract.
|
| 1728 |
|
| 1729 |
`system_name` (wave 16 C-TOPIC) labels the system view per TOPIC ("All products" on the
|
|
|
|
| 1742 |
"id": "all-customers", "name": system_name, "kind": "system",
|
| 1743 |
"locked": True, "config": dict(base),
|
| 1744 |
}]
|
| 1745 |
+
# β WAVE-27 item 27 (R8) β the IG Overview, ABOVE All records.
|
| 1746 |
+
#
|
| 1747 |
+
# β INJECTED, not seeded into the store, and that is what makes "existing IG databases gain
|
| 1748 |
+
# it too" true with no migration and no write on a read path. It is the same mechanism the
|
| 1749 |
+
# system view above has always used; the pinned id means a user's own edits overlay it
|
| 1750 |
+
# through the saved-config loop below rather than forking a second view.
|
| 1751 |
+
_overview = _ig_overview_view(fields, base)
|
| 1752 |
+
if _overview:
|
| 1753 |
+
views.insert(0, _overview)
|
| 1754 |
op_map = {">=": "gte", ">": "gt", "<=": "lte", "<": "lt", "=": "eq",
|
| 1755 |
"contains": "contains"}
|
| 1756 |
for name, definition in (defs or {}).items():
|
|
|
|
| 1812 |
# One thing, one name: the cohort store owns it (the rename event routes there), so
|
| 1813 |
# a stale `name` on the saved record can never fork into a second title.
|
| 1814 |
_v['name'] = _entry.get('name') or _v['id']
|
| 1815 |
+
# ββ β WAVE-27 item 5, contract C7: the PER-USER VIEW ORDER βββββββββββββββββββββββββββββββ
|
| 1816 |
+
#
|
| 1817 |
+
# `view_order` is a list of view ids this user dragged into place. Applied LAST, over the
|
| 1818 |
+
# finished list, so it reorders whatever the assembly produced without having to know how any
|
| 1819 |
+
# of it got there (system, list:, cohort projection, saved, injected Overview).
|
| 1820 |
+
#
|
| 1821 |
+
# β THE SYSTEM VIEW STAYS AT INDEX 0 (C7), and it is re-pinned here rather than trusted to
|
| 1822 |
+
# sort correctly: `all-customers` is the client's landing default and one of its
|
| 1823 |
+
# UNDELETABLE_VIEW_IDS, so a stored order that happened to omit it β or list it third β
|
| 1824 |
+
# would move the rail's home row. β R8's Overview is the ONE thing allowed above it, because
|
| 1825 |
+
# the owner put it there; it is re-pinned with the system view so a drag cannot bury it
|
| 1826 |
+
# either. Both are facts about the table rather than the user's arrangement of it.
|
| 1827 |
+
#
|
| 1828 |
+
# β UNKNOWN IDS APPEND IN SERVER ORDER (C7). A view created since this order was stored, or
|
| 1829 |
+
# one shared to this user yesterday, must APPEAR β dropping it would make sharing look
|
| 1830 |
+
# broken, and the failure would be invisible to whoever shared it. Ids in the stored order
|
| 1831 |
+
# that no longer resolve are simply skipped.
|
| 1832 |
+
if view_order:
|
| 1833 |
+
_rank = {vid: i for i, vid in enumerate(view_order) if isinstance(vid, str)}
|
| 1834 |
+
_pinned = [v for v in views if v.get('id') in (IG_OVERVIEW_ID, 'all-customers')]
|
| 1835 |
+
_rest = [v for v in views if v.get('id') not in (IG_OVERVIEW_ID, 'all-customers')]
|
| 1836 |
+
# A stable sort over a rank that DEFAULTS TO THE END keeps unranked views in their
|
| 1837 |
+
# server order behind the ranked ones, rather than interleaving them by accident.
|
| 1838 |
+
_rest.sort(key=lambda v: _rank.get(v.get('id'), len(_rank) + 1))
|
| 1839 |
+
views = _pinned + _rest
|
| 1840 |
return views
|
| 1841 |
|
| 1842 |
|
|
|
|
| 1898 |
else "All records"
|
| 1899 |
if str(scope_key or '').startswith('ut_')
|
| 1900 |
else "All customers"),
|
| 1901 |
+
locked_lists=cohort_lists,
|
| 1902 |
+
# β WAVE-27 item 5 (C7) β this user's own rail arrangement, from
|
| 1903 |
+
# their own stratum. Read here rather than sorted by the client so
|
| 1904 |
+
# the ORDER a request answers with is the order that was stored:
|
| 1905 |
+
# sorting client-side would make the rail settle after a paint on
|
| 1906 |
+
# every load, and shared views would land in server order first.
|
| 1907 |
+
view_order=ws.get('viewOrder'))
|
| 1908 |
workspace = {'storageKey': storage_key, 'views': views, 'lists': cohort_lists}
|
| 1909 |
# Owner item 3 (2026-07-31): where this user left off. The client's own localStorage copy
|
| 1910 |
# wins when present; this is the server's answer for a FRESH browser, which used to fall
|
platform/core/grid_events.py
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
platform/core/table_store.py
CHANGED
|
@@ -339,6 +339,37 @@ class TableStore:
|
|
| 339 |
ws['itemFolders'] = dict(item_folders or {})
|
| 340 |
self._update(username, _set)
|
| 341 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 342 |
def shared_views(self, viewer, is_admin=False):
|
| 343 |
"""Every SHARED view this viewer may see, by id (wave-9 I17).
|
| 344 |
|
|
|
|
| 339 |
ws['itemFolders'] = dict(item_folders or {})
|
| 340 |
self._update(username, _set)
|
| 341 |
|
| 342 |
+
def save_view_order(self, username, order):
|
| 343 |
+
"""β WAVE-27 item 5 (contract C7) β this user's own ORDER for the views rail.
|
| 344 |
+
|
| 345 |
+
Wholesale, like `save_folders` above and for the same reason: the client sends the full
|
| 346 |
+
list it is looking at, not a delta, because a partial order cannot say where an UNNAMED
|
| 347 |
+
view went.
|
| 348 |
+
|
| 349 |
+
β PER USER, and it belongs in this stratum rather than on the view records themselves.
|
| 350 |
+
`aios_grid`'s own folder note argues it out for placements and every word applies: an
|
| 351 |
+
arrangement is a per-user ORGANISING act, not part of what a view IS β so keeping it out
|
| 352 |
+
of the view config means duplicating, sharing or exporting a view does not drag one
|
| 353 |
+
person's rail position along with it. It also means a SHARED view can sit in a different
|
| 354 |
+
place for each person who can see it, which is the only coherent answer once two people
|
| 355 |
+
share one view.
|
| 356 |
+
|
| 357 |
+
An empty list CLEARS the arrangement (back to server order) rather than storing `[]`.
|
| 358 |
+
"""
|
| 359 |
+
def _set(ws):
|
| 360 |
+
clean = []
|
| 361 |
+
seen = set()
|
| 362 |
+
for vid in (order or []):
|
| 363 |
+
vid = str(vid).strip()[:120]
|
| 364 |
+
if vid and vid not in seen:
|
| 365 |
+
seen.add(vid)
|
| 366 |
+
clean.append(vid)
|
| 367 |
+
if clean:
|
| 368 |
+
ws['viewOrder'] = clean
|
| 369 |
+
else:
|
| 370 |
+
ws.pop('viewOrder', None)
|
| 371 |
+
self._update(username, _set)
|
| 372 |
+
|
| 373 |
def shared_views(self, viewer, is_admin=False):
|
| 374 |
"""Every SHARED view this viewer may see, by id (wave-9 I17).
|
| 375 |
|
platform/core/user_tables.py
CHANGED
|
@@ -79,9 +79,19 @@ def records_mutable(table_key, st=None):
|
|
| 79 |
#: materialised into the row, because a rollup reads ANOTHER TABLE'S ROWS β data the client has
|
| 80 |
#: not loaded and must not have to. `formula` stayed out of this list because it computes
|
| 81 |
#: client-side over one row; that argument does not reach these two.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
UT_FIELD_TYPES = {'text', 'select', 'multiselect', 'user', 'int', 'currency', 'pct', 'date',
|
| 83 |
'checkbox', 'phone', 'email', 'url', 'rating', 'automation', 'json',
|
| 84 |
-
'link', 'rollup'}
|
| 85 |
#: A cell is still a scalar on the wire (`Row` values are strings/numbers) β what this bounds is
|
| 86 |
#: the DOCUMENT inside it. Source data is one already-paid provider response; keep it whole so a
|
| 87 |
#: provider field is never silently discarded merely because the response is rich. 32 MiB matches
|
|
@@ -292,6 +302,26 @@ def clean_fields(raw):
|
|
| 292 |
entry['options'] = opts
|
| 293 |
if f.get('default') is True:
|
| 294 |
entry['default'] = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 295 |
# C3 (wave 25): the profile flag rides the CREATE path too, and the one-per-table law
|
| 296 |
# holds inside a single list. β This validator and `_clean_field` are two doors onto one
|
| 297 |
# contract (a pre-existing split β `create`/`set_fields` come through here, `add_field`/
|
|
@@ -874,6 +904,31 @@ def _clean_field(raw, previous=None):
|
|
| 874 |
out['rollup'] = rl
|
| 875 |
elif ftype == 'rollup':
|
| 876 |
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 877 |
return out
|
| 878 |
|
| 879 |
|
|
|
|
| 79 |
#: materialised into the row, because a rollup reads ANOTHER TABLE'S ROWS β data the client has
|
| 80 |
#: not loaded and must not have to. `formula` stayed out of this list because it computes
|
| 81 |
#: client-side over one row; that argument does not reach these two.
|
| 82 |
+
#: β `image` WAS MISSING FROM THIS SET UNTIL WAVE 27, AND THAT WAS A LIVE DEFECT β recorded
|
| 83 |
+
#: here because the shape repeats and the next kind will be added by somebody reading this line.
|
| 84 |
+
#: Wave-19 R7 landed `image` on FOUR of the five surfaces (the `FieldType` union, `CREATABLE_TYPES`,
|
| 85 |
+
#: `aios_grid.CUSTOM_FIELD_TYPES`, the shape/label tables) and missed this one. The client
|
| 86 |
+
#: therefore offered an Image column in EVERY column menu, including on `ut_*` databases, while
|
| 87 |
+
#: `_clean_field` returned None for it β so on a user database the column was created, named,
|
| 88 |
+
#: configured, and GONE on the next read, with nothing anywhere going red. It survived three
|
| 89 |
+
#: waves because `verify_fields_contract` diffed the client's offer against the ODOO grid's
|
| 90 |
+
#: acceptance and never against this set. Wave-27 item 13 adds that derived leg, which is what
|
| 91 |
+
#: found it (measured, not reviewed: `_clean_field({'type':'image'})` returned None).
|
| 92 |
UT_FIELD_TYPES = {'text', 'select', 'multiselect', 'user', 'int', 'currency', 'pct', 'date',
|
| 93 |
'checkbox', 'phone', 'email', 'url', 'rating', 'automation', 'json',
|
| 94 |
+
'link', 'rollup', 'code', 'image'}
|
| 95 |
#: A cell is still a scalar on the wire (`Row` values are strings/numbers) β what this bounds is
|
| 96 |
#: the DOCUMENT inside it. Source data is one already-paid provider response; keep it whole so a
|
| 97 |
#: provider field is never silently discarded merely because the response is rich. 32 MiB matches
|
|
|
|
| 302 |
entry['options'] = opts
|
| 303 |
if f.get('default') is True:
|
| 304 |
entry['default'] = True
|
| 305 |
+
# β WAVE-27 item 19 (R15) + D-80 β THE PRIMARY COLUMN, CARRIED THROUGH THE CREATE DOOR.
|
| 306 |
+
#
|
| 307 |
+
# `_clean_field` has honoured `pinned` since 2026-08-07; THIS door silently dropped it,
|
| 308 |
+
# and the split the comment below names is why. It did not matter while `create()` minted
|
| 309 |
+
# one column β with nothing pinned, `fields.find(f => f.pinned) ?? fields[0]` made the
|
| 310 |
+
# only column the primary either way. R15 seeds FOUR at once, so "whichever came first"
|
| 311 |
+
# stops being a coincidence that happens to be right, and D-80 is the register entry for
|
| 312 |
+
# exactly that fallback quietly being the whole rule. MEASURED before fixing:
|
| 313 |
+
# `clean_fields([{...'pinned': True}])` returned the field without the key.
|
| 314 |
+
if f.get('pinned') is True:
|
| 315 |
+
entry['pinned'] = True
|
| 316 |
+
# β WAVE-27 item 13 β the code language, for the same reason: a `code` column created
|
| 317 |
+
# through THIS door would otherwise arrive without the bag `_clean_field` preserves, and
|
| 318 |
+
# a column whose language depends on which door made it is the divergence the note below
|
| 319 |
+
# warns about, arriving through a different key.
|
| 320 |
+
if ftype == 'code' and f.get('code') is not None:
|
| 321 |
+
import aios_grid as _agc
|
| 322 |
+
c = _agc._clean_code(f.get('code'))
|
| 323 |
+
if c:
|
| 324 |
+
entry['code'] = c
|
| 325 |
# C3 (wave 25): the profile flag rides the CREATE path too, and the one-per-table law
|
| 326 |
# holds inside a single list. β This validator and `_clean_field` are two doors onto one
|
| 327 |
# contract (a pre-existing split β `create`/`set_fields` come through here, `add_field`/
|
|
|
|
| 904 |
out['rollup'] = rl
|
| 905 |
elif ftype == 'rollup':
|
| 906 |
return None
|
| 907 |
+
# β WAVE-27 item 13 (owner ruling R13) β the `code` column's language bag.
|
| 908 |
+
#
|
| 909 |
+
# β Deliberately the WEAKEST posture of the four bags above, and the asymmetry is the whole
|
| 910 |
+
# point rather than an inconsistency. `metric`/`link`/`rollup` bags DEFINE what their column
|
| 911 |
+
# is: without one the cell can never resolve a value, so a missing or mis-shaped bag refuses
|
| 912 |
+
# the field. A `language` chooses a HIGHLIGHTER over a string the column already holds
|
| 913 |
+
# perfectly well β so it is optional (an unconfigured code column renders plain), it survives
|
| 914 |
+
# a patch that omits it (the `automation` rule: the gear owns it, a header rename must not
|
| 915 |
+
# clear it), and an unknown language degrades to `plain` instead of destroying the column.
|
| 916 |
+
# R13's "NO execution engine" is why this can be so relaxed: the value selects a renderer and
|
| 917 |
+
# can never select an interpreter.
|
| 918 |
+
# β Function-local import, the convention `grid_events` already uses for the same module
|
| 919 |
+
# (`import aios_grid as _ag2`, five call sites): `core` must not import the layer above it at
|
| 920 |
+
# MODULE level. One vocabulary, one validator β declaring the language list a second time
|
| 921 |
+
# here is exactly the drift the fields contract exists to catch.
|
| 922 |
+
# β OMIT = KEEP, `plain` = CLEAR. `_clean_code` returns None for plain (see its docstring),
|
| 923 |
+
# so an explicit `{'language': 'plain'}` from the editor drops the key here while a patch
|
| 924 |
+
# that never mentions `code` inherits the previous bag. Without that split, switching a
|
| 925 |
+
# column back to Plain text would be a control that silently does not save.
|
| 926 |
+
code_raw = raw.get('code') if 'code' in raw else prev.get('code')
|
| 927 |
+
if code_raw is not None and ftype == 'code':
|
| 928 |
+
import aios_grid as _agc
|
| 929 |
+
c = _agc._clean_code(code_raw)
|
| 930 |
+
if c:
|
| 931 |
+
out['code'] = c
|
| 932 |
return out
|
| 933 |
|
| 934 |
|
web/src/alerts/AlertsPane.tsx
CHANGED
|
@@ -23,11 +23,14 @@ import {
|
|
| 23 |
EMPTY_INBOX,
|
| 24 |
applyRead,
|
| 25 |
inboxOrder,
|
|
|
|
| 26 |
isAutomationReview,
|
| 27 |
routeForTopic,
|
| 28 |
stampText,
|
| 29 |
} from "./alertsModel";
|
| 30 |
import type { Alert, Inbox, Notification } from "./alertsModel";
|
|
|
|
|
|
|
| 31 |
|
| 32 |
/** The clock face this pane uses for its one glyph β drawn, never an emoji. */
|
| 33 |
function BellIcon() {
|
|
@@ -142,6 +145,15 @@ export default function AlertsPane({
|
|
| 142 |
onClose();
|
| 143 |
return;
|
| 144 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
// A route this client cannot resolve opens NOTHING and says so β alerts
|
| 146 |
// outlive the surfaces they were made from.
|
| 147 |
if (!routeForTopic(n.topic)) {
|
|
@@ -198,12 +210,33 @@ export default function AlertsPane({
|
|
| 198 |
// "Open the alert's view" over a review notification described a journey
|
| 199 |
// the click does not take.
|
| 200 |
title={
|
| 201 |
-
isAutomationReview(n)
|
| 202 |
? "Open the automation"
|
| 203 |
: `Open ${n.alertLabel || "the alert's view"}`
|
| 204 |
}
|
| 205 |
>
|
| 206 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
<span className="alerts-row-meta">
|
| 208 |
{n.alertLabel ? `${n.alertLabel} Β· ` : ""}
|
| 209 |
{/* Readable, but never re-derived: `stampText` is string surgery
|
|
|
|
| 23 |
EMPTY_INBOX,
|
| 24 |
applyRead,
|
| 25 |
inboxOrder,
|
| 26 |
+
isAutomationOutcome,
|
| 27 |
isAutomationReview,
|
| 28 |
routeForTopic,
|
| 29 |
stampText,
|
| 30 |
} from "./alertsModel";
|
| 31 |
import type { Alert, Inbox, Notification } from "./alertsModel";
|
| 32 |
+
// WAVE 27 C5 β the ONE generated loop mark, consumed rather than redrawn (C7's rule).
|
| 33 |
+
import { Mark } from "../shell/Brand";
|
| 34 |
|
| 35 |
/** The clock face this pane uses for its one glyph β drawn, never an emoji. */
|
| 36 |
function BellIcon() {
|
|
|
|
| 145 |
onClose();
|
| 146 |
return;
|
| 147 |
}
|
| 148 |
+
// β WAVE 27 C5 β a RUN OUTCOME routes to its automation too, and it carries the id in
|
| 149 |
+
// `alertId` rather than `autoId` (`core.alerts.notify`'s shape, not `_queue_review`'s).
|
| 150 |
+
// Beside the review branch and after it: a review notification satisfies BOTH predicates,
|
| 151 |
+
// and only the review one knows about the stage to scroll to.
|
| 152 |
+
if (isAutomationOutcome(n)) {
|
| 153 |
+
onOpenAutomation(n.alertId, undefined);
|
| 154 |
+
onClose();
|
| 155 |
+
return;
|
| 156 |
+
}
|
| 157 |
// A route this client cannot resolve opens NOTHING and says so β alerts
|
| 158 |
// outlive the surfaces they were made from.
|
| 159 |
if (!routeForTopic(n.topic)) {
|
|
|
|
| 210 |
// "Open the alert's view" over a review notification described a journey
|
| 211 |
// the click does not take.
|
| 212 |
title={
|
| 213 |
+
isAutomationReview(n) || isAutomationOutcome(n)
|
| 214 |
? "Open the automation"
|
| 215 |
: `Open ${n.alertLabel || "the alert's view"}`
|
| 216 |
}
|
| 217 |
>
|
| 218 |
+
{/* β WAVE 27 C5 β an automation's row wears the LOOP MARK.
|
| 219 |
+
β NOT A STATUS DOT, and not a second one: wave-26 R14 deleted every
|
| 220 |
+
status dot in the automation module on the grounds that *"these
|
| 221 |
+
automations are basically loops"*, and a run that FAILED is already said
|
| 222 |
+
in `n.label` (the run summary) in words. A coloured dot here would
|
| 223 |
+
reintroduce, in the inbox, the vocabulary that was deleted from the
|
| 224 |
+
surface it points at.
|
| 225 |
+
β The generated `Mark`, never a redrawn path: `shell/Brand.tsx`'s header
|
| 226 |
+
records a hand-copied version silently painting LAST WAVE'S BRAND while
|
| 227 |
+
a comment claimed parity. */}
|
| 228 |
+
<span className="alerts-row-label">
|
| 229 |
+
{isAutomationOutcome(n) || isAutomationReview(n) ? (
|
| 230 |
+
// β INSIDE the label span, not beside it. `.alerts-row-main` is a flex
|
| 231 |
+
// COLUMN, so a sibling here becomes a third ROW stacked above the text
|
| 232 |
+
// ([[wrong-parent-not-broken-control]]); inline, it sits on the line it
|
| 233 |
+
// annotates and rides the same ellipsis.
|
| 234 |
+
<span className="alerts-row-mark">
|
| 235 |
+
<Mark size={12} />
|
| 236 |
+
</span>
|
| 237 |
+
) : null}
|
| 238 |
+
{n.label}
|
| 239 |
+
</span>
|
| 240 |
<span className="alerts-row-meta">
|
| 241 |
{n.alertLabel ? `${n.alertLabel} Β· ` : ""}
|
| 242 |
{/* Readable, but never re-derived: `stampText` is string surgery
|
web/src/alerts/alertsModel.ts
CHANGED
|
@@ -183,6 +183,31 @@ export function isAutomationReview(n: Notification): boolean {
|
|
| 183 |
return n.kind === AUTOMATION_REVIEW_KIND && !!str(n.autoId).trim();
|
| 184 |
}
|
| 185 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
/** Newest first, and unread before read at the same instant β the inbox order.
|
| 187 |
* Stable: two notifications from one write keep the server's order. */
|
| 188 |
export function inboxOrder(items: Notification[]): Notification[] {
|
|
|
|
| 183 |
return n.kind === AUTOMATION_REVIEW_KIND && !!str(n.autoId).trim();
|
| 184 |
}
|
| 185 |
|
| 186 |
+
/** WAVE 27 C5 β the topic an automation RUN OUTCOME arrives under (`core.alerts.notify`'s
|
| 187 |
+
* default). One place, for the same reason `AUTOMATION_REVIEW_KIND` is one place. */
|
| 188 |
+
export const AUTOMATION_TOPIC = "automation";
|
| 189 |
+
|
| 190 |
+
/**
|
| 191 |
+
* β WAVE 27 Β· CONTRACT C5 β did an automation RUN produce this, rather than a view?
|
| 192 |
+
*
|
| 193 |
+
* β A SECOND AUTOMATION SHAPE, AND IT IS NOT THE REVIEW ONE. `isAutomationReview` reads
|
| 194 |
+
* `kind` + `autoId`, which is what `_queue_review` writes. `core.alerts.notify()` β the door
|
| 195 |
+
* `_commit_run` uses for "this run succeeded / this run failed" (I7) β writes NEITHER: it puts
|
| 196 |
+
* the producer's key in `alertId`, leaves `viewId` empty, sets no `kind` at all, and identifies
|
| 197 |
+
* itself by `topic`. Two producers, two shapes, one inbox.
|
| 198 |
+
*
|
| 199 |
+
* β WITHOUT THIS the row falls to the view branch, `routeForTopic('automation')` answers null,
|
| 200 |
+
* and clicking a run outcome says *"That alert's table is no longer available to this account"*
|
| 201 |
+
* β a confidently wrong sentence about a feature that is working, which is the exact defect
|
| 202 |
+
* `isAutomationReview`'s own header records from wave 23. The shape changed; the trap did not.
|
| 203 |
+
*
|
| 204 |
+
* β `alertId` IS REQUIRED, same fail-closed direction as the review predicate: a run outcome
|
| 205 |
+
* whose automation id never arrived would otherwise dispatch an open request naming nothing.
|
| 206 |
+
*/
|
| 207 |
+
export function isAutomationOutcome(n: Notification): boolean {
|
| 208 |
+
return str(n.topic).trim() === AUTOMATION_TOPIC && !!str(n.alertId).trim();
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
/** Newest first, and unread before read at the same instant β the inbox order.
|
| 212 |
* Stable: two notifications from one write keep the server's order. */
|
| 213 |
export function inboxOrder(items: Notification[]): Notification[] {
|
web/src/automation/AutomationBuilder.tsx
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
web/src/automation/AutomationDetail.tsx
CHANGED
|
@@ -20,9 +20,9 @@
|
|
| 20 |
// ([[no-unverifiable-aggregates]]) β a number with no way back to its records is
|
| 21 |
// what this codebase treats as a defect rather than a summary.
|
| 22 |
// ---------------------------------------------------------------------------
|
| 23 |
-
import { useCallback, useEffect, useState } from "react";
|
| 24 |
-
|
| 25 |
-
import AutomationBuilder from "./AutomationBuilder";
|
| 26 |
import AutomationFind from "./AutomationFind";
|
| 27 |
import AutomationTrigger from "./AutomationTrigger";
|
| 28 |
import type {
|
|
@@ -49,7 +49,7 @@ import {
|
|
| 49 |
deleteAutomation,
|
| 50 |
discoverEstimate,
|
| 51 |
fieldKeyFor,
|
| 52 |
-
listTables,
|
| 53 |
oauthStatus,
|
| 54 |
patchAutomation,
|
| 55 |
previewSource,
|
|
@@ -178,13 +178,13 @@ export default function AutomationDetail({
|
|
| 178 |
const [saving, setSaving] = useState(false);
|
| 179 |
const [touched, setTouched] = useState(false);
|
| 180 |
const [triggerBusy, setTriggerBusy] = useState(false);
|
| 181 |
-
const [oauth, setOauth] = useState<OAuthStatus | null>(null);
|
| 182 |
/**
|
| 183 |
* β "SHOW ME THE CRON" IS A VIEW CHOICE, NOT A SCHEDULE CHANGE β and forgetting that once
|
| 184 |
* made the Custom option DEAD. Everything else on the trigger face is derived from the
|
| 185 |
* stored cron, so picking "Custom (cron)" wrote⦠the same cron, which `readCron` read back
|
| 186 |
* as "every Wednesday" and the select snapped straight back. It lives HERE, above the two
|
| 187 |
-
* builder controls does not lose it.
|
| 188 |
*/
|
| 189 |
const [showCron, setShowCron] = useState(false);
|
| 190 |
|
|
@@ -255,6 +255,45 @@ export default function AutomationDetail({
|
|
| 255 |
const [drill, setDrill] = useState<RunRows | null>(null);
|
| 256 |
const [drillFor, setDrillFor] = useState("");
|
| 257 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 258 |
useEffect(() => {
|
| 259 |
const ac = new AbortController();
|
| 260 |
listTables(ac.signal)
|
|
@@ -427,9 +466,19 @@ export default function AutomationDetail({
|
|
| 427 |
* filter with the row still on screen and not a word anywhere. Holding a half-written row back
|
| 428 |
* is a courtesy; holding it back in silence is the drop class this module refuses everywhere.
|
| 429 |
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 430 |
const heldNote = (): string => {
|
| 431 |
-
|
| 432 |
-
const held = preds.length - completePreds().length;
|
| 433 |
if (held < 1) return "";
|
| 434 |
return `Saved β ${held} condition${held === 1 ? " was" : "s were"} not saved yet, `
|
| 435 |
+ `${held === 1 ? "it needs" : "they need"} a value.`;
|
|
@@ -518,9 +567,9 @@ export default function AutomationDetail({
|
|
| 518 |
config: buildConfig(),
|
| 519 |
schedule: { cron: next.cron, enabled: next.enabled },
|
| 520 |
});
|
| 521 |
-
setTouched(false);
|
| 522 |
-
setMessage(heldNote());
|
| 523 |
-
await onSaved(automation.id);
|
| 524 |
} catch (e) {
|
| 525 |
setProblem(e instanceof AutomationError ? e.message : "That schedule was not saved.");
|
| 526 |
} finally {
|
|
@@ -555,9 +604,9 @@ export default function AutomationDetail({
|
|
| 555 |
trigger: { key },
|
| 556 |
schedule: { cron, enabled: key === "schedule" },
|
| 557 |
});
|
| 558 |
-
setTouched(false);
|
| 559 |
-
setMessage(heldNote());
|
| 560 |
-
await onSaved(automation.id);
|
| 561 |
} catch (e) {
|
| 562 |
setProblem(e instanceof AutomationError ? e.message : "That trigger was not saved.");
|
| 563 |
} finally {
|
|
@@ -584,9 +633,9 @@ export default function AutomationDetail({
|
|
| 584 |
setSaving(true);
|
| 585 |
setProblem("");
|
| 586 |
setMessage("");
|
| 587 |
-
try {
|
| 588 |
-
const id = await persist();
|
| 589 |
-
await onSaved(id);
|
| 590 |
} catch (e) {
|
| 591 |
setProblem(e instanceof AutomationError ? e.message : "That could not be saved.");
|
| 592 |
} finally {
|
|
@@ -599,23 +648,58 @@ export default function AutomationDetail({
|
|
| 599 |
* switch. Unsaved panel edits are persisted FIRST rather than being discarded
|
| 600 |
* by the reload that follows, which is the one way this could lose work.
|
| 601 |
*/
|
| 602 |
-
const flip = async (nodeId: string) => {
|
| 603 |
-
setProblem("");
|
| 604 |
setMessage("");
|
| 605 |
try {
|
| 606 |
-
if (touched) await persist(false);
|
| 607 |
-
await toggleNode(automation.id, nodeId);
|
| 608 |
-
await onSaved(automation.id);
|
| 609 |
-
} catch (e) {
|
| 610 |
-
setProblem(e instanceof AutomationError ? e.message : "That step was not changed.");
|
| 611 |
-
}
|
| 612 |
-
};
|
| 613 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 614 |
const start = async () => {
|
| 615 |
setProblem("");
|
| 616 |
try {
|
|
|
|
| 617 |
await runAutomation(automation.id);
|
| 618 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 619 |
await onSaved(automation.id);
|
| 620 |
} catch (e) {
|
| 621 |
setProblem(e instanceof AutomationError ? e.message : "It did not start.");
|
|
@@ -690,9 +774,9 @@ export default function AutomationDetail({
|
|
| 690 |
setTriggerBusy(true);
|
| 691 |
setProblem("");
|
| 692 |
setMessage("");
|
| 693 |
-
try {
|
| 694 |
-
await patchAutomation(automation.id, body);
|
| 695 |
-
await onSaved(automation.id);
|
| 696 |
} catch (e) {
|
| 697 |
// β THE SERVER'S SENTENCE, VERBATIM. `clean_flow` refuses an empty group, an unready
|
| 698 |
// action kind, a valueless compare β each with a reason worth reading. A client that
|
|
@@ -1082,7 +1166,7 @@ export default function AutomationDetail({
|
|
| 1082 |
on that point and the consequence (no name in the Board view) is booked, not patched.
|
| 1083 |
*/}
|
| 1084 |
<div className="auto-head-title">
|
| 1085 |
-
<span className="autox-view is-on">Builder</span>
|
| 1086 |
</div>
|
| 1087 |
<div className="auto-head-actions">
|
| 1088 |
{/*
|
|
@@ -1157,7 +1241,7 @@ export default function AutomationDetail({
|
|
| 1157 |
engine's own steps AND what the owner added, from data the rail already had) and there
|
| 1158 |
is no longer a state in which the reader gets it by accident.
|
| 1159 |
*/}
|
| 1160 |
-
<>
|
| 1161 |
<AutomationBuilder
|
| 1162 |
automation={automation}
|
| 1163 |
// ITEM 15b β the name left the header, and this is where it went. Three REQUIRED
|
|
@@ -1212,11 +1296,24 @@ export default function AutomationDetail({
|
|
| 1212 |
// ONE cron round-trip, rendered inside the Properties panel with its own picker
|
| 1213 |
// suppressed β the builder supplies the "Trigger type" select above it.
|
| 1214 |
scheduleFace={scheduleFace}
|
| 1215 |
-
|
| 1216 |
-
|
| 1217 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1218 |
<div className="auto-panel-head">
|
| 1219 |
-
|
| 1220 |
</div>
|
| 1221 |
{!automation.runs?.length ? (
|
| 1222 |
<p className="auto-note">
|
|
@@ -1280,13 +1377,13 @@ export default function AutomationDetail({
|
|
| 1280 |
</li>
|
| 1281 |
))}
|
| 1282 |
</ol>
|
| 1283 |
-
)}
|
| 1284 |
-
<p className="auto-hint">
|
| 1285 |
-
Open a run to inspect the records it touched.
|
| 1286 |
-
</p>
|
| 1287 |
-
</>
|
| 1288 |
-
</aside>
|
| 1289 |
-
</>
|
| 1290 |
</div>
|
| 1291 |
</div>
|
| 1292 |
);
|
|
|
|
| 20 |
// ([[no-unverifiable-aggregates]]) β a number with no way back to its records is
|
| 21 |
// what this codebase treats as a defect rather than a summary.
|
| 22 |
// ---------------------------------------------------------------------------
|
| 23 |
+
import { useCallback, useEffect, useState } from "react";
|
| 24 |
+
|
| 25 |
+
import AutomationBuilder from "./AutomationBuilder";
|
| 26 |
import AutomationFind from "./AutomationFind";
|
| 27 |
import AutomationTrigger from "./AutomationTrigger";
|
| 28 |
import type {
|
|
|
|
| 49 |
deleteAutomation,
|
| 50 |
discoverEstimate,
|
| 51 |
fieldKeyFor,
|
| 52 |
+
listTables,
|
| 53 |
oauthStatus,
|
| 54 |
patchAutomation,
|
| 55 |
previewSource,
|
|
|
|
| 178 |
const [saving, setSaving] = useState(false);
|
| 179 |
const [touched, setTouched] = useState(false);
|
| 180 |
const [triggerBusy, setTriggerBusy] = useState(false);
|
| 181 |
+
const [oauth, setOauth] = useState<OAuthStatus | null>(null);
|
| 182 |
/**
|
| 183 |
* β "SHOW ME THE CRON" IS A VIEW CHOICE, NOT A SCHEDULE CHANGE β and forgetting that once
|
| 184 |
* made the Custom option DEAD. Everything else on the trigger face is derived from the
|
| 185 |
* stored cron, so picking "Custom (cron)" wrote⦠the same cron, which `readCron` read back
|
| 186 |
* as "every Wednesday" and the select snapped straight back. It lives HERE, above the two
|
| 187 |
+
* builder controls does not lose it.
|
| 188 |
*/
|
| 189 |
const [showCron, setShowCron] = useState(false);
|
| 190 |
|
|
|
|
| 255 |
const [drill, setDrill] = useState<RunRows | null>(null);
|
| 256 |
const [drillFor, setDrillFor] = useState("");
|
| 257 |
|
| 258 |
+
/**
|
| 259 |
+
* β WAVE 27 Β· OWNER ITEM 33 / CONTRACT C11 β WHICH PANEL OWNS THE RIGHT-HAND COLUMN.
|
| 260 |
+
*
|
| 261 |
+
* β THE STATE IS HERE BECAUSE THE TWO PANELS ARE NOT SIBLINGS IN ONE FILE. Properties is
|
| 262 |
+
* rendered by `AutomationBuilder`; the Run log is rendered below by this component. Both are
|
| 263 |
+
* `.auto-panel` children of `.auto-work`, so they were drawn SIDE BY SIDE β two 380px columns
|
| 264 |
+
* on a surface whose actual content is the flow. The reference (`reference/Airtable
|
| 265 |
+
* Automation 11.png`) shows one dismissable panel, and the only component that can guarantee
|
| 266 |
+
* "exactly one" is the parent of both.
|
| 267 |
+
*
|
| 268 |
+
* β PROPERTIES IS THE DEFAULT, not the log. Opening an automation to read last night's run is
|
| 269 |
+
* the rarer errand; opening it to change something is the common one, and the panel that
|
| 270 |
+
* appears should be the one a click on a step is about to fill.
|
| 271 |
+
*/
|
| 272 |
+
const [aside, setAside] = useState<"properties" | "runs">("properties");
|
| 273 |
+
/**
|
| 274 |
+
* The switch, drawn in BOTH panel heads so it does not move when the panel does.
|
| 275 |
+
*
|
| 276 |
+
* β A RADIOGROUP, not two buttons that happen to look joined: they are two values of one
|
| 277 |
+
* setting, and `aria-pressed` on each would tell a screen reader about two independent
|
| 278 |
+
* toggles that can both be off β a state this control cannot express.
|
| 279 |
+
*/
|
| 280 |
+
const panelTabs = (
|
| 281 |
+
<div className="auto-paneltabs" role="radiogroup" aria-label="Right-hand panel">
|
| 282 |
+
{([["properties", "Properties"], ["runs", "Run history"]] as const).map(([k, label]) => (
|
| 283 |
+
<button
|
| 284 |
+
key={k}
|
| 285 |
+
type="button"
|
| 286 |
+
role="radio"
|
| 287 |
+
aria-checked={aside === k}
|
| 288 |
+
className={"auto-paneltab" + (aside === k ? " is-on" : "")}
|
| 289 |
+
onClick={() => setAside(k)}
|
| 290 |
+
>
|
| 291 |
+
{label}
|
| 292 |
+
</button>
|
| 293 |
+
))}
|
| 294 |
+
</div>
|
| 295 |
+
);
|
| 296 |
+
|
| 297 |
useEffect(() => {
|
| 298 |
const ac = new AbortController();
|
| 299 |
listTables(ac.signal)
|
|
|
|
| 466 |
* filter with the row still on screen and not a word anywhere. Holding a half-written row back
|
| 467 |
* is a courtesy; holding it back in silence is the drop class this module refuses everywhere.
|
| 468 |
*/
|
| 469 |
+
/**
|
| 470 |
+
* β WAVE 27 (item 11) β the COUNT, split out of the sentence below.
|
| 471 |
+
*
|
| 472 |
+
* `start()` has to say the same fact in a different sentence ("it is running without it"),
|
| 473 |
+
* and the alternative was for it to read `heldNote()`'s prose and sniff it for a plural β
|
| 474 |
+
* a second reader of a string that exists to be shown to a person. One arithmetic, two
|
| 475 |
+
* wordings, and neither wording is parsed by anything.
|
| 476 |
+
*/
|
| 477 |
+
const heldCount = (): number =>
|
| 478 |
+
kind === "discover_instagram" ? preds.length - completePreds().length : 0;
|
| 479 |
+
|
| 480 |
const heldNote = (): string => {
|
| 481 |
+
const held = heldCount();
|
|
|
|
| 482 |
if (held < 1) return "";
|
| 483 |
return `Saved β ${held} condition${held === 1 ? " was" : "s were"} not saved yet, `
|
| 484 |
+ `${held === 1 ? "it needs" : "they need"} a value.`;
|
|
|
|
| 567 |
config: buildConfig(),
|
| 568 |
schedule: { cron: next.cron, enabled: next.enabled },
|
| 569 |
});
|
| 570 |
+
setTouched(false);
|
| 571 |
+
setMessage(heldNote());
|
| 572 |
+
await onSaved(automation.id);
|
| 573 |
} catch (e) {
|
| 574 |
setProblem(e instanceof AutomationError ? e.message : "That schedule was not saved.");
|
| 575 |
} finally {
|
|
|
|
| 604 |
trigger: { key },
|
| 605 |
schedule: { cron, enabled: key === "schedule" },
|
| 606 |
});
|
| 607 |
+
setTouched(false);
|
| 608 |
+
setMessage(heldNote());
|
| 609 |
+
await onSaved(automation.id);
|
| 610 |
} catch (e) {
|
| 611 |
setProblem(e instanceof AutomationError ? e.message : "That trigger was not saved.");
|
| 612 |
} finally {
|
|
|
|
| 633 |
setSaving(true);
|
| 634 |
setProblem("");
|
| 635 |
setMessage("");
|
| 636 |
+
try {
|
| 637 |
+
const id = await persist();
|
| 638 |
+
await onSaved(id);
|
| 639 |
} catch (e) {
|
| 640 |
setProblem(e instanceof AutomationError ? e.message : "That could not be saved.");
|
| 641 |
} finally {
|
|
|
|
| 648 |
* switch. Unsaved panel edits are persisted FIRST rather than being discarded
|
| 649 |
* by the reload that follows, which is the one way this could lose work.
|
| 650 |
*/
|
| 651 |
+
const flip = async (nodeId: string) => {
|
| 652 |
+
setProblem("");
|
| 653 |
setMessage("");
|
| 654 |
try {
|
| 655 |
+
if (touched) await persist(false);
|
| 656 |
+
await toggleNode(automation.id, nodeId);
|
| 657 |
+
await onSaved(automation.id);
|
| 658 |
+
} catch (e) {
|
| 659 |
+
setProblem(e instanceof AutomationError ? e.message : "That step was not changed.");
|
| 660 |
+
}
|
| 661 |
+
};
|
| 662 |
|
| 663 |
+
/**
|
| 664 |
+
* β WAVE 27 Β· OWNER ITEM 11 β **RUN NOW WRITES WHAT IS ON SCREEN.**
|
| 665 |
+
*
|
| 666 |
+
* β THE DEFECT, in the owner's words: *"I have to save twice"*. Every trigger-side control
|
| 667 |
+
* this panel owns β the discovery conditions (`preds`), the record limit, the and/or join,
|
| 668 |
+
* `maxPosts` β lives in LOCAL STATE until something calls `persist()`. `start()` called
|
| 669 |
+
* `runAutomation` directly, so pressing Run after editing a condition ran the automation
|
| 670 |
+
* against the config as it was BEFORE the edit, and the only tell was that pressing Save
|
| 671 |
+
* first made it behave. Two presses looked like a fussy UI; it was a run against stale
|
| 672 |
+
* config, and on a `discover_instagram` automation that is a PAID search of the wrong filter.
|
| 673 |
+
*
|
| 674 |
+
* β THE FIX IS `flip()`'s, VERBATIM (`:606`), and deliberately not a new discipline: a node
|
| 675 |
+
* switch already persisted unsaved panel edits before toggling, for exactly this reason, and
|
| 676 |
+
* the two buttons sit in the same header. `if (touched)` and not an unconditional PATCH β
|
| 677 |
+
* an untouched panel writing its config back would re-send `buildConfig()` on every Run,
|
| 678 |
+
* which is how a clamp or a validator default silently becomes a value the user never chose
|
| 679 |
+
* ([[default-must-pass-its-own-guard]]).
|
| 680 |
+
*
|
| 681 |
+
* β A FAILED FLUSH MUST NOT RUN. Both calls share one `try`, so a PATCH that 400s leaves the
|
| 682 |
+
* server's sentence on screen and `runAutomation` unreached β running anyway would spend
|
| 683 |
+
* money on precisely the config the server just refused.
|
| 684 |
+
*
|
| 685 |
+
* β AND THE HELD-BACK SENTENCE IS SAID HERE TOO. `persist(false)` suppresses `heldNote()`
|
| 686 |
+
* because `flip()` had nothing to add to it; this path does. `completePreds()` withholds a
|
| 687 |
+
* condition that has a comparison and no value yet, so a Run pressed mid-edit legitimately
|
| 688 |
+
* searches WITHOUT it β silence there would be the module's own drop class (see `heldNote`),
|
| 689 |
+
* and it is worse on this button than on any other because this one is the one that bills.
|
| 690 |
+
*/
|
| 691 |
const start = async () => {
|
| 692 |
setProblem("");
|
| 693 |
try {
|
| 694 |
+
if (touched) await persist(false);
|
| 695 |
await runAutomation(automation.id);
|
| 696 |
+
const held = heldCount();
|
| 697 |
+
setMessage(
|
| 698 |
+
held < 1
|
| 699 |
+
? "Started. The node dots follow it."
|
| 700 |
+
: `Started β running without ${held} condition${held === 1 ? "" : "s"} that still `
|
| 701 |
+
+ `${held === 1 ? "needs" : "need"} a value.`
|
| 702 |
+
);
|
| 703 |
await onSaved(automation.id);
|
| 704 |
} catch (e) {
|
| 705 |
setProblem(e instanceof AutomationError ? e.message : "It did not start.");
|
|
|
|
| 774 |
setTriggerBusy(true);
|
| 775 |
setProblem("");
|
| 776 |
setMessage("");
|
| 777 |
+
try {
|
| 778 |
+
await patchAutomation(automation.id, body);
|
| 779 |
+
await onSaved(automation.id);
|
| 780 |
} catch (e) {
|
| 781 |
// β THE SERVER'S SENTENCE, VERBATIM. `clean_flow` refuses an empty group, an unready
|
| 782 |
// action kind, a valueless compare β each with a reason worth reading. A client that
|
|
|
|
| 1166 |
on that point and the consequence (no name in the Board view) is booked, not patched.
|
| 1167 |
*/}
|
| 1168 |
<div className="auto-head-title">
|
| 1169 |
+
<span className="autox-view is-on">Builder</span>
|
| 1170 |
</div>
|
| 1171 |
<div className="auto-head-actions">
|
| 1172 |
{/*
|
|
|
|
| 1241 |
engine's own steps AND what the owner added, from data the rail already had) and there
|
| 1242 |
is no longer a state in which the reader gets it by accident.
|
| 1243 |
*/}
|
| 1244 |
+
<>
|
| 1245 |
<AutomationBuilder
|
| 1246 |
automation={automation}
|
| 1247 |
// ITEM 15b β the name left the header, and this is where it went. Three REQUIRED
|
|
|
|
| 1296 |
// ONE cron round-trip, rendered inside the Properties panel with its own picker
|
| 1297 |
// suppressed β the builder supplies the "Trigger type" select above it.
|
| 1298 |
scheduleFace={scheduleFace}
|
| 1299 |
+
// β WAVE 27 Β· C11 β the panel switch and its state, both owned here.
|
| 1300 |
+
showProperties={aside === "properties"}
|
| 1301 |
+
panelTabs={panelTabs}
|
| 1302 |
+
onStepPicked={() => setAside("properties")}
|
| 1303 |
+
/>
|
| 1304 |
+
{/* β THE RUN LOG IS UNMOUNTED WHEN HIDDEN, unlike Properties, and the asymmetry is
|
| 1305 |
+
deliberate rather than an oversight: this panel holds no editing state (its only
|
| 1306 |
+
local state, the drill-down, is this component's and survives), while re-mounting
|
| 1307 |
+
it re-reads nothing β the runs ride on `automation`. Properties keeps a half-typed
|
| 1308 |
+
name and cron, so hiding it has to leave it alive. */}
|
| 1309 |
+
<aside
|
| 1310 |
+
className="auto-panel is-appearing"
|
| 1311 |
+
aria-label="Run history"
|
| 1312 |
+
hidden={aside !== "runs"}
|
| 1313 |
+
>
|
| 1314 |
+
<>
|
| 1315 |
<div className="auto-panel-head">
|
| 1316 |
+
{panelTabs}
|
| 1317 |
</div>
|
| 1318 |
{!automation.runs?.length ? (
|
| 1319 |
<p className="auto-note">
|
|
|
|
| 1377 |
</li>
|
| 1378 |
))}
|
| 1379 |
</ol>
|
| 1380 |
+
)}
|
| 1381 |
+
<p className="auto-hint">
|
| 1382 |
+
Open a run to inspect the records it touched.
|
| 1383 |
+
</p>
|
| 1384 |
+
</>
|
| 1385 |
+
</aside>
|
| 1386 |
+
</>
|
| 1387 |
</div>
|
| 1388 |
</div>
|
| 1389 |
);
|
web/src/automation/AutomationFind.tsx
CHANGED
|
@@ -1,763 +1,893 @@
|
|
| 1 |
-
// ---------------------------------------------------------------------------
|
| 2 |
-
// automation/AutomationFind.tsx β the discovery filter, as TOGGLES (owner item 6,
|
| 3 |
-
// contract C4).
|
| 4 |
-
//
|
| 5 |
-
// WHAT CHANGED AND WHY. It was a condition BUILDER: an empty row, a field
|
| 6 |
-
// dropdown listing 21 names, "Add a condition". That shape asks the user to
|
| 7 |
-
// remember what is searchable before they can look, and it hid the only fact
|
| 8 |
-
// that decides whether a search returns anything at all β which fields actually
|
| 9 |
-
// carry values. The corpus is 620 million profiles and every run is billed, so
|
| 10 |
-
// "I did not know I could filter on that" and "I filtered on a field that is
|
| 11 |
-
// empty on every row" are both expensive mistakes made in silence.
|
| 12 |
-
//
|
| 13 |
-
// So every searchable field is ON SCREEN, off by default, and turning one on is
|
| 14 |
-
// what creates its condition. The list leads with the fields MEASURED to carry
|
| 15 |
-
// values; the rest are grouped under what is known about them, and neither group
|
| 16 |
-
// is hidden β R3 already decided that "every filter" means the 21 we can stand
|
| 17 |
-
// behind, so all 21 are visible.
|
| 18 |
-
//
|
| 19 |
-
// β THE VOCABULARY IS THE SERVER'S, ALL OF IT. Field names, operators, which
|
| 20 |
-
// operators take no value, the record ceiling and (once C4 lands it) which
|
| 21 |
-
// fields are populated and which narrow β every one of those rides on
|
| 22 |
-
// `GET /automations`. This file holds no list of its own. The reason is the one
|
| 23 |
-
// `automationApi.ts:11-15` gives for cron presets: the thing that ACCEPTS a
|
| 24 |
-
// filter is Python, and a client copy of what it accepts is a copy that can
|
| 25 |
-
// offer a search the server refuses.
|
| 26 |
-
//
|
| 27 |
-
// β AND IT DOES NOT RE-IMPLEMENT THE GUARD. `guard` carries the server's
|
| 28 |
-
// numbers, so the rows can say which fields narrow β but the refusal is the
|
| 29 |
-
// server's to make and this surface prints it VERBATIM when it comes back
|
| 30 |
-
// (`DiscoverGuard`'s note). A client that predicts the refusal is a second copy
|
| 31 |
-
// of the rule, free to disagree with the first, and when they disagree the user
|
| 32 |
-
// gets a Save button that is disabled for a reason nobody can see.
|
| 33 |
-
// ---------------------------------------------------------------------------
|
| 34 |
-
import { useEffect, useState } from "react";
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
*
|
| 65 |
-
*
|
| 66 |
-
*
|
| 67 |
-
*
|
| 68 |
-
*
|
| 69 |
-
*
|
| 70 |
-
*
|
| 71 |
-
*
|
| 72 |
-
*
|
| 73 |
-
*
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
<svg
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
<
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
<svg
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
<svg
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
<
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
<svg
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
<
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
}
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
*
|
| 233 |
-
*
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
return text;
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
/
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
*
|
| 250 |
-
*
|
| 251 |
-
*
|
| 252 |
-
*
|
| 253 |
-
*
|
| 254 |
-
*
|
| 255 |
-
*
|
| 256 |
-
*
|
| 257 |
-
*
|
| 258 |
-
*
|
| 259 |
-
*
|
| 260 |
-
*
|
| 261 |
-
*
|
| 262 |
-
*
|
| 263 |
-
*
|
| 264 |
-
*
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
*
|
| 277 |
-
*
|
| 278 |
-
*
|
| 279 |
-
*
|
| 280 |
-
*
|
| 281 |
-
*
|
| 282 |
-
*
|
| 283 |
-
*
|
| 284 |
-
*
|
| 285 |
-
*
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
*
|
| 298 |
-
*
|
| 299 |
-
*
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
}
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
const
|
| 352 |
-
const
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
//
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
*
|
| 376 |
-
*
|
| 377 |
-
*
|
| 378 |
-
*
|
| 379 |
-
*
|
| 380 |
-
*
|
| 381 |
-
*
|
| 382 |
-
*
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
}
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
const
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
const
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
/
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
{
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
|
| 615 |
-
|
| 616 |
-
|
| 617 |
-
|
| 618 |
-
|
| 619 |
-
|
| 620 |
-
|
| 621 |
-
|
| 622 |
-
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
|
| 626 |
-
|
| 627 |
-
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
|
| 635 |
-
|
| 636 |
-
|
| 637 |
-
</
|
| 638 |
-
</
|
| 639 |
-
|
| 640 |
-
</div>
|
| 641 |
-
);
|
| 642 |
-
};
|
| 643 |
-
|
| 644 |
-
|
| 645 |
-
|
| 646 |
-
|
| 647 |
-
|
| 648 |
-
<
|
| 649 |
-
|
| 650 |
-
|
| 651 |
-
|
| 652 |
-
|
| 653 |
-
|
| 654 |
-
|
| 655 |
-
|
| 656 |
-
|
| 657 |
-
|
| 658 |
-
|
| 659 |
-
|
| 660 |
-
|
| 661 |
-
|
| 662 |
-
|
| 663 |
-
|
| 664 |
-
|
| 665 |
-
|
| 666 |
-
|
| 667 |
-
|
| 668 |
-
className="
|
| 669 |
-
|
| 670 |
-
|
| 671 |
-
|
| 672 |
-
|
| 673 |
-
|
| 674 |
-
|
| 675 |
-
|
| 676 |
-
|
| 677 |
-
|
| 678 |
-
|
| 679 |
-
|
| 680 |
-
|
| 681 |
-
|
| 682 |
-
|
| 683 |
-
|
| 684 |
-
|
| 685 |
-
|
| 686 |
-
|
| 687 |
-
|
| 688 |
-
|
| 689 |
-
|
| 690 |
-
|
| 691 |
-
|
| 692 |
-
</div>
|
| 693 |
-
|
| 694 |
-
|
| 695 |
-
|
| 696 |
-
|
| 697 |
-
|
| 698 |
-
|
| 699 |
-
|
| 700 |
-
|
| 701 |
-
|
| 702 |
-
|
| 703 |
-
|
| 704 |
-
|
| 705 |
-
|
| 706 |
-
</
|
| 707 |
-
|
| 708 |
-
|
| 709 |
-
|
| 710 |
-
|
| 711 |
-
|
| 712 |
-
|
| 713 |
-
|
| 714 |
-
|
| 715 |
-
|
| 716 |
-
|
| 717 |
-
|
| 718 |
-
|
| 719 |
-
|
| 720 |
-
|
| 721 |
-
|
| 722 |
-
|
| 723 |
-
|
| 724 |
-
|
| 725 |
-
|
| 726 |
-
|
| 727 |
-
|
| 728 |
-
|
| 729 |
-
|
| 730 |
-
|
| 731 |
-
|
| 732 |
-
|
| 733 |
-
</
|
| 734 |
-
|
| 735 |
-
|
| 736 |
-
|
| 737 |
-
|
| 738 |
-
|
| 739 |
-
|
| 740 |
-
|
| 741 |
-
|
| 742 |
-
|
| 743 |
-
<
|
| 744 |
-
|
| 745 |
-
|
| 746 |
-
|
| 747 |
-
|
| 748 |
-
|
| 749 |
-
|
| 750 |
-
|
| 751 |
-
|
| 752 |
-
|
| 753 |
-
|
| 754 |
-
|
| 755 |
-
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
<
|
| 759 |
-
|
| 760 |
-
|
| 761 |
-
|
| 762 |
-
|
| 763 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ---------------------------------------------------------------------------
|
| 2 |
+
// automation/AutomationFind.tsx β the discovery filter, as TOGGLES (owner item 6,
|
| 3 |
+
// contract C4).
|
| 4 |
+
//
|
| 5 |
+
// WHAT CHANGED AND WHY. It was a condition BUILDER: an empty row, a field
|
| 6 |
+
// dropdown listing 21 names, "Add a condition". That shape asks the user to
|
| 7 |
+
// remember what is searchable before they can look, and it hid the only fact
|
| 8 |
+
// that decides whether a search returns anything at all β which fields actually
|
| 9 |
+
// carry values. The corpus is 620 million profiles and every run is billed, so
|
| 10 |
+
// "I did not know I could filter on that" and "I filtered on a field that is
|
| 11 |
+
// empty on every row" are both expensive mistakes made in silence.
|
| 12 |
+
//
|
| 13 |
+
// So every searchable field is ON SCREEN, off by default, and turning one on is
|
| 14 |
+
// what creates its condition. The list leads with the fields MEASURED to carry
|
| 15 |
+
// values; the rest are grouped under what is known about them, and neither group
|
| 16 |
+
// is hidden β R3 already decided that "every filter" means the 21 we can stand
|
| 17 |
+
// behind, so all 21 are visible.
|
| 18 |
+
//
|
| 19 |
+
// β THE VOCABULARY IS THE SERVER'S, ALL OF IT. Field names, operators, which
|
| 20 |
+
// operators take no value, the record ceiling and (once C4 lands it) which
|
| 21 |
+
// fields are populated and which narrow β every one of those rides on
|
| 22 |
+
// `GET /automations`. This file holds no list of its own. The reason is the one
|
| 23 |
+
// `automationApi.ts:11-15` gives for cron presets: the thing that ACCEPTS a
|
| 24 |
+
// filter is Python, and a client copy of what it accepts is a copy that can
|
| 25 |
+
// offer a search the server refuses.
|
| 26 |
+
//
|
| 27 |
+
// β AND IT DOES NOT RE-IMPLEMENT THE GUARD. `guard` carries the server's
|
| 28 |
+
// numbers, so the rows can say which fields narrow β but the refusal is the
|
| 29 |
+
// server's to make and this surface prints it VERBATIM when it comes back
|
| 30 |
+
// (`DiscoverGuard`'s note). A client that predicts the refusal is a second copy
|
| 31 |
+
// of the rule, free to disagree with the first, and when they disagree the user
|
| 32 |
+
// gets a Save button that is disabled for a reason nobody can see.
|
| 33 |
+
// ---------------------------------------------------------------------------
|
| 34 |
+
import { useEffect, useState } from "react";
|
| 35 |
+
// β WAVE 27 item 29 β the overlay layer the grid already owns, consumed rather than
|
| 36 |
+
// re-implemented: it is a body portal (so it escapes `.auto-panel`'s 380px), and it brings
|
| 37 |
+
// the dismiss/focus/placement behaviour every other popover on this product already has.
|
| 38 |
+
import { AnchoredOverlay } from "../customer-grid/OverlaySurface";
|
| 39 |
+
import type { AnchorRect } from "../customer-grid/OverlaySurface";
|
| 40 |
+
|
| 41 |
+
import type {
|
| 42 |
+
DiscoverEstimate,
|
| 43 |
+
DiscoverFieldMeta,
|
| 44 |
+
DiscoverOperator,
|
| 45 |
+
DiscoverVocab,
|
| 46 |
+
Predicate,
|
| 47 |
+
} from "./automationApi";
|
| 48 |
+
import { discoverCategories } from "./automationApi";
|
| 49 |
+
|
| 50 |
+
interface Props {
|
| 51 |
+
/** The server-declared discovery vocabulary (absent until the list loads). */
|
| 52 |
+
discover?: DiscoverVocab;
|
| 53 |
+
recordsLimit: number;
|
| 54 |
+
onRecordsLimit: (n: number) => void;
|
| 55 |
+
joinOp: string;
|
| 56 |
+
onJoinOp: (v: string) => void;
|
| 57 |
+
preds: Predicate[];
|
| 58 |
+
onPreds: (next: Predicate[]) => void;
|
| 59 |
+
estimate: DiscoverEstimate | null;
|
| 60 |
+
onEstimate: () => void;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
/**
|
| 64 |
+
* A FILTER FIELD'S ICON (owner item 5). Drawn, `currentColor`, never an emoji β and in the
|
| 65 |
+
* existing `TriggerMark`/`ActionMark` language rather than a new one: same 16 viewBox, same 15px
|
| 66 |
+
* box, same 1.4 stroke, so a row here and a card in the builder read as one product.
|
| 67 |
+
*
|
| 68 |
+
* β SHARED SHAPES WHERE THE FIELDS SHARE A MEANING, distinct everywhere else. `TriggerMark`'s
|
| 69 |
+
* note settled the principle β a column of identical glyphs is decoration, the eye learns nothing
|
| 70 |
+
* β but its converse matters just as much here: `bio_hashtags` and `post_hashtags` ARE both
|
| 71 |
+
* hashtags, and drawing two different marks for them would invent a distinction the vendor does
|
| 72 |
+
* not make. Twenty-one contrived glyphs would be twenty-one things to misread.
|
| 73 |
+
*
|
| 74 |
+
* β THE FALLBACK IS NOT A MEMBER OF THE SET, which is the `ActionMark` scar exactly: its default
|
| 75 |
+
* used to BE the pencil, a real member, so every unmatched kind silently borrowed "edit" and a
|
| 76 |
+
* fallback could not be told from a match. The vocabulary is the SERVER's β it can grow a field
|
| 77 |
+
* tomorrow β so an unmatched name draws a neutral mark that is deliberately meaningless.
|
| 78 |
+
*/
|
| 79 |
+
function FilterMark({ name }: { name: string }) {
|
| 80 |
+
const common = {
|
| 81 |
+
width: 15, height: 15, viewBox: "0 0 16 16", fill: "none", stroke: "currentColor",
|
| 82 |
+
strokeWidth: 1.4, strokeLinecap: "round" as const, strokeLinejoin: "round" as const,
|
| 83 |
+
"aria-hidden": true,
|
| 84 |
+
};
|
| 85 |
+
// Audience size β two figures, one behind the other.
|
| 86 |
+
if (name === "followers")
|
| 87 |
+
return (
|
| 88 |
+
<svg {...common}>
|
| 89 |
+
<circle cx="6.2" cy="5.6" r="2.4" />
|
| 90 |
+
<path d="M2.2 13c.5-2 2.1-3.2 4-3.2s3.5 1.2 4 3.2" />
|
| 91 |
+
<path d="M10.6 3.6a2.4 2.4 0 0 1 0 4M11.4 9.9c1.4.4 2.4 1.5 2.8 3.1" />
|
| 92 |
+
</svg>
|
| 93 |
+
);
|
| 94 |
+
// Who this account follows β a figure with an outbound arrow.
|
| 95 |
+
if (name === "following")
|
| 96 |
+
return (
|
| 97 |
+
<svg {...common}>
|
| 98 |
+
<circle cx="6" cy="5.6" r="2.4" />
|
| 99 |
+
<path d="M1.8 13c.5-2 2.1-3.2 4.2-3.2 .6 0 1.2.1 1.7.3" />
|
| 100 |
+
<path d="M9.8 10.6h4.2M12.2 8.8l1.8 1.8-1.8 1.8" />
|
| 101 |
+
</svg>
|
| 102 |
+
);
|
| 103 |
+
if (name === "posts_count")
|
| 104 |
+
return (
|
| 105 |
+
<svg {...common}>
|
| 106 |
+
<rect x="2.6" y="2.6" width="4.6" height="4.6" rx="1" />
|
| 107 |
+
<rect x="8.8" y="2.6" width="4.6" height="4.6" rx="1" />
|
| 108 |
+
<rect x="2.6" y="8.8" width="4.6" height="4.6" rx="1" />
|
| 109 |
+
<rect x="8.8" y="8.8" width="4.6" height="4.6" rx="1" />
|
| 110 |
+
</svg>
|
| 111 |
+
);
|
| 112 |
+
// A story highlight β the ring Instagram draws around one.
|
| 113 |
+
if (name === "highlights_count")
|
| 114 |
+
return (
|
| 115 |
+
<svg {...common}>
|
| 116 |
+
<circle cx="8" cy="8" r="5.6" strokeDasharray="2.6 1.8" />
|
| 117 |
+
<circle cx="8" cy="8" r="2.2" />
|
| 118 |
+
</svg>
|
| 119 |
+
);
|
| 120 |
+
if (name === "avg_engagement")
|
| 121 |
+
return (
|
| 122 |
+
<svg {...common}>
|
| 123 |
+
<path d="M8 13.2 3.4 8.8a2.9 2.9 0 0 1 4.6-3.4 2.9 2.9 0 0 1 4.6 3.4z" />
|
| 124 |
+
</svg>
|
| 125 |
+
);
|
| 126 |
+
if (name === "biography")
|
| 127 |
+
return (
|
| 128 |
+
<svg {...common}>
|
| 129 |
+
<rect x="2.4" y="2.8" width="11.2" height="10.4" rx="1.6" />
|
| 130 |
+
<path d="M4.8 6h6.4M4.8 8.4h6.4M4.8 10.8h3.6" />
|
| 131 |
+
</svg>
|
| 132 |
+
);
|
| 133 |
+
if (name === "category_name" || name === "business_category_name")
|
| 134 |
+
return (
|
| 135 |
+
<svg {...common}>
|
| 136 |
+
<path d="M8.4 2.6H13v4.6l-6.2 6.2-4.6-4.6z" />
|
| 137 |
+
<circle cx="10.8" cy="5.2" r="0.9" />
|
| 138 |
+
</svg>
|
| 139 |
+
);
|
| 140 |
+
if (name === "is_business_account" || name === "is_professional_account")
|
| 141 |
+
return (
|
| 142 |
+
<svg {...common}>
|
| 143 |
+
<rect x="2.2" y="5" width="11.6" height="8.2" rx="1.6" />
|
| 144 |
+
<path d="M6 5V3.6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1V5" />
|
| 145 |
+
</svg>
|
| 146 |
+
);
|
| 147 |
+
if (name === "is_verified")
|
| 148 |
+
return (
|
| 149 |
+
<svg {...common}>
|
| 150 |
+
<path d="M8 2.2l1.7 1.2 2-.2.6 2 1.7 1.1-.9 1.9.9 1.9-1.7 1.1-.6 2-2-.2L8 14.2l-1.7-1.2-2 .2-.6-2L2 10.1l.9-1.9L2 6.3l1.7-1.1.6-2 2 .2z" />
|
| 151 |
+
<path d="m5.8 8.1 1.5 1.5 3-3.1" />
|
| 152 |
+
</svg>
|
| 153 |
+
);
|
| 154 |
+
// The handle, and the display name it is written under.
|
| 155 |
+
if (name === "account" || name === "profile_name")
|
| 156 |
+
return (
|
| 157 |
+
<svg {...common}>
|
| 158 |
+
<circle cx="8" cy="8" r="2.4" />
|
| 159 |
+
<path d="M10.4 5.6v3.2a1.9 1.9 0 0 0 3.2 1.3A5.8 5.8 0 1 0 11 13.1" />
|
| 160 |
+
</svg>
|
| 161 |
+
);
|
| 162 |
+
if (name === "full_name")
|
| 163 |
+
return (
|
| 164 |
+
<svg {...common}>
|
| 165 |
+
<circle cx="8" cy="5.6" r="2.6" />
|
| 166 |
+
<path d="M3 13.4c.7-2.3 2.6-3.6 5-3.6s4.3 1.3 5 3.6" />
|
| 167 |
+
</svg>
|
| 168 |
+
);
|
| 169 |
+
if (name === "external_url" || name === "profile_url")
|
| 170 |
+
return (
|
| 171 |
+
<svg {...common}>
|
| 172 |
+
<path d="M6.6 9.4 4.9 11a2.6 2.6 0 1 1-1.5-4.4" />
|
| 173 |
+
<path d="M9.4 6.6 11.1 5a2.6 2.6 0 1 1 1.5 4.4" />
|
| 174 |
+
<path d="M6.2 8h3.6" />
|
| 175 |
+
</svg>
|
| 176 |
+
);
|
| 177 |
+
if (name === "bio_hashtags" || name === "post_hashtags")
|
| 178 |
+
return (
|
| 179 |
+
<svg {...common}>
|
| 180 |
+
<path d="M6.2 2.8 4.8 13.2M11.2 2.8 9.8 13.2M2.8 6h10.4M2.2 10h10.4" />
|
| 181 |
+
</svg>
|
| 182 |
+
);
|
| 183 |
+
if (name === "related_accounts")
|
| 184 |
+
return (
|
| 185 |
+
<svg {...common}>
|
| 186 |
+
<circle cx="8" cy="3.6" r="1.8" />
|
| 187 |
+
<circle cx="3.6" cy="12" r="1.8" />
|
| 188 |
+
<circle cx="12.4" cy="12" r="1.8" />
|
| 189 |
+
<path d="M6.8 5.2 4.6 10.4M9.2 5.2l2.2 5.2M5.4 12h5.2" />
|
| 190 |
+
</svg>
|
| 191 |
+
);
|
| 192 |
+
// The vendor's own record keys β the thing you hold to open exactly one row.
|
| 193 |
+
if (name === "id" || name === "fbid")
|
| 194 |
+
return (
|
| 195 |
+
<svg {...common}>
|
| 196 |
+
<circle cx="5.4" cy="10.6" r="2.6" />
|
| 197 |
+
<path d="M7.2 8.8 13 3M10.6 5.4l1.6 1.6M9.2 6.8l1.6 1.6" />
|
| 198 |
+
</svg>
|
| 199 |
+
);
|
| 200 |
+
return (
|
| 201 |
+
<svg {...common}>
|
| 202 |
+
<rect x="3.2" y="3.2" width="9.6" height="9.6" rx="2.2" />
|
| 203 |
+
<circle cx="8" cy="8" r="1.4" />
|
| 204 |
+
</svg>
|
| 205 |
+
);
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
/** One field's line in the list, with everything known about it. */
|
| 209 |
+
interface FieldRow {
|
| 210 |
+
name: string;
|
| 211 |
+
/** What the row is CALLED. Falls back to the raw name only if the server sent none. */
|
| 212 |
+
label: string;
|
| 213 |
+
hint: string;
|
| 214 |
+
kind: string;
|
| 215 |
+
operators: DiscoverOperator[];
|
| 216 |
+
options: { value: string; label: string }[];
|
| 217 |
+
/** Every stored condition naming this field, with its index in the saved array. */
|
| 218 |
+
at: number[];
|
| 219 |
+
/** MEASURED to carry values. `null` = the server has not said (C4 not shipped yet). */
|
| 220 |
+
populated: boolean | null;
|
| 221 |
+
/** A condition here cuts the corpus down. `null` = not said. */
|
| 222 |
+
narrowing: boolean | null;
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
/** A stored value β what the text box shows. A list is the "any of" shape. */
|
| 226 |
+
function valueText(v: Predicate["value"]): string {
|
| 227 |
+
if (Array.isArray(v)) return v.join(", ");
|
| 228 |
+
return v === undefined || v === null ? "" : String(v);
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
/**
|
| 232 |
+
* What the user typed β what is stored. Comma-separated becomes a LIST for the operators that
|
| 233 |
+
* accept one, and stays a plain string for the ones that do not.
|
| 234 |
+
*
|
| 235 |
+
* β A single value stays a SCALAR rather than a one-element list β the server sends scalars
|
| 236 |
+
* flat and lists as a nested OR group, and a one-element group is a shape nothing has been
|
| 237 |
+
* billed against.
|
| 238 |
+
*/
|
| 239 |
+
function parseValue(text: string, multi: boolean): Predicate["value"] {
|
| 240 |
+
if (!multi) return text;
|
| 241 |
+
const parts = text.split(",").map((s) => s.trim()).filter(Boolean);
|
| 242 |
+
if (parts.length > 1) return parts;
|
| 243 |
+
// Keep the RAW text while it is still being typed β trimming here would fight the cursor on
|
| 244 |
+
// every keystroke, and the server trims anyway.
|
| 245 |
+
return text;
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
/**
|
| 249 |
+
* β WAVE 26 Β· DEBT D-69 β A THIRD VALUE COULD NOT BE TYPED, and the cause was one round trip
|
| 250 |
+
* through this pair of functions.
|
| 251 |
+
*
|
| 252 |
+
* `parseValue` returns an ARRAY at 2+ values; `valueText` then renders that array as
|
| 253 |
+
* `join(", ")` β which has NO TRAILING COMMA. So on a controlled input the separator was
|
| 254 |
+
* normalised away between keystrokes: typing `,` onto `skincare, beauty` re-rendered as
|
| 255 |
+
* `skincare, beauty`, and the next character landed as `skincare, beautym`. Two keywords
|
| 256 |
+
* silently became one that matches nothing. β It hit the FIRST surface a new user meets (wave 24
|
| 257 |
+
* made this panel the only door) and it hit precisely the 3+ keyword list the feature was built
|
| 258 |
+
* for β the owner's *"if i want to include many keywords like floral, flower, beauty"*.
|
| 259 |
+
*
|
| 260 |
+
* β THE FIX IS THE ONE `parseValue`'s OWN COMMENT ALREADY DESCRIBES FOR THE 1-VALUE CASE:
|
| 261 |
+
* keep the raw text while it is being typed. That comment was right and its scope was too narrow
|
| 262 |
+
* β it protected the cursor at one value and handed the 2+ case to `join`. So the raw text is
|
| 263 |
+
* held for whichever input is FOCUSED, and the stored value is still parsed on every keystroke
|
| 264 |
+
* (so nothing depends on blur to save) and re-parsed on blur (so the display settles).
|
| 265 |
+
*
|
| 266 |
+
* β KEYED BY THE ROW'S REACT KEY, not by index alone: two conditions on the same field are
|
| 267 |
+
* ordinary here ("Another condition on Bio"), and an index-only key would leak one row's draft
|
| 268 |
+
* into its sibling on a removal.
|
| 269 |
+
*/
|
| 270 |
+
interface Draft {
|
| 271 |
+
key: string;
|
| 272 |
+
text: string;
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
/**
|
| 276 |
+
* The comparison a freshly toggled field starts with β ASKED FOR, never chosen here.
|
| 277 |
+
*
|
| 278 |
+
* β THE THIRD COSTUME OF ONE SCAR, and the reason this function no longer has an opinion.
|
| 279 |
+
* Wave 21 made a new condition NULLARY (`is_not_null`) so it would be saveable without a
|
| 280 |
+
* value, and called that "narrowing-in-the-right-direction". Wave 22 then wrote the narrowing
|
| 281 |
+
* law server-side and `is_not_null` is not in it. From that moment, toggling ANY field on and
|
| 282 |
+
* pressing Save returned "add at least one CONTENT conditionβ¦" β the error told the user to do
|
| 283 |
+
* the exact thing they had just done. Wave 24 deleted the wizard and made this panel the only
|
| 284 |
+
* door, so it stopped being a corner case and became the first thing a new user hits.
|
| 285 |
+
*
|
| 286 |
+
* The fix is not a better guess. It is that the module owning the guard also names the default
|
| 287 |
+
* (`automation_engine.default_operator`, asserted against `predicate_narrows` in
|
| 288 |
+
* `verify_automation.py`), and this file looks it up per FIELD. An absent one falls back to the
|
| 289 |
+
* server's first operator β never to a nullary, which is the thing that could not narrow.
|
| 290 |
+
*/
|
| 291 |
+
function firstOperator(v: DiscoverVocab | undefined, name: string): string {
|
| 292 |
+
const meta = (v?.filterMeta || []).find((m) => m.name === name);
|
| 293 |
+
return meta?.defaultOperator || (v?.operators || [])[0] || "";
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
/**
|
| 297 |
+
* The rows, ordered: measured-populated first, then the rest.
|
| 298 |
+
*
|
| 299 |
+
* TWO SOURCES, AND THE FALLBACK IS NARROWER THAN THE REAL THING. With C4's
|
| 300 |
+
* `filterMeta` the answer is per field and complete. Without it, `lead` names
|
| 301 |
+
* the three fields seen carrying values and says NOTHING about the other
|
| 302 |
+
* eighteen β so those come back `null`, not `false`, and the UI prints no claim
|
| 303 |
+
* about them rather than an invented one.
|
| 304 |
+
*/
|
| 305 |
+
function buildRows(preds: Predicate[], v?: DiscoverVocab): FieldRow[] {
|
| 306 |
+
const meta = new Map<string, DiscoverFieldMeta>(
|
| 307 |
+
(v?.filterMeta || []).map((m) => [m.name, m])
|
| 308 |
+
);
|
| 309 |
+
const lead = new Set(v?.lead || []);
|
| 310 |
+
const byName = new Map<string, number[]>();
|
| 311 |
+
preds.forEach((p, i) => {
|
| 312 |
+
const list = byName.get(p.name);
|
| 313 |
+
if (list) list.push(i);
|
| 314 |
+
else byName.set(p.name, [i]);
|
| 315 |
+
});
|
| 316 |
+
|
| 317 |
+
const rows = (v?.fields || []).map((name) => {
|
| 318 |
+
const m = meta.get(name);
|
| 319 |
+
return {
|
| 320 |
+
name,
|
| 321 |
+
label: m?.label || name,
|
| 322 |
+
hint: m?.hint || "",
|
| 323 |
+
kind: m?.kind || "text",
|
| 324 |
+
// β NO FALLBACK TO THE GLOBAL OPERATOR LIST. An older server that sends no per-field list
|
| 325 |
+
// gets a row with no comparisons rather than all fourteen on every field β visibly
|
| 326 |
+
// unfinished beats quietly offering `at least` on a yes/no column.
|
| 327 |
+
operators: m?.operators || [],
|
| 328 |
+
options: m?.options || [],
|
| 329 |
+
at: byName.get(name) || [],
|
| 330 |
+
populated: m ? !!m.populated : lead.has(name) ? true : null,
|
| 331 |
+
narrowing: m ? !!m.narrowing : null,
|
| 332 |
+
};
|
| 333 |
+
});
|
| 334 |
+
// Stable partition, never a sort: the server's order inside each half is the
|
| 335 |
+
// order the engine lists them in, and re-alphabetising it would be this file
|
| 336 |
+
// having an opinion about a server list.
|
| 337 |
+
return [...rows.filter((r) => r.populated === true), ...rows.filter((r) => r.populated !== true)];
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
export default function AutomationFind({
|
| 341 |
+
discover,
|
| 342 |
+
recordsLimit,
|
| 343 |
+
onRecordsLimit,
|
| 344 |
+
joinOp,
|
| 345 |
+
onJoinOp,
|
| 346 |
+
preds,
|
| 347 |
+
onPreds,
|
| 348 |
+
estimate,
|
| 349 |
+
onEstimate,
|
| 350 |
+
}: Props) {
|
| 351 |
+
const rows = buildRows(preds, discover);
|
| 352 |
+
const known = new Set(discover?.fields || []);
|
| 353 |
+
// The GLOBAL operator list is gone from this component: comparisons are per field now
|
| 354 |
+
// (`row.operators`). `nullary` survives for STRAYS only β a stored condition on a field the
|
| 355 |
+
// vendor dropped has no per-field row to read from, and it still has to render to be removable.
|
| 356 |
+
const nullary = new Set(discover?.nullaryOperators || []);
|
| 357 |
+
const withValues = rows.filter((r) => r.populated === true);
|
| 358 |
+
const rest = rows.filter((r) => r.populated !== true);
|
| 359 |
+
const knownMeta = !!(discover?.filterMeta || []).length;
|
| 360 |
+
// β THE STORED FILTER CAN NAME A FIELD THE LIST NO LONGER HAS β a vocabulary
|
| 361 |
+
// that moved, an automation copied from elsewhere. It must stay VISIBLE and
|
| 362 |
+
// REMOVABLE: a condition the user cannot see is one they cannot delete, and
|
| 363 |
+
// every Save keeps sending it. Same defect as a `<select>` whose value matches
|
| 364 |
+
// no option, one level up.
|
| 365 |
+
const strays = preds
|
| 366 |
+
.map((p, i) => ({ p, i }))
|
| 367 |
+
.filter(({ p }) => !known.has(p.name));
|
| 368 |
+
|
| 369 |
+
const maxRecords = discover?.guard?.maxRecords || discover?.maxRecords || 500;
|
| 370 |
+
|
| 371 |
+
/** D-69 β the raw text of the input a person is typing in right now (see `Draft`). */
|
| 372 |
+
const [draft, setDraft] = useState<Draft | null>(null);
|
| 373 |
+
|
| 374 |
+
/**
|
| 375 |
+
* β WAVE 27 Β· OWNER ITEM 29 β which condition's value is open in the BIG editor, if any.
|
| 376 |
+
*
|
| 377 |
+
* β THE TEXT IS HELD HERE, NOT WRITTEN THROUGH ON EVERY KEYSTROKE, and that is the one place
|
| 378 |
+
* this differs from the rail input beside it. The rail input writes per keystroke on purpose
|
| 379 |
+
* (a Save pressed straight from the field must not store the previous value β D-69's note).
|
| 380 |
+
* A modal has its own Save, so per-keystroke writes would buy nothing and would make Cancel
|
| 381 |
+
* a lie: the value would already be in the config by the time it was pressed.
|
| 382 |
+
* β The ANCHOR is captured at click time and stored, because the button it came from is
|
| 383 |
+
* inside a panel that scrolls β re-reading it later would place the overlay against a rect
|
| 384 |
+
* that has moved.
|
| 385 |
+
*/
|
| 386 |
+
const [big, setBig] = useState<{
|
| 387 |
+
key: string;
|
| 388 |
+
index: number;
|
| 389 |
+
label: string;
|
| 390 |
+
multi: boolean;
|
| 391 |
+
text: string;
|
| 392 |
+
anchor: AnchorRect;
|
| 393 |
+
} | null>(null);
|
| 394 |
+
|
| 395 |
+
/**
|
| 396 |
+
* β ITEM 16 / D-71 β THE OBSERVED CATEGORY VALUES, fetched WHEN THIS PANEL OPENS.
|
| 397 |
+
*
|
| 398 |
+
* β ON MOUNT, ONCE, AND NEVER ON THE POLLED PAYLOAD. This component is rendered only while the
|
| 399 |
+
* Find panel is open, so mounting IS the panel opening β and the server moved these off
|
| 400 |
+
* `GET /automations` after measuring that deriving them reads two user tables plus the platform
|
| 401 |
+
* master, i.e. a network round-trip per open tab every 2.5 s. Putting the request here is the
|
| 402 |
+
* client half of that same decision, not an optimisation.
|
| 403 |
+
*
|
| 404 |
+
* β AN EMPTY LIST IS AN ANSWER AND IS RENDERED AS ONE. It means this deployment has not seen a
|
| 405 |
+
* category value yet β which is TRUE for a fresh tenant β and the field keeps its free-text
|
| 406 |
+
* input either way. It must never read as "loading forever", and it must never be filled in
|
| 407 |
+
* with a guess: D-59 is explicit that an invented taxonomy is worse than no dropdown.
|
| 408 |
+
*/
|
| 409 |
+
const [cats, setCats] = useState<{ value: string; count: number }[]>([]);
|
| 410 |
+
useEffect(() => {
|
| 411 |
+
const ac = new AbortController();
|
| 412 |
+
discoverCategories(ac.signal)
|
| 413 |
+
.then((r) => setCats(Array.isArray(r?.options) ? r.options : []))
|
| 414 |
+
// Fail-quiet, on purpose: the picker is an ASSIST over a control that works without it.
|
| 415 |
+
// An error banner here would report a broken panel when the only thing missing is a
|
| 416 |
+
// convenience β and the free-text input beside it is unaffected.
|
| 417 |
+
.catch(() => setCats([]));
|
| 418 |
+
return () => ac.abort();
|
| 419 |
+
}, []);
|
| 420 |
+
|
| 421 |
+
const setAt = (i: number, patch: Partial<Predicate>) =>
|
| 422 |
+
onPreds(preds.map((p, j) => (j === i ? { ...p, ...patch } : p)));
|
| 423 |
+
|
| 424 |
+
const removeAt = (i: number) => onPreds(preds.filter((_p, j) => j !== i));
|
| 425 |
+
|
| 426 |
+
const toggleField = (row: FieldRow) => {
|
| 427 |
+
if (row.at.length) {
|
| 428 |
+
onPreds(preds.filter((p) => p.name !== row.name));
|
| 429 |
+
return;
|
| 430 |
+
}
|
| 431 |
+
onPreds([...preds, { name: row.name, operator: firstOperator(discover, row.name) }]);
|
| 432 |
+
};
|
| 433 |
+
|
| 434 |
+
/** One condition line β the comparison, its value, and a way out. */
|
| 435 |
+
const condition = (i: number, label: string, row?: FieldRow) => {
|
| 436 |
+
const p = preds[i];
|
| 437 |
+
if (!p) return null;
|
| 438 |
+
// The field's OWN comparisons. `row` is absent only for a stray (a stored condition on a
|
| 439 |
+
// field the vendor no longer offers), which keeps the raw token so it stays removable.
|
| 440 |
+
const ops = row?.operators || [];
|
| 441 |
+
const cur = ops.find((o) => o.value === p.operator);
|
| 442 |
+
const isNullary = cur ? cur.nullary : nullary.has(p.operator);
|
| 443 |
+
const isMulti = !!cur?.multi;
|
| 444 |
+
const options = row?.options || [];
|
| 445 |
+
const rowKey = `${p.name}-${i}`;
|
| 446 |
+
// D-69: the focused input shows what was TYPED; every other one shows the stored value.
|
| 447 |
+
const shown = draft && draft.key === rowKey ? draft.text : valueText(p.value);
|
| 448 |
+
/*
|
| 449 |
+
* β ITEM 16 / D-71 β WHICH FIELDS GET THE OBSERVED-VALUES PICKER, DERIVED OFF THE WIRE.
|
| 450 |
+
*
|
| 451 |
+
* β NOT A CLIENT-SIDE LIST OF FIELD NAMES. Naming the vendor's two category columns here
|
| 452 |
+
* would be the D-55 class verbatim β the wave-9 silent-drop shape, a client copy of a server
|
| 453 |
+
* vocabulary that is free to drift the day the engine adds a third one. (Their literal keys
|
| 454 |
+
* are deliberately not written anywhere in this file: the gate asserts the tokens are ABSENT,
|
| 455 |
+
* and an absence check cannot tell a hard-coded list from the comment forbidding one.)
|
| 456 |
+
* The server already publishes the answer twice over: `kind: "choice"` is its own declaration
|
| 457 |
+
* (`BD_FIELD_KINDS`), and `filter_meta` deliberately ships `options: []` for those fields
|
| 458 |
+
* because their vocabulary is OBSERVED rather than declared and arrives on its own route.
|
| 459 |
+
* So the rule is exactly that: a choice-kind field with no declared options is one whose
|
| 460 |
+
* values we can only have learned by seeing them. A new choice field inherits this for free.
|
| 461 |
+
*/
|
| 462 |
+
const wantsObserved = row?.kind === "choice" && !options.length;
|
| 463 |
+
/** D-71 β APPEND, never replace: the picker has to compose with the comma list. */
|
| 464 |
+
const appendValue = (v: string) => {
|
| 465 |
+
const has = shown
|
| 466 |
+
.split(",")
|
| 467 |
+
.map((s) => s.trim().toLowerCase())
|
| 468 |
+
.filter(Boolean);
|
| 469 |
+
// Picking the same value twice is a no-op rather than a duplicate: the server expands a
|
| 470 |
+
// multi-value condition into an OR, and `beauty OR beauty` costs a slot to say nothing.
|
| 471 |
+
if (has.includes(v.trim().toLowerCase())) return;
|
| 472 |
+
const next = shown.trim() ? `${shown.replace(/[\s,]+$/, "")}, ${v}` : v;
|
| 473 |
+
setDraft(null);
|
| 474 |
+
setAt(i, { value: parseValue(next, isMulti) });
|
| 475 |
+
};
|
| 476 |
+
return (
|
| 477 |
+
<div className="autob-cond" key={rowKey}>
|
| 478 |
+
<select
|
| 479 |
+
className="auto-input is-small"
|
| 480 |
+
aria-label={`Comparison for ${label}`}
|
| 481 |
+
value={p.operator}
|
| 482 |
+
onChange={(e) => setAt(i, { operator: e.target.value })}
|
| 483 |
+
>
|
| 484 |
+
{/* The stored value is ALWAYS an option. A select whose value matches no
|
| 485 |
+
option renders the FIRST one, and the next Save writes a comparison
|
| 486 |
+
nobody chose β this codebase has paid for that twice. */}
|
| 487 |
+
{p.operator && !ops.some((o) => o.value === p.operator) ? (
|
| 488 |
+
<option value={p.operator}>{p.operator}</option>
|
| 489 |
+
) : null}
|
| 490 |
+
{ops.map((o) => (
|
| 491 |
+
<option key={o.value} value={o.value}>
|
| 492 |
+
{o.label}
|
| 493 |
+
</option>
|
| 494 |
+
))}
|
| 495 |
+
</select>
|
| 496 |
+
{isNullary ? null : options.length ? (
|
| 497 |
+
// A fixed vocabulary gets a dropdown. Owner item 2: a yes/no column was a box you
|
| 498 |
+
// typed `true` into, beside a comparison list that offered "at least".
|
| 499 |
+
<select
|
| 500 |
+
className="auto-input is-small"
|
| 501 |
+
aria-label={`Value for ${label}`}
|
| 502 |
+
value={valueText(p.value)}
|
| 503 |
+
onChange={(e) => setAt(i, { value: e.target.value })}
|
| 504 |
+
>
|
| 505 |
+
<option value="">Chooseβ¦</option>
|
| 506 |
+
{options.map((o) => (
|
| 507 |
+
<option key={o.value} value={o.value}>
|
| 508 |
+
{o.label}
|
| 509 |
+
</option>
|
| 510 |
+
))}
|
| 511 |
+
</select>
|
| 512 |
+
) : (
|
| 513 |
+
<input
|
| 514 |
+
className="auto-input is-small"
|
| 515 |
+
type={row?.kind === "number" ? "number" : "text"}
|
| 516 |
+
aria-label={`Value for ${label}`}
|
| 517 |
+
// β OWNER ITEM 3. Several comma-separated values become an "any of" condition, which
|
| 518 |
+
// the server sends as its own OR group β so it does NOT drag Followers into a union
|
| 519 |
+
// the way the Match dropdown would.
|
| 520 |
+
placeholder={isMulti ? "floral, flower, beauty" : ""}
|
| 521 |
+
// D-69: `shown` is the RAW text while this input has focus, so a trailing comma
|
| 522 |
+
// survives long enough to type the next value after it.
|
| 523 |
+
value={shown}
|
| 524 |
+
onFocus={() => setDraft({ key: rowKey, text: valueText(p.value) })}
|
| 525 |
+
onChange={(e) => {
|
| 526 |
+
setDraft({ key: rowKey, text: e.target.value });
|
| 527 |
+
// The STORE still updates on every keystroke. Parsing only on blur would mean a
|
| 528 |
+
// Save pressed straight from the field wrote the previous value β trading a typing
|
| 529 |
+
// bug for a data-loss one.
|
| 530 |
+
setAt(i, { value: parseValue(e.target.value, isMulti) });
|
| 531 |
+
}}
|
| 532 |
+
onBlur={(e) => {
|
| 533 |
+
setDraft(null);
|
| 534 |
+
setAt(i, { value: parseValue(e.target.value, isMulti) });
|
| 535 |
+
}}
|
| 536 |
+
/>
|
| 537 |
+
)}
|
| 538 |
+
{/* β WAVE 27 Β· OWNER ITEM 29 β A WIDE EDITOR FOR THE VALUES THAT DO NOT FIT.
|
| 539 |
+
β THE COMPLAINT IS GEOMETRY, and the geometry is a CHAIN nothing here can widen:
|
| 540 |
+
`.auto-panel` is 380px, `.autob-cond .auto-input` divides what is left across three
|
| 541 |
+
controls, and `.is-small` trims it again β so a bio phrase list ("floral, flower,
|
| 542 |
+
wedding florist, event styling") is typed six characters at a time through a box
|
| 543 |
+
that scrolls sideways. The panel cannot grow; the EDITOR can leave it, and an
|
| 544 |
+
overlay is drawn in a body portal, so it is not bound by that chain at all.
|
| 545 |
+
β ALWAYS OFFERED, never "appears once the text is long": a control that materialises
|
| 546 |
+
at some threshold is one people do not know exists at the moment they need it.
|
| 547 |
+
β NOT on a `<select>` value (a fixed vocabulary has nothing to expand) and not on a
|
| 548 |
+
nullary comparison (which has no value at all). */}
|
| 549 |
+
{!isNullary && !options.length ? (
|
| 550 |
+
<button
|
| 551 |
+
type="button"
|
| 552 |
+
className="auto-input is-small autoc-expand"
|
| 553 |
+
aria-label={`Open a bigger editor for ${label}`}
|
| 554 |
+
title="Edit in a bigger box"
|
| 555 |
+
onClick={(e) => {
|
| 556 |
+
// β READ SYNCHRONOUSLY from the event. `currentTarget` is null by the time React
|
| 557 |
+
// re-invokes a state updater, and a null rect here paints the overlay at 0,0 β
|
| 558 |
+
// measured, in this repo, on a different control ([[react-event-currenttarget-updater]]).
|
| 559 |
+
const r = e.currentTarget.getBoundingClientRect();
|
| 560 |
+
setBig({
|
| 561 |
+
key: rowKey,
|
| 562 |
+
index: i,
|
| 563 |
+
label,
|
| 564 |
+
multi: isMulti,
|
| 565 |
+
text: valueText(p.value),
|
| 566 |
+
anchor: { left: r.left, top: r.top, right: r.right, bottom: r.bottom,
|
| 567 |
+
width: r.width, height: r.height },
|
| 568 |
+
});
|
| 569 |
+
}}
|
| 570 |
+
>
|
| 571 |
+
{/* Drawn, never a glyph: the design constitution's "no emojis in the UI" covers
|
| 572 |
+
the arrow characters too, and every other mark in this product is a path in the
|
| 573 |
+
same 16x16 stroke vocabulary. Two corners pulling apart = "make this bigger". */}
|
| 574 |
+
<svg viewBox="0 0 16 16" aria-hidden className="autoc-expand-icon">
|
| 575 |
+
<path d="M9.5 2.5h4v4M13.5 2.5 9.6 6.4" />
|
| 576 |
+
<path d="M6.5 13.5h-4v-4M2.5 13.5l3.9-3.9" />
|
| 577 |
+
</svg>
|
| 578 |
+
</button>
|
| 579 |
+
) : null}
|
| 580 |
+
{/* β ITEM 16 / D-71 β THE APPEND-PICKER, BESIDE the input and never instead of it.
|
| 581 |
+
Free text stays the primary control: these are the values this deployment has SEEN,
|
| 582 |
+
not the values that exist, so the picker is a shortcut over a superset it cannot
|
| 583 |
+
enumerate. Appending in code also sidesteps D-69 entirely β a picked value never has
|
| 584 |
+
to survive a round trip through the text box. */}
|
| 585 |
+
{wantsObserved && !isNullary ? (
|
| 586 |
+
<select
|
| 587 |
+
className="auto-input is-small autoc-catpick"
|
| 588 |
+
aria-label={`Add a value seen before, to ${label}`}
|
| 589 |
+
title={
|
| 590 |
+
cats.length
|
| 591 |
+
? "Values this workspace has actually seen, most-seen first. Adds to the list."
|
| 592 |
+
: "No category values have been seen in your data yet β type one."
|
| 593 |
+
}
|
| 594 |
+
value=""
|
| 595 |
+
disabled={!cats.length}
|
| 596 |
+
onChange={(e) => {
|
| 597 |
+
if (e.target.value) appendValue(e.target.value);
|
| 598 |
+
}}
|
| 599 |
+
>
|
| 600 |
+
<option value="">{cats.length ? "Seen beforeβ¦" : "None seen yet"}</option>
|
| 601 |
+
{cats.map((c) => (
|
| 602 |
+
// The COUNT is the honest half (D-59): a value seen once and one seen forty times
|
| 603 |
+
// are different bets, and an alphabetical list of bare strings hides that.
|
| 604 |
+
<option key={c.value} value={c.value}>
|
| 605 |
+
{c.value} ({c.count.toLocaleString()})
|
| 606 |
+
</option>
|
| 607 |
+
))}
|
| 608 |
+
</select>
|
| 609 |
+
) : null}
|
| 610 |
+
{isMulti && Array.isArray(p.value) && p.value.length > 1 ? (
|
| 611 |
+
/*
|
| 612 |
+
* β ITEM 16 / D-71 β HOW MANY VALUES THIS CONDITION CARRIES, and against what ceiling.
|
| 613 |
+
*
|
| 614 |
+
* The COUNT is ours and is always shown. The CEILING is the server's and is shown only
|
| 615 |
+
* when the server sends one (`guard.maxValues` β an open `ASK ->A:`; `guard` ships
|
| 616 |
+
* `{minNarrowing, maxRecords}` today).
|
| 617 |
+
* β NO CLIENT-SIDE `4`. D-71's exit says "how many of D-68's 4 value slots" β but A
|
| 618 |
+
* shipped `depth_refusal()`, which computes the depth of the shape actually emitted
|
| 619 |
+
* rather than budgeting fixed slots, so the number 4 describes a model that no longer
|
| 620 |
+
* exists. Printing it would be a client copy of a server rule that has already changed
|
| 621 |
+
* once, which is the specific failure this file's header refuses to commit
|
| 622 |
+
* ([[measure-the-real-call]]: a correct-looking answer about the wrong subject).
|
| 623 |
+
*/
|
| 624 |
+
<span className="autob-cond-any" title="Any one of these is a match">
|
| 625 |
+
any of {p.value.length}
|
| 626 |
+
{discover?.guard?.maxValues ? ` of ${discover.guard.maxValues}` : ""}
|
| 627 |
+
</span>
|
| 628 |
+
) : null}
|
| 629 |
+
<button
|
| 630 |
+
type="button"
|
| 631 |
+
className="autob-cond-x"
|
| 632 |
+
aria-label={`Remove this condition on ${label}`}
|
| 633 |
+
title="Remove this condition"
|
| 634 |
+
onClick={() => removeAt(i)}
|
| 635 |
+
>
|
| 636 |
+
<svg width="12" height="12" viewBox="0 0 16 16" fill="none" aria-hidden="true">
|
| 637 |
+
<path d="M4 4l8 8M12 4l-8 8" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" />
|
| 638 |
+
</svg>
|
| 639 |
+
</button>
|
| 640 |
+
</div>
|
| 641 |
+
);
|
| 642 |
+
};
|
| 643 |
+
|
| 644 |
+
const fieldRow = (row: FieldRow) => {
|
| 645 |
+
const on = row.at.length > 0;
|
| 646 |
+
return (
|
| 647 |
+
<div className={"autob-tgl" + (on ? " is-on" : "")} key={row.name}>
|
| 648 |
+
<div className="autob-tgl-head">
|
| 649 |
+
<button
|
| 650 |
+
type="button"
|
| 651 |
+
className={"auto-step-switch autob-tgl-switch" + (on ? " is-on" : "")}
|
| 652 |
+
aria-pressed={on}
|
| 653 |
+
aria-label={`${on ? "Stop searching" : "Search"} on ${row.label}`}
|
| 654 |
+
title={`${on ? "Stop searching" : "Search"} on ${row.label}`}
|
| 655 |
+
onClick={() => toggleField(row)}
|
| 656 |
+
>
|
| 657 |
+
<span className="auto-step-switch-knob" />
|
| 658 |
+
</button>
|
| 659 |
+
<span className="autob-tgl-mark">
|
| 660 |
+
<FilterMark name={row.name} />
|
| 661 |
+
</span>
|
| 662 |
+
{/* β THE HUMAN LABEL (owner item 1: "wtf is id/fbid").
|
| 663 |
+
This used to render the vendor's own column name verbatim, and the comment
|
| 664 |
+
defending it was RIGHT about the reason β a refusal names the field, and a label
|
| 665 |
+
that reads differently makes the error unmatchable. So the label did not move
|
| 666 |
+
alone: `field_label()` is what the SERVER's refusals use too, which is the only
|
| 667 |
+
version of this change that does not trade one confusion for another. */}
|
| 668 |
+
<span className="autob-tgl-name" title={row.hint || undefined}>
|
| 669 |
+
{row.label}
|
| 670 |
+
</span>
|
| 671 |
+
{/*
|
| 672 |
+
β ONE CHIP, AND IT MARKS THE MINORITY. The first version chipped every
|
| 673 |
+
non-narrowing field "broad" AND every unpopulated one "no values seen" β
|
| 674 |
+
which put two chips on 18 of the 21 rows, and one of them repeated the group
|
| 675 |
+
heading the row was already sitting under. A mark that is on almost every row
|
| 676 |
+
stops being a mark. Read off the screenshot; no assertion could have said it.
|
| 677 |
+
|
| 678 |
+
So: the group label carries POPULATED (it is what the groups ARE), and the
|
| 679 |
+
chip carries NARROWING, inverted to mark the five that DO narrow. That is the
|
| 680 |
+
actionable half β the server refuses a filter with no narrowing condition, so
|
| 681 |
+
"these are the ones that satisfy it" is the sentence a user needs, and
|
| 682 |
+
"this one does not" is not.
|
| 683 |
+
*/}
|
| 684 |
+
{row.narrowing === true ? (
|
| 685 |
+
<span
|
| 686 |
+
className="autob-tgl-flag is-narrow"
|
| 687 |
+
title="A search needs at least one condition like this."
|
| 688 |
+
>
|
| 689 |
+
narrows
|
| 690 |
+
</span>
|
| 691 |
+
) : null}
|
| 692 |
+
</div>
|
| 693 |
+
{on ? (
|
| 694 |
+
<div className="autob-tgl-body">
|
| 695 |
+
{row.at.map((i) => condition(i, row.label, row))}
|
| 696 |
+
{row.hint ? <p className="autob-tgl-hint">{row.hint}</p> : null}
|
| 697 |
+
<button
|
| 698 |
+
type="button"
|
| 699 |
+
className="autob-cond-add"
|
| 700 |
+
onClick={() =>
|
| 701 |
+
onPreds([...preds, { name: row.name, operator: firstOperator(discover, row.name) }])
|
| 702 |
+
}
|
| 703 |
+
>
|
| 704 |
+
Another condition on {row.label}
|
| 705 |
+
</button>
|
| 706 |
+
</div>
|
| 707 |
+
) : null}
|
| 708 |
+
</div>
|
| 709 |
+
);
|
| 710 |
+
};
|
| 711 |
+
|
| 712 |
+
return (
|
| 713 |
+
<>
|
| 714 |
+
<div className="auto-field">
|
| 715 |
+
<label htmlFor="auto-records">How many profiles to fetch</label>
|
| 716 |
+
<input
|
| 717 |
+
id="auto-records"
|
| 718 |
+
className="auto-input"
|
| 719 |
+
type="number"
|
| 720 |
+
min={1}
|
| 721 |
+
max={maxRecords}
|
| 722 |
+
value={recordsLimit}
|
| 723 |
+
onChange={(e) => onRecordsLimit(Number(e.target.value) || 1)}
|
| 724 |
+
/>
|
| 725 |
+
</div>
|
| 726 |
+
{/* Owner item 5: "Stop at the 'A search must be at most 500 profiles a run'". The two
|
| 727 |
+
sentences that followed explained the vendor's billing model to somebody who wants a
|
| 728 |
+
list of florists. */}
|
| 729 |
+
<p className="auto-hint">At most {maxRecords.toLocaleString()} profiles a run.</p>
|
| 730 |
+
|
| 731 |
+
<h3>Conditions</h3>
|
| 732 |
+
<div className="auto-field autob-match">
|
| 733 |
+
<label htmlFor="auto-joinop">Match</label>
|
| 734 |
+
<select
|
| 735 |
+
id="auto-joinop"
|
| 736 |
+
className="auto-input"
|
| 737 |
+
value={joinOp}
|
| 738 |
+
onChange={(e) => onJoinOp(e.target.value)}
|
| 739 |
+
>
|
| 740 |
+
<option value="and">All of them</option>
|
| 741 |
+
<option value="or">Any of them</option>
|
| 742 |
+
</select>
|
| 743 |
+
</div>
|
| 744 |
+
|
| 745 |
+
{!rows.length ? (
|
| 746 |
+
<p className="auto-note">
|
| 747 |
+
The searchable fields have not loaded yet.
|
| 748 |
+
</p>
|
| 749 |
+
) : null}
|
| 750 |
+
|
| 751 |
+
{withValues.length ? (
|
| 752 |
+
<div className="autob-tglgroup">
|
| 753 |
+
<p
|
| 754 |
+
className="autob-tglgroup-label"
|
| 755 |
+
title="Most accounts have this filled in."
|
| 756 |
+
>
|
| 757 |
+
Usually filled in
|
| 758 |
+
</p>
|
| 759 |
+
{withValues.map(fieldRow)}
|
| 760 |
+
</div>
|
| 761 |
+
) : null}
|
| 762 |
+
|
| 763 |
+
{rest.length ? (
|
| 764 |
+
<div className="autob-tglgroup">
|
| 765 |
+
<p
|
| 766 |
+
className="autob-tglgroup-label"
|
| 767 |
+
title={
|
| 768 |
+
knownMeta
|
| 769 |
+
? "Most accounts leave these blank, so a condition here can return nothing."
|
| 770 |
+
: "We have not measured how often these are filled in."
|
| 771 |
+
}
|
| 772 |
+
>
|
| 773 |
+
{knownMeta ? "Often blank" : "Not measured"}
|
| 774 |
+
</p>
|
| 775 |
+
{rest.map(fieldRow)}
|
| 776 |
+
</div>
|
| 777 |
+
) : null}
|
| 778 |
+
|
| 779 |
+
{strays.length ? (
|
| 780 |
+
<div className="autob-tglgroup">
|
| 781 |
+
<p className="autob-tglgroup-label">Not in the searchable list</p>
|
| 782 |
+
{strays.map(({ p, i }) => (
|
| 783 |
+
<div className="autob-tgl is-on is-stray" key={`stray-${i}`}>
|
| 784 |
+
<div className="autob-tgl-head">
|
| 785 |
+
{/* A stray gets a mark too β "every filter row" includes the ones the vendor no
|
| 786 |
+
longer offers, and a row missing the icon its neighbours have would read as a
|
| 787 |
+
different KIND of thing rather than as a field that fell out of the list. It
|
| 788 |
+
draws the neutral fallback by construction: a stray is, by definition, not in
|
| 789 |
+
the vocabulary this component has arms for. */}
|
| 790 |
+
<span className="autob-tgl-mark">
|
| 791 |
+
<FilterMark name={p.name} />
|
| 792 |
+
</span>
|
| 793 |
+
<span className="autob-tgl-name">{p.name}</span>
|
| 794 |
+
<span className="autob-tgl-flag is-stray" title="The server will refuse this condition by name.">
|
| 795 |
+
not searchable
|
| 796 |
+
</span>
|
| 797 |
+
</div>
|
| 798 |
+
<div className="autob-tgl-body">{condition(i, p.name)}</div>
|
| 799 |
+
</div>
|
| 800 |
+
))}
|
| 801 |
+
</div>
|
| 802 |
+
) : null}
|
| 803 |
+
|
| 804 |
+
{/* The consequence kept, the mechanism dropped: a condition on an often-blank field
|
| 805 |
+
returning nothing is a thing that will happen to somebody and confuse them. Why the
|
| 806 |
+
search is slow when broad is our problem, not theirs. */}
|
| 807 |
+
<p className="auto-hint">
|
| 808 |
+
Conditions on often-blank fields can come back with nothing.
|
| 809 |
+
</p>
|
| 810 |
+
|
| 811 |
+
<h3>What it costs</h3>
|
| 812 |
+
<div className="auto-head-actions">
|
| 813 |
+
<button type="button" className="auto-btn" onClick={onEstimate}>
|
| 814 |
+
Estimate this search
|
| 815 |
+
</button>
|
| 816 |
+
</div>
|
| 817 |
+
{estimate ? (
|
| 818 |
+
<p className="auto-hint">
|
| 819 |
+
About <strong>${estimate.usd}</strong> for {estimate.records} profiles, at $
|
| 820 |
+
{estimate.unitUsd} each.{" "}
|
| 821 |
+
{/*
|
| 822 |
+
THE CAVEAT IS NOT OPTIONAL. The vendor never quotes a price before a run and this
|
| 823 |
+
deployment cannot read its own balance, so presenting this as a billed figure
|
| 824 |
+
would be inventing a measurement.
|
| 825 |
+
*/}
|
| 826 |
+
<strong>This is an estimate</strong> β {estimate.note}.
|
| 827 |
+
</p>
|
| 828 |
+
) : null}
|
| 829 |
+
|
| 830 |
+
{/* β WAVE 27 Β· OWNER ITEM 29 β THE BIG EDITOR, rendered ONCE for the whole panel.
|
| 831 |
+
β Not one overlay per condition row: `AnchoredOverlay` mounts a body portal and
|
| 832 |
+
installs document-level dismiss/focus handlers, so N of them would be N listener
|
| 833 |
+
stacks fighting over one Escape key. One overlay, told which row it is editing.
|
| 834 |
+
β `role="dialog"`, not "menu": it holds a text field, and the menu layer's arrow-key
|
| 835 |
+
handling would take the cursor keys away from the text being typed. */}
|
| 836 |
+
{big ? (
|
| 837 |
+
<AnchoredOverlay
|
| 838 |
+
anchor={big.anchor}
|
| 839 |
+
className="autoc-bigedit"
|
| 840 |
+
placement="right-start"
|
| 841 |
+
role="dialog"
|
| 842 |
+
ariaLabel={`Value for ${big.label}`}
|
| 843 |
+
onDismiss={() => setBig(null)}
|
| 844 |
+
dataKind="find-value-editor"
|
| 845 |
+
>
|
| 846 |
+
<label htmlFor="autoc-bigedit-text">{big.label}</label>
|
| 847 |
+
<textarea
|
| 848 |
+
id="autoc-bigedit-text"
|
| 849 |
+
className="autoc-bigedit-text"
|
| 850 |
+
data-overlay-autofocus
|
| 851 |
+
autoFocus
|
| 852 |
+
rows={7}
|
| 853 |
+
spellCheck={false}
|
| 854 |
+
value={big.text}
|
| 855 |
+
placeholder={big.multi ? "floral, flower, wedding florist, event styling" : ""}
|
| 856 |
+
onChange={(e) => setBig((cur) => (cur ? { ...cur, text: e.target.value } : cur))}
|
| 857 |
+
onKeyDown={(e) => {
|
| 858 |
+
// Escape abandons; Ctrl/Cmd+Enter commits. A bare Enter types a NEWLINE, because
|
| 859 |
+
// this is a textarea and the whole reason it exists is that the value is long.
|
| 860 |
+
if (e.key === "Escape") setBig(null);
|
| 861 |
+
if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
|
| 862 |
+
setAt(big.index, { value: parseValue(big.text, big.multi) });
|
| 863 |
+
setBig(null);
|
| 864 |
+
}
|
| 865 |
+
}}
|
| 866 |
+
/>
|
| 867 |
+
{/* The same sentence the rail input's placeholder makes, said where there is room
|
| 868 |
+
for it: a comma list is several values, and the server turns them into an OR. */}
|
| 869 |
+
{big.multi ? (
|
| 870 |
+
<p className="auto-hint">
|
| 871 |
+
Separate values with commas β the search matches any of them.
|
| 872 |
+
</p>
|
| 873 |
+
) : null}
|
| 874 |
+
<div className="auto-head-actions">
|
| 875 |
+
<button
|
| 876 |
+
type="button"
|
| 877 |
+
className="auto-btn auto-btn--primary"
|
| 878 |
+
onClick={() => {
|
| 879 |
+
setAt(big.index, { value: parseValue(big.text, big.multi) });
|
| 880 |
+
setBig(null);
|
| 881 |
+
}}
|
| 882 |
+
>
|
| 883 |
+
Done
|
| 884 |
+
</button>
|
| 885 |
+
<button type="button" className="auto-btn" onClick={() => setBig(null)}>
|
| 886 |
+
Cancel
|
| 887 |
+
</button>
|
| 888 |
+
</div>
|
| 889 |
+
</AnchoredOverlay>
|
| 890 |
+
) : null}
|
| 891 |
+
</>
|
| 892 |
+
);
|
| 893 |
+
}
|
web/src/automation/automationApi.ts
CHANGED
|
@@ -409,8 +409,8 @@ export interface Action {
|
|
| 409 |
}
|
| 410 |
|
| 411 |
/** `flow.ending` (C5) β what happens to a record that reaches the end. */
|
| 412 |
-
export interface Flow {
|
| 413 |
-
actions: Action[];
|
| 414 |
}
|
| 415 |
|
| 416 |
/**
|
|
@@ -434,20 +434,36 @@ export interface ActionCatalogRow {
|
|
| 434 |
* still renders every group it sends.
|
| 435 |
*/
|
| 436 |
groupOrder?: number;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 437 |
}
|
| 438 |
|
| 439 |
/** The builder's own ceilings, server-declared so the client never hard-codes the same numbers. */
|
| 440 |
-
export interface FlowVocab {
|
| 441 |
condOps: string[];
|
| 442 |
nullaryCondOps: string[];
|
| 443 |
maxCondDepth: number;
|
| 444 |
maxCondChildren: number;
|
| 445 |
maxGroupDepth: number;
|
| 446 |
-
maxActions: number;
|
| 447 |
-
/** Legacy read compatibility only; the server no longer sends Board review vocabulary. */
|
| 448 |
-
reviewDeciders?: string[];
|
| 449 |
-
/** Legacy read compatibility only; the server no longer sends Board review readiness. */
|
| 450 |
-
aiReady?: boolean;
|
| 451 |
/**
|
| 452 |
* β PER-DEPLOYMENT, AND HONEST RATHER THAN DECORATIVE. With no LLM key configured the engine
|
| 453 |
* holds every card for a human β so an enabled-looking "decided by AI" control would promise
|
|
|
|
| 409 |
}
|
| 410 |
|
| 411 |
/** `flow.ending` (C5) β what happens to a record that reaches the end. */
|
| 412 |
+
export interface Flow {
|
| 413 |
+
actions: Action[];
|
| 414 |
}
|
| 415 |
|
| 416 |
/**
|
|
|
|
| 434 |
* still renders every group it sends.
|
| 435 |
*/
|
| 436 |
groupOrder?: number;
|
| 437 |
+
/**
|
| 438 |
+
* β WAVE 27 Β· OWNER ITEM 33 / CONTRACT C4 β WHICH CONNECTOR OWNS THIS ACTION.
|
| 439 |
+
*
|
| 440 |
+
* The trigger vocabulary has carried this since wave 24 (`TriggerOption.connector`, which is
|
| 441 |
+
* what nests Gmail / Webhooks / Scraper / TikTok under the Connector heading); the ACTION
|
| 442 |
+
* catalog did not, and that gap IS item 33 β the Bright Data and Apify actions sat loose in
|
| 443 |
+
* "Connected" beside unrelated rows, where the Airtable reference
|
| 444 |
+
* (`reference/Airtable Automation 10.png`) shows one row per connector with its own submenu.
|
| 445 |
+
*
|
| 446 |
+
* β OPTIONAL, AND THE CLIENT INVENTS NOTHING. B stamps `{key:'scraper', label:'Scraper'}` on
|
| 447 |
+
* the BD/Apify rows server-side; until that lands every row simply has no connector and the
|
| 448 |
+
* menu is exactly the flat list it is today. There is NO client-side list of which kinds are
|
| 449 |
+
* "scraper" actions β that would be a second copy of the catalog's own structure, which is
|
| 450 |
+
* the mistake `groupOrder`'s note one field up already records.
|
| 451 |
+
*/
|
| 452 |
+
connector?: { key: string; label: string };
|
| 453 |
}
|
| 454 |
|
| 455 |
/** The builder's own ceilings, server-declared so the client never hard-codes the same numbers. */
|
| 456 |
+
export interface FlowVocab {
|
| 457 |
condOps: string[];
|
| 458 |
nullaryCondOps: string[];
|
| 459 |
maxCondDepth: number;
|
| 460 |
maxCondChildren: number;
|
| 461 |
maxGroupDepth: number;
|
| 462 |
+
maxActions: number;
|
| 463 |
+
/** Legacy read compatibility only; the server no longer sends Board review vocabulary. */
|
| 464 |
+
reviewDeciders?: string[];
|
| 465 |
+
/** Legacy read compatibility only; the server no longer sends Board review readiness. */
|
| 466 |
+
aiReady?: boolean;
|
| 467 |
/**
|
| 468 |
* β PER-DEPLOYMENT, AND HONEST RATHER THAN DECORATIVE. With no LLM key configured the engine
|
| 469 |
* holds every card for a human β so an enabled-looking "decided by AI" control would promise
|
web/src/automation/steps.ts
CHANGED
|
@@ -1,359 +1,422 @@
|
|
| 1 |
-
// ---------------------------------------------------------------------------
|
| 2 |
-
// automation/steps.ts β the arithmetic behind the numbered Steps (owner ruling R9).
|
| 3 |
-
//
|
| 4 |
-
// Pure functions, deliberately separate from the component: both of the things in
|
| 5 |
-
// here are the kind that go subtly wrong (a step number, a cron round-trip) and
|
| 6 |
-
// stay wrong invisibly, so they are written where they can be read on their own.
|
| 7 |
-
//
|
| 8 |
-
// β NOTHING HERE INVENTS A STEP. The node list, its order and its `col` all come
|
| 9 |
-
// from the server's `engine.graph()` β the same module that RUNS the steps β and
|
| 10 |
-
// this file only counts them (contract C6). A client-side second idea of what the
|
| 11 |
-
// steps are is the exact drift the split was built to prevent; the rationale is
|
| 12 |
-
// written at AutomationCreate.tsx:1-13.
|
| 13 |
-
// ---------------------------------------------------------------------------
|
| 14 |
-
import type { Action, Branch, Cond, GraphNode, TriggerOption }
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
*
|
| 19 |
-
*
|
| 20 |
-
*
|
| 21 |
-
*
|
| 22 |
-
*
|
| 23 |
-
*
|
| 24 |
-
*
|
| 25 |
-
*
|
| 26 |
-
*
|
| 27 |
-
*
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
*
|
| 44 |
-
*
|
| 45 |
-
*
|
| 46 |
-
*
|
| 47 |
-
*
|
| 48 |
-
* Β·
|
| 49 |
-
*
|
| 50 |
-
*
|
| 51 |
-
*
|
| 52 |
-
* `2.1`,
|
| 53 |
-
*
|
| 54 |
-
*
|
| 55 |
-
*
|
| 56 |
-
*
|
| 57 |
-
*
|
| 58 |
-
*
|
| 59 |
-
*
|
| 60 |
-
*
|
| 61 |
-
*
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
const
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
*
|
| 87 |
-
*
|
| 88 |
-
*
|
| 89 |
-
* `
|
| 90 |
-
*
|
| 91 |
-
*
|
| 92 |
-
*
|
| 93 |
-
*
|
| 94 |
-
*
|
| 95 |
-
*
|
| 96 |
-
*
|
| 97 |
-
*
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
const
|
| 102 |
-
const
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
}
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
*
|
| 110 |
-
*
|
| 111 |
-
*
|
| 112 |
-
*
|
| 113 |
-
* "
|
| 114 |
-
*
|
| 115 |
-
*
|
| 116 |
-
*
|
| 117 |
-
*
|
| 118 |
-
*
|
| 119 |
-
*
|
| 120 |
-
* the
|
| 121 |
-
*
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
const
|
| 130 |
-
const
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
const
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
panel
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
*
|
| 150 |
-
*
|
| 151 |
-
*
|
| 152 |
-
*
|
| 153 |
-
*
|
| 154 |
-
*
|
| 155 |
-
*
|
| 156 |
-
*
|
| 157 |
-
*
|
| 158 |
-
*
|
| 159 |
-
*
|
| 160 |
-
*
|
| 161 |
-
*
|
| 162 |
-
*
|
| 163 |
-
*
|
| 164 |
-
*
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
const
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
//
|
| 171 |
-
//
|
| 172 |
-
|
| 173 |
-
const
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
}
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
every
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
const
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
*
|
| 201 |
-
*
|
| 202 |
-
*
|
| 203 |
-
*
|
| 204 |
-
*
|
| 205 |
-
*
|
| 206 |
-
*
|
| 207 |
-
*
|
| 208 |
-
*
|
| 209 |
-
*
|
| 210 |
-
*
|
| 211 |
-
* the
|
| 212 |
-
*
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
const
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
}
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
const
|
| 235 |
-
const
|
| 236 |
-
|
| 237 |
-
}
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
{ value: "
|
| 243 |
-
{ value: "
|
| 244 |
-
{ value: "
|
| 245 |
-
{ value: "
|
| 246 |
-
{ value: "
|
| 247 |
-
{ value: "
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
//
|
| 252 |
-
//
|
| 253 |
-
//
|
| 254 |
-
//
|
| 255 |
-
//
|
| 256 |
-
//
|
| 257 |
-
//
|
| 258 |
-
//
|
| 259 |
-
//
|
| 260 |
-
//
|
| 261 |
-
//
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
*
|
| 286 |
-
*
|
| 287 |
-
*
|
| 288 |
-
*
|
| 289 |
-
*
|
| 290 |
-
*
|
| 291 |
-
*
|
| 292 |
-
*
|
| 293 |
-
*
|
| 294 |
-
*
|
| 295 |
-
*
|
| 296 |
-
*
|
| 297 |
-
*
|
| 298 |
-
*
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
const
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
//
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
//
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
*
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
*
|
| 347 |
-
*
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ---------------------------------------------------------------------------
|
| 2 |
+
// automation/steps.ts β the arithmetic behind the numbered Steps (owner ruling R9).
|
| 3 |
+
//
|
| 4 |
+
// Pure functions, deliberately separate from the component: both of the things in
|
| 5 |
+
// here are the kind that go subtly wrong (a step number, a cron round-trip) and
|
| 6 |
+
// stay wrong invisibly, so they are written where they can be read on their own.
|
| 7 |
+
//
|
| 8 |
+
// β NOTHING HERE INVENTS A STEP. The node list, its order and its `col` all come
|
| 9 |
+
// from the server's `engine.graph()` β the same module that RUNS the steps β and
|
| 10 |
+
// this file only counts them (contract C6). A client-side second idea of what the
|
| 11 |
+
// steps are is the exact drift the split was built to prevent; the rationale is
|
| 12 |
+
// written at AutomationCreate.tsx:1-13.
|
| 13 |
+
// ---------------------------------------------------------------------------
|
| 14 |
+
import type { Action, ActionCatalogRow, Branch, Cond, GraphNode, TriggerOption }
|
| 15 |
+
from "./automationApi";
|
| 16 |
+
|
| 17 |
+
/**
|
| 18 |
+
* The branches of an If / then, TOLERATING the pre-wave-24 `{cond, actions}` shape on READ.
|
| 19 |
+
*
|
| 20 |
+
* β THIS MIRRORS `automation_engine.group_branches` AND THE DUPLICATION IS DELIBERATE, which is
|
| 21 |
+
* worth defending because this file's own header forbids a second idea of the server's data. It
|
| 22 |
+
* is a READ-SIDE TOLERANCE, not a second validator: it never decides what is legal, and every
|
| 23 |
+
* write still goes to `clean_actions`, which returns the one canonical shape. The alternative is
|
| 24 |
+
* strictly worse β a group stored in the old shape would render with no branches and no children,
|
| 25 |
+
* so a live automation's actions would simply VANISH from the screen while running perfectly.
|
| 26 |
+
* A migration the server performs on write and the client tolerates on read is the pair that has
|
| 27 |
+
* no window; trusting `branches` alone has one, for exactly as long as a definition sits unsaved.
|
| 28 |
+
*/
|
| 29 |
+
export function groupBranches(a: Action): Branch[] {
|
| 30 |
+
const cfg = (a?.config || {}) as {
|
| 31 |
+
branches?: Branch[];
|
| 32 |
+
cond?: Cond | null;
|
| 33 |
+
actions?: Action[];
|
| 34 |
+
};
|
| 35 |
+
if (Array.isArray(cfg.branches)) return cfg.branches;
|
| 36 |
+
// The pre-wave-24 shape, read as the one branch the engine migrates it to.
|
| 37 |
+
if (Array.isArray(cfg.actions))
|
| 38 |
+
return [{ id: "b1", label: "A", cond: cfg.cond ?? null, actions: cfg.actions }];
|
| 39 |
+
return [];
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
/**
|
| 43 |
+
* R8's STEP NUMBERS for a whole flow, keyed by action id.
|
| 44 |
+
*
|
| 45 |
+
* THE RULING, and each clause is a line here:
|
| 46 |
+
* Β· the TRIGGER is unnumbered β it is not in this map at all, and the card carries the word
|
| 47 |
+
* "Trigger" instead. (This REVERSES wave 21's R9, "Step 1 is always the Trigger".)
|
| 48 |
+
* Β· the first action is 1, the second 2, β¦
|
| 49 |
+
* Β· an If / then occupies ONE number. Its branches are alternatives, not later steps, so they
|
| 50 |
+
* consume no numbers of their own.
|
| 51 |
+
* Β· a branch's children are numbered RELATIVE TO THEIR BRANCH β the fork at step 2 gives every
|
| 52 |
+
* one of its branches a `2.1`, a `2.2`, and so on. Two branches therefore both contain a
|
| 53 |
+
* `2.1`, which is correct rather than colliding: they are alternatives in lettered lanes and
|
| 54 |
+
* only one of them ever runs (the engine takes the first matching branch and breaks).
|
| 55 |
+
*
|
| 56 |
+
* β IT DOES NOT LETTER THE BRANCHES, and that is a change from the contract text. `clean_actions`
|
| 57 |
+
* assigns the letter server-side (`_branch_letter`, and "Otherwise" for the null-cond last leg),
|
| 58 |
+
* preserving any label the client sends β so the letter rides on `Branch.label` and a second
|
| 59 |
+
* lettering here would be exactly the client-copy-of-a-server-vocabulary this wave keeps deleting.
|
| 60 |
+
* The client sends an EMPTY label and renders what comes back, which also means letters re-flow
|
| 61 |
+
* correctly when a branch is deleted instead of going stale.
|
| 62 |
+
*/
|
| 63 |
+
export function numberActions(actions: Action[]): Map<string, string> {
|
| 64 |
+
const out = new Map<string, string>();
|
| 65 |
+
const walk = (list: Action[], prefix: string) => {
|
| 66 |
+
(list || []).forEach((a, i) => {
|
| 67 |
+
const n = prefix ? `${prefix}.${i + 1}` : String(i + 1);
|
| 68 |
+
out.set(a.id, n);
|
| 69 |
+
if (a.kind === "group")
|
| 70 |
+
for (const br of groupBranches(a)) walk(br.actions || [], n);
|
| 71 |
+
});
|
| 72 |
+
};
|
| 73 |
+
walk(actions || [], "");
|
| 74 |
+
return out;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
export interface Step {
|
| 78 |
+
node: GraphNode;
|
| 79 |
+
/** The number the card carries. */
|
| 80 |
+
n: number;
|
| 81 |
+
/** True when this node shares its position with the one before it β an ALTERNATIVE, not a next. */
|
| 82 |
+
alt: boolean;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
/**
|
| 86 |
+
* Number the server's nodes for display.
|
| 87 |
+
*
|
| 88 |
+
* β THE NUMBER IS `col + 1`, NOT the array index, and that is the honest one. The
|
| 89 |
+
* `field_instagram` graph forks: `capture_paid` and `capture_anon` both sit at
|
| 90 |
+
* `col: 3` because they are the SAME position in the flow reached two ways (the
|
| 91 |
+
* paid rung answers, or the anonymous ladder does). Numbering them 4 and 5 would
|
| 92 |
+
* state a sequence that never happens. They share a number and the second is
|
| 93 |
+
* marked `alt`, so the list says "either of these" rather than "then".
|
| 94 |
+
*
|
| 95 |
+
* "Step 1 is always the Trigger" (R9) therefore falls out of the payload β the
|
| 96 |
+
* trigger is the node at `col: 0` β instead of being asserted by this client. If
|
| 97 |
+
* the engine ever emits something else first, the UI shows what the engine does.
|
| 98 |
+
*/
|
| 99 |
+
export function numberSteps(nodes: GraphNode[]): Step[] {
|
| 100 |
+
return (nodes || []).map((node, i) => {
|
| 101 |
+
const col = typeof node.col === "number" ? node.col : i;
|
| 102 |
+
const before = i > 0 ? nodes[i - 1] : null;
|
| 103 |
+
const beforeCol = before && typeof before.col === "number" ? before.col : -1;
|
| 104 |
+
return { node, n: col + 1, alt: i > 0 && beforeCol === col };
|
| 105 |
+
});
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
/**
|
| 109 |
+
* Move `dragId` into `dropId`'s position within one list (owner item 11).
|
| 110 |
+
*
|
| 111 |
+
* β IT RETURNS `null` RATHER THAN THE LIST UNCHANGED, and the distinction is what keeps a
|
| 112 |
+
* pointless PATCH off the wire: "these two are the same card", "one of them is not in this list"
|
| 113 |
+
* and "here is your new order" are three different answers, and collapsing the first two into
|
| 114 |
+
* "the order you already had" would have the caller write the flow back to the server on every
|
| 115 |
+
* aborted drag. The caller writes only when this says something happened.
|
| 116 |
+
*
|
| 117 |
+
* THE CARD LANDS EXACTLY WHERE THE TARGET WAS, in both directions β splice out, then splice in at
|
| 118 |
+
* the target's ORIGINAL index. Dragging down, the target shifts up; dragging up, it shifts down.
|
| 119 |
+
* (The tempting version β insert at the target's index *after* the removal β is off by one when
|
| 120 |
+
* dragging downwards and drops the card one slot short of where the pointer is, which reads as
|
| 121 |
+
* the drag not having worked.)
|
| 122 |
+
*/
|
| 123 |
+
export function reorderList<T extends { id: string }>(
|
| 124 |
+
list: T[],
|
| 125 |
+
dragId: string,
|
| 126 |
+
dropId: string
|
| 127 |
+
): T[] | null {
|
| 128 |
+
if (!dragId || !dropId || dragId === dropId) return null;
|
| 129 |
+
const src = list || [];
|
| 130 |
+
const from = src.findIndex((x) => x.id === dragId);
|
| 131 |
+
const to = src.findIndex((x) => x.id === dropId);
|
| 132 |
+
if (from < 0 || to < 0) return null;
|
| 133 |
+
const next = [...src];
|
| 134 |
+
const [moved] = next.splice(from, 1);
|
| 135 |
+
if (!moved) return null;
|
| 136 |
+
next.splice(to, 0, moved);
|
| 137 |
+
return next;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
/** One Properties section under "How this fetches": a panel, and every node that opens it. */
|
| 141 |
+
export interface PanelGroup {
|
| 142 |
+
/** The panel key β what the caller passes to `renderNodeBody`. */
|
| 143 |
+
panel: string;
|
| 144 |
+
/** Every machine node whose `panel` is this one, in the server's own order. */
|
| 145 |
+
nodes: GraphNode[];
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
/**
|
| 149 |
+
* The machine steps, GROUPED BY PANEL (item 5, contract C-CFG).
|
| 150 |
+
*
|
| 151 |
+
* β GROUPED, NEVER MAPPED ONE-TO-ONE, and the difference is a defect rather than a nicety.
|
| 152 |
+
* `panel` is MANY-TO-ONE over nodes, which is easy to miss because the old surface hid it: you
|
| 153 |
+
* clicked ONE card and got ONE panel. `field_instagram` gives `capture`, `capture_paid`,
|
| 154 |
+
* `capture_anon` AND `capture_metrics` all `panel: "capture"` (`automation_engine.py:3334-3352`),
|
| 155 |
+
* and `discover_instagram` gives both of its nodes `panel: "find"` (`:3381`/`:3387`). So a body
|
| 156 |
+
* rendered per NODE would print the capture prose four times over, and β the one that actually
|
| 157 |
+
* loses work β mount the 21-toggle discovery filter TWICE against a single `preds` array, two
|
| 158 |
+
* editors writing one piece of state where whichever blurred last silently wins.
|
| 159 |
+
*
|
| 160 |
+
* The detail panel has always joined on `panel` and never on node id (`AutomationDetail`'s own
|
| 161 |
+
* note says so); this keeps that law now that the panels are no longer reached by clicking a card.
|
| 162 |
+
*
|
| 163 |
+
* ORDER IS THE SERVER'S β first appearance wins, so the sections read in flow order rather than
|
| 164 |
+
* in whatever order a Map or a sort would produce.
|
| 165 |
+
*/
|
| 166 |
+
export function groupByPanel(nodes: GraphNode[]): PanelGroup[] {
|
| 167 |
+
const order: string[] = [];
|
| 168 |
+
const byPanel = new Map<string, GraphNode[]>();
|
| 169 |
+
for (const n of nodes || []) {
|
| 170 |
+
// `panel` falls back to the id exactly as `graph()`'s own `node()` does (`panel or nid`),
|
| 171 |
+
// so a node the engine ships without one still gets its own section instead of joining
|
| 172 |
+
// every other panel-less node under the empty string.
|
| 173 |
+
const key = n.panel || n.id;
|
| 174 |
+
const seen = byPanel.get(key);
|
| 175 |
+
if (seen) seen.push(n);
|
| 176 |
+
else {
|
| 177 |
+
byPanel.set(key, [n]);
|
| 178 |
+
order.push(key);
|
| 179 |
+
}
|
| 180 |
+
}
|
| 181 |
+
return order.map((panel) => ({ panel, nodes: byPanel.get(panel) || [] }));
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
/** How the Step-1 card is currently set: what it repeats on, and at what time. */
|
| 185 |
+
export interface TriggerShape {
|
| 186 |
+
/** `day` = every day Β· `0`..`6` = that weekday (cron numbering, 0 = Sunday) Β· `custom` = a cron only. */
|
| 187 |
+
every: string;
|
| 188 |
+
/** `HH:MM`, empty when the cron does not express a single fire time. */
|
| 189 |
+
time: string;
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
const DAILY = /^(\d{1,2}) (\d{1,2}) \* \* \*$/;
|
| 193 |
+
const WEEKLY = /^(\d{1,2}) (\d{1,2}) \* \* ([0-7])$/;
|
| 194 |
+
|
| 195 |
+
function two(n: number): string {
|
| 196 |
+
return String(n).padStart(2, "0");
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
/**
|
| 200 |
+
* A stored cron β the controls that can express it.
|
| 201 |
+
*
|
| 202 |
+
* β ANYTHING THIS CANNOT EXPRESS COMES BACK AS `custom`, NEVER AS THE FIRST OPTION.
|
| 203 |
+
* A `<select>` whose value matches no `<option>` renders the first one, and the next
|
| 204 |
+
* Save then writes a schedule nobody chose β the defect this codebase has already
|
| 205 |
+
* paid for twice ([[cg-condition-builder-items]]; the two `(not in this database)`
|
| 206 |
+
* options in AutomationDetail exist for the same reason). A quarter-hourly weekday
|
| 207 |
+
* cron is a legal schedule the engine runs happily; the editor's job is to leave it
|
| 208 |
+
* alone, not to quietly turn it into "every day at 08:00".
|
| 209 |
+
*
|
| 210 |
+
* (Written without the literal cron string on purpose β a step-slash inside a block
|
| 211 |
+
* comment ENDS the comment, and the compiler's 20 cascading errors say nothing about
|
| 212 |
+
* the cron.)
|
| 213 |
+
*/
|
| 214 |
+
export function readCron(cron: string): TriggerShape {
|
| 215 |
+
const raw = String(cron || "").trim();
|
| 216 |
+
const daily = DAILY.exec(raw);
|
| 217 |
+
if (daily) {
|
| 218 |
+
const [, m, h] = daily;
|
| 219 |
+
if (Number(h) <= 23 && Number(m) <= 59) return { every: "day", time: `${two(Number(h))}:${two(Number(m))}` };
|
| 220 |
+
}
|
| 221 |
+
const weekly = WEEKLY.exec(raw);
|
| 222 |
+
if (weekly) {
|
| 223 |
+
const [, m, h, d] = weekly;
|
| 224 |
+
if (Number(h) <= 23 && Number(m) <= 59) {
|
| 225 |
+
return { every: String(Number(d) % 7), time: `${two(Number(h))}:${two(Number(m))}` };
|
| 226 |
+
}
|
| 227 |
+
}
|
| 228 |
+
return { every: "custom", time: "" };
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
/** The controls β a cron string. `custom` keeps whatever the user typed, untouched. */
|
| 232 |
+
export function writeCron(every: string, time: string, custom: string): string {
|
| 233 |
+
if (every === "custom") return String(custom || "").trim();
|
| 234 |
+
const [h, m] = String(time || "06:00").split(":");
|
| 235 |
+
const hh = Math.min(23, Math.max(0, Number(h) || 0));
|
| 236 |
+
const mm = Math.min(59, Math.max(0, Number(m) || 0));
|
| 237 |
+
return every === "day" ? `${mm} ${hh} * * *` : `${mm} ${hh} * * ${Number(every) || 0}`;
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
/** The weekday options, in the order a week is read rather than in cron's 0-first order. */
|
| 241 |
+
export const WEEKDAYS: { value: string; label: string }[] = [
|
| 242 |
+
{ value: "1", label: "Every Monday" },
|
| 243 |
+
{ value: "2", label: "Every Tuesday" },
|
| 244 |
+
{ value: "3", label: "Every Wednesday" },
|
| 245 |
+
{ value: "4", label: "Every Thursday" },
|
| 246 |
+
{ value: "5", label: "Every Friday" },
|
| 247 |
+
{ value: "6", label: "Every Saturday" },
|
| 248 |
+
{ value: "0", label: "Every Sunday" },
|
| 249 |
+
];
|
| 250 |
+
|
| 251 |
+
// ββ WAVE 25 Β· C2: THE GROUPED TRIGGER PICKER'S ARITHMETIC βββββββββββββββββββββββββββββββββββ
|
| 252 |
+
//
|
| 253 |
+
// β WHY THIS IS HERE AND NOT IN THE COMPONENT. Both functions below are the kind that go subtly
|
| 254 |
+
// wrong and stay wrong INVISIBLY β a group silently sorted first, a stored trigger silently
|
| 255 |
+
// rendering as nothing β and this file exists precisely so that class can be executed under node
|
| 256 |
+
// by `verify_steps.py` instead of eyeballed in a screenshot. It is also D-58's minimum: the
|
| 257 |
+
// builder's largest surface has had no gate but `tsc` and eyes, and the picker's grouped and
|
| 258 |
+
// SELECTED states are the two things a screenshot is worst at proving (the selected row looks
|
| 259 |
+
// identical to an unselected one at a glance, which is the whole scar).
|
| 260 |
+
//
|
| 261 |
+
// β NOTHING HERE INVENTS A GROUP, A CAPTION OR AN ORDER β the file header's law, applied. Every
|
| 262 |
+
// one of the three rides `TriggerOption` from `routes_automation._triggers_vocab`.
|
| 263 |
+
|
| 264 |
+
/** One connector's rows inside the Connector group (Gmail / Webhooks / Scraper / TikTok). */
|
| 265 |
+
export interface TriggerSubGroup {
|
| 266 |
+
key: string;
|
| 267 |
+
label: string;
|
| 268 |
+
rows: TriggerOption[];
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
/** One rendered section of the picker: a caption, the rows under it, and any connector nests. */
|
| 272 |
+
export interface TriggerGroup {
|
| 273 |
+
/** The server's group id. `""` when the server sent none β one unlabelled section. */
|
| 274 |
+
key: string;
|
| 275 |
+
/** The server's caption, PRINTED verbatim. `""` renders no heading, never an invented one. */
|
| 276 |
+
label: string;
|
| 277 |
+
order: number;
|
| 278 |
+
/** Rows that hang directly off the group head. */
|
| 279 |
+
rows: TriggerOption[];
|
| 280 |
+
/** Connector nests, in first-appearance order. Empty for Time and Database. */
|
| 281 |
+
sub: TriggerSubGroup[];
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
/**
|
| 285 |
+
* The picker's sections: CATEGORY first (Time / Database / Connector), then the trigger, with
|
| 286 |
+
* connector rows nested under their own product name.
|
| 287 |
+
*
|
| 288 |
+
* β ORDER COMES FROM `groupOrder`, AND AN ABSENT ONE SORTS **LAST**. This is the
|
| 289 |
+
* `ACTION_GROUP_ORDER` rule and it is the safe direction: an unordered group is one this client
|
| 290 |
+
* has no server opinion about, and putting it at the TOP of the menu would present the
|
| 291 |
+
* unclassified thing as the primary answer. Ties keep FIRST-APPEARANCE order, which is what the
|
| 292 |
+
* old `<select>` used as its only ordering and is still the honest fallback for a server that
|
| 293 |
+
* sends no `groupOrder` at all.
|
| 294 |
+
*
|
| 295 |
+
* β AND NOTHING IS DROPPED. Every option in, every option out β `planned` and `ready:false` rows
|
| 296 |
+
* included, because a picker that hides them answers "can it run when an email arrives?" with
|
| 297 |
+
* silence, and the question then gets asked again (R9's precedent). Faded is a wall the server
|
| 298 |
+
* enforces at `clean_trigger`; a shorter list is a lie.
|
| 299 |
+
*/
|
| 300 |
+
export function groupTriggers(options: TriggerOption[]): TriggerGroup[] {
|
| 301 |
+
const out: TriggerGroup[] = [];
|
| 302 |
+
const byKey = new Map<string, TriggerGroup>();
|
| 303 |
+
for (const t of options) {
|
| 304 |
+
const key = t.group || "";
|
| 305 |
+
let g = byKey.get(key);
|
| 306 |
+
if (!g) {
|
| 307 |
+
g = {
|
| 308 |
+
key,
|
| 309 |
+
// β `groupLabel` OR NOTHING. Falling back to `t.group` would print the id ("connector")
|
| 310 |
+
// as a heading β a client inventing the server's wording, one `||` at a time.
|
| 311 |
+
label: t.groupLabel || "",
|
| 312 |
+
order: typeof t.groupOrder === "number" ? t.groupOrder : Number.MAX_SAFE_INTEGER,
|
| 313 |
+
rows: [],
|
| 314 |
+
sub: [],
|
| 315 |
+
};
|
| 316 |
+
byKey.set(key, g);
|
| 317 |
+
out.push(g);
|
| 318 |
+
}
|
| 319 |
+
const c = t.connector;
|
| 320 |
+
if (c && c.key) {
|
| 321 |
+
let s = g.sub.find((x) => x.key === c.key);
|
| 322 |
+
if (!s) {
|
| 323 |
+
s = { key: c.key, label: c.label || c.key, rows: [] };
|
| 324 |
+
g.sub.push(s);
|
| 325 |
+
}
|
| 326 |
+
s.rows.push(t);
|
| 327 |
+
} else {
|
| 328 |
+
g.rows.push(t);
|
| 329 |
+
}
|
| 330 |
+
}
|
| 331 |
+
// A STABLE sort by order alone: `Array.prototype.sort` is stable in every runtime this ships to
|
| 332 |
+
// (ES2019 mandates it), so equal orders keep the first-appearance sequence above.
|
| 333 |
+
return out.sort((a, b) => a.order - b.order);
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
/** One rendered section of the ACTION menu: the same shape `TriggerGroup` has, over the
|
| 337 |
+
* catalog's rows. */
|
| 338 |
+
export interface ActionGroup {
|
| 339 |
+
key: string;
|
| 340 |
+
order: number;
|
| 341 |
+
rows: ActionCatalogRow[];
|
| 342 |
+
sub: { key: string; label: string; rows: ActionCatalogRow[] }[];
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
/**
|
| 346 |
+
* β WAVE 27 Β· OWNER ITEM 33 / CONTRACT C4 β the action menu, with connector rows NESTED.
|
| 347 |
+
*
|
| 348 |
+
* β THE SAME ARITHMETIC AS `groupTriggers`, AND THAT IS THE POINT. The trigger picker has
|
| 349 |
+
* nested connectors since wave 24; the action menu is the identical question about a different
|
| 350 |
+
* catalog, and C4 asks for the nest to be "driven by server data, name-for-name". So this reads
|
| 351 |
+
* `row.connector` exactly as `groupTriggers` reads `t.connector`, sorts by `groupOrder` with an
|
| 352 |
+
* absent one LAST, and holds no list of connector names of its own.
|
| 353 |
+
*
|
| 354 |
+
* β INERT UNTIL THE SERVER STAMPS THE ROWS, by construction rather than by a flag: with no
|
| 355 |
+
* `connector` on any row, every row lands in `rows` and `sub` is empty β which renders the flat
|
| 356 |
+
* menu that ships today. That is what lets this half land before B's, instead of two sessions
|
| 357 |
+
* having to meet in the middle.
|
| 358 |
+
*
|
| 359 |
+
* β THE GROUP KEY IS ALSO ITS LABEL here, unlike triggers. The action catalog's `group` IS the
|
| 360 |
+
* printed caption ("Web action", "Database", "Connected", "Advanced logic") β the server sends
|
| 361 |
+
* no separate `groupLabel` for actions β so this returns `key` and the caller prints it. Adding
|
| 362 |
+
* a `label` member that merely copied `key` would invent a second name for one string.
|
| 363 |
+
*/
|
| 364 |
+
export function groupActions(rows: ActionCatalogRow[]): ActionGroup[] {
|
| 365 |
+
const out: ActionGroup[] = [];
|
| 366 |
+
const byKey = new Map<string, ActionGroup>();
|
| 367 |
+
for (const c of rows) {
|
| 368 |
+
const key = c.group || "";
|
| 369 |
+
let g = byKey.get(key);
|
| 370 |
+
if (!g) {
|
| 371 |
+
g = {
|
| 372 |
+
key,
|
| 373 |
+
order: typeof c.groupOrder === "number" ? c.groupOrder : Number.MAX_SAFE_INTEGER,
|
| 374 |
+
rows: [],
|
| 375 |
+
sub: [],
|
| 376 |
+
};
|
| 377 |
+
byKey.set(key, g);
|
| 378 |
+
out.push(g);
|
| 379 |
+
}
|
| 380 |
+
const con = c.connector;
|
| 381 |
+
if (con && con.key) {
|
| 382 |
+
let s = g.sub.find((x) => x.key === con.key);
|
| 383 |
+
if (!s) {
|
| 384 |
+
// The server's LABEL, or its key when it sent none β never a prettified guess.
|
| 385 |
+
s = { key: con.key, label: con.label || con.key, rows: [] };
|
| 386 |
+
g.sub.push(s);
|
| 387 |
+
}
|
| 388 |
+
s.rows.push(c);
|
| 389 |
+
} else {
|
| 390 |
+
g.rows.push(c);
|
| 391 |
+
}
|
| 392 |
+
}
|
| 393 |
+
// Stable by order alone (ES2019 mandates a stable sort), so equal orders keep first
|
| 394 |
+
// appearance β the same rule `groupTriggers` states one function up.
|
| 395 |
+
return out.sort((a, b) => a.order - b.order);
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
/**
|
| 399 |
+
* The option the picker must render as SELECTED β and this function is the scar, in one place.
|
| 400 |
+
*
|
| 401 |
+
* β A `<select>` WHOSE `value` MATCHES NO `<option>` RENDERS THE FIRST ONE. A custom listbox
|
| 402 |
+
* fails DIFFERENTLY and worse: it renders nothing selected, looks unconfigured, and the next
|
| 403 |
+
* patch writes the blank over a real stored key. This repo has paid for the first form twice
|
| 404 |
+
* (`enters_view`'s view id, and the condition builder's operator) and the control it replaces
|
| 405 |
+
* carried an explicit guard for it.
|
| 406 |
+
*
|
| 407 |
+
* So: a stored key the server did not offer comes back as a SYNTHETIC row saying so, never as
|
| 408 |
+
* `null`. `null` means one thing only β nothing is picked yet β which is also what R14 gates the
|
| 409 |
+
* Configuration section on, so conflating the two would hide a configured automation's settings.
|
| 410 |
+
*/
|
| 411 |
+
export function selectedTrigger(
|
| 412 |
+
options: TriggerOption[],
|
| 413 |
+
key: string
|
| 414 |
+
): TriggerOption | null {
|
| 415 |
+
if (!key) return null;
|
| 416 |
+
const hit = options.find((t) => t.key === key);
|
| 417 |
+
if (hit) return hit;
|
| 418 |
+
// β `ready: false` and NO `detail`: this row is not something the reader can act on, and
|
| 419 |
+
// inventing a description for a trigger this deployment does not offer would be the client
|
| 420 |
+
// speaking for a server that said nothing.
|
| 421 |
+
return { key, label: `${key} (not offered here)`, ready: false };
|
| 422 |
+
}
|
web/src/customer-grid/ColumnMenu.tsx
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
web/src/customer-grid/CustomerGrid.tsx
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
web/src/customer-grid/JsonViewer.tsx
CHANGED
|
@@ -1,481 +1,1015 @@
|
|
| 1 |
-
// ---------------------------------------------------------------------------
|
| 2 |
-
// customer-grid / JsonViewer.tsx β β wave-23 C7 (owner item 5 / ruling R5).
|
| 3 |
-
//
|
| 4 |
-
// THE BIG VIEWER a json cell opens on click. One component, reached from two
|
| 5 |
-
// places (the grid cell's click path and the record drawer's value slot), for
|
| 6 |
-
// the reason `assetUrl` is one resolver: two readers of the same document that
|
| 7 |
-
// disagree about how it folds is a bug nobody can see in either one alone.
|
| 8 |
-
//
|
| 9 |
-
// The document is a STRING at rest (the scalar Row contract β see the `json`
|
| 10 |
-
// note in types.ts), so everything here is text in and text out. Nothing in
|
| 11 |
-
// this file ever writes a parsed OBJECT back.
|
| 12 |
-
//
|
| 13 |
-
// THREE decisions worth stating, because each has a plausible alternative:
|
| 14 |
-
//
|
| 15 |
-
// 1. THE RAW TAB IS THE EDITOR, and there is no field-by-field one. A form
|
| 16 |
-
// over a document whose shape nobody declared would have to invent that
|
| 17 |
-
// shape from the current value β so adding a key would mean editing the
|
| 18 |
-
// form's idea of the schema, and the first machine write with a different
|
| 19 |
-
// shape would silently drop what it did not recognise.
|
| 20 |
-
// 2. PARSE ON SAVE, REFUSE WITH A SENTENCE. Never repair, never re-indent on
|
| 21 |
-
// the way in: `{a:1}` is not JSON and quietly "fixing" it to `{"a":1}`
|
| 22 |
-
// teaches a person their typo was fine, until the day a value cannot be
|
| 23 |
-
// guessed. The host applies the same rule at the write wall (C7), so a
|
| 24 |
-
// refusal here says the same thing the server would.
|
| 25 |
-
// 3. THE TREE
|
| 26 |
-
//
|
| 27 |
-
//
|
| 28 |
-
//
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
/
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
const
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
}
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
if (
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
/
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
);
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
}
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
<
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ---------------------------------------------------------------------------
|
| 2 |
+
// customer-grid / JsonViewer.tsx β β wave-23 C7 (owner item 5 / ruling R5).
|
| 3 |
+
//
|
| 4 |
+
// THE BIG VIEWER a json cell opens on click. One component, reached from two
|
| 5 |
+
// places (the grid cell's click path and the record drawer's value slot), for
|
| 6 |
+
// the reason `assetUrl` is one resolver: two readers of the same document that
|
| 7 |
+
// disagree about how it folds is a bug nobody can see in either one alone.
|
| 8 |
+
//
|
| 9 |
+
// The document is a STRING at rest (the scalar Row contract β see the `json`
|
| 10 |
+
// note in types.ts), so everything here is text in and text out. Nothing in
|
| 11 |
+
// this file ever writes a parsed OBJECT back.
|
| 12 |
+
//
|
| 13 |
+
// THREE decisions worth stating, because each has a plausible alternative:
|
| 14 |
+
//
|
| 15 |
+
// 1. THE RAW TAB IS THE EDITOR, and there is no field-by-field one. A form
|
| 16 |
+
// over a document whose shape nobody declared would have to invent that
|
| 17 |
+
// shape from the current value β so adding a key would mean editing the
|
| 18 |
+
// form's idea of the schema, and the first machine write with a different
|
| 19 |
+
// shape would silently drop what it did not recognise.
|
| 20 |
+
// 2. PARSE ON SAVE, REFUSE WITH A SENTENCE. Never repair, never re-indent on
|
| 21 |
+
// the way in: `{a:1}` is not JSON and quietly "fixing" it to `{"a":1}`
|
| 22 |
+
// teaches a person their typo was fine, until the day a value cannot be
|
| 23 |
+
// guessed. The host applies the same rule at the write wall (C7), so a
|
| 24 |
+
// refusal here says the same thing the server would.
|
| 25 |
+
// 3. THE TREE COLLAPSES BY DEPTH, not by hand-kept state per node beyond what
|
| 26 |
+
// the reader opens. A 200-key payload that arrives fully expanded is a
|
| 27 |
+
// scroll bar, not a document.
|
| 28 |
+
//
|
| 29 |
+
// β WAVE-27 item 13 (owner ruling R13) AMENDS decision 3: THE TREE IS EDITABLE
|
| 30 |
+
// NOW, two-way synced with the raw tab, and the raw text WINS on conflict.
|
| 31 |
+
//
|
| 32 |
+
// "Wins" is structural rather than a rule anybody has to enforce: `draft` (the
|
| 33 |
+
// raw text) is the single source of truth, `parsed` is derived from it, and the
|
| 34 |
+
// tree is a projection of `parsed`. A tree edit writes a new VALUE at a path,
|
| 35 |
+
// re-serialises the whole document and sets `draft` β so there is never a second
|
| 36 |
+
// copy of the document to reconcile, and a draft that stops parsing simply has
|
| 37 |
+
// no tree to show (the raw tab is where it gets read, exactly as before).
|
| 38 |
+
//
|
| 39 |
+
// β WHAT THE TREE EDITS, AND WHAT IT DELIBERATELY DOES NOT. Leaf VALUES, in
|
| 40 |
+
// place, keeping each leaf's own type. NOT keys, NOT structure, NOT a value's
|
| 41 |
+
// type β those stay on the raw tab, and that is decision 1 above still standing:
|
| 42 |
+
// a form that can add a key has to have an opinion about the document's shape,
|
| 43 |
+
// and nobody declared one. Editing `"12"` into `12` is a shape change, so it is
|
| 44 |
+
// a raw edit; editing `"Anna"` into `"Anne"` is a value change, so it is here.
|
| 45 |
+
// ---------------------------------------------------------------------------
|
| 46 |
+
|
| 47 |
+
import { useEffect, useId, useMemo, useRef, useState } from "react";
|
| 48 |
+
import type { ReactNode } from "react";
|
| 49 |
+
import { BodyPortal, useOverlayLayer } from "./OverlaySurface";
|
| 50 |
+
import { dayText, jsonParse, jsonPretty, MAX_JSON_BYTES, postsWindowOf } from "./display";
|
| 51 |
+
import type { PostSummary, PostsWindow } from "./display";
|
| 52 |
+
|
| 53 |
+
/** Bytes, not characters β the host's cap is on the stored UTF-8, and a
|
| 54 |
+
* document of 20,000 emoji is 80 KB. Counting `length` would let a value
|
| 55 |
+
* through here that the server then refuses, which is the one refusal a user
|
| 56 |
+
* cannot act on (nothing on screen said it was too big). */
|
| 57 |
+
export function jsonByteLength(text: string): number {
|
| 58 |
+
return typeof TextEncoder === "undefined"
|
| 59 |
+
? text.length
|
| 60 |
+
: new TextEncoder().encode(text).length;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
/** The one-line summary in the modal's header: what this document IS. */
|
| 64 |
+
export function jsonSummary(text: string): string {
|
| 65 |
+
const parsed = jsonParse(text);
|
| 66 |
+
const bytes = jsonByteLength(text);
|
| 67 |
+
const size = bytes < 1024 ? `${bytes} bytes` : `${(bytes / 1024).toFixed(1)} KB`;
|
| 68 |
+
if (String(text ?? "").trim() === "") return "Empty";
|
| 69 |
+
if (!parsed.ok) return `Not valid JSON Β· ${size}`;
|
| 70 |
+
const v = parsed.value;
|
| 71 |
+
if (Array.isArray(v)) return `${v.length} item${v.length === 1 ? "" : "s"} Β· ${size}`;
|
| 72 |
+
if (v !== null && typeof v === "object") {
|
| 73 |
+
const n = Object.keys(v as object).length;
|
| 74 |
+
return `${n} key${n === 1 ? "" : "s"} Β· ${size}`;
|
| 75 |
+
}
|
| 76 |
+
return `${v === null ? "null" : typeof v} Β· ${size}`;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
// --- the tree ---------------------------------------------------------------
|
| 80 |
+
|
| 81 |
+
/** How deep a node is open when the viewer mounts. Two levels shows the shape
|
| 82 |
+
* of every payload this product actually receives (an object of objects) and
|
| 83 |
+
* stops before the leaf spam of a scraped array. */
|
| 84 |
+
const OPEN_TO_DEPTH = 2;
|
| 85 |
+
|
| 86 |
+
function isBranch(v: unknown): v is Record<string, unknown> | unknown[] {
|
| 87 |
+
return v !== null && typeof v === "object";
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
/** The value's own text, in its own ink class. Strings keep their quotes: a
|
| 91 |
+
* bare `12` and a `"12"` are different documents and the tree is where that
|
| 92 |
+
* difference has to be visible. */
|
| 93 |
+
function Leaf({ v }: { v: unknown }): ReactNode {
|
| 94 |
+
if (v === null) return <span className="cg-json-null">null</span>;
|
| 95 |
+
if (typeof v === "string") return <span className="cg-json-str">"{v}"</span>;
|
| 96 |
+
if (typeof v === "number") return <span className="cg-json-num">{String(v)}</span>;
|
| 97 |
+
if (typeof v === "boolean") return <span className="cg-json-bool">{String(v)}</span>;
|
| 98 |
+
return <span className="cg-json-str">{String(v)}</span>;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
/**
|
| 102 |
+
* β R13 β the path a tree edit names, and the ONE function that applies it.
|
| 103 |
+
*
|
| 104 |
+
* Structural clone down the path only: every container on the way is copied, everything else is
|
| 105 |
+
* shared. That keeps a 32 KB document's edit cheap AND keeps the old value untouched, which is
|
| 106 |
+
* what makes the raw tab's Revert honest.
|
| 107 |
+
*
|
| 108 |
+
* β Returns the ORIGINAL root unchanged if the path does not resolve β a stale path (the raw tab
|
| 109 |
+
* changed the shape under an open tree) must not invent the containers it names. The caller reads
|
| 110 |
+
* that as "nothing to do" rather than silently growing the document a key it never had.
|
| 111 |
+
*/
|
| 112 |
+
function setAtPath(root: unknown, path: (string | number)[], next: unknown): unknown {
|
| 113 |
+
if (path.length === 0) return next;
|
| 114 |
+
const [head, ...rest] = path;
|
| 115 |
+
if (Array.isArray(root)) {
|
| 116 |
+
const i = typeof head === "number" ? head : Number(head);
|
| 117 |
+
if (!Number.isInteger(i) || i < 0 || i >= root.length) return root;
|
| 118 |
+
const copy = root.slice();
|
| 119 |
+
copy[i] = setAtPath(root[i], rest, next);
|
| 120 |
+
return copy;
|
| 121 |
+
}
|
| 122 |
+
if (root !== null && typeof root === "object") {
|
| 123 |
+
const obj = root as Record<string, unknown>;
|
| 124 |
+
const k = String(head);
|
| 125 |
+
if (!Object.prototype.hasOwnProperty.call(obj, k)) return root;
|
| 126 |
+
return { ...obj, [k]: setAtPath(obj[k], rest, next) };
|
| 127 |
+
}
|
| 128 |
+
return root;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
/**
|
| 132 |
+
* R13 β the in-place leaf editor.
|
| 133 |
+
*
|
| 134 |
+
* TYPE-PRESERVING by construction, which is the whole reason it is not one "edit as JSON" box:
|
| 135 |
+
* a string edits as text (no quotes to type), a number as a number, a boolean as its two values.
|
| 136 |
+
* A leaf therefore cannot change TYPE here β that is a shape change and belongs to the raw tab
|
| 137 |
+
* (see the amendment at the top of the file).
|
| 138 |
+
*
|
| 139 |
+
* β A number that does not parse is REFUSED, not repaired and not coerced to a string. This is
|
| 140 |
+
* decision 2 of the header applied one level down: quietly turning `12a` into `"12a"` teaches a
|
| 141 |
+
* person their typo was fine, right up until a consumer of the document expects arithmetic.
|
| 142 |
+
*/
|
| 143 |
+
function LeafEditor({
|
| 144 |
+
value,
|
| 145 |
+
onCommit,
|
| 146 |
+
onCancel,
|
| 147 |
+
}: {
|
| 148 |
+
value: string | number | boolean;
|
| 149 |
+
onCommit: (next: string | number | boolean) => void;
|
| 150 |
+
onCancel: () => void;
|
| 151 |
+
}) {
|
| 152 |
+
const kind = typeof value;
|
| 153 |
+
const [text, setText] = useState(() => String(value));
|
| 154 |
+
const [bad, setBad] = useState(false);
|
| 155 |
+
const commit = () => {
|
| 156 |
+
if (kind === "number") {
|
| 157 |
+
const n = Number(text.trim());
|
| 158 |
+
if (text.trim() === "" || !Number.isFinite(n)) {
|
| 159 |
+
setBad(true);
|
| 160 |
+
return;
|
| 161 |
+
}
|
| 162 |
+
onCommit(n);
|
| 163 |
+
return;
|
| 164 |
+
}
|
| 165 |
+
onCommit(text);
|
| 166 |
+
};
|
| 167 |
+
if (kind === "boolean")
|
| 168 |
+
return (
|
| 169 |
+
<select
|
| 170 |
+
className="cg-json-leafedit"
|
| 171 |
+
autoFocus
|
| 172 |
+
value={String(value)}
|
| 173 |
+
aria-label="Value"
|
| 174 |
+
onChange={(e) => onCommit(e.target.value === "true")}
|
| 175 |
+
onBlur={onCancel}
|
| 176 |
+
>
|
| 177 |
+
<option value="true">true</option>
|
| 178 |
+
<option value="false">false</option>
|
| 179 |
+
</select>
|
| 180 |
+
);
|
| 181 |
+
return (
|
| 182 |
+
<input
|
| 183 |
+
className={"cg-json-leafedit" + (bad ? " is-bad" : "")}
|
| 184 |
+
autoFocus
|
| 185 |
+
value={text}
|
| 186 |
+
spellCheck={false}
|
| 187 |
+
aria-label="Value"
|
| 188 |
+
aria-invalid={bad || undefined}
|
| 189 |
+
title={bad ? "That is not a number β the value was not changed." : undefined}
|
| 190 |
+
onChange={(e) => {
|
| 191 |
+
setText(e.target.value);
|
| 192 |
+
if (bad) setBad(false);
|
| 193 |
+
}}
|
| 194 |
+
onKeyDown={(e) => {
|
| 195 |
+
if (e.key === "Enter") {
|
| 196 |
+
e.preventDefault();
|
| 197 |
+
commit();
|
| 198 |
+
} else if (e.key === "Escape") {
|
| 199 |
+
e.preventDefault();
|
| 200 |
+
onCancel();
|
| 201 |
+
}
|
| 202 |
+
}}
|
| 203 |
+
// Blur commits rather than discards: a person who clicks away from an edit box in a
|
| 204 |
+
// document editor means "keep it" far more often than "throw it away", and Escape is the
|
| 205 |
+
// discard that is actually reachable.
|
| 206 |
+
onBlur={commit}
|
| 207 |
+
/>
|
| 208 |
+
);
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
function Node({
|
| 212 |
+
name,
|
| 213 |
+
value,
|
| 214 |
+
depth,
|
| 215 |
+
last,
|
| 216 |
+
path,
|
| 217 |
+
onValue,
|
| 218 |
+
editing,
|
| 219 |
+
onEditing,
|
| 220 |
+
}: {
|
| 221 |
+
name: string | null;
|
| 222 |
+
value: unknown;
|
| 223 |
+
depth: number;
|
| 224 |
+
last: boolean;
|
| 225 |
+
/** β R13 β where this node lives in the document, for `setAtPath`. */
|
| 226 |
+
path: (string | number)[];
|
| 227 |
+
/** β R13 β absent = the tree is READ-ONLY (the same condition `onSave` states one level up:
|
| 228 |
+
* a machine-owned, Odoo-sourced or unpermitted field). Present = leaves are editable. */
|
| 229 |
+
onValue?: (path: (string | number)[], next: unknown) => void;
|
| 230 |
+
/** The ONE leaf currently open for editing, as a joined path. Hoisted out of the node so
|
| 231 |
+
* opening a second editor closes the first β per-node state would leave a trail of open
|
| 232 |
+
* inputs down a document. */
|
| 233 |
+
editing?: string;
|
| 234 |
+
onEditing?: (key: string | undefined) => void;
|
| 235 |
+
}) {
|
| 236 |
+
const [open, setOpen] = useState(depth < OPEN_TO_DEPTH);
|
| 237 |
+
const pathKey = path.join(" |