Deploy AIOS web (React glide grid + FastAPI slice)
Browse files- RELEASES.json +7 -1
- VERSION +1 -1
- api/assistant_mirror.py +289 -0
- api/automation_engine.py +288 -8
- api/deps.py +250 -25
- api/main.py +11 -0
- api/routes_automation.py +32 -2
- api/routes_charts.py +220 -0
- api/routes_customers.py +0 -0
- api/routes_grid.py +319 -0
- api/routes_notes.py +109 -0
- platform/aios_grid.py +155 -3
- platform/core/chart_system.py +263 -0
- platform/core/grid_events.py +102 -31
- platform/core/user_tables.py +78 -0
- platform/model/topics/odoo_customers.yml +37 -3
- web/src/assistant/AssistantPage.tsx +41 -79
- web/src/automation/AutomationDetail.tsx +381 -35
- web/src/automation/automationApi.ts +34 -0
- web/src/customer-grid/CustomerGrid.tsx +153 -6
- web/src/customer-grid/DatePicker.tsx +156 -47
- web/src/customer-grid/MapView.tsx +0 -0
- web/src/customer-grid/RecordDetail.css +153 -0
- web/src/customer-grid/RouteNav.tsx +0 -0
- web/src/customer-grid/SavedChartNav.tsx +412 -0
- web/src/customer-grid/TimeSeriesPanel.tsx +120 -8
- web/src/customer-grid/Toolbar.tsx +31 -9
- web/src/customer-grid/ViewSidebar.tsx +383 -16
- web/src/customer-grid/folders.ts +45 -0
- web/src/customer-grid/map.css +16 -4
- web/src/customer-grid/routeZoneTypes.ts +144 -140
- web/src/customer-grid/theme.ts +32 -11
- web/src/customer-grid/viewModes.tsx +49 -11
- web/src/filter-kit/FieldsHidePanel.tsx +110 -68
- web/src/filter-kit/FilterBuilderPanel.tsx +26 -29
- web/src/manage-agent/ManageAgentPane.tsx +7 -1
- web/src/settings/ManageDatabase.tsx +294 -30
- web/src/settings/PermsEditor.tsx +220 -471
- web/src/settings/SettingsModal.tsx +8 -2
- web/src/shell/NavExtras.tsx +44 -10
- web/src/styles/wave45/data-applications.css +157 -152
- web/src/styles/wave46/map-panels.css +173 -5
RELEASES.json
CHANGED
|
@@ -1,6 +1,12 @@
|
|
| 1 |
{
|
| 2 |
-
"current": "
|
| 3 |
"releases": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
{
|
| 5 |
"version": "v60",
|
| 6 |
"sha": "dd1b062",
|
|
|
|
| 1 |
{
|
| 2 |
+
"current": "f34c12a",
|
| 3 |
"releases": [
|
| 4 |
+
{
|
| 5 |
+
"version": "v61",
|
| 6 |
+
"sha": "bbc4c07",
|
| 7 |
+
"date": "2026-08-30",
|
| 8 |
+
"subject": "v61 - wave 46 hotfix: D-590 schema overlay reaches the grid read (all three assemblies), D-599 route to zone association"
|
| 9 |
+
},
|
| 10 |
{
|
| 11 |
"version": "v60",
|
| 12 |
"sha": "dd1b062",
|
VERSION
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
f34c12a
|
api/assistant_mirror.py
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""assistant_mirror.py - the assistant's read of a MIRROR-SERVED connector database (R11 / C7).
|
| 2 |
+
|
| 3 |
+
ββ WHY THIS FILE EXISTS. `deps._assistant_user_table` reads a user table out of the tenant
|
| 4 |
+
document and refuses, 409, when the table does not materialise: *"this database is mirror-served
|
| 5 |
+
and needs its materialised reader"*. Its own comment named the missing half - *"E must consume the
|
| 6 |
+
mirror through its own `mirror_cursor`-guarded seam"* - and this is that seam. Owner R11: *"Why
|
| 7 |
+
can't it be queried by the AI if user has access to it? just query it using our own Filter work. I
|
| 8 |
+
want the AI to be able to use our tools."*
|
| 9 |
+
|
| 10 |
+
β C7 IS THE WHOLE CONSTRAINT, AND IT IS A CONSTRAINT ON WHAT THIS FILE MAY CONTAIN, not only on
|
| 11 |
+
what it must do: *"the assistant reads a mirror-served database through the SAME filter compiler
|
| 12 |
+
the grid uses, under `mirror_cursor` and the assistant's existing permission validation. No second
|
| 13 |
+
filter dialect, and no widening of what a scoped user may reach."* So every predicate below is
|
| 14 |
+
compiled by `harness.filter_sql.compile_filter_tree`, every column comes from
|
| 15 |
+
`routes_odoo_tables._filter_columns`, and the cursor comes from `routes_odoo_tables._mirror_cur`.
|
| 16 |
+
There is no hand-built SQL for a condition anywhere in this module. If you find yourself writing a
|
| 17 |
+
string with an operator in it, you are writing the second dialect this contract forbids.
|
| 18 |
+
|
| 19 |
+
β AND NO PERMISSION DECISION IS TAKEN HERE. This module is handed an already-resolved wall tree
|
| 20 |
+
and an already-resolved list of columns the caller's own filter may name; `deps.py` owns both,
|
| 21 |
+
through `_assistant_preflight_request`, which is the assistant's existing permission validation
|
| 22 |
+
that C7 says to reuse rather than restate. A second permission wall would be a second thing to
|
| 23 |
+
forget.
|
| 24 |
+
|
| 25 |
+
β IMPORT DIRECTION. `routes_odoo_tables` imports `deps` at module level, so BOTH the import from
|
| 26 |
+
`deps` into here and the import from here into `routes_odoo_tables` are lazy, inside the functions
|
| 27 |
+
that need them. A module-level import either way is a cycle at startup.
|
| 28 |
+
"""
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class MirrorRefusal(Exception):
|
| 32 |
+
"""A named, fail-closed refusal with the status and code `deps` should raise it as.
|
| 33 |
+
|
| 34 |
+
β AN EXCEPTION RATHER THAN A RETURN, so a caller cannot read "refused" as "no rows". This
|
| 35 |
+
module never answers a question it could not fully answer; the caller turns this into the
|
| 36 |
+
ordinary assistant error shape.
|
| 37 |
+
"""
|
| 38 |
+
|
| 39 |
+
def __init__(self, status, code, message):
|
| 40 |
+
super().__init__(message)
|
| 41 |
+
self.status = int(status)
|
| 42 |
+
self.code = str(code)
|
| 43 |
+
self.message = str(message)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def _rot():
|
| 47 |
+
"""The grid's own read-through module, imported lazily to break the `deps` cycle."""
|
| 48 |
+
import routes_odoo_tables
|
| 49 |
+
return routes_odoo_tables
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def open_cursor(session):
|
| 53 |
+
"""`(cursor, MirrorRefusal | None)` for THIS session's tenant. Exactly one is None.
|
| 54 |
+
|
| 55 |
+
β THE TWO FAILURES ARE NOT THE SAME FAILURE and the statuses differ, exactly as they do on
|
| 56 |
+
the grid door. `_mirror_cur` has already consumed `DatastoreMismatch` and hands it back as a
|
| 57 |
+
sentence, so a bare `RuntimeError` escaping it means the mirror is completing its first sync
|
| 58 |
+
and retrying works: 503. A mis-pinned process serving another tenant's file never becomes
|
| 59 |
+
un-mis-pinned by waiting: 409. Collapsing them would render the loudest refusal in the system
|
| 60 |
+
as a spinner.
|
| 61 |
+
"""
|
| 62 |
+
rot = _rot()
|
| 63 |
+
try:
|
| 64 |
+
cur, mismatch = rot._mirror_cur(session)
|
| 65 |
+
except RuntimeError as exc:
|
| 66 |
+
return None, MirrorRefusal(503, "assistant_store_not_ready", str(exc))
|
| 67 |
+
except Exception as exc: # noqa: BLE001
|
| 68 |
+
# β A DELIBERATE THIRD CLAUSE, and it is not laziness. This module is reached from
|
| 69 |
+
# `deps`, which every fixture and gate in the repo imports and drives with runtimes that
|
| 70 |
+
# are not a real `TenantRuntime`; `mirror_cursor` calls `assert_datastore_matches` on
|
| 71 |
+
# whatever it is handed. An unexpected failure there is a 500 on an assistant answer,
|
| 72 |
+
# which reads to a user as the product being broken rather than the mirror being shut.
|
| 73 |
+
# Named and fail-closed beats a stack trace.
|
| 74 |
+
return None, MirrorRefusal(409, "assistant_snapshot_unavailable",
|
| 75 |
+
f"this database's connector mirror could not be opened "
|
| 76 |
+
f"({exc})")
|
| 77 |
+
if mismatch:
|
| 78 |
+
return None, MirrorRefusal(409, "assistant_cross_tenant_store", str(mismatch))
|
| 79 |
+
return cur, None
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def binding(cur, table_key):
|
| 83 |
+
"""The resolved read-through spec for one connected grid, or None when it has no binding.
|
| 84 |
+
|
| 85 |
+
`None` is a real, reportable answer: this deployment's mirror carries no table for this grid,
|
| 86 |
+
which is not the same as the grid being empty.
|
| 87 |
+
"""
|
| 88 |
+
try:
|
| 89 |
+
return _rot()._source_for(cur, str(table_key or ""))
|
| 90 |
+
except Exception: # noqa: BLE001
|
| 91 |
+
# A spec that cannot be resolved is indistinguishable, to every caller, from a grid with
|
| 92 |
+
# no binding: neither can be read. Fail closed to the reportable answer.
|
| 93 |
+
return None
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def is_bound(cur, table_key):
|
| 97 |
+
"""CAN this deployment read `table_key` through the mirror at all? The availability question.
|
| 98 |
+
|
| 99 |
+
ββ THE CHEAP PREFIX OF `_source_for`, AND IT IS HERE BECAUSE THE FULL CALL COSTS 300 ms.
|
| 100 |
+
MEASURED on this worktree's mirror, warm: `_source_for('ut_odoo_accounts')` 2.9 ms, but
|
| 101 |
+
`ut_odoo_order_lines`, `ut_odoo_gl_lines` and `ut_odoo_orders` carry `needs_excluded`, and
|
| 102 |
+
that branch runs `odoo_relational.excluded_ids`, a scan of all 5,334 `res_partner` rows, at
|
| 103 |
+
44 ms to 297 ms EACH. `assistant_source_status` is called on mount by BOTH the Assistant and
|
| 104 |
+
Query and used to answer in 0.4 ms warm; resolving every read-through grid's full spec there
|
| 105 |
+
measured **+605 ms median** on the whole batch. A picker that now tells the truth about ten
|
| 106 |
+
databases must not cost two thirds of a second to say it.
|
| 107 |
+
|
| 108 |
+
β IT IS A PREFIX, NOT A SECOND ANSWER, and that distinction is what keeps it honest.
|
| 109 |
+
`_source_for` returns `None` in EXACTLY two cases: this deployment registers no spec for the
|
| 110 |
+
key, or the mirror carries no table behind one of the spec's aliases. Both are checked here,
|
| 111 |
+
with the same calls, in the same order. Everything after them in `_source_for` builds the
|
| 112 |
+
COLUMN EXPRESSIONS a read needs and cannot change whether the answer is `None`. The expensive
|
| 113 |
+
`excluded_ids` lookup is part of that second half.
|
| 114 |
+
β SO IF `_source_for` EVER GROWS A THIRD `return None`, THIS MUST FOLLOW IT. The failure that
|
| 115 |
+
would cause is bounded and visible rather than silent: a source reported answerable that then
|
| 116 |
+
answers a named refusal when actually read. It can never produce a wrong NUMBER, which is the
|
| 117 |
+
direction that matters.
|
| 118 |
+
"""
|
| 119 |
+
from harness import datastore
|
| 120 |
+
try:
|
| 121 |
+
spec = _rot()._sources().get(str(table_key or ""))
|
| 122 |
+
if not spec:
|
| 123 |
+
return False
|
| 124 |
+
aliases = dict(spec.get("tables") or {})
|
| 125 |
+
if spec.get("table"):
|
| 126 |
+
aliases.setdefault("", spec["table"])
|
| 127 |
+
return all(datastore.columns_of(name, cur=cur) for name in aliases.values())
|
| 128 |
+
except Exception: # noqa: BLE001
|
| 129 |
+
return False
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
def declared_fields(table_key):
|
| 133 |
+
"""`mk_fields()` for one connected grid, or None when this key is not a connected Odoo grid.
|
| 134 |
+
|
| 135 |
+
β THE STABLE MIRROR CONTRACT, NOT THE STORED DEFINITION. `odoo_relational.apply_plan` built
|
| 136 |
+
each table's stored `fields` from this same function, so reading it directly is reading the
|
| 137 |
+
source both agree on, and it is why `odoo_table_rows` uses it too. A stored definition can
|
| 138 |
+
also carry user-added columns that have no mirror expression at all.
|
| 139 |
+
"""
|
| 140 |
+
import odoo_relational
|
| 141 |
+
for _bucket, key, _label, mk_fields in odoo_relational.TABLES:
|
| 142 |
+
if key == str(table_key or ""):
|
| 143 |
+
return [dict(field) for field in (mk_fields() or [])
|
| 144 |
+
if isinstance(field, dict) and field.get("key")]
|
| 145 |
+
return None
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def answerable_fields(table_key, spec):
|
| 149 |
+
"""The declared field contract INTERSECTED with the columns the mirror can actually express.
|
| 150 |
+
|
| 151 |
+
β THE INTERSECTION IS THE POINT, and dropping it would be the quiet defect. A declared field
|
| 152 |
+
with no expression in `spec["cols"]` (a link, a rollup, a column this deployment has not
|
| 153 |
+
backfilled) cannot be answered from SQL at all. Offering it anyway would put it in the
|
| 154 |
+
assistant's field list, where a request naming it comes back present-but-empty rather than
|
| 155 |
+
refused - a wrong answer with nothing on screen saying so. Left out, `deps` answers a request
|
| 156 |
+
for it with a loud `assistant_unknown_field`.
|
| 157 |
+
"""
|
| 158 |
+
fields = declared_fields(table_key)
|
| 159 |
+
if fields is None:
|
| 160 |
+
return None
|
| 161 |
+
cols = set((spec or {}).get("cols") or ())
|
| 162 |
+
return [field for field in fields if field["key"] in cols]
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
def _compiled(nodes, conj, columns, *, code, subject, rot):
|
| 166 |
+
"""Compile ONE tree through the grid's compiler, or refuse. Never returns a partial predicate.
|
| 167 |
+
|
| 168 |
+
β THREE WAYS TO FAIL AND ALL THREE FAIL CLOSED, which is the same policy `odoo_table_rows`
|
| 169 |
+
carries for the administrator's wall - a column with no mirror expression, an operator with no
|
| 170 |
+
SQL form, an aggregate. The grid can afford to report an unpushable USER condition in its
|
| 171 |
+
`limits` array and let the client see it; the assistant's snapshot envelope has no such
|
| 172 |
+
channel, and an ignored condition does not narrow, it WIDENS. So on this path both trees
|
| 173 |
+
refuse.
|
| 174 |
+
"""
|
| 175 |
+
unknown = sorted(rot._leaf_cols(nodes) - set(columns))
|
| 176 |
+
if unknown:
|
| 177 |
+
raise MirrorRefusal(
|
| 178 |
+
409, code,
|
| 179 |
+
f"{subject} names {', '.join(unknown)}, and this database's live connection cannot "
|
| 180 |
+
f"read that column, so the condition cannot be applied here. Applying the rest would "
|
| 181 |
+
f"answer a wider question than the one asked")
|
| 182 |
+
try:
|
| 183 |
+
pred = rot._fs().compile_filter_tree(nodes, conj=conj, columns=columns,
|
| 184 |
+
today=rot._today())
|
| 185 |
+
except ValueError as exc:
|
| 186 |
+
raise MirrorRefusal(
|
| 187 |
+
409, code,
|
| 188 |
+
f"{subject} uses a condition this database's live connection cannot evaluate "
|
| 189 |
+
f"({exc}), so it is refused rather than ignored")
|
| 190 |
+
if pred is None:
|
| 191 |
+
return None
|
| 192 |
+
if pred.uses_aggregate:
|
| 193 |
+
raise MirrorRefusal(
|
| 194 |
+
409, code,
|
| 195 |
+
f"{subject} is a condition on an aggregate column, and this database's live "
|
| 196 |
+
f"connection cannot evaluate one of those a row at a time")
|
| 197 |
+
return pred
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
def read_rows(session, table_key, cur, spec, fields, *, wall_tree=None, filter_tree=None,
|
| 201 |
+
filter_keys=None):
|
| 202 |
+
"""Every permitted row of a mirror-served grid, or a refusal that names its cause.
|
| 203 |
+
|
| 204 |
+
Returns `(rows, stamp, total)`. `rows` are FULL canonical rows in `scoped_pool`'s shape
|
| 205 |
+
(`{pid, **cells}`), sorted by pid.
|
| 206 |
+
|
| 207 |
+
β NO TRUNCATION, EVER, AND THAT IS WHY THIS REFUSES RATHER THAN PAGES. Standing rule 1: a
|
| 208 |
+
connector's records get no cap, and a limit that genuinely cannot be removed must be REPORTED
|
| 209 |
+
with its cause and a recommended fix, never silently enforced. `routes_query._system_prompt`
|
| 210 |
+
states `PERMISSION-FILTERED RECORD COUNT: {len(records)}` to the model and the server computes
|
| 211 |
+
every aggregate from those same records, so a short set does not produce a smaller answer, it
|
| 212 |
+
produces a confidently WRONG one with nothing on screen saying so. `whole_pool` one file over
|
| 213 |
+
already settled this policy in the same words: REFUSE, NEVER TRIM.
|
| 214 |
+
|
| 215 |
+
β FULL CANONICAL ROWS, NOT THE PROJECTION. `deps.assistant_read_scope` runs the row wall and
|
| 216 |
+
the field projection in Python AFTER this returns. Hand it a row missing a column the wall
|
| 217 |
+
names and `filter_eval` reads `None` there and its verdict changes, so the belt-and-braces
|
| 218 |
+
pass would quietly disagree with the pushdown it is meant to double-check.
|
| 219 |
+
"""
|
| 220 |
+
from harness import datastore
|
| 221 |
+
rot = _rot()
|
| 222 |
+
fe = rot._fe()
|
| 223 |
+
|
| 224 |
+
cols = rot._filter_columns(spec, fields)
|
| 225 |
+
|
| 226 |
+
# ββ the administrator's wall, compiled FIRST and pushed down ββββββββββββββββββββββββββββββ
|
| 227 |
+
# β PUSHED DOWN RATHER THAN APPLIED AFTERWARDS, for one reason that is specific to this door:
|
| 228 |
+
# the row TOTAL below decides whether this read is refused as too large. A wall applied only
|
| 229 |
+
# in Python would count rows the reader may not see, and refuse a scoped user whose own slice
|
| 230 |
+
# of a million-row table is two hundred rows.
|
| 231 |
+
#
|
| 232 |
+
# β AND IT IS THE ASSISTANT'S WALL, NOT `row_scope_applies`. The grid door uses
|
| 233 |
+
# `perm_scope.row_scope_applies`, which is False for an admin. `assistant_apply_row_scope`
|
| 234 |
+
# has no admin break-glass: it applies the grant's filter to every caller. The caller hands
|
| 235 |
+
# the tree it will apply in Python, so the two passes are the SAME predicate by construction
|
| 236 |
+
# rather than by two spellings that agree today.
|
| 237 |
+
#
|
| 238 |
+
# READ THROUGH `tree_parts`, WHICH IS THE ONE READER OF THIS SHAPE. A stored wall is
|
| 239 |
+
# `{conj, nodes}` and both consumers need a bare node list plus a separate conj. Handing
|
| 240 |
+
# either the dict is silently EMPTY rather than an error, i.e. no wall at all, on the one path
|
| 241 |
+
# where that means serving the whole database.
|
| 242 |
+
where = spec.get("where") or ""
|
| 243 |
+
params = []
|
| 244 |
+
wall_nodes, wall_conj = fe.tree_parts(wall_tree)
|
| 245 |
+
if wall_nodes:
|
| 246 |
+
wall = _compiled(wall_nodes, wall_conj, cols, code="assistant_scope_not_applicable",
|
| 247 |
+
subject="the restriction an administrator set on your view of this "
|
| 248 |
+
"database", rot=rot)
|
| 249 |
+
if wall is not None:
|
| 250 |
+
where = f"({where}) AND {wall.sql}" if where else wall.sql
|
| 251 |
+
params.extend(wall.params)
|
| 252 |
+
|
| 253 |
+
# ββ the caller's own filter βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 254 |
+
# β AGAINST THE VISIBLE COLUMNS ONLY. `filter_keys` is the assistant's visible field list,
|
| 255 |
+
# already resolved by the caller's `_assistant_preflight_request`. Compiling against the full
|
| 256 |
+
# contract instead would let a scoped reader infer a hidden column's values by filtering on
|
| 257 |
+
# it, which is exactly the widening C7 forbids. The wall above is compiled against the FULL
|
| 258 |
+
# contract on purpose, precisely as `perm_scope._scoped` evaluates it against unstripped
|
| 259 |
+
# fields.
|
| 260 |
+
user_cols = ({key: value for key, value in cols.items() if key in set(filter_keys)}
|
| 261 |
+
if filter_keys is not None else dict(cols))
|
| 262 |
+
nodes, conj = fe.tree_parts(filter_tree)
|
| 263 |
+
if nodes:
|
| 264 |
+
pred = _compiled(nodes, conj, user_cols, code="assistant_filter_not_answerable",
|
| 265 |
+
subject="the filter on this request", rot=rot)
|
| 266 |
+
if pred is not None:
|
| 267 |
+
where = f"({where}) AND {pred.sql}" if where else pred.sql
|
| 268 |
+
params.extend(pred.params)
|
| 269 |
+
|
| 270 |
+
# β EXACTLY ONE of `table`/`from_sql` - `window` raises if both or neither arrive, so the
|
| 271 |
+
# spec's own shape decides and a malformed spec fails loudly instead of serving a wrong FROM.
|
| 272 |
+
select = ", ".join(f'{expr} AS "{key}"' for key, (expr, _c) in spec["cols"].items())
|
| 273 |
+
frm = {"from_sql": spec["from_sql"]} if spec.get("from_sql") else {"table": spec["table"]}
|
| 274 |
+
win = datastore.window(select=f'{spec["id"]} AS "_pid", {select}',
|
| 275 |
+
where=where, params=tuple(params), order_by=spec["id"],
|
| 276 |
+
limit=datastore.WINDOW_MAX, cur=cur, **frm)
|
| 277 |
+
if win["total"] > len(win["rows"]):
|
| 278 |
+
raise MirrorRefusal(
|
| 279 |
+
409, "assistant_source_too_large",
|
| 280 |
+
f"this database matches {win['total']:,} rows for that question, and the assistant "
|
| 281 |
+
f"reads a connected database in one pass of at most "
|
| 282 |
+
f"{datastore.WINDOW_MAX:,} rows, so answering now would mean counting only part of "
|
| 283 |
+
f"them and reporting the total as if it were whole. Narrow it with a filter and ask "
|
| 284 |
+
f"again")
|
| 285 |
+
|
| 286 |
+
stamp = rot.mirror_stamp(spec, cur, table_key, getattr(session, "runtime", None))
|
| 287 |
+
rows = rot._pool_from_window(spec, win, stamp=stamp)
|
| 288 |
+
rows.sort(key=lambda row: row["pid"])
|
| 289 |
+
return rows, stamp, int(win["total"])
|
api/automation_engine.py
CHANGED
|
@@ -61,6 +61,24 @@ STORE_KEY = "automations"
|
|
| 61 |
AGENT_CONTRACT_KEY = "agent_contracts"
|
| 62 |
AGENT_EVENT_TYPES = ("transcript", "message", "gathered_data", "run", "consent")
|
| 63 |
AGENT_ACTIONS = ("read", "create", "update", "overwrite", "delete")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
#: The user-table bucket. β Read/written HERE through `TenantRuntime`, never through
|
| 65 |
#: `core.user_tables` β that module writes the UNPREFIXED module-global key, which is correct for
|
| 66 |
#: tenant #0 (empty prefix) and silently cross-tenant for every R2 tenant after it. Booked in the
|
|
@@ -2856,6 +2874,107 @@ def create_agent_workflow(rt, agent_id, name, purpose=""):
|
|
| 2856 |
return result
|
| 2857 |
|
| 2858 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2859 |
def configure_agent_governance(rt, agent_id, raw, allowed_databases=None, allowed_users=None):
|
| 2860 |
"""Store private sharing and named-field grants after the caller's wall has narrowed them."""
|
| 2861 |
body = raw if isinstance(raw, dict) else {}
|
|
@@ -2894,6 +3013,24 @@ def configure_agent_governance(rt, agent_id, raw, allowed_databases=None, allowe
|
|
| 2894 |
clean[action] = sorted({str(v).strip()[:120] for v in value if str(v).strip()})
|
| 2895 |
if field_wall and not set(clean[action]).issubset(field_wall.get(str(table), set())):
|
| 2896 |
raise PermissionError("field permission denied before Agent execution")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2897 |
clean_dbs[str(table)] = clean
|
| 2898 |
clean_workflows[str(wid)] = clean_dbs
|
| 2899 |
rec["sharing"] = {"visibility": visibility, "sharedWith": users if visibility == "shared" else []}
|
|
@@ -2905,8 +3042,32 @@ def configure_agent_governance(rt, agent_id, raw, allowed_databases=None, allowe
|
|
| 2905 |
|
| 2906 |
|
| 2907 |
def authorize_agent_action(rt, agent_id, workflow_id, table, action, field="",
|
| 2908 |
-
actor_databases=None, actor_fields=None):
|
| 2909 |
-
"""Capability intersection. This must run before a model or provider is invoked.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2910 |
rec = _agent_contracts(rt).get(str(agent_id or "")) or {}
|
| 2911 |
actor_dbs = set(str(v) for v in (actor_databases or []))
|
| 2912 |
if str(table) not in actor_dbs:
|
|
@@ -2924,10 +3085,24 @@ def authorize_agent_action(rt, agent_id, workflow_id, table, action, field="",
|
|
| 2924 |
raise PermissionError(f"Agent {act} capability denied before execution")
|
| 2925 |
if actor_fields is not None and str(field) not in set(str(v) for v in actor_fields):
|
| 2926 |
raise PermissionError("field permission denied before Agent execution")
|
| 2927 |
-
if grant.get("mode") == "preview" and act in {"create", "update"}:
|
| 2928 |
-
return {"allowed": True, "mode": "preview", "action": act}
|
| 2929 |
else:
|
| 2930 |
raise PermissionError("unknown Agent capability")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2931 |
return {"allowed": True, "mode": str(grant.get("mode") or "preview"), "action": act}
|
| 2932 |
|
| 2933 |
|
|
@@ -11233,6 +11408,34 @@ def apply_actions(rt, defn, table_key, row_ids, username="automation", log=print
|
|
| 11233 |
log(f"[aios-auto] TikTok preset top-up on {table} failed: "
|
| 11234 |
f"{type(exc).__name__}: {exc}")
|
| 11235 |
rows = dict((ut_get(rt, table) or {}).get("rows") or {})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11236 |
if not rows:
|
| 11237 |
return counts
|
| 11238 |
# β NOTHING HERE TRACKS WHERE A RECORD "GOT TO" ANY MORE (wave 27 item 12, ruling R3). The
|
|
@@ -11243,6 +11446,22 @@ def apply_actions(rt, defn, table_key, row_ids, username="automation", log=print
|
|
| 11243 |
# The RUN LOG is the operational record of what happened now, and it is the only one.
|
| 11244 |
patches, creates = {}, {}
|
| 11245 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11246 |
#: ββ W33-T58 Β· D-191 β this record's web results, keyed by ACTION ID, and the run's job
|
| 11247 |
#: count. `web_done` is cleared per record (a batch is built from one row's interpolated
|
| 11248 |
#: values and means nothing for the next one); `web_jobs` counts JOBS across the whole run,
|
|
@@ -11403,6 +11622,30 @@ def apply_actions(rt, defn, table_key, row_ids, username="automation", log=print
|
|
| 11403 |
elif kind == "create_record":
|
| 11404 |
target = str(cfg.get("table") or "")
|
| 11405 |
vals = {k: interpolate(v, row) for k, v in (cfg.get("values") or {}).items()}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11406 |
# C5: keyed by (table, uniqueOn) rather than by table alone, because two actions
|
| 11407 |
# may legitimately write to ONE database on different keys β collapsing them onto
|
| 11408 |
# the table would silently apply one action's uniqueness rule to the other's rows.
|
|
@@ -11897,8 +12140,13 @@ def apply_actions(rt, defn, table_key, row_ids, username="automation", log=print
|
|
| 11897 |
# write `instagram:<handle>` verdicts, and without the scoping one of those
|
| 11898 |
# would silently suppress a TikTok read of a different person's account.
|
| 11899 |
elif kind == "find_records":
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11900 |
found = find_records(rt, cfg.get("table"), cfg.get("cond"),
|
| 11901 |
-
int(cfg.get("limit") or 25)
|
|
|
|
| 11902 |
counts["found"] += len(found)
|
| 11903 |
# β THE `review` BRANCH IS DELETED (wave 27 item 12, owner ruling R3), and it had
|
| 11904 |
# already stopped being reachable one wave earlier β which is the part worth reading.
|
|
@@ -11938,6 +12186,18 @@ def apply_actions(rt, defn, table_key, row_ids, username="automation", log=print
|
|
| 11938 |
counts.update(_tt_out)
|
| 11939 |
if _flush_notes:
|
| 11940 |
counts[RUN_NOTES_KEY] = _flush_notes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11941 |
# β C5: the REALIZED numbers overwrite the walk's attempt count. `counts["created"]` was
|
| 11942 |
# incremented once per create the flow decided to make; what landed is what the store says,
|
| 11943 |
# and with `uniqueOn` on they are routinely different (a re-run of a scheduled flow matches
|
|
@@ -12914,13 +13174,33 @@ def ai_decide(rt, defn, act, row, row_id="", log=print):
|
|
| 12914 |
return choice
|
| 12915 |
|
| 12916 |
|
| 12917 |
-
def find_records(rt, table_key, cond, limit=25):
|
| 12918 |
"""The `find_records` action's read: matching row ids, bounded and DISCLOSED (the caller puts
|
| 12919 |
-
the count in the run log, where it drills β [[no-unverifiable-aggregates]]).
|
| 12920 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12921 |
out = []
|
| 12922 |
for rid, row in rows.items():
|
| 12923 |
if lane_match(cond, row or {}):
|
|
|
|
|
|
|
| 12924 |
out.append(str(rid))
|
| 12925 |
if len(out) >= max(1, min(int(limit or 25), FIND_LIMIT_MAX)):
|
| 12926 |
break
|
|
|
|
| 61 |
AGENT_CONTRACT_KEY = "agent_contracts"
|
| 62 |
AGENT_EVENT_TYPES = ("transcript", "message", "gathered_data", "run", "consent")
|
| 63 |
AGENT_ACTIONS = ("read", "create", "update", "overwrite", "delete")
|
| 64 |
+
#: ββ W47-T21 / R3 β THE THREE NAMED REASONS AN AGENT'S ROW FILTER REFUSES WITH.
|
| 65 |
+
#:
|
| 66 |
+
#: R3, verbatim: an agent's row filter is *"its whole world: it may neither read nor write a
|
| 67 |
+
#: record outside the filter, and a Create that would land outside is refused with a NAMED
|
| 68 |
+
#: REASON"*. Named means the sentence says WHICH world the record fell outside of, not merely
|
| 69 |
+
#: "denied" β the wording style the four refusals already in `authorize_agent_action` set.
|
| 70 |
+
#:
|
| 71 |
+
#: β CONSTANTS RATHER THAN LITERALS BECAUSE THE REFUSAL HAPPENS AT TWO ALTITUDES AND MUST NOT
|
| 72 |
+
#: DRIFT BETWEEN THEM. `authorize_agent_action` RAISES them (the choke point, where a caller is
|
| 73 |
+
#: asking permission for one act and an exception is the answer); `apply_actions` PRINTS the same
|
| 74 |
+
#: sentence into the run notes and the log, because a scheduled run walks many records and an
|
| 75 |
+
#: exception there would refuse the ONE record by destroying the whole run. Two mechanisms, one
|
| 76 |
+
#: sentence β so what a person reads in a run log is what the API would have said.
|
| 77 |
+
#: β NO EM DASH AND NO EN DASH: these reach a screen (the run notes strip renders them, and the
|
| 78 |
+
#: routes turn the PermissionError into a 403 body). CLAUDE.md standing rule 2.
|
| 79 |
+
AGENT_ROW_READ_REFUSAL = "Agent read denied: this record is outside the Agent's row filter"
|
| 80 |
+
AGENT_ROW_CREATE_REFUSAL = "Agent create denied: this record would land outside the Agent's row filter"
|
| 81 |
+
AGENT_ROW_WRITE_REFUSAL = "Agent {act} denied: this record is outside the Agent's row filter"
|
| 82 |
#: The user-table bucket. β Read/written HERE through `TenantRuntime`, never through
|
| 83 |
#: `core.user_tables` β that module writes the UNPREFIXED module-global key, which is correct for
|
| 84 |
#: tenant #0 (empty prefix) and silently cross-tenant for every R2 tenant after it. Booked in the
|
|
|
|
| 2874 |
return result
|
| 2875 |
|
| 2876 |
|
| 2877 |
+
def _clean_agent_filter(raw):
|
| 2878 |
+
"""C4 β the SERVER MIRROR of `settings/permsModel.ts::parseFilter`. A tree WHOLE, or `None`.
|
| 2879 |
+
|
| 2880 |
+
β A FILTER IS TAKEN WHOLE OR NOT AT ALL, and that is the one rule in this function. A tree
|
| 2881 |
+
whose `nodes` is not a list is not a NARROWER filter, it is an UNREADABLE one: reading the
|
| 2882 |
+
conjunction and dropping the nodes would store a rule that admits everything, i.e. exactly
|
| 2883 |
+
the widest possible reading of a payload we could not parse. `parseFilter`'s own docstring
|
| 2884 |
+
makes the same argument on the client, and the two must answer identically or the editor
|
| 2885 |
+
shows a rule the server did not save.
|
| 2886 |
+
|
| 2887 |
+
β AN EMPTY TREE COLLAPSES TO `None`, WHICH MIRRORS `setFilter` RATHER THAN `parseFilter`,
|
| 2888 |
+
AND THE DIFFERENCE IS DELIBERATE. `parseFilter` is the READ side and passes `{nodes: []}`
|
| 2889 |
+
through untouched; `setFilter` is the WRITE side and collapses it to `null`. This function is
|
| 2890 |
+
a write path, so it takes the write side's rule: an emptied builder stores "no filter", not
|
| 2891 |
+
"a filter that asks nothing". Both readings admit every row, so nothing behaves differently
|
| 2892 |
+
today; storing the collapsed form is what keeps `hasFilter`-style tests honest for whoever
|
| 2893 |
+
writes one next. Do not "fix" this back to `parseFilter`'s pass-through.
|
| 2894 |
+
|
| 2895 |
+
β THE NODES ARE NOT VALIDATED LEAF BY LEAF HERE. `filter_eval.permits` runs in PERMISSION
|
| 2896 |
+
mode, where anything present but unanswerable DENIES, so a malformed leaf fails CLOSED at
|
| 2897 |
+
enforcement time. A grammar check duplicated here would be a second, drifting reader of the
|
| 2898 |
+
same tree, which is the failure C4 is written to prevent.
|
| 2899 |
+
"""
|
| 2900 |
+
if not isinstance(raw, dict):
|
| 2901 |
+
return None
|
| 2902 |
+
nodes = raw.get("nodes")
|
| 2903 |
+
if not isinstance(nodes, list) or not nodes:
|
| 2904 |
+
return None
|
| 2905 |
+
return {"conj": "or" if raw.get("conj") == "or" else "and", "nodes": copy.deepcopy(nodes)}
|
| 2906 |
+
|
| 2907 |
+
|
| 2908 |
+
def agent_row_wall(rt, agent_id, workflow_id="", table=""):
|
| 2909 |
+
"""R3's stored world for one (agent, workflow, database): `(filter tree, hidden field keys)`.
|
| 2910 |
+
|
| 2911 |
+
ββ FAIL-OPEN WHEN UNDECLARED, AND THAT SHAPE IS WHAT MAKES THIS SAFE TO CALL FROM
|
| 2912 |
+
`apply_actions`. That function is EVERY automation's walk, not only an agent's: the flows
|
| 2913 |
+
that fill Instagram tables, the scheduled discovery runs, the owner's own plain flows all go
|
| 2914 |
+
through it. No contract, no grant, or a grant with no `filter` means this returns
|
| 2915 |
+
`(None, set())` and the caller's behaviour is bit-identical to the day before this landed.
|
| 2916 |
+
A wall that narrowed anything by DEFAULT would silently stop rows in flows nobody
|
| 2917 |
+
permissioned, with the symptom "the automation quietly does less than it used to".
|
| 2918 |
+
|
| 2919 |
+
β THE RUN PATH RESOLVES **ONE** WORKFLOW, AND THAT LIMIT IS DECLARED RATHER THAN PAPERED
|
| 2920 |
+
OVER. A run carries no workflow id (`run_now` -> `apply_actions` knows the automation, not
|
| 2921 |
+
which of its workflows is speaking), so an empty `workflow_id` resolves the contract's FIRST
|
| 2922 |
+
workflow β which for every agent minted by `_new_agent_contract` is `wf_main`, the only one
|
| 2923 |
+
it has. β A SECOND WORKFLOW'S GRANT FOR THE SAME DATABASE IS THEREFORE NOT ENFORCED ON THE
|
| 2924 |
+
RUN PATH. Intersecting the trees was considered and rejected: nothing in C4 defines a
|
| 2925 |
+
composition rule for two permission filters, the user grant this one is a superset of has
|
| 2926 |
+
exactly one entry per (account, module), and an invented AND would show a two-workflow agent
|
| 2927 |
+
ZERO rows with nothing red anywhere. An honest declared gap beats a clever silent one.
|
| 2928 |
+
"""
|
| 2929 |
+
rec = _agent_contracts(rt).get(str(agent_id or "")) or {}
|
| 2930 |
+
wid = str(workflow_id or "")
|
| 2931 |
+
if not wid:
|
| 2932 |
+
wid = str(((rec.get("workflows") or [{}])[0] or {}).get("id") or "")
|
| 2933 |
+
grant = ((((rec.get("capabilities") or {}).get("workflows") or {})
|
| 2934 |
+
.get(wid) or {}).get(str(table)) or {})
|
| 2935 |
+
hidden = {str(v) for v in (grant.get("hiddenFields") or []) if str(v)}
|
| 2936 |
+
tree = grant.get("filter")
|
| 2937 |
+
return (tree if isinstance(tree, dict) and tree.get("nodes") else None), hidden
|
| 2938 |
+
|
| 2939 |
+
|
| 2940 |
+
def agent_row_permitted(tree, row, fields=None):
|
| 2941 |
+
"""Does R3's world contain this record? `filter_eval.permits`, never `matches`.
|
| 2942 |
+
|
| 2943 |
+
β `permits` IS THE PERMISSION EVALUATOR AND `matches` IS THE DISPLAY ONE, and picking the
|
| 2944 |
+
wrong twin here is a SILENT HOLE rather than a wrong answer: `matches` passes a rule it
|
| 2945 |
+
cannot answer (a leaf naming a column that has since been renamed away), so a filter that
|
| 2946 |
+
stopped being evaluable would stop stopping anything and every gate would stay green.
|
| 2947 |
+
`permits` denies exactly those, which is the fail-closed direction a wall needs.
|
| 2948 |
+
|
| 2949 |
+
β AN ABSENT TREE ADMITS, and that is `permits`' own contract rather than a shortcut taken
|
| 2950 |
+
here: "nothing declared" is not "nothing allowed". Whether an agent with no grant may reach
|
| 2951 |
+
the database AT ALL is `authorize_agent_action`'s database leg, which runs above this.
|
| 2952 |
+
|
| 2953 |
+
β THE IMPORT IS LAZY AND IN-FUNCTION, matching every other platform touch in this module
|
| 2954 |
+
(`from core import alerts`, `from harness import runtime`). This file has no top-level
|
| 2955 |
+
`core`/`harness` import and must not grow one: it is imported by routes that run in contexts
|
| 2956 |
+
where the platform package is resolved later.
|
| 2957 |
+
"""
|
| 2958 |
+
if not tree:
|
| 2959 |
+
return True
|
| 2960 |
+
from harness import filter_eval as fe
|
| 2961 |
+
return bool(fe.permits(tree, row if isinstance(row, dict) else {}, fields or []))
|
| 2962 |
+
|
| 2963 |
+
|
| 2964 |
+
def agent_visible_row(row, hidden):
|
| 2965 |
+
"""One record minus the field keys this agent's grant hides. `perm_scope.strip_row`, reused.
|
| 2966 |
+
|
| 2967 |
+
β THE FIELD LIST AND THE ROW PAYLOAD ARE TWO DIFFERENT WIRES β `strip_row`'s own docstring β
|
| 2968 |
+
so a caller that strips rows must narrow the FIELDS it ships beside them too, or the column
|
| 2969 |
+
disappears from the header while its values ride under the same keys. Both halves are done
|
| 2970 |
+
at this module's one agent read door, `routes_automation.run_rows`.
|
| 2971 |
+
"""
|
| 2972 |
+
if not hidden:
|
| 2973 |
+
return row
|
| 2974 |
+
from core import perm_scope
|
| 2975 |
+
return perm_scope.strip_row(row, hidden)
|
| 2976 |
+
|
| 2977 |
+
|
| 2978 |
def configure_agent_governance(rt, agent_id, raw, allowed_databases=None, allowed_users=None):
|
| 2979 |
"""Store private sharing and named-field grants after the caller's wall has narrowed them."""
|
| 2980 |
body = raw if isinstance(raw, dict) else {}
|
|
|
|
| 3013 |
clean[action] = sorted({str(v).strip()[:120] for v in value if str(v).strip()})
|
| 3014 |
if field_wall and not set(clean[action]).issubset(field_wall.get(str(table), set())):
|
| 3015 |
raise PermissionError("field permission denied before Agent execution")
|
| 3016 |
+
# ββ W47-T21 / C4 β THE ROW FILTER AND THE HIDDEN FIELDS, IN `permsModel.ts`'s
|
| 3017 |
+
# OWN VOCABULARY, AND THIS BLOCK IS WHY THEY SURVIVE A SAVE AT ALL. Everything
|
| 3018 |
+
# this function does not read into `clean` is DROPPED without a word, so a grant
|
| 3019 |
+
# arriving with a perfectly valid `filter` would have round-tripped as an empty
|
| 3020 |
+
# one and the editor would have shown the rule vanishing on reload.
|
| 3021 |
+
clean["filter"] = _clean_agent_filter(grant.get("filter"))
|
| 3022 |
+
hidden_raw = grant.get("hiddenFields")
|
| 3023 |
+
if hidden_raw is None:
|
| 3024 |
+
hidden_raw = []
|
| 3025 |
+
if not isinstance(hidden_raw, list):
|
| 3026 |
+
raise ValueError("hiddenFields needs a list of field keys")
|
| 3027 |
+
clean["hiddenFields"] = sorted({str(v).strip()[:120] for v in hidden_raw
|
| 3028 |
+
if str(v).strip()})
|
| 3029 |
+
# β THE SAME WALL THE VERB LISTS PASS THROUGH. A hidden-field list is a list of
|
| 3030 |
+
# this database's field keys like any other, and letting it name a key outside
|
| 3031 |
+
# the caller's own wall would let an editor describe a column it may not see.
|
| 3032 |
+
if field_wall and not set(clean["hiddenFields"]).issubset(field_wall.get(str(table), set())):
|
| 3033 |
+
raise PermissionError("field permission denied before Agent execution")
|
| 3034 |
clean_dbs[str(table)] = clean
|
| 3035 |
clean_workflows[str(wid)] = clean_dbs
|
| 3036 |
rec["sharing"] = {"visibility": visibility, "sharedWith": users if visibility == "shared" else []}
|
|
|
|
| 3042 |
|
| 3043 |
|
| 3044 |
def authorize_agent_action(rt, agent_id, workflow_id, table, action, field="",
|
| 3045 |
+
actor_databases=None, actor_fields=None, row=None, fields=None):
|
| 3046 |
+
"""Capability intersection. This must run before a model or provider is invoked.
|
| 3047 |
+
|
| 3048 |
+
ββ W47-T21 / R3 β `row` IS THE ROW-LEVEL LEG, AND IT IS THE ONE THING THIS CHOKE POINT
|
| 3049 |
+
HAD NO VERSION OF. R3: an agent's row filter is *"its whole world: it may neither read nor
|
| 3050 |
+
write a record outside the filter, and a Create that would land outside is refused with a
|
| 3051 |
+
named reason."* For `read`/`update`/`overwrite`/`delete` `row` is the EXISTING record; for
|
| 3052 |
+
`create` it is the PROPOSED one, which is why the parameter is the record rather than a row
|
| 3053 |
+
id β a create has no id to look up, and that is precisely the clause most easily dropped.
|
| 3054 |
+
|
| 3055 |
+
β BOTH NEW PARAMETERS ARE TRAILING AND OPTIONAL, AND THAT IS A COMPATIBILITY REQUIREMENT
|
| 3056 |
+
RATHER THAN A STYLE. `verify_w45_agent_operator.py` calls this at three sites with the
|
| 3057 |
+
existing eight arguments and is outside this ticket's fence; `row=None` means "no record was
|
| 3058 |
+
offered", so every one of those calls behaves exactly as it did. β It also means this leg
|
| 3059 |
+
CANNOT enforce anything a caller does not hand it a record for. That is why the run path is
|
| 3060 |
+
walled at its own doors (`apply_actions`) as well as here: a choke point that can only judge
|
| 3061 |
+
what it is shown is not a wall on its own.
|
| 3062 |
+
|
| 3063 |
+
ββ THE LEG SITS ABOVE THE PREVIEW SHORT-CIRCUIT, AND THE PREVIEW RETURN MOVED OUT OF THE
|
| 3064 |
+
WRITE-VERB BRANCH TO MAKE THAT TRUE. `create`/`update` under `mode == "preview"` used to
|
| 3065 |
+
return from INSIDE the `elif`, before the function's final return β so a row check appended
|
| 3066 |
+
at the end of this function would have been skipped for exactly those two verbs, i.e. for
|
| 3067 |
+
R3's create clause. It would have failed OPEN while reading as closed, and no test that only
|
| 3068 |
+
exercises `autonomous` mode could tell. The condition is unchanged and the two returns are
|
| 3069 |
+
byte-identical in what they answer; only the position moved.
|
| 3070 |
+
"""
|
| 3071 |
rec = _agent_contracts(rt).get(str(agent_id or "")) or {}
|
| 3072 |
actor_dbs = set(str(v) for v in (actor_databases or []))
|
| 3073 |
if str(table) not in actor_dbs:
|
|
|
|
| 3085 |
raise PermissionError(f"Agent {act} capability denied before execution")
|
| 3086 |
if actor_fields is not None and str(field) not in set(str(v) for v in actor_fields):
|
| 3087 |
raise PermissionError("field permission denied before Agent execution")
|
|
|
|
|
|
|
| 3088 |
else:
|
| 3089 |
raise PermissionError("unknown Agent capability")
|
| 3090 |
+
# ββ ROW LEG: AFTER THE DATABASE AND FIELD WALLS, ABOVE THE PREVIEW SHORT-CIRCUIT.
|
| 3091 |
+
#
|
| 3092 |
+
# β THE ORDER IS WHAT MAKES THE NON-CLAIM "a widened filter never silently widens the
|
| 3093 |
+
# DATABASE wall above it" TRUE BY CONSTRUCTION rather than by test. The `actor_databases` and
|
| 3094 |
+
# `actor_fields` refusals have already raised by the time control reaches here, so no filter
|
| 3095 |
+
# β however permissive, however edited β can be reached by a caller the database wall already
|
| 3096 |
+
# turned away. Widening a filter can only ever narrow LESS inside a wall that already held.
|
| 3097 |
+
if row is not None and grant.get("filter"):
|
| 3098 |
+
if not agent_row_permitted(grant.get("filter"), row, fields):
|
| 3099 |
+
if act == "read":
|
| 3100 |
+
raise PermissionError(AGENT_ROW_READ_REFUSAL)
|
| 3101 |
+
if act == "create":
|
| 3102 |
+
raise PermissionError(AGENT_ROW_CREATE_REFUSAL)
|
| 3103 |
+
raise PermissionError(AGENT_ROW_WRITE_REFUSAL.format(act=act))
|
| 3104 |
+
if act in {"create", "update"} and grant.get("mode") == "preview":
|
| 3105 |
+
return {"allowed": True, "mode": "preview", "action": act}
|
| 3106 |
return {"allowed": True, "mode": str(grant.get("mode") or "preview"), "action": act}
|
| 3107 |
|
| 3108 |
|
|
|
|
| 11408 |
log(f"[aios-auto] TikTok preset top-up on {table} failed: "
|
| 11409 |
f"{type(exc).__name__}: {exc}")
|
| 11410 |
rows = dict((ut_get(rt, table) or {}).get("rows") or {})
|
| 11411 |
+
# ββ W47-T21 / R3 β THE AGENT'S ROW FILTER, APPLIED TO THE WALK ITSELF.
|
| 11412 |
+
#
|
| 11413 |
+
# ββ BLAST RADIUS, SAID OUT LOUD BECAUSE IT IS THE WHOLE RISK OF THIS TICKET: this function
|
| 11414 |
+
# is EVERY automation's walk and `_commit_action_writes` below it is EVERY automation's
|
| 11415 |
+
# write, not only an agent's. What keeps that safe is the FAIL-OPEN-WHEN-UNDECLARED shape of
|
| 11416 |
+
# `agent_row_wall`: no agent contract, no grant for this database, or a grant carrying no
|
| 11417 |
+
# `filter` returns `(None, ...)`, this block does nothing, and the run is bit-identical to
|
| 11418 |
+
# the day before this landed. Nothing here narrows by default. A wall that did would stop
|
| 11419 |
+
# rows in the owner's own Instagram and discovery flows, whose symptom is "the automation
|
| 11420 |
+
# quietly does less than it used to" β the hardest kind of regression to see.
|
| 11421 |
+
#
|
| 11422 |
+
# β NARROWING THE WALK IS BOTH THE READ LEG AND THE UPDATE LEG AT ONCE, which is why it is
|
| 11423 |
+
# here rather than at two places. A record the filter excludes is never handed to `_walk`, so
|
| 11424 |
+
# no `update_record` can patch it, no `lane_match` can read it, and no interpolation can copy
|
| 11425 |
+
# a cell out of it. R3's "may neither read nor write a record outside the filter" is one
|
| 11426 |
+
# statement about one loop.
|
| 11427 |
+
#
|
| 11428 |
+
# β AND `hiddenFields` IS DELIBERATELY *NOT* STRIPPED FROM THESE ROWS. `interpolate`'s own
|
| 11429 |
+
# docstring: an unknown key resolves to EMPTY. So stripping a hidden column here would make
|
| 11430 |
+
# an `update_record` whose template names that column interpolate to "" and WRITE THAT EMPTY
|
| 11431 |
+
# OVER A REAL CELL β data loss caused by the permission wall, on cells the wall was never
|
| 11432 |
+
# asked about. The hide is enforced where rows LEAVE the engine (`routes_automation.run_rows`),
|
| 11433 |
+
# which is the wire a person actually reads; see this ticket's handoff for the declaration.
|
| 11434 |
+
_agent_tree, _agent_hidden = agent_row_wall(rt, str(defn.get("id") or ""), "", table)
|
| 11435 |
+
if _agent_tree:
|
| 11436 |
+
_tbl_fields = (ut_get(rt, table) or {}).get("fields") or []
|
| 11437 |
+
rows = {rid: row for rid, row in rows.items()
|
| 11438 |
+
if agent_row_permitted(_agent_tree, row or {}, _tbl_fields)}
|
| 11439 |
if not rows:
|
| 11440 |
return counts
|
| 11441 |
# β NOTHING HERE TRACKS WHERE A RECORD "GOT TO" ANY MORE (wave 27 item 12, ruling R3). The
|
|
|
|
| 11446 |
# The RUN LOG is the operational record of what happened now, and it is the only one.
|
| 11447 |
patches, creates = {}, {}
|
| 11448 |
|
| 11449 |
+
#: β W47-T21 β ONE RESOLVED WALL PER TARGET DATABASE. `create_record` and `find_records` may
|
| 11450 |
+
#: each name a database other than the one being walked, so the walked table's wall is not
|
| 11451 |
+
#: the whole answer. Memoised for the run because `agent_row_wall` reads the agent-contract
|
| 11452 |
+
#: bucket, and resolving it inside the per-record walk would be a store read per record per
|
| 11453 |
+
#: action β the same reason `enrich_plan` and `known_gone` are hoisted above the walk.
|
| 11454 |
+
_wall_memo = {table: (_agent_tree, _agent_hidden)}
|
| 11455 |
+
#: R3's create refusals, counted across the whole run and reported ONCE at the end. A note
|
| 11456 |
+
#: per record would print the same sentence a thousand times on a flow that creates per row.
|
| 11457 |
+
_create_refused = [0]
|
| 11458 |
+
|
| 11459 |
+
def _wall_for(tkey):
|
| 11460 |
+
key = str(tkey or "")
|
| 11461 |
+
if key not in _wall_memo:
|
| 11462 |
+
_wall_memo[key] = agent_row_wall(rt, str(defn.get("id") or ""), "", key)
|
| 11463 |
+
return _wall_memo[key]
|
| 11464 |
+
|
| 11465 |
#: ββ W33-T58 Β· D-191 β this record's web results, keyed by ACTION ID, and the run's job
|
| 11466 |
#: count. `web_done` is cleared per record (a batch is built from one row's interpolated
|
| 11467 |
#: values and means nothing for the next one); `web_jobs` counts JOBS across the whole run,
|
|
|
|
| 11622 |
elif kind == "create_record":
|
| 11623 |
target = str(cfg.get("table") or "")
|
| 11624 |
vals = {k: interpolate(v, row) for k, v in (cfg.get("values") or {}).items()}
|
| 11625 |
+
# ββ W47-T21 / R3 β THE CREATE CLAUSE, AND IT IS THE ONE THAT NEEDS THE
|
| 11626 |
+
# *PROPOSED* RECORD RATHER THAN AN EXISTING ONE. Every other leg of this wall
|
| 11627 |
+
# judges a row that is already in the store; a create has no id and no stored
|
| 11628 |
+
# row, so the thing judged is `vals` β the interpolated cells this action is
|
| 11629 |
+
# about to write. That is why the check lives HERE, at the moment the payload
|
| 11630 |
+
# exists, rather than in `_commit_action_writes` where the (table, uniqueOn)
|
| 11631 |
+
# grouping has already lost which action proposed what.
|
| 11632 |
+
#
|
| 11633 |
+
# β REFUSED, NOT SILENTLY DROPPED, and NOT folded into `createSkipped`. That
|
| 11634 |
+
# counter means "this row had no value for the unique key" β a property of the
|
| 11635 |
+
# DATA. A permission refusal is a property of the SYSTEM, and one number for
|
| 11636 |
+
# both is how a wall stops being visible (the same argument `capped` won against
|
| 11637 |
+
# `skipped` in `_commit_action_writes`). The named reason is reported once at the
|
| 11638 |
+
# end of the run, in the run notes a person actually reads.
|
| 11639 |
+
#
|
| 11640 |
+
# β `continue` RATHER THAN `raise`. `authorize_agent_action` raises the identical
|
| 11641 |
+
# sentence, because there a caller is asking about ONE act and an exception is
|
| 11642 |
+
# the answer. A scheduled run walks many records: raising would refuse this one
|
| 11643 |
+
# record by destroying the whole run, including the records the filter admits.
|
| 11644 |
+
_create_tree, _unused_hidden = _wall_for(target)
|
| 11645 |
+
if _create_tree and not agent_row_permitted(
|
| 11646 |
+
_create_tree, vals, (ut_get(rt, target) or {}).get("fields") or []):
|
| 11647 |
+
_create_refused[0] += 1
|
| 11648 |
+
continue
|
| 11649 |
# C5: keyed by (table, uniqueOn) rather than by table alone, because two actions
|
| 11650 |
# may legitimately write to ONE database on different keys β collapsing them onto
|
| 11651 |
# the table would silently apply one action's uniqueness rule to the other's rows.
|
|
|
|
| 12140 |
# write `instagram:<handle>` verdicts, and without the scoping one of those
|
| 12141 |
# would silently suppress a TikTok read of a different person's account.
|
| 12142 |
elif kind == "find_records":
|
| 12143 |
+
# β W47-T21 / R3 β the READ half of the wall reaches this action too, and it
|
| 12144 |
+
# names its OWN database (`cfg.table`), which need not be the walked one. The
|
| 12145 |
+
# wall is resolved through `_wall_for`, so a step pointed at a database the
|
| 12146 |
+
# agent has no grant on is unwalled exactly as it is today.
|
| 12147 |
found = find_records(rt, cfg.get("table"), cfg.get("cond"),
|
| 12148 |
+
int(cfg.get("limit") or 25),
|
| 12149 |
+
row_filter=_wall_for(cfg.get("table"))[0])
|
| 12150 |
counts["found"] += len(found)
|
| 12151 |
# β THE `review` BRANCH IS DELETED (wave 27 item 12, owner ruling R3), and it had
|
| 12152 |
# already stopped being reachable one wave earlier β which is the part worth reading.
|
|
|
|
| 12186 |
counts.update(_tt_out)
|
| 12187 |
if _flush_notes:
|
| 12188 |
counts[RUN_NOTES_KEY] = _flush_notes
|
| 12189 |
+
# ββ W47-T21 / R3 β THE NAMED REASON, REPORTED AFTER THE FLUSH MERGE AND NOT BEFORE.
|
| 12190 |
+
# The two lines above ASSIGN `RUN_NOTES_KEY` rather than appending to it, so a note written
|
| 12191 |
+
# earlier in this function would be silently discarded on any flow that also carries an
|
| 12192 |
+
# Instagram or TikTok step β the precise defect the comment above them describes, arriving
|
| 12193 |
+
# from a third writer. Appended to whatever is already there, for the same reason.
|
| 12194 |
+
# β ONE SENTENCE CARRYING THE COUNT, rather than one note per refused record: R3 asks for a
|
| 12195 |
+
# named reason, and a flow that creates per row would otherwise print the same sentence once
|
| 12196 |
+
# per record and bury every other note in the run.
|
| 12197 |
+
if _create_refused[0]:
|
| 12198 |
+
_refusal = (f"{_create_refused[0]} record(s) not created. {AGENT_ROW_CREATE_REFUSAL}")
|
| 12199 |
+
counts[RUN_NOTES_KEY] = list(counts.get(RUN_NOTES_KEY) or []) + [_refusal]
|
| 12200 |
+
log(f"[aios-auto] create_record: {_refusal}")
|
| 12201 |
# β C5: the REALIZED numbers overwrite the walk's attempt count. `counts["created"]` was
|
| 12202 |
# incremented once per create the flow decided to make; what landed is what the store says,
|
| 12203 |
# and with `uniqueOn` on they are routinely different (a re-run of a scheduled flow matches
|
|
|
|
| 13174 |
return choice
|
| 13175 |
|
| 13176 |
|
| 13177 |
+
def find_records(rt, table_key, cond, limit=25, row_filter=None):
|
| 13178 |
"""The `find_records` action's read: matching row ids, bounded and DISCLOSED (the caller puts
|
| 13179 |
+
the count in the run log, where it drills β [[no-unverifiable-aggregates]]).
|
| 13180 |
+
|
| 13181 |
+
ββ W47-T21 / R3 β `row_filter` IS THE AGENT'S WORLD, AND THIS IS A READ DOOR SO IT APPLIES
|
| 13182 |
+
HERE TOO. R3 says the filter governs reads as well as writes; a `find_records` step that
|
| 13183 |
+
could enumerate ids outside the agent's filter would be the read half of the rule leaking
|
| 13184 |
+
through the one action whose entire purpose is to find records the walk did not start with.
|
| 13185 |
+
|
| 13186 |
+
β IT NARROWS BEFORE THE LIMIT, NOT AFTER, and that ordering is the careful half. Filtering
|
| 13187 |
+
the first 25 ids the condition matched would return FEWER than 25 permitted records while
|
| 13188 |
+
reporting the cap as the reason, so the count in the run log would be a number about the
|
| 13189 |
+
wall rather than about the data β an unverifiable aggregate, which this action's own
|
| 13190 |
+
docstring already forbids in the sentence above.
|
| 13191 |
+
|
| 13192 |
+
β TRAILING AND OPTIONAL: absent means no wall was declared and this function is byte-for-byte
|
| 13193 |
+
what it was. `fields` are read off the table itself rather than passed, because this door
|
| 13194 |
+
already holds the table document and a caller-supplied list could disagree with it.
|
| 13195 |
+
"""
|
| 13196 |
+
doc = ut_get(rt, str(table_key or "")) or {}
|
| 13197 |
+
rows = doc.get("rows") or {}
|
| 13198 |
+
fields = doc.get("fields") or []
|
| 13199 |
out = []
|
| 13200 |
for rid, row in rows.items():
|
| 13201 |
if lane_match(cond, row or {}):
|
| 13202 |
+
if row_filter and not agent_row_permitted(row_filter, row or {}, fields):
|
| 13203 |
+
continue
|
| 13204 |
out.append(str(rid))
|
| 13205 |
if len(out) >= max(1, min(int(limit or 25), FIND_LIMIT_MAX)):
|
| 13206 |
break
|
api/deps.py
CHANGED
|
@@ -164,14 +164,30 @@ def _assistant_cached_builtin(session: Session, database: str, requested_fields=
|
|
| 164 |
return list(entry[1]), [dict(field) for field in fields if isinstance(field, dict)], entry[0]
|
| 165 |
|
| 166 |
|
| 167 |
-
|
| 168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
from core import user_tables
|
| 170 |
|
| 171 |
-
# A guessed `ut_*` key must never make `user_tables.get()` copy the tenant's rows before the
|
| 172 |
-
# table resolver refuses it. `all_defs` can fall back to a whole-document read for older
|
| 173 |
-
# stores, so use the runtime's projection primitive directly and fail closed if it is absent.
|
| 174 |
-
# The existing `may_open` remains THE resolver; it is lent this rows-dropped document.
|
| 175 |
try:
|
| 176 |
definitions = session.runtime.get_projection('user_tables', drop=('rows',))
|
| 177 |
except Exception:
|
|
@@ -189,6 +205,16 @@ def _assistant_user_table(session: Session, database: str, requested_fields=None
|
|
| 189 |
# for somebody else's database.
|
| 190 |
_assistant_refuse(403, "assistant_forbidden",
|
| 191 |
"your current permissions do not allow this database")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
fields = [dict(field) for field in (definition.get("fields") or [])
|
| 194 |
if isinstance(field, dict) and field.get("key")]
|
|
@@ -202,11 +228,20 @@ def _assistant_user_table(session: Session, database: str, requested_fields=None
|
|
| 202 |
_assistant_refuse(409, "assistant_snapshot_unavailable",
|
| 203 |
"this database changed before its stored snapshot could be read")
|
| 204 |
if not user_tables.materialises(database, st=session.runtime, defn=table):
|
| 205 |
-
#
|
| 206 |
-
#
|
| 207 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
_assistant_refuse(409, "assistant_snapshot_unavailable",
|
| 209 |
-
"this database
|
|
|
|
| 210 |
|
| 211 |
# A table's field contract was authorized from the rows-free definition. If it changed while
|
| 212 |
# the materialised document was fetched, fail rather than projecting a schema that was never
|
|
@@ -234,6 +269,102 @@ def _assistant_user_table(session: Session, database: str, requested_fields=None
|
|
| 234 |
return rows, fields, (table.get("updated") or table.get("created")), table.get("label") or database
|
| 235 |
|
| 236 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
def _assistant_requested_fields(fields, visible_fields):
|
| 238 |
"""Resolve an explicit field selection without turning an unknown key into an omission."""
|
| 239 |
by_key = {str(field.get("key")): field for field in visible_fields
|
|
@@ -276,8 +407,24 @@ def assistant_read_scope(session: Session, database, fields=None, filters=None):
|
|
| 276 |
label = _ASSISTANT_BUILT_INS[key]["label"]
|
| 277 |
source_kind = "runtime_cache"
|
| 278 |
elif key.startswith("ut_"):
|
| 279 |
-
|
| 280 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
else:
|
| 282 |
_assistant_refuse(404, "assistant_unknown_database", "that database is not available")
|
| 283 |
|
|
@@ -287,9 +434,13 @@ def assistant_read_scope(session: Session, database, fields=None, filters=None):
|
|
| 287 |
# Validate even that grant before evaluating it: `permits` would deny an unknown operand row
|
| 288 |
# by row, but the Assistant contract requires an explicit refusal for unresolved grants.
|
| 289 |
grant = perm_scope.assistant_entry(session.user, key)
|
| 290 |
-
if source_kind
|
| 291 |
# `_assistant_cached_builtin` already made this decision before touching its cache. Keep
|
| 292 |
# this guard adjacent to the field/row projection so a future source cannot forget it.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
_assistant_refuse(403, "assistant_forbidden",
|
| 294 |
"your current permissions do not allow this database")
|
| 295 |
try:
|
|
@@ -379,18 +530,32 @@ def assistant_source_status(session: Session, databases=None):
|
|
| 379 |
ββ `answerable` EXISTS BECAUSE `permitted` IS NOT THE QUESTION THE READER IS ASKING.
|
| 380 |
Measured on tenant #0, signed in, 2026-08-15: the Assistant offered **twelve** source chips
|
| 381 |
and could answer for **two**. The other ten are the `ut_odoo_*` grids, and
|
| 382 |
-
`_assistant_user_table`
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
β It is R6's SECOND SENTENCE, in the family that rule was written for β a limit that cannot be
|
| 388 |
removed must be REPORTED with its cause, never silently enforced.
|
| 389 |
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 394 |
|
| 395 |
β `databases=None` enumerates every source this tenant HAS (the two built-ins plus every
|
| 396 |
`ut_*` in the projection) rather than taking a caller-supplied list. A client list would make
|
|
@@ -402,6 +567,34 @@ def assistant_source_status(session: Session, databases=None):
|
|
| 402 |
|
| 403 |
definitions = None
|
| 404 |
read_definitions = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 405 |
|
| 406 |
def _definitions():
|
| 407 |
nonlocal definitions, read_definitions
|
|
@@ -436,8 +629,11 @@ def assistant_source_status(session: Session, databases=None):
|
|
| 436 |
# `GET /query` listed nine sources and `product_data` was not among them, while
|
| 437 |
# `POST /query/chat {database:"product_data"}` answered 403 `assistant_forbidden` β
|
| 438 |
# for a database the SAME account opens from the nav, holds saved views on, and can
|
| 439 |
-
# see in the Database flyout. The
|
| 440 |
-
#
|
|
|
|
|
|
|
|
|
|
| 441 |
# β THE ASYMMETRY IS THE DEFECT, NOT THE REFUSAL. R6's second sentence: a limit that
|
| 442 |
# cannot be removed must be REPORTED with its cause, never silently enforced.
|
| 443 |
# β `visible` IS WHAT KEEPS THIS FROM BEING A DISCLOSURE. A source the caller cannot
|
|
@@ -495,8 +691,37 @@ def assistant_source_status(session: Session, databases=None):
|
|
| 495 |
row["permitted"] = True
|
| 496 |
if user_tables.materialises(key, st=lent, defn=definition):
|
| 497 |
row["answerable"] = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 498 |
else:
|
| 499 |
-
row["reason"] = "
|
|
|
|
|
|
|
| 500 |
return out
|
| 501 |
|
| 502 |
|
|
|
|
| 164 |
return list(entry[1]), [dict(field) for field in fields if isinstance(field, dict)], entry[0]
|
| 165 |
|
| 166 |
|
| 167 |
+
#: ββ THE TWO WAYS A `ut_*` DATABASE REACHES THE ASSISTANT, AS A SET RATHER THAN AN `or`.
|
| 168 |
+
#: Both are walled by `user_tables.may_open` inside their reader, which is why both tolerate a
|
| 169 |
+
#: `None` assistant grant at the row/field projection below - and why a THIRD user-table source
|
| 170 |
+
#: added later must be added here too or it will be refused for the wrong reason.
|
| 171 |
+
_ASSISTANT_USER_TABLE_KINDS = frozenset({"materialised_user_table", "mirror_user_table"})
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
def _assistant_table_defn(session: Session, database: str):
|
| 175 |
+
"""The rows-free definition for one `ut_*` database plus its lent runtime, after `may_open`.
|
| 176 |
+
|
| 177 |
+
β THE ROWS-FREE PROJECTION IS THE POINT, not a micro-optimisation. A guessed `ut_*` key must
|
| 178 |
+
never make `user_tables.get()` copy the tenant's rows before the table resolver refuses it,
|
| 179 |
+
and `all_defs` can fall back to a whole-document read for older stores, so the runtime's
|
| 180 |
+
projection primitive is used directly and an absent one fails closed. The existing `may_open`
|
| 181 |
+
remains THE resolver; it is lent this rows-dropped document.
|
| 182 |
+
|
| 183 |
+
β FACTORED OUT (W47-T23) because there are now TWO readers behind this one wall - the
|
| 184 |
+
materialised document reader and the mirror reader - and `assistant_read_scope` has to know
|
| 185 |
+
which of them applies BEFORE it calls either. Reading the projection once and handing the
|
| 186 |
+
definition down keeps that dispatch from costing a second store read, and keeps the two
|
| 187 |
+
readers from growing two ideas of who may open a database.
|
| 188 |
+
"""
|
| 189 |
from core import user_tables
|
| 190 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
try:
|
| 192 |
definitions = session.runtime.get_projection('user_tables', drop=('rows',))
|
| 193 |
except Exception:
|
|
|
|
| 205 |
# for somebody else's database.
|
| 206 |
_assistant_refuse(403, "assistant_forbidden",
|
| 207 |
"your current permissions do not allow this database")
|
| 208 |
+
return definition, definition_runtime
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
def _assistant_user_table(session: Session, database: str, requested_fields=None, filters=None,
|
| 212 |
+
*, defn=None, lent=None):
|
| 213 |
+
"""Read a materialised user-table document after a rows-free database grant check."""
|
| 214 |
+
from core import user_tables
|
| 215 |
+
|
| 216 |
+
definition, _lent = ((defn, lent) if isinstance(defn, dict)
|
| 217 |
+
else _assistant_table_defn(session, database))
|
| 218 |
|
| 219 |
fields = [dict(field) for field in (definition.get("fields") or [])
|
| 220 |
if isinstance(field, dict) and field.get("key")]
|
|
|
|
| 228 |
_assistant_refuse(409, "assistant_snapshot_unavailable",
|
| 229 |
"this database changed before its stored snapshot could be read")
|
| 230 |
if not user_tables.materialises(database, st=session.runtime, defn=table):
|
| 231 |
+
# ββ W47-T23 / R11 - THIS IS NO LONGER THE ANSWER FOR A MIRROR-SERVED DATABASE, and the
|
| 232 |
+
# seam this comment used to ask for now exists: `assistant_mirror.py`, reached through
|
| 233 |
+
# `_assistant_mirror_table`. `assistant_read_scope` reads `materialises` off the rows-free
|
| 234 |
+
# DEFINITION and dispatches there before this reader is ever entered.
|
| 235 |
+
# β SO WHAT SURVIVES HERE IS A RACE GUARD, NOT A POLICY. It fires only when the definition
|
| 236 |
+
# said "materialised" at dispatch and the fetched document says otherwise, i.e. the table
|
| 237 |
+
# was un-materialised between the two reads. Returning an empty table would be a false
|
| 238 |
+
# answer, so it still refuses; it is simply no longer the ten `ut_odoo_*` grids' fate.
|
| 239 |
+
# β DO NOT "FIX" THIS BY FLIPPING `readThrough`. D-378 says these tables' classification
|
| 240 |
+
# is separately wrong; changing the flag to make a read pass would hide that defect and
|
| 241 |
+
# move ten grids onto the wrong reader.
|
| 242 |
_assistant_refuse(409, "assistant_snapshot_unavailable",
|
| 243 |
+
"this database stopped storing its rows while it was being read; ask "
|
| 244 |
+
"again and it will be read from its connector mirror instead")
|
| 245 |
|
| 246 |
# A table's field contract was authorized from the rows-free definition. If it changed while
|
| 247 |
# the materialised document was fetched, fail rather than projecting a schema that was never
|
|
|
|
| 269 |
return rows, fields, (table.get("updated") or table.get("created")), table.get("label") or database
|
| 270 |
|
| 271 |
|
| 272 |
+
def _assistant_mirror_table(session: Session, database: str, requested_fields=None, filters=None,
|
| 273 |
+
*, defn=None, lent=None):
|
| 274 |
+
"""Read a MIRROR-SERVED user table through the same filter compiler the grid uses (R11 / C7).
|
| 275 |
+
|
| 276 |
+
Returns `_assistant_user_table`'s 4-tuple - `(rows, fields, source_version, label)` - so the
|
| 277 |
+
dispatcher below can swap one for the other and nothing downstream changes.
|
| 278 |
+
|
| 279 |
+
ββ OWNER R11, VERBATIM: *"Why can't it be queried by the AI if user has access to it? just
|
| 280 |
+
query it using our own Filter work. I want the AI to be able to use our tools."* Ten
|
| 281 |
+
`ut_odoo_*` databases were offered to the assistant and refused one spent prompt at a time,
|
| 282 |
+
because their rows left the tenant document for the DuckDB mirror and this boundary had no
|
| 283 |
+
mirror reader. It has one now, and it is the grid's own: `routes_odoo_tables`'s cursor guard,
|
| 284 |
+
its column resolver, its window, and `harness.filter_sql`.
|
| 285 |
+
|
| 286 |
+
β THE OPENING IS `_assistant_user_table`'S, DELIBERATELY UNCHANGED - rows-free projection,
|
| 287 |
+
`may_open`, `_assistant_preflight_request`. C7: *"the assistant's existing permission
|
| 288 |
+
validation"*, reused rather than restated. Only the ROW SOURCE differs.
|
| 289 |
+
β AND IT NEVER CALLS `user_tables.get()`. That whole-document read is precisely what this
|
| 290 |
+
path exists to avoid: the rows are not in the document, and fetching 28.6 MB to discover that
|
| 291 |
+
is the cost `assistant_permitted_sources` was written to stop paying.
|
| 292 |
+
|
| 293 |
+
β THE FIELD CONTRACT IS `mk_fields()` INTERSECTED WITH THE MIRROR'S COLUMNS, not the stored
|
| 294 |
+
`fields`. A declared field with no mirror expression (a link, a rollup) cannot be answered
|
| 295 |
+
from SQL, so offering it would return it silently absent; left out, `_assistant_requested_fields`
|
| 296 |
+
refuses a request naming it with a loud `assistant_unknown_field`. The preflight therefore
|
| 297 |
+
runs against THAT list, so the grant, the wall and the request are all validated against what
|
| 298 |
+
can actually be read.
|
| 299 |
+
"""
|
| 300 |
+
import assistant_mirror
|
| 301 |
+
import core.perm_scope as perm_scope
|
| 302 |
+
|
| 303 |
+
definition, _lent = ((defn, lent) if isinstance(defn, dict)
|
| 304 |
+
else _assistant_table_defn(session, database))
|
| 305 |
+
|
| 306 |
+
# THE CHEAP QUESTION FIRST, and it needs no cursor: is this key a connected Odoo grid at all?
|
| 307 |
+
# A `readThrough` table that is not one has no mirror rows anywhere, and asking the mirror
|
| 308 |
+
# about it would open a cursor to learn nothing.
|
| 309 |
+
if assistant_mirror.declared_fields(database) is None:
|
| 310 |
+
_assistant_refuse(409, "assistant_snapshot_unavailable",
|
| 311 |
+
"this database does not store its rows and it is not one of the "
|
| 312 |
+
"connected databases the assistant can read from the mirror")
|
| 313 |
+
cur, refusal = assistant_mirror.open_cursor(session)
|
| 314 |
+
if refusal is not None:
|
| 315 |
+
_assistant_refuse(refusal.status, refusal.code, refusal.message)
|
| 316 |
+
spec = assistant_mirror.binding(cur, database)
|
| 317 |
+
if spec is None:
|
| 318 |
+
_assistant_refuse(409, "assistant_snapshot_unavailable",
|
| 319 |
+
"this database is served live from its connector and this deployment "
|
| 320 |
+
"has no read-through binding for it yet, so it holds no rows to read")
|
| 321 |
+
fields = assistant_mirror.answerable_fields(database, spec)
|
| 322 |
+
if not fields:
|
| 323 |
+
_assistant_refuse(409, "assistant_snapshot_unavailable",
|
| 324 |
+
"this database's connector mirror carries none of its declared columns "
|
| 325 |
+
"on this deployment, so there is nothing to answer from")
|
| 326 |
+
|
| 327 |
+
grant, visible = _assistant_preflight_request(session, database, fields, requested_fields,
|
| 328 |
+
filters, require_explicit_grant=False)
|
| 329 |
+
|
| 330 |
+
# β COMPILE THE **VALIDATED** TREES, NEVER THE RAW ONES, and this is what makes the done-when
|
| 331 |
+
# structural rather than lucky. `assistant_read_scope` runs `filter_eval.permits` over
|
| 332 |
+
# `validate_assistant_filter`'s RETURN, and `assistant_apply_row_scope` over the grant's tree.
|
| 333 |
+
# Pushing the raw input to SQL instead would mean the pushdown and the Python pass are two
|
| 334 |
+
# predicates that happen to agree, which is this repo's recorded defect class. Same input to
|
| 335 |
+
# both compilers, same answer by construction.
|
| 336 |
+
try:
|
| 337 |
+
wall_tree = perm_scope.validate_assistant_filter((grant or {}).get("filter"), fields)
|
| 338 |
+
filter_tree = perm_scope.validate_assistant_filter(filters, visible)
|
| 339 |
+
except ValueError as exc:
|
| 340 |
+
_assistant_refuse(400, "assistant_bad_filter", str(exc))
|
| 341 |
+
raise # unreachable; keeps the names bound for a reader
|
| 342 |
+
# β NO GRANT MEANS NO ROW WALL ON THIS PATH, matching `assistant_read_scope` exactly: it
|
| 343 |
+
# applies `assistant_apply_row_scope` only when a grant resolved, because `may_open` above is
|
| 344 |
+
# what admitted a user table. Pushing a wall down that Python will not apply would narrow the
|
| 345 |
+
# answer below what the caller is entitled to, which is a wrong number in the other direction.
|
| 346 |
+
if grant is None:
|
| 347 |
+
wall_tree = None
|
| 348 |
+
|
| 349 |
+
try:
|
| 350 |
+
rows, stamp, total = assistant_mirror.read_rows(
|
| 351 |
+
session, database, cur, spec, fields,
|
| 352 |
+
wall_tree=wall_tree, filter_tree=filter_tree,
|
| 353 |
+
filter_keys=[field["key"] for field in visible
|
| 354 |
+
if isinstance(field, dict) and field.get("key")])
|
| 355 |
+
except assistant_mirror.MirrorRefusal as exc:
|
| 356 |
+
_assistant_refuse(exc.status, exc.code, exc.message)
|
| 357 |
+
raise # unreachable; see above
|
| 358 |
+
|
| 359 |
+
# β PROVENANCE A CITATION CAN CARRY. `routes_query._system_prompt` runs
|
| 360 |
+
# `json.dumps(source_version, default=str)`, so this stays plain JSON: when the mirror last
|
| 361 |
+
# reconciled this table against its connector, and how many rows the answer was computed over.
|
| 362 |
+
# The count is here because the model is told the record count separately, and a reader
|
| 363 |
+
# checking one against the other should find the same integer.
|
| 364 |
+
source_version = {"read": "connector mirror", "refreshed": stamp, "rows": total}
|
| 365 |
+
return rows, fields, source_version, definition.get("label") or database
|
| 366 |
+
|
| 367 |
+
|
| 368 |
def _assistant_requested_fields(fields, visible_fields):
|
| 369 |
"""Resolve an explicit field selection without turning an unknown key into an omission."""
|
| 370 |
by_key = {str(field.get("key")): field for field in visible_fields
|
|
|
|
| 407 |
label = _ASSISTANT_BUILT_INS[key]["label"]
|
| 408 |
source_kind = "runtime_cache"
|
| 409 |
elif key.startswith("ut_"):
|
| 410 |
+
# ββ W47-T23 / R11 - TWO READERS BEHIND ONE WALL, CHOSEN OFF THE ROWS-FREE DEFINITION.
|
| 411 |
+
# `_assistant_table_defn` is read ONCE here and lent to whichever reader applies, so the
|
| 412 |
+
# dispatch costs no extra store read and the two readers cannot grow two ideas of who may
|
| 413 |
+
# open a database. `materialises` is the FIRST of the two predicates
|
| 414 |
+
# `assistant_source_status` reports `answerable` from, and the mirror binding is the
|
| 415 |
+
# second, so the picker and the reader admit the same set by construction.
|
| 416 |
+
# β THE FLAG IS READ, NEVER WRITTEN. D-378 says these tables' `readThrough` classification
|
| 417 |
+
# is separately wrong; the fix for that is not to reclassify them here so a read passes.
|
| 418 |
+
from core import user_tables
|
| 419 |
+
_defn, _lent = _assistant_table_defn(session, key)
|
| 420 |
+
if user_tables.materialises(key, st=_lent, defn=_defn):
|
| 421 |
+
rows, canonical_fields, source_version, label = _assistant_user_table(
|
| 422 |
+
session, key, fields, filters, defn=_defn, lent=_lent)
|
| 423 |
+
source_kind = "materialised_user_table"
|
| 424 |
+
else:
|
| 425 |
+
rows, canonical_fields, source_version, label = _assistant_mirror_table(
|
| 426 |
+
session, key, fields, filters, defn=_defn, lent=_lent)
|
| 427 |
+
source_kind = "mirror_user_table"
|
| 428 |
else:
|
| 429 |
_assistant_refuse(404, "assistant_unknown_database", "that database is not available")
|
| 430 |
|
|
|
|
| 434 |
# Validate even that grant before evaluating it: `permits` would deny an unknown operand row
|
| 435 |
# by row, but the Assistant contract requires an explicit refusal for unresolved grants.
|
| 436 |
grant = perm_scope.assistant_entry(session.user, key)
|
| 437 |
+
if source_kind not in _ASSISTANT_USER_TABLE_KINDS and grant is None:
|
| 438 |
# `_assistant_cached_builtin` already made this decision before touching its cache. Keep
|
| 439 |
# this guard adjacent to the field/row projection so a future source cannot forget it.
|
| 440 |
+
# β A SET, NOT AN `or`, AND BOTH USER-TABLE KINDS ARE IN IT (W47-T23). Either reader has
|
| 441 |
+
# already passed `user_tables.may_open`, which is the wall for that family; requiring a
|
| 442 |
+
# SECOND, assistant-specific grant here would refuse a table the user demonstrably holds.
|
| 443 |
+
# Spelled as membership so a third user-table source is one line, not a growing chain.
|
| 444 |
_assistant_refuse(403, "assistant_forbidden",
|
| 445 |
"your current permissions do not allow this database")
|
| 446 |
try:
|
|
|
|
| 530 |
ββ `answerable` EXISTS BECAUSE `permitted` IS NOT THE QUESTION THE READER IS ASKING.
|
| 531 |
Measured on tenant #0, signed in, 2026-08-15: the Assistant offered **twelve** source chips
|
| 532 |
and could answer for **two**. The other ten are the `ut_odoo_*` grids, and
|
| 533 |
+
`_assistant_user_table` refused every one of them because their rows live UNCAPPED in the
|
| 534 |
+
DuckDB mirror and are read through it (W30/R6 is exactly why). The refusal was correct, named
|
| 535 |
+
and fail-closed. The defect was that it arrived one spent prompt at a time: a picker that
|
| 536 |
+
offers ten doors which cannot open is the same shape as the rail that painted two rows
|
| 537 |
+
differently from five.
|
| 538 |
β It is R6's SECOND SENTENCE, in the family that rule was written for β a limit that cannot be
|
| 539 |
removed must be REPORTED with its cause, never silently enforced.
|
| 540 |
|
| 541 |
+
ββ W47-T23 / OWNER R11 β **THE LIMIT IS NOW CLOSED, NOT EXPLAINED**, so `answerable` has TWO
|
| 542 |
+
ways to be true. Owner: *"Why can't it be queried by the AI if user has access to it? just
|
| 543 |
+
query it using our own Filter work. I want the AI to be able to use our tools."* A `ut_*`
|
| 544 |
+
database is answerable when it materialises OR when this deployment has a read-through
|
| 545 |
+
binding for it, because `_assistant_mirror_table` reads that binding through the same filter
|
| 546 |
+
compiler the grid uses. MEASURED on this worktree, all eight connected grids declared
|
| 547 |
+
read-through: **four answerable** (`ut_odoo_accounts`, `ut_odoo_gl_lines`,
|
| 548 |
+
`ut_odoo_order_lines`, `ut_odoo_orders`), four still reported with their cause, which is that
|
| 549 |
+
this deployment's mirror carries no table behind them.
|
| 550 |
+
|
| 551 |
+
β IT NO LONGER COSTS NOTHING, AND THE PRICE IS STATED RATHER THAN LEFT TO BE FOUND.
|
| 552 |
+
`user_tables.materialises()` reads the `readThrough` flag off the DEFINITION the rows-free
|
| 553 |
+
projection already carries, so the first predicate is still free. The second needs the mirror.
|
| 554 |
+
MEASURED warm, median of five, whole batch of ten sources on this worktree: **0.5 ms before,
|
| 555 |
+
15.6 ms after (+15.1 ms)**, using ONE cursor for the batch and `assistant_mirror.is_bound`
|
| 556 |
+
rather than a full spec resolve. The full resolve was tried FIRST and measured **+605 ms**,
|
| 557 |
+
because `_source_for` runs `excluded_ids`, a scan of every partner row, once per grid;
|
| 558 |
+
`is_bound`'s docstring carries that measurement and the reason it is safe to stop short of it.
|
| 559 |
|
| 560 |
β `databases=None` enumerates every source this tenant HAS (the two built-ins plus every
|
| 561 |
`ut_*` in the projection) rather than taking a caller-supplied list. A client list would make
|
|
|
|
| 567 |
|
| 568 |
definitions = None
|
| 569 |
read_definitions = False
|
| 570 |
+
mirror_cur = None
|
| 571 |
+
read_mirror = False
|
| 572 |
+
|
| 573 |
+
def _mirror():
|
| 574 |
+
"""The batch's ONE mirror cursor, opened lazily, or None. Never raises.
|
| 575 |
+
|
| 576 |
+
ββ W47-T23 - `answerable` NOW HAS A SECOND WAY TO BE TRUE, because the assistant can
|
| 577 |
+
read a mirror-served database (R11). A table that does not materialise is answerable when
|
| 578 |
+
this deployment has a read-through binding for it, so this batch has to ask the mirror.
|
| 579 |
+
β AT MOST ONE CURSOR, AND ONLY WHEN SOMETHING NEEDS IT. `databases=None` enumerates every
|
| 580 |
+
source the tenant has, and this function is called on mount by both the Assistant and
|
| 581 |
+
Query; a cursor per key, or a cursor on a tenant with no read-through tables at all, would
|
| 582 |
+
put a mirror open on the hot path of a route that used to touch one projection. Opened on
|
| 583 |
+
first need, reused for the rest of the batch, closed by the process as before.
|
| 584 |
+
β FAIL-QUIET TO `None`, unlike the READ path. This function reports availability; if the
|
| 585 |
+
mirror cannot be opened, the honest answer is "not answerable yet, and here is why",
|
| 586 |
+
which is the branch below. A raise here would take down the whole picker over one source.
|
| 587 |
+
"""
|
| 588 |
+
nonlocal mirror_cur, read_mirror
|
| 589 |
+
if not read_mirror:
|
| 590 |
+
read_mirror = True
|
| 591 |
+
try:
|
| 592 |
+
import assistant_mirror
|
| 593 |
+
cur, refusal = assistant_mirror.open_cursor(session)
|
| 594 |
+
mirror_cur = None if refusal is not None else cur
|
| 595 |
+
except Exception: # noqa: BLE001
|
| 596 |
+
mirror_cur = None
|
| 597 |
+
return mirror_cur
|
| 598 |
|
| 599 |
def _definitions():
|
| 600 |
nonlocal definitions, read_definitions
|
|
|
|
| 629 |
# `GET /query` listed nine sources and `product_data` was not among them, while
|
| 630 |
# `POST /query/chat {database:"product_data"}` answered 403 `assistant_forbidden` β
|
| 631 |
# for a database the SAME account opens from the nav, holds saved views on, and can
|
| 632 |
+
# see in the Database flyout. The mirror-served grids were un-askable too and they
|
| 633 |
+
# WERE listed, with their cause in the chip; this one said nothing at all. (W47-T23
|
| 634 |
+
# has since made those grids readable, so the contrast is now with the four whose
|
| 635 |
+
# mirror table this deployment does not carry; the asymmetry this branch fixes is
|
| 636 |
+
# unchanged.)
|
| 637 |
# β THE ASYMMETRY IS THE DEFECT, NOT THE REFUSAL. R6's second sentence: a limit that
|
| 638 |
# cannot be removed must be REPORTED with its cause, never silently enforced.
|
| 639 |
# β `visible` IS WHAT KEEPS THIS FROM BEING A DISCLOSURE. A source the caller cannot
|
|
|
|
| 691 |
row["permitted"] = True
|
| 692 |
if user_tables.materialises(key, st=lent, defn=definition):
|
| 693 |
row["answerable"] = True
|
| 694 |
+
continue
|
| 695 |
+
# ββ W47-T23 / R11 - THE SECOND WAY TO BE ANSWERABLE. This used to end here with a flat
|
| 696 |
+
# "the assistant cannot read it yet", which was true of every mirror-served grid and is
|
| 697 |
+
# now true of none that this deployment binds. `_assistant_mirror_table` reads them
|
| 698 |
+
# through the same filter compiler the grid uses, so the picker must stop saying they are
|
| 699 |
+
# shut.
|
| 700 |
+
# β THE REASON STILL HAS TO NAME ITS CAUSE (R6's second sentence), and the two remaining
|
| 701 |
+
# causes are DIFFERENT causes with different fixes: a mirror that cannot be opened at all
|
| 702 |
+
# is transient and retrying works, while a grid this deployment has no read-through
|
| 703 |
+
# binding for will not fix itself by waiting. One sentence for both would make the first
|
| 704 |
+
# look permanent, which is the failure mode the ruling exists to prevent.
|
| 705 |
+
cur = _mirror()
|
| 706 |
+
if cur is None:
|
| 707 |
+
row["reason"] = ("this database is read live from its connector mirror, and that "
|
| 708 |
+
"mirror is not open on this deployment right now; try again shortly")
|
| 709 |
+
continue
|
| 710 |
+
# β `is_bound`, NOT `binding` - THE AVAILABILITY QUESTION, NOT THE READ ONE, and the
|
| 711 |
+
# difference is 300 ms PER KEY here. Resolving a full spec runs `excluded_ids`, a scan of
|
| 712 |
+
# every partner row, for three of this tenant's grids; measured, it put +605 ms on this
|
| 713 |
+
# batch, which is called on mount by both the Assistant and Query. See `is_bound`.
|
| 714 |
+
try:
|
| 715 |
+
import assistant_mirror
|
| 716 |
+
bound = assistant_mirror.is_bound(cur, key)
|
| 717 |
+
except Exception: # noqa: BLE001
|
| 718 |
+
bound = False
|
| 719 |
+
if bound:
|
| 720 |
+
row["answerable"] = True
|
| 721 |
else:
|
| 722 |
+
row["reason"] = ("this database is read live from its connector mirror, and this "
|
| 723 |
+
"deployment has no read-through binding for it yet, so it holds no "
|
| 724 |
+
"rows the assistant can read")
|
| 725 |
return out
|
| 726 |
|
| 727 |
|
api/main.py
CHANGED
|
@@ -60,6 +60,8 @@ import routes_assets # noqa: E402 (wave 18 C2-ASSET β catalog product imager
|
|
| 60 |
import routes_auth # noqa: E402
|
| 61 |
import routes_automation # noqa: E402 (wave 18 C4-AUTO β SESSION D's router, mounted by A)
|
| 62 |
import routes_changes # noqa: E402 (wave 29 item 20 / C6 β F's change token, mounted by A)
|
|
|
|
|
|
|
| 63 |
import routes_customers # noqa: E402
|
| 64 |
import routes_grid # noqa: E402
|
| 65 |
import routes_keychain # noqa: E402 (wave 18 C7 β keychain + connectors admin surfaces)
|
|
@@ -315,6 +317,15 @@ app.include_router(routes_changes.router) # item 20 / C6 β F's router, A's
|
|
| 315 |
# 60/61 for it. Four waves of the same defect β three routers in wave 23, four features in
|
| 316 |
# wave 29 β is why the assertion exists and why the line is not left for later.
|
| 317 |
app.include_router(routes_web_agent.router) # R10 / C5 β E's router, A's line
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 318 |
# ββ WAVE 32 (R1 / C5, cross-fence wiring 6) β THE QUERY MODULE. E's router, A's line, and the
|
| 319 |
# FIFTH consecutive wave in which this exact line is the artifact the protocol nearly loses.
|
| 320 |
# β MOUNTED HERE, IN THIS BLOCK, AND NOT AT THE END OF THE FILE β measured by SESSION E in its own
|
|
|
|
| 60 |
import routes_auth # noqa: E402
|
| 61 |
import routes_automation # noqa: E402 (wave 18 C4-AUTO β SESSION D's router, mounted by A)
|
| 62 |
import routes_changes # noqa: E402 (wave 29 item 20 / C6 β F's change token, mounted by A)
|
| 63 |
+
import routes_notes # noqa: E402 (wave 47 instr 19 / W47-T16 β shared-note read state, lane C's router)
|
| 64 |
+
import routes_charts # noqa: E402 (wave 47 instr 18 / W47-T30 / R7 β saved charts as records, lane H's router)
|
| 65 |
import routes_customers # noqa: E402
|
| 66 |
import routes_grid # noqa: E402
|
| 67 |
import routes_keychain # noqa: E402 (wave 18 C7 β keychain + connectors admin surfaces)
|
|
|
|
| 317 |
# 60/61 for it. Four waves of the same defect β three routers in wave 23, four features in
|
| 318 |
# wave 29 β is why the assertion exists and why the line is not left for later.
|
| 319 |
app.include_router(routes_web_agent.router) # R10 / C5 β E's router, A's line
|
| 320 |
+
# ββ WAVE 47 β BOTH NEW ROUTERS MOUNTED IN THE PLANNING MANIFEST, BEFORE EITHER HAS A ROUTE.
|
| 321 |
+
# The five waves of comments above all describe the same loss, and wave 47 makes its CAUSE explicit:
|
| 322 |
+
# `main.py` can sit in exactly ONE lane's fence, so a router built in any other lane has nowhere to
|
| 323 |
+
# be mounted from, and the line gets deferred to a session that no longer exists. Mounting empty
|
| 324 |
+
# routers at plan time removes the failure mode instead of warning about it a sixth time.
|
| 325 |
+
# `routes_notes` is lane C's (W47-T16, the Notes unread badge); `routes_charts` is lane H's
|
| 326 |
+
# (W47-T30 / R7, saved charts as their own records). Neither lane may edit this file.
|
| 327 |
+
app.include_router(routes_notes.router)
|
| 328 |
+
app.include_router(routes_charts.router)
|
| 329 |
# ββ WAVE 32 (R1 / C5, cross-fence wiring 6) β THE QUERY MODULE. E's router, A's line, and the
|
| 330 |
# FIFTH consecutive wave in which this exact line is the artifact the protocol nearly loses.
|
| 331 |
# β MOUNTED HERE, IN THIS BLOCK, AND NOT AT THE END OF THE FILE β measured by SESSION E in its own
|
api/routes_automation.py
CHANGED
|
@@ -2420,6 +2420,26 @@ def run_rows(auto_id: str, session: Session = Depends(_GATE)):
|
|
| 2420 |
Every count in this product drills to the exact rows behind it ([[no-unverifiable-aggregates]]);
|
| 2421 |
a run history that said "412 updated" and could not show which would be the thing that rule
|
| 2422 |
exists to forbid.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2423 |
"""
|
| 2424 |
defn = engine.all_definitions(session.runtime).get(str(auto_id))
|
| 2425 |
if defn is None:
|
|
@@ -2428,11 +2448,21 @@ def run_rows(auto_id: str, session: Session = Depends(_GATE)):
|
|
| 2428 |
table_key = (defn.get("config") or {}).get("targetTable") or ""
|
| 2429 |
t = engine.ut_get(session.runtime, table_key) or {}
|
| 2430 |
rows = t.get("rows") or {}
|
|
|
|
| 2431 |
ids = [str(i) for i in (last.get("affected") or [])]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2432 |
return {"table": table_key, "label": t.get("label") or table_key,
|
| 2433 |
"fields": [{"key": f.get("key"), "label": f.get("label")}
|
| 2434 |
-
for f in (
|
| 2435 |
-
"rows":
|
| 2436 |
"truncated": len(ids) >= 200}
|
| 2437 |
|
| 2438 |
|
|
|
|
| 2420 |
Every count in this product drills to the exact rows behind it ([[no-unverifiable-aggregates]]);
|
| 2421 |
a run history that said "412 updated" and could not show which would be the thing that rule
|
| 2422 |
exists to forbid.
|
| 2423 |
+
|
| 2424 |
+
ββ W47-T21 / R3 + C4 β THIS IS THE AGENT'S ONE ROW-BEARING READ DOOR, so it is where the
|
| 2425 |
+
stored grant's `filter` and `hiddenFields` are enforced on the WIRE. `auto_id` IS the agent
|
| 2426 |
+
id (`ensure_agent_contract` is minted against `defn["id"]`), so the wall this route needs is
|
| 2427 |
+
the wall the Access tab edits, resolved with no extra plumbing.
|
| 2428 |
+
|
| 2429 |
+
ββ BOTH WIRES, AND THAT IS THE HALF THAT IS EASY TO MISS. `perm_scope.strip_row`'s own
|
| 2430 |
+
docstring: *"the field list and the row payload are two different wires, and stripping only
|
| 2431 |
+
the first would leave the value sitting in the second where anyone can read it."* Here the
|
| 2432 |
+
field list is `fields` and the payload is `rows`, in one response body, so a hide applied to
|
| 2433 |
+
either alone is not a hide at all. Both are narrowed below by the same set.
|
| 2434 |
+
|
| 2435 |
+
β THE FILTER RUNS BEFORE THE HIDE, and never the other way round: a rule may legitimately
|
| 2436 |
+
name a column the same grant hides (an agent that may see only Manhattan records and may not
|
| 2437 |
+
read the Zone column is a coherent, ordinary grant), and judging a stripped row would make
|
| 2438 |
+
that rule unanswerable, which `filter_eval.permits` correctly turns into a DENY. The wall
|
| 2439 |
+
would then hide every record instead of the Brooklyn ones.
|
| 2440 |
+
|
| 2441 |
+
β `truncated` STILL COUNTS THE IDS THE RUN TOUCHED, not the rows this reader received. The
|
| 2442 |
+
two are different numbers on a walled agent and the flag is about the 200-id ceiling.
|
| 2443 |
"""
|
| 2444 |
defn = engine.all_definitions(session.runtime).get(str(auto_id))
|
| 2445 |
if defn is None:
|
|
|
|
| 2448 |
table_key = (defn.get("config") or {}).get("targetTable") or ""
|
| 2449 |
t = engine.ut_get(session.runtime, table_key) or {}
|
| 2450 |
rows = t.get("rows") or {}
|
| 2451 |
+
fields = t.get("fields") or []
|
| 2452 |
ids = [str(i) for i in (last.get("affected") or [])]
|
| 2453 |
+
tree, hidden = engine.agent_row_wall(session.runtime, str(auto_id), "", table_key)
|
| 2454 |
+
out = []
|
| 2455 |
+
for i in ids:
|
| 2456 |
+
if i not in rows:
|
| 2457 |
+
continue
|
| 2458 |
+
row = rows.get(i) or {}
|
| 2459 |
+
if tree and not engine.agent_row_permitted(tree, row, fields):
|
| 2460 |
+
continue
|
| 2461 |
+
out.append({"id": i, **engine.agent_visible_row(row, hidden)})
|
| 2462 |
return {"table": table_key, "label": t.get("label") or table_key,
|
| 2463 |
"fields": [{"key": f.get("key"), "label": f.get("label")}
|
| 2464 |
+
for f in fields if str(f.get("key") or "") not in hidden],
|
| 2465 |
+
"rows": out,
|
| 2466 |
"truncated": len(ids) >= 200}
|
| 2467 |
|
| 2468 |
|
api/routes_charts.py
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""routes_charts.py β SAVED CHARTS as their own records (wave 47, instruction 18, ticket W47-T30).
|
| 2 |
+
|
| 3 |
+
ββ **THIS FILE IS MOUNTED BEFORE IT HAS A SINGLE ROUTE, ON PURPOSE.** See the identical note in
|
| 4 |
+
`routes_notes.py` and the mount block in `main.py`: five consecutive waves lost the
|
| 5 |
+
`include_router` line, and in a worktree-parallel wave that is structural rather than careless β
|
| 6 |
+
`main.py` can live in exactly ONE lane's fence, so a router built in any other lane has nowhere to
|
| 7 |
+
be mounted from. The planning manifest mounts both of this wave's new routers so no lane has to
|
| 8 |
+
reach across a fence and no ticket can reach BUILT while its surface is 404.
|
| 9 |
+
|
| 10 |
+
WHAT GOES HERE:
|
| 11 |
+
|
| 12 |
+
W47-T30 gives a saved chart configuration its own record β id, name, owner, database, metrics,
|
| 13 |
+
bucket and span β with create / list / rename / load / delete doors, backed by
|
| 14 |
+
`platform/core/chart_system.py`.
|
| 15 |
+
|
| 16 |
+
β **OWNER RULING R7, and it is the reason this is a record and not a view setting.** Verbatim:
|
| 17 |
+
*"every interface like chart, swap etc. that we need to configure should act like route with the
|
| 18 |
+
right side navigation to choose the specific view we want to see. So its not pegged on a per view
|
| 19 |
+
basis."* Time-series state hides today inside `ws["views"][vid]["config"]["display"]`, one per
|
| 20 |
+
view, listed nowhere β which is exactly what the ruling rejects. The shipped pattern to mirror is
|
| 21 |
+
`platform/core/route_system.py::put_route` behind `/api/v1/customers/routes`.
|
| 22 |
+
|
| 23 |
+
β Build the record type REUSABLE. The time-series panel is its FIRST CONSUMER, not its definition:
|
| 24 |
+
the ruling says every configurable interface should work this way, so a second consumer must not
|
| 25 |
+
need a second record type.
|
| 26 |
+
|
| 27 |
+
β Contract C6: a chart carries its own owner and is visible only to callers who may see its
|
| 28 |
+
database. Deleting a VIEW must not delete a chart β that negative control is part of W47-T30's
|
| 29 |
+
`done-when`, not a follow-up.
|
| 30 |
+
"""
|
| 31 |
+
|
| 32 |
+
from fastapi import APIRouter, Body, Depends, HTTPException
|
| 33 |
+
|
| 34 |
+
from deps import Session, err, require_session
|
| 35 |
+
|
| 36 |
+
router = APIRouter(prefix="/api/v1")
|
| 37 |
+
|
| 38 |
+
#: ββ THERE IS NO `module_gate(MODULE)` HERE, AND ITS ABSENCE IS THE DESIGN. A chart is not a
|
| 39 |
+
#: surface of one module; it belongs to whichever DATABASE it was saved against. So every door
|
| 40 |
+
#: takes the bare authenticated session and then calls `_require_database(session, <the chart's
|
| 41 |
+
#: database>)` β the shipped chokepoint (`core.perm_scope.nav_may_open` plus the tenant module
|
| 42 |
+
#: catalogue, both fail-closed), the very predicate the nav rail uses to decide what to offer.
|
| 43 |
+
#: That is what makes the done-when's "a chart is visible only to users who may see its database"
|
| 44 |
+
#: true, with no second permission vocabulary invented for charts.
|
| 45 |
+
#:
|
| 46 |
+
#: ββ THE DOOR IS `_require_database`, NOT `deps.Session.require`, AND SIMPLIFYING IT BACK BREAKS
|
| 47 |
+
#: EVERY `ut_*` TABLE. `Session.require` calls `nav_may_open(user, key)` with NO `st=` argument, so
|
| 48 |
+
#: the `ut_*` leg of that predicate resolves the table against the PROCESS-DEFAULT tenant store
|
| 49 |
+
#: instead of THIS session's tenant runtime. Every other caller of `Session.require` passes a
|
| 50 |
+
#: built-in module key (`customer_data`, `product_data`), which never reaches that leg β this file
|
| 51 |
+
#: was the first caller to pass a `ut_*` key, and it therefore asked the wrong tenant's store.
|
| 52 |
+
#: MEASURED on the running app, same user, same table, same request: with the server started
|
| 53 |
+
#: WITHOUT `AIOS_TENANT=qa-b`, `GET /charts?database=ut_w39_visual_qa_20260820t214846z` returned
|
| 54 |
+
#: 403 `forbidden` while that same user could list rows and add a field to that very table through
|
| 55 |
+
#: the grid; restarted WITH `AIOS_TENANT=qa-b` (process default now equal to the session tenant)
|
| 56 |
+
#: the identical request returned 200 `{"charts": []}`. The variable was the store, not the user.
|
| 57 |
+
#: The `deps.py` bug is real and is booked against the file that owns it; `st=session.runtime`
|
| 58 |
+
#: is how this file stops inheriting it.
|
| 59 |
+
#:
|
| 60 |
+
#: β `st` IS A STORE HANDLE, i.e. anything with `.get(name)`, and `session.runtime` IS one:
|
| 61 |
+
#: `harness/runtime.py` defines `get(self, name, fresh=False)`, `user_tables.may_open` uses `st`
|
| 62 |
+
#: only as `get(table_key, st)` / `shares.may_see(..., st=st)`, and the shipped precedent is
|
| 63 |
+
#: `routes_customers.py`'s `nav_may_open(principal, MODULE, st=session.runtime)`. The nav rail
|
| 64 |
+
#: itself (`routes_nav.py`, `routes_tables.py`) passes a per-request prewarm wrapper built over
|
| 65 |
+
#: that same runtime, so this asks the identical store by a shorter path.
|
| 66 |
+
#:
|
| 67 |
+
#: β AND IT CANNOT WIDEN ANYTHING. `_require_database` runs the SAME two legs as `Session.require`
|
| 68 |
+
#: β `nav_may_open` first, the tenant module catalogue second, both fail-closed β with the SAME
|
| 69 |
+
#: store the nav rail itself passes. So its verdict is exactly the rail's verdict: it can only ever
|
| 70 |
+
#: agree with what the caller already sees offered to them, never grant a database the rail would
|
| 71 |
+
#: withhold. What it fixes is a refusal on a database the caller demonstrably CAN open.
|
| 72 |
+
#:
|
| 73 |
+
#: β `database` IS A DATABASE KEY: `customer_data`, `product_data`, a `ut_*` table key β the same
|
| 74 |
+
#: string `GET /query/metrics?database=` and `_require_database()` both take. It is NOT the React
|
| 75 |
+
#: client's `SurfaceScope` ("customer", "product", "cohort"), which is a different string space
|
| 76 |
+
#: (`semantic.topic_for_grid("customer")` is None while `topic_for_grid("customer_data")` is not).
|
| 77 |
+
#: That mismatch is a real defect booked elsewhere; this record type refuses to re-encode it.
|
| 78 |
+
|
| 79 |
+
_INVALID_CHART = ("a saved chart needs a name, a database, and a configuration object under "
|
| 80 |
+
"64 KB")
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def _reject_client_create_id(raw):
|
| 84 |
+
"""POST stays create-only; ids are minted by the server.
|
| 85 |
+
|
| 86 |
+
`chart_system.put_chart` is intentionally an upsert primitive so PATCH can reuse it. Letting a
|
| 87 |
+
browser-supplied `id` through POST would turn create into an undocumented update door. Key
|
| 88 |
+
presence is the wall, and the refusal is loud so a malformed caller learns to use PATCH.
|
| 89 |
+
"""
|
| 90 |
+
if isinstance(raw, dict) and "id" in raw:
|
| 91 |
+
raise err(400, "server_managed_chart_id",
|
| 92 |
+
"Chart ids are server-managed; omit id when creating and use PATCH to update "
|
| 93 |
+
"an existing Chart")
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def _require_database(session: Session, database) -> str:
|
| 97 |
+
"""THE per-database wall, and the ONE place a raw value becomes a checked database key.
|
| 98 |
+
|
| 99 |
+
Runs the same two legs as `deps.Session.require` β `core.perm_scope.nav_may_open`, then the
|
| 100 |
+
tenant's module catalogue β but threads THIS session's own runtime into the predicate as `st`.
|
| 101 |
+
That argument is load-bearing and the file header says why at length: without it the `ut_*`
|
| 102 |
+
leg of `nav_may_open` resolves against the process-default tenant store, which produced a
|
| 103 |
+
measured 403 on `?database=ut_w39_visual_qa_20260820t214846z` for a user who could read and
|
| 104 |
+
edit that very table through the grid, and a 200 for the identical request once the process
|
| 105 |
+
default happened to equal the session tenant. Same predicate, same store as the nav rail, so
|
| 106 |
+
this can only ever agree with what the caller already sees offered β it widens nothing.
|
| 107 |
+
|
| 108 |
+
Accepts the raw payload value (or a stored record's `database`) and returns the stripped key.
|
| 109 |
+
"""
|
| 110 |
+
key = str(database or "").strip()
|
| 111 |
+
if not key:
|
| 112 |
+
raise err(400, "chart_database_required",
|
| 113 |
+
"a saved chart needs the database it belongs to")
|
| 114 |
+
import core.perm_scope as perm_scope
|
| 115 |
+
if not perm_scope.nav_may_open(session.user, key, st=session.runtime):
|
| 116 |
+
raise err(403, "forbidden", f"your account does not have access to {key}")
|
| 117 |
+
tcfg = getattr(session.runtime.tenant, "config", None) or {}
|
| 118 |
+
tmods = tcfg.get("modules", "all")
|
| 119 |
+
if tmods != "all" and key not in {str(k) for k in (tmods or [])}:
|
| 120 |
+
raise err(403, "forbidden", f"this workspace does not include {key}")
|
| 121 |
+
return key
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
def _may_open(session: Session, database, seen=None):
|
| 125 |
+
"""Would `_require_database(session, database)` pass? Memoized per request.
|
| 126 |
+
|
| 127 |
+
β It must be THAT helper and not a second copy of the rule: the list door and the single
|
| 128 |
+
record doors are then incapable of disagreeing about who may see a database.
|
| 129 |
+
|
| 130 |
+
β `HTTPException` ONLY. A bare `except Exception` here would turn a real failure into a
|
| 131 |
+
silently short list, which is the failure mode a list door can least afford.
|
| 132 |
+
"""
|
| 133 |
+
key = str(database or "").strip()
|
| 134 |
+
if not key:
|
| 135 |
+
return False
|
| 136 |
+
if seen is not None and key in seen:
|
| 137 |
+
return seen[key]
|
| 138 |
+
try:
|
| 139 |
+
_require_database(session, key)
|
| 140 |
+
verdict = True
|
| 141 |
+
except HTTPException:
|
| 142 |
+
verdict = False
|
| 143 |
+
if seen is not None:
|
| 144 |
+
seen[key] = verdict
|
| 145 |
+
return verdict
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def _chart_or_404(session: Session, chart_id):
|
| 149 |
+
"""The chart, after the per-database wall. 404 when it does not exist, 403 when it is not yours
|
| 150 |
+
to see β the store read is only how we learn WHICH database to ask about, and nothing from an
|
| 151 |
+
unpermitted record ever leaves the server.
|
| 152 |
+
|
| 153 |
+
A stored record with no `database` at all cannot be created through POST or PATCH; should one
|
| 154 |
+
exist it is malformed, and it refuses through the same wall as `chart_database_required`."""
|
| 155 |
+
from core import chart_system
|
| 156 |
+
chart = chart_system.get_chart(session.runtime, chart_id, tenant_id=session.tenant)
|
| 157 |
+
if not isinstance(chart, dict):
|
| 158 |
+
raise err(404, "chart_not_found", "that saved chart does not exist")
|
| 159 |
+
_require_database(session, chart.get("database"))
|
| 160 |
+
return chart
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
@router.get("/charts")
|
| 164 |
+
def charts(database: str = "", session: Session = Depends(require_session)):
|
| 165 |
+
"""The navigator's list. `?database=` narrows it; omitted, it is every chart this caller may
|
| 166 |
+
see, filtered one database at a time rather than 403ing the whole list."""
|
| 167 |
+
from core import chart_system
|
| 168 |
+
want = str(database or "").strip()
|
| 169 |
+
if want:
|
| 170 |
+
_require_database(session, want)
|
| 171 |
+
return {"charts": chart_system.list_charts(session.runtime, database=want,
|
| 172 |
+
tenant_id=session.tenant)}
|
| 173 |
+
seen = {}
|
| 174 |
+
return {"charts": [c for c in chart_system.list_charts(session.runtime,
|
| 175 |
+
tenant_id=session.tenant)
|
| 176 |
+
if _may_open(session, c.get("database"), seen)]}
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
@router.post("/charts", status_code=201)
|
| 180 |
+
def create_chart(body: dict = Body(default=None), session: Session = Depends(require_session)):
|
| 181 |
+
from core import chart_system
|
| 182 |
+
raw = dict(body or {})
|
| 183 |
+
_reject_client_create_id(raw)
|
| 184 |
+
_require_database(session, raw.get("database"))
|
| 185 |
+
chart = chart_system.put_chart(session.runtime, raw, tenant_id=session.tenant,
|
| 186 |
+
created_by=session.uname)
|
| 187 |
+
if chart is None:
|
| 188 |
+
raise err(400, "invalid_chart", _INVALID_CHART)
|
| 189 |
+
return {"chart": chart}
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
@router.get("/charts/{chart_id}")
|
| 193 |
+
def read_chart(chart_id: str, session: Session = Depends(require_session)):
|
| 194 |
+
return {"chart": _chart_or_404(session, chart_id)}
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
@router.patch("/charts/{chart_id}")
|
| 198 |
+
def update_chart(chart_id: str, body: dict = Body(default=None),
|
| 199 |
+
session: Session = Depends(require_session)):
|
| 200 |
+
"""Rename and/or replace the opaque config. `database` is immutable: the caller passed the wall
|
| 201 |
+
for the database this chart is ON, not for whichever one a payload might name."""
|
| 202 |
+
from core import chart_system
|
| 203 |
+
prior = _chart_or_404(session, chart_id)
|
| 204 |
+
raw = dict(body or {})
|
| 205 |
+
raw["id"] = prior["id"]
|
| 206 |
+
raw.pop("database", None)
|
| 207 |
+
chart = chart_system.put_chart(session.runtime, raw, tenant_id=session.tenant,
|
| 208 |
+
created_by=session.uname)
|
| 209 |
+
if chart is None:
|
| 210 |
+
raise err(400, "invalid_chart", _INVALID_CHART)
|
| 211 |
+
return {"chart": chart}
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
@router.delete("/charts/{chart_id}")
|
| 215 |
+
def remove_chart(chart_id: str, session: Session = Depends(require_session)):
|
| 216 |
+
from core import chart_system
|
| 217 |
+
chart = _chart_or_404(session, chart_id)
|
| 218 |
+
if not chart_system.delete_chart(session.runtime, chart["id"]):
|
| 219 |
+
raise err(404, "chart_not_found", "that saved chart does not exist")
|
| 220 |
+
return {"deleted": chart["id"]}
|
api/routes_customers.py
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
api/routes_grid.py
CHANGED
|
@@ -1145,6 +1145,315 @@ def recurrence_preview(body: dict = Body(default=None),
|
|
| 1145 |
}
|
| 1146 |
|
| 1147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1148 |
@router.post("/grid/events")
|
| 1149 |
def grid_events_route(body: dict = Body(default=None),
|
| 1150 |
session: Session = Depends(require_session)):
|
|
@@ -1309,6 +1618,16 @@ def grid_events_route(body: dict = Body(default=None),
|
|
| 1309 |
out["derived"] = {str(pid): cells for pid, cells in fresh["derived"].items()}
|
| 1310 |
except Exception:
|
| 1311 |
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1312 |
# β NOTHING IS INVALIDATED HERE, on purpose. The runtime cache holds ONLY the scope-shaped
|
| 1313 |
# Odoo pool (see `routes_customers._pool_rows`), and no event on this route can change an
|
| 1314 |
# Odoo column β Odoo is read-only. Everything an event DOES change (overlays, fields, views,
|
|
|
|
| 1145 |
}
|
| 1146 |
|
| 1147 |
|
| 1148 |
+
# ββ ββ W47-T26 (owner instruction 13 / ruling R2, contract C5): THE NEXT DATE IS A REAL CELL β
|
| 1149 |
+
#
|
| 1150 |
+
# R2, verbatim: the computed next date is STORED in the cell, "so it filters, sorts and groups
|
| 1151 |
+
# like an ordinary date", written on rule save and whenever the anchor field changes. Before
|
| 1152 |
+
# this, `project_date_recurrences` re-derived `nextDate` on every response and wrote NOTHING β
|
| 1153 |
+
# which is exactly why `filter-kit/ops.ts` has zero references to it and the value could not be
|
| 1154 |
+
# filtered, sorted or grouped at all.
|
| 1155 |
+
#
|
| 1156 |
+
# β C5 IS THE TEST AND IT WAS NOT EDITED TO PASS IT. Nothing under `web/src/filter-kit/` and
|
| 1157 |
+
# nothing in `harness/filter_eval.py` knows this column exists: what lands in the row is an ISO
|
| 1158 |
+
# day STRING in an ordinary `date` cell, indistinguishable from one a person typed. A special
|
| 1159 |
+
# case anywhere on the filter, sort or group path would have meant the storage shape was wrong.
|
| 1160 |
+
#
|
| 1161 |
+
# β SCOPE, STATED RATHER THAN HIDDEN (standing rule 1). This materialises for `ut_*` USER
|
| 1162 |
+
# TABLES ONLY. The registry topics (`customer_data`, `product_data`) keep their cells in a
|
| 1163 |
+
# per-user/tenant overlay written by `core/table_store.py::TableStore.patch_overlay`, which takes
|
| 1164 |
+
# ONE pid per call and is a whole-document read-modify-write each time; there is no bulk
|
| 1165 |
+
# equivalent anywhere in the tree. Writing ~3,600 customer rows through it is a performance
|
| 1166 |
+
# defect, so the limit is REPORTED with its fix rather than silently enforced: a
|
| 1167 |
+
# `patch_many_overlay` on TableStore, mirroring `user_tables.patch_many_cells`.
|
| 1168 |
+
|
| 1169 |
+
|
| 1170 |
+
def _recurrence_columns(fields):
|
| 1171 |
+
"""`(field_key, recurrence, anchor_key)` for every SAME-DATABASE recurrence date column.
|
| 1172 |
+
|
| 1173 |
+
β A LINKED anchor (`anchorField.table != "same"`) is DROPPED here rather than guessed at:
|
| 1174 |
+
the anchor day lives in another database behind a per-row Link cell, and resolving that from
|
| 1175 |
+
this seam is a join this pass does not do. Reported as unbuilt, not silently narrowed.
|
| 1176 |
+
|
| 1177 |
+
ββ SELF-ANCHORING IS THE ORDINARY CASE AND IT IS ALLOWED. W47-T24 makes `anchorField.field`
|
| 1178 |
+
DEFAULT to the field's own key, so a person who opens a Date column and says "repeat weekly"
|
| 1179 |
+
lands here with `key == anchor_key` β and that is instruction 13's headline ask, the one next
|
| 1180 |
+
date appearing in the cell the moment the rule is saved. Refusing it would build the feature
|
| 1181 |
+
and then decline to run it on almost every column that has it.
|
| 1182 |
+
|
| 1183 |
+
β WITH EXACTLY ONE EXCLUSION, AND IT IS NOT THE OBVIOUS ONE. A self-anchored column computes
|
| 1184 |
+
from its OWN previous output, so the question is whether that iteration CONVERGES, and for
|
| 1185 |
+
every PERIODIC kind it does, after a single pass: `_recurrence_matches` matches at
|
| 1186 |
+
`day == start` (`(day - start).days % interval == 0`), so a stale value rolls forward once and
|
| 1187 |
+
then stops moving β which IS ruling R2's "a stored date now in the past rolls forward to the
|
| 1188 |
+
next occurrence". MEASURED on this module, repeated passes at today = 2026-08-30:
|
| 1189 |
+
|
| 1190 |
+
weekly, stale 2026-08-01 -> 2026-09-01 -> 2026-09-01 -> 2026-09-01 (fixed point)
|
| 1191 |
+
weekly, future 2026-09-08 -> 2026-09-08 -> 2026-09-08 (fixed point)
|
| 1192 |
+
monthly, stale 2026-06-15 -> 2026-09-15 -> 2026-09-15 (fixed point)
|
| 1193 |
+
yearly, stale 2024-03-01 -> 2027-03-01 -> 2027-03-01 (fixed point)
|
| 1194 |
+
holiday, stale 2025-12-25 -> 2026-12-25 -> 2026-12-25 (fixed point)
|
| 1195 |
+
anchored +7d 2026-09-01 -> 2026-09-08 -> 2026-09-15 -> 2026-09-22 β RUNS AWAY
|
| 1196 |
+
|
| 1197 |
+
An `anchored` rule is an OFFSET FROM THE ANCHOR (`_anchored_occurrence` shifts by N and does
|
| 1198 |
+
not consult a period), so pointed at itself it walks forward by N on every pass forever β no
|
| 1199 |
+
fixed point, and T27's nightly job would march the column into the future one night at a time.
|
| 1200 |
+
THAT is the case this drops, and only that one. β Do not "simplify" this back to a flat
|
| 1201 |
+
`key != anchor_key`: the table above is why the inequality is wrong.
|
| 1202 |
+
"""
|
| 1203 |
+
out = []
|
| 1204 |
+
for field in fields or ():
|
| 1205 |
+
if not isinstance(field, dict) or field.get("type") != "date":
|
| 1206 |
+
continue
|
| 1207 |
+
recurrence = field.get("recurrence")
|
| 1208 |
+
if not isinstance(recurrence, dict):
|
| 1209 |
+
continue
|
| 1210 |
+
anchor = recurrence.get("anchorField")
|
| 1211 |
+
if not isinstance(anchor, dict) or str(anchor.get("table") or "same") != "same":
|
| 1212 |
+
continue
|
| 1213 |
+
key, anchor_key = str(field.get("key") or ""), str(anchor.get("field") or "")
|
| 1214 |
+
if not key or not anchor_key:
|
| 1215 |
+
continue
|
| 1216 |
+
if key == anchor_key and any(
|
| 1217 |
+
isinstance(rule, dict) and rule.get("kind") == "anchored"
|
| 1218 |
+
for rule in (recurrence.get("rules") or ())):
|
| 1219 |
+
continue # the one divergent shape: an offset measured from itself
|
| 1220 |
+
out.append((key, recurrence, anchor_key))
|
| 1221 |
+
return out
|
| 1222 |
+
|
| 1223 |
+
|
| 1224 |
+
def _materialise_recurrence_cells(session, scope, events, results, fields):
|
| 1225 |
+
"""R2's writer: each row's computed next date, into the cell, in ONE store update.
|
| 1226 |
+
|
| 1227 |
+
Returns the number of ROWS written. Zero when nothing changed β recompute, compare, write
|
| 1228 |
+
only the differences β which is the idempotence T27's nightly pass is built on top of.
|
| 1229 |
+
|
| 1230 |
+
β NOT WRAPPED IN A BLANKET `except: pass`, and that is the opposite of the measure-values
|
| 1231 |
+
shortcut fifty lines below. That block's own note says "nothing depends on this having
|
| 1232 |
+
worked"; here a swallowed failure means the cell keeps a STALE date that every filter, sort
|
| 1233 |
+
and group then treats as truth. A bug must be loud. The defensiveness is therefore in the
|
| 1234 |
+
type checks, not in a hidden handler.
|
| 1235 |
+
"""
|
| 1236 |
+
if not scope.startswith("ut_"):
|
| 1237 |
+
return 0
|
| 1238 |
+
import aios_grid
|
| 1239 |
+
from core import user_tables
|
| 1240 |
+
|
| 1241 |
+
# ββ THE PRE-SCREEN, off the field contract the route is ALREADY holding. The overwhelming
|
| 1242 |
+
# majority of events touch no recurrence column, and they must not pay for a store read to
|
| 1243 |
+
# discover it: `user_tables.get` is a whole-document deep copy under the store lock.
|
| 1244 |
+
existing = _recurrence_columns(fields)
|
| 1245 |
+
anchors = {anchor_key for _, _, anchor_key in existing}
|
| 1246 |
+
saved, touched = [], {}
|
| 1247 |
+
for event, result in zip(events, results):
|
| 1248 |
+
if not isinstance(event, dict) or (result or {}).get("refused"):
|
| 1249 |
+
continue
|
| 1250 |
+
kind = event.get("type")
|
| 1251 |
+
if kind == "field_upsert":
|
| 1252 |
+
# TRIGGER 1 β the rule was just saved: recompute the WHOLE column.
|
| 1253 |
+
field = event.get("field")
|
| 1254 |
+
if not isinstance(field, dict) or field.get("type") != "date" \
|
| 1255 |
+
or not isinstance(field.get("recurrence"), dict) or not field.get("key"):
|
| 1256 |
+
continue
|
| 1257 |
+
# The SAME authority the write itself passed through, CALLED rather than restated:
|
| 1258 |
+
# the config `grid_events` persisted IS this function's return value, so the cell is
|
| 1259 |
+
# computed from the config that was stored and not from the browser's copy of it.
|
| 1260 |
+
try:
|
| 1261 |
+
clean = govern_date_recurrence(session, scope, fields,
|
| 1262 |
+
field.get("recurrence"))
|
| 1263 |
+
except ValueError:
|
| 1264 |
+
continue
|
| 1265 |
+
saved.extend(_recurrence_columns([{**field, "recurrence": clean}]))
|
| 1266 |
+
elif kind == "overlay_patch":
|
| 1267 |
+
# TRIGGER 2 β an anchor cell moved: recompute the AFFECTED ROWS only. This is the
|
| 1268 |
+
# done-when's "changing the anchor field rewrites it".
|
| 1269 |
+
updates = event.get("updates")
|
| 1270 |
+
if event.get("pid") is None or not isinstance(updates, dict) \
|
| 1271 |
+
or not set(updates) & anchors:
|
| 1272 |
+
continue
|
| 1273 |
+
for key, recurrence, anchor_key in existing:
|
| 1274 |
+
if anchor_key in updates:
|
| 1275 |
+
touched.setdefault(key, (recurrence, anchor_key, set()))[2].add(
|
| 1276 |
+
str(event.get("pid")))
|
| 1277 |
+
if not saved and not touched:
|
| 1278 |
+
return 0
|
| 1279 |
+
|
| 1280 |
+
st = session.runtime
|
| 1281 |
+
if not user_tables.is_user_table(scope, st=st):
|
| 1282 |
+
return 0
|
| 1283 |
+
table = user_tables.get(scope, st=st) or {}
|
| 1284 |
+
# β A READ-THROUGH GRID HAS NO `rows` DOCUMENT AT ALL, by design β GL-scale tables are kept
|
| 1285 |
+
# out of it for memory β so this SKIPS one rather than force-materialising it, and the
|
| 1286 |
+
# record-mutability wall is asked before any write, not after.
|
| 1287 |
+
if not table or not user_tables.materialises(scope, st=st, defn=table) \
|
| 1288 |
+
or not user_tables.records_mutable(scope, st=st):
|
| 1289 |
+
return 0
|
| 1290 |
+
rows = table.get("rows") or {}
|
| 1291 |
+
if not rows:
|
| 1292 |
+
return 0
|
| 1293 |
+
|
| 1294 |
+
today = time.strftime("%Y-%m-%d")
|
| 1295 |
+
condition_fields = {str(field.get("key")) for field in (fields or ())
|
| 1296 |
+
if isinstance(field, dict) and field.get("key")}
|
| 1297 |
+
plan = {key: (recurrence, anchor_key, None) for key, recurrence, anchor_key in saved}
|
| 1298 |
+
for key, (recurrence, anchor_key, pids) in touched.items():
|
| 1299 |
+
# A column whose rule was saved in this same batch is already scheduled for every row;
|
| 1300 |
+
# the narrower per-pid pass would only redo a subset of it.
|
| 1301 |
+
plan.setdefault(key, (recurrence, anchor_key, pids))
|
| 1302 |
+
|
| 1303 |
+
updates = {}
|
| 1304 |
+
for key, (recurrence, anchor_key, pids) in plan.items():
|
| 1305 |
+
wanted = aios_grid.recurrence_column_values(
|
| 1306 |
+
recurrence, rows, anchor_key, today=today,
|
| 1307 |
+
condition_fields=condition_fields, row_ids=pids)
|
| 1308 |
+
for rid, value in wanted.items():
|
| 1309 |
+
have = (rows.get(rid) or {}).get(key)
|
| 1310 |
+
if value == ("" if have is None else str(have)):
|
| 1311 |
+
continue # β ONLY THE DIFFERENCES: a second identical pass writes nothing
|
| 1312 |
+
updates.setdefault(rid, {})[key] = value
|
| 1313 |
+
if not updates:
|
| 1314 |
+
return 0
|
| 1315 |
+
return user_tables.patch_many_cells(scope, updates, st=st)
|
| 1316 |
+
|
| 1317 |
+
|
| 1318 |
+
# ββ ββ W47-T27 (owner instruction 13 / ruling R2): THE STORED DATE ROLLS FORWARD ON ITS OWN ββ
|
| 1319 |
+
#
|
| 1320 |
+
# R2 in the owner's words: *"nextDate has to change everyday or not depending if the current
|
| 1321 |
+
# hardcoded nextDate that is populated is already stale"*. So the nightly job is a STALE CHECK,
|
| 1322 |
+
# and the check is the DIFF β not a date comparison written here.
|
| 1323 |
+
#
|
| 1324 |
+
# β THE ROLL-FORWARD IS ALREADY THE ARITHMETIC, measured by T26 on this module:
|
| 1325 |
+
# `_recurrence_matches` matches at `day == start`, so recomputing a periodic rule from a STALE
|
| 1326 |
+
# stored value yields the next occurrence, and recomputing from a FUTURE stored value yields that
|
| 1327 |
+
# same value back. A future cell therefore produces NO DIFFERENCE and is never written. An
|
| 1328 |
+
# `if stored < today` branch on top of that would be a second definition of "stale" to keep in
|
| 1329 |
+
# step with the first, and the two would disagree on the first edge case.
|
| 1330 |
+
#
|
| 1331 |
+
# β NO SHARED-SECRET GLOBAL TICK. `routes_automation.py::tick` β the old fire-every-schedule-
|
| 1332 |
+
# for-every-tenant door β is RETIRED and raises 410 ("enabled automations own exact AWS schedules
|
| 1333 |
+
# and direct events dispatch scale-to-zero workers"). Resurrecting that pattern here would
|
| 1334 |
+
# reinstate a retired architecture, so the HTTP door below is an ordinary session-authenticated
|
| 1335 |
+
# admin route over the CALLING TENANT, and a scheduler must call it once per tenant.
|
| 1336 |
+
|
| 1337 |
+
|
| 1338 |
+
def refresh_recurrence_columns(st, scope, today=None, defn=None):
|
| 1339 |
+
"""R2's roll-forward for ONE database: `{field_key: rows_written}`; `{}` when nothing moved.
|
| 1340 |
+
|
| 1341 |
+
Callable WITHOUT an HTTP request β `st` is a store handle (`session.runtime`) and `scope` a
|
| 1342 |
+
`ut_*` key β so a scheduler, a probe or a shell can drive it. `defn` LENDS the definition a
|
| 1343 |
+
caller is already holding: `user_tables.get` is a whole-document deep copy under the store
|
| 1344 |
+
lock, so the tenant walk below must not pay for one per table.
|
| 1345 |
+
β A lent definition must come from `all_tables`, never `all_defs` β the projection DROPS
|
| 1346 |
+
`rows` and raises on the read rather than answering an empty grid.
|
| 1347 |
+
|
| 1348 |
+
β IDEMPOTENT BY INHERITANCE rather than by a second mechanism: this is
|
| 1349 |
+
`_materialise_recurrence_cells`' recompute-diff-write shape with the event trigger removed and
|
| 1350 |
+
the whole column in scope. A second pass on the same day writes nothing because every stored
|
| 1351 |
+
cell already IS the value the recompute produces.
|
| 1352 |
+
|
| 1353 |
+
β THE COLUMN SELECTION IS `_recurrence_columns` AND IS NOT RELAXED HERE. Its one exclusion β
|
| 1354 |
+
a SELF-ANCHORED column carrying an `anchored` rule β is precisely the runaway this job would
|
| 1355 |
+
otherwise march into the future one night at a time (`2026-09-01 -> 09-08 -> 09-15 -> ...`),
|
| 1356 |
+
because an anchored occurrence is an offset from the anchor and has no fixed point when the
|
| 1357 |
+
anchor is its own previous output.
|
| 1358 |
+
"""
|
| 1359 |
+
import aios_grid
|
| 1360 |
+
from core import user_tables
|
| 1361 |
+
|
| 1362 |
+
scope = str(scope or "")
|
| 1363 |
+
if not scope.startswith(user_tables.KEY_PREFIX):
|
| 1364 |
+
return {}
|
| 1365 |
+
table = defn if isinstance(defn, dict) else user_tables.get(scope, st=st)
|
| 1366 |
+
if not isinstance(table, dict) or not table:
|
| 1367 |
+
return {}
|
| 1368 |
+
# ββ CHEAPEST QUESTIONS FIRST. Both of these are answered off the definition already in hand;
|
| 1369 |
+
# only a table that genuinely has work to do pays for the `records_mutable` store read.
|
| 1370 |
+
columns = _recurrence_columns(table.get("fields") or [])
|
| 1371 |
+
if not columns:
|
| 1372 |
+
return {}
|
| 1373 |
+
if not user_tables.materialises(scope, st=st, defn=table):
|
| 1374 |
+
return {} # β a read-through grid has no `rows` document at all, by design
|
| 1375 |
+
rows = table.get("rows") or {}
|
| 1376 |
+
if not rows or not user_tables.records_mutable(scope, st=st):
|
| 1377 |
+
return {}
|
| 1378 |
+
|
| 1379 |
+
today = str(today or time.strftime("%Y-%m-%d"))
|
| 1380 |
+
# β THE STORED FIELD SET, not the permission-projected contract `_materialise_recurrence_cells`
|
| 1381 |
+
# holds β and the two CANNOT disagree on a date. `condition_fields` is only ever
|
| 1382 |
+
# `clean_filter_tree`'s `valid_keys` for the recurrence's `conditions`
|
| 1383 |
+
# (`aios_grid.clean_date_recurrence`), and neither `recurrence_preview` nor
|
| 1384 |
+
# `recurrence_payload` reads `conditions` when it computes `nextDate`. It decides which saved
|
| 1385 |
+
# conditions SURVIVE cleaning, never which day is next. This pass has no viewer, so
|
| 1386 |
+
# projecting against one account's contract would be inventing one.
|
| 1387 |
+
condition_fields = {str(field.get("key")) for field in (table.get("fields") or ())
|
| 1388 |
+
if isinstance(field, dict) and field.get("key")}
|
| 1389 |
+
|
| 1390 |
+
updates, counts = {}, {}
|
| 1391 |
+
for key, recurrence, anchor_key in columns:
|
| 1392 |
+
wanted = aios_grid.recurrence_column_values(
|
| 1393 |
+
recurrence, rows, anchor_key, today=today, condition_fields=condition_fields)
|
| 1394 |
+
for rid, value in wanted.items():
|
| 1395 |
+
have = (rows.get(rid) or {}).get(key)
|
| 1396 |
+
if value == ("" if have is None else str(have)):
|
| 1397 |
+
continue # β ONLY THE DIFFERENCES: a future date, and an empty anchor's
|
| 1398 |
+
updates.setdefault(rid, {})[key] = value # empty answer, both land here
|
| 1399 |
+
counts[key] = counts.get(key, 0) + 1
|
| 1400 |
+
if not updates:
|
| 1401 |
+
return {}
|
| 1402 |
+
written = user_tables.patch_many_cells(scope, updates, st=st)
|
| 1403 |
+
if not written:
|
| 1404 |
+
return {}
|
| 1405 |
+
if written != len(updates):
|
| 1406 |
+
# `patch_many_cells` SKIPS a row id that no longer exists rather than creating it, so a
|
| 1407 |
+
# record deleted between the read and the write is a smaller number here. Reported
|
| 1408 |
+
# rather than reconciled: the counts are the plan, and the plan is now known to be stale.
|
| 1409 |
+
print(f"[recurrence-refresh] {scope}: planned {len(updates)} rows, wrote {written}")
|
| 1410 |
+
return counts
|
| 1411 |
+
|
| 1412 |
+
|
| 1413 |
+
def refresh_recurrence_tenant(st, today=None):
|
| 1414 |
+
"""Every user database in ONE tenant: `{table_key: {field_key: rows_written}}`.
|
| 1415 |
+
|
| 1416 |
+
ONE `all_tables` read for the whole walk, with each definition LENT onward β see
|
| 1417 |
+
`refresh_recurrence_columns`. Tables with nothing to write are absent from the answer rather
|
| 1418 |
+
than present with zeros, so the caller can report what it actually did.
|
| 1419 |
+
"""
|
| 1420 |
+
from core import user_tables
|
| 1421 |
+
|
| 1422 |
+
today = str(today or time.strftime("%Y-%m-%d"))
|
| 1423 |
+
out = {}
|
| 1424 |
+
for scope, defn in (user_tables.all_tables(st=st) or {}).items():
|
| 1425 |
+
counts = refresh_recurrence_columns(st, scope, today=today, defn=defn)
|
| 1426 |
+
if counts:
|
| 1427 |
+
out[str(scope)] = counts
|
| 1428 |
+
return out
|
| 1429 |
+
|
| 1430 |
+
|
| 1431 |
+
@router.post("/grid/recurrence-refresh")
|
| 1432 |
+
def recurrence_refresh(session: Session = Depends(require_session)):
|
| 1433 |
+
"""R2's nightly roll-forward, for THE CALLING TENANT ONLY. Admin-only, session-authenticated.
|
| 1434 |
+
|
| 1435 |
+
β PER TENANT, BY CONSTRUCTION β and a scheduler must therefore call this route ONCE PER
|
| 1436 |
+
TENANT, with that tenant's own admin session. There is deliberately no cross-tenant door:
|
| 1437 |
+
the shared-secret every-tenant tick that used to be one (`routes_automation.py::tick`) is
|
| 1438 |
+
retired and answers 410, and rebuilding it here would reinstate a retired architecture.
|
| 1439 |
+
|
| 1440 |
+
Admin-only because one call writes cells in every database in the workspace at once,
|
| 1441 |
+
including ones the calling account may not open; a grid gesture it is not.
|
| 1442 |
+
|
| 1443 |
+
Idempotent: calling it twice on the same day writes nothing the second time.
|
| 1444 |
+
"""
|
| 1445 |
+
if not session.admin:
|
| 1446 |
+
raise err(403, "admin_only", "refreshing stored next dates is an admin action")
|
| 1447 |
+
if not session.runtime.available():
|
| 1448 |
+
raise err(503, "store_unavailable",
|
| 1449 |
+
"the tenant store is unavailable. Nothing was refreshed")
|
| 1450 |
+
today = time.strftime("%Y-%m-%d")
|
| 1451 |
+
tables = refresh_recurrence_tenant(session.runtime, today=today)
|
| 1452 |
+
return {"today": today, "tables": tables,
|
| 1453 |
+
"cells": sum(sum(counts.values()) for counts in tables.values()),
|
| 1454 |
+
"columns": sum(len(counts) for counts in tables.values())}
|
| 1455 |
+
|
| 1456 |
+
|
| 1457 |
@router.post("/grid/events")
|
| 1458 |
def grid_events_route(body: dict = Body(default=None),
|
| 1459 |
session: Session = Depends(require_session)):
|
|
|
|
| 1618 |
out["derived"] = {str(pid): cells for pid, cells in fresh["derived"].items()}
|
| 1619 |
except Exception:
|
| 1620 |
pass
|
| 1621 |
+
# ββ ββ W47-T26 / R2 β THE NEXT DATE BECOMES A REAL CELL, on the one door the date picker
|
| 1622 |
+
# actually uses (`CustomerGrid.saveField` -> `field_upsert` -> here). Placed after the batch
|
| 1623 |
+
# so it reads the config that WAS stored, not the one that was merely proposed.
|
| 1624 |
+
_recurrence_rows = _materialise_recurrence_cells(session, scope, events, results, g["fields"])
|
| 1625 |
+
if _recurrence_rows:
|
| 1626 |
+
# β AND THE CLIENT MUST BE TOLD. An accepted `overlay_patch` legitimately answers
|
| 1627 |
+
# `rerender: false` on the no-blip path, so without this line a changed anchor rewrote
|
| 1628 |
+
# the stored date and the grid went on painting the old one β R2's "changing the anchor
|
| 1629 |
+
# field rewrites it" made true in the store and unobservable on the screen.
|
| 1630 |
+
out["rerender"] = True
|
| 1631 |
# β NOTHING IS INVALIDATED HERE, on purpose. The runtime cache holds ONLY the scope-shaped
|
| 1632 |
# Odoo pool (see `routes_customers._pool_rows`), and no event on this route can change an
|
| 1633 |
# Odoo column β Odoo is read-only. Everything an event DOES change (overlays, fields, views,
|
api/routes_notes.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""routes_notes.py β shared-note READ STATE (wave 47, instruction 19, ticket W47-T16).
|
| 2 |
+
|
| 3 |
+
ββ **THIS FILE WAS MOUNTED BEFORE IT HAD A SINGLE ROUTE, ON PURPOSE, AND THAT IS THE WHOLE POINT
|
| 4 |
+
OF IT EXISTING AT PLAN TIME.** `main.py`'s own mount block records the scar: three routers in wave
|
| 5 |
+
23, four features in wave 29, and the `include_router` line lost again in waves 31 and 32 β five
|
| 6 |
+
consecutive waves in which a complete, gated, type-clean router shipped 404 for every caller. In a
|
| 7 |
+
worktree-parallel wave the cause is structural rather than careless: `main.py` can live in exactly
|
| 8 |
+
ONE lane's fence, so a new router built in any OTHER lane has nowhere to be mounted from. Mounting
|
| 9 |
+
an empty router in the planning manifest removes the failure mode instead of warning about it.
|
| 10 |
+
|
| 11 |
+
WHAT LIVES HERE, and what deliberately does not:
|
| 12 |
+
|
| 13 |
+
W47-T16 adds the per-user READ STATE behind the Notes button's unread badge β a read version per
|
| 14 |
+
(subject, user), plus the door that stamps it when a note is opened. `platform/core/
|
| 15 |
+
user_tables.py::put_shared_note` already stores `revisions[]` and bumps `version` on every save,
|
| 16 |
+
so a note has a version to compare against; it stored no read state at all, which is why the
|
| 17 |
+
badge needed a new marker rather than a new read of an old one.
|
| 18 |
+
|
| 19 |
+
β The EXISTING shared-note doors stay where they are. `routes_grid.py::get_shared_note` and
|
| 20 |
+
`::update_shared_note` belong to lane G this wave (that file also carries the date-recurrence
|
| 21 |
+
persist path), and W47-T16 must not reach into them. This module is ADDITIVE for exactly that
|
| 22 |
+
reason: the unread count is a separate question from the note's body, and asking it separately is
|
| 23 |
+
also cheaper to poll.
|
| 24 |
+
|
| 25 |
+
β **THE PERMISSION WALL IS BORROWED, NOT REBUILT.** `_shared_note_subject` resolves a scope and an
|
| 26 |
+
optional view id into a note subject *only after the ordinary workspace wall has admitted the
|
| 27 |
+
caller*, and it 404s a view the caller cannot see. Importing it is a deliberate choice over copying
|
| 28 |
+
it: a second wall around the same data is how two answers to "may this person see this note" start
|
| 29 |
+
to disagree, and the unread count must never be the looser of the two. It is a read-only dependency
|
| 30 |
+
on lane G's file β this module never writes there.
|
| 31 |
+
β If that helper is ever renamed, THIS import is the thing that breaks, loudly, at boot. That is the
|
| 32 |
+
intended failure mode: a mounted router that cannot resolve its subject should refuse to start
|
| 33 |
+
rather than quietly answer with a wall of its own.
|
| 34 |
+
|
| 35 |
+
β An empty router is a real router: `verify_api.py::section_mounts` walks `main.app.routes` and
|
| 36 |
+
reads `main.py`'s `import routes_*` lines against `git ls-files`, so this file has been tracked from
|
| 37 |
+
the manifest commit onward. Adding these routes does not change the mount line.
|
| 38 |
+
"""
|
| 39 |
+
|
| 40 |
+
from fastapi import APIRouter, Body, Depends
|
| 41 |
+
|
| 42 |
+
from deps import Session, err, require_session
|
| 43 |
+
|
| 44 |
+
router = APIRouter(prefix="/api/v1")
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def _subjects_for(session, scope, view_id):
|
| 48 |
+
"""The note subjects the Notes button covers: the DATABASE, plus the open View if there is one.
|
| 49 |
+
|
| 50 |
+
β That pair is the button's whole world, and the count has to match it. The drawer offers
|
| 51 |
+
exactly two tabs, Database note and View note, so a badge that counted anything else would be
|
| 52 |
+
promising notes the button cannot reach.
|
| 53 |
+
"""
|
| 54 |
+
from routes_grid import _shared_note_subject
|
| 55 |
+
|
| 56 |
+
kind, subject_id, _view = _shared_note_subject(session, scope, "")
|
| 57 |
+
subjects = [(kind, subject_id)]
|
| 58 |
+
if view_id:
|
| 59 |
+
v_kind, v_id, _v = _shared_note_subject(session, scope, view_id)
|
| 60 |
+
subjects.append((v_kind, v_id))
|
| 61 |
+
return subjects
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
@router.get("/notes/unread")
|
| 65 |
+
def notes_unread(scope: str = "customer", viewId: str = "",
|
| 66 |
+
session: Session = Depends(require_session)):
|
| 67 |
+
"""How many of this Database's notes THIS viewer has not opened at their current version.
|
| 68 |
+
|
| 69 |
+
Answers the subjects too, each with the version that would clear it, so the client never has to
|
| 70 |
+
invent a number: it stamps back exactly what it was told it had read.
|
| 71 |
+
"""
|
| 72 |
+
from core import user_tables
|
| 73 |
+
|
| 74 |
+
unread = user_tables.unread_note_subjects(
|
| 75 |
+
_subjects_for(session, scope, viewId), session.uname, st=session.runtime)
|
| 76 |
+
return {"unread": len(unread), "subjects": unread}
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
@router.post("/notes/read")
|
| 80 |
+
def notes_mark_read(scope: str = "customer", viewId: str = "",
|
| 81 |
+
body: dict = Body(default=None),
|
| 82 |
+
session: Session = Depends(require_session)):
|
| 83 |
+
"""Stamp that this viewer has opened one subject's note at a given version.
|
| 84 |
+
|
| 85 |
+
β THE SUBJECT IS RESOLVED THROUGH THE SAME WALL AS THE NOTE ITSELF, never taken from the body.
|
| 86 |
+
A caller who could name an arbitrary `subjectId` could stamp a read mark against a database they
|
| 87 |
+
cannot open β harmless on its own, but it would make the store's per-user branch a place an
|
| 88 |
+
outsider can write, and that is the property the whole design rests on.
|
| 89 |
+
β AND IT WRITES ONLY THIS SESSION'S OWN BRANCH: `session.uname`, never a name from the body.
|
| 90 |
+
"""
|
| 91 |
+
from core import user_tables
|
| 92 |
+
|
| 93 |
+
payload = body or {}
|
| 94 |
+
kind = str(payload.get("subjectKind") or "database")
|
| 95 |
+
if kind not in {"database", "view"}:
|
| 96 |
+
raise err(400, "bad_subject_kind", "a note belongs to a Database or a View")
|
| 97 |
+
wanted_view = viewId if kind == "view" else ""
|
| 98 |
+
if kind == "view" and not wanted_view:
|
| 99 |
+
raise err(400, "view_required", "a View note needs the View it belongs to")
|
| 100 |
+
|
| 101 |
+
from routes_grid import _shared_note_subject
|
| 102 |
+
|
| 103 |
+
resolved_kind, subject_id, _view = _shared_note_subject(session, scope, wanted_view)
|
| 104 |
+
mark = user_tables.mark_note_read(
|
| 105 |
+
resolved_kind, subject_id, session.uname, payload.get("version"), st=session.runtime)
|
| 106 |
+
if mark is None:
|
| 107 |
+
raise err(400, "note_read_refused", "that note could not be marked as read")
|
| 108 |
+
return {"subjectKind": resolved_kind, "subjectId": str(subject_id),
|
| 109 |
+
"version": mark.get("version", 0)}
|
platform/aios_grid.py
CHANGED
|
@@ -682,7 +682,20 @@ def _clean_geocode(raw):
|
|
| 682 |
# configuration bag: persisting a JavaScript Date, locale label, or a client-computed next value
|
| 683 |
# would make an identical record mean different things to two hosts. The host computes the
|
| 684 |
# next occurrence and preview at projection time from this compact, durable shape.
|
| 685 |
-
_RECURRENCE_KINDS = frozenset({'daily', 'weekly', 'monthly', 'yearly', 'holiday'})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 686 |
# A calendar appears here only when the server really evaluates it. The Date picker reads this
|
| 687 |
# same registry, so a selector cannot promise a country whose recurrence becomes a no-op later.
|
| 688 |
#
|
|
@@ -1080,6 +1093,20 @@ def clean_date_recurrence(raw, condition_fields=None):
|
|
| 1080 |
if not isinstance(offset, int) or isinstance(offset, bool) or offset not in (-1, 0, 1):
|
| 1081 |
continue
|
| 1082 |
rule.update({'calendar': calendar, 'offset': offset})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1083 |
if rule not in out_rules:
|
| 1084 |
out_rules.append(rule)
|
| 1085 |
if not out_rules:
|
|
@@ -1107,6 +1134,40 @@ def clean_date_recurrence(raw, condition_fields=None):
|
|
| 1107 |
return out
|
| 1108 |
|
| 1109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1110 |
def _recurrence_matches(day, start, rule):
|
| 1111 |
kind, interval = rule['kind'], rule['interval']
|
| 1112 |
if day < start:
|
|
@@ -1160,8 +1221,22 @@ def recurrence_preview(raw, today=None, count=None, condition_fields=None):
|
|
| 1160 |
horizon = min(horizon, _iso_day(ends.get('date')) or horizon)
|
| 1161 |
found, day = set(), lower
|
| 1162 |
holiday_rules = [rule for rule in config['rules'] if rule['kind'] == 'holiday']
|
| 1163 |
-
|
| 1164 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1165 |
if any(_recurrence_matches(day, start, rule) for rule in ordinary_rules):
|
| 1166 |
found.add(day)
|
| 1167 |
for rule in holiday_rules:
|
|
@@ -1209,6 +1284,83 @@ def project_date_recurrences(fields, today=None):
|
|
| 1209 |
return out
|
| 1210 |
|
| 1211 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1212 |
def _field_extras(saved, ftype, condition_fields=None):
|
| 1213 |
"""createdBy / permissions / format / scope β the validated passthrough the created strata
|
| 1214 |
share (wave 5). `createdBy` is only ever WRITTEN host-side (the handler stamps it); here it
|
|
|
|
| 682 |
# configuration bag: persisting a JavaScript Date, locale label, or a client-computed next value
|
| 683 |
# would make an identical record mean different things to two hosts. The host computes the
|
| 684 |
# next occurrence and preview at projection time from this compact, durable shape.
|
| 685 |
+
_RECURRENCE_KINDS = frozenset({'daily', 'weekly', 'monthly', 'yearly', 'holiday', 'anchored'})
|
| 686 |
+
# β W47-T25 (owner instruction 13, ruling R1): "the date is N days ON / AFTER / BEFORE another
|
| 687 |
+
# date field". The other date field is the recurrence-level `anchorField` that
|
| 688 |
+
# `routes_grid.govern_date_recurrence` already requires and already validates as same-database or
|
| 689 |
+
# linked-through-a-Link-field, so this kind needs no anchor of its own β and because the anchor is
|
| 690 |
+
# a COLUMN, every record computes its own answer from its own anchor value. That is the
|
| 691 |
+
# per-record behaviour the instruction asks for, without a per-record rule store.
|
| 692 |
+
#
|
| 693 |
+
# β THE KIND IS `anchored`, NOT `offset`. A holiday rule already stores a key called `offset`
|
| 694 |
+
# (the -1/0/1 day-before/on/after number built from `_HOLIDAY_RELATIONS`), and a second, unrelated
|
| 695 |
+
# vocabulary under the same word inside this one function is the confusion this file keeps paying
|
| 696 |
+
# for. An anchored rule's direction word lives in `relation`.
|
| 697 |
+
_ANCHORED_UNITS = frozenset({'day', 'week', 'month'})
|
| 698 |
+
_ANCHORED_RELATIONS = frozenset({'on', 'after', 'before'})
|
| 699 |
# A calendar appears here only when the server really evaluates it. The Date picker reads this
|
| 700 |
# same registry, so a selector cannot promise a country whose recurrence becomes a no-op later.
|
| 701 |
#
|
|
|
|
| 1093 |
if not isinstance(offset, int) or isinstance(offset, bool) or offset not in (-1, 0, 1):
|
| 1094 |
continue
|
| 1095 |
rule.update({'calendar': calendar, 'offset': offset})
|
| 1096 |
+
elif kind == 'anchored':
|
| 1097 |
+
# β `relation` here is a WORD (on / after / before) and is NOT the holiday branch's
|
| 1098 |
+
# `relation`, which is a synonym for the -1/0/1 `offset` number. The two never meet:
|
| 1099 |
+
# the kinds are exclusive and each branch writes only its own keys.
|
| 1100 |
+
#
|
| 1101 |
+
# An unknown unit or relation drops the rule, exactly as an unknown calendar does
|
| 1102 |
+
# above, rather than degrading to a default the person never chose. `interval` was
|
| 1103 |
+
# already bounded to 1..366 by the shared check, so `relation: on` arrives as 1 and a
|
| 1104 |
+
# 0 would have dropped the rule before reaching here.
|
| 1105 |
+
unit = str(raw_rule.get('unit') or 'day').strip().lower()
|
| 1106 |
+
relation = str(raw_rule.get('relation') or 'after').strip().lower()
|
| 1107 |
+
if unit not in _ANCHORED_UNITS or relation not in _ANCHORED_RELATIONS:
|
| 1108 |
+
continue
|
| 1109 |
+
rule.update({'unit': unit, 'relation': relation})
|
| 1110 |
if rule not in out_rules:
|
| 1111 |
out_rules.append(rule)
|
| 1112 |
if not out_rules:
|
|
|
|
| 1134 |
return out
|
| 1135 |
|
| 1136 |
|
| 1137 |
+
def _shift_months(day, amount):
|
| 1138 |
+
"""``day`` moved ``amount`` calendar months, CLAMPED to the target month's last valid day.
|
| 1139 |
+
|
| 1140 |
+
Adding one month to 31 January has no 31 February, so the answer is 28 or 29 February rather
|
| 1141 |
+
than a rolled-over 2 or 3 March. Python's FLOOR division and modulo are what make a negative
|
| 1142 |
+
amount (a ``before`` rule) land in the right year: a total of -1 gives year - 1, month 12,
|
| 1143 |
+
where a C-style remainder would give month 0.
|
| 1144 |
+
"""
|
| 1145 |
+
total = (day.year * 12 + day.month - 1) + amount
|
| 1146 |
+
year, month = divmod(total, 12)
|
| 1147 |
+
month += 1
|
| 1148 |
+
# The last day of `month` is the day before the first of the next one, without importing
|
| 1149 |
+
# `calendar` for a single call.
|
| 1150 |
+
last = (_dt.date(year + (month // 12), month % 12 + 1, 1) - _dt.timedelta(days=1)).day
|
| 1151 |
+
return _dt.date(year, month, min(day.day, last))
|
| 1152 |
+
|
| 1153 |
+
|
| 1154 |
+
def _anchored_occurrence(start, rule):
|
| 1155 |
+
"""The ONE date an ``anchored`` rule names, computed straight from the anchor date.
|
| 1156 |
+
|
| 1157 |
+
β NEVER route this through `_recurrence_matches`. That function returns False for
|
| 1158 |
+
``day < start``, and a ``before`` date is by definition EARLIER than the anchor, so the day
|
| 1159 |
+
scan below could never find one however far it walked.
|
| 1160 |
+
"""
|
| 1161 |
+
relation = rule.get('relation', 'after')
|
| 1162 |
+
if relation == 'on':
|
| 1163 |
+
return start
|
| 1164 |
+
amount = rule['interval'] * (1 if relation == 'after' else -1)
|
| 1165 |
+
unit = rule.get('unit', 'day')
|
| 1166 |
+
if unit == 'month':
|
| 1167 |
+
return _shift_months(start, amount)
|
| 1168 |
+
return start + _dt.timedelta(days=amount * (7 if unit == 'week' else 1))
|
| 1169 |
+
|
| 1170 |
+
|
| 1171 |
def _recurrence_matches(day, start, rule):
|
| 1172 |
kind, interval = rule['kind'], rule['interval']
|
| 1173 |
if day < start:
|
|
|
|
| 1221 |
horizon = min(horizon, _iso_day(ends.get('date')) or horizon)
|
| 1222 |
found, day = set(), lower
|
| 1223 |
holiday_rules = [rule for rule in config['rules'] if rule['kind'] == 'holiday']
|
| 1224 |
+
anchored_rules = [rule for rule in config['rules'] if rule['kind'] == 'anchored']
|
| 1225 |
+
ordinary_rules = [rule for rule in config['rules']
|
| 1226 |
+
if rule['kind'] not in ('holiday', 'anchored')]
|
| 1227 |
+
# W47-T25: an anchored rule names ONE date rather than a repeating series, so it is COMPUTED
|
| 1228 |
+
# here instead of being searched for by the scan below. It still passes the trailing
|
| 1229 |
+
# `item >= now` filter, and that is deliberate: the cell holds the NEXT date, so an anchored
|
| 1230 |
+
# date that has already gone by is EMPTY rather than a date in the past. One column, one
|
| 1231 |
+
# meaning, which is what lets the ordinary filter, sort and group paths read it unchanged.
|
| 1232 |
+
# `horizon` is already final at this point, so an `ends: on` boundary binds here too.
|
| 1233 |
+
for rule in anchored_rules:
|
| 1234 |
+
occurrence = _anchored_occurrence(start, rule)
|
| 1235 |
+
if occurrence is not None and occurrence <= horizon:
|
| 1236 |
+
found.add(occurrence)
|
| 1237 |
+
# An anchored-only recurrence has nothing to scan for, and without this guard it would walk
|
| 1238 |
+
# ten years of days on every preview keystroke to find exactly nothing.
|
| 1239 |
+
while (ordinary_rules or holiday_rules) and day <= horizon and len(found) < limit:
|
| 1240 |
if any(_recurrence_matches(day, start, rule) for rule in ordinary_rules):
|
| 1241 |
found.add(day)
|
| 1242 |
for rule in holiday_rules:
|
|
|
|
| 1284 |
return out
|
| 1285 |
|
| 1286 |
|
| 1287 |
+
# ββ ββ W47-T26 (owner instruction 13 / ruling R2, contract C5): THE NEXT DATE AS A CELL ββ
|
| 1288 |
+
#
|
| 1289 |
+
# R2, verbatim: the computed next date is STORED in the cell, "so it filters, sorts and groups
|
| 1290 |
+
# like an ordinary date". Everything below is PURE β it reads a recurrence config and a row's
|
| 1291 |
+
# anchor cell and returns an ISO day string. The writer lives on the write path
|
| 1292 |
+
# (`aios-web/api/routes_grid.py`), because a value re-derived on every response is exactly the
|
| 1293 |
+
# thing that cannot be filtered, and that is the defect this pair closes.
|
| 1294 |
+
#
|
| 1295 |
+
# β `project_date_recurrences` ABOVE IS UNCHANGED AND STAYS UNCHANGED. It projects the field's
|
| 1296 |
+
# METADATA (the config plus a server-authoritative preview) for the editor to draw; these two
|
| 1297 |
+
# functions project a ROW's value. Two different questions, and `verify_fields_contract.py` and
|
| 1298 |
+
# `verify_api.py::section_recurrence_preview` both assert the first one's exact output.
|
| 1299 |
+
|
| 1300 |
+
|
| 1301 |
+
def recurrence_row_next_date(recurrence, anchor_value, today=None, condition_fields=None):
|
| 1302 |
+
"""The ONE next date a row's recurrence names, computed from THAT ROW's anchor cell.
|
| 1303 |
+
|
| 1304 |
+
β AN EMPTY ANCHOR CELL IS AN EMPTY ANSWER, never the field-level ``startDate``. Falling
|
| 1305 |
+
back to the field's own start would hand every unanchored row the SAME date β a column full
|
| 1306 |
+
of confident wrong values instead of an honestly empty one, and W47-T25 already ruled that
|
| 1307 |
+
clause. ``None`` here becomes an empty cell there.
|
| 1308 |
+
|
| 1309 |
+
The per-row config is the STORED config with ``startDate`` REPLACED, which is deliberately
|
| 1310 |
+
simpler than `recurrence_preview`'s unused ``resolvedAnchorDate`` hook: one substitution, and
|
| 1311 |
+
then every rule kind β daily, weekly, monthly, yearly, holiday, anchored β is answered by
|
| 1312 |
+
exactly the code that answers the field-level preview. There is no second definition of
|
| 1313 |
+
"next" to keep in step, which is the whole reason the substitution happens here rather than
|
| 1314 |
+
inside the scan.
|
| 1315 |
+
"""
|
| 1316 |
+
if not isinstance(recurrence, dict):
|
| 1317 |
+
return None
|
| 1318 |
+
anchor = _iso_day(anchor_value)
|
| 1319 |
+
if anchor is None:
|
| 1320 |
+
return None
|
| 1321 |
+
payload = recurrence_payload({**recurrence, 'startDate': anchor.isoformat()},
|
| 1322 |
+
today=today, condition_fields=condition_fields)
|
| 1323 |
+
return (payload or {}).get('nextDate') or None
|
| 1324 |
+
|
| 1325 |
+
|
| 1326 |
+
def recurrence_column_values(recurrence, rows, anchor_key, today=None, condition_fields=None,
|
| 1327 |
+
row_ids=None):
|
| 1328 |
+
"""``{row_id: <ISO day> or ''}`` for one recurrence date column over ``rows``.
|
| 1329 |
+
|
| 1330 |
+
``rows`` is the store's own ``{row_id: {field_key: value}}`` shape. ``row_ids`` narrows the
|
| 1331 |
+
pass to the rows an anchor edit actually touched; ``None`` means the whole column.
|
| 1332 |
+
|
| 1333 |
+
β MEMOISED ON THE ANCHOR DAY, and that is not a micro-optimisation. `recurrence_preview`
|
| 1334 |
+
walks a day at a time until it has ``previewCount`` matches, so ONE yearly rule is ~3,650
|
| 1335 |
+
iterations β per row. Rows overwhelmingly share anchor days (a batch loaded on one date, a
|
| 1336 |
+
renewal month), so the cache collapses a thousand-row column onto a handful of computations.
|
| 1337 |
+
β The obvious alternative β asking `recurrence_preview` for ``count=1`` β is NOT equivalent
|
| 1338 |
+
and must not be substituted: an anchored occurrence joins ``found`` BEFORE the scan and may be
|
| 1339 |
+
in the past, and ``sorted(found)[:limit]`` truncates BEFORE the ``>= now`` filter, so a limit
|
| 1340 |
+
of one can answer empty exactly where the full preview answers correctly.
|
| 1341 |
+
|
| 1342 |
+
An empty answer is ``''`` rather than ``None`` because that is what the grid stores when a
|
| 1343 |
+
person CLEARS a date cell (`core/grid_events.py`'s overlay branch). One representation of
|
| 1344 |
+
empty, so a materialised blank and a typed blank are the same value to every reader.
|
| 1345 |
+
"""
|
| 1346 |
+
if not isinstance(recurrence, dict) or not isinstance(rows, dict) or not anchor_key:
|
| 1347 |
+
return {}
|
| 1348 |
+
anchor_key = str(anchor_key)
|
| 1349 |
+
ids = list(rows) if row_ids is None else [str(rid) for rid in row_ids]
|
| 1350 |
+
memo, out = {}, {}
|
| 1351 |
+
for rid in ids:
|
| 1352 |
+
row = rows.get(str(rid))
|
| 1353 |
+
if not isinstance(row, dict):
|
| 1354 |
+
continue
|
| 1355 |
+
anchor = _iso_day(row.get(anchor_key))
|
| 1356 |
+
day = anchor.isoformat() if anchor is not None else ''
|
| 1357 |
+
if day not in memo:
|
| 1358 |
+
memo[day] = (recurrence_row_next_date(
|
| 1359 |
+
recurrence, day, today=today, condition_fields=condition_fields) or '')
|
| 1360 |
+
out[str(rid)] = memo[day]
|
| 1361 |
+
return out
|
| 1362 |
+
|
| 1363 |
+
|
| 1364 |
def _field_extras(saved, ftype, condition_fields=None):
|
| 1365 |
"""createdBy / permissions / format / scope β the validated passthrough the created strata
|
| 1366 |
share (wave 5). `createdBy` is only ever WRITTEN host-side (the handler stamps it); here it
|
platform/core/chart_system.py
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""chart_system.py β a SAVED CONFIGURABLE-INTERFACE RECORD (wave 47, instruction 18, W47-T30).
|
| 2 |
+
|
| 3 |
+
β **OWNER RULING R7 IS WHY THIS FILE EXISTS.** Verbatim: *"every interface like chart, swap etc.
|
| 4 |
+
that we need to configure should act like route with the right side navigation to choose the
|
| 5 |
+
specific view we want to see. So its not pegged on a per view basis."* Time-series state hides
|
| 6 |
+
today inside `ws["views"][vid]["config"]["display"]` β one copy per view, owned by nobody, listed
|
| 7 |
+
nowhere, and lost the moment the view it rode on is changed or deleted. That is precisely what the
|
| 8 |
+
ruling rejects.
|
| 9 |
+
|
| 10 |
+
β **CONTRACT C6:** *"a saved chart is a record, not a view setting. It carries its own id, name and
|
| 11 |
+
owner and is listed independently of `ws["views"]`, so a second consumer can reuse the type
|
| 12 |
+
unchanged."*
|
| 13 |
+
|
| 14 |
+
ββ **THIS FILE MUST NEVER INTERPRET `config`, AND THAT IS THE WHOLE REUSABILITY CONTRACT.** A
|
| 15 |
+
record carries a `kind` (this wave's only shipped consumer writes `"timeseries"`) and an OPAQUE
|
| 16 |
+
`config` dict stored verbatim. There is deliberately NO allowlist of kinds and NO knowledge of a
|
| 17 |
+
single config key: a second consumer ("swap", a map preset, a pivot) stores its own `kind` and its
|
| 18 |
+
own config shape with ZERO change to this file. An `if kind == "timeseries"` here β or a field
|
| 19 |
+
named after the time-series β breaks C6 while passing every gate.
|
| 20 |
+
|
| 21 |
+
β **INDEPENDENT STORAGE IS THE NEGATIVE CONTROL, not a detail.** Charts live in their own
|
| 22 |
+
dedicated store bucket, `loopable_chart_system`. The view documents live in the per-topic table
|
| 23 |
+
workspace buckets (`customer_table_workspace`, `product_table_workspace`, a `ut_*` key) under
|
| 24 |
+
`__shared__ -> views`. Nothing in this module reads or writes a workspace document, a `views` map,
|
| 25 |
+
or anything named `ws[...]`, so deleting a view cannot delete a chart: they are different keys in
|
| 26 |
+
the store and there is no code path between them.
|
| 27 |
+
|
| 28 |
+
β **THE SHAPE OF THIS MODULE MIRRORS `core/route_system.py` DELIBERATELY** β a dedicated
|
| 29 |
+
module-level `STORE_KEY`, a projected `_store` read, a read-modify-write `_persist` under the
|
| 30 |
+
store's own lock, server-minted ids, and a duck-typed `st` (only `get` / `get_projection` /
|
| 31 |
+
`update` are ever used). Like that module this one imports ONLY stdlib and NOTHING from
|
| 32 |
+
`platform/core/`, so it can never drag a topic, a permission model or a connector into a record
|
| 33 |
+
type that is meant to outlive all three. The small duplication of `_now` / `_store` / `_persist` is
|
| 34 |
+
correct here rather than a smell: there is no shared lower-level helper to reuse, and importing
|
| 35 |
+
`route_system` would couple charts to routes for four lines of code.
|
| 36 |
+
|
| 37 |
+
β NAME IS NOT UNIQUE. `id` is the only match key, exactly as for a Route. Two charts may share a
|
| 38 |
+
name on one database and neither is lost.
|
| 39 |
+
|
| 40 |
+
β PERMISSION IS NOT DECIDED HERE. Visibility is a per-database question and its one chokepoint is
|
| 41 |
+
`deps.Session.require(<database>)` in `aios-web/api/routes_charts.py`, the same predicate the nav
|
| 42 |
+
uses. This module stores `database` as a DATABASE KEY (`customer_data`, `product_data`, a `ut_*`
|
| 43 |
+
table key) β never the React client's separate `SurfaceScope` vocabulary ("customer", "product"),
|
| 44 |
+
which is a different string space and a separately booked defect.
|
| 45 |
+
"""
|
| 46 |
+
import copy
|
| 47 |
+
import json
|
| 48 |
+
import re
|
| 49 |
+
import uuid
|
| 50 |
+
from datetime import datetime, timezone
|
| 51 |
+
|
| 52 |
+
#: The DEDICATED bucket. Not inside any workspace document β that separation is what makes C6's
|
| 53 |
+
#: "listed independently of ws['views']" a fact about storage rather than a promise about code.
|
| 54 |
+
STORE_KEY = "loopable_chart_system"
|
| 55 |
+
|
| 56 |
+
#: This wave's only consumer. A DEFAULT, never a constraint: any slug is accepted.
|
| 57 |
+
DEFAULT_KIND = "timeseries"
|
| 58 |
+
|
| 59 |
+
_MAX_NAME = 120
|
| 60 |
+
_MAX_KIND = 40
|
| 61 |
+
_MAX_DATABASE = 200
|
| 62 |
+
_MAX_ID = 80
|
| 63 |
+
_MAX_STAMP = 120
|
| 64 |
+
#: A client may not park an unbounded blob in the tenant store. A BYTE CAP is not interpretation:
|
| 65 |
+
#: it never looks at a key, only at the serialized length.
|
| 66 |
+
MAX_CONFIG_BYTES = 64 * 1024
|
| 67 |
+
|
| 68 |
+
_KIND_CLEAN = re.compile(r"[^a-z0-9_]+")
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def _now():
|
| 72 |
+
return datetime.now(timezone.utc).replace(microsecond=0).isoformat()
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def _store(st):
|
| 76 |
+
"""The bucket, projected when the runtime offers a projection (never the whole store)."""
|
| 77 |
+
try:
|
| 78 |
+
projected = getattr(st, "get_projection", None)
|
| 79 |
+
if callable(projected):
|
| 80 |
+
return dict(projected(STORE_KEY, drop=()) or {})
|
| 81 |
+
return dict(st.get(STORE_KEY) or {})
|
| 82 |
+
except Exception:
|
| 83 |
+
return {}
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def _persist(st, mutate):
|
| 87 |
+
"""Read-modify-write under the store's own lock, mirroring `route_system._persist`."""
|
| 88 |
+
result = {}
|
| 89 |
+
|
| 90 |
+
def apply(current):
|
| 91 |
+
state = copy.deepcopy(current) if isinstance(current, dict) else {}
|
| 92 |
+
state.setdefault("charts", [])
|
| 93 |
+
next_state, value = mutate(state)
|
| 94 |
+
result["value"] = copy.deepcopy(value)
|
| 95 |
+
return next_state
|
| 96 |
+
|
| 97 |
+
st.update(STORE_KEY, apply, flush="sync")
|
| 98 |
+
return result.get("value")
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
def _text(raw, limit):
|
| 102 |
+
return str(raw if raw is not None else "").strip()[:limit]
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def _slug_kind(raw):
|
| 106 |
+
"""A kind is SANITIZED, never validated against a list. See the module note."""
|
| 107 |
+
slug = _KIND_CLEAN.sub("_", str(raw or "").strip().lower())[:_MAX_KIND].strip("_")
|
| 108 |
+
return slug or DEFAULT_KIND
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
def _config(raw):
|
| 112 |
+
"""`(value, ok)` for an OPAQUE config: JSON-safe and under the byte cap, or refused.
|
| 113 |
+
|
| 114 |
+
Strictly JSON-serializable with no `default=` coercion, because the store persists JSON and a
|
| 115 |
+
value that only stringifies would be a write that fails later, somewhere else. Nothing here
|
| 116 |
+
inspects a key, and nothing may start to.
|
| 117 |
+
"""
|
| 118 |
+
if raw is None:
|
| 119 |
+
return {}, True
|
| 120 |
+
if not isinstance(raw, dict):
|
| 121 |
+
return {}, False
|
| 122 |
+
try:
|
| 123 |
+
blob = json.dumps(raw)
|
| 124 |
+
except (TypeError, ValueError):
|
| 125 |
+
return {}, False
|
| 126 |
+
if len(blob.encode("utf-8")) > MAX_CONFIG_BYTES:
|
| 127 |
+
return {}, False
|
| 128 |
+
return copy.deepcopy(raw), True
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def _record(raw, *, created_by="", tenant_id="", prior=None):
|
| 132 |
+
"""Normalize one chart, or None when it is not a chart.
|
| 133 |
+
|
| 134 |
+
β `database`, `createdBy`, `createdAt`, `tenantId` and `id` are all PRIOR-WINS on update.
|
| 135 |
+
An update that could move a chart to another database would be a permission escape: the caller
|
| 136 |
+
passed the wall for the database the chart is on, not for the one being named.
|
| 137 |
+
"""
|
| 138 |
+
raw = raw if isinstance(raw, dict) else {}
|
| 139 |
+
prior = prior if isinstance(prior, dict) else None
|
| 140 |
+
|
| 141 |
+
name = _text(raw.get("name"), _MAX_NAME)
|
| 142 |
+
if not name and prior is not None:
|
| 143 |
+
name = _text(prior.get("name"), _MAX_NAME)
|
| 144 |
+
if not name:
|
| 145 |
+
return None
|
| 146 |
+
|
| 147 |
+
database = _text(prior.get("database") if prior is not None else raw.get("database"),
|
| 148 |
+
_MAX_DATABASE)
|
| 149 |
+
if not database:
|
| 150 |
+
return None
|
| 151 |
+
|
| 152 |
+
kind_src = raw.get("kind")
|
| 153 |
+
if kind_src in (None, "") and prior is not None:
|
| 154 |
+
kind_src = prior.get("kind")
|
| 155 |
+
kind = _slug_kind(kind_src)
|
| 156 |
+
|
| 157 |
+
if "config" in raw:
|
| 158 |
+
config, ok = _config(raw.get("config"))
|
| 159 |
+
if not ok:
|
| 160 |
+
return None
|
| 161 |
+
elif prior is not None:
|
| 162 |
+
config = copy.deepcopy(prior.get("config") or {})
|
| 163 |
+
else:
|
| 164 |
+
config = {}
|
| 165 |
+
|
| 166 |
+
now = _now()
|
| 167 |
+
if prior is not None:
|
| 168 |
+
chart_id = _text(prior.get("id"), _MAX_ID)
|
| 169 |
+
owner = _text(prior.get("createdBy"), _MAX_STAMP).lower()
|
| 170 |
+
tenant = _text(prior.get("tenantId"), _MAX_STAMP)
|
| 171 |
+
created_at = _text(prior.get("createdAt"), 40) or now
|
| 172 |
+
else:
|
| 173 |
+
chart_id = "chart_" + uuid.uuid4().hex
|
| 174 |
+
owner = _text(created_by, _MAX_STAMP).lower()
|
| 175 |
+
tenant = _text(tenant_id, _MAX_STAMP)
|
| 176 |
+
created_at = now
|
| 177 |
+
|
| 178 |
+
return {"id": chart_id,
|
| 179 |
+
"tenantId": tenant,
|
| 180 |
+
"kind": kind,
|
| 181 |
+
"database": database,
|
| 182 |
+
"name": name,
|
| 183 |
+
"config": config,
|
| 184 |
+
"createdBy": owner,
|
| 185 |
+
"createdAt": created_at,
|
| 186 |
+
"updatedAt": now}
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
def _tenant_ok(chart, tenant_id):
|
| 190 |
+
if not tenant_id:
|
| 191 |
+
return True
|
| 192 |
+
stamped = str(chart.get("tenantId") or "")
|
| 193 |
+
return not stamped or stamped == str(tenant_id)
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
def list_charts(st, *, database=None, tenant_id=None):
|
| 197 |
+
"""Every saved chart in this store, optionally narrowed to one database key.
|
| 198 |
+
|
| 199 |
+
Sorted by name then id so a navigator renders stably; NAME IS NOT UNIQUE, so id breaks ties.
|
| 200 |
+
"""
|
| 201 |
+
charts = [c for c in (_store(st).get("charts") or []) if isinstance(c, dict)]
|
| 202 |
+
charts = [c for c in charts if _tenant_ok(c, tenant_id)]
|
| 203 |
+
want = str(database or "").strip()
|
| 204 |
+
if want:
|
| 205 |
+
charts = [c for c in charts if str(c.get("database") or "") == want]
|
| 206 |
+
return sorted(charts, key=lambda c: (str(c.get("name") or "").lower(), str(c.get("id") or "")))
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
def get_chart(st, chart_id, *, tenant_id=None):
|
| 210 |
+
"""One chart by id, or None. The caller still owes the per-database wall."""
|
| 211 |
+
wanted = str(chart_id or "").strip()
|
| 212 |
+
if not wanted:
|
| 213 |
+
return None
|
| 214 |
+
for chart in list_charts(st, tenant_id=tenant_id):
|
| 215 |
+
if str(chart.get("id") or "") == wanted:
|
| 216 |
+
return chart
|
| 217 |
+
return None
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
def put_chart(st, raw, *, tenant_id, created_by):
|
| 221 |
+
"""Create (no `id`) or update (`id` of an existing chart). None when the input is not a chart.
|
| 222 |
+
|
| 223 |
+
An `id` naming a chart that does not exist is refused rather than created, so an upsert
|
| 224 |
+
primitive cannot become a way to choose your own id.
|
| 225 |
+
"""
|
| 226 |
+
incoming = dict(raw) if isinstance(raw, dict) else {}
|
| 227 |
+
wanted = str(incoming.get("id") or "").strip()
|
| 228 |
+
prior = get_chart(st, wanted, tenant_id=tenant_id) if wanted else None
|
| 229 |
+
if wanted and prior is None:
|
| 230 |
+
return None
|
| 231 |
+
record = _record(incoming, created_by=created_by, tenant_id=tenant_id, prior=prior)
|
| 232 |
+
if record is None:
|
| 233 |
+
return None
|
| 234 |
+
|
| 235 |
+
def mutate(state):
|
| 236 |
+
charts = [c for c in (state.get("charts") or []) if isinstance(c, dict)]
|
| 237 |
+
replaced = False
|
| 238 |
+
for index, chart in enumerate(charts):
|
| 239 |
+
if str(chart.get("id") or "") == record["id"]:
|
| 240 |
+
charts[index] = record
|
| 241 |
+
replaced = True
|
| 242 |
+
break
|
| 243 |
+
if not replaced:
|
| 244 |
+
charts.append(record)
|
| 245 |
+
state["charts"] = charts
|
| 246 |
+
return state, record
|
| 247 |
+
|
| 248 |
+
return _persist(st, mutate)
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
def delete_chart(st, chart_id):
|
| 252 |
+
"""True when a chart was removed. Touches nothing but this module's own bucket."""
|
| 253 |
+
wanted = str(chart_id or "").strip()
|
| 254 |
+
if not wanted:
|
| 255 |
+
return False
|
| 256 |
+
|
| 257 |
+
def mutate(state):
|
| 258 |
+
charts = [c for c in (state.get("charts") or []) if isinstance(c, dict)]
|
| 259 |
+
keep = [c for c in charts if str(c.get("id") or "") != wanted]
|
| 260 |
+
state["charts"] = keep
|
| 261 |
+
return state, len(keep) != len(charts)
|
| 262 |
+
|
| 263 |
+
return bool(_persist(st, mutate))
|
platform/core/grid_events.py
CHANGED
|
@@ -2531,43 +2531,114 @@ def handle_one(event, ctx):
|
|
| 2531 |
return _no('move_without_item',
|
| 2532 |
'That move did not say which item to file, so nothing was saved. '
|
| 2533 |
'Drag the item again.')
|
| 2534 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2535 |
# β Worded for the person, not the wall: a view shared WITH someone is in
|
| 2536 |
# their rail and is not theirs to file, which is the case they will meet.
|
| 2537 |
return _no('item_not_yours',
|
| 2538 |
'You can file only the items you own, and this one belongs to '
|
| 2539 |
'somebody else, so it stayed where it was.', key=item_id)
|
| 2540 |
-
cur = dict(placed.get(surface) or {})
|
| 2541 |
-
if target is None:
|
| 2542 |
-
# β "UNFILE" β the client says nothing about where it went. Popping is right
|
| 2543 |
-
# here and always was: no placement = render at the top level, and that is the
|
| 2544 |
-
# state a brand-new item is already in.
|
| 2545 |
-
cur.pop(item_id, None) # back to the root
|
| 2546 |
-
elif str(target) == _agf.ROOT_PLACEMENT:
|
| 2547 |
-
# ββ WAVE 32 Β· OWNER ITEM 20 (`W32-T27`, ASK C-16) β "FILED AT ROOT", STORED.
|
| 2548 |
-
#
|
| 2549 |
-
# β THE THIRD CASE, AND ITS ABSENCE IS THE WHOLE DEFECT. Popping (above) and
|
| 2550 |
-
# this branch produce the SAME rendering for an ordinary view, which is why
|
| 2551 |
-
# nobody missed it for nine waves β but they are different FACTS, and for a
|
| 2552 |
-
# SHARED view the difference is the entire feature: "never filed" sends it to
|
| 2553 |
-
# the Shared group, "the receiver dragged it out" must not. Absence cannot hold
|
| 2554 |
-
# two facts, so the second one gets a value.
|
| 2555 |
-
#
|
| 2556 |
-
# β AND IT IS DELIBERATELY EXEMPT FROM THE FOLDER-EXISTS TEST BELOW. This id
|
| 2557 |
-
# names no folder by design; running it through `any(f['id'] == tid ...)` would
|
| 2558 |
-
# refuse every root filing, which is the same silent no-op this ticket exists
|
| 2559 |
-
# to remove. `aios_grid.clean_item_folders` carries the matching exemption on
|
| 2560 |
-
# the READ side β the two are one change (see its note).
|
| 2561 |
-
cur[item_id] = _agf.ROOT_PLACEMENT
|
| 2562 |
else:
|
| 2563 |
-
|
| 2564 |
-
if
|
| 2565 |
-
|
| 2566 |
-
|
| 2567 |
-
|
| 2568 |
-
|
| 2569 |
-
|
| 2570 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2571 |
folders[surface] = lst
|
| 2572 |
clean = _agf.clean_folders(folders)
|
| 2573 |
return clean, _agf.clean_item_folders(
|
|
|
|
| 2531 |
return _no('move_without_item',
|
| 2532 |
'That move did not say which item to file, so nothing was saved. '
|
| 2533 |
'Drag the item again.')
|
| 2534 |
+
# ββ W47-T12 Β· OWNER INSTRUCTION 3 β AN `itemId` NAMING A **FOLDER** IS A
|
| 2535 |
+
# RE-PARENT, NOT A PLACEMENT.
|
| 2536 |
+
#
|
| 2537 |
+
# Owner: *"make sure we can drag and drop folder into another folder"*. Until this
|
| 2538 |
+
# branch the product had no re-parent gesture at all: `folder_create` was the only
|
| 2539 |
+
# event that carried `parent`, so a folder could be BORN inside another one and
|
| 2540 |
+
# could never be MOVED into one afterwards.
|
| 2541 |
+
#
|
| 2542 |
+
# β NO NEW EVENT KIND, AND THAT IS A CONSTRAINT RATHER THAN A PREFERENCE. The
|
| 2543 |
+
# client's `HostEvent` union and the emitters that build it live in files this
|
| 2544 |
+
# ticket does not own, so a `folder_move` would have been a kind nothing could
|
| 2545 |
+
# ever send. `item_move` already carries exactly the two fields a re-parent needs
|
| 2546 |
+
# (what moved, where it went) and already lands on this door.
|
| 2547 |
+
#
|
| 2548 |
+
# β THE ORDER OF THE TWO TESTS IS THE WHOLE SAFETY OF IT. An id this user OWNS as
|
| 2549 |
+
# an item is still an item move, checked first, so every event that has ever been
|
| 2550 |
+
# emitted takes the byte-identical path it always did. Only an id that is NOT an
|
| 2551 |
+
# item β which until today was refused outright as `item_not_yours` β is looked up
|
| 2552 |
+
# among the folders. A view and a folder cannot both answer to one id here, and if
|
| 2553 |
+
# they somehow did the item would win and nothing new would happen.
|
| 2554 |
+
#
|
| 2555 |
+
# β THE TREE WALL IS `validate_folder_tree`, NOT THIS BRANCH, and deliberately so:
|
| 2556 |
+
# `save_folders` below already refuses a multi-folder cycle and any chain past
|
| 2557 |
+
# `MAX_FOLDER_DEPTH`, naming the shallowest folder at fault in a sentence
|
| 2558 |
+
# `_folder_refuse` turns into a toast. Re-deriving either rule here would be a
|
| 2559 |
+
# second evaluator for a question that already has one, and the two would drift
|
| 2560 |
+
# the first time the cap moved. What this branch owes is the part the validator
|
| 2561 |
+
# cannot answer: the parent has to be a folder that IS HERE.
|
| 2562 |
+
#
|
| 2563 |
+
# β THE ONE CASE THE VALIDATOR NEVER SEES IS A **SELF**-PARENT, and this comment
|
| 2564 |
+
# said the opposite in its first draft. `aios_grid.clean_folders` runs first and
|
| 2565 |
+
# drops `parent` when it equals the folder's own id (`aios_grid.py`, the
|
| 2566 |
+
# `if parent and parent != fid` line), so a self-nest arriving on the wire is a
|
| 2567 |
+
# silent no-op here rather than a refusal β the folder simply stays where it is.
|
| 2568 |
+
# The RAIL refuses it out loud (`folders.ts::mayNestFolder`, *"A folder cannot go
|
| 2569 |
+
# inside itself."*), which is the path a person can actually take, and the create
|
| 2570 |
+
# branch above drops the same case the same way. Written down rather than
|
| 2571 |
+
# "fixed": a second refusal would claim the single toast slot on the path that
|
| 2572 |
+
# already speaks, and a comment asserting a guard that does not fire is what
|
| 2573 |
+
# W41-T12's own correction three screens down exists to warn about.
|
| 2574 |
+
own_here = _own_ids(surface, cur_ws)
|
| 2575 |
+
nested = (None if item_id in own_here
|
| 2576 |
+
else next((f for f in lst if f['id'] == item_id), None))
|
| 2577 |
+
if nested is not None:
|
| 2578 |
+
if target is None or str(target) == _agf.ROOT_PLACEMENT:
|
| 2579 |
+
# β BOTH SPELLINGS OF "THE TOP LEVEL" CLEAR THE PARENT. For an ITEM the
|
| 2580 |
+
# two are different facts (W32-T27: absence means never filed, the
|
| 2581 |
+
# sentinel means filed at root on purpose) because a shared view reads
|
| 2582 |
+
# them apart. A FOLDER has no such split β `folderNesting` renders every
|
| 2583 |
+
# unresolvable parent at the top level β so one behaviour for both is the
|
| 2584 |
+
# honest answer rather than a distinction nothing downstream can see.
|
| 2585 |
+
nested.pop('parent', None)
|
| 2586 |
+
else:
|
| 2587 |
+
pid_ = str(target).strip()[:80]
|
| 2588 |
+
if not any(f['id'] == pid_ for f in lst):
|
| 2589 |
+
return _no('folder_gone',
|
| 2590 |
+
'That folder is not on this sidebar any more, so the '
|
| 2591 |
+
'folder you dragged stayed where it was. Reload the page '
|
| 2592 |
+
'to see the folders you have, then try again.', key=pid_)
|
| 2593 |
+
nested['parent'] = pid_
|
| 2594 |
+
# β NO `placed` WRITE, AND NO RETURN EITHER. A folder is not an item and has no
|
| 2595 |
+
# placement: writing `itemFolders` here would file a folder as though it were a
|
| 2596 |
+
# view, and `clean_item_folders` would prune it on the very next read for naming
|
| 2597 |
+
# an id that is not in `_own_ids`. The parent IS the whole record β and `lst`
|
| 2598 |
+
# holds the row by reference, so the shared tail below (`folders[surface] = lst`,
|
| 2599 |
+
# then one `clean_folders`) carries it out through the ONE sanitise-and-return
|
| 2600 |
+
# this function has. A second copy of that tail here would be a second success
|
| 2601 |
+
# path to keep in step.
|
| 2602 |
+
elif item_id not in own_here:
|
| 2603 |
# β Worded for the person, not the wall: a view shared WITH someone is in
|
| 2604 |
# their rail and is not theirs to file, which is the case they will meet.
|
| 2605 |
return _no('item_not_yours',
|
| 2606 |
'You can file only the items you own, and this one belongs to '
|
| 2607 |
'somebody else, so it stayed where it was.', key=item_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2608 |
else:
|
| 2609 |
+
cur = dict(placed.get(surface) or {})
|
| 2610 |
+
if target is None:
|
| 2611 |
+
# β "UNFILE" β the client says nothing about where it went. Popping is
|
| 2612 |
+
# right here and always was: no placement = render at the top level, and
|
| 2613 |
+
# that is the state a brand-new item is already in.
|
| 2614 |
+
cur.pop(item_id, None) # back to the root
|
| 2615 |
+
elif str(target) == _agf.ROOT_PLACEMENT:
|
| 2616 |
+
# ββ WAVE 32 Β· OWNER ITEM 20 (`W32-T27`, ASK C-16) β "FILED AT ROOT",
|
| 2617 |
+
# STORED.
|
| 2618 |
+
#
|
| 2619 |
+
# β THE THIRD CASE, AND ITS ABSENCE IS THE WHOLE DEFECT. Popping (above)
|
| 2620 |
+
# and this branch produce the SAME rendering for an ordinary view, which
|
| 2621 |
+
# is why nobody missed it for nine waves β but they are different FACTS,
|
| 2622 |
+
# and for a SHARED view the difference is the entire feature: "never
|
| 2623 |
+
# filed" sends it to the Shared group, "the receiver dragged it out" must
|
| 2624 |
+
# not. Absence cannot hold two facts, so the second one gets a value.
|
| 2625 |
+
#
|
| 2626 |
+
# β AND IT IS DELIBERATELY EXEMPT FROM THE FOLDER-EXISTS TEST BELOW. This
|
| 2627 |
+
# id names no folder by design; running it through `any(f['id'] == tid
|
| 2628 |
+
# ...)` would refuse every root filing, which is the same silent no-op
|
| 2629 |
+
# that ticket exists to remove. `aios_grid.clean_item_folders` carries the
|
| 2630 |
+
# matching exemption on the READ side β the two are one change (see its
|
| 2631 |
+
# note).
|
| 2632 |
+
cur[item_id] = _agf.ROOT_PLACEMENT
|
| 2633 |
+
else:
|
| 2634 |
+
tid = str(target)[:80]
|
| 2635 |
+
if not any(f['id'] == tid for f in lst):
|
| 2636 |
+
return _no('folder_gone',
|
| 2637 |
+
'That folder is not on this sidebar any more, so the item '
|
| 2638 |
+
'stayed where it was. Reload the page to see the folders '
|
| 2639 |
+
'you have, then try again.', key=tid)
|
| 2640 |
+
cur[item_id] = tid
|
| 2641 |
+
placed[surface] = cur
|
| 2642 |
folders[surface] = lst
|
| 2643 |
clean = _agf.clean_folders(folders)
|
| 2644 |
return clean, _agf.clean_item_folders(
|
platform/core/user_tables.py
CHANGED
|
@@ -58,6 +58,14 @@ STORE_KEY = 'user_tables'
|
|
| 58 |
ZONE_STORE_KEY = 'table_zones'
|
| 59 |
VALUE_HISTORY_KEY = 'value_history'
|
| 60 |
SHARED_NOTES_KEY = 'shared_notes'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
ODOO_SCHEMA_SNAPSHOT_KEY = 'odoo_schema_snapshot'
|
| 62 |
ODOO_SCHEMA_ENABLEMENTS_KEY = 'odoo_schema_enablements'
|
| 63 |
ODOO_SYNC_STATUS_KEY = 'odoo_sync_status'
|
|
@@ -4503,6 +4511,76 @@ def put_shared_note(subject_kind, subject_id, body, actor, *, st=None):
|
|
| 4503 |
return result
|
| 4504 |
|
| 4505 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4506 |
def nav_entries(viewer=None, is_admin=False, st=None):
|
| 4507 |
"""Registry-SHAPED dicts so the nav can render user tables beside real modules with no
|
| 4508 |
special-casing: the same keys the flat nav reads (`key`, `label`, `source`).
|
|
|
|
| 58 |
ZONE_STORE_KEY = 'table_zones'
|
| 59 |
VALUE_HISTORY_KEY = 'value_history'
|
| 60 |
SHARED_NOTES_KEY = 'shared_notes'
|
| 61 |
+
#: W47-T16 (owner instruction 19) - PER-USER read marks for the shared notes above.
|
| 62 |
+
#: Keyed USER FIRST and subject second, which is the whole safety property: one person's
|
| 63 |
+
#: stamp is written into their own branch of the document and cannot reach anybody else's,
|
| 64 |
+
#: so "opening a note clears its own count and does not clear anybody else's" is true by
|
| 65 |
+
#: SHAPE rather than by a careful writer. The value is the note VERSION that was read, not a
|
| 66 |
+
#: boolean: `put_shared_note` already increments `version` on every save, so a note edited
|
| 67 |
+
#: after you read it goes unread again with no extra bookkeeping.
|
| 68 |
+
SHARED_NOTE_READS_KEY = 'shared_note_reads'
|
| 69 |
ODOO_SCHEMA_SNAPSHOT_KEY = 'odoo_schema_snapshot'
|
| 70 |
ODOO_SCHEMA_ENABLEMENTS_KEY = 'odoo_schema_enablements'
|
| 71 |
ODOO_SYNC_STATUS_KEY = 'odoo_sync_status'
|
|
|
|
| 4511 |
return result
|
| 4512 |
|
| 4513 |
|
| 4514 |
+
def note_read_version(subject_kind, subject_id, viewer, *, st=None):
|
| 4515 |
+
"""The note VERSION this viewer has already opened for one subject. 0 when never opened."""
|
| 4516 |
+
marks = (_st(st).get(SHARED_NOTE_READS_KEY) or {}).get(str(viewer or '')) or {}
|
| 4517 |
+
try:
|
| 4518 |
+
return int(marks.get(f"{subject_kind}:{subject_id}") or 0)
|
| 4519 |
+
except (TypeError, ValueError):
|
| 4520 |
+
return 0
|
| 4521 |
+
|
| 4522 |
+
|
| 4523 |
+
def mark_note_read(subject_kind, subject_id, viewer, version, *, st=None):
|
| 4524 |
+
"""Stamp that this viewer has read a subject's note at `version`.
|
| 4525 |
+
|
| 4526 |
+
β WRITES ONLY INSIDE `viewer`'s OWN BRANCH. The document is `{user: {subject: version}}`, so
|
| 4527 |
+
there is no expressible write here that could clear somebody else's count - the done-when's
|
| 4528 |
+
"does not clear anybody else's" is a property of the SHAPE, not of this function being careful.
|
| 4529 |
+
β Monotonic on purpose: a stale client answering late must not un-read a newer version the
|
| 4530 |
+
same person has already opened, so the stamp only ever moves FORWARD.
|
| 4531 |
+
"""
|
| 4532 |
+
if subject_kind not in {'database', 'view'}:
|
| 4533 |
+
return None
|
| 4534 |
+
user = str(viewer or '')
|
| 4535 |
+
if not user:
|
| 4536 |
+
return None
|
| 4537 |
+
key = f"{subject_kind}:{subject_id}"
|
| 4538 |
+
try:
|
| 4539 |
+
wanted = int(version or 0)
|
| 4540 |
+
except (TypeError, ValueError):
|
| 4541 |
+
wanted = 0
|
| 4542 |
+
result = {}
|
| 4543 |
+
|
| 4544 |
+
def _put(current):
|
| 4545 |
+
current = dict(current or {})
|
| 4546 |
+
mine = dict(current.get(user) or {})
|
| 4547 |
+
try:
|
| 4548 |
+
held = int(mine.get(key) or 0)
|
| 4549 |
+
except (TypeError, ValueError):
|
| 4550 |
+
held = 0
|
| 4551 |
+
mine[key] = max(held, wanted)
|
| 4552 |
+
current[user] = mine
|
| 4553 |
+
result['version'] = mine[key]
|
| 4554 |
+
return current
|
| 4555 |
+
|
| 4556 |
+
_st(st).update(SHARED_NOTE_READS_KEY, _put, flush='sync')
|
| 4557 |
+
return result
|
| 4558 |
+
|
| 4559 |
+
|
| 4560 |
+
def unread_note_subjects(subjects, viewer, *, st=None):
|
| 4561 |
+
"""Which of `subjects` carry a note this viewer has not opened at its current version.
|
| 4562 |
+
|
| 4563 |
+
`subjects` is an iterable of `(subject_kind, subject_id)`. Returns the list of unread ones,
|
| 4564 |
+
each with the version that would have to be stamped to clear it, so a caller never has to
|
| 4565 |
+
guess a number the store already knows.
|
| 4566 |
+
β A note with an EMPTY body is not unread. `put_shared_note` bumps `version` on every save
|
| 4567 |
+
including a blank one, so counting version alone would leave a badge on a note somebody had
|
| 4568 |
+
just cleared - the same reasoning the client's `asSharedNote` uses to decide there is no note.
|
| 4569 |
+
"""
|
| 4570 |
+
out = []
|
| 4571 |
+
for kind, subject_id in subjects:
|
| 4572 |
+
note = shared_note(kind, subject_id, st=st)
|
| 4573 |
+
if not str(note.get('body') or '').strip():
|
| 4574 |
+
continue
|
| 4575 |
+
try:
|
| 4576 |
+
version = int(note.get('version') or 0)
|
| 4577 |
+
except (TypeError, ValueError):
|
| 4578 |
+
version = 0
|
| 4579 |
+
if version > note_read_version(kind, subject_id, viewer, st=st):
|
| 4580 |
+
out.append({'subjectKind': kind, 'subjectId': str(subject_id), 'version': version})
|
| 4581 |
+
return out
|
| 4582 |
+
|
| 4583 |
+
|
| 4584 |
def nav_entries(viewer=None, is_admin=False, st=None):
|
| 4585 |
"""Registry-SHAPED dicts so the nav can render user tables beside real modules with no
|
| 4586 |
special-casing: the same keys the flat nav reads (`key`, `label`, `source`).
|
platform/model/topics/odoo_customers.yml
CHANGED
|
@@ -16,17 +16,50 @@ scope:
|
|
| 16 |
population: "the customer book `modules/customer_data.pool()` builds; the grid's own contract states it as one row per customer who ordered in the last 24 months"
|
| 17 |
identity: "the Odoo res.partner id β exposed as the `partner_id` column (W33-T43) and used as the row pid, so there is ONE id per row and no second one"
|
| 18 |
merged: "W33-T44 retired `ut_odoo_customers`, which presented this same subject. This topic describes the SURVIVING database, `customer_data`, which keeps its store bucket so no saved view, grant, cohort or formula moved"
|
| 19 |
-
no_date: "
|
| 20 |
store:
|
| 21 |
table: res_partner
|
| 22 |
alias: p
|
| 23 |
-
# NO date_col
|
| 24 |
# omitted, so its absence reads as a fact and not as an unfinished file.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
dims:
|
| 26 |
agent: {label: "Sales agent"}
|
| 27 |
state: {label: "State"}
|
| 28 |
country: {label: "Country"}
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
# key / label / type / kind, derived from the grid contract. `kind` says where the
|
| 31 |
# value COMES FROM: a `data` column is stored on the row; a `rollup` is computed
|
| 32 |
# from another topic; a `link` points at another database.
|
|
@@ -240,4 +273,5 @@ fields:
|
|
| 240 |
ai_context: >
|
| 241 |
The customer REGISTRY as a person sees it in the app β the database labelled 'Odoo customers'.
|
| 242 |
Use it to answer 'who is this customer', 'which customers exist', 'which agent owns them', 'where are they', and for the AR columns it carries (ar_open, ar_overdue, days_to_pay), which are reconciled by modules/ar.py.
|
| 243 |
-
|
|
|
|
|
|
| 16 |
population: "the customer book `modules/customer_data.pool()` builds; the grid's own contract states it as one row per customer who ordered in the last 24 months"
|
| 17 |
identity: "the Odoo res.partner id β exposed as the `partner_id` column (W33-T43) and used as the row pid, so there is ONE id per row and no second one"
|
| 18 |
merged: "W33-T44 retired `ut_odoo_customers`, which presented this same subject. This topic describes the SURVIVING database, `customer_data`, which keeps its store bucket so no saved view, grant, cohort or formula moved"
|
| 19 |
+
no_date: "this registry owns no date column of its own, so it stores nothing dated. It does serve WINDOWED sales measures: the `measures:` binding below draws them from sales_lines, which owns the date column, joined on that topic's `order_partner` dim. For anything else time-windowed about a customer, or at line grain, ask sales_lines or customer_invoices"
|
| 20 |
store:
|
| 21 |
table: res_partner
|
| 22 |
alias: p
|
| 23 |
+
# NO date_col. A registry is not a dated event stream. Stated rather than
|
| 24 |
# omitted, so its absence reads as a fact and not as an unfinished file.
|
| 25 |
+
#
|
| 26 |
+
# W47-T29 / R5: this stays true and is NOT contradicted by the `measures:` block
|
| 27 |
+
# below. The windowed sales columns are not stored on this table; they are read
|
| 28 |
+
# THROUGH `sales_lines`, whose `date_col` (o.date_order) is the one the window
|
| 29 |
+
# applies to. The join is that topic's `order_partner` dim.
|
| 30 |
dims:
|
| 31 |
agent: {label: "Sales agent"}
|
| 32 |
state: {label: "State"}
|
| 33 |
country: {label: "Country"}
|
| 34 |
|
| 35 |
+
# ββ W47-T29 / OWNER RULING R5 (closes D-478): sales measures on a customer.
|
| 36 |
+
#
|
| 37 |
+
# β THE JOIN KEY NEEDS NO NEW DIM, unlike the product side. `sales_lines.order_partner`
|
| 38 |
+
# is `l.order_partner_id`, which IS the Odoo `res.partner` id, which IS this grid's own
|
| 39 |
+
# identity (see `scope.identity` above: the row's pid IS the partner id, exposed as the
|
| 40 |
+
# `partner_id` column). `odoo_products` needed a separate `product_code` dim only because
|
| 41 |
+
# its grid keys on `default_code` rather than on Odoo's `product_id`; there is no such
|
| 42 |
+
# gap here, so binding to `order_partner` keys every cell on the number each grid row
|
| 43 |
+
# already carries.
|
| 44 |
+
#
|
| 45 |
+
# β NO `scope_variant`, DELIBERATELY, and this is the one line not to copy from
|
| 46 |
+
# `odoo_products`. That file sets `all_channels` because PRODUCT movement must include
|
| 47 |
+
# Amazon. A CUSTOMER number must not: the project's fixed scope puts the Amazon channel
|
| 48 |
+
# (partner GIFTWARE DEALS) outside wholesale customer scope, and `sales_lines.scope_sql`
|
| 49 |
+
# already states that fence. Inheriting the variant would silently redefine what every
|
| 50 |
+
# customer revenue figure means. Consequence, stated so it is not filed as a defect: a
|
| 51 |
+
# customer whose only orders are Amazon channel orders shows blank here, correctly.
|
| 52 |
+
#
|
| 53 |
+
# β A SINGLE-TOPIC GROUPED QUERY, so `semantic.store_query`'s cross-topic refusal does
|
| 54 |
+
# not bite: all six metrics live ON `sales_lines` and we group `sales_lines` by its OWN
|
| 55 |
+
# dim. `orders`/`aov` are absent for the same reason they are absent on the product and
|
| 56 |
+
# agent bindings (the `orders` denominator lives on `sales_orders`), and
|
| 57 |
+
# `entity_measures()` re-proves the list rather than trusting it.
|
| 58 |
+
measures:
|
| 59 |
+
- source: sales_lines
|
| 60 |
+
dim: order_partner
|
| 61 |
+
keys: [revenue, units, margin, cogs, margin_pct, asp]
|
| 62 |
+
|
| 63 |
# key / label / type / kind, derived from the grid contract. `kind` says where the
|
| 64 |
# value COMES FROM: a `data` column is stored on the row; a `rollup` is computed
|
| 65 |
# from another topic; a `link` points at another database.
|
|
|
|
| 273 |
ai_context: >
|
| 274 |
The customer REGISTRY as a person sees it in the app β the database labelled 'Odoo customers'.
|
| 275 |
Use it to answer 'who is this customer', 'which customers exist', 'which agent owns them', 'where are they', and for the AR columns it carries (ar_open, ar_overdue, days_to_pay), which are reconciled by modules/ar.py.
|
| 276 |
+
β WINDOWED SALES MEASURES ARE AVAILABLE ON THIS DATABASE (W47-T29 / R5): revenue, units, margin, cogs, margin_pct and asp all accept a date window, as Time-series and as the grid's Metric field kind. They are not stored here. They are read through sales_lines, which owns the date column, joined on that topic's `order_partner` dim, and they carry the wholesale scope sales_lines declares, so a customer whose only orders are Amazon channel orders shows blank.
|
| 277 |
+
β This topic still has NO date column of its own, and nothing else about it is time-windowed. For any OTHER windowed question, or at line grain (individual order lines, invoices, open items), go to sales_lines / customer_invoices / receivables, which own the time dimension.
|
web/src/assistant/AssistantPage.tsx
CHANGED
|
@@ -1,11 +1,9 @@
|
|
| 1 |
import { lazy, Suspense, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
| 2 |
|
| 3 |
import { QUERY_OPEN_EVENT, signal } from "../apiContract";
|
| 4 |
-
import { FolderMark } from "../customer-grid/icons";
|
| 5 |
import { queryCitationLabel } from "../customer-grid/queryPreview";
|
| 6 |
import { retryEmit } from "../inbox/inboxModel";
|
| 7 |
import { queryGroups, QueryRail } from "../query/queryParts";
|
| 8 |
-
import { DbIcon } from "../shell/dbFrame";
|
| 9 |
import { ASSISTANT_ROUTE, databaseEntries, QUERY_ROUTE, routeKeyOf } from "../shell/nav";
|
| 10 |
import type { NavEntry } from "../shell/nav";
|
| 11 |
import { getQueryModelCatalog, persistQueryArtifacts, runQueryTool, type QueryModelIdentity, type QueryToolArtifacts } from "../automation/automationApi";
|
|
@@ -338,15 +336,16 @@ function initialIndex(): QueryIndex {
|
|
| 338 |
* Β· `reference/ChatGPT 1.png` β the CONVERSATION: one centred column, the question as a bubble
|
| 339 |
* on the right, the answer as plain flowing text with no label and no bubble, the composer
|
| 340 |
* pinned to the bottom with its controls INSIDE the field.
|
| 341 |
-
* Β· `reference/Glean 1.png` β the SOURCES: a row of chips
|
| 342 |
-
*
|
|
|
|
|
|
|
| 343 |
* Β· `reference/Airtable AI 1.png` β the NAVIGATION: "New chat" at the top of a left panel, the
|
| 344 |
* thread list under it, and a centred "How can I help?" when the thread is empty.
|
| 345 |
*
|
| 346 |
* β WHAT IS DELIBERATELY NOT COPIED: ChatGPT's dark canvas and Glean's vendor logos. The palette
|
| 347 |
* is Loopable's own (`DESIGN.md`, and the font-token rule is gated app-wide over every CSS file
|
| 348 |
-
* in this tree),
|
| 349 |
-
* database β because a brand logo for someone else's product is what those references have and
|
| 350 |
* this product's databases are not brands. "Exactly like" is about the interaction shape.
|
| 351 |
*
|
| 352 |
* β AND THE TOOL BOUNDARY IS NARROWER THAN THE SENTENCE "the chatbot can basically call the tools
|
|
@@ -357,7 +356,6 @@ function initialIndex(): QueryIndex {
|
|
| 357 |
export default function AssistantPage({ granted }: AssistantPageProps) {
|
| 358 |
const [index, setIndex] = useState<QueryIndex>(initialIndex);
|
| 359 |
const [activeThread, setActiveThread] = useState("");
|
| 360 |
-
const [selected, setSelected] = useState<string[]>([]);
|
| 361 |
const [target, setTarget] = useState("");
|
| 362 |
const [model, setModel] = useState("auto");
|
| 363 |
const [question, setQuestion] = useState("");
|
|
@@ -384,21 +382,13 @@ export default function AssistantPage({ granted }: AssistantPageProps) {
|
|
| 384 |
const databases = useMemo(() => databaseEntries(granted).filter((entry) => entry.kind !== "group"), [granted]);
|
| 385 |
const labels = useMemo(() => new Map(databases.map((entry) => [entry.key, entry.label])), [databases]);
|
| 386 |
/**
|
| 387 |
-
* ββ
|
| 388 |
-
*
|
| 389 |
-
*
|
| 390 |
-
*
|
| 391 |
-
*
|
| 392 |
-
*
|
| 393 |
-
* refusal is still the wall; a client that greyed out everything it had not heard about would
|
| 394 |
-
* hide a working source the moment this field failed to arrive.
|
| 395 |
*/
|
| 396 |
-
const sourceStatus = useMemo(
|
| 397 |
-
() => new Map(index.sources.map((row) => [row.database, row])), [index.sources]);
|
| 398 |
-
const blockedReason = useCallback(
|
| 399 |
-
(key: string) => (sourceStatus.get(key)?.answerable === false
|
| 400 |
-
? sourceStatus.get(key)?.reason || "this database cannot be asked yet" : ""),
|
| 401 |
-
[sourceStatus]);
|
| 402 |
const messages = index.messages.filter((row) => row.threadId === activeThread);
|
| 403 |
const viewById = useMemo(() => new Map(index.views.map((view) => [view.id, view])), [index.views]);
|
| 404 |
|
|
@@ -430,19 +420,20 @@ export default function AssistantPage({ granted }: AssistantPageProps) {
|
|
| 430 |
return () => controller.abort();
|
| 431 |
}, []);
|
| 432 |
useEffect(() => () => openCancel.current?.(), []);
|
|
|
|
|
|
|
| 433 |
useEffect(() => {
|
| 434 |
const permitted = databases.map((entry) => entry.key);
|
| 435 |
-
|
| 436 |
-
setTarget((current) => permitted.includes(current) ? current : "");
|
| 437 |
}, [databases]);
|
| 438 |
-
// A resume token is bound to the database
|
| 439 |
-
//
|
| 440 |
useEffect(() => {
|
| 441 |
-
if (alignment &&
|
| 442 |
setAlignment(null);
|
| 443 |
setAlignmentFields([]);
|
| 444 |
}
|
| 445 |
-
}, [alignment,
|
| 446 |
// The conversation reads bottom-up, like every chat the owner named.
|
| 447 |
useEffect(() => { foot.current?.scrollIntoView({ block: "end" }); }, [messages.length, busy]);
|
| 448 |
|
|
@@ -520,26 +511,17 @@ export default function AssistantPage({ granted }: AssistantPageProps) {
|
|
| 520 |
setActiveThread(""); setQuestion(""); setProblem("");
|
| 521 |
}, []);
|
| 522 |
|
| 523 |
-
/** Opening a past chat restores the
|
| 524 |
const openThread = useCallback((id: string) => {
|
| 525 |
setActiveThread(id); setProblem("");
|
| 526 |
const row = index.threads.find((thread) => thread.id === id);
|
| 527 |
if (!row) return;
|
| 528 |
const permitted = databases.map((entry) => entry.key);
|
| 529 |
-
const
|
| 530 |
-
if (
|
| 531 |
if (row.model && index.models.includes(row.model) && !modelBlocked(row.model)) setModel(row.model);
|
| 532 |
}, [databases, index.models, index.threads, modelBlocked]);
|
| 533 |
|
| 534 |
-
const toggleSource = useCallback((key: string) => {
|
| 535 |
-
if (blockedReason(key)) return;
|
| 536 |
-
setSelected((current) => {
|
| 537 |
-
const next = current.includes(key) ? current.filter((item) => item !== key) : [...current, key];
|
| 538 |
-
setTarget((currentTarget) => next.includes(currentTarget) ? currentTarget : next[0] || "");
|
| 539 |
-
return next;
|
| 540 |
-
});
|
| 541 |
-
}, [blockedReason]);
|
| 542 |
-
|
| 543 |
/**
|
| 544 |
* ββ R16 β ENTER GOES TO THE CHAT, NOT TO A WAIT. Owner: *"Pressing enter goes immediately to
|
| 545 |
* the chat view showing that it is loading; there is a thinking animation."*
|
|
@@ -557,7 +539,7 @@ export default function AssistantPage({ granted }: AssistantPageProps) {
|
|
| 557 |
const ask = useCallback(async (approvedFields?: string[]) => {
|
| 558 |
const text = approvedFields && alignment ? alignment.prompt : question.trim();
|
| 559 |
const database = approvedFields && alignment ? alignment.database : target;
|
| 560 |
-
if (!text || !database ||
|
| 561 |
setBusy(true); setProblem("");
|
| 562 |
let governed: Awaited<ReturnType<typeof runQueryTool>>;
|
| 563 |
try {
|
|
@@ -577,12 +559,15 @@ export default function AssistantPage({ granted }: AssistantPageProps) {
|
|
| 577 |
const optimistic: QueryMessage = {
|
| 578 |
id: pendingId, threadId: activeThread, role: "user", content: text,
|
| 579 |
createdAt: new Date().toISOString(), targetDatabase: database,
|
| 580 |
-
sources:
|
| 581 |
};
|
| 582 |
const withoutPending = (rows: QueryMessage[]) => rows.filter((row) => row.id !== pendingId);
|
| 583 |
setQuestion("");
|
| 584 |
setIndex((current) => ({ ...current, messages: [...current.messages, optimistic] }));
|
| 585 |
-
|
|
|
|
|
|
|
|
|
|
| 586 |
...(activeThread ? { threadId: activeThread } : {}), model });
|
| 587 |
setBusy(false);
|
| 588 |
if (!result.ok) {
|
|
@@ -602,7 +587,7 @@ export default function AssistantPage({ granted }: AssistantPageProps) {
|
|
| 602 |
views: result.value.view ? [result.value.view, ...current.views.filter((row) => row.id !== result.value.view?.id)] : current.views,
|
| 603 |
citations: [...current.citations, ...result.value.citations],
|
| 604 |
}));
|
| 605 |
-
}, [activeThread, alignment, busy, model, question,
|
| 606 |
|
| 607 |
/** β The chat goes; the views it built STAY (they live in Query). Two-click, in the row. */
|
| 608 |
const removeThread = useCallback(async (id: string) => {
|
|
@@ -657,7 +642,7 @@ export default function AssistantPage({ granted }: AssistantPageProps) {
|
|
| 657 |
className="as-prompt"
|
| 658 |
value={question}
|
| 659 |
rows={1}
|
| 660 |
-
placeholder={target ? `Ask about ${labels.get(target) || target}β¦` : "
|
| 661 |
aria-label="Ask the assistant"
|
| 662 |
onChange={(event) => setQuestion(event.currentTarget.value)}
|
| 663 |
onKeyDown={(event) => {
|
|
@@ -684,14 +669,16 @@ export default function AssistantPage({ granted }: AssistantPageProps) {
|
|
| 684 |
</select>
|
| 685 |
</label>
|
| 686 |
{/* β ONLY WHEN THE ANSWER IS AMBIGUOUS. Every generated view names ONE database (R3);
|
| 687 |
-
with a single
|
| 688 |
-
be chrome for its own sake. */}
|
| 689 |
-
{
|
| 690 |
<label className="as-pick">
|
| 691 |
<span className="as-pick-label">Build on</span>
|
| 692 |
<select className="as-pick-select" value={target} aria-label="Target database"
|
| 693 |
onChange={(event) => setTarget(event.currentTarget.value)}>
|
| 694 |
-
{
|
|
|
|
|
|
|
| 695 |
</select>
|
| 696 |
</label>
|
| 697 |
) : null}
|
|
@@ -703,38 +690,13 @@ export default function AssistantPage({ granted }: AssistantPageProps) {
|
|
| 703 |
</button>
|
| 704 |
</div>
|
| 705 |
</div>
|
| 706 |
-
{/*
|
| 707 |
-
|
| 708 |
-
|
| 709 |
-
|
| 710 |
-
const blocked = blockedReason(database.key);
|
| 711 |
-
return (
|
| 712 |
-
<button type="button" key={database.key}
|
| 713 |
-
className={"as-chip" + (on ? " is-selected" : "")
|
| 714 |
-
+ (database.key === target ? " is-target" : "") + (blocked ? " is-blocked" : "")}
|
| 715 |
-
aria-pressed={on}
|
| 716 |
-
aria-disabled={blocked ? true : undefined}
|
| 717 |
-
title={blocked || undefined}
|
| 718 |
-
onClick={() => toggleSource(database.key)}>
|
| 719 |
-
<span className="as-chip-mark" aria-hidden="true">
|
| 720 |
-
{database.icon ? <FolderMark icon={database.icon} size={14} /> : <DbIcon />}
|
| 721 |
-
</span>
|
| 722 |
-
<span className="as-chip-name">{database.label}</span>
|
| 723 |
-
</button>
|
| 724 |
-
);
|
| 725 |
-
})}
|
| 726 |
-
{/* β ONE sentence for the whole row, not one per chip: with ten blocked sources the
|
| 727 |
-
per-chip copy would be the loudest thing on a surface whose whole instruction was
|
| 728 |
-
"plain". The chip carries the exact cause in its `title`. */}
|
| 729 |
-
{databases.some((database) => blockedReason(database.key)) ? (
|
| 730 |
-
<p className="as-chips-note">
|
| 731 |
-
Greyed databases are served live from a connector and cannot be asked yet.
|
| 732 |
-
</p>
|
| 733 |
-
) : null}
|
| 734 |
-
{databases.length === 0 && loaded ? (
|
| 735 |
<p className="as-chips-empty">No databases are shared with your account yet.</p>
|
| 736 |
-
|
| 737 |
-
|
| 738 |
</div>
|
| 739 |
);
|
| 740 |
|
|
|
|
| 1 |
import { lazy, Suspense, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
| 2 |
|
| 3 |
import { QUERY_OPEN_EVENT, signal } from "../apiContract";
|
|
|
|
| 4 |
import { queryCitationLabel } from "../customer-grid/queryPreview";
|
| 5 |
import { retryEmit } from "../inbox/inboxModel";
|
| 6 |
import { queryGroups, QueryRail } from "../query/queryParts";
|
|
|
|
| 7 |
import { ASSISTANT_ROUTE, databaseEntries, QUERY_ROUTE, routeKeyOf } from "../shell/nav";
|
| 8 |
import type { NavEntry } from "../shell/nav";
|
| 9 |
import { getQueryModelCatalog, persistQueryArtifacts, runQueryTool, type QueryModelIdentity, type QueryToolArtifacts } from "../automation/automationApi";
|
|
|
|
| 336 |
* Β· `reference/ChatGPT 1.png` β the CONVERSATION: one centred column, the question as a bubble
|
| 337 |
* on the right, the answer as plain flowing text with no label and no bubble, the composer
|
| 338 |
* pinned to the bottom with its controls INSIDE the field.
|
| 339 |
+
* Β· `reference/Glean 1.png` β the SOURCES: it USED to be a row of chips under the composer,
|
| 340 |
+
* one per database, each toggling whether the assistant could read it. β RETIRED by owner
|
| 341 |
+
* instruction 12 / R11 (W47-T22): the assistant reads every database the caller can access, so
|
| 342 |
+
* there is nothing to pick. Glean's shape answered a question this product no longer asks.
|
| 343 |
* Β· `reference/Airtable AI 1.png` β the NAVIGATION: "New chat" at the top of a left panel, the
|
| 344 |
* thread list under it, and a centred "How can I help?" when the thread is empty.
|
| 345 |
*
|
| 346 |
* β WHAT IS DELIBERATELY NOT COPIED: ChatGPT's dark canvas and Glean's vendor logos. The palette
|
| 347 |
* is Loopable's own (`DESIGN.md`, and the font-token rule is gated app-wide over every CSS file
|
| 348 |
+
* in this tree), because a brand logo for someone else's product is what those references have and
|
|
|
|
| 349 |
* this product's databases are not brands. "Exactly like" is about the interaction shape.
|
| 350 |
*
|
| 351 |
* β AND THE TOOL BOUNDARY IS NARROWER THAN THE SENTENCE "the chatbot can basically call the tools
|
|
|
|
| 356 |
export default function AssistantPage({ granted }: AssistantPageProps) {
|
| 357 |
const [index, setIndex] = useState<QueryIndex>(initialIndex);
|
| 358 |
const [activeThread, setActiveThread] = useState("");
|
|
|
|
| 359 |
const [target, setTarget] = useState("");
|
| 360 |
const [model, setModel] = useState("auto");
|
| 361 |
const [question, setQuestion] = useState("");
|
|
|
|
| 382 |
const databases = useMemo(() => databaseEntries(granted).filter((entry) => entry.kind !== "group"), [granted]);
|
| 383 |
const labels = useMemo(() => new Map(databases.map((entry) => [entry.key, entry.label])), [databases]);
|
| 384 |
/**
|
| 385 |
+
* ββ INSTRUCTION 12 / R11 β NO SOURCE PICKER AT ALL. Owner: *"the Assistant should always have
|
| 386 |
+
* access to all database that the user have access to. So it doesn't need the database clicks
|
| 387 |
+
* under the chat."* The chip row and the sentence explaining why some chips were grey are both
|
| 388 |
+
* gone; the limit they explained is closed in the read boundary, not narrated to the reader.
|
| 389 |
+
* `databases` above IS the answer to "what may the assistant read", and the server wall
|
| 390 |
+
* (`deps.py::assistant_source_status`) remains the authority on every request.
|
|
|
|
|
|
|
| 391 |
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 392 |
const messages = index.messages.filter((row) => row.threadId === activeThread);
|
| 393 |
const viewById = useMemo(() => new Map(index.views.map((view) => [view.id, view])), [index.views]);
|
| 394 |
|
|
|
|
| 420 |
return () => controller.abort();
|
| 421 |
}, []);
|
| 422 |
useEffect(() => () => openCancel.current?.(), []);
|
| 423 |
+
// There is no picker any more, so the target DEFAULTS to the first database the caller can
|
| 424 |
+
// reach: without this the composer would open with no target and a Send button nothing enables.
|
| 425 |
useEffect(() => {
|
| 426 |
const permitted = databases.map((entry) => entry.key);
|
| 427 |
+
setTarget((current) => permitted.includes(current) ? current : databases[0]?.key ?? "");
|
|
|
|
| 428 |
}, [databases]);
|
| 429 |
+
// A resume token is bound to the database that produced it. Changing the target invalidates the
|
| 430 |
+
// clarification instead of replaying the token against a different database.
|
| 431 |
useEffect(() => {
|
| 432 |
+
if (alignment && alignment.database !== target) {
|
| 433 |
setAlignment(null);
|
| 434 |
setAlignmentFields([]);
|
| 435 |
}
|
| 436 |
+
}, [alignment, target]);
|
| 437 |
// The conversation reads bottom-up, like every chat the owner named.
|
| 438 |
useEffect(() => { foot.current?.scrollIntoView({ block: "end" }); }, [messages.length, busy]);
|
| 439 |
|
|
|
|
| 511 |
setActiveThread(""); setQuestion(""); setProblem("");
|
| 512 |
}, []);
|
| 513 |
|
| 514 |
+
/** Opening a past chat restores the database it ran against and the model it ran with (R6). */
|
| 515 |
const openThread = useCallback((id: string) => {
|
| 516 |
setActiveThread(id); setProblem("");
|
| 517 |
const row = index.threads.find((thread) => thread.id === id);
|
| 518 |
if (!row) return;
|
| 519 |
const permitted = databases.map((entry) => entry.key);
|
| 520 |
+
const restored = (row.sources || []).find((key) => permitted.includes(key));
|
| 521 |
+
if (restored) setTarget(restored);
|
| 522 |
if (row.model && index.models.includes(row.model) && !modelBlocked(row.model)) setModel(row.model);
|
| 523 |
}, [databases, index.models, index.threads, modelBlocked]);
|
| 524 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 525 |
/**
|
| 526 |
* ββ R16 β ENTER GOES TO THE CHAT, NOT TO A WAIT. Owner: *"Pressing enter goes immediately to
|
| 527 |
* the chat view showing that it is loading; there is a thinking animation."*
|
|
|
|
| 539 |
const ask = useCallback(async (approvedFields?: string[]) => {
|
| 540 |
const text = approvedFields && alignment ? alignment.prompt : question.trim();
|
| 541 |
const database = approvedFields && alignment ? alignment.database : target;
|
| 542 |
+
if (!text || !database || busy) return;
|
| 543 |
setBusy(true); setProblem("");
|
| 544 |
let governed: Awaited<ReturnType<typeof runQueryTool>>;
|
| 545 |
try {
|
|
|
|
| 559 |
const optimistic: QueryMessage = {
|
| 560 |
id: pendingId, threadId: activeThread, role: "user", content: text,
|
| 561 |
createdAt: new Date().toISOString(), targetDatabase: database,
|
| 562 |
+
sources: [database], requestedModel: model,
|
| 563 |
};
|
| 564 |
const withoutPending = (rows: QueryMessage[]) => rows.filter((row) => row.id !== pendingId);
|
| 565 |
setQuestion("");
|
| 566 |
setIndex((current) => ({ ...current, messages: [...current.messages, optimistic] }));
|
| 567 |
+
// β THE TARGET, ALONE. `routes_query.py::_sources` runs EVERY key in this array through the
|
| 568 |
+
// read scope with no try/except, so one refusal kills the whole request; and the model is only
|
| 569 |
+
// ever handed the target's snapshot anyway. A wider array buys nothing and breaks the turn.
|
| 570 |
+
const result = await submitChat({ question: text, database, sources: [database],
|
| 571 |
...(activeThread ? { threadId: activeThread } : {}), model });
|
| 572 |
setBusy(false);
|
| 573 |
if (!result.ok) {
|
|
|
|
| 587 |
views: result.value.view ? [result.value.view, ...current.views.filter((row) => row.id !== result.value.view?.id)] : current.views,
|
| 588 |
citations: [...current.citations, ...result.value.citations],
|
| 589 |
}));
|
| 590 |
+
}, [activeThread, alignment, busy, model, question, target]);
|
| 591 |
|
| 592 |
/** β The chat goes; the views it built STAY (they live in Query). Two-click, in the row. */
|
| 593 |
const removeThread = useCallback(async (id: string) => {
|
|
|
|
| 642 |
className="as-prompt"
|
| 643 |
value={question}
|
| 644 |
rows={1}
|
| 645 |
+
placeholder={target ? `Ask about ${labels.get(target) || target}β¦` : "Ask about your dataβ¦"}
|
| 646 |
aria-label="Ask the assistant"
|
| 647 |
onChange={(event) => setQuestion(event.currentTarget.value)}
|
| 648 |
onKeyDown={(event) => {
|
|
|
|
| 669 |
</select>
|
| 670 |
</label>
|
| 671 |
{/* β ONLY WHEN THE ANSWER IS AMBIGUOUS. Every generated view names ONE database (R3);
|
| 672 |
+
with a single database reachable that database is not a question, so asking it would
|
| 673 |
+
be chrome for its own sake. This is now the ONLY database control on the surface. */}
|
| 674 |
+
{databases.length > 1 ? (
|
| 675 |
<label className="as-pick">
|
| 676 |
<span className="as-pick-label">Build on</span>
|
| 677 |
<select className="as-pick-select" value={target} aria-label="Target database"
|
| 678 |
onChange={(event) => setTarget(event.currentTarget.value)}>
|
| 679 |
+
{databases.map((entry) => (
|
| 680 |
+
<option key={entry.key} value={entry.key}>{labels.get(entry.key) || entry.key}</option>
|
| 681 |
+
))}
|
| 682 |
</select>
|
| 683 |
</label>
|
| 684 |
) : null}
|
|
|
|
| 690 |
</button>
|
| 691 |
</div>
|
| 692 |
</div>
|
| 693 |
+
{/* No source row: the assistant reads every database the caller can reach. What remains is
|
| 694 |
+
the one case the reader still has to be told about, which is having none at all. */}
|
| 695 |
+
{databases.length === 0 && loaded ? (
|
| 696 |
+
<div className="as-chips">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 697 |
<p className="as-chips-empty">No databases are shared with your account yet.</p>
|
| 698 |
+
</div>
|
| 699 |
+
) : null}
|
| 700 |
</div>
|
| 701 |
);
|
| 702 |
|
web/src/automation/AutomationDetail.tsx
CHANGED
|
@@ -20,7 +20,7 @@
|
|
| 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 |
// β WAVE 34 Β· W34-T41/T42 (R17) β the Chat view. A STATIC import, deliberately, unlike
|
|
@@ -96,6 +96,73 @@ import "../styles/wave45/agent-operator.css";
|
|
| 96 |
than relying on order alone. See [[a-lane-stylesheet-cannot-override-index-css]].
|
| 97 |
*/
|
| 98 |
import "../styles/wave46/schema-viewer.css";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
interface Props {
|
| 101 |
automation: Automation;
|
|
@@ -395,7 +462,19 @@ export default function AutomationDetail({
|
|
| 395 |
β THE DEFAULT IS STILL `properties`. `openTab` is the inbox's one-shot request and it names
|
| 396 |
`runs` alone; a harness file is never what a notification is about.
|
| 397 |
*/
|
| 398 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 399 |
openTab === "runs" ? "runs" : "properties");
|
| 400 |
/**
|
| 401 |
* The switch, drawn in BOTH panel heads so it does not move when the panel does.
|
|
@@ -476,6 +555,14 @@ export default function AutomationDetail({
|
|
| 476 |
*/
|
| 477 |
const workflowStorageKey = (id: string) => `aios-agent-workflow-${id}`;
|
| 478 |
const [governanceDatabase, setGovernanceDatabase] = useState("");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 479 |
useEffect(() => {
|
| 480 |
if (automation.system) { setAgentContract(null); return; }
|
| 481 |
const controller = new AbortController();
|
|
@@ -530,9 +617,25 @@ export default function AutomationDetail({
|
|
| 530 |
setAgentContract(agent); setActiveWorkflow(workflow.id); setView("canvas");
|
| 531 |
} catch (error) { setProblem(error instanceof Error ? error.message : "Workflow could not be created."); }
|
| 532 |
};
|
| 533 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 534 |
if (!agentContract) return;
|
| 535 |
-
const database = governanceDatabase;
|
| 536 |
const existing = agentContract.capabilities.workflows;
|
| 537 |
const workflowGrants = { ...(existing[activeWorkflow] || {}) };
|
| 538 |
if (nextGrant && database) workflowGrants[database] = nextGrant;
|
|
@@ -638,10 +741,13 @@ export default function AutomationDetail({
|
|
| 638 |
switch to the left of this strip, not a member of it, and that is what the ruling
|
| 639 |
describes rather than contradicts: hiding this rail is what gives "the full Chat
|
| 640 |
interface" (owner item 3), so a Chat that lived INSIDE the rail would disappear with it.
|
| 641 |
-
Read left to right across the head, the four words are the ruling's four words.
|
|
|
|
|
|
|
| 642 |
{([["properties", "Properties"],
|
| 643 |
...(automation.kind === "field_agent" ? [] : [["harness", "Harness"]] as const),
|
| 644 |
-
["runs", "
|
|
|
|
| 645 |
<button
|
| 646 |
key={k}
|
| 647 |
type="button"
|
|
@@ -711,6 +817,22 @@ export default function AutomationDetail({
|
|
| 711 |
|
| 712 |
const table = tables.find((t) => t.key === targetTable) || null;
|
| 713 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 714 |
/** ITEM 22 / D-70 / R12 β may Run be pressed, and what does it say if not. One definition,
|
| 715 |
* shared with the Builder's own Run button (`runBlock`). */
|
| 716 |
const runState = runBlock(automation);
|
|
@@ -1897,34 +2019,17 @@ export default function AutomationDetail({
|
|
| 1897 |
}}>{agentContract.sharing.visibility === "private" ? "Share agent" : "Make private"}</button>
|
| 1898 |
</>
|
| 1899 |
) : null}
|
| 1900 |
-
{
|
| 1901 |
-
|
| 1902 |
-
|
| 1903 |
-
|
| 1904 |
-
|
| 1905 |
-
|
| 1906 |
-
|
| 1907 |
-
|
| 1908 |
-
|
| 1909 |
-
|
| 1910 |
-
|
| 1911 |
-
<span className={"w45-chip " + (grant ? "is-on" : "is-off")}>{grant ? `Read ${String(grant.read)} Β· ${grant.mode}` : "Not granted"}</span>
|
| 1912 |
-
<div className="w45-chip-row" aria-label="Execution mode">
|
| 1913 |
-
{(["preview", "autonomous"] as const).map((mode) => <button type="button" className="w45-quiet" key={mode}
|
| 1914 |
-
aria-pressed={grant?.mode === mode} onClick={() => void saveGovernance({ ...editable, mode })}>{mode}</button>)}
|
| 1915 |
-
</div>
|
| 1916 |
-
{operations.map((operation) => <div className="w45-field-grants" key={operation}>
|
| 1917 |
-
<strong>{operation}</strong>
|
| 1918 |
-
{fields.map((field) => <label key={field.key}><input type="checkbox" checked={editable[operation].includes(field.key)}
|
| 1919 |
-
onChange={(event) => {
|
| 1920 |
-
const selected = event.currentTarget.checked
|
| 1921 |
-
? Array.from(new Set([...editable[operation], field.key]))
|
| 1922 |
-
: editable[operation].filter((key) => key !== field.key);
|
| 1923 |
-
void saveGovernance({ ...editable, [operation]: selected });
|
| 1924 |
-
}} />{field.label}</label>)}
|
| 1925 |
-
</div>)}
|
| 1926 |
-
</fieldset>;
|
| 1927 |
-
})() : null}
|
| 1928 |
</div>
|
| 1929 |
) : null}
|
| 1930 |
<div className={"auto-work" + (railShut ? " autod-folded" : "")}>
|
|
@@ -2094,9 +2199,13 @@ export default function AutomationDetail({
|
|
| 2094 |
Synthetic field agents do not expose a Harness. Manage the source field instead.
|
| 2095 |
</p>
|
| 2096 |
) : null}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2097 |
<aside
|
| 2098 |
className="auto-panel is-appearing"
|
| 2099 |
-
aria-label="
|
| 2100 |
hidden={aside !== "runs"}
|
| 2101 |
>
|
| 2102 |
<>
|
|
@@ -2221,6 +2330,243 @@ export default function AutomationDetail({
|
|
| 2221 |
</p>
|
| 2222 |
</>
|
| 2223 |
</aside>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2224 |
{/*
|
| 2225 |
ββ W36-T32 β THE FOLD MUST SURVIVE THE FOLD. Hiding all three panels also hides the
|
| 2226 |
only control that brings them back, which is "minimizing gets stuck and cannot be
|
|
|
|
| 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, useMemo, useState } from "react";
|
| 24 |
|
| 25 |
import AutomationBuilder from "./AutomationBuilder";
|
| 26 |
// β WAVE 34 Β· W34-T41/T42 (R17) β the Chat view. A STATIC import, deliberately, unlike
|
|
|
|
| 96 |
than relying on order alone. See [[a-lane-stylesheet-cannot-override-index-css]].
|
| 97 |
*/
|
| 98 |
import "../styles/wave46/schema-viewer.css";
|
| 99 |
+
/*
|
| 100 |
+
β W47-T20 β THE ACCESS TAB BORROWS THE MANAGE USER PANEL'S CLASSES, SO IT MUST BORROW ITS SHEET.
|
| 101 |
+
`set-card`, `set-check`, `set-perm-panels`, `set-perm-pop`, `set-h4` and `set-help` are in
|
| 102 |
+
`index.css` and arrive with the shell, but `set-perm-headend`, `set-perm-disclose` and
|
| 103 |
+
`set-perm-edit` live ONLY here. This editor is a `lazy()` chunk and the settings modal is a
|
| 104 |
+
different one, so without this line those three rules reach the Access tab only when somebody
|
| 105 |
+
has already opened Settings in the same session β a panel that is styled or not depending on
|
| 106 |
+
where the reader has been, with nothing red anywhere. CSS imports are idempotent and every
|
| 107 |
+
selector in the sheet is a `set-*` class, so nothing on this surface changes.
|
| 108 |
+
β THE SHEET ITSELF IS NOT EDITED, and this ticket writes no class that has no rule.
|
| 109 |
+
*/
|
| 110 |
+
import "../settings/perms.css";
|
| 111 |
+
/*
|
| 112 |
+
ββ W47-T21 / C4 β THE SAME TWO PANELS THE MANAGE USER ROOM MOUNTS, FROM THE SAME KIT.
|
| 113 |
+
`settings/ModulePermsList.tsx` mounts exactly this pair inside `.set-perm-panels`, each in a
|
| 114 |
+
bare `div.cg-pop.set-perm-pop`, and the Access tab is now that room's shape for an agent. C4:
|
| 115 |
+
*"a reader must not have to learn two permission vocabularies."* A locally built condition
|
| 116 |
+
editor would be a second one, and it would drift within the wave.
|
| 117 |
+
β NEITHER PANEL FILE IS EDITED HERE. They are owned by another lane; this is a MOUNT.
|
| 118 |
+
*/
|
| 119 |
+
import { FilterBuilderPanel, FieldsHidePanel } from "../filter-kit";
|
| 120 |
+
import { identityKey } from "../settings/permsModel";
|
| 121 |
+
import type { PermsField } from "../settings/permsModel";
|
| 122 |
+
import { TYPE_LABELS } from "../customer-grid/iconShapes";
|
| 123 |
+
import type { FieldType, FilterTree } from "../customer-grid/types";
|
| 124 |
+
|
| 125 |
+
/**
|
| 126 |
+
* β W47-T21 β ONE `UserTable` COLUMN AS THE FILTER KIT READS IT.
|
| 127 |
+
*
|
| 128 |
+
* The two shapes are genuinely different and the gap is two keys: `UserTable.fields` is
|
| 129 |
+
* `{key, label, type: string, automation?}`, while `customer-grid/types::Field` requires `type`
|
| 130 |
+
* to be a `FieldType` LITERAL and requires `source`. So a small adapter is unavoidable; what it
|
| 131 |
+
* must not do is invent anything.
|
| 132 |
+
*
|
| 133 |
+
* β THE TYPE IS CHECKED AGAINST `TYPE_LABELS`, NOT CAST, AND THAT IS THE WHOLE CARE IN THIS
|
| 134 |
+
* FUNCTION. `TYPE_LABELS` is declared `Record<FieldType, string>`, so its KEYS are the union
|
| 135 |
+
* itself and the membership test cannot fall out of date with it. A bare `as FieldType` would
|
| 136 |
+
* hand the condition builder a type it has no operators for, and the picker would offer a
|
| 137 |
+
* comparison the server's own evaluator (`harness/filter_eval`) then refuses. β THE FALLBACK IS
|
| 138 |
+
* `text`, which is the widest set of operators and therefore the one that cannot claim a
|
| 139 |
+
* comparison the column does not support; a column arriving with an unknown type is a schema we
|
| 140 |
+
* have not met, not a reason to render nothing.
|
| 141 |
+
*
|
| 142 |
+
* β `source: "overlay"` IS A FACT, NOT A DEFAULT. Every `ut_*` database's cells are overlay
|
| 143 |
+
* stored; `odoo` is the connector-backed grids' value and no column reachable from this list
|
| 144 |
+
* has it.
|
| 145 |
+
*/
|
| 146 |
+
function asPermsField(field: UserTable["fields"][number]): PermsField {
|
| 147 |
+
const known = Object.prototype.hasOwnProperty.call(TYPE_LABELS, field.type);
|
| 148 |
+
return {
|
| 149 |
+
key: field.key,
|
| 150 |
+
label: field.label,
|
| 151 |
+
type: (known ? field.type : "text") as FieldType,
|
| 152 |
+
source: "overlay",
|
| 153 |
+
};
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
/**
|
| 157 |
+
* The four write verbs, worded for a heading. The KEYS are the grant's own vocabulary and are
|
| 158 |
+
* never re-spelled; this is only their sentence case, because a raw key is not a heading.
|
| 159 |
+
*/
|
| 160 |
+
const OPERATION_LABELS: Record<"create" | "update" | "overwrite" | "delete", string> = {
|
| 161 |
+
create: "Create",
|
| 162 |
+
update: "Update",
|
| 163 |
+
overwrite: "Overwrite",
|
| 164 |
+
delete: "Delete",
|
| 165 |
+
};
|
| 166 |
|
| 167 |
interface Props {
|
| 168 |
automation: Automation;
|
|
|
|
| 462 |
β THE DEFAULT IS STILL `properties`. `openTab` is the inbox's one-shot request and it names
|
| 463 |
`runs` alone; a harness file is never what a notification is about.
|
| 464 |
*/
|
| 465 |
+
/*
|
| 466 |
+
ββ W47-T20 (owner instruction 10) β "access" JOINS THE SAME SWITCH, and "Run history" is
|
| 467 |
+
relabelled "History". Owner: *"It should be located under the same toggle as
|
| 468 |
+
'Properties/Harness/Run history/', just call Run history, History, and add it there as
|
| 469 |
+
Access."* A FOURTH VALUE of one setting, exactly as "harness" was a third: the Capabilities
|
| 470 |
+
fieldset used to hang off the workflow bar above the canvas, which is what made it read as a
|
| 471 |
+
checkbox matrix bolted to a control strip.
|
| 472 |
+
β THE `runs` KEY DOES NOT MOVE. Only its LABEL changes; `openTab` is the inbox's one-shot
|
| 473 |
+
request and it names `runs` on the wire, so renaming the key would break a notification's
|
| 474 |
+
deep link to say a word differently on screen.
|
| 475 |
+
β THE DEFAULT IS STILL `properties`, for the reason the notes above give.
|
| 476 |
+
*/
|
| 477 |
+
const [aside, setAside] = useState<"properties" | "harness" | "runs" | "access">(
|
| 478 |
openTab === "runs" ? "runs" : "properties");
|
| 479 |
/**
|
| 480 |
* The switch, drawn in BOTH panel heads so it does not move when the panel does.
|
|
|
|
| 555 |
*/
|
| 556 |
const workflowStorageKey = (id: string) => `aios-agent-workflow-${id}`;
|
| 557 |
const [governanceDatabase, setGovernanceDatabase] = useState("");
|
| 558 |
+
/*
|
| 559 |
+
β W47-T20 β WHICH DATABASE ROW IS OPEN in the Access tab, single-valued for the reason
|
| 560 |
+
`ModulePermsList`'s own `openDetail` is: the complaint about the old fieldset was a wall of
|
| 561 |
+
checkboxes, and an accordion cannot become one by accumulation.
|
| 562 |
+
β IT IS NOT THE SAME FACT AS `governanceDatabase`, which is what `saveGovernance` writes
|
| 563 |
+
THROUGH; `null` here means every row is collapsed, and that is not a database.
|
| 564 |
+
*/
|
| 565 |
+
const [accessOpen, setAccessOpen] = useState<string | null>(null);
|
| 566 |
useEffect(() => {
|
| 567 |
if (automation.system) { setAgentContract(null); return; }
|
| 568 |
const controller = new AbortController();
|
|
|
|
| 617 |
setAgentContract(agent); setActiveWorkflow(workflow.id); setView("canvas");
|
| 618 |
} catch (error) { setProblem(error instanceof Error ? error.message : "Workflow could not be created."); }
|
| 619 |
};
|
| 620 |
+
/**
|
| 621 |
+
* β W47-T20 β `forDatabase` IS THE ONE ADDITION, AND IT CLOSES A REAL HAZARD RATHER THAN
|
| 622 |
+
* TIDYING ONE.
|
| 623 |
+
*
|
| 624 |
+
* The Access tab draws EVERY database as its own row (owner instruction 10: an agent's access
|
| 625 |
+
* is read the way a user's is), so a write can now originate from a row that is not the one
|
| 626 |
+
* held in `governanceDatabase`. `setGovernanceDatabase(key)` followed by a save in the SAME
|
| 627 |
+
* handler does not help: this function is re-created each render and closes over the value of
|
| 628 |
+
* that render, so the state set a microsecond earlier is not the value it reads. The result
|
| 629 |
+
* would be a grant stored against the previously opened database, with the checkbox the person
|
| 630 |
+
* clicked drawn correctly and every gate green.
|
| 631 |
+
*
|
| 632 |
+
* β OPTIONAL, WITH THE OLD READ AS ITS DEFAULT, so every existing call site is unchanged: the
|
| 633 |
+
* disclosed body's own writes are already gated on `governanceDatabase === table.key` and pass
|
| 634 |
+
* nothing. Only the row head, which sits OUTSIDE that gate, names its database.
|
| 635 |
+
*/
|
| 636 |
+
const saveGovernance = async (nextGrant?: AgentDatabaseGrant, forDatabase?: string) => {
|
| 637 |
if (!agentContract) return;
|
| 638 |
+
const database = forDatabase || governanceDatabase;
|
| 639 |
const existing = agentContract.capabilities.workflows;
|
| 640 |
const workflowGrants = { ...(existing[activeWorkflow] || {}) };
|
| 641 |
if (nextGrant && database) workflowGrants[database] = nextGrant;
|
|
|
|
| 741 |
switch to the left of this strip, not a member of it, and that is what the ruling
|
| 742 |
describes rather than contradicts: hiding this rail is what gives "the full Chat
|
| 743 |
interface" (owner item 3), so a Chat that lived INSIDE the rail would disappear with it.
|
| 744 |
+
Read left to right across the head, the four words are the ruling's four words.
|
| 745 |
+
β W47-T20 amends that order with the owner's own later words (instruction 10): the third
|
| 746 |
+
arm is now "History" and a fourth, "Access", follows it. */}
|
| 747 |
{([["properties", "Properties"],
|
| 748 |
...(automation.kind === "field_agent" ? [] : [["harness", "Harness"]] as const),
|
| 749 |
+
["runs", "History"],
|
| 750 |
+
["access", "Access"]] as const).map(([k, label]) => (
|
| 751 |
<button
|
| 752 |
key={k}
|
| 753 |
type="button"
|
|
|
|
| 817 |
|
| 818 |
const table = tables.find((t) => t.key === targetTable) || null;
|
| 819 |
|
| 820 |
+
/**
|
| 821 |
+
* β W47-T21 β EACH GOVERNED DATABASE'S COLUMNS IN THE FILTER KIT'S SHAPE, MEMOISED.
|
| 822 |
+
*
|
| 823 |
+
* β THE MEMO IS NOT A PERFORMANCE TWEAK, IT IS AN IDENTITY ONE. `FilterBuilderPanel` holds
|
| 824 |
+
* DRAFT state for the rule a person is part way through building; handing it a freshly built
|
| 825 |
+
* `fields` array on every render is a new prop identity on every keystroke elsewhere in this
|
| 826 |
+
* component, which is exactly the shape that makes a builder panel reset itself while somebody
|
| 827 |
+
* is typing in it. Keyed by database because a row is drawn per database and the panel is
|
| 828 |
+
* mounted inside that row.
|
| 829 |
+
*/
|
| 830 |
+
const permsFieldsByTable = useMemo(() => {
|
| 831 |
+
const out: Record<string, PermsField[]> = {};
|
| 832 |
+
for (const row of tables) out[row.key] = (row.fields || []).map(asPermsField);
|
| 833 |
+
return out;
|
| 834 |
+
}, [tables]);
|
| 835 |
+
|
| 836 |
/** ITEM 22 / D-70 / R12 β may Run be pressed, and what does it say if not. One definition,
|
| 837 |
* shared with the Builder's own Run button (`runBlock`). */
|
| 838 |
const runState = runBlock(automation);
|
|
|
|
| 2019 |
}}>{agentContract.sharing.visibility === "private" ? "Share agent" : "Make private"}</button>
|
| 2020 |
</>
|
| 2021 |
) : null}
|
| 2022 |
+
{/*
|
| 2023 |
+
ββ W47-T20 (owner instruction 10) β THE CAPABILITIES FIELDSET IS GONE FROM THIS BAR.
|
| 2024 |
+
Owner, on `reference/ERROR 16.png`: *"the Capabilities section under Agent module, its
|
| 2025 |
+
really bad looking."* It was a `<fieldset>` hanging off the end of a one-line control
|
| 2026 |
+
strip, so a database picker plus four rows of every field in that database were laid
|
| 2027 |
+
out by `.w45-workflow-bar`'s `display: flex; align-items: center` β a matrix wedged
|
| 2028 |
+
into a row of buttons. It now lives in the Access tab of the right-hand rail, where
|
| 2029 |
+
the other three panes live, and it is drawn as the Manage User access list.
|
| 2030 |
+
β THE BAR KEEPS ITS OWN JOB: choose a workflow, add one, share the agent. Nothing
|
| 2031 |
+
about the grant shape moved with the JSX; see the Access aside below.
|
| 2032 |
+
*/}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2033 |
</div>
|
| 2034 |
) : null}
|
| 2035 |
<div className={"auto-work" + (railShut ? " autod-folded" : "")}>
|
|
|
|
| 2199 |
Synthetic field agents do not expose a Harness. Manage the source field instead.
|
| 2200 |
</p>
|
| 2201 |
) : null}
|
| 2202 |
+
{/* β W47-T20 β the LANDMARK is renamed with the tab (owner instruction 10: *"just call
|
| 2203 |
+
Run history, History"*). A tab reading "History" beside a landmark announced as "Run
|
| 2204 |
+
history" is the same pane wearing two names, which is exactly what a screen reader
|
| 2205 |
+
user has no way to reconcile. The `runs` KEY is untouched. */}
|
| 2206 |
<aside
|
| 2207 |
className="auto-panel is-appearing"
|
| 2208 |
+
aria-label="History"
|
| 2209 |
hidden={aside !== "runs"}
|
| 2210 |
>
|
| 2211 |
<>
|
|
|
|
| 2330 |
</p>
|
| 2331 |
</>
|
| 2332 |
</aside>
|
| 2333 |
+
{/*
|
| 2334 |
+
ββ W47-T20 (owner instruction 10) β ACCESS, AND IT IS THE MANAGE USER PANEL'S SHAPE.
|
| 2335 |
+
Owner: *"this access should be the same UI/UX as the Manage User access, where we can
|
| 2336 |
+
think of each agent as a user access, we can give it filter of data it can see,
|
| 2337 |
+
database it can see, and the Fields in that database. But this time We have a bigger
|
| 2338 |
+
umbrella, not just see, but edit/update/overwrite/delete."*
|
| 2339 |
+
|
| 2340 |
+
β SO THE DATABASE PICKER IS GONE AND A LIST TOOK ITS PLACE. `<label>Database<select>`
|
| 2341 |
+
is what made the old fieldset read as a matrix bolted to one row: it showed the grants
|
| 2342 |
+
of exactly one database and gave no way to see that any other database had any. Manage
|
| 2343 |
+
User answers "what may this account reach" with one card per database and a one-line
|
| 2344 |
+
summary on each, which is the question an agent's access is now asked in the same
|
| 2345 |
+
words. Every class below already has a rule (`ModulePermsList.tsx` renders the same
|
| 2346 |
+
anatomy); this ticket writes no CSS.
|
| 2347 |
+
|
| 2348 |
+
β UNMOUNTED WHEN HIDDEN, like Harness and the run log and unlike Properties. The
|
| 2349 |
+
grants are read off `agentContract`, which is fetched per agent, and a pane kept alive
|
| 2350 |
+
across a switch would paint the previous agent's capabilities as editable checkboxes.
|
| 2351 |
+
Properties keeps a half-typed name and must stay mounted; nothing here is typed.
|
| 2352 |
+
|
| 2353 |
+
β EVERY VALUE IS DERIVED PER ROW, from `table.key`, NEVER from `governanceDatabase`.
|
| 2354 |
+
The fieldset this replaces had one database and could read the single state variable;
|
| 2355 |
+
a list cannot, and reading it would make every row report the open row's grant while
|
| 2356 |
+
looking perfectly correct on a one-database tenant.
|
| 2357 |
+
|
| 2358 |
+
β THE SEAM FOR W47-T21 is `.set-perm-panels` below: the row filter and the hidden
|
| 2359 |
+
fields list are two more `div.cg-pop.set-perm-pop` children of that same container,
|
| 2360 |
+
appended after the verb blocks, with no change to anything here.
|
| 2361 |
+
*/}
|
| 2362 |
+
<aside
|
| 2363 |
+
className="auto-panel is-appearing"
|
| 2364 |
+
aria-label="Access"
|
| 2365 |
+
hidden={aside !== "access"}
|
| 2366 |
+
>
|
| 2367 |
+
<div className="auto-panel-head">
|
| 2368 |
+
{panelTabs}
|
| 2369 |
+
</div>
|
| 2370 |
+
{aside === "access" ? (
|
| 2371 |
+
!agentContract ? (
|
| 2372 |
+
<p className="set-help">Access opens once this agent's contract has loaded.</p>
|
| 2373 |
+
) : !activeWorkflow ? (
|
| 2374 |
+
<p className="set-help">Add a workflow to set what this agent may reach.</p>
|
| 2375 |
+
) : tables.length === 0 ? (
|
| 2376 |
+
<p className="set-help">No database is available to this agent yet.</p>
|
| 2377 |
+
) : (
|
| 2378 |
+
<div role="group" aria-label="Workflow database capabilities">
|
| 2379 |
+
{tables.map((governed) => {
|
| 2380 |
+
const grant = agentContract.capabilities.workflows[activeWorkflow]?.[governed.key];
|
| 2381 |
+
/* β W47-T21 β THE TWO NEW KEYS BELONG IN THIS FALLBACK, and leaving them out
|
| 2382 |
+
is not a cosmetic omission. Every write on this card spreads `editable`, so
|
| 2383 |
+
a card with NO STORED GRANT would otherwise post a grant object missing
|
| 2384 |
+
`filter` and `hiddenFields` entirely: `AgentGovernanceInput` would stop
|
| 2385 |
+
type-checking, and were it cast past that, the first click on any checkbox
|
| 2386 |
+
would store a grant the editor cannot round-trip. `null` and `[]` are the
|
| 2387 |
+
same "nothing declared" the server writes for an absent key. */
|
| 2388 |
+
const editable = grant || { mode: agentContract.capabilities.defaultMode, read: true,
|
| 2389 |
+
create: [], update: [], overwrite: [], delete: [],
|
| 2390 |
+
filter: null, hiddenFields: [] } as AgentDatabaseGrant;
|
| 2391 |
+
const fields = governed.fields || [];
|
| 2392 |
+
/* The same columns in the filter kit's shape. See `asPermsField`. */
|
| 2393 |
+
const permFields = permsFieldsByTable[governed.key] || [];
|
| 2394 |
+
const operations = ["create", "update", "overwrite", "delete"] as const;
|
| 2395 |
+
const held = operations.reduce((total, verb) => total + editable[verb].length, 0);
|
| 2396 |
+
/* β BOTH HALVES, and the second is the write guard rather than a tidiness
|
| 2397 |
+
point: the body's own saves pass no database, so they resolve through
|
| 2398 |
+
`governanceDatabase`, and rendering a body for a row that is not the one
|
| 2399 |
+
that state holds would write one database's checkbox onto another. */
|
| 2400 |
+
const shown = accessOpen === governed.key && governanceDatabase === governed.key;
|
| 2401 |
+
return (
|
| 2402 |
+
<section className="set-card set-perm-mod" key={governed.key}>
|
| 2403 |
+
<div className="set-perm-modhead">
|
| 2404 |
+
<label className="set-check set-perm-toggle">
|
| 2405 |
+
<input
|
| 2406 |
+
type="checkbox"
|
| 2407 |
+
checked={!!grant && grant.read}
|
| 2408 |
+
/* β NAMES ITS DATABASE. This control sits outside the disclosure
|
| 2409 |
+
gate above, so it is the one write that cannot rely on it. */
|
| 2410 |
+
onChange={(event) => void saveGovernance(
|
| 2411 |
+
{ ...editable, read: event.currentTarget.checked }, governed.key)}
|
| 2412 |
+
/>
|
| 2413 |
+
<span className="set-perm-modname">{governed.label}</span>
|
| 2414 |
+
</label>
|
| 2415 |
+
{/* β THE HEAD ROW CARRIES TWO CHILDREN, NOT THREE. `set-perm-headend`
|
| 2416 |
+
stays because `.set-perm-modhead`'s `space-between` in `index.css` is
|
| 2417 |
+
written for exactly two flex children, and it is the wrapper that
|
| 2418 |
+
keeps that true; what left is the summary, below. */}
|
| 2419 |
+
<span className="set-perm-headend">
|
| 2420 |
+
<button
|
| 2421 |
+
type="button"
|
| 2422 |
+
className="set-secondary set-perm-disclose"
|
| 2423 |
+
aria-expanded={shown}
|
| 2424 |
+
onClick={() => {
|
| 2425 |
+
setGovernanceDatabase(governed.key);
|
| 2426 |
+
setAccessOpen((open) => (open === governed.key ? null : governed.key));
|
| 2427 |
+
}}
|
| 2428 |
+
>
|
| 2429 |
+
{/* Short because the rail is 359px wide, not because the words were
|
| 2430 |
+
spare. "Mode and fields" plus `white-space: nowrap` on this button
|
| 2431 |
+
pushed ~39px of it past the panel's right edge. */}
|
| 2432 |
+
{shown ? "Hide" : "Fields"}
|
| 2433 |
+
</button>
|
| 2434 |
+
</span>
|
| 2435 |
+
</div>
|
| 2436 |
+
{/* β THE SUMMARY GETS ITS OWN LINE, AND IT IS A LAYOUT FACT NOT A TASTE ONE.
|
| 2437 |
+
`.set-perm-sum` carries `flex: none`, so inside the head it refused to
|
| 2438 |
+
shrink and forced the row to 384px of scrollWidth in a 359px rail. As a
|
| 2439 |
+
block child of `.set-card` that declaration is inert, the line gets the
|
| 2440 |
+
full card width, and the text wraps instead of clipping. It stays
|
| 2441 |
+
OUTSIDE the disclosure gate: a one-line restatement that only appears
|
| 2442 |
+
when the detail is already open restates nothing. */}
|
| 2443 |
+
<div className="set-perm-sum">
|
| 2444 |
+
{grant
|
| 2445 |
+
? `${grant.read ? "Read" : "No read"}, ${grant.mode}, `
|
| 2446 |
+
+ `${held} field grant${held === 1 ? "" : "s"}`
|
| 2447 |
+
: "No access"}
|
| 2448 |
+
</div>
|
| 2449 |
+
{shown ? (
|
| 2450 |
+
<>
|
| 2451 |
+
<div className="w45-chip-row" aria-label="Execution mode">
|
| 2452 |
+
{(["preview", "autonomous"] as const).map((mode) => (
|
| 2453 |
+
<button
|
| 2454 |
+
type="button"
|
| 2455 |
+
className="w45-quiet"
|
| 2456 |
+
key={mode}
|
| 2457 |
+
aria-pressed={editable.mode === mode}
|
| 2458 |
+
onClick={() => void saveGovernance({ ...editable, mode })}
|
| 2459 |
+
>
|
| 2460 |
+
{mode === "preview" ? "Preview" : "Autonomous"}
|
| 2461 |
+
</button>
|
| 2462 |
+
))}
|
| 2463 |
+
</div>
|
| 2464 |
+
<div className="set-perm-panels">
|
| 2465 |
+
{operations.map((operation) => (
|
| 2466 |
+
<div className="cg-pop set-perm-pop" key={operation}>
|
| 2467 |
+
<h4 className="set-h4">{OPERATION_LABELS[operation]}</h4>
|
| 2468 |
+
{fields.length === 0 ? (
|
| 2469 |
+
<p className="set-help">This database publishes no fields yet.</p>
|
| 2470 |
+
) : fields.map((field) => (
|
| 2471 |
+
<label className="set-check" key={field.key}>
|
| 2472 |
+
<input
|
| 2473 |
+
type="checkbox"
|
| 2474 |
+
checked={editable[operation].includes(field.key)}
|
| 2475 |
+
onChange={(event) => {
|
| 2476 |
+
const selected = event.currentTarget.checked
|
| 2477 |
+
? Array.from(new Set([...editable[operation], field.key]))
|
| 2478 |
+
: editable[operation].filter((key) => key !== field.key);
|
| 2479 |
+
void saveGovernance({ ...editable, [operation]: selected });
|
| 2480 |
+
}}
|
| 2481 |
+
/>
|
| 2482 |
+
<span>{field.label}</span>
|
| 2483 |
+
</label>
|
| 2484 |
+
))}
|
| 2485 |
+
</div>
|
| 2486 |
+
))}
|
| 2487 |
+
{/*
|
| 2488 |
+
ββ W47-T21 (owner instruction 10, ruling R3, contract C4) β THE
|
| 2489 |
+
ROW FILTER AND THE HIDDEN FIELDS, as the two `cg-pop set-perm-pop`
|
| 2490 |
+
siblings W47-T20 left the seam for. Owner: an agent is read the way
|
| 2491 |
+
a user's access is, *"we can give it filter of data it can see,
|
| 2492 |
+
database it can see, and the Fields in that database"* β so these
|
| 2493 |
+
are the SAME two panels the Manage User room mounts, in the same
|
| 2494 |
+
container, with the same classes. No new class, no CSS.
|
| 2495 |
+
|
| 2496 |
+
β GATED ON THERE BEING COLUMNS AT ALL, and deliberately with no
|
| 2497 |
+
sentence of its own: the verb blocks above already say "This
|
| 2498 |
+
database publishes no fields yet" once, and repeating it twice more
|
| 2499 |
+
would be the over-explaining an empty state is supposed to avoid.
|
| 2500 |
+
A condition builder over a schema-less database would offer an
|
| 2501 |
+
empty picker, which reads as broken rather than as empty.
|
| 2502 |
+
*/}
|
| 2503 |
+
{permFields.length > 0 ? (
|
| 2504 |
+
<>
|
| 2505 |
+
<div className="cg-pop set-perm-pop">
|
| 2506 |
+
<FilterBuilderPanel
|
| 2507 |
+
fields={permFields}
|
| 2508 |
+
/* β THE WHOLE TREE OR AN EMPTY ONE, never a bare node list.
|
| 2509 |
+
`{nodes: []}` is what this panel reads as "no conditions
|
| 2510 |
+
yet"; `null` is what the record stores for the same fact
|
| 2511 |
+
(C-PERM amendment 2, mirrored by `permsModel::setFilter`
|
| 2512 |
+
and by `_clean_agent_filter` on the server). */
|
| 2513 |
+
filters={editable.filter || { nodes: [] }}
|
| 2514 |
+
onChange={(next: FilterTree) => void saveGovernance(
|
| 2515 |
+
/* The collapse is `setFilter`'s, spelled here because
|
| 2516 |
+
this card writes the grant directly: an emptied builder
|
| 2517 |
+
stores "no filter", not "a filter that asks nothing" β
|
| 2518 |
+
and R3's non-claim is that removing the filter restores
|
| 2519 |
+
full access, which is what `null` means to the wall. */
|
| 2520 |
+
{ ...editable,
|
| 2521 |
+
filter: next.nodes.length ? next : null },
|
| 2522 |
+
governed.key)}
|
| 2523 |
+
/>
|
| 2524 |
+
</div>
|
| 2525 |
+
<div className="cg-pop set-perm-pop">
|
| 2526 |
+
<FieldsHidePanel
|
| 2527 |
+
fields={permFields}
|
| 2528 |
+
hidden={new Set(editable.hiddenFields)}
|
| 2529 |
+
onToggle={(key) => void saveGovernance(
|
| 2530 |
+
{ ...editable,
|
| 2531 |
+
hiddenFields: editable.hiddenFields.includes(key)
|
| 2532 |
+
? editable.hiddenFields.filter((k) => k !== key)
|
| 2533 |
+
: [...editable.hiddenFields, key] },
|
| 2534 |
+
governed.key)}
|
| 2535 |
+
/* β `lockedKey` IS NOT OPTIONAL HERE, whatever the prop
|
| 2536 |
+
says, and `ModulePermsList` carries the same warning for
|
| 2537 |
+
the same reason: absent, the panel locks nothing and one
|
| 2538 |
+
click on "Hide all" hides the record's own identity
|
| 2539 |
+
column. The server would accept it, because that key is a
|
| 2540 |
+
perfectly known field key, and the agent's faithful read
|
| 2541 |
+
would be a table of blank rows. */
|
| 2542 |
+
lockedKey={identityKey(permFields)}
|
| 2543 |
+
/* This IS the permissioning room for an agent, so the
|
| 2544 |
+
shared sections are off for the reason they are off in
|
| 2545 |
+
`ModulePermsList`: a permission is set on the database's
|
| 2546 |
+
own columns, not on somebody's personal ones. */
|
| 2547 |
+
sharedSections={false}
|
| 2548 |
+
onHideAll={() => void saveGovernance(
|
| 2549 |
+
{ ...editable,
|
| 2550 |
+
hiddenFields: permFields
|
| 2551 |
+
.map((f) => f.key)
|
| 2552 |
+
.filter((k) => k !== identityKey(permFields)) },
|
| 2553 |
+
governed.key)}
|
| 2554 |
+
onShowAll={() => void saveGovernance(
|
| 2555 |
+
{ ...editable, hiddenFields: [] }, governed.key)}
|
| 2556 |
+
/>
|
| 2557 |
+
</div>
|
| 2558 |
+
</>
|
| 2559 |
+
) : null}
|
| 2560 |
+
</div>
|
| 2561 |
+
</>
|
| 2562 |
+
) : null}
|
| 2563 |
+
</section>
|
| 2564 |
+
);
|
| 2565 |
+
})}
|
| 2566 |
+
</div>
|
| 2567 |
+
)
|
| 2568 |
+
) : null}
|
| 2569 |
+
</aside>
|
| 2570 |
{/*
|
| 2571 |
ββ W36-T32 β THE FOLD MUST SURVIVE THE FOLD. Hiding all three panels also hides the
|
| 2572 |
only control that brings them back, which is "minimizing gets stuck and cannot be
|
web/src/automation/automationApi.ts
CHANGED
|
@@ -22,6 +22,16 @@ import {
|
|
| 22 |
checkTenant,
|
| 23 |
signal,
|
| 24 |
} from "../apiContract";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
import type {
|
| 26 |
VoiceAgent,
|
| 27 |
VoiceAgentDraft,
|
|
@@ -2025,6 +2035,30 @@ export interface AgentDatabaseGrant {
|
|
| 2025 |
update: string[];
|
| 2026 |
overwrite: string[];
|
| 2027 |
delete: string[];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2028 |
}
|
| 2029 |
|
| 2030 |
export interface AgentSetupQuestion {
|
|
|
|
| 22 |
checkTenant,
|
| 23 |
signal,
|
| 24 |
} from "../apiContract";
|
| 25 |
+
/*
|
| 26 |
+
β W47-T21 / C4 β THE ONE EDGE INTO THE GRID TREE, AND IT IS `import type`, WHICH IS WHY IT IS
|
| 27 |
+
ALLOWED. This file's header says it imports `apiContract` "and nothing else", and the reason it
|
| 28 |
+
gives is a BUNDLE reason: the grid tree is an asset that also ships elsewhere and an automation
|
| 29 |
+
surface must not grow a runtime edge into it. A type-only import is erased by TypeScript before
|
| 30 |
+
emit, so no module edge exists at runtime and the stated hazard cannot occur. Re-declaring
|
| 31 |
+
`FilterTree` here instead would be the thing C4 forbids outright: a second spelling of one
|
| 32 |
+
permission vocabulary, free to drift from the one `permsModel.ts` and the filter kit both read.
|
| 33 |
+
*/
|
| 34 |
+
import type { FilterTree } from "../customer-grid/types";
|
| 35 |
import type {
|
| 36 |
VoiceAgent,
|
| 37 |
VoiceAgentDraft,
|
|
|
|
| 2035 |
update: string[];
|
| 2036 |
overwrite: string[];
|
| 2037 |
delete: string[];
|
| 2038 |
+
/**
|
| 2039 |
+
* ββ W47-T21 / CONTRACT C4 β THE ROW FILTER, IN `settings/permsModel.ts`'s OWN WORDS.
|
| 2040 |
+
*
|
| 2041 |
+
* C4: *"the agent grant is a superset of the user grant shape⦠a reader must not have to learn
|
| 2042 |
+
* two permission vocabularies."* So this is spelled exactly as `PermsEntry.filter` is spelled:
|
| 2043 |
+
* the WHOLE tree (`{conj?, nodes}`), never a bare node list, and `null` for "no filter". The
|
| 2044 |
+
* whole-tree rule is C-PERM amendment 2's and it is not stylistic: `[A, B]` under `or` means
|
| 2045 |
+
* something entirely different from `[A, B]` under `and`, and the loss is invisible in every
|
| 2046 |
+
* payload it passes through.
|
| 2047 |
+
*
|
| 2048 |
+
* β R3 β WHAT IT MEANS IS "THE WHOLE WORLD", NOT "THE DEFAULT VIEW". An agent may neither
|
| 2049 |
+
* READ nor WRITE a record outside it, and a Create that would land outside is refused with a
|
| 2050 |
+
* named reason (`automation_engine.AGENT_ROW_CREATE_REFUSAL`). That is why it belongs on the
|
| 2051 |
+
* GRANT beside the verb lists rather than on anything view-shaped.
|
| 2052 |
+
*/
|
| 2053 |
+
filter: FilterTree | null;
|
| 2054 |
+
/**
|
| 2055 |
+
* C4 β the field keys this agent never receives, same meaning and same name as
|
| 2056 |
+
* `PermsEntry.hiddenFields`: server-stripped from the wire rather than hidden in the client.
|
| 2057 |
+
* β The server strips BOTH the field list and the row payload at its one row-bearing agent
|
| 2058 |
+
* read door (`routes_automation.run_rows`); a client that filtered only what it renders would
|
| 2059 |
+
* leave the values sitting in the response.
|
| 2060 |
+
*/
|
| 2061 |
+
hiddenFields: string[];
|
| 2062 |
}
|
| 2063 |
|
| 2064 |
export interface AgentSetupQuestion {
|
web/src/customer-grid/CustomerGrid.tsx
CHANGED
|
@@ -473,6 +473,52 @@ type SavedApplication = {
|
|
| 473 |
/** C3 locks are present on the server projection, while the long-lived shared type remains
|
| 474 |
* deliberately backward-compatible. Keep that wire detail additive here rather than widening a
|
| 475 |
* cross-lane contract just to paint one property. */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 476 |
type LockedFilterRule = FilterRule & { locked?: boolean };
|
| 477 |
type LockedSortRule = SortRule & { locked?: boolean };
|
| 478 |
type ManagedRouteClause = {
|
|
@@ -3562,9 +3608,39 @@ function CustomerGridSurface({
|
|
| 3562 |
}).catch(() => undefined);
|
| 3563 |
return () => controller.abort();
|
| 3564 |
}, [applicationDatabase, applicationKind, applySavedApplication, config.application, dataPath?.application]);
|
|
|
|
|
|
|
| 3565 |
const [drawerBusy, setDrawerBusy] = useState(false);
|
| 3566 |
const [drawerError, setDrawerError] = useState("");
|
| 3567 |
const [sharedNote, setSharedNote] = useState("");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3568 |
const [notesMode, setNotesMode] = useState<"database" | "view">("database");
|
| 3569 |
const [historyRows, setHistoryRows] = useState<Array<Record<string, unknown>>>([]);
|
| 3570 |
const [historyRetention, setHistoryRetention] = useState<30 | 90>(30);
|
|
@@ -3572,6 +3648,7 @@ function CustomerGridSurface({
|
|
| 3572 |
useEffect(() => {
|
| 3573 |
if (!workspaceDrawer) return;
|
| 3574 |
const controller = new AbortController();
|
|
|
|
| 3575 |
setDrawerBusy(true); setDrawerError("");
|
| 3576 |
const noteViewQuery = notesMode === "view" ? `&viewId=${encodeURIComponent(activeViewId)}` : "";
|
| 3577 |
const userTableHistory = scope.startsWith("ut_");
|
|
@@ -3585,22 +3662,91 @@ function CustomerGridSurface({
|
|
| 3585 |
void fetch(url, { credentials: CREDENTIALS, signal: controller.signal }).then(async (response) => {
|
| 3586 |
const body = await response.json().catch(() => ({}));
|
| 3587 |
if (!response.ok) throw new Error(String(body?.detail?.message ?? body?.detail ?? "Could not load drawer"));
|
| 3588 |
-
if (workspaceDrawer === "notes")
|
| 3589 |
else setHistoryRows(Array.isArray(body?.events) ? body.events : Array.isArray(body?.history) ? body.history : []);
|
| 3590 |
}).catch((error: unknown) => { if (!controller.signal.aborted) setDrawerError(error instanceof Error ? error.message : "Could not load drawer"); })
|
| 3591 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3592 |
return () => controller.abort();
|
| 3593 |
}, [activeViewId, historyPid, historyRetention, notesMode, scope, workspaceDrawer]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3594 |
const saveSharedNote = useCallback(async () => {
|
| 3595 |
-
|
| 3596 |
try {
|
| 3597 |
const noteViewQuery = notesMode === "view" ? `&viewId=${encodeURIComponent(activeViewId)}` : "";
|
| 3598 |
const response = await fetch(`${API_V1}/grid/shared-note?scope=${encodeURIComponent(scope)}${noteViewQuery}`, { method: "PUT", credentials: CREDENTIALS, headers: { "Content-Type": "application/json" }, body: JSON.stringify({ body: sharedNote }) });
|
| 3599 |
const body = await response.json().catch(() => ({}));
|
| 3600 |
if (!response.ok) throw new Error(String(body?.detail?.message ?? body?.detail ?? "Could not save note"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3601 |
} catch (error) { setDrawerError(error instanceof Error ? error.message : "Could not save note"); }
|
| 3602 |
-
finally {
|
| 3603 |
-
}, [activeViewId, notesMode, scope, sharedNote]);
|
| 3604 |
const embeddedPropKeyRef = useRef(embeddedSelectedKey);
|
| 3605 |
useEffect(() => {
|
| 3606 |
if (!embeddedSelectable) {
|
|
@@ -8906,6 +9052,7 @@ function CustomerGridSurface({
|
|
| 8906 |
// row drove, moved to the toolbar so Related, Notes and Full screen read as one run.
|
| 8907 |
// Only this render supplies it, so the pivot toolbar shows no Notes button at all.
|
| 8908 |
notesOpen={workspaceDrawer === "notes"}
|
|
|
|
| 8909 |
onNotes={() => setWorkspaceDrawer((open) => (open === "notes" ? null : "notes"))}
|
| 8910 |
/>
|
| 8911 |
{/* β R11's SECOND ROW β live, on the pivoted database. It renders only once the pivot has
|
|
@@ -8913,7 +9060,7 @@ function CustomerGridSurface({
|
|
| 8913 |
not be wired yet: absent beats present-and-inert. A control row over a database whose
|
| 8914 |
columns never arrived would offer Hide fields, Filter, Sort and Group on nothing. */}
|
| 8915 |
{secondaryToolbar}
|
| 8916 |
-
{workspaceDrawer && <aside className="cg-workspace-drawer" aria-label={workspaceDrawer === "notes" ? "Notes" : "History"}><header><strong>{workspaceDrawer === "notes" ? "Notes" : "History"}</strong><button type="button" className="cg-icon-button" aria-label="Close drawer" onClick={() => setWorkspaceDrawer(null)}>Γ</button></header>{drawerBusy && <span className="lp-spin" role="status" aria-label="Loading" />}{drawerError && <p role="alert">{drawerError}</p>}{workspaceDrawer === "notes" ? <><div className="cg-
|
| 8917 |
{displayMode === "map" && !pivotOn && (
|
| 8918 |
<MapSettings
|
| 8919 |
coordField={mapCoordField}
|
|
|
|
| 473 |
/** C3 locks are present on the server projection, while the long-lived shared type remains
|
| 474 |
* deliberately backward-compatible. Keep that wire detail additive here rather than widening a
|
| 475 |
* cross-lane contract just to paint one property. */
|
| 476 |
+
/**
|
| 477 |
+
* β W47-T15 (owner instruction 17) β the ONE shared note on a Database or a View, as the server
|
| 478 |
+
* actually returns it (`core/user_tables.py::put_shared_note`): body, who wrote it, when, and the
|
| 479 |
+
* append-only revision number. It is a single note with revisions, NOT a thread, which is why the
|
| 480 |
+
* panel renders one comment-shaped article rather than a feed.
|
| 481 |
+
*/
|
| 482 |
+
type SharedNoteMeta = { body: string; author: string; updated: string; version: number };
|
| 483 |
+
|
| 484 |
+
/**
|
| 485 |
+
* ββ THE `[object Object]` FIX LIVES HERE, AND IT IS A SHAPE TEST, NOT A CAST.
|
| 486 |
+
* `user_tables.py::shared_note` answers `{}` when a subject has no note yet. The old reader was
|
| 487 |
+
* `String(body?.note?.body ?? body?.note ?? "")`, and `{}` is TRUTHY, so `??` fell through to the
|
| 488 |
+
* empty OBJECT and `String({})` printed the literal `[object Object]` into the composer. Returning
|
| 489 |
+
* null for "no note" is what makes an empty state expressible at all; a `String()` of anything can
|
| 490 |
+
* only ever produce more text.
|
| 491 |
+
* β An empty `body` counts as NO note on purpose: a note saved and then blanked is not a note, and
|
| 492 |
+
* rendering an authored article with nothing in it would say something false about who wrote what.
|
| 493 |
+
*/
|
| 494 |
+
function asSharedNote(raw: unknown): SharedNoteMeta | null {
|
| 495 |
+
if (!raw || typeof raw !== "object") return null;
|
| 496 |
+
const note = raw as Record<string, unknown>;
|
| 497 |
+
const body = typeof note.body === "string" ? note.body : "";
|
| 498 |
+
if (!body.trim()) return null;
|
| 499 |
+
return {
|
| 500 |
+
body,
|
| 501 |
+
author: typeof note.author === "string" ? note.author : "",
|
| 502 |
+
updated: typeof note.updated === "string" ? note.updated : "",
|
| 503 |
+
version: Number(note.version ?? 0) || 0,
|
| 504 |
+
};
|
| 505 |
+
}
|
| 506 |
+
|
| 507 |
+
/** Up to two initials, mirroring `RecordComments.tsx::initials` so the two avatars agree. */
|
| 508 |
+
function noteInitials(name: string): string {
|
| 509 |
+
return (
|
| 510 |
+
name.trim().split(/\s+/).slice(0, 2).map((part) => part[0]?.toUpperCase()).join("") || "?"
|
| 511 |
+
);
|
| 512 |
+
}
|
| 513 |
+
|
| 514 |
+
/** Same format as `RecordComments.tsx::when`, so a note and a comment read the same date. */
|
| 515 |
+
function noteWhen(value: string): string {
|
| 516 |
+
const date = new Date(value);
|
| 517 |
+
if (!Number.isFinite(date.getTime())) return value;
|
| 518 |
+
return new Intl.DateTimeFormat(undefined, { dateStyle: "medium", timeStyle: "short" })
|
| 519 |
+
.format(date);
|
| 520 |
+
}
|
| 521 |
+
|
| 522 |
type LockedFilterRule = FilterRule & { locked?: boolean };
|
| 523 |
type LockedSortRule = SortRule & { locked?: boolean };
|
| 524 |
type ManagedRouteClause = {
|
|
|
|
| 3608 |
}).catch(() => undefined);
|
| 3609 |
return () => controller.abort();
|
| 3610 |
}, [applicationDatabase, applicationKind, applySavedApplication, config.application, dataPath?.application]);
|
| 3611 |
+
/** W47-T15 β which drawer load is the CURRENT one; see the `.finally` below for why. */
|
| 3612 |
+
const drawerSeq = useRef(0);
|
| 3613 |
const [drawerBusy, setDrawerBusy] = useState(false);
|
| 3614 |
const [drawerError, setDrawerError] = useState("");
|
| 3615 |
const [sharedNote, setSharedNote] = useState("");
|
| 3616 |
+
/**
|
| 3617 |
+
* ββ W47-T15 (owner instruction 17) β THE SAVED NOTE, KEPT AS AN OBJECT, WHICH IS ALSO THE
|
| 3618 |
+
* `[object Object]` FIX. The drawer used to read `String(body?.note?.body ?? body?.note ?? "")`
|
| 3619 |
+
* straight into the textarea. `core/user_tables.py::shared_note` returns `{}` for a subject with
|
| 3620 |
+
* no note, and `{}` is TRUTHY, so `??` never reached the `""` and `String({})` rendered the
|
| 3621 |
+
* literal text `[object Object]` into the composer β the defect in ERROR 17.png. `asSharedNote`
|
| 3622 |
+
* below returns null for that shape instead, so "no note yet" is a STATE rather than a string.
|
| 3623 |
+
* β Keeping the whole record, not just the body, is what lets the panel wear the comment
|
| 3624 |
+
* anatomy at all: `author` and `updated` are the avatar and the timestamp, and there is nowhere
|
| 3625 |
+
* else to get them from. `sharedNote` stays what it always was, the COMPOSER DRAFT, and is now
|
| 3626 |
+
* deliberately reset to empty on load: the saved note is shown above the composer instead of
|
| 3627 |
+
* being pre-loaded into it, so a stray keystroke cannot silently replace a colleague's note.
|
| 3628 |
+
*/
|
| 3629 |
+
const [savedNote, setSavedNote] = useState<SharedNoteMeta | null>(null);
|
| 3630 |
+
/** W47-T15 - SAVING is not LOADING. `drawerBusy` covers both the note fetch and the history
|
| 3631 |
+
* fetch, so labelling the submit off it made the button read "Saving..." while the panel was
|
| 3632 |
+
* merely opening, which is a button describing something nobody asked for. The spinner already
|
| 3633 |
+
* says "loading"; this flag is the only thing that may say "saving". */
|
| 3634 |
+
const [noteSaving, setNoteSaving] = useState(false);
|
| 3635 |
+
/**
|
| 3636 |
+
* ββ W47-T16 (owner instruction 19) β HOW MANY NOTES THIS VIEWER HAS NOT OPENED, and the
|
| 3637 |
+
* subjects that would clear it. The server answers BOTH, so the client never invents a
|
| 3638 |
+
* version number: it stamps back exactly the version it was told it had not read. That is
|
| 3639 |
+
* what keeps the badge honest when somebody edits a note between the count and the click.
|
| 3640 |
+
*/
|
| 3641 |
+
const [notesUnread, setNotesUnread] = useState<{ subjectKind: string; version: number }[]>([]);
|
| 3642 |
+
/** W47-T16 β the note is being EDITED in place, so the composer holds its current body. */
|
| 3643 |
+
const [noteEditing, setNoteEditing] = useState(false);
|
| 3644 |
const [notesMode, setNotesMode] = useState<"database" | "view">("database");
|
| 3645 |
const [historyRows, setHistoryRows] = useState<Array<Record<string, unknown>>>([]);
|
| 3646 |
const [historyRetention, setHistoryRetention] = useState<30 | 90>(30);
|
|
|
|
| 3648 |
useEffect(() => {
|
| 3649 |
if (!workspaceDrawer) return;
|
| 3650 |
const controller = new AbortController();
|
| 3651 |
+
const mine = ++drawerSeq.current;
|
| 3652 |
setDrawerBusy(true); setDrawerError("");
|
| 3653 |
const noteViewQuery = notesMode === "view" ? `&viewId=${encodeURIComponent(activeViewId)}` : "";
|
| 3654 |
const userTableHistory = scope.startsWith("ut_");
|
|
|
|
| 3662 |
void fetch(url, { credentials: CREDENTIALS, signal: controller.signal }).then(async (response) => {
|
| 3663 |
const body = await response.json().catch(() => ({}));
|
| 3664 |
if (!response.ok) throw new Error(String(body?.detail?.message ?? body?.detail ?? "Could not load drawer"));
|
| 3665 |
+
if (workspaceDrawer === "notes") { setSavedNote(asSharedNote(body?.note)); setSharedNote(""); }
|
| 3666 |
else setHistoryRows(Array.isArray(body?.events) ? body.events : Array.isArray(body?.history) ? body.history : []);
|
| 3667 |
}).catch((error: unknown) => { if (!controller.signal.aborted) setDrawerError(error instanceof Error ? error.message : "Could not load drawer"); })
|
| 3668 |
+
// ββ W47-T15 β THE BUSY FLAG IS CLEARED BY THE RUN THAT IS STILL THE LATEST, NOT BY THE
|
| 3669 |
+
// RUN THAT WAS NOT ABORTED, AND THOSE ARE DIFFERENT QUESTIONS. This read `if
|
| 3670 |
+
// (!controller.signal.aborted) setDrawerBusy(false)`, so an ABORTED run cleared nothing --
|
| 3671 |
+
// and this effect's deps include `historyPid`, which changes as the grid's selection
|
| 3672 |
+
// settles just after a database opens. Open Notes in that window and the last run in flight
|
| 3673 |
+
// is aborted by a re-render whose successor never re-fetches, leaving `drawerBusy` TRUE
|
| 3674 |
+
// FOREVER: a permanent spinner and a panel that never shows its note. It was invisible
|
| 3675 |
+
// before this ticket only because the composer painted `[object Object]` either way, so the
|
| 3676 |
+
// panel looked populated while it was in fact still loading. SEEN in a browser on this
|
| 3677 |
+
// change: one tab rendered the note, a second tab on the same database hung on the spinner.
|
| 3678 |
+
// Sequencing, which is what makes clearing safe: React runs the previous effect's cleanup
|
| 3679 |
+
// and then the new effect body SYNCHRONOUSLY, so a superseding run has already set the flag
|
| 3680 |
+
// back to true before this rejected promise settles. Comparing the seq is what stops the
|
| 3681 |
+
// stale run from clearing the fresh run's flag.
|
| 3682 |
+
.finally(() => { if (drawerSeq.current === mine) setDrawerBusy(false); });
|
| 3683 |
return () => controller.abort();
|
| 3684 |
}, [activeViewId, historyPid, historyRetention, notesMode, scope, workspaceDrawer]);
|
| 3685 |
+
/**
|
| 3686 |
+
* β W47-T16 β the unread COUNT, asked separately from the note itself and deliberately so.
|
| 3687 |
+
* `routes_notes.py` is additive precisely because this question is cheaper than fetching a
|
| 3688 |
+
* note body, and the badge has to be right BEFORE the drawer is ever opened. It re-asks
|
| 3689 |
+
* whenever the database or the open View changes, and after a save, which is the only other
|
| 3690 |
+
* moment the answer can move for this viewer.
|
| 3691 |
+
*/
|
| 3692 |
+
const refreshNotesUnread = useCallback(async () => {
|
| 3693 |
+
try {
|
| 3694 |
+
const viewQuery = activeViewId ? `&viewId=${encodeURIComponent(activeViewId)}` : "";
|
| 3695 |
+
const response = await fetch(
|
| 3696 |
+
`${API_V1}/notes/unread?scope=${encodeURIComponent(scope)}${viewQuery}`,
|
| 3697 |
+
{ credentials: CREDENTIALS });
|
| 3698 |
+
if (!response.ok) return;
|
| 3699 |
+
const body = await response.json().catch(() => ({}));
|
| 3700 |
+
setNotesUnread(Array.isArray(body?.subjects) ? body.subjects : []);
|
| 3701 |
+
} catch { /* a badge is not worth an error state; it simply stays as it was */ }
|
| 3702 |
+
}, [activeViewId, scope]);
|
| 3703 |
+
useEffect(() => { void refreshNotesUnread(); }, [refreshNotesUnread]);
|
| 3704 |
+
/**
|
| 3705 |
+
* ββ W47-T16 β OPENING A NOTE IS WHAT MARKS IT READ, and the version comes from the note
|
| 3706 |
+
* the viewer is actually looking at. The server refuses to take a subject id from the body
|
| 3707 |
+
* (`routes_notes.py`), so this can only ever stamp the subject the current scope resolves
|
| 3708 |
+
* to, under this session's own name. Cheap enough to fire on every open: the store write is
|
| 3709 |
+
* monotonic, so a repeat is a no-op rather than a correction.
|
| 3710 |
+
*/
|
| 3711 |
+
const markNoteRead = useCallback(async () => {
|
| 3712 |
+
const version = savedNote?.version ?? 0;
|
| 3713 |
+
if (!version) return;
|
| 3714 |
+
try {
|
| 3715 |
+
const viewQuery = notesMode === "view" && activeViewId
|
| 3716 |
+
? `&viewId=${encodeURIComponent(activeViewId)}` : "";
|
| 3717 |
+
await fetch(`${API_V1}/notes/read?scope=${encodeURIComponent(scope)}${viewQuery}`, {
|
| 3718 |
+
method: "POST", credentials: CREDENTIALS,
|
| 3719 |
+
headers: { "Content-Type": "application/json" },
|
| 3720 |
+
body: JSON.stringify({ subjectKind: notesMode === "view" ? "view" : "database", version }),
|
| 3721 |
+
});
|
| 3722 |
+
void refreshNotesUnread();
|
| 3723 |
+
} catch { /* the badge is advisory; a failed stamp just leaves it lit */ }
|
| 3724 |
+
}, [activeViewId, notesMode, refreshNotesUnread, savedNote, scope]);
|
| 3725 |
+
/** Opening the drawer on a note that HAS a body is the read event instruction 19 describes. */
|
| 3726 |
+
useEffect(() => {
|
| 3727 |
+
if (workspaceDrawer !== "notes" || !savedNote?.version) return;
|
| 3728 |
+
void markNoteRead();
|
| 3729 |
+
}, [markNoteRead, savedNote, workspaceDrawer]);
|
| 3730 |
const saveSharedNote = useCallback(async () => {
|
| 3731 |
+
setNoteSaving(true); setDrawerError("");
|
| 3732 |
try {
|
| 3733 |
const noteViewQuery = notesMode === "view" ? `&viewId=${encodeURIComponent(activeViewId)}` : "";
|
| 3734 |
const response = await fetch(`${API_V1}/grid/shared-note?scope=${encodeURIComponent(scope)}${noteViewQuery}`, { method: "PUT", credentials: CREDENTIALS, headers: { "Content-Type": "application/json" }, body: JSON.stringify({ body: sharedNote }) });
|
| 3735 |
const body = await response.json().catch(() => ({}));
|
| 3736 |
if (!response.ok) throw new Error(String(body?.detail?.message ?? body?.detail ?? "Could not save note"));
|
| 3737 |
+
// W47-T15 β the PUT answers with the stored record, so the article above the composer shows
|
| 3738 |
+
// the new author and timestamp without a second round trip, and the draft empties the way a
|
| 3739 |
+
// posted comment's does. Falling back to a locally-built record keeps the panel truthful if
|
| 3740 |
+
// a future server answer omits the echo.
|
| 3741 |
+
setSavedNote(asSharedNote(body?.note) ?? { body: sharedNote, author: viewer?.name ?? "", updated: new Date().toISOString(), version: 0 });
|
| 3742 |
+
setSharedNote("");
|
| 3743 |
+
setNoteEditing(false);
|
| 3744 |
+
// W47-T16 β saving is also a READ: you have plainly seen the note you just wrote, and
|
| 3745 |
+
// the version moved, so without this the author's own badge lights up for their own edit.
|
| 3746 |
+
void markNoteRead();
|
| 3747 |
} catch (error) { setDrawerError(error instanceof Error ? error.message : "Could not save note"); }
|
| 3748 |
+
finally { setNoteSaving(false); }
|
| 3749 |
+
}, [activeViewId, notesMode, scope, sharedNote, viewer]);
|
| 3750 |
const embeddedPropKeyRef = useRef(embeddedSelectedKey);
|
| 3751 |
useEffect(() => {
|
| 3752 |
if (!embeddedSelectable) {
|
|
|
|
| 9052 |
// row drove, moved to the toolbar so Related, Notes and Full screen read as one run.
|
| 9053 |
// Only this render supplies it, so the pivot toolbar shows no Notes button at all.
|
| 9054 |
notesOpen={workspaceDrawer === "notes"}
|
| 9055 |
+
notesUnread={notesUnread.length}
|
| 9056 |
onNotes={() => setWorkspaceDrawer((open) => (open === "notes" ? null : "notes"))}
|
| 9057 |
/>
|
| 9058 |
{/* β R11's SECOND ROW β live, on the pivoted database. It renders only once the pivot has
|
|
|
|
| 9060 |
not be wired yet: absent beats present-and-inert. A control row over a database whose
|
| 9061 |
columns never arrived would offer Hide fields, Filter, Sort and Group on nothing. */}
|
| 9062 |
{secondaryToolbar}
|
| 9063 |
+
{workspaceDrawer && <aside className="cg-workspace-drawer" aria-label={workspaceDrawer === "notes" ? "Notes" : "History"}><header><strong>{workspaceDrawer === "notes" ? "Notes" : "History"}</strong><button type="button" className="cg-icon-button" aria-label="Close drawer" onClick={() => setWorkspaceDrawer(null)}>Γ</button></header>{drawerBusy && <span className="lp-spin" role="status" aria-label="Loading" />}{drawerError && <p role="alert">{drawerError}</p>}{workspaceDrawer === "notes" ? <><div className="cg-note-tabs" role="group" aria-label="Notes scope"><button type="button" className="cg-note-tab" aria-pressed={notesMode === "database"} onClick={() => setNotesMode("database")}>Database note</button><button type="button" className="cg-note-tab" aria-pressed={notesMode === "view"} onClick={() => setNotesMode("view")}>View note</button></div><div className="cg-note-feed" aria-live="polite">{savedNote ? <article className="cg-record-comment"><div className="cg-record-comment-avatar" aria-hidden>{noteInitials(savedNote.author)}</div><div className="cg-record-comment-content"><div className="cg-record-comment-meta"><strong>{savedNote.author || "Unknown"}</strong><time dateTime={savedNote.updated}>{noteWhen(savedNote.updated)}</time><button type="button" className="cg-note-edit" aria-label={notesMode === "view" ? "Edit this View note" : "Edit this Database note"} title="Edit note" onClick={() => { setSharedNote(savedNote.body); setNoteEditing(true); window.setTimeout(() => document.getElementById("cg-note-input")?.focus(), 0); }}>Edit</button></div><p>{savedNote.body}</p></div></article> : !drawerBusy && <div className="cg-record-comment-state">No note yet. Write the first one below.</div>}</div><form className="cg-note-compose cg-record-comment-compose" onSubmit={(event) => { event.preventDefault(); void saveSharedNote(); }}><label htmlFor="cg-note-input">{noteEditing ? (notesMode === "view" ? "Editing this View note" : "Editing this Database note") : savedNote ? (notesMode === "view" ? "Update this View note" : "Update this Database note") : (notesMode === "view" ? "Add a View note" : "Add a Database note")}</label><textarea id="cg-note-input" className="cg-note-input" value={sharedNote} maxLength={100000} placeholder={noteEditing ? "Edit the note and save your changes" : savedNote ? "Write a new version of this note" : "Share context with the team here"} onChange={(event) => setSharedNote(event.target.value)} onKeyDown={(event) => { if ((event.ctrlKey || event.metaKey) && event.key === "Enter") { event.preventDefault(); event.currentTarget.form?.requestSubmit(); } }} /><div className="cg-record-comment-compose-foot"><span>Ctrl/Cmd + Enter to save</span>{noteEditing && <button type="button" className="cg-note-cancel" onClick={() => { setNoteEditing(false); setSharedNote(""); }}>Cancel</button>}<button type="submit" disabled={drawerBusy || noteSaving || !sharedNote.trim()}>{noteSaving ? "Savingβ¦" : noteEditing ? "Save changes" : savedNote ? "Update note" : "Save note"}</button></div></form></> : <><label>Retention<select className="cg-select" value={historyRetention} onChange={(event) => setHistoryRetention(Number(event.target.value) as 30 | 90)}><option value={30}>30 days</option><option value={90}>90 days Β· platform admin</option></select></label>{historyPid == null ? <p>Select one record to inspect its history.</p> : historyRows.length === 0 && !drawerBusy ? <p>No retained changes.</p> : <ol className="cg-history-list">{historyRows.map((event, index) => <li key={String(event.id ?? index)}><strong>{String(event.field ?? event.fieldKey ?? "Record")}</strong><span>{String(event.updatedAt ?? event.at ?? "")}</span><button type="button" className="cg-link-btn" onClick={async () => { if (!window.confirm("Restore this recorded value? This writes a new auditable change and does not erase history.")) return; const id = String(event.id ?? ""); const restoreUrl = scope.startsWith("ut_") ? `${API_V1}/tables/${encodeURIComponent(scope)}/history/${encodeURIComponent(id)}/restore` : `${API_V1}/grid/history/${encodeURIComponent(id)}/restore?scope=${encodeURIComponent(scope)}`; const response = await fetch(restoreUrl, { method: "POST", credentials: CREDENTIALS, headers: { "Content-Type": "application/json" }, body: JSON.stringify({ rowId: historyPid, field: event.field ?? event.fieldKey, retentionDays: historyRetention }) }); if (!response.ok) setDrawerError("Restore was refused. Your current value was not changed."); else setWorkspaceDrawer(null); }}>Restoreβ¦</button></li>)}</ol>}</>}</aside>}
|
| 9064 |
{displayMode === "map" && !pivotOn && (
|
| 9065 |
<MapSettings
|
| 9066 |
coordField={mapCoordField}
|
web/src/customer-grid/DatePicker.tsx
CHANGED
|
@@ -10,7 +10,24 @@ const WEEKDAYS = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
|
|
| 10 |
const WEEKDAY_INITIALS = ["M", "T", "W", "T", "F", "S", "S"];
|
| 11 |
const ORDINALS: ReadonlyArray<readonly [DateRecurrenceRule["ordinal"], string]> = [[1, "First"], [2, "Second"], [3, "Third"], [4, "Fourth"], [5, "Fifth"], [-1, "Last"]];
|
| 12 |
const RULE_KINDS = ["daily", "weekly", "monthly", "monthly_ordinal", "yearly", "holiday"] as const;
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
// W46-T33: a holiday rule may now name ONE holiday instead of a whole national calendar, so the
|
| 15 |
// code is any string the server's registry admits and `group` says which heading it belongs
|
| 16 |
// under. This LOCAL type widens; `types.ts` does not, because the granular id rides the existing
|
|
@@ -38,18 +55,31 @@ function parseIso(value: unknown): Date | null {
|
|
| 38 |
function iso(date: Date): string { return date.toISOString().slice(0, 10); }
|
| 39 |
function addMonths(date: Date, amount: number): Date { const out = new Date(date); out.setUTCMonth(out.getUTCMonth() + amount); return out; }
|
| 40 |
function bounded(value: unknown, lower: number, upper: number, fallback: number): number { const number = Math.round(Number(value)); return Number.isFinite(number) ? Math.max(lower, Math.min(upper, number)) : fallback; }
|
| 41 |
-
function ruleKind(rule:
|
| 42 |
-
function newRule(kind: RuleKind, selected: Date):
|
| 43 |
if (kind === "weekly") return { kind, interval: 1, weekdays: [((selected.getUTCDay() + 6) % 7)] };
|
| 44 |
if (kind === "monthly_ordinal") return { kind: "monthly", interval: 1, ordinal: 1, weekday: 0 };
|
| 45 |
if (kind === "monthly") return { kind, interval: 1, day: selected.getUTCDate() };
|
| 46 |
if (kind === "yearly") return { kind, interval: 1, month: selected.getUTCMonth() + 1, day: selected.getUTCDate() };
|
| 47 |
if (kind === "holiday") return { kind, interval: 1, calendar: "US", offset: 0 };
|
|
|
|
|
|
|
|
|
|
| 48 |
return { kind, interval: 1 };
|
| 49 |
}
|
| 50 |
// The unit words that finish the "Repeat every N ..." sentence, so the control reads as one
|
| 51 |
// phrase instead of restating the whole rule inside its own dropdown.
|
| 52 |
-
function labelForKind(kind: RuleKind): string { return ({ daily: "day", weekly: "week", monthly: "month", monthly_ordinal: "month on a weekday", yearly: "year", holiday: "holiday" } as Record<RuleKind, string>)[kind]; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
type RecurrenceCondition = {
|
| 55 |
colId: string;
|
|
@@ -60,7 +90,8 @@ type RecurrenceCondition = {
|
|
| 60 |
// `anchorField` and `conditions` are persisted by the server and absent from `DateRecurrence`;
|
| 61 |
// they have ridden this local intersection since wave 43. `ends` joins them the same way.
|
| 62 |
type RecurrenceEnds = { kind: "never" } | { kind: "on"; date: string } | { kind: "after"; count: number };
|
| 63 |
-
type LinkedRecurrence = DateRecurrence & {
|
|
|
|
| 64 |
anchorField?: { table: "same" | string; field: string; linkedVia?: string };
|
| 65 |
conditions?: RecurrenceCondition[];
|
| 66 |
ends?: RecurrenceEnds;
|
|
@@ -68,7 +99,7 @@ type LinkedRecurrence = DateRecurrence & {
|
|
| 68 |
|
| 69 |
// The plain-language line the closed picker shows, so a person reads the schedule without
|
| 70 |
// reopening the editor. Commas and full stops only, and never a dash character.
|
| 71 |
-
function ruleSentence(rule:
|
| 72 |
const every = bounded(rule.interval ?? 1, 1, 366, 1);
|
| 73 |
const unit = (word: string) => (every === 1 ? word : `${every} ${word}s`);
|
| 74 |
const kind = ruleKind(rule);
|
|
@@ -85,14 +116,25 @@ function ruleSentence(rule: DateRecurrenceRule, calendars: CalendarOption[]): st
|
|
| 85 |
if (kind === "holiday") {
|
| 86 |
const option = calendars.find((item) => item.code === (rule.calendar ?? "US"));
|
| 87 |
const relation = ["the day before", "the day of", "the day after"][bounded(rule.offset ?? 0, -1, 1, 0) + 1];
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
// A single holiday reads as itself. "each holiday in Christmas Day" is what the calendar
|
| 89 |
// phrasing becomes once a rule can name one day, and it is not a sentence anybody wrote.
|
| 90 |
-
if (option?.group === "holiday") return `on ${relation} ${option.label}`;
|
| 91 |
-
return `on ${relation} each holiday in ${option?.label ?? "public holidays"}`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
}
|
| 93 |
return `every ${unit("day")}`;
|
| 94 |
}
|
| 95 |
-
function recurrenceSentence(rules:
|
| 96 |
if (!rules.length) return "";
|
| 97 |
const body = rules.map((rule) => ruleSentence(rule, calendars)).join(", and ");
|
| 98 |
if (ends.kind === "on") return `Repeats ${body}, until ${ends.date}.`;
|
|
@@ -107,22 +149,36 @@ export function DatePicker({ anchor, field, fields, scopeKey, value, today, onCh
|
|
| 107 |
const selected = parseIso(value) ?? parseIso(today) ?? new Date();
|
| 108 |
const selectedIso = iso(selected);
|
| 109 |
const [cursor, setCursor] = useState(() => new Date(Date.UTC(selected.getUTCFullYear(), selected.getUTCMonth(), 1)));
|
| 110 |
-
const [rules, setRules] = useState<
|
| 111 |
const [previewCount, setPreviewCount] = useState(() => field.recurrence?.previewCount ?? 10);
|
| 112 |
const [preview, setPreview] = useState<string[]>(() => field.recurrence?.preview ?? []);
|
| 113 |
const [nextDate, setNextDate] = useState<string | null | undefined>(() => field.recurrence?.nextDate);
|
| 114 |
const [calendars, setCalendars] = useState<CalendarOption[]>(DEFAULT_CALENDARS);
|
| 115 |
const [previewError, setPreviewError] = useState("");
|
| 116 |
-
|
|
|
|
|
|
|
|
|
|
| 117 |
const [anchorTable, setAnchorTable] = useState(() => storedRecurrence?.anchorField?.table ?? "same");
|
| 118 |
-
|
|
|
|
|
|
|
|
|
|
| 119 |
const [linkedVia, setLinkedVia] = useState(() => storedRecurrence?.anchorField?.linkedVia ?? "");
|
| 120 |
const [conditions, setConditions] = useState<RecurrenceCondition[]>(() => storedRecurrence?.conditions ?? []);
|
| 121 |
const [ends, setEnds] = useState<RecurrenceEnds>(() => storedRecurrence?.ends ?? { kind: "never" });
|
| 122 |
// Step 1 is a plain date. The repeat editor is a second step in the SAME overlay, so the
|
| 123 |
// anchor block, the conditions and the rule rows leave the default path entirely.
|
| 124 |
const [step, setStep] = useState<"date" | "repeat">("date");
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
const endsName = useId();
|
| 127 |
const dateFields = useMemo(() => fields.filter((candidate) => candidate.type === "date"), [fields]);
|
| 128 |
const linkedFields = useMemo(() => fields.filter((candidate) => candidate.type === "link" && candidate.link?.table), [fields]);
|
|
@@ -159,7 +215,7 @@ export function DatePicker({ anchor, field, fields, scopeKey, value, today, onCh
|
|
| 159 |
return () => controller.abort();
|
| 160 |
}, [recurrence]);
|
| 161 |
|
| 162 |
-
const updateRule = (index: number, patch: Partial<
|
| 163 |
const replaceKind = (index: number, kind: RuleKind) => setRules((current) => current.map((rule, item) => item === index ? newRule(kind, selected) : rule));
|
| 164 |
const toggleWeekday = (index: number, weekday: number, checked: boolean) => setRules((current) => current.map((rule, item) => {
|
| 165 |
if (item !== index) return rule;
|
|
@@ -168,8 +224,9 @@ export function DatePicker({ anchor, field, fields, scopeKey, value, today, onCh
|
|
| 168 |
return { ...rule, weekdays: weekdays.length ? weekdays : existing };
|
| 169 |
}));
|
| 170 |
const openEditor = () => {
|
| 171 |
-
setRestorePoint({ rules, ends, anchorTable, anchorField, linkedVia, conditions, previewCount });
|
| 172 |
if (!rules.length) setRules([newRule("weekly", selected)]);
|
|
|
|
| 173 |
setStep("repeat");
|
| 174 |
};
|
| 175 |
const cancelEditor = () => {
|
|
@@ -177,17 +234,23 @@ export function DatePicker({ anchor, field, fields, scopeKey, value, today, onCh
|
|
| 177 |
setRules(restorePoint.rules); setEnds(restorePoint.ends); setAnchorTable(restorePoint.anchorTable);
|
| 178 |
setAnchorField(restorePoint.anchorField); setLinkedVia(restorePoint.linkedVia);
|
| 179 |
setConditions(restorePoint.conditions); setPreviewCount(restorePoint.previewCount);
|
|
|
|
| 180 |
}
|
| 181 |
setRestorePoint(null);
|
|
|
|
| 182 |
setStep("date");
|
| 183 |
};
|
| 184 |
-
const saveEditor = () => { onRecurrence(recurrence); setRestorePoint(null); setStep("date"); };
|
| 185 |
-
const removeRepeat = () => { setRules([]); setEnds({ kind: "never" }); setConditions([]); onRecurrence(null); setRestorePoint(null); setStep("date"); };
|
| 186 |
const monthStart = new Date(Date.UTC(cursor.getUTCFullYear(), cursor.getUTCMonth(), 1));
|
| 187 |
const leading = (monthStart.getUTCDay() + 6) % 7;
|
| 188 |
const days = new Date(Date.UTC(cursor.getUTCFullYear(), cursor.getUTCMonth() + 1, 0)).getUTCDate();
|
| 189 |
const cells = Array.from({ length: Math.ceil((leading + days) / 7) * 7 }, (_, index) => index - leading + 1);
|
| 190 |
const summary = recurrenceSentence(rules, ends, calendars);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
|
| 192 |
// This is a body-portal overlay, so `cg-date-picker` alone only supplies its width and padding.
|
| 193 |
// Keep the shared `cg-pop` contract on the same element: it supplies the opaque surface, border,
|
|
@@ -214,13 +277,59 @@ export function DatePicker({ anchor, field, fields, scopeKey, value, today, onCh
|
|
| 214 |
<div className="cg-pop-title">Custom repeat</div>
|
| 215 |
</div>
|
| 216 |
{rules.map((rule, index) => <div className="w46-recur-card" key={`${rule.kind}-${index}`}>
|
| 217 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
<span className="w46-recur-label">Repeat every</span>
|
| 219 |
<div className="w46-recur-controls">
|
| 220 |
<input className="cg-input w46-recur-count" min="1" max="366" type="number" aria-label={`Repeat interval ${index + 1}`} value={rule.interval ?? 1} onChange={(event) => updateRule(index, { interval: bounded(event.target.value, 1, 366, 1) })} />
|
| 221 |
<select className="cg-select" value={ruleKind(rule)} aria-label={`Repeat unit ${index + 1}`} onChange={(event) => replaceKind(index, event.target.value as RuleKind)}>{RULE_KINDS.map((kind) => <option key={kind} value={kind}>{labelForKind(kind)}</option>)}</select>
|
| 222 |
</div>
|
| 223 |
-
</div>
|
| 224 |
{rule.kind === "weekly" && <div className="w46-recur-row">
|
| 225 |
<span className="w46-recur-label" id={`${endsName}-days-${index}`}>Repeat on</span>
|
| 226 |
<div className="w46-recur-pills" role="group" aria-labelledby={`${endsName}-days-${index}`}>{WEEKDAY_INITIALS.map((initial, weekday) => {
|
|
@@ -246,19 +355,33 @@ export function DatePicker({ anchor, field, fields, scopeKey, value, today, onCh
|
|
| 246 |
<input className="cg-input w46-recur-count" min="1" max="31" type="number" aria-label="Day of the month" value={rule.day ?? 1} onChange={(event) => updateRule(index, { day: bounded(event.target.value, 1, 31, 1) })} />
|
| 247 |
</div>
|
| 248 |
</div>}
|
| 249 |
-
{rule.kind === "holiday" && <div className="w46-recur-row">
|
| 250 |
-
<span className="w46-recur-label">Repeat on</span>
|
| 251 |
-
<div className="w46-recur-controls">
|
| 252 |
-
<select className="cg-select" value={rule.calendar ?? "US"} aria-label="Public calendar" onChange={(event) => updateRule(index, { calendar: event.target.value as "US" | "CA" })}>{CALENDAR_GROUPS.map(([group, heading]) => {
|
| 253 |
-
const members = calendars.filter((calendar) => (calendar.group ?? "calendar") === group);
|
| 254 |
-
return members.length ? <optgroup key={heading} label={heading}>{members.map((calendar) => <option key={calendar.code} value={calendar.code}>{calendar.label}</option>)}</optgroup> : null;
|
| 255 |
-
})}</select>
|
| 256 |
-
<select className="cg-select" value={rule.offset ?? 0} aria-label="Holiday relation" onChange={(event) => updateRule(index, { offset: Number(event.target.value) as -1 | 0 | 1 })}><option value={-1}>Day before</option><option value={0}>Day on</option><option value={1}>Day after</option></select>
|
| 257 |
-
</div>
|
| 258 |
-
</div>}
|
| 259 |
{rules.length > 1 && <div className="w46-recur-card-foot"><button type="button" className="w46-recur-quiet" onClick={() => setRules((current) => current.filter((_, item) => item !== index))}>Remove rule</button></div>}
|
| 260 |
</div>)}
|
| 261 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
<div className="w46-recur-row">
|
| 263 |
<span className="w46-recur-label" id={`${endsName}-label`}>Ends</span>
|
| 264 |
<div className="w46-recur-ends" role="group" aria-labelledby={`${endsName}-label`}>
|
|
@@ -269,23 +392,9 @@ export function DatePicker({ anchor, field, fields, scopeKey, value, today, onCh
|
|
| 269 |
<input className="cg-input w46-recur-count" type="number" min="1" max="365" aria-label="Number of occurrences" disabled={ends.kind !== "after"} value={ends.kind === "after" ? ends.count : ""} onChange={(event) => setEnds({ kind: "after", count: bounded(event.target.value, 1, 365, 13) })} /><span className="w46-recur-word">occurrences</span></label>
|
| 270 |
</div>
|
| 271 |
</div>
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
<label>Anchor database<select className="cg-select" value={anchorTable} onChange={(event) => {
|
| 276 |
-
const table = event.target.value;
|
| 277 |
-
setAnchorTable(table);
|
| 278 |
-
if (table === "same") setLinkedVia("");
|
| 279 |
-
else setLinkedVia(linkedFields.find((candidate) => candidate.link?.table === table)?.key ?? "");
|
| 280 |
-
setAnchorField("");
|
| 281 |
-
}}><option value="same">This database</option>{linkedFields.map((candidate) => <option value={candidate.link!.table} key={candidate.key}>{candidate.label} Β· {candidate.link!.table}</option>)}</select></label>
|
| 282 |
-
{anchorTable === "same" ? <label>Date field<select className="cg-select" value={anchorField} onChange={(event) => setAnchorField(event.target.value)}><option value="">This date</option>{dateFields.map((candidate) => <option value={candidate.key} key={candidate.key}>{candidate.label}</option>)}</select></label>
|
| 283 |
-
: <><label>Linked through<select className="cg-select" value={linkedVia} onChange={(event) => setLinkedVia(event.target.value)}>{linkedFields.filter((candidate) => candidate.link?.table === anchorTable).map((candidate) => <option value={candidate.key} key={candidate.key}>{candidate.label}</option>)}</select></label><label>Linked date field key<input className="cg-input" value={anchorField} onChange={(event) => setAnchorField(event.target.value)} placeholder="due_date" /></label></>}
|
| 284 |
-
</div>
|
| 285 |
-
<div className="cg-date-boundary" aria-label="Recurrence conditions"><div className="cg-pop-title">Only when</div>{conditions.map((condition, index) => <div className="cg-date-holidays" key={`${condition.colId}-${index}`}><select className="cg-select" aria-label={`Condition field ${index + 1}`} value={condition.colId} onChange={(event) => setConditions((current) => current.map((item, itemIndex) => itemIndex === index ? { ...item, colId: event.target.value } : item))}>{fields.map((candidate) => <option key={candidate.key} value={candidate.key}>{candidate.label}</option>)}</select><select className="cg-select" aria-label={`Condition operator ${index + 1}`} value={condition.op} onChange={(event) => setConditions((current) => current.map((item, itemIndex) => itemIndex === index ? { ...item, op: event.target.value as RecurrenceCondition["op"], ...(event.target.value === "between" ? {} : { value2: undefined }) } : item))}><option value="eq">is</option><option value="neq">is not</option><option value="not_empty">is not empty</option><option value="between">is between</option></select>{condition.op !== "not_empty" && <input className="cg-input" aria-label={`Condition value ${index + 1}`} value={condition.value} onChange={(event) => setConditions((current) => current.map((item, itemIndex) => itemIndex === index ? { ...item, value: event.target.value } : item))} />}{condition.op === "between" && <input className="cg-input" aria-label={`Condition second value ${index + 1}`} value={condition.value2 ?? ""} onChange={(event) => setConditions((current) => current.map((item, itemIndex) => itemIndex === index ? { ...item, value2: event.target.value } : item))} />}<button type="button" className="cg-link-btn" onClick={() => setConditions((current) => current.filter((_, itemIndex) => itemIndex !== index))}>Remove</button></div>)}<button type="button" className="cg-link-btn" disabled={!fields.length} onClick={() => setConditions((current) => [...current, { colId: fields[0]?.key ?? "", op: "eq", value: "" }])}>+ Add condition</button></div>
|
| 286 |
-
<label className="w46-recur-preview-count">Show next <select className="cg-select" value={previewCount} aria-label="Number of preview dates" onChange={(event) => setPreviewCount(bounded(event.target.value, 1, 50, 10))}>{[3, 5, 10, 20, 50].map((count) => <option key={count} value={count}>{count}</option>)}</select> dates</label>
|
| 287 |
-
</details>
|
| 288 |
-
<div className="cg-date-preview" aria-live="polite"><div className="cg-pop-title">Next dates{nextDate ? ` Β· next ${nextDate}` : ""}</div>{preview.map((date) => <span key={date}>{date}</span>)}{rules.length > 0 && !preview.length && !previewError && <span>Calculating the server previewβ¦</span>}{previewError && <span role="status">{previewError}</span>}</div>
|
| 289 |
<div className="w46-recur-foot">
|
| 290 |
{storedRecurrence?.rules?.length ? <button type="button" className="w46-recur-quiet is-danger" onClick={removeRepeat}>Remove repeat</button> : null}
|
| 291 |
<button type="button" className="w46-recur-quiet" onClick={cancelEditor}>Cancel</button>
|
|
|
|
| 10 |
const WEEKDAY_INITIALS = ["M", "T", "W", "T", "F", "S", "S"];
|
| 11 |
const ORDINALS: ReadonlyArray<readonly [DateRecurrenceRule["ordinal"], string]> = [[1, "First"], [2, "Second"], [3, "Third"], [4, "Fourth"], [5, "Fifth"], [-1, "Last"]];
|
| 12 |
const RULE_KINDS = ["daily", "weekly", "monthly", "monthly_ordinal", "yearly", "holiday"] as const;
|
| 13 |
+
// W47-T25 (R1): a rule may now be ANCHORED, meaning "the date is N days on, after or before
|
| 14 |
+
// another date field". The other date field is the recurrence's EXISTING `anchorField`, so there
|
| 15 |
+
// is no second anchor concept and no per-rule anchor; because that anchor is a column, every
|
| 16 |
+
// record computes its own answer from its own value.
|
| 17 |
+
// This LOCAL type widens and `types.ts` does not, for the same reason `CalendarOption` below
|
| 18 |
+
// widens locally: `aios_grid.clean_date_recurrence` is what validates the kind and its two words,
|
| 19 |
+
// and widening the shared shape would ask three parity gates to agree about a value only the
|
| 20 |
+
// server can judge.
|
| 21 |
+
// β The kind is `anchored`, not `offset`: a holiday rule already stores a numeric `offset` key,
|
| 22 |
+
// and one word for two vocabularies is the confusion this surface keeps paying for.
|
| 23 |
+
type AnchoredUnit = "day" | "week" | "month";
|
| 24 |
+
type AnchoredRelation = "on" | "after" | "before";
|
| 25 |
+
type DateRule = Omit<DateRecurrenceRule, "kind"> & {
|
| 26 |
+
kind: DateRecurrenceRule["kind"] | "anchored";
|
| 27 |
+
unit?: AnchoredUnit;
|
| 28 |
+
relation?: AnchoredRelation;
|
| 29 |
+
};
|
| 30 |
+
type RuleKind = DateRule["kind"] | "monthly_ordinal";
|
| 31 |
// W46-T33: a holiday rule may now name ONE holiday instead of a whole national calendar, so the
|
| 32 |
// code is any string the server's registry admits and `group` says which heading it belongs
|
| 33 |
// under. This LOCAL type widens; `types.ts` does not, because the granular id rides the existing
|
|
|
|
| 55 |
function iso(date: Date): string { return date.toISOString().slice(0, 10); }
|
| 56 |
function addMonths(date: Date, amount: number): Date { const out = new Date(date); out.setUTCMonth(out.getUTCMonth() + amount); return out; }
|
| 57 |
function bounded(value: unknown, lower: number, upper: number, fallback: number): number { const number = Math.round(Number(value)); return Number.isFinite(number) ? Math.max(lower, Math.min(upper, number)) : fallback; }
|
| 58 |
+
function ruleKind(rule: DateRule): RuleKind { return rule.kind === "monthly" && rule.ordinal !== undefined ? "monthly_ordinal" : rule.kind; }
|
| 59 |
+
function newRule(kind: RuleKind, selected: Date): DateRule {
|
| 60 |
if (kind === "weekly") return { kind, interval: 1, weekdays: [((selected.getUTCDay() + 6) % 7)] };
|
| 61 |
if (kind === "monthly_ordinal") return { kind: "monthly", interval: 1, ordinal: 1, weekday: 0 };
|
| 62 |
if (kind === "monthly") return { kind, interval: 1, day: selected.getUTCDate() };
|
| 63 |
if (kind === "yearly") return { kind, interval: 1, month: selected.getUTCMonth() + 1, day: selected.getUTCDate() };
|
| 64 |
if (kind === "holiday") return { kind, interval: 1, calendar: "US", offset: 0 };
|
| 65 |
+
// β Never emit `interval: 0`: `clean_date_recurrence` bounds it to 1..366 and SILENTLY DROPS
|
| 66 |
+
// the whole rule below that, so an "on" relation still carries 1.
|
| 67 |
+
if (kind === "anchored") return { kind, interval: 1, unit: "day", relation: "after" };
|
| 68 |
return { kind, interval: 1 };
|
| 69 |
}
|
| 70 |
// The unit words that finish the "Repeat every N ..." sentence, so the control reads as one
|
| 71 |
// phrase instead of restating the whole rule inside its own dropdown.
|
| 72 |
+
function labelForKind(kind: RuleKind): string { return ({ daily: "day", weekly: "week", monthly: "month", monthly_ordinal: "month on a weekday", yearly: "year", holiday: "holiday", anchored: "another date field" } as Record<RuleKind, string>)[kind]; }
|
| 73 |
+
// W47-T24: the chooser names what gets ADDED, so its labels are nouns and not `labelForKind`'s
|
| 74 |
+
// sentence-finishing unit words. Same order and same six kinds as `RULE_KINDS`; the chooser is
|
| 75 |
+
// deliberately its own list so a seventh entry that is NOT a repeat rule can join it.
|
| 76 |
+
const ADD_KINDS: ReadonlyArray<readonly [RuleKind, string]> = [
|
| 77 |
+
["daily", "Day"], ["weekly", "Week"], ["monthly", "Month"],
|
| 78 |
+
["monthly_ordinal", "Month on a weekday"], ["yearly", "Year"], ["holiday", "Holidays"],
|
| 79 |
+
// W47-T25: the seventh entry, and the first that is NOT a repeat rule. It is worded as what it
|
| 80 |
+
// counts from, because the anchor is the whole point of it.
|
| 81 |
+
["anchored", "Days from another date field"],
|
| 82 |
+
];
|
| 83 |
|
| 84 |
type RecurrenceCondition = {
|
| 85 |
colId: string;
|
|
|
|
| 90 |
// `anchorField` and `conditions` are persisted by the server and absent from `DateRecurrence`;
|
| 91 |
// they have ridden this local intersection since wave 43. `ends` joins them the same way.
|
| 92 |
type RecurrenceEnds = { kind: "never" } | { kind: "on"; date: string } | { kind: "after"; count: number };
|
| 93 |
+
type LinkedRecurrence = Omit<DateRecurrence, "rules"> & {
|
| 94 |
+
rules: DateRule[];
|
| 95 |
anchorField?: { table: "same" | string; field: string; linkedVia?: string };
|
| 96 |
conditions?: RecurrenceCondition[];
|
| 97 |
ends?: RecurrenceEnds;
|
|
|
|
| 99 |
|
| 100 |
// The plain-language line the closed picker shows, so a person reads the schedule without
|
| 101 |
// reopening the editor. Commas and full stops only, and never a dash character.
|
| 102 |
+
function ruleSentence(rule: DateRule, calendars: CalendarOption[]): string {
|
| 103 |
const every = bounded(rule.interval ?? 1, 1, 366, 1);
|
| 104 |
const unit = (word: string) => (every === 1 ? word : `${every} ${word}s`);
|
| 105 |
const kind = ruleKind(rule);
|
|
|
|
| 116 |
if (kind === "holiday") {
|
| 117 |
const option = calendars.find((item) => item.code === (rule.calendar ?? "US"));
|
| 118 |
const relation = ["the day before", "the day of", "the day after"][bounded(rule.offset ?? 0, -1, 1, 0) + 1];
|
| 119 |
+
// W47-T28: on a holiday rule `interval` counts YEARS, which the card now says out loud, so
|
| 120 |
+
// the sentence says it too. At 1 the phrase is left exactly as it was, because every year is
|
| 121 |
+
// what a holiday rule already means and repeating it reads as noise.
|
| 122 |
+
const cadence = every === 1 ? "" : `, every ${every} years`;
|
| 123 |
// A single holiday reads as itself. "each holiday in Christmas Day" is what the calendar
|
| 124 |
// phrasing becomes once a rule can name one day, and it is not a sentence anybody wrote.
|
| 125 |
+
if (option?.group === "holiday") return `on ${relation} ${option.label}${cadence}`;
|
| 126 |
+
return `on ${relation} each holiday in ${option?.label ?? "public holidays"}${cadence}`;
|
| 127 |
+
}
|
| 128 |
+
if (kind === "anchored") {
|
| 129 |
+
// `unit()` above drops the count at 1, which reads right for "every day" and wrong for
|
| 130 |
+
// "1 day after", so an anchored rule spells its own phrase out.
|
| 131 |
+
const relation = rule.relation ?? "after";
|
| 132 |
+
if (relation === "on") return "on the anchor date";
|
| 133 |
+
return `${every} ${rule.unit ?? "day"}${every === 1 ? "" : "s"} ${relation} the anchor date`;
|
| 134 |
}
|
| 135 |
return `every ${unit("day")}`;
|
| 136 |
}
|
| 137 |
+
function recurrenceSentence(rules: DateRule[], ends: RecurrenceEnds, calendars: CalendarOption[]): string {
|
| 138 |
if (!rules.length) return "";
|
| 139 |
const body = rules.map((rule) => ruleSentence(rule, calendars)).join(", and ");
|
| 140 |
if (ends.kind === "on") return `Repeats ${body}, until ${ends.date}.`;
|
|
|
|
| 149 |
const selected = parseIso(value) ?? parseIso(today) ?? new Date();
|
| 150 |
const selectedIso = iso(selected);
|
| 151 |
const [cursor, setCursor] = useState(() => new Date(Date.UTC(selected.getUTCFullYear(), selected.getUTCMonth(), 1)));
|
| 152 |
+
const [rules, setRules] = useState<DateRule[]>(() => field.recurrence?.rules ?? []);
|
| 153 |
const [previewCount, setPreviewCount] = useState(() => field.recurrence?.previewCount ?? 10);
|
| 154 |
const [preview, setPreview] = useState<string[]>(() => field.recurrence?.preview ?? []);
|
| 155 |
const [nextDate, setNextDate] = useState<string | null | undefined>(() => field.recurrence?.nextDate);
|
| 156 |
const [calendars, setCalendars] = useState<CalendarOption[]>(DEFAULT_CALENDARS);
|
| 157 |
const [previewError, setPreviewError] = useState("");
|
| 158 |
+
// `?? undefined` is load-bearing: `LinkedRecurrence` now widens `rules`, so the assertion is
|
| 159 |
+
// only legal in the direction DateRecurrence -> LinkedRecurrence, and a `null` on the source
|
| 160 |
+
// side has no counterpart in the target union.
|
| 161 |
+
const storedRecurrence = (field.recurrence ?? undefined) as LinkedRecurrence | undefined;
|
| 162 |
const [anchorTable, setAnchorTable] = useState(() => storedRecurrence?.anchorField?.table ?? "same");
|
| 163 |
+
// W47-T24: the anchor DEFAULTS to this field's own column. `govern_date_recurrence` requires an
|
| 164 |
+
// `anchorField` on every recurrence it admits, and the picker used to emit none until somebody
|
| 165 |
+
// opened the old disclosure and picked one, so a fresh repeat previewed and saved as a 400.
|
| 166 |
+
const [anchorField, setAnchorField] = useState(() => storedRecurrence?.anchorField?.field ?? field.key);
|
| 167 |
const [linkedVia, setLinkedVia] = useState(() => storedRecurrence?.anchorField?.linkedVia ?? "");
|
| 168 |
const [conditions, setConditions] = useState<RecurrenceCondition[]>(() => storedRecurrence?.conditions ?? []);
|
| 169 |
const [ends, setEnds] = useState<RecurrenceEnds>(() => storedRecurrence?.ends ?? { kind: "never" });
|
| 170 |
// Step 1 is a plain date. The repeat editor is a second step in the SAME overlay, so the
|
| 171 |
// anchor block, the conditions and the rule rows leave the default path entirely.
|
| 172 |
const [step, setStep] = useState<"date" | "repeat">("date");
|
| 173 |
+
// W47-T24 (R1): the old disclosure is gone, wording and all. Its anchor and condition blocks now
|
| 174 |
+
// render inline, and the door that reveals them is the SAME "Add another rule" button that
|
| 175 |
+
// appends a repeat rule, so one affordance adds every kind of clause. Nothing about what a
|
| 176 |
+
// recurrence MEANS changed: this is placement only, and the affordance is built to hold a
|
| 177 |
+
// seventh choice.
|
| 178 |
+
const [showAnchor, setShowAnchor] = useState(false);
|
| 179 |
+
const [showConditions, setShowConditions] = useState(false);
|
| 180 |
+
const [chooserOpen, setChooserOpen] = useState(false);
|
| 181 |
+
const [restorePoint, setRestorePoint] = useState<null | { rules: DateRule[]; ends: RecurrenceEnds; anchorTable: string; anchorField: string; linkedVia: string; conditions: RecurrenceCondition[]; previewCount: number; showAnchor: boolean; showConditions: boolean }>(null);
|
| 182 |
const endsName = useId();
|
| 183 |
const dateFields = useMemo(() => fields.filter((candidate) => candidate.type === "date"), [fields]);
|
| 184 |
const linkedFields = useMemo(() => fields.filter((candidate) => candidate.type === "link" && candidate.link?.table), [fields]);
|
|
|
|
| 215 |
return () => controller.abort();
|
| 216 |
}, [recurrence]);
|
| 217 |
|
| 218 |
+
const updateRule = (index: number, patch: Partial<DateRule>) => setRules((current) => current.map((rule, item) => item === index ? { ...rule, ...patch } : rule));
|
| 219 |
const replaceKind = (index: number, kind: RuleKind) => setRules((current) => current.map((rule, item) => item === index ? newRule(kind, selected) : rule));
|
| 220 |
const toggleWeekday = (index: number, weekday: number, checked: boolean) => setRules((current) => current.map((rule, item) => {
|
| 221 |
if (item !== index) return rule;
|
|
|
|
| 224 |
return { ...rule, weekdays: weekdays.length ? weekdays : existing };
|
| 225 |
}));
|
| 226 |
const openEditor = () => {
|
| 227 |
+
setRestorePoint({ rules, ends, anchorTable, anchorField, linkedVia, conditions, previewCount, showAnchor, showConditions });
|
| 228 |
if (!rules.length) setRules([newRule("weekly", selected)]);
|
| 229 |
+
setChooserOpen(false);
|
| 230 |
setStep("repeat");
|
| 231 |
};
|
| 232 |
const cancelEditor = () => {
|
|
|
|
| 234 |
setRules(restorePoint.rules); setEnds(restorePoint.ends); setAnchorTable(restorePoint.anchorTable);
|
| 235 |
setAnchorField(restorePoint.anchorField); setLinkedVia(restorePoint.linkedVia);
|
| 236 |
setConditions(restorePoint.conditions); setPreviewCount(restorePoint.previewCount);
|
| 237 |
+
setShowAnchor(restorePoint.showAnchor); setShowConditions(restorePoint.showConditions);
|
| 238 |
}
|
| 239 |
setRestorePoint(null);
|
| 240 |
+
setChooserOpen(false);
|
| 241 |
setStep("date");
|
| 242 |
};
|
| 243 |
+
const saveEditor = () => { onRecurrence(recurrence as DateRecurrence | null); setRestorePoint(null); setChooserOpen(false); setStep("date"); };
|
| 244 |
+
const removeRepeat = () => { setRules([]); setEnds({ kind: "never" }); setConditions([]); setShowAnchor(false); setShowConditions(false); onRecurrence(null); setRestorePoint(null); setChooserOpen(false); setStep("date"); };
|
| 245 |
const monthStart = new Date(Date.UTC(cursor.getUTCFullYear(), cursor.getUTCMonth(), 1));
|
| 246 |
const leading = (monthStart.getUTCDay() + 6) % 7;
|
| 247 |
const days = new Date(Date.UTC(cursor.getUTCFullYear(), cursor.getUTCMonth() + 1, 0)).getUTCDate();
|
| 248 |
const cells = Array.from({ length: Math.ceil((leading + days) / 7) * 7 }, (_, index) => index - leading + 1);
|
| 249 |
const summary = recurrenceSentence(rules, ends, calendars);
|
| 250 |
+
// Each optional clause is on screen whenever it HOLDS something, or once the chooser opened it.
|
| 251 |
+
// The anchor holds something the moment it stops naming this field's own column.
|
| 252 |
+
const anchorShown = showAnchor || anchorTable !== "same" || anchorField !== field.key;
|
| 253 |
+
const conditionsShown = showConditions || conditions.length > 0;
|
| 254 |
|
| 255 |
// This is a body-portal overlay, so `cg-date-picker` alone only supplies its width and padding.
|
| 256 |
// Keep the shared `cg-pop` contract on the same element: it supplies the opaque surface, border,
|
|
|
|
| 277 |
<div className="cg-pop-title">Custom repeat</div>
|
| 278 |
</div>
|
| 279 |
{rules.map((rule, index) => <div className="w46-recur-card" key={`${rule.kind}-${index}`}>
|
| 280 |
+
{/* W47-T25: an anchored rule gets its OWN first row. `RULE_KINDS` deliberately stays at
|
| 281 |
+
six, so feeding "anchored" to the kind select would render a control whose value
|
| 282 |
+
matches no option and whose first interaction silently rewrites the rule. */}
|
| 283 |
+
{rule.kind === "anchored" ? <>
|
| 284 |
+
<div className="w46-recur-row">
|
| 285 |
+
<span className="w46-recur-label">Date is</span>
|
| 286 |
+
<div className="w46-recur-controls">
|
| 287 |
+
{(rule.relation ?? "after") !== "on" && <>
|
| 288 |
+
<input className="cg-input w46-recur-count" min="1" max="366" type="number" aria-label={`Distance from the anchor ${index + 1}`} value={rule.interval ?? 1} onChange={(event) => updateRule(index, { interval: bounded(event.target.value, 1, 366, 1) })} />
|
| 289 |
+
<select className="cg-select" value={rule.unit ?? "day"} aria-label={`Distance unit ${index + 1}`} onChange={(event) => updateRule(index, { unit: event.target.value as AnchoredUnit })}><option value="day">days</option><option value="week">weeks</option><option value="month">months</option></select>
|
| 290 |
+
</>}
|
| 291 |
+
{/* Switching to "on" carries `interval: 1` with it. The count input goes away, and a
|
| 292 |
+
stale 5 left behind it would be saved and then read back as a distance nobody
|
| 293 |
+
can see. */}
|
| 294 |
+
<select className="cg-select" value={rule.relation ?? "after"} aria-label={`Anchor relation ${index + 1}`} onChange={(event) => {
|
| 295 |
+
const relation = event.target.value as AnchoredRelation;
|
| 296 |
+
updateRule(index, relation === "on" ? { relation, interval: 1 } : { relation });
|
| 297 |
+
}}><option value="on">on the anchor date</option><option value="after">after the anchor date</option><option value="before">before the anchor date</option></select>
|
| 298 |
+
</div>
|
| 299 |
+
</div>
|
| 300 |
+
{anchorField === field.key && <div className="w46-recur-row"><span className="w46-recur-word">Choose the date field this counts from.</span></div>}
|
| 301 |
+
{(rule.relation ?? "after") === "before" && <div className="w46-recur-row"><span className="w46-recur-word">A date that has already passed is left empty.</span></div>}
|
| 302 |
+
</> : rule.kind === "holiday" ? <>
|
| 303 |
+
{/* W47-T28 (R8): a holiday rule gets its OWN first row for the same reason. The generic
|
| 304 |
+
row read "Repeat every 1 holiday", which says nothing a person can act on and hides
|
| 305 |
+
what `interval` means here: the server counts YEARS on this kind
|
| 306 |
+
(`(holiday_year - start.year) % rule['interval']` in `recurrence_preview`), so the
|
| 307 |
+
row says the word year out loud. The two selects below are the wave-46 ones, moved
|
| 308 |
+
and not rewritten; the grouping keeps single days out of the federal calendars. */}
|
| 309 |
+
<div className="w46-recur-row">
|
| 310 |
+
<span className="w46-recur-label">Holidays</span>
|
| 311 |
+
<div className="w46-recur-controls">
|
| 312 |
+
<select className="cg-select" value={rule.calendar ?? "US"} aria-label="Public calendar" onChange={(event) => updateRule(index, { calendar: event.target.value as "US" | "CA" })}>{CALENDAR_GROUPS.map(([group, heading]) => {
|
| 313 |
+
const members = calendars.filter((calendar) => (calendar.group ?? "calendar") === group);
|
| 314 |
+
return members.length ? <optgroup key={heading} label={heading}>{members.map((calendar) => <option key={calendar.code} value={calendar.code}>{calendar.label}</option>)}</optgroup> : null;
|
| 315 |
+
})}</select>
|
| 316 |
+
<select className="cg-select" value={rule.offset ?? 0} aria-label="Holiday relation" onChange={(event) => updateRule(index, { offset: Number(event.target.value) as -1 | 0 | 1 })}><option value={-1}>Day before</option><option value={0}>Day on</option><option value={1}>Day after</option></select>
|
| 317 |
+
</div>
|
| 318 |
+
</div>
|
| 319 |
+
<div className="w46-recur-row">
|
| 320 |
+
<span className="w46-recur-label">Repeat every</span>
|
| 321 |
+
<div className="w46-recur-controls">
|
| 322 |
+
<input className="cg-input w46-recur-count" min="1" max="366" type="number" aria-label={`Repeat interval ${index + 1}`} value={rule.interval ?? 1} onChange={(event) => updateRule(index, { interval: bounded(event.target.value, 1, 366, 1) })} />
|
| 323 |
+
<span className="w46-recur-word">{bounded(rule.interval ?? 1, 1, 366, 1) === 1 ? "year" : "years"}</span>
|
| 324 |
+
</div>
|
| 325 |
+
</div>
|
| 326 |
+
</> : <div className="w46-recur-row">
|
| 327 |
<span className="w46-recur-label">Repeat every</span>
|
| 328 |
<div className="w46-recur-controls">
|
| 329 |
<input className="cg-input w46-recur-count" min="1" max="366" type="number" aria-label={`Repeat interval ${index + 1}`} value={rule.interval ?? 1} onChange={(event) => updateRule(index, { interval: bounded(event.target.value, 1, 366, 1) })} />
|
| 330 |
<select className="cg-select" value={ruleKind(rule)} aria-label={`Repeat unit ${index + 1}`} onChange={(event) => replaceKind(index, event.target.value as RuleKind)}>{RULE_KINDS.map((kind) => <option key={kind} value={kind}>{labelForKind(kind)}</option>)}</select>
|
| 331 |
</div>
|
| 332 |
+
</div>}
|
| 333 |
{rule.kind === "weekly" && <div className="w46-recur-row">
|
| 334 |
<span className="w46-recur-label" id={`${endsName}-days-${index}`}>Repeat on</span>
|
| 335 |
<div className="w46-recur-pills" role="group" aria-labelledby={`${endsName}-days-${index}`}>{WEEKDAY_INITIALS.map((initial, weekday) => {
|
|
|
|
| 355 |
<input className="cg-input w46-recur-count" min="1" max="31" type="number" aria-label="Day of the month" value={rule.day ?? 1} onChange={(event) => updateRule(index, { day: bounded(event.target.value, 1, 31, 1) })} />
|
| 356 |
</div>
|
| 357 |
</div>}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 358 |
{rules.length > 1 && <div className="w46-recur-card-foot"><button type="button" className="w46-recur-quiet" onClick={() => setRules((current) => current.filter((_, item) => item !== index))}>Remove rule</button></div>}
|
| 359 |
</div>)}
|
| 360 |
+
{anchorShown && <div className="cg-date-boundary" aria-label="Recurrence anchor">
|
| 361 |
+
<label>Anchor database<select className="cg-select" value={anchorTable} onChange={(event) => {
|
| 362 |
+
const table = event.target.value;
|
| 363 |
+
setAnchorTable(table);
|
| 364 |
+
if (table === "same") setLinkedVia("");
|
| 365 |
+
else setLinkedVia(linkedFields.find((candidate) => candidate.link?.table === table)?.key ?? "");
|
| 366 |
+
setAnchorField(table === "same" ? field.key : "");
|
| 367 |
+
}}><option value="same">This database</option>{linkedFields.map((candidate) => <option value={candidate.link!.table} key={candidate.key}>{candidate.label} Β· {candidate.link!.table}</option>)}</select></label>
|
| 368 |
+
{anchorTable === "same" ? <label>Date field<select className="cg-select" value={anchorField} onChange={(event) => setAnchorField(event.target.value)}><option value={field.key}>This date</option>{dateFields.filter((candidate) => candidate.key !== field.key).map((candidate) => <option value={candidate.key} key={candidate.key}>{candidate.label}</option>)}</select></label>
|
| 369 |
+
: <><label>Linked through<select className="cg-select" value={linkedVia} onChange={(event) => setLinkedVia(event.target.value)}>{linkedFields.filter((candidate) => candidate.link?.table === anchorTable).map((candidate) => <option value={candidate.key} key={candidate.key}>{candidate.label}</option>)}</select></label><label>Linked date field key<input className="cg-input" value={anchorField} onChange={(event) => setAnchorField(event.target.value)} placeholder="due_date" /></label></>}
|
| 370 |
+
</div>}
|
| 371 |
+
{conditionsShown && <div className="cg-date-boundary" aria-label="Recurrence conditions"><div className="cg-pop-title">Only when</div>{conditions.map((condition, index) => <div className="cg-date-holidays" key={`${condition.colId}-${index}`}><select className="cg-select" aria-label={`Condition field ${index + 1}`} value={condition.colId} onChange={(event) => setConditions((current) => current.map((item, itemIndex) => itemIndex === index ? { ...item, colId: event.target.value } : item))}>{fields.map((candidate) => <option key={candidate.key} value={candidate.key}>{candidate.label}</option>)}</select><select className="cg-select" aria-label={`Condition operator ${index + 1}`} value={condition.op} onChange={(event) => setConditions((current) => current.map((item, itemIndex) => itemIndex === index ? { ...item, op: event.target.value as RecurrenceCondition["op"], ...(event.target.value === "between" ? {} : { value2: undefined }) } : item))}><option value="eq">is</option><option value="neq">is not</option><option value="not_empty">is not empty</option><option value="between">is between</option></select>{condition.op !== "not_empty" && <input className="cg-input" aria-label={`Condition value ${index + 1}`} value={condition.value} onChange={(event) => setConditions((current) => current.map((item, itemIndex) => itemIndex === index ? { ...item, value: event.target.value } : item))} />}{condition.op === "between" && <input className="cg-input" aria-label={`Condition second value ${index + 1}`} value={condition.value2 ?? ""} onChange={(event) => setConditions((current) => current.map((item, itemIndex) => itemIndex === index ? { ...item, value2: event.target.value } : item))} />}<button type="button" className="cg-link-btn" onClick={() => setConditions((current) => current.filter((_, itemIndex) => itemIndex !== index))}>Remove</button></div>)}<button type="button" className="cg-link-btn" disabled={!fields.length} onClick={() => setConditions((current) => [...current, { colId: fields[0]?.key ?? "", op: "eq", value: "" }])}>+ Add condition</button></div>}
|
| 372 |
+
<button type="button" className="w46-recur-add" aria-expanded={chooserOpen} onClick={() => setChooserOpen((open) => !open)}>Add another rule</button>
|
| 373 |
+
{chooserOpen && <div className="w46-recur-card">
|
| 374 |
+
<div className="w46-recur-controls" role="group" aria-label="Add another rule">
|
| 375 |
+
{/* W47-T25: an anchored rule is meaningless without an anchor that is not this field's
|
| 376 |
+
own column, so choosing it puts the anchor block on screen in the same click. */}
|
| 377 |
+
{ADD_KINDS.map(([kind, label]) => <button key={kind} type="button" className="cg-link-btn" onClick={() => { setRules((current) => [...current, newRule(kind, selected)]); if (kind === "anchored") setShowAnchor(true); setChooserOpen(false); }}>{label}</button>)}
|
| 378 |
+
{!anchorShown && <button type="button" className="cg-link-btn" onClick={() => { setShowAnchor(true); setChooserOpen(false); }}>Anchor to another date field</button>}
|
| 379 |
+
<button type="button" className="cg-link-btn" disabled={!fields.length} onClick={() => {
|
| 380 |
+
setConditions((current) => [...current, { colId: fields[0]?.key ?? "", op: "eq", value: "" }]);
|
| 381 |
+
setShowConditions(true); setChooserOpen(false);
|
| 382 |
+
}}>Only when a condition is met</button>
|
| 383 |
+
</div>
|
| 384 |
+
</div>}
|
| 385 |
<div className="w46-recur-row">
|
| 386 |
<span className="w46-recur-label" id={`${endsName}-label`}>Ends</span>
|
| 387 |
<div className="w46-recur-ends" role="group" aria-labelledby={`${endsName}-label`}>
|
|
|
|
| 392 |
<input className="cg-input w46-recur-count" type="number" min="1" max="365" aria-label="Number of occurrences" disabled={ends.kind !== "after"} value={ends.kind === "after" ? ends.count : ""} onChange={(event) => setEnds({ kind: "after", count: bounded(event.target.value, 1, 365, 13) })} /><span className="w46-recur-word">occurrences</span></label>
|
| 393 |
</div>
|
| 394 |
</div>
|
| 395 |
+
{/* W47-T24: "Show next N dates" is a display control, not a clause of the recurrence, so it
|
| 396 |
+
reads beside the preview it sizes rather than behind the door that adds rules. */}
|
| 397 |
+
<div className="cg-date-preview" aria-live="polite"><div className="cg-pop-title">Next dates{nextDate ? ` Β· next ${nextDate}` : ""}<label className="w46-recur-preview-count">Show next <select className="cg-select" value={previewCount} aria-label="Number of preview dates" onChange={(event) => setPreviewCount(bounded(event.target.value, 1, 50, 10))}>{[3, 5, 10, 20, 50].map((count) => <option key={count} value={count}>{count}</option>)}</select> dates</label></div>{preview.map((date) => <span key={date}>{date}</span>)}{rules.length > 0 && !preview.length && !previewError && <span>Calculating the server previewβ¦</span>}{previewError && <span role="status">{previewError}</span>}</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 398 |
<div className="w46-recur-foot">
|
| 399 |
{storedRecurrence?.rules?.length ? <button type="button" className="w46-recur-quiet is-danger" onClick={removeRepeat}>Remove repeat</button> : null}
|
| 400 |
<button type="button" className="w46-recur-quiet" onClick={cancelEditor}>Cancel</button>
|
web/src/customer-grid/MapView.tsx
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
web/src/customer-grid/RecordDetail.css
CHANGED
|
@@ -1054,3 +1054,156 @@
|
|
| 1054 |
animation: none;
|
| 1055 |
}
|
| 1056 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1054 |
animation: none;
|
| 1055 |
}
|
| 1056 |
}
|
| 1057 |
+
|
| 1058 |
+
/* ββ W47-T15 (owner instruction 17) β THE WORKSPACE NOTES PANEL, IN THE COMMENT LANGUAGE.
|
| 1059 |
+
Owner: "the UI/UX should be just like a comment, we already have that nice UI/UX for comment
|
| 1060 |
+
under the record detail view. Just copy it for godsake." So the note reuses the record-comment
|
| 1061 |
+
anatomy above (`cg-record-comment`, `-avatar`, `-content`, `-meta`, `-compose`, `-compose-foot`)
|
| 1062 |
+
and adds only what the drawer needs that a comment column does not.
|
| 1063 |
+
|
| 1064 |
+
β IT DELIBERATELY DOES NOT WEAR `.cg-record-comments`. That wrapper carries its own
|
| 1065 |
+
`border-left` and `--lp-wash` background for a column inside the record modal;
|
| 1066 |
+
`.cg-workspace-drawer` (styles/wave45/data-applications.css) already supplies the surface,
|
| 1067 |
+
border and padding here, and stacking both would be the card-in-card DESIGN.md section 4 bans.
|
| 1068 |
+
|
| 1069 |
+
β THE TABS EXISTED WITH NO RULE AT ALL. The old markup used `.cg-segmented`, and the ONLY
|
| 1070 |
+
selectors in the tree are `.cg-segmented-path` (index.css, styles/wave46/rail-select.css) β
|
| 1071 |
+
a different component. So those two buttons were rendering as raw user-agent chrome with a
|
| 1072 |
+
default border and grey fill: that is precisely the "buttons unbranded" the owner photographed
|
| 1073 |
+
in ERROR 17.png, and it is why a rule of their own is part of the fix rather than decoration.
|
| 1074 |
+
Base rule resets native chrome per DESIGN.md section 4. */
|
| 1075 |
+
.cg-note-tabs {
|
| 1076 |
+
display: flex;
|
| 1077 |
+
gap: 4px;
|
| 1078 |
+
margin-bottom: 12px;
|
| 1079 |
+
}
|
| 1080 |
+
|
| 1081 |
+
.cg-note-tab {
|
| 1082 |
+
flex: 1 1 0;
|
| 1083 |
+
padding: 6px 10px;
|
| 1084 |
+
border: 0;
|
| 1085 |
+
border-radius: var(--lp-r-md);
|
| 1086 |
+
background: transparent;
|
| 1087 |
+
color: var(--lp-muted);
|
| 1088 |
+
font: inherit;
|
| 1089 |
+
font-size: var(--lp-fs-2xs);
|
| 1090 |
+
font-weight: 600;
|
| 1091 |
+
cursor: pointer;
|
| 1092 |
+
}
|
| 1093 |
+
|
| 1094 |
+
.cg-note-tab:hover {
|
| 1095 |
+
background: var(--lp-surface-2);
|
| 1096 |
+
color: var(--lp-ink);
|
| 1097 |
+
}
|
| 1098 |
+
|
| 1099 |
+
.cg-note-tab[aria-pressed="true"] {
|
| 1100 |
+
background: var(--lp-blue-tint);
|
| 1101 |
+
color: var(--lp-blue-deep);
|
| 1102 |
+
}
|
| 1103 |
+
|
| 1104 |
+
.cg-note-tab:focus-visible {
|
| 1105 |
+
outline: 2px solid var(--lp-blue-deep);
|
| 1106 |
+
outline-offset: -1px;
|
| 1107 |
+
}
|
| 1108 |
+
|
| 1109 |
+
.cg-note-feed {
|
| 1110 |
+
margin-bottom: 4px;
|
| 1111 |
+
}
|
| 1112 |
+
|
| 1113 |
+
/* The composer sits flush in the drawer, which already pads itself. */
|
| 1114 |
+
.cg-note-compose {
|
| 1115 |
+
padding: 12px 0 0;
|
| 1116 |
+
}
|
| 1117 |
+
|
| 1118 |
+
/* ββ SPECIFICITY, NOT TIDINESS, AND IT IS LOAD-BEARING.
|
| 1119 |
+
`styles/wave45/data-applications.css` carries `.cg-workspace-drawer textarea { min-height:220px;
|
| 1120 |
+
margin-bottom:10px; ... }`. That selector is (0,1,1) and so is `.cg-record-comment-compose
|
| 1121 |
+
textarea`, so the two TIE β and ties break on source order. `CustomerGrid.tsx` imports
|
| 1122 |
+
`RecordDetail` (line 85) before `data-applications.css` (line 114), so THIS file is emitted
|
| 1123 |
+
FIRST and LOSES. Naming the element's own class as well makes this (0,2,1), which wins on
|
| 1124 |
+
specificity and therefore does not depend on import order at all. Do not "simplify" it back to
|
| 1125 |
+
a single class: the composer silently grows a 220px box again and the panel stops matching the
|
| 1126 |
+
comment it was asked to copy. */
|
| 1127 |
+
.cg-note-compose textarea.cg-note-input {
|
| 1128 |
+
width: 100%;
|
| 1129 |
+
min-height: 96px;
|
| 1130 |
+
max-height: 220px;
|
| 1131 |
+
margin-bottom: 0;
|
| 1132 |
+
resize: vertical;
|
| 1133 |
+
padding: 9px 10px;
|
| 1134 |
+
border: 1px solid var(--lp-line);
|
| 1135 |
+
border-radius: var(--lp-r-md);
|
| 1136 |
+
background: var(--lp-surface);
|
| 1137 |
+
color: var(--lp-ink);
|
| 1138 |
+
font: inherit;
|
| 1139 |
+
font-size: var(--lp-fs-2xs);
|
| 1140 |
+
line-height: 1.45;
|
| 1141 |
+
}
|
| 1142 |
+
|
| 1143 |
+
.cg-note-compose textarea.cg-note-input:focus {
|
| 1144 |
+
outline: 2px solid var(--lp-blue-deep);
|
| 1145 |
+
outline-offset: -1px;
|
| 1146 |
+
border-color: transparent;
|
| 1147 |
+
}
|
| 1148 |
+
|
| 1149 |
+
/* ββ W47-T16 (owner instruction 19) β THE UNREAD MARK, AND THE NOTE'S EDIT DOOR.
|
| 1150 |
+
β WHY THE BADGE'S RULE LIVES IN THIS FILE and not beside the toolbar's other controls: lane C's
|
| 1151 |
+
fence this wave contains exactly one stylesheet, this one. `index.css` and
|
| 1152 |
+
`styles/wave46/chrome.css` belong to nobody's fence and `styles/wave45/data-applications.css` is
|
| 1153 |
+
lane A's. CSS is global, so the rule works from here; it is filed under the notes block it
|
| 1154 |
+
belongs to rather than smuggled into a sheet this lane may not write. A later wave that owns the
|
| 1155 |
+
toolbar sheet should move it, and this comment is the note to do so.
|
| 1156 |
+
β NO absolute positioning and no overlap: the badge is a FLEX SIBLING after the glyph, inside
|
| 1157 |
+
the button. `.cg-tb-btn` sets no containing block, and a badge pinned to a corner would need one,
|
| 1158 |
+
so it would have drifted the moment the toolbar re-flowed. */
|
| 1159 |
+
.cg-notes-badge {
|
| 1160 |
+
display: inline-flex;
|
| 1161 |
+
align-items: center;
|
| 1162 |
+
justify-content: center;
|
| 1163 |
+
min-width: 16px;
|
| 1164 |
+
height: 16px;
|
| 1165 |
+
padding: 0 4px;
|
| 1166 |
+
margin-left: 5px;
|
| 1167 |
+
border-radius: var(--lp-r-pill);
|
| 1168 |
+
background: var(--lp-blue-solid);
|
| 1169 |
+
color: #fff;
|
| 1170 |
+
font-size: var(--lp-fs-4xs);
|
| 1171 |
+
font-weight: 700;
|
| 1172 |
+
line-height: 1;
|
| 1173 |
+
}
|
| 1174 |
+
|
| 1175 |
+
/* The edit door rides the comment meta row, exactly where `RecordComments` puts its delete
|
| 1176 |
+
control, so the note keeps the anatomy instruction 17 asked it to copy. It is a QUIET button
|
| 1177 |
+
(DESIGN.md section 4): muted ink, wash on hover, no chrome at rest. It is not destructive and
|
| 1178 |
+
must never take the red the delete control uses. */
|
| 1179 |
+
.cg-note-edit,
|
| 1180 |
+
.cg-note-cancel {
|
| 1181 |
+
margin-left: auto;
|
| 1182 |
+
padding: 2px 6px;
|
| 1183 |
+
border: 0;
|
| 1184 |
+
border-radius: var(--lp-r-md);
|
| 1185 |
+
background: transparent;
|
| 1186 |
+
color: var(--lp-muted);
|
| 1187 |
+
font: inherit;
|
| 1188 |
+
font-size: var(--lp-fs-3xs);
|
| 1189 |
+
font-weight: 600;
|
| 1190 |
+
cursor: pointer;
|
| 1191 |
+
}
|
| 1192 |
+
|
| 1193 |
+
.cg-note-edit:hover,
|
| 1194 |
+
.cg-note-cancel:hover {
|
| 1195 |
+
background: var(--lp-surface-2);
|
| 1196 |
+
color: var(--lp-ink);
|
| 1197 |
+
}
|
| 1198 |
+
|
| 1199 |
+
.cg-note-edit:focus-visible,
|
| 1200 |
+
.cg-note-cancel:focus-visible {
|
| 1201 |
+
outline: 2px solid var(--lp-blue-deep);
|
| 1202 |
+
outline-offset: -1px;
|
| 1203 |
+
}
|
| 1204 |
+
|
| 1205 |
+
/* In the composer foot the Cancel sits beside the submit, not pushed away from it. */
|
| 1206 |
+
.cg-record-comment-compose-foot .cg-note-cancel {
|
| 1207 |
+
margin-left: auto;
|
| 1208 |
+
margin-right: 6px;
|
| 1209 |
+
}
|
web/src/customer-grid/RouteNav.tsx
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
web/src/customer-grid/SavedChartNav.tsx
ADDED
|
@@ -0,0 +1,412 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* SavedChartNav.tsx β W47-T31 (owner R7, contract C6): the Time series view's right-side
|
| 3 |
+
* navigator over SAVED CHARTS.
|
| 4 |
+
*
|
| 5 |
+
* β **A SAVED CHART IS A RECORD, NOT A VIEW SETTING (C6).** It carries its own id, name and
|
| 6 |
+
* owner on the server (`/api/v1/charts`, `core.chart_system`) and is listed independently of
|
| 7 |
+
* `ws["views"]`. That is the whole point of R7, in the owner's words: *"every interface like
|
| 8 |
+
* chart, swap etc. that we need to configure should act like route with the right side
|
| 9 |
+
* navigation to choose the specific view we want to see. So its not pegged on a per view
|
| 10 |
+
* basis."* Deleting a view therefore cannot delete a chart, and one chart is reachable from
|
| 11 |
+
* every view on the same database.
|
| 12 |
+
*
|
| 13 |
+
* β THIS FILE OWNS NO DISPLAY STATE. `TimeSeriesPanel` is fully controlled by its `display`
|
| 14 |
+
* prop, so "open this chart" is exactly one `onApply(...)` call that the panel forwards to
|
| 15 |
+
* `onDisplay`. A second copy of the bucket/span/field state here would be a second answer to
|
| 16 |
+
* the question the view already answers, and the two would drift on the first save.
|
| 17 |
+
*
|
| 18 |
+
* β NO STYLESHEET OF ITS OWN, ON PURPOSE. `.cg-workspace-drawer` is the shipped right-side
|
| 19 |
+
* drawer idiom (`styles/wave45/data-applications.css`, imported by `CustomerGrid.tsx`) and
|
| 20 |
+
* `.cg-history-list` is that drawer's own list rule: a bordered row of `1fr auto`, which is a
|
| 21 |
+
* name on the left and its actions on the right. Both are reused rather than re-declared, so
|
| 22 |
+
* this navigator cannot drift from the drawer beside it and `verify_reachability`'s
|
| 23 |
+
* orphan-stylesheet lens has nothing new to find. The `cg-history-list` NAME is inherited from
|
| 24 |
+
* its first caller and describes its shape, not its subject.
|
| 25 |
+
*/
|
| 26 |
+
import { useCallback, useEffect, useState } from "react";
|
| 27 |
+
import { API_V1, CREDENTIALS } from "../apiContract";
|
| 28 |
+
import { MenuIcon } from "./icons";
|
| 29 |
+
import { cleanDisplay } from "./types";
|
| 30 |
+
import type { DisplaySpec } from "./types";
|
| 31 |
+
|
| 32 |
+
/**
|
| 33 |
+
* The display keys a time-series chart owns, and the ONLY ones it may write back.
|
| 34 |
+
*
|
| 35 |
+
* β EVERY KEY IS ALWAYS PRESENT, `undefined` when the chart does not carry it. The host merges
|
| 36 |
+
* with `{ ...spec, ...next }` and persists through `JSON.stringify`, so an explicitly
|
| 37 |
+
* `undefined` key DELETES the stored one. Omitting a key instead would leave a toggle from the
|
| 38 |
+
* previously loaded chart switched on under a configuration that never asked for it.
|
| 39 |
+
*/
|
| 40 |
+
export type TsChartConfig = Pick<
|
| 41 |
+
DisplaySpec,
|
| 42 |
+
| "tsFields"
|
| 43 |
+
| "tsBucket"
|
| 44 |
+
| "tsSpan"
|
| 45 |
+
| "tsDeltas"
|
| 46 |
+
| "tsStyles"
|
| 47 |
+
| "tsGridlines"
|
| 48 |
+
| "tsSparkline"
|
| 49 |
+
| "tsRows"
|
| 50 |
+
>;
|
| 51 |
+
|
| 52 |
+
/** One row of `GET /api/v1/charts`, after narrowing. `config` stays opaque here (C6). */
|
| 53 |
+
export interface SavedChartRecord {
|
| 54 |
+
id: string;
|
| 55 |
+
name: string;
|
| 56 |
+
database: string;
|
| 57 |
+
kind: string;
|
| 58 |
+
config: Record<string, unknown>;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
/** `chart_system._MAX_NAME`. Said here so the field stops the user rather than the server. */
|
| 62 |
+
const NAME_MAX = 120;
|
| 63 |
+
const CHART_KIND = "timeseries";
|
| 64 |
+
const JSON_HEADERS = { "Content-Type": "application/json" };
|
| 65 |
+
|
| 66 |
+
const LOAD_FAILED = "Saved charts could not be loaded.";
|
| 67 |
+
|
| 68 |
+
/**
|
| 69 |
+
* A stored config, narrowed into the eight keys this panel owns.
|
| 70 |
+
*
|
| 71 |
+
* β `cleanDisplay` IS THE NARROWER, rather than a second validator written here. It is the
|
| 72 |
+
* same function the View reader uses, it already knows every asymmetry these keys carry
|
| 73 |
+
* (`tsGridlines` is the literal `false`, `tsSparkline` the literal `true`, `tsSpan.lastN` is
|
| 74 |
+
* bounded), and a private copy would be a second set of rules for one question. It needs a
|
| 75 |
+
* legal `mode` to return anything at all, so one is supplied: the record's `kind` already says
|
| 76 |
+
* what this config is, and the stored blob is not required to repeat it.
|
| 77 |
+
*/
|
| 78 |
+
export function tsChartConfigFrom(raw: unknown): TsChartConfig {
|
| 79 |
+
const source = raw && typeof raw === "object" && !Array.isArray(raw)
|
| 80 |
+
? (raw as Record<string, unknown>)
|
| 81 |
+
: {};
|
| 82 |
+
const spec = cleanDisplay({ ...source, mode: "timeseries" });
|
| 83 |
+
return {
|
| 84 |
+
tsFields: spec?.tsFields,
|
| 85 |
+
tsBucket: spec?.tsBucket,
|
| 86 |
+
tsSpan: spec?.tsSpan,
|
| 87 |
+
tsDeltas: spec?.tsDeltas,
|
| 88 |
+
tsStyles: spec?.tsStyles,
|
| 89 |
+
tsGridlines: spec?.tsGridlines,
|
| 90 |
+
tsSparkline: spec?.tsSparkline,
|
| 91 |
+
tsRows: spec?.tsRows,
|
| 92 |
+
};
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
function readChart(raw: unknown): SavedChartRecord | null {
|
| 96 |
+
if (!raw || typeof raw !== "object") return null;
|
| 97 |
+
const row = raw as Record<string, unknown>;
|
| 98 |
+
const id = typeof row.id === "string" ? row.id : "";
|
| 99 |
+
const name = typeof row.name === "string" ? row.name : "";
|
| 100 |
+
if (!id || !name) return null;
|
| 101 |
+
return {
|
| 102 |
+
id,
|
| 103 |
+
name,
|
| 104 |
+
database: typeof row.database === "string" ? row.database : "",
|
| 105 |
+
kind: typeof row.kind === "string" ? row.kind : CHART_KIND,
|
| 106 |
+
config: row.config && typeof row.config === "object" && !Array.isArray(row.config)
|
| 107 |
+
? (row.config as Record<string, unknown>)
|
| 108 |
+
: {},
|
| 109 |
+
};
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
export interface SavedChartNavProps {
|
| 113 |
+
/** The DATABASE key these charts belong to, never a `SurfaceScope`. */
|
| 114 |
+
database: string;
|
| 115 |
+
/** The configuration a save would capture: the RESOLVED one now on screen. */
|
| 116 |
+
current: TsChartConfig;
|
| 117 |
+
/** Apply a saved chart. Always receives all eight keys, so stale ones are cleared. */
|
| 118 |
+
onApply: (config: TsChartConfig) => void;
|
| 119 |
+
/** The id last applied from here, so the list can say which chart is on screen. */
|
| 120 |
+
activeId: string | null;
|
| 121 |
+
onActiveId: (id: string | null) => void;
|
| 122 |
+
onClose: () => void;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
export default function SavedChartNav({
|
| 126 |
+
database,
|
| 127 |
+
current,
|
| 128 |
+
onApply,
|
| 129 |
+
activeId,
|
| 130 |
+
onActiveId,
|
| 131 |
+
onClose,
|
| 132 |
+
}: SavedChartNavProps) {
|
| 133 |
+
const [charts, setCharts] = useState<SavedChartRecord[]>([]);
|
| 134 |
+
const [loading, setLoading] = useState(false);
|
| 135 |
+
const [error, setError] = useState("");
|
| 136 |
+
const [busy, setBusy] = useState(false);
|
| 137 |
+
const [reload, setReload] = useState(0);
|
| 138 |
+
const [newName, setNewName] = useState("");
|
| 139 |
+
const [renaming, setRenaming] = useState<string | null>(null);
|
| 140 |
+
const [renameText, setRenameText] = useState("");
|
| 141 |
+
const [deleting, setDeleting] = useState<string | null>(null);
|
| 142 |
+
|
| 143 |
+
// The list is re-keyed on `database`: switching grids asks a different question, and showing
|
| 144 |
+
// the previous database's charts for one paint would invite a click that then 403s.
|
| 145 |
+
useEffect(() => {
|
| 146 |
+
if (!database) {
|
| 147 |
+
setCharts([]);
|
| 148 |
+
return;
|
| 149 |
+
}
|
| 150 |
+
const controller = new AbortController();
|
| 151 |
+
setLoading(true);
|
| 152 |
+
void fetch(`${API_V1}/charts?database=${encodeURIComponent(database)}`, {
|
| 153 |
+
credentials: CREDENTIALS,
|
| 154 |
+
signal: controller.signal,
|
| 155 |
+
})
|
| 156 |
+
.then(async (response) => ({ ok: response.ok, body: await response.json().catch(() => ({})) }))
|
| 157 |
+
.then(({ ok, body }) => {
|
| 158 |
+
if (controller.signal.aborted) return;
|
| 159 |
+
if (!ok) {
|
| 160 |
+
setCharts([]);
|
| 161 |
+
setError(LOAD_FAILED);
|
| 162 |
+
return;
|
| 163 |
+
}
|
| 164 |
+
const rows = Array.isArray((body as { charts?: unknown })?.charts)
|
| 165 |
+
? ((body as { charts: unknown[] }).charts)
|
| 166 |
+
: [];
|
| 167 |
+
setCharts(rows.map(readChart).filter((row): row is SavedChartRecord => row !== null));
|
| 168 |
+
setError("");
|
| 169 |
+
})
|
| 170 |
+
.catch(() => {
|
| 171 |
+
if (!controller.signal.aborted) setError(LOAD_FAILED);
|
| 172 |
+
})
|
| 173 |
+
.finally(() => {
|
| 174 |
+
if (!controller.signal.aborted) setLoading(false);
|
| 175 |
+
});
|
| 176 |
+
return () => controller.abort();
|
| 177 |
+
}, [database, reload]);
|
| 178 |
+
|
| 179 |
+
const refresh = useCallback(() => setReload((n) => n + 1), []);
|
| 180 |
+
|
| 181 |
+
/**
|
| 182 |
+
* Create. β NO `id` IN THE BODY: the server refuses one with `server_managed_chart_id`,
|
| 183 |
+
* deliberately, so that POST cannot become an undocumented update door.
|
| 184 |
+
*
|
| 185 |
+
* The list is REFETCHED rather than prepended. The server sorts by name then id, so a
|
| 186 |
+
* prepended row would sit somewhere the next reload does not reproduce.
|
| 187 |
+
*/
|
| 188 |
+
const save = useCallback(async () => {
|
| 189 |
+
const name = newName.trim().slice(0, NAME_MAX);
|
| 190 |
+
if (!name || !database) return;
|
| 191 |
+
setBusy(true);
|
| 192 |
+
try {
|
| 193 |
+
const response = await fetch(`${API_V1}/charts`, {
|
| 194 |
+
method: "POST",
|
| 195 |
+
credentials: CREDENTIALS,
|
| 196 |
+
headers: JSON_HEADERS,
|
| 197 |
+
body: JSON.stringify({ kind: CHART_KIND, database, name, config: current }),
|
| 198 |
+
});
|
| 199 |
+
if (!response.ok) {
|
| 200 |
+
setError("That chart could not be saved. Nothing was stored.");
|
| 201 |
+
return;
|
| 202 |
+
}
|
| 203 |
+
const body = await response.json().catch(() => ({}));
|
| 204 |
+
const made = readChart((body as { chart?: unknown })?.chart);
|
| 205 |
+
if (made) onActiveId(made.id);
|
| 206 |
+
setNewName("");
|
| 207 |
+
setError("");
|
| 208 |
+
refresh();
|
| 209 |
+
} catch {
|
| 210 |
+
setError("That chart could not be saved. Nothing was stored.");
|
| 211 |
+
} finally {
|
| 212 |
+
setBusy(false);
|
| 213 |
+
}
|
| 214 |
+
}, [current, database, newName, onActiveId, refresh]);
|
| 215 |
+
|
| 216 |
+
/** Rename. β `database` is never sent: the server holds it prior-wins and a payload naming
|
| 217 |
+
* another one would be a permission escape rather than a move. */
|
| 218 |
+
const rename = useCallback(async (chart: SavedChartRecord) => {
|
| 219 |
+
const name = renameText.trim().slice(0, NAME_MAX);
|
| 220 |
+
if (!name) return;
|
| 221 |
+
setBusy(true);
|
| 222 |
+
try {
|
| 223 |
+
const response = await fetch(`${API_V1}/charts/${encodeURIComponent(chart.id)}`, {
|
| 224 |
+
method: "PATCH",
|
| 225 |
+
credentials: CREDENTIALS,
|
| 226 |
+
headers: JSON_HEADERS,
|
| 227 |
+
body: JSON.stringify({ name }),
|
| 228 |
+
});
|
| 229 |
+
if (!response.ok) {
|
| 230 |
+
setError("That chart could not be renamed. Its old name is still in place.");
|
| 231 |
+
return;
|
| 232 |
+
}
|
| 233 |
+
setRenaming(null);
|
| 234 |
+
setError("");
|
| 235 |
+
refresh();
|
| 236 |
+
} catch {
|
| 237 |
+
setError("That chart could not be renamed. Its old name is still in place.");
|
| 238 |
+
} finally {
|
| 239 |
+
setBusy(false);
|
| 240 |
+
}
|
| 241 |
+
}, [refresh, renameText]);
|
| 242 |
+
|
| 243 |
+
const remove = useCallback(async (chart: SavedChartRecord) => {
|
| 244 |
+
setBusy(true);
|
| 245 |
+
try {
|
| 246 |
+
const response = await fetch(`${API_V1}/charts/${encodeURIComponent(chart.id)}`, {
|
| 247 |
+
method: "DELETE",
|
| 248 |
+
credentials: CREDENTIALS,
|
| 249 |
+
});
|
| 250 |
+
if (!response.ok) {
|
| 251 |
+
setError("That chart could not be deleted. It is still saved.");
|
| 252 |
+
return;
|
| 253 |
+
}
|
| 254 |
+
setDeleting(null);
|
| 255 |
+
setError("");
|
| 256 |
+
if (activeId === chart.id) onActiveId(null);
|
| 257 |
+
refresh();
|
| 258 |
+
} catch {
|
| 259 |
+
setError("That chart could not be deleted. It is still saved.");
|
| 260 |
+
} finally {
|
| 261 |
+
setBusy(false);
|
| 262 |
+
}
|
| 263 |
+
}, [activeId, onActiveId, refresh]);
|
| 264 |
+
|
| 265 |
+
const canSave = !!newName.trim() && !busy && !!database;
|
| 266 |
+
|
| 267 |
+
return (
|
| 268 |
+
<section className="cg-workspace-drawer" aria-label="Saved charts">
|
| 269 |
+
<header>
|
| 270 |
+
<strong>Saved charts</strong>
|
| 271 |
+
<button type="button" className="cg-btn" onClick={onClose}>
|
| 272 |
+
Close
|
| 273 |
+
</button>
|
| 274 |
+
</header>
|
| 275 |
+
|
| 276 |
+
{loading && <span className="lp-spin" role="status" aria-label="Loading saved charts" />}
|
| 277 |
+
{error && <p role="alert">{error}</p>}
|
| 278 |
+
|
| 279 |
+
<div className="cg-ts-group">
|
| 280 |
+
<input
|
| 281 |
+
className="cg-input"
|
| 282 |
+
aria-label="Name for this chart"
|
| 283 |
+
placeholder="Name this chart"
|
| 284 |
+
maxLength={NAME_MAX}
|
| 285 |
+
value={newName}
|
| 286 |
+
disabled={busy}
|
| 287 |
+
onChange={(event) => setNewName(event.target.value)}
|
| 288 |
+
onKeyDown={(event) => {
|
| 289 |
+
if (event.key === "Enter" && canSave) {
|
| 290 |
+
event.preventDefault();
|
| 291 |
+
void save();
|
| 292 |
+
}
|
| 293 |
+
}}
|
| 294 |
+
/>
|
| 295 |
+
<button
|
| 296 |
+
type="button"
|
| 297 |
+
className="cg-btn cg-btn--primary"
|
| 298 |
+
disabled={!canSave}
|
| 299 |
+
onClick={() => void save()}
|
| 300 |
+
>
|
| 301 |
+
Save chart
|
| 302 |
+
</button>
|
| 303 |
+
</div>
|
| 304 |
+
|
| 305 |
+
{charts.length === 0 && !loading ? (
|
| 306 |
+
<p>No saved charts yet. Name the chart on screen and save it.</p>
|
| 307 |
+
) : (
|
| 308 |
+
<ul className="cg-history-list">
|
| 309 |
+
{charts.map((chart) => (
|
| 310 |
+
<li key={chart.id}>
|
| 311 |
+
{renaming === chart.id ? (
|
| 312 |
+
<>
|
| 313 |
+
<input
|
| 314 |
+
className="cg-input"
|
| 315 |
+
aria-label={`Rename ${chart.name}`}
|
| 316 |
+
maxLength={NAME_MAX}
|
| 317 |
+
value={renameText}
|
| 318 |
+
disabled={busy}
|
| 319 |
+
onChange={(event) => setRenameText(event.target.value)}
|
| 320 |
+
/>
|
| 321 |
+
<span className="cg-ts-group">
|
| 322 |
+
<button
|
| 323 |
+
type="button"
|
| 324 |
+
className="cg-btn cg-btn--primary"
|
| 325 |
+
disabled={busy || !renameText.trim()}
|
| 326 |
+
onClick={() => void rename(chart)}
|
| 327 |
+
>
|
| 328 |
+
Save name
|
| 329 |
+
</button>
|
| 330 |
+
<button
|
| 331 |
+
type="button"
|
| 332 |
+
className="cg-btn"
|
| 333 |
+
disabled={busy}
|
| 334 |
+
onClick={() => setRenaming(null)}
|
| 335 |
+
>
|
| 336 |
+
Cancel
|
| 337 |
+
</button>
|
| 338 |
+
</span>
|
| 339 |
+
</>
|
| 340 |
+
) : (
|
| 341 |
+
<>
|
| 342 |
+
<button
|
| 343 |
+
type="button"
|
| 344 |
+
className="cg-btn"
|
| 345 |
+
aria-current={activeId === chart.id ? "true" : undefined}
|
| 346 |
+
onClick={() => {
|
| 347 |
+
onApply(tsChartConfigFrom(chart.config));
|
| 348 |
+
onActiveId(chart.id);
|
| 349 |
+
}}
|
| 350 |
+
>
|
| 351 |
+
{chart.name}
|
| 352 |
+
</button>
|
| 353 |
+
<span className="cg-ts-group">
|
| 354 |
+
<button
|
| 355 |
+
type="button"
|
| 356 |
+
className="cg-btn"
|
| 357 |
+
aria-label={`Rename ${chart.name}`}
|
| 358 |
+
disabled={busy}
|
| 359 |
+
onClick={() => {
|
| 360 |
+
setRenameText(chart.name);
|
| 361 |
+
setDeleting(null);
|
| 362 |
+
setRenaming(chart.id);
|
| 363 |
+
}}
|
| 364 |
+
>
|
| 365 |
+
<MenuIcon name="rename" />
|
| 366 |
+
</button>
|
| 367 |
+
<button
|
| 368 |
+
type="button"
|
| 369 |
+
className="cg-btn cg-btn--danger"
|
| 370 |
+
aria-label={`Delete ${chart.name}`}
|
| 371 |
+
disabled={busy}
|
| 372 |
+
onClick={() => {
|
| 373 |
+
setRenaming(null);
|
| 374 |
+
setDeleting(chart.id);
|
| 375 |
+
}}
|
| 376 |
+
>
|
| 377 |
+
<MenuIcon name="trash" />
|
| 378 |
+
</button>
|
| 379 |
+
</span>
|
| 380 |
+
</>
|
| 381 |
+
)}
|
| 382 |
+
|
| 383 |
+
{deleting === chart.id && (
|
| 384 |
+
<div role="alertdialog" aria-label={`Delete ${chart.name}`}>
|
| 385 |
+
<p>Delete this saved chart? The view on screen is not changed.</p>
|
| 386 |
+
<span className="cg-ts-group">
|
| 387 |
+
<button
|
| 388 |
+
type="button"
|
| 389 |
+
className="cg-btn cg-btn--danger"
|
| 390 |
+
disabled={busy}
|
| 391 |
+
onClick={() => void remove(chart)}
|
| 392 |
+
>
|
| 393 |
+
Confirm delete
|
| 394 |
+
</button>
|
| 395 |
+
<button
|
| 396 |
+
type="button"
|
| 397 |
+
className="cg-btn"
|
| 398 |
+
disabled={busy}
|
| 399 |
+
onClick={() => setDeleting(null)}
|
| 400 |
+
>
|
| 401 |
+
Cancel
|
| 402 |
+
</button>
|
| 403 |
+
</span>
|
| 404 |
+
</div>
|
| 405 |
+
)}
|
| 406 |
+
</li>
|
| 407 |
+
))}
|
| 408 |
+
</ul>
|
| 409 |
+
)}
|
| 410 |
+
</section>
|
| 411 |
+
);
|
| 412 |
+
}
|
web/src/customer-grid/TimeSeriesPanel.tsx
CHANGED
|
@@ -81,6 +81,8 @@ import { Popover } from "../filter-kit";
|
|
| 81 |
import { toVegaLiteSpec } from "../viz/vega/toVegaLiteSpec";
|
| 82 |
import VegaLiteChart from "../viz/vega/VegaLiteChart";
|
| 83 |
import { API_V1, CREDENTIALS } from "../apiContract";
|
|
|
|
|
|
|
| 84 |
|
| 85 |
const BUCKET_LABELS: Record<TsBucket, string> = {
|
| 86 |
week: "Weekly",
|
|
@@ -89,6 +91,30 @@ const BUCKET_LABELS: Record<TsBucket, string> = {
|
|
| 89 |
year: "Yearly",
|
| 90 |
};
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
/** The rolling spans offered, per bucket. Capped well inside `TS_MAX_LAST_N`. */
|
| 93 |
const LAST_N_CHOICES = [6, 12, 24, 36];
|
| 94 |
|
|
@@ -136,7 +162,14 @@ export interface TimeSeriesPanelProps {
|
|
| 136 |
* `modeDataRows`.
|
| 137 |
*/
|
| 138 |
rows?: readonly Record<string, unknown>[];
|
| 139 |
-
/**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
display?: DisplaySpec;
|
| 141 |
/** Persist a display change. Absent = the panel is ephemeral (RECORD's embed, v1). */
|
| 142 |
onDisplay?: (next: Partial<DisplaySpec>) => void;
|
|
@@ -311,6 +344,8 @@ export default function TimeSeriesPanel({
|
|
| 311 |
locked,
|
| 312 |
onSheet,
|
| 313 |
}: TimeSeriesPanelProps) {
|
|
|
|
|
|
|
| 314 |
const classed = useMemo(() => classifyFields(fields), [fields]);
|
| 315 |
type MetricCatalogItem = { key: string; label: string; description?: string; format?: string; source?: string; approved: true };
|
| 316 |
type SemanticField = { field: string; state?: string; role?: string; sensitivity?: string; valueProfile?: { redacted?: boolean; distinctCount?: number | null; values?: string[]; sample?: string[] } };
|
|
@@ -318,15 +353,15 @@ export default function TimeSeriesPanel({
|
|
| 318 |
const [metricCatalog, setMetricCatalog] = useState<MetricCatalogItem[]>([]);
|
| 319 |
useEffect(() => {
|
| 320 |
const controller = new AbortController();
|
| 321 |
-
void fetch(`${API_V1}/query/semantics/${encodeURIComponent(
|
| 322 |
.then(async (response) => response.ok ? response.json() : { fields: [] })
|
| 323 |
.then((body) => { if (!controller.signal.aborted) setSemanticFields(Array.isArray(body?.fields) ? body.fields : []); })
|
| 324 |
.catch(() => undefined);
|
| 325 |
return () => controller.abort();
|
| 326 |
-
}, [
|
| 327 |
useEffect(() => {
|
| 328 |
const controller = new AbortController();
|
| 329 |
-
void fetch(`${API_V1}/query/metrics?database=${encodeURIComponent(
|
| 330 |
.then(async (response) => response.ok ? response.json() : { metrics: [] })
|
| 331 |
.then((body) => {
|
| 332 |
if (controller.signal.aborted) return;
|
|
@@ -338,7 +373,7 @@ export default function TimeSeriesPanel({
|
|
| 338 |
}));
|
| 339 |
}).catch(() => { if (!controller.signal.aborted) setMetricCatalog([]); });
|
| 340 |
return () => controller.abort();
|
| 341 |
-
}, [
|
| 342 |
// The OFFERED list: everything with a way onto the sheet, server-served first so a real series
|
| 343 |
// is never buried under a flat one in the picker.
|
| 344 |
const eligible = useMemo(
|
|
@@ -417,6 +452,34 @@ export default function TimeSeriesPanel({
|
|
| 417 |
const gridlines = display?.tsGridlines !== false;
|
| 418 |
const sparkline = display?.tsSparkline === true;
|
| 419 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 420 |
const [payload, setPayload] = useState<TsPayload | null>(null);
|
| 421 |
const [state, setState] = useState<"idle" | "loading" | "error">("idle");
|
| 422 |
const [errStatus, setErrStatus] = useState(0);
|
|
@@ -764,7 +827,7 @@ export default function TimeSeriesPanel({
|
|
| 764 |
}
|
| 765 |
}
|
| 766 |
try {
|
| 767 |
-
const response = await fetch(`${API_V1}/query/timeseries/validate`, { method: "POST", credentials: CREDENTIALS, headers: { "Content-Type": "application/json" }, body: JSON.stringify({ database
|
| 768 |
const body = await response.json().catch(() => ({}));
|
| 769 |
if (!response.ok) {
|
| 770 |
setSeriesValidationError(String(body?.detail?.message ?? body?.error ?? "These series cannot be saved."));
|
|
@@ -776,7 +839,7 @@ export default function TimeSeriesPanel({
|
|
| 776 |
setSeriesValidationError("Series validation is unavailable. Nothing was saved.");
|
| 777 |
return false;
|
| 778 |
}
|
| 779 |
-
}, [catalogKeys,
|
| 780 |
const setMetrics = async (keys: string[], options = laterSeries) => {
|
| 781 |
// Never persist an EMPTY metric list: it would read back as "no data" on the next open.
|
| 782 |
if (!keys.length) return;
|
|
@@ -834,7 +897,11 @@ export default function TimeSeriesPanel({
|
|
| 834 |
snapshotSelected.length > 0 && sheet.columns.length === 0 && state !== "loading";
|
| 835 |
|
| 836 |
return (
|
| 837 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 838 |
<details className="cg-semantic-profile"><summary>Metric definitions and value profiles</summary>{semanticFields.map((item) => <div className="cg-semantic-row" key={item.field}><strong>{fields.find((field) => field.key === item.field)?.label ?? item.field}</strong><span>{item.state ?? "draft"} Β· {item.role ?? "attribute"} Β· {item.sensitivity ?? "internal"}</span>{item.valueProfile?.redacted ? <span className="cg-redacted">Values redacted</span> : <span>{item.valueProfile?.values?.join(", ") || item.valueProfile?.sample?.join(", ") || `${item.valueProfile?.distinctCount ?? 0} distinct values`}</span>}</div>)}</details>
|
| 839 |
{formulaContractError && <div className="cg-ts-note" role="alert">{formulaContractError}</div>}
|
| 840 |
{Object.entries(formulaPreviewErrors).some(([, error]) => error) && <div className="cg-ts-note" role="alert">{Object.entries(formulaPreviewErrors).filter(([, error]) => error).map(([id, error]) => <span key={id}>{error}</span>)}</div>}
|
|
@@ -930,6 +997,35 @@ export default function TimeSeriesPanel({
|
|
| 930 |
</button>
|
| 931 |
</span>
|
| 932 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 933 |
{/* β NO EXPORT BUTTON HERE (owner item 3, 2026-08-03). Export lives in the view's "β¦"
|
| 934 |
menu, on every view, in four formats β and from a time-series view it now carries
|
| 935 |
THIS SHEET rather than the rows beneath it (see `onSheet` above). A second door on
|
|
@@ -941,6 +1037,22 @@ export default function TimeSeriesPanel({
|
|
| 941 |
</span>
|
| 942 |
</div>
|
| 943 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 944 |
{selected.slice(1).some((key) => !fields.find((field) => field.key === key)?.measure?.key) && <div className="cg-ts-series-options" aria-label="Later series settings">{selected.slice(1).map((key) => {
|
| 945 |
const field = fields.find((candidate) => candidate.key === key);
|
| 946 |
if (!field || field.measure?.key) return null;
|
|
|
|
| 81 |
import { toVegaLiteSpec } from "../viz/vega/toVegaLiteSpec";
|
| 82 |
import VegaLiteChart from "../viz/vega/VegaLiteChart";
|
| 83 |
import { API_V1, CREDENTIALS } from "../apiContract";
|
| 84 |
+
import SavedChartNav from "./SavedChartNav";
|
| 85 |
+
import type { TsChartConfig } from "./SavedChartNav";
|
| 86 |
|
| 87 |
const BUCKET_LABELS: Record<TsBucket, string> = {
|
| 88 |
week: "Weekly",
|
|
|
|
| 91 |
year: "Yearly",
|
| 92 |
};
|
| 93 |
|
| 94 |
+
/**
|
| 95 |
+
* W47-T31 β the DATABASE key for a surface scope. **THE TWO ARE DIFFERENT STRING SPACES.**
|
| 96 |
+
*
|
| 97 |
+
* β THIS IS A DEFECT FIX, NOT A CONVENIENCE. `SurfaceScope` is what `CustomerGrid` mounts with
|
| 98 |
+
* ("customer", "product", a `ut_*` key); a DATABASE key is what the semantic layer, the metric
|
| 99 |
+
* catalogue and `session.require()` all take. `semantic.topic_for_grid("customer")` is None
|
| 100 |
+
* while `topic_for_grid("customer_data")` resolves `odoo_customers`, so every door this panel
|
| 101 |
+
* knocked on with a raw scope answered with an EMPTY metric list on both built-in pools and the
|
| 102 |
+
* Time series view offered nothing to plot. Only `ut_*` grids worked, because their scope string
|
| 103 |
+
* happens to equal their grid key.
|
| 104 |
+
*
|
| 105 |
+
* β "cohort" MAPS TO THE CUSTOMER POOL, and that is read off the server rather than assumed:
|
| 106 |
+
* `routes_records._CUSTOMER_SCOPES = ("", "customer", "cohort")` with the note *"the customer
|
| 107 |
+
* topic's two names, one book, two surfaces (the Cohort page is the customer table over
|
| 108 |
+
* hand-curated sets)"*, and `routes_nav` puts `cohort` in the `customer_data` family. The branch
|
| 109 |
+
* is currently unreachable from the shell anyway (`shell/dbFrame.tsx::gridScopeFor` never returns
|
| 110 |
+
* it), which is why naming it correctly costs nothing and guessing it would have.
|
| 111 |
+
*/
|
| 112 |
+
function databaseForScope(scope: SurfaceScope): string {
|
| 113 |
+
if (scope === "customer" || scope === "cohort") return "customer_data";
|
| 114 |
+
if (scope === "product") return "product_data";
|
| 115 |
+
return scope;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
/** The rolling spans offered, per bucket. Capped well inside `TS_MAX_LAST_N`. */
|
| 119 |
const LAST_N_CHOICES = [6, 12, 24, 36];
|
| 120 |
|
|
|
|
| 162 |
* `modeDataRows`.
|
| 163 |
*/
|
| 164 |
rows?: readonly Record<string, unknown>[];
|
| 165 |
+
/**
|
| 166 |
+
* The view's `config.display`; absent keys fall back to the panel's defaults.
|
| 167 |
+
*
|
| 168 |
+
* β STILL THE VIEW'S, AFTER W47-T31. A saved chart (R7 / C6) is a listed RECORD with its own
|
| 169 |
+
* id and name, not a second home for this state: opening one WRITES its stored keys through
|
| 170 |
+
* `onDisplay` into exactly this spec. So the live display state is where it always was, and
|
| 171 |
+
* the navigator is a source of values for it rather than a rival owner of it.
|
| 172 |
+
*/
|
| 173 |
display?: DisplaySpec;
|
| 174 |
/** Persist a display change. Absent = the panel is ephemeral (RECORD's embed, v1). */
|
| 175 |
onDisplay?: (next: Partial<DisplaySpec>) => void;
|
|
|
|
| 344 |
locked,
|
| 345 |
onSheet,
|
| 346 |
}: TimeSeriesPanelProps) {
|
| 347 |
+
// β EVERY DATABASE-KEYED DOOR BELOW TAKES THIS, NEVER `scope`. See `databaseForScope`.
|
| 348 |
+
const database = databaseForScope(scope);
|
| 349 |
const classed = useMemo(() => classifyFields(fields), [fields]);
|
| 350 |
type MetricCatalogItem = { key: string; label: string; description?: string; format?: string; source?: string; approved: true };
|
| 351 |
type SemanticField = { field: string; state?: string; role?: string; sensitivity?: string; valueProfile?: { redacted?: boolean; distinctCount?: number | null; values?: string[]; sample?: string[] } };
|
|
|
|
| 353 |
const [metricCatalog, setMetricCatalog] = useState<MetricCatalogItem[]>([]);
|
| 354 |
useEffect(() => {
|
| 355 |
const controller = new AbortController();
|
| 356 |
+
void fetch(`${API_V1}/query/semantics/${encodeURIComponent(database)}`, { credentials: CREDENTIALS, signal: controller.signal })
|
| 357 |
.then(async (response) => response.ok ? response.json() : { fields: [] })
|
| 358 |
.then((body) => { if (!controller.signal.aborted) setSemanticFields(Array.isArray(body?.fields) ? body.fields : []); })
|
| 359 |
.catch(() => undefined);
|
| 360 |
return () => controller.abort();
|
| 361 |
+
}, [database]);
|
| 362 |
useEffect(() => {
|
| 363 |
const controller = new AbortController();
|
| 364 |
+
void fetch(`${API_V1}/query/metrics?database=${encodeURIComponent(database)}`, { credentials: CREDENTIALS, signal: controller.signal })
|
| 365 |
.then(async (response) => response.ok ? response.json() : { metrics: [] })
|
| 366 |
.then((body) => {
|
| 367 |
if (controller.signal.aborted) return;
|
|
|
|
| 373 |
}));
|
| 374 |
}).catch(() => { if (!controller.signal.aborted) setMetricCatalog([]); });
|
| 375 |
return () => controller.abort();
|
| 376 |
+
}, [database]);
|
| 377 |
// The OFFERED list: everything with a way onto the sheet, server-served first so a real series
|
| 378 |
// is never buried under a flat one in the picker.
|
| 379 |
const eligible = useMemo(
|
|
|
|
| 452 |
const gridlines = display?.tsGridlines !== false;
|
| 453 |
const sparkline = display?.tsSparkline === true;
|
| 454 |
|
| 455 |
+
/* βββββββββββββ W47-T31 / R7 / C6 β SAVED CHARTS, IN A RIGHT-SIDE NAVIGATOR βββββββββββββ
|
| 456 |
+
Owner R7: *"every interface like chart, swap etc. that we need to configure should act like
|
| 457 |
+
route with the right side navigation to choose the specific view we want to see. So its not
|
| 458 |
+
pegged on a per view basis."*
|
| 459 |
+
|
| 460 |
+
β THE PANEL NEEDS NO NEW STATE MACHINE FOR THIS, and that is the whole design. Bucket, span,
|
| 461 |
+
fields, comparisons, styles and both toggles are ALREADY derived from `display` and written
|
| 462 |
+
back through `onDisplay`, so "open that chart" is one `onDisplay(...)` call and "save this
|
| 463 |
+
one" is a read of the values below. A chart is a RECORD on the server (C6), listed beside
|
| 464 |
+
every view rather than stored inside one.
|
| 465 |
+
|
| 466 |
+
β THE RESOLVED VALUES, NOT `display?.*`. A view that never chose a bucket still SHOWS
|
| 467 |
+
Monthly, and saving the raw absent key would produce a chart that reloads as "nothing
|
| 468 |
+
chosen" while its author was looking at a full sheet. */
|
| 469 |
+
const chartConfig: TsChartConfig = useMemo(() => ({
|
| 470 |
+
tsFields: selected.length ? [...selected] : undefined,
|
| 471 |
+
tsBucket: bucket,
|
| 472 |
+
tsSpan: { lastN },
|
| 473 |
+
tsDeltas: deltaKinds.length ? [...deltaKinds] : undefined,
|
| 474 |
+
tsStyles: styles,
|
| 475 |
+
// Both toggles keep the host's storage asymmetry: the DEFAULT is stored by deleting the key.
|
| 476 |
+
tsGridlines: gridlines ? undefined : false,
|
| 477 |
+
tsSparkline: sparkline ? true : undefined,
|
| 478 |
+
tsRows: customRows.length ? [...customRows] : undefined,
|
| 479 |
+
}), [bucket, customRows, deltaKinds, gridlines, lastN, selected, sparkline, styles]);
|
| 480 |
+
const [chartNavOpen, setChartNavOpen] = useState(false);
|
| 481 |
+
const [activeChartId, setActiveChartId] = useState<string | null>(null);
|
| 482 |
+
|
| 483 |
const [payload, setPayload] = useState<TsPayload | null>(null);
|
| 484 |
const [state, setState] = useState<"idle" | "loading" | "error">("idle");
|
| 485 |
const [errStatus, setErrStatus] = useState(0);
|
|
|
|
| 827 |
}
|
| 828 |
}
|
| 829 |
try {
|
| 830 |
+
const response = await fetch(`${API_V1}/query/timeseries/validate`, { method: "POST", credentials: CREDENTIALS, headers: { "Content-Type": "application/json" }, body: JSON.stringify({ database, series }) });
|
| 831 |
const body = await response.json().catch(() => ({}));
|
| 832 |
if (!response.ok) {
|
| 833 |
setSeriesValidationError(String(body?.detail?.message ?? body?.error ?? "These series cannot be saved."));
|
|
|
|
| 839 |
setSeriesValidationError("Series validation is unavailable. Nothing was saved.");
|
| 840 |
return false;
|
| 841 |
}
|
| 842 |
+
}, [catalogKeys, database, fields]);
|
| 843 |
const setMetrics = async (keys: string[], options = laterSeries) => {
|
| 844 |
// Never persist an EMPTY metric list: it would read back as "no data" on the next open.
|
| 845 |
if (!keys.length) return;
|
|
|
|
| 897 |
snapshotSelected.length > 0 && sheet.columns.length === 0 && state !== "loading";
|
| 898 |
|
| 899 |
return (
|
| 900 |
+
/* `position: relative` is INLINE because `.cg-ts` has none and this ticket may not touch
|
| 901 |
+
a stylesheet. It anchors the shared `.cg-workspace-drawer` (absolute) to the Time series
|
| 902 |
+
panel rather than to whatever positioned ancestor happens to be above it, and changes
|
| 903 |
+
no layout: an absolutely positioned child leaves the flex column entirely. */
|
| 904 |
+
<div className="cg-ts" onPointerDown={foldNavOnWorkSurface} style={{ position: "relative" }}>
|
| 905 |
<details className="cg-semantic-profile"><summary>Metric definitions and value profiles</summary>{semanticFields.map((item) => <div className="cg-semantic-row" key={item.field}><strong>{fields.find((field) => field.key === item.field)?.label ?? item.field}</strong><span>{item.state ?? "draft"} Β· {item.role ?? "attribute"} Β· {item.sensitivity ?? "internal"}</span>{item.valueProfile?.redacted ? <span className="cg-redacted">Values redacted</span> : <span>{item.valueProfile?.values?.join(", ") || item.valueProfile?.sample?.join(", ") || `${item.valueProfile?.distinctCount ?? 0} distinct values`}</span>}</div>)}</details>
|
| 906 |
{formulaContractError && <div className="cg-ts-note" role="alert">{formulaContractError}</div>}
|
| 907 |
{Object.entries(formulaPreviewErrors).some(([, error]) => error) && <div className="cg-ts-note" role="alert">{Object.entries(formulaPreviewErrors).filter(([, error]) => error).map(([id, error]) => <span key={id}>{error}</span>)}</div>}
|
|
|
|
| 997 |
</button>
|
| 998 |
</span>
|
| 999 |
|
| 1000 |
+
{/* W47-T31 β the navigator's door.
|
| 1001 |
+
|
| 1002 |
+
β GUARDED ON `onDisplay`, WHICH IS THE PREDICATE THAT ACTUALLY MATTERS: applying a
|
| 1003 |
+
saved chart IS an `onDisplay` call, so a mount that cannot write cannot open one and
|
| 1004 |
+
must not offer a button that lies.
|
| 1005 |
+
|
| 1006 |
+
β BOTH SHIPPED MOUNTS PASS IT, and it is easy to read the props and assume only one
|
| 1007 |
+
does, so it is worth saying plainly. `CustomerGrid.tsx` passes the VIEW's
|
| 1008 |
+
`config.display` and persists;
|
| 1009 |
+
`RecordDetail.tsx`'s Insights embed passes its OWN local `tsDisplay` state and keeps
|
| 1010 |
+
every control on this bar live (its own note says so). The navigator therefore appears
|
| 1011 |
+
in both, which is right rather than accidental: R7 says a saved chart is "not pegged
|
| 1012 |
+
on a per view basis", and the record embed is not even a view. What the record embed
|
| 1013 |
+
gets is a chart it can apply for the length of the modal, drawn from the same listed
|
| 1014 |
+
records the grid sees. No new prop, so `CustomerGrid.tsx` stays outside this fence. */}
|
| 1015 |
+
{onDisplay && (
|
| 1016 |
+
<span className="cg-ts-group">
|
| 1017 |
+
<button
|
| 1018 |
+
type="button"
|
| 1019 |
+
className={"cg-ts-tog" + (chartNavOpen ? " is-on" : "")}
|
| 1020 |
+
aria-pressed={chartNavOpen}
|
| 1021 |
+
aria-expanded={chartNavOpen}
|
| 1022 |
+
onClick={() => setChartNavOpen((open) => !open)}
|
| 1023 |
+
>
|
| 1024 |
+
Saved charts
|
| 1025 |
+
</button>
|
| 1026 |
+
</span>
|
| 1027 |
+
)}
|
| 1028 |
+
|
| 1029 |
{/* β NO EXPORT BUTTON HERE (owner item 3, 2026-08-03). Export lives in the view's "β¦"
|
| 1030 |
menu, on every view, in four formats β and from a time-series view it now carries
|
| 1031 |
THIS SHEET rather than the rows beneath it (see `onSheet` above). A second door on
|
|
|
|
| 1037 |
</span>
|
| 1038 |
</div>
|
| 1039 |
|
| 1040 |
+
{onDisplay && chartNavOpen && (
|
| 1041 |
+
<SavedChartNav
|
| 1042 |
+
database={database}
|
| 1043 |
+
current={chartConfig}
|
| 1044 |
+
/* β THE WHOLE CONFIG, ALWAYS ALL EIGHT KEYS. `SavedChartNav.tsChartConfigFrom` emits
|
| 1045 |
+
`undefined` for every key the saved chart does not carry, and the host merges with
|
| 1046 |
+
`{ ...spec, ...next }` before persisting through `JSON.stringify` β so an absent key
|
| 1047 |
+
DELETES the stored one. Forwarding only the keys present would leave a comparison or
|
| 1048 |
+
a trend line from the previously opened chart switched on underneath this one. */
|
| 1049 |
+
onApply={(config) => onDisplay?.(config)}
|
| 1050 |
+
activeId={activeChartId}
|
| 1051 |
+
onActiveId={setActiveChartId}
|
| 1052 |
+
onClose={() => setChartNavOpen(false)}
|
| 1053 |
+
/>
|
| 1054 |
+
)}
|
| 1055 |
+
|
| 1056 |
{selected.slice(1).some((key) => !fields.find((field) => field.key === key)?.measure?.key) && <div className="cg-ts-series-options" aria-label="Later series settings">{selected.slice(1).map((key) => {
|
| 1057 |
const field = fields.find((candidate) => candidate.key === key);
|
| 1058 |
if (!field || field.measure?.key) return null;
|
web/src/customer-grid/Toolbar.tsx
CHANGED
|
@@ -269,6 +269,13 @@ interface ToolbarBaseProps {
|
|
| 269 |
* toolbar so that Related, Notes and Full screen are one contiguous run. Supplied only by
|
| 270 |
* the main grid render, which is the only place a workspace drawer exists. */
|
| 271 |
notesOpen?: boolean;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
onNotes?: () => void;
|
| 273 |
}
|
| 274 |
|
|
@@ -800,6 +807,7 @@ export default function Toolbar({
|
|
| 800 |
fullscreen = false,
|
| 801 |
onFullscreen,
|
| 802 |
notesOpen = false,
|
|
|
|
| 803 |
onNotes,
|
| 804 |
}: ToolbarProps) {
|
| 805 |
const shownCount = fields.filter((f) => visible.has(f.key)).length;
|
|
@@ -986,11 +994,15 @@ export default function Toolbar({
|
|
| 986 |
</Popover>
|
| 987 |
|
| 988 |
{/* Filter β condition builder.
|
| 989 |
-
|
| 990 |
-
|
| 991 |
-
|
| 992 |
-
|
| 993 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 994 |
<Popover
|
| 995 |
label={filterLabel}
|
| 996 |
icon={<IconFilter />}
|
|
@@ -1001,7 +1013,7 @@ export default function Toolbar({
|
|
| 1001 |
pairWide={hasComparand}
|
| 1002 |
forceOpenSignal={filterSeed?.n}
|
| 1003 |
>
|
| 1004 |
-
{(
|
| 1005 |
<ImmutableViewConfigNotice subject="filters" onCopyToChange={onCopyToChange} />
|
| 1006 |
) : (
|
| 1007 |
<FilterBuilderPanel
|
|
@@ -1016,7 +1028,6 @@ export default function Toolbar({
|
|
| 1016 |
onChange={onFilterTree}
|
| 1017 |
statusValues={statusValues}
|
| 1018 |
cohortLock={cohortLock}
|
| 1019 |
-
onClose={close}
|
| 1020 |
footerExtra={
|
| 1021 |
canCopyConfig ? (
|
| 1022 |
<CopyFromViewDoor
|
|
@@ -1290,11 +1301,22 @@ export default function Toolbar({
|
|
| 1290 |
say "toggle button, not pressed" and "collapsed" in one breath. Full screen next
|
| 1291 |
door is genuinely a pressed state, so the two attributes differ on purpose. */
|
| 1292 |
aria-expanded={notesOpen}
|
| 1293 |
-
aria-label="Notes"
|
| 1294 |
-
title="Notes"
|
| 1295 |
onClick={onNotes}
|
| 1296 |
>
|
| 1297 |
<IconNote />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1298 |
<span className="cg-tb-label">Notes</span>
|
| 1299 |
</button>
|
| 1300 |
)}
|
|
|
|
| 269 |
* toolbar so that Related, Notes and Full screen are one contiguous run. Supplied only by
|
| 270 |
* the main grid render, which is the only place a workspace drawer exists. */
|
| 271 |
notesOpen?: boolean;
|
| 272 |
+
/**
|
| 273 |
+
* β W47-T16 (owner instruction 19) β how many notes behind this button THIS viewer has
|
| 274 |
+
* not opened yet. Supplied, never derived here: the count is a SERVER answer about a
|
| 275 |
+
* per-user read mark, and a toolbar that guessed it would be wrong the moment a
|
| 276 |
+
* colleague edited a note. Zero and undefined both paint nothing.
|
| 277 |
+
*/
|
| 278 |
+
notesUnread?: number;
|
| 279 |
onNotes?: () => void;
|
| 280 |
}
|
| 281 |
|
|
|
|
| 807 |
fullscreen = false,
|
| 808 |
onFullscreen,
|
| 809 |
notesOpen = false,
|
| 810 |
+
notesUnread = 0,
|
| 811 |
onNotes,
|
| 812 |
}: ToolbarProps) {
|
| 813 |
const shownCount = fields.filter((f) => visible.has(f.key)).length;
|
|
|
|
| 994 |
</Popover>
|
| 995 |
|
| 996 |
{/* Filter β condition builder.
|
| 997 |
+
β W47-T13 (owner instruction 15) β THE RENDER PROP IS TAKEN ZERO-ARG AGAIN, AND THAT
|
| 998 |
+
IS THE TICKET. `Popover` still manufactures a closer and still hands it to this
|
| 999 |
+
render-prop; W38-T02 took it and wired it to a header X inside the panel, which the
|
| 1000 |
+
owner has now ruled redundant ("its quite intuitive for user to just click elsewhere to
|
| 1001 |
+
close the Filter navigation"). So the argument is dropped here and `onClose` is gone
|
| 1002 |
+
from `FilterBuilderPanelProps` entirely β a prop kept "just in case" is how the button
|
| 1003 |
+
comes back. Nothing is lost: `OverlaySurface.tsx::AnchoredOverlay` dismisses on an
|
| 1004 |
+
outside pointerdown, and Escape works, neither of which was ever this closer's doing.
|
| 1005 |
+
β The argument is not merely unused, it is UNNAMED: `noUnusedParameters` is on. */}
|
| 1006 |
<Popover
|
| 1007 |
label={filterLabel}
|
| 1008 |
icon={<IconFilter />}
|
|
|
|
| 1013 |
pairWide={hasComparand}
|
| 1014 |
forceOpenSignal={filterSeed?.n}
|
| 1015 |
>
|
| 1016 |
+
{() => filtersLocked ? (
|
| 1017 |
<ImmutableViewConfigNotice subject="filters" onCopyToChange={onCopyToChange} />
|
| 1018 |
) : (
|
| 1019 |
<FilterBuilderPanel
|
|
|
|
| 1028 |
onChange={onFilterTree}
|
| 1029 |
statusValues={statusValues}
|
| 1030 |
cohortLock={cohortLock}
|
|
|
|
| 1031 |
footerExtra={
|
| 1032 |
canCopyConfig ? (
|
| 1033 |
<CopyFromViewDoor
|
|
|
|
| 1301 |
say "toggle button, not pressed" and "collapsed" in one breath. Full screen next
|
| 1302 |
door is genuinely a pressed state, so the two attributes differ on purpose. */
|
| 1303 |
aria-expanded={notesOpen}
|
| 1304 |
+
aria-label={notesUnread > 0 ? `Notes, ${notesUnread} unread` : "Notes"}
|
| 1305 |
+
title={notesUnread > 0 ? `Notes, ${notesUnread} unread` : "Notes"}
|
| 1306 |
onClick={onNotes}
|
| 1307 |
>
|
| 1308 |
<IconNote />
|
| 1309 |
+
{/* β W47-T16 β the unread mark rides INSIDE the button, after the glyph, so it
|
| 1310 |
+
travels with the control at the narrow width where `.cg-tb-label` is hidden by
|
| 1311 |
+
`@container cgtoolbar (max-width: 1080px)`. A badge parked beside the label
|
| 1312 |
+
would vanish exactly when the button became icon-only. `aria-hidden` because
|
| 1313 |
+
the count is already spoken in the button's own `aria-label` below: announcing
|
| 1314 |
+
a bare number after "Notes" reads as a second control. */}
|
| 1315 |
+
{notesUnread > 0 && (
|
| 1316 |
+
<span className="cg-notes-badge" aria-hidden>
|
| 1317 |
+
{notesUnread > 9 ? "9+" : notesUnread}
|
| 1318 |
+
</span>
|
| 1319 |
+
)}
|
| 1320 |
<span className="cg-tb-label">Notes</span>
|
| 1321 |
</button>
|
| 1322 |
)}
|
web/src/customer-grid/ViewSidebar.tsx
CHANGED
|
@@ -38,7 +38,9 @@ import { FolderMark, LockMark, MenuLabel, ModeIcon, ToneModeIcon } from "./icons
|
|
| 38 |
* `customer-grid/**` importing `shell/**`; the event-name/dispatch contract is a sibling of the
|
| 39 |
* grid, and `FormInterface.tsx` and `ImportDialog.tsx` already reach it the same way.
|
| 40 |
*/
|
| 41 |
-
|
|
|
|
|
|
|
| 42 |
import { ROOT_FOLDER_ID } from "./folders";
|
| 43 |
import {
|
| 44 |
folderPath,
|
|
@@ -56,10 +58,29 @@ import type { DataDatabase, DataDatabaseFolder } from "./dataPath";
|
|
| 56 |
// menu vocabulary. The Inbox module's header wears the SAME component (`ui/icons.BellIcon`),
|
| 57 |
// so the bell that opens the Inbox and the bell that fills it cannot drift apart.
|
| 58 |
import { BellIcon, StarIcon } from "../ui/icons";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
// β `SHARED_FOLDER_ID` is no longer imported: W34-T25 replaced both of its call sites with
|
| 60 |
// `isSyntheticFolderId`, and `noUnusedLocals` turns a leftover import into a build error rather
|
| 61 |
// than into dead weight. The constant itself is still exported and still used by `folders.ts`.
|
| 62 |
import {
|
|
|
|
| 63 |
folderNesting,
|
| 64 |
groupByFolder,
|
| 65 |
isSyntheticFolderId,
|
|
@@ -113,6 +134,18 @@ import {
|
|
| 113 |
* β NOT `LockMark`. A share is not one of DESIGN.md Β§4's three locks, and the padlock means a
|
| 114 |
* lock (D-254 is the register row for what happens when one glyph carries both ideas).
|
| 115 |
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
function ShareMark({ size = 13 }: { size?: number }) {
|
| 117 |
return (
|
| 118 |
<svg width={size} height={size} viewBox="0 0 16 16" aria-hidden>
|
|
@@ -1352,7 +1385,54 @@ export default function ViewSidebar({
|
|
| 1352 |
/** The folder being dragged, and the group its insertion line is currently drawn above. */
|
| 1353 |
const [foldDrag, setFoldDrag] = useState<string | null>(null);
|
| 1354 |
const [foldOver, setFoldOver] = useState<string | null>(null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1355 |
const foldsReorderable = !!folders && !!onFolderReorder;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1356 |
/**
|
| 1357 |
* Land `draggedId` before `beforeId` (null = last) and emit the new order. The arithmetic
|
| 1358 |
* lives in `folders.ts` so a gate can run it under node β the handler around it is DOM.
|
|
@@ -1440,10 +1520,58 @@ export default function ViewSidebar({
|
|
| 1440 |
* a memoized grouping fed by a freshly-allocated folder order recomputes on every render
|
| 1441 |
* anyway, so the two are pinned together or neither is (W41-T37, owner instruction 14).
|
| 1442 |
*/
|
| 1443 |
-
|
| 1444 |
-
|
| 1445 |
-
|
| 1446 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1447 |
const canFileMenuView =
|
| 1448 |
foldersOn && !!menuView && mayFileView(menuView, canEditMenuView);
|
| 1449 |
const moveFolders = useMemo(
|
|
@@ -1737,6 +1865,129 @@ export default function ViewSidebar({
|
|
| 1737 |
* serves never fires, so the idle rail pays nothing for it.
|
| 1738 |
*/
|
| 1739 |
const addPreview = addTarget && folderAddPreview ? folderAddPreview(addTarget) : null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1740 |
/**
|
| 1741 |
* ONE pair of drop handlers per group, serving TWO drags β a view being filed into this
|
| 1742 |
* folder (`text/plain`) and, since wave 20 item 19, a folder being dropped in front of
|
|
@@ -1931,16 +2182,68 @@ export default function ViewSidebar({
|
|
| 1931 |
setName("");
|
| 1932 |
};
|
| 1933 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1934 |
const createFolder = () => {
|
| 1935 |
const value = folderName.trim();
|
| 1936 |
if (!value) return;
|
| 1937 |
-
/
|
| 1938 |
-
|
| 1939 |
-
|
| 1940 |
-
|
| 1941 |
-
|
| 1942 |
-
|
| 1943 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1944 |
/**
|
| 1945 |
* ββ WAVE 41 Β· T34 β FILING A FOLDER INTO ONE OPENS IT, or the new folder is created
|
| 1946 |
* INVISIBLY.
|
|
@@ -2231,7 +2534,17 @@ export default function ViewSidebar({
|
|
| 2231 |
no create-flyout to fold it into; that file is deleted this wave, so the class now has
|
| 2232 |
no consumer in this tree. Left in index.css rather than swept blind: a CSS rule with
|
| 2233 |
no consumer is inert, and hunting one down mid-wave is how a rule something else still
|
| 2234 |
-
reads gets removed. Named here so the sweep is a decision, not a discovery.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2235 |
<div className="cg-create-new">
|
| 2236 |
<button
|
| 2237 |
type="button"
|
|
@@ -2310,8 +2623,14 @@ export default function ViewSidebar({
|
|
| 2310 |
form the user has to remember which menu they came from. One line, the folder's
|
| 2311 |
own name, no explanation of what nesting is (DESIGN.md Β§4). */}
|
| 2312 |
<label htmlFor="cg-new-folder">
|
| 2313 |
-
{
|
| 2314 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2315 |
: "New folder"}
|
| 2316 |
</label>
|
| 2317 |
<input
|
|
@@ -2537,6 +2856,29 @@ export default function ViewSidebar({
|
|
| 2537 |
folder, so the old `gid ?? "__root__"` would give React two children with the same
|
| 2538 |
key and it would reconcile one over the other. */
|
| 2539 |
key={isPinnedGroup ? "__pinned__" : gid ?? "__root__"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2540 |
/**
|
| 2541 |
* ββ WAVE 41 Β· T33 (instruction 12) β A NESTED FOLDER IS THIS ROW, INDENTED.
|
| 2542 |
*
|
|
@@ -2555,7 +2897,16 @@ export default function ViewSidebar({
|
|
| 2555 |
same shape of thing rendered in a different place. DESIGN.md Β§4 β this is an
|
| 2556 |
existing element joining the existing rhythm, not a new control shape. */
|
| 2557 |
(asLeaves ? "cg-fold-root" : "cg-fold") +
|
| 2558 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2559 |
// Item 19 β the insertion rule reads "the folder you are dragging lands HERE":
|
| 2560 |
// above this folder, or above the ungrouped section, which is after them all.
|
| 2561 |
(!isPinnedGroup && foldOver === (gid ?? "__root__") && foldDrag && foldDrag !== gid
|
|
@@ -2621,7 +2972,23 @@ export default function ViewSidebar({
|
|
| 2621 |
onDragEnd={() => {
|
| 2622 |
setFoldDrag(null);
|
| 2623 |
setFoldOver(null);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2624 |
}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2625 |
>
|
| 2626 |
{/* β NO DRAG GRIP, and that is a decision rather than an omission. A grip in
|
| 2627 |
flow shifts the folder's name to the right, and this rail's indent is
|
|
|
|
| 38 |
* `customer-grid/**` importing `shell/**`; the event-name/dispatch contract is a sibling of the
|
| 39 |
* grid, and `FormInterface.tsx` and `ImportDialog.tsx` already reach it the same way.
|
| 40 |
*/
|
| 41 |
+
// β W47-T11 adds `TOAST_EVENT` on the same channel: a nesting this rail refuses is a sentence
|
| 42 |
+
// the user has to read, and the frame already listens here for exactly that.
|
| 43 |
+
import { TOAST_EVENT, WORKSPACE_STALE_EVENT, signal } from "../apiContract";
|
| 44 |
import { ROOT_FOLDER_ID } from "./folders";
|
| 45 |
import {
|
| 46 |
folderPath,
|
|
|
|
| 58 |
// menu vocabulary. The Inbox module's header wears the SAME component (`ui/icons.BellIcon`),
|
| 59 |
// so the bell that opens the Inbox and the bell that fills it cannot drift apart.
|
| 60 |
import { BellIcon, StarIcon } from "../ui/icons";
|
| 61 |
+
/**
|
| 62 |
+
* ββ W47-T12 (owner instruction 3) β THE FOLDER RE-PARENT IS EMITTED FROM HERE, AND DELIBERATELY
|
| 63 |
+
* NOT THROUGH THE `onItemMove` PROP.
|
| 64 |
+
*
|
| 65 |
+
* β `onItemMove` IS A VIEW CHANNEL WITH A VIEW WATCHDOG ON IT. `CustomerGrid.tsx::watchItemMove`
|
| 66 |
+
* arms a timer per moved id and then reads `hostViews.find(v => v.id === id)?.folderId ?? null`;
|
| 67 |
+
* a FOLDER id matches no view, so `settled` collapses to `null`, the comparison fails, and every
|
| 68 |
+
* successful nest would be followed seconds later by the sentence *"That view could not be filed
|
| 69 |
+
* there, so it stayed where it was."* β a refusal toast for a move that worked. The watchdog is
|
| 70 |
+
* right about views and simply is not asking about folders, and it lives in a file this ticket
|
| 71 |
+
* does not own.
|
| 72 |
+
*
|
| 73 |
+
* β THE WIRE IS UNCHANGED. This emits the SAME `item_move` event the prop does (`types.ts`'s
|
| 74 |
+
* union already types `itemId` as a plain string), so no new host event kind is invented and the
|
| 75 |
+
* host reads it on the one door `core/grid_events.py::_folder_mutate` already opens. Emitting
|
| 76 |
+
* host events from outside `CustomerGrid` is established here: `useCustomerData.ts` does it.
|
| 77 |
+
*/
|
| 78 |
+
import { emitHostEvent, eventId } from "./hostBridge";
|
| 79 |
// β `SHARED_FOLDER_ID` is no longer imported: W34-T25 replaced both of its call sites with
|
| 80 |
// `isSyntheticFolderId`, and `noUnusedLocals` turns a leftover import into a build error rather
|
| 81 |
// than into dead weight. The constant itself is still exported and still used by `folders.ts`.
|
| 82 |
import {
|
| 83 |
+
folderDropIntent,
|
| 84 |
folderNesting,
|
| 85 |
groupByFolder,
|
| 86 |
isSyntheticFolderId,
|
|
|
|
| 134 |
* β NOT `LockMark`. A share is not one of DESIGN.md Β§4's three locks, and the padlock means a
|
| 135 |
* lock (D-254 is the register row for what happens when one glyph carries both ideas).
|
| 136 |
*/
|
| 137 |
+
/**
|
| 138 |
+
* β W47-T12 β how long the rail shows a folder re-parent the host has not confirmed yet.
|
| 139 |
+
*
|
| 140 |
+
* β DELIBERATELY NOT `ECHO_RECENT_MS` (120s), which is the window `folders.ts` holds a NAME or a
|
| 141 |
+
* TOMBSTONE for. Those are corrections to a payload that is otherwise right; this is a structural
|
| 142 |
+
* claim about where a folder lives, and if the host refuses it the rail is lying about the shape
|
| 143 |
+
* of the tree for the whole window. Two minutes of that is unacceptable and six seconds is a
|
| 144 |
+
* round trip with room to spare, so a nesting that took hangs on to its place and a nesting that
|
| 145 |
+
* was refused snaps back while the host's own refusal sentence is still on screen.
|
| 146 |
+
*/
|
| 147 |
+
const NEST_HOLD_MS = 6_000;
|
| 148 |
+
|
| 149 |
function ShareMark({ size = 13 }: { size?: number }) {
|
| 150 |
return (
|
| 151 |
<svg width={size} height={size} viewBox="0 0 16 16" aria-hidden>
|
|
|
|
| 1385 |
/** The folder being dragged, and the group its insertion line is currently drawn above. */
|
| 1386 |
const [foldDrag, setFoldDrag] = useState<string | null>(null);
|
| 1387 |
const [foldOver, setFoldOver] = useState<string | null>(null);
|
| 1388 |
+
/**
|
| 1389 |
+
* ββ W47-T12 (owner instruction 3) β THE FOLDER THE DRAG WOULD GO *INSIDE*, as opposed to
|
| 1390 |
+
* {@link foldOver}, which is the folder it would land ABOVE.
|
| 1391 |
+
*
|
| 1392 |
+
* TWO STATES RATHER THAN ONE WITH A MODE, because they paint two different pictures that must
|
| 1393 |
+
* never both be on: `foldOver` draws the insertion RULE (`.cg-fold.is-drop-above`) and this one
|
| 1394 |
+
* draws the FILL (`.cg-fold.is-drop`). A single "the folder under the pointer" value plus a
|
| 1395 |
+
* separate "and this is what it means" flag would let a render read the two halves out of one
|
| 1396 |
+
* commit and paint a rule and a fill at once, which is precisely the ambiguity this ticket is
|
| 1397 |
+
* about. Every setter below writes both, so exactly one of them is ever non-null.
|
| 1398 |
+
*
|
| 1399 |
+
* β IT CARRIES `ok`, AND ONLY `ok` PAINTS. `mayNestFolder` is asked during `dragover`, not only
|
| 1400 |
+
* at the drop, so a target that will be refused never lights up β a fill under a drop that is
|
| 1401 |
+
* about to be rejected is worse than no fill. The refused case is still RECORDED rather than
|
| 1402 |
+
* discarded, because `data-fold-drop="refused"` is the difference between "the app has not
|
| 1403 |
+
* noticed my pointer" and "it has, and it will not do this", and releasing there says WHY out
|
| 1404 |
+
* loud on the toast channel.
|
| 1405 |
+
*/
|
| 1406 |
+
const [foldNest, setFoldNest] = useState<{ id: string; ok: boolean } | null>(null);
|
| 1407 |
+
/**
|
| 1408 |
+
* β W47-T12 β the re-parent this browser just performed, held until the host echoes it.
|
| 1409 |
+
*
|
| 1410 |
+
* The rail renders folders from server state, so between the emit and the echo the dragged
|
| 1411 |
+
* folder would sit exactly where it was and the gesture would read as "nothing happened" β the
|
| 1412 |
+
* NO-BLIP law of `folders.ts`, applied to a parent instead of to a name. `folders.ts`'s stamp
|
| 1413 |
+
* map cannot carry it: `CustomerGrid` writes those stamps and this event does not go through
|
| 1414 |
+
* `CustomerGrid`, so the hold lives beside the gesture that made it.
|
| 1415 |
+
*
|
| 1416 |
+
* β IT EXPIRES. A refusal (the store is unreachable, the tree validator says the chain is too
|
| 1417 |
+
* deep) never echoes agreement, and a hold with no clock would leave the rail showing a nesting
|
| 1418 |
+
* the server does not have until the page was reloaded. So it clears the moment the incoming
|
| 1419 |
+
* `folders` prop agrees, and unconditionally a few seconds later whether it agreed or not β by
|
| 1420 |
+
* which time the host's own refusal toast has already said why the folder moved back.
|
| 1421 |
+
*/
|
| 1422 |
+
const [nestHold, setNestHold] =
|
| 1423 |
+
useState<{ id: string; parent: string | null; at: number } | null>(null);
|
| 1424 |
const foldsReorderable = !!folders && !!onFolderReorder;
|
| 1425 |
+
/**
|
| 1426 |
+
* β W47-T12 β nesting needs the folder list and the `item_move` door, and nothing else. It is
|
| 1427 |
+
* deliberately NOT gated on `foldersOn` (which also demands `folderIdOf`, a VIEW-placement
|
| 1428 |
+
* accessor a folder move never consults) so the gesture cannot be switched off by a prop that
|
| 1429 |
+
* has nothing to do with it.
|
| 1430 |
+
*
|
| 1431 |
+
* β `onItemMove` IS READ AS A CAPABILITY, NOT CALLED. Its presence is how a host says it takes
|
| 1432 |
+
* `item_move` at all; the emit itself goes direct, for the reason the `emitHostEvent` import
|
| 1433 |
+
* at the top of this file records.
|
| 1434 |
+
*/
|
| 1435 |
+
const foldsNestable = !!folders && !!onItemMove;
|
| 1436 |
/**
|
| 1437 |
* Land `draggedId` before `beforeId` (null = last) and emit the new order. The arithmetic
|
| 1438 |
* lives in `folders.ts` so a gate can run it under node β the handler around it is DOM.
|
|
|
|
| 1520 |
* a memoized grouping fed by a freshly-allocated folder order recomputes on every render
|
| 1521 |
* anyway, so the two are pinned together or neither is (W41-T37, owner instruction 14).
|
| 1522 |
*/
|
| 1523 |
+
/**
|
| 1524 |
+
* ββ W47-T12 β THE FOLDER LIST WITH THIS BROWSER'S PENDING RE-PARENT APPLIED.
|
| 1525 |
+
*
|
| 1526 |
+
* β APPLIED HERE, ABOVE `folderNesting`, RATHER THAN TO THE GROUPS BELOW IT, because the
|
| 1527 |
+
* parent is not a decoration on a row: it decides `nesting.ordered` (where the folder renders,
|
| 1528 |
+
* and in whose subtree), `nesting.depth` (its indent) and every subsequent `mayNestFolder`
|
| 1529 |
+
* verdict. Patching the picture further down would move the folder on screen while the model
|
| 1530 |
+
* behind the next drag still believed the old tree.
|
| 1531 |
+
*
|
| 1532 |
+
* β COPIED, NEVER MUTATED. `folders` is the memoized list `CustomerGrid` reconciled; writing
|
| 1533 |
+
* `parent` into that row in place would edit the host's own copy and the hold could then never
|
| 1534 |
+
* expire β the value it is supposed to expire back to would be gone.
|
| 1535 |
+
*/
|
| 1536 |
+
const foldersHeld = useMemo(() => {
|
| 1537 |
+
const list = foldersOn ? (folders as GridFolder[]) : [];
|
| 1538 |
+
if (!nestHold) return list;
|
| 1539 |
+
if (!list.some((f) => f.id === nestHold.id)) return list;
|
| 1540 |
+
return list.map((f) => {
|
| 1541 |
+
if (f.id !== nestHold.id) return f;
|
| 1542 |
+
const next: GridFolder = { ...f };
|
| 1543 |
+
// β DELETED, not set to `undefined`. `folderNesting` reads anything that is not a known
|
| 1544 |
+
// string as the top level, so both spellings RENDER the same β but this list is handed on
|
| 1545 |
+
// to `groupByFolder`, whose contract with its own tests is byte-identical output, and a
|
| 1546 |
+
// row carrying an explicit `undefined` key does not serialise like a row without one.
|
| 1547 |
+
if (nestHold.parent) next.parent = nestHold.parent;
|
| 1548 |
+
else delete next.parent;
|
| 1549 |
+
return next;
|
| 1550 |
+
});
|
| 1551 |
+
}, [folders, foldersOn, nestHold]);
|
| 1552 |
+
const nesting = useMemo(() => folderNesting(foldersHeld), [foldersHeld]);
|
| 1553 |
+
/**
|
| 1554 |
+
* β W47-T12 β RETIRE THE HOLD. Two exits, and both are needed:
|
| 1555 |
+
* Β· the incoming list AGREES (the echo landed, or another tab did the same move) β drop it
|
| 1556 |
+
* immediately, so the rail is reading server state again at the first opportunity;
|
| 1557 |
+
* Β· the clock runs out β drop it whether it agreed or not. A refusal never agrees, and this
|
| 1558 |
+
* is what stops a rejected nesting from sitting on screen as a lie until the next reload.
|
| 1559 |
+
* The wait is measured from the DROP, not from this render, so a rail whose folder list churns
|
| 1560 |
+
* cannot keep restarting the timer and extend the hold indefinitely.
|
| 1561 |
+
*/
|
| 1562 |
+
useEffect(() => {
|
| 1563 |
+
if (!nestHold) return;
|
| 1564 |
+
const row = (folders ?? []).find((f) => f.id === nestHold.id);
|
| 1565 |
+
if (!row || (row.parent ?? null) === nestHold.parent) {
|
| 1566 |
+
setNestHold(null);
|
| 1567 |
+
return;
|
| 1568 |
+
}
|
| 1569 |
+
const timer = window.setTimeout(
|
| 1570 |
+
() => setNestHold(null),
|
| 1571 |
+
Math.max(0, nestHold.at + NEST_HOLD_MS - Date.now())
|
| 1572 |
+
);
|
| 1573 |
+
return () => window.clearTimeout(timer);
|
| 1574 |
+
}, [folders, nestHold]);
|
| 1575 |
const canFileMenuView =
|
| 1576 |
foldersOn && !!menuView && mayFileView(menuView, canEditMenuView);
|
| 1577 |
const moveFolders = useMemo(
|
|
|
|
| 1865 |
* serves never fires, so the idle rail pays nothing for it.
|
| 1866 |
*/
|
| 1867 |
const addPreview = addTarget && folderAddPreview ? folderAddPreview(addTarget) : null;
|
| 1868 |
+
/**
|
| 1869 |
+
* ββ W47-T12 (owner instruction 3) β PUT `draggedId` INSIDE `parentId`.
|
| 1870 |
+
*
|
| 1871 |
+
* β `mayNestFolder` IS THE ONLY ORACLE, and it is asked here rather than re-derived: it already
|
| 1872 |
+
* refuses a shared-folder parent, a self-nest, a move into your own descendant and the eleventh
|
| 1873 |
+
* level, and it returns the SENTENCE for each. W47-T11 made the create path speak those same
|
| 1874 |
+
* words on the same channel, so the two halves of the owner's instruction refuse in one voice.
|
| 1875 |
+
*
|
| 1876 |
+
* β THE SERVER IS A SECOND WALL, NOT A DUPLICATE OF THIS ONE. `mayNestFolder` weighs the
|
| 1877 |
+
* PARENT's level plus one; `core/table_store.py::validate_folder_tree` weighs the whole tree
|
| 1878 |
+
* after the move, so dragging a folder that has three levels under it onto a level-9 parent
|
| 1879 |
+
* passes here and is refused there, by name, with its own sentence on the toast channel. Both
|
| 1880 |
+
* refusals are visible; neither invents a second cap.
|
| 1881 |
+
*/
|
| 1882 |
+
const nestFolder = (draggedId: string, parentId: string) => {
|
| 1883 |
+
if (!foldsNestable || !draggedId) return;
|
| 1884 |
+
const verdict = mayNestFolder(nesting, parentId, draggedId);
|
| 1885 |
+
if (!verdict.ok) {
|
| 1886 |
+
signal(TOAST_EVENT, verdict.reason || "That folder cannot go inside that one.");
|
| 1887 |
+
return;
|
| 1888 |
+
}
|
| 1889 |
+
// Already there: say nothing. An event that changes nothing still bumps every reader's
|
| 1890 |
+
// payload and reconciles to the identical tree β `reorderFolderIds`' own rule, one layer up.
|
| 1891 |
+
if ((nesting.parent[draggedId] ?? null) === parentId) return;
|
| 1892 |
+
setNestHold({ id: draggedId, parent: parentId, at: Date.now() });
|
| 1893 |
+
// β `surface: "views"` is not a guess: this rail's every folder event is emitted by
|
| 1894 |
+
// `CustomerGrid` against that surface, and the cohort rail is a different component with its
|
| 1895 |
+
// own. See the `emitHostEvent` import for why this does not ride the `onItemMove` prop.
|
| 1896 |
+
emitHostEvent({
|
| 1897 |
+
id: eventId("foldnest"),
|
| 1898 |
+
type: "item_move",
|
| 1899 |
+
surface: "views",
|
| 1900 |
+
itemId: draggedId,
|
| 1901 |
+
folderId: parentId,
|
| 1902 |
+
});
|
| 1903 |
+
};
|
| 1904 |
+
/**
|
| 1905 |
+
* ββ W47-T12 β THE FOLDER HEAD IS WHERE THE GESTURE FORKS, and this is the whole affordance.
|
| 1906 |
+
*
|
| 1907 |
+
* β THE HARD PART OF THIS TICKET IS NOT THE RE-PARENT, IT IS TELLING THE TWO DROPS APART. One
|
| 1908 |
+
* drag now means two things, so without a visible fork every reorder becomes an accidental nest
|
| 1909 |
+
* and the user has to go hunting for the folder they lost. The fork is geometric and the two
|
| 1910 |
+
* pictures already exist in `index.css`, built for exactly these meanings:
|
| 1911 |
+
*
|
| 1912 |
+
* Β· the top 8px of the head (or a third of it, whichever is less β {@link folderDropIntent})
|
| 1913 |
+
* -> REORDER. `.cg-fold.is-drop-above`: a 2px inset rule along the folder's top edge,
|
| 1914 |
+
* which is wave 20's own indicator and reads as "it lands here".
|
| 1915 |
+
* Β· the rest of the head -> NEST. `.cg-fold.is-drop`: the tint plus dashed outline whose own
|
| 1916 |
+
* comment in index.css glosses it as "drop this INTO me".
|
| 1917 |
+
* Β· everywhere ELSE in the group (the view rows, the space under them) -> REORDER, exactly as
|
| 1918 |
+
* before. That is deliberate: it leaves the big, easy target meaning what it always meant
|
| 1919 |
+
* and asks for deliberate aim only for the new thing.
|
| 1920 |
+
*
|
| 1921 |
+
* β `stopPropagation` ON THE FOLD TYPE ONLY. This element sits inside the group whose
|
| 1922 |
+
* `dropHandlers` claim the same MIME and would immediately overwrite the fork with a plain
|
| 1923 |
+
* "land above". A VIEW drag (`text/plain`) is deliberately left to bubble, so filing a view by
|
| 1924 |
+
* dropping it on a folder head keeps working byte for byte.
|
| 1925 |
+
*
|
| 1926 |
+
* β AND THE DROP CLEARS `foldDrag` ITSELF. A successful nest re-parents this folder, React
|
| 1927 |
+
* unmounts the node that started the drag, and the browser never dispatches `dragend` on a
|
| 1928 |
+
* removed node β the scar W34-T21 left on the view path, where `is-viewdrag`'s 45% opacity
|
| 1929 |
+
* stuck permanently. Same shape here, same fix: clear at the drop, not only at `dragend`.
|
| 1930 |
+
*/
|
| 1931 |
+
const foldHeadDropHandlers = (folderId: string) =>
|
| 1932 |
+
foldsReorderable
|
| 1933 |
+
? {
|
| 1934 |
+
onDragOver: (e: React.DragEvent) => {
|
| 1935 |
+
if (!e.dataTransfer.types.includes(FOLD_DRAG_TYPE)) return;
|
| 1936 |
+
e.preventDefault();
|
| 1937 |
+
e.stopPropagation();
|
| 1938 |
+
e.dataTransfer.dropEffect = "move";
|
| 1939 |
+
const box = e.currentTarget.getBoundingClientRect();
|
| 1940 |
+
if (!foldsNestable
|
| 1941 |
+
|| folderDropIntent(e.clientY - box.top, box.height) === "before") {
|
| 1942 |
+
setFoldNest(null);
|
| 1943 |
+
setFoldOver(folderId);
|
| 1944 |
+
return;
|
| 1945 |
+
}
|
| 1946 |
+
setFoldOver(null);
|
| 1947 |
+
// β READ OFF `foldDrag`, NEVER off `dataTransfer`. Every browser puts the payload in
|
| 1948 |
+
// protected mode during `dragover` β `getData` answers "" until the drop β so a
|
| 1949 |
+
// verdict asked of the transfer would be a verdict about an empty id, and the fill
|
| 1950 |
+
// would light up on targets that are about to refuse.
|
| 1951 |
+
setFoldNest({
|
| 1952 |
+
id: folderId,
|
| 1953 |
+
ok: !!foldDrag && mayNestFolder(nesting, folderId, foldDrag).ok,
|
| 1954 |
+
});
|
| 1955 |
+
},
|
| 1956 |
+
onDragLeave: (e: React.DragEvent) => {
|
| 1957 |
+
// The GROUP's `onDragLeave` clears `dropTarget` and `foldOver` and knows nothing
|
| 1958 |
+
// about the fork, so the fill would survive the pointer leaving the head.
|
| 1959 |
+
//
|
| 1960 |
+
// β BUT ONLY WHEN THE POINTER REALLY LEFT. `dragleave` BUBBLES, and this head holds
|
| 1961 |
+
// a button, a mark and a name span β so crossing between them fires a leave on each
|
| 1962 |
+
// one that arrives here, and an unguarded clear would blink the fill off and on for
|
| 1963 |
+
// the whole time the pointer sits on the very target it is aimed at. `relatedTarget`
|
| 1964 |
+
// is where the pointer went; if that is still inside this head, nothing was left.
|
| 1965 |
+
// (Null means it went outside the document, which IS a leave.)
|
| 1966 |
+
const gone = e.relatedTarget as Node | null;
|
| 1967 |
+
if (gone && e.currentTarget.contains(gone)) return;
|
| 1968 |
+
setFoldNest(null);
|
| 1969 |
+
setFoldOver(null);
|
| 1970 |
+
},
|
| 1971 |
+
onDrop: (e: React.DragEvent) => {
|
| 1972 |
+
if (!e.dataTransfer.types.includes(FOLD_DRAG_TYPE)) return;
|
| 1973 |
+
e.preventDefault();
|
| 1974 |
+
e.stopPropagation();
|
| 1975 |
+
const dragged = e.dataTransfer.getData(FOLD_DRAG_TYPE);
|
| 1976 |
+
const box = e.currentTarget.getBoundingClientRect();
|
| 1977 |
+
const intent = folderDropIntent(e.clientY - box.top, box.height);
|
| 1978 |
+
setFoldNest(null);
|
| 1979 |
+
setFoldOver(null);
|
| 1980 |
+
setFoldDrag(null);
|
| 1981 |
+
setDropTarget(null);
|
| 1982 |
+
if (!dragged) return;
|
| 1983 |
+
if (!foldsNestable || intent === "before") {
|
| 1984 |
+
reorderFolders(dragged, folderId);
|
| 1985 |
+
return;
|
| 1986 |
+
}
|
| 1987 |
+
nestFolder(dragged, folderId);
|
| 1988 |
+
},
|
| 1989 |
+
}
|
| 1990 |
+
: {};
|
| 1991 |
/**
|
| 1992 |
* ONE pair of drop handlers per group, serving TWO drags β a view being filed into this
|
| 1993 |
* folder (`text/plain`) and, since wave 20 item 19, a folder being dropped in front of
|
|
|
|
| 2182 |
setName("");
|
| 2183 |
};
|
| 2184 |
|
| 2185 |
+
/**
|
| 2186 |
+
* ββ W47-T11 (owner instruction 3) β WHERE A NEW FOLDER ACTUALLY GOES, answered ONCE for both
|
| 2187 |
+
* the pane's label and the Create click, so the form cannot name one destination and the
|
| 2188 |
+
* commit quietly choose another.
|
| 2189 |
+
*
|
| 2190 |
+
* β `folderParent ?? atId` IS THE FIX, and the missing half was the whole of what the owner
|
| 2191 |
+
* reported as *"Creating a folder inside a folder needs to work, it doesn't for now. Only view
|
| 2192 |
+
* works."* `create` (views, above) has always read BOTH sources; this door read only the
|
| 2193 |
+
* explicit one, so "+ Create new" then "Folder" while the rail was standing three levels down
|
| 2194 |
+
* built a folder at the TOP LEVEL. Both doors now mean the same thing by "here", which is why
|
| 2195 |
+
* one worked and the other did not.
|
| 2196 |
+
*
|
| 2197 |
+
* β THE PARENT IS RESOLVED AT THE COMMIT, not trusted from when the pane opened (W41-T33's
|
| 2198 |
+
* reason, unchanged): the pane outlives the click that pointed it somewhere, and that folder
|
| 2199 |
+
* can be deleted or arrive a level deeper from another tab while the name is being typed.
|
| 2200 |
+
*
|
| 2201 |
+
* β A PARENT THE TREE CANNOT RESOLVE STILL FALLS TO THE ROOT IN SILENCE, exactly as it did
|
| 2202 |
+
* before, and only the verdicts a person can actually cause are spoken. `atId` is returned raw
|
| 2203 |
+
* while a search needle is live, so an unresolvable id is a stale path rather than a placement
|
| 2204 |
+
* anyone chose; refusing it by name would replace the old lie with a new one.
|
| 2205 |
+
*/
|
| 2206 |
+
const folderDestOf = (
|
| 2207 |
+
wanted: string | null
|
| 2208 |
+
): { into: string | null; refusal: string | null } => {
|
| 2209 |
+
if (!wanted) return { into: null, refusal: null };
|
| 2210 |
+
if (!isSyntheticFolderId(wanted) && !nesting.depth[wanted])
|
| 2211 |
+
return { into: null, refusal: null };
|
| 2212 |
+
const verdict = mayNestFolder(nesting, wanted);
|
| 2213 |
+
if (verdict.ok) return { into: wanted, refusal: null };
|
| 2214 |
+
/*
|
| 2215 |
+
* The CAUSE comes from `mayNestFolder`, which is the one place that decides it; the OUTCOME
|
| 2216 |
+
* and the next step are added here, because a sentence that explains the cap and stops
|
| 2217 |
+
* leaves the user hunting for a folder that was never made. Same shape as the refusals
|
| 2218 |
+
* `core/grid_events.py` already sends from the other wall.
|
| 2219 |
+
*/
|
| 2220 |
+
return {
|
| 2221 |
+
into: null,
|
| 2222 |
+
refusal:
|
| 2223 |
+
`${verdict.reason ?? "That folder cannot hold another folder."} `
|
| 2224 |
+
+ "Nothing was created, so pick a different place for it and try again.",
|
| 2225 |
+
};
|
| 2226 |
+
};
|
| 2227 |
+
const folderDest = folderDestOf(folderParent ?? atId);
|
| 2228 |
+
|
| 2229 |
const createFolder = () => {
|
| 2230 |
const value = folderName.trim();
|
| 2231 |
if (!value) return;
|
| 2232 |
+
/*
|
| 2233 |
+
* ββ W47-T11 β A REFUSED NESTING IS SAID OUT LOUD AND NOTHING IS WRITTEN.
|
| 2234 |
+
*
|
| 2235 |
+
* β THIS LINE USED TO READ `mayNestFolder(...).ok ? folderParent : null`, which put the
|
| 2236 |
+
* folder at the top level with no word said. From outside that is indistinguishable from
|
| 2237 |
+
* "creating a folder inside a folder does not work": the user aimed at a folder, pressed
|
| 2238 |
+
* Create, and found the result somewhere else. The pane is deliberately LEFT OPEN with the
|
| 2239 |
+
* typed name in it, so the choice between cancelling and aiming somewhere else is still
|
| 2240 |
+
* theirs to make.
|
| 2241 |
+
*/
|
| 2242 |
+
if (folderDest.refusal) {
|
| 2243 |
+
signal(TOAST_EVENT, folderDest.refusal);
|
| 2244 |
+
return;
|
| 2245 |
+
}
|
| 2246 |
+
const into = folderDest.into;
|
| 2247 |
/**
|
| 2248 |
* ββ WAVE 41 Β· T34 β FILING A FOLDER INTO ONE OPENS IT, or the new folder is created
|
| 2249 |
* INVISIBLY.
|
|
|
|
| 2534 |
no create-flyout to fold it into; that file is deleted this wave, so the class now has
|
| 2535 |
no consumer in this tree. Left in index.css rather than swept blind: a CSS rule with
|
| 2536 |
no consumer is inert, and hunting one down mid-wave is how a rule something else still
|
| 2537 |
+
reads gets removed. Named here so the sweep is a decision, not a discovery.
|
| 2538 |
+
|
| 2539 |
+
ββ WAVE 47 T10 (owner instruction 1) β `cg-link-btn cg-create-btn` AND THE TWO SPANS
|
| 2540 |
+
BELOW ARE NOW READ BY A SECOND CALL SITE. The owner walked from a database into a
|
| 2541 |
+
folder path and saw one job in two treatments, and named THIS one as the keeper. So
|
| 2542 |
+
`shell/NavExtras.tsx::CreateNewRow` β the door the data layer mounts through
|
| 2543 |
+
`createControl`, one level up in this same rail β renders exactly this markup instead
|
| 2544 |
+
of its old `.shell-newfolder` register.
|
| 2545 |
+
β CONSEQUENCE FOR ANY LATER EDIT HERE: these class names are a shared contract now,
|
| 2546 |
+
not private to this button. Changing the treatment means changing both call sites, and
|
| 2547 |
+
moving it to a local class re-opens the drift the owner reported. */}
|
| 2548 |
<div className="cg-create-new">
|
| 2549 |
<button
|
| 2550 |
type="button"
|
|
|
|
| 2623 |
form the user has to remember which menu they came from. One line, the folder's
|
| 2624 |
own name, no explanation of what nesting is (DESIGN.md Β§4). */}
|
| 2625 |
<label htmlFor="cg-new-folder">
|
| 2626 |
+
{/* β W47-T11 β THE SAME RESOLVED DESTINATION THE CLICK WILL USE, `folderParent`
|
| 2627 |
+
falling back to the folder the rail is standing in. Reading `folderParent` alone
|
| 2628 |
+
here would now say "New folder" while Create nested it, and a label that has to
|
| 2629 |
+
be wrong for the feature to work is the defect one layer up. A destination that
|
| 2630 |
+
is REFUSED reads as the plain "New folder", because the pane must not advertise a
|
| 2631 |
+
nest the Create button is about to decline. */}
|
| 2632 |
+
{folderDest.into && folders?.find((f) => f.id === folderDest.into)
|
| 2633 |
+
? `New folder in ${folders.find((f) => f.id === folderDest.into)!.name}`
|
| 2634 |
: "New folder"}
|
| 2635 |
</label>
|
| 2636 |
<input
|
|
|
|
| 2856 |
folder, so the old `gid ?? "__root__"` would give React two children with the same
|
| 2857 |
key and it would reconcile one over the other. */
|
| 2858 |
key={isPinnedGroup ? "__pinned__" : gid ?? "__root__"}
|
| 2859 |
+
/**
|
| 2860 |
+
* ββ W47-T12 β WHICH OF THE TWO THINGS THIS DROP WOULD DO, in a word, on the element.
|
| 2861 |
+
*
|
| 2862 |
+
* β AN ATTRIBUTE RATHER THAN A THIRD CLASS, and the reason is a fence rather than a
|
| 2863 |
+
* preference: this ticket may not add a CSS rule, so a class nothing styles would be
|
| 2864 |
+
* invisible and a class something styles would need that rule. The two PICTURES are
|
| 2865 |
+
* `.is-drop` (nest) and `.is-drop-above` (reorder), which already exist; this says the
|
| 2866 |
+
* same thing in a form a person driving the gesture, or a headless check, can read
|
| 2867 |
+
* without measuring pixels β including the one state that paints NOTHING on purpose,
|
| 2868 |
+
* `refused`, which is otherwise indistinguishable from the app not noticing the pointer.
|
| 2869 |
+
*
|
| 2870 |
+
* β ABSENT unless a folder drag is actually in flight, so the idle rail's DOM is
|
| 2871 |
+
* byte-identical to the pre-T12 one.
|
| 2872 |
+
*/
|
| 2873 |
+
data-fold-drop={
|
| 2874 |
+
foldDrag === null
|
| 2875 |
+
? undefined
|
| 2876 |
+
: foldNest && foldNest.id === gid
|
| 2877 |
+
? (foldNest.ok ? "nest" : "refused")
|
| 2878 |
+
: !isPinnedGroup && foldOver === (gid ?? "__root__") && foldDrag !== gid
|
| 2879 |
+
? "before"
|
| 2880 |
+
: undefined
|
| 2881 |
+
}
|
| 2882 |
/**
|
| 2883 |
* ββ WAVE 41 Β· T33 (instruction 12) β A NESTED FOLDER IS THIS ROW, INDENTED.
|
| 2884 |
*
|
|
|
|
| 2897 |
same shape of thing rendered in a different place. DESIGN.md Β§4 β this is an
|
| 2898 |
existing element joining the existing rhythm, not a new control shape. */
|
| 2899 |
(asLeaves ? "cg-fold-root" : "cg-fold") +
|
| 2900 |
+
// ββ W47-T12 β THE SECOND READER OF THIS FILL, and it is the same sentence.
|
| 2901 |
+
// `.is-drop` has meant "drop this INTO me" since wave 8 (index.css says so in as many
|
| 2902 |
+
// words); a folder about to be nested is that sentence with a folder in it, so the
|
| 2903 |
+
// rail gains a meaning without gaining a vocabulary. `foldNest.ok` gates it: a target
|
| 2904 |
+
// `mayNestFolder` will refuse never lights up, it only records `data-fold-drop`.
|
| 2905 |
+
(!isPinnedGroup
|
| 2906 |
+
&& (dropTarget === (gid ?? "__root__")
|
| 2907 |
+
|| (!!foldNest && foldNest.ok && foldNest.id === gid))
|
| 2908 |
+
? " is-drop"
|
| 2909 |
+
: "") +
|
| 2910 |
// Item 19 β the insertion rule reads "the folder you are dragging lands HERE":
|
| 2911 |
// above this folder, or above the ungrouped section, which is after them all.
|
| 2912 |
(!isPinnedGroup && foldOver === (gid ?? "__root__") && foldDrag && foldDrag !== gid
|
|
|
|
| 2972 |
onDragEnd={() => {
|
| 2973 |
setFoldDrag(null);
|
| 2974 |
setFoldOver(null);
|
| 2975 |
+
// β W47-T12 β the fork's own state joins the two it was modelled on. A drag
|
| 2976 |
+
// abandoned over a folder head would otherwise leave the "will nest" fill lit
|
| 2977 |
+
// with nothing being dragged.
|
| 2978 |
+
setFoldNest(null);
|
| 2979 |
}}
|
| 2980 |
+
/* ββ W47-T12 β THE TWO-BAND FORK, on the head and only on the head. Spread LAST so
|
| 2981 |
+
it is unmistakable that these add `onDragOver` / `onDragLeave` / `onDrop` and
|
| 2982 |
+
replace none of the three handlers above: this element had no drop handlers at
|
| 2983 |
+
all before this ticket, which is why the group underneath could claim every
|
| 2984 |
+
folder drop as "land above me".
|
| 2985 |
+
β AND NOT ON A SYNTHESISED OR MANAGED HEAD, matching the group's own spread two
|
| 2986 |
+
dozen lines up. "Shared with me" and a colleague's shared folder are a READING of
|
| 2987 |
+
the view list with no record behind them, so a nest would emit `item_move` naming
|
| 2988 |
+
a parent that exists in nobody's store and a reorder would send an order carrying
|
| 2989 |
+
an id `reorderFolderIds` was never given. `mayNestFolder` refuses the first in
|
| 2990 |
+
words; the second has no such wall, so the gesture simply is not offered here. */
|
| 2991 |
+
{...(isSynthetic || isManaged ? {} : foldHeadDropHandlers(group.folder.id))}
|
| 2992 |
>
|
| 2993 |
{/* β NO DRAG GRIP, and that is a decision rather than an omission. A grip in
|
| 2994 |
flow shifts the folder's name to the right, and this rail's indent is
|
web/src/customer-grid/folders.ts
CHANGED
|
@@ -763,6 +763,51 @@ export function reorderFolderIds(
|
|
| 763 |
return next;
|
| 764 |
}
|
| 765 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 766 |
/**
|
| 767 |
* ββ WAVE 34 Β· T22 (ruling R4, `D-249`) β MAY THIS VIEWER FILE THIS VIEW INTO A FOLDER?
|
| 768 |
*
|
|
|
|
| 763 |
return next;
|
| 764 |
}
|
| 765 |
|
| 766 |
+
/**
|
| 767 |
+
* ββ WAVE 47 Β· T12 (owner instruction 3) β WHICH OF THE TWO THINGS A FOLDER DROP MEANS.
|
| 768 |
+
*
|
| 769 |
+
* Owner: *"make sure we can drag and drop folder into another folder"*. Wave 20 gave the rail a
|
| 770 |
+
* folder drag that only ever REORDERED siblings, so the same gesture now has to say two things β
|
| 771 |
+
* *land above this folder* and *go inside this folder* β and the whole risk of the feature is
|
| 772 |
+
* that the second one eats the first. A user who meant to reorder and got a nest has to find the
|
| 773 |
+
* folder they lost.
|
| 774 |
+
*
|
| 775 |
+
* β SO THE MEANING IS A BAND, READ OFF THE FOLDER HEAD, AND THE TOP EDGE KEEPS THE OLD MEANING.
|
| 776 |
+
* `offsetY` is the pointer's distance below the top of the `.cg-fold-head` row (its
|
| 777 |
+
* `getBoundingClientRect()`), `height` that row's height:
|
| 778 |
+
*
|
| 779 |
+
* Β· the top strip -> `"before"`, wave 20's sibling reorder, drawn as the insertion RULE
|
| 780 |
+
* (`.cg-fold.is-drop-above`, an inset 2px line at the folder's top edge);
|
| 781 |
+
* Β· everything else -> `"nest"`, drawn as the FILL (`.cg-fold.is-drop`, tint + dashed outline),
|
| 782 |
+
* which index.css already glosses as *"drop this view INTO me"*. The two
|
| 783 |
+
* pictures exist, they were built to be told apart, and neither is new.
|
| 784 |
+
*
|
| 785 |
+
* β THE STRIP IS 8px OR A THIRD OF THE ROW, WHICHEVER IS SMALLER, and both halves matter. 8px is
|
| 786 |
+
* the size of the insertion rule's own affordance on a ~24px head, so the paint and the hit box
|
| 787 |
+
* agree; the fraction is what keeps a squashed or zoomed row from turning its whole surface into
|
| 788 |
+
* a reorder band. There is no third band for *"land AFTER this folder"* because there is no such
|
| 789 |
+
* arithmetic to route it to β {@link reorderFolderIds} takes a `beforeId` and nothing else β and
|
| 790 |
+
* inventing one here would be a second evaluator for the sequence.
|
| 791 |
+
*
|
| 792 |
+
* β REORDER IS NOT LEFT ON A 8px TARGET ALONE. The head is the only NESTING surface; the rest of
|
| 793 |
+
* the folder's group (its view rows, the space under them) keeps wave 20's drop untouched, so the
|
| 794 |
+
* big easy target still means reorder and only the deliberate one means nest.
|
| 795 |
+
*
|
| 796 |
+
* Pure, and in this module rather than in the handler, for the reason the file header gives: the
|
| 797 |
+
* drop handler is DOM and cannot be run under node, and this is the part of the gesture a test
|
| 798 |
+
* can hold.
|
| 799 |
+
*/
|
| 800 |
+
export type FolderDropIntent = "nest" | "before";
|
| 801 |
+
|
| 802 |
+
export function folderDropIntent(offsetY: number, height: number): FolderDropIntent {
|
| 803 |
+
const tall = Number.isFinite(height) && height > 0 ? height : 0;
|
| 804 |
+
const band = Math.min(8, tall / 3);
|
| 805 |
+
// β `<` rather than `<=`, so a zero-height row (a folder mid-unmount, a display:none read)
|
| 806 |
+
// cannot answer "before" for a pointer that is nowhere: with `band === 0` every offset falls
|
| 807 |
+
// through to the nest branch, which is the branch `mayNestFolder` then gets to refuse out loud.
|
| 808 |
+
return Number.isFinite(offsetY) && offsetY < band ? "before" : "nest";
|
| 809 |
+
}
|
| 810 |
+
|
| 811 |
/**
|
| 812 |
* ββ WAVE 34 Β· T22 (ruling R4, `D-249`) β MAY THIS VIEWER FILE THIS VIEW INTO A FOLDER?
|
| 813 |
*
|
web/src/customer-grid/map.css
CHANGED
|
@@ -249,11 +249,23 @@
|
|
| 249 |
.cg-w44-route-detail:disabled { color: var(--lp-muted); cursor: not-allowed; }
|
| 250 |
.cg-w44-route-select:focus-visible, .cg-w44-route-detail:focus-visible, .cg-w44-route-back:focus-visible, .cg-w44-route-stops button:focus-visible { outline: 2px solid var(--lp-blue-deep); outline-offset: 2px; }
|
| 251 |
.cg-w44-route-empty { margin: 0; color: var(--lp-muted); }
|
| 252 |
-
|
| 253 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
.cg-w44-route-stop-open { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
| 255 |
-
|
| 256 |
-
|
|
|
|
|
|
|
| 257 |
.cg-w44-route-position { display: grid; gap: 2px; color: var(--lp-muted); font-size: var(--lp-fs-3xs); }
|
| 258 |
.cg-w44-route-order { box-sizing: border-box; width: 46px; height: 28px; padding: 3px 5px; border: 1px solid var(--lp-line); border-radius: var(--lp-r-sm); background: var(--cg-white); color: inherit; font: inherit; text-align: center; }
|
| 259 |
.cg-w44-route-order:focus-visible { outline: 2px solid var(--lp-blue-deep); outline-offset: 1px; }
|
|
|
|
| 249 |
.cg-w44-route-detail:disabled { color: var(--lp-muted); cursor: not-allowed; }
|
| 250 |
.cg-w44-route-select:focus-visible, .cg-w44-route-detail:focus-visible, .cg-w44-route-back:focus-visible, .cg-w44-route-stops button:focus-visible { outline: 2px solid var(--lp-blue-deep); outline-offset: 2px; }
|
| 251 |
.cg-w44-route-empty { margin: 0; color: var(--lp-muted); }
|
| 252 |
+
/* β W47-T04: `minmax(0, 1fr)` IS LOAD-BEARING. A grid's implicit column is `auto`, which
|
| 253 |
+
sizes to MAX-CONTENT, so each row was free to grow past the panel and take its Move
|
| 254 |
+
button off the right edge no matter how the row itself was laid out. Capping the track
|
| 255 |
+
at `minmax(0, 1fr)` is what lets the row shrink and the name's ellipsis engage. */
|
| 256 |
+
.cg-w44-route-stops { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; margin: 0; padding-left: 20px; }
|
| 257 |
+
/* β W47-T04 (owner instruction 4, reference image ERROR 15.png): ONE STOP, ONE LINE.
|
| 258 |
+
β THE OLD RULE WAS A TWO-COLUMN GRID AND THE ROW HAS THREE OR FOUR CHILDREN - grip, open
|
| 259 |
+
button, action cluster, and a conditional error. So the actions were placed in column 1 of a
|
| 260 |
+
SECOND row, under the name, which is exactly the "name and list is all over the place" the
|
| 261 |
+
owner photographed. A flex row cannot do that: only the error is allowed to wrap, via its own
|
| 262 |
+
100 percent basis. */
|
| 263 |
+
.cg-w44-route-stops li { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; }
|
| 264 |
.cg-w44-route-stop-open { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
| 265 |
+
/* `margin-left: auto` pins the controls to the trailing edge, so every row's Move button starts
|
| 266 |
+
on the same x no matter how long the record name is. */
|
| 267 |
+
.cg-w44-route-stop-actions { display: inline-flex; align-items: center; flex: 0 0 auto; margin-left: auto; gap: 4px; }
|
| 268 |
+
.cg-w44-route-outside { flex: 1 0 100%; grid-column: 1 / -1; color: var(--lp-muted); font: 500 var(--lp-fs-3xs)/1.4 Inter, system-ui, sans-serif; }
|
| 269 |
.cg-w44-route-position { display: grid; gap: 2px; color: var(--lp-muted); font-size: var(--lp-fs-3xs); }
|
| 270 |
.cg-w44-route-order { box-sizing: border-box; width: 46px; height: 28px; padding: 3px 5px; border: 1px solid var(--lp-line); border-radius: var(--lp-r-sm); background: var(--cg-white); color: inherit; font: inherit; text-align: center; }
|
| 271 |
.cg-w44-route-order:focus-visible { outline: 2px solid var(--lp-blue-deep); outline-offset: 1px; }
|
web/src/customer-grid/routeZoneTypes.ts
CHANGED
|
@@ -1,140 +1,144 @@
|
|
| 1 |
-
// Wave 44 Route / Zone wire model. MapView never writes a legacy Destination N field.
|
| 2 |
-
export type ZoneGeometry =
|
| 3 |
-
| { type: "Polygon"; coordinates: number[][][] }
|
| 4 |
-
| { type: "MultiPolygon"; coordinates: number[][][][] }
|
| 5 |
-
| { type: "Circle"; center: [number, number]; radiusMeters: number };
|
| 6 |
-
|
| 7 |
-
export interface MapZoneDto {
|
| 8 |
-
id: string; name: string; color: string; geometryGeoJson: ZoneGeometry | null;
|
| 9 |
-
zipCodes: string[]; visible: boolean; memberships: number[];
|
| 10 |
-
geographicField?: string;
|
| 11 |
-
membershipRevision?: number;
|
| 12 |
-
sourceViewId?: string | null;
|
| 13 |
-
createdBy?: string;
|
| 14 |
-
createdAt?: string;
|
| 15 |
-
permission?: { canEdit?: boolean; canDelete?: boolean };
|
| 16 |
-
}
|
| 17 |
-
|
| 18 |
-
export interface RouteDeliveryDto {
|
| 19 |
-
id: string;
|
| 20 |
-
name: string;
|
| 21 |
-
recipient: string;
|
| 22 |
-
schedule: { cron?: string; enabled?: boolean; timezone?: string };
|
| 23 |
-
snapshot: {
|
| 24 |
-
routeId: string;
|
| 25 |
-
sourceViewId: string;
|
| 26 |
-
sourceViewRevision: string;
|
| 27 |
-
sourceViewName: string;
|
| 28 |
-
timezone: string;
|
| 29 |
-
routeField: string;
|
| 30 |
-
orderedStopIds: number[];
|
| 31 |
-
mapsPerLink: number;
|
| 32 |
-
};
|
| 33 |
-
createdBy?: string;
|
| 34 |
-
created?: string;
|
| 35 |
-
}
|
| 36 |
-
|
| 37 |
-
export interface RouteDeliveryRequest {
|
| 38 |
-
recipient: string;
|
| 39 |
-
timezone: string;
|
| 40 |
-
mapsPerLink: number;
|
| 41 |
-
}
|
| 42 |
-
|
| 43 |
-
export interface RouteAssignee {
|
| 44 |
-
username: string;
|
| 45 |
-
name: string;
|
| 46 |
-
}
|
| 47 |
-
|
| 48 |
-
export interface RouteAssigneeDirectory {
|
| 49 |
-
today: string;
|
| 50 |
-
people: RouteAssignee[];
|
| 51 |
-
}
|
| 52 |
-
|
| 53 |
-
export interface MapRouteDto {
|
| 54 |
-
id: string; name: string; color: string; number: number; visibleStopIds: number[];
|
| 55 |
-
outsideFilter: boolean;
|
| 56 |
-
permission: { canEdit: boolean; sourceViewId: string | null };
|
| 57 |
-
source: { viewId: string | null; revision: string | null };
|
| 58 |
-
/** Read-through of a saved route-order field. It remains visible without mutating on GET. */
|
| 59 |
-
compatibility?: "legacy-route-order";
|
| 60 |
-
mapsUrl?: string;
|
| 61 |
-
owner: string;
|
| 62 |
-
shared: boolean;
|
| 63 |
-
sharedOut: boolean;
|
| 64 |
-
hasShares: boolean;
|
| 65 |
-
sharedRole: "view" | "edit" | null;
|
| 66 |
-
/** Generic field bridge address consumed by the established Share dialog. */
|
| 67 |
-
shareId: string;
|
| 68 |
-
/** This reader's personal Route filing; it never changes the shared Route object. */
|
| 69 |
-
folderId: string | null;
|
| 70 |
-
navOrder: number;
|
| 71 |
-
assignee: string | null;
|
| 72 |
-
date: string | null;
|
| 73 |
-
/** D-599: the Zone this Route belongs to, or null. Always present on the wire; every Route
|
| 74 |
-
* saved before wave 46's hotfix legitimately has none, so null is data and not an error. */
|
| 75 |
-
zoneId: string | null;
|
| 76 |
-
starred?: boolean;
|
| 77 |
-
capabilities?: Partial<Record<"rename" | "duplicate" | "star" | "share" | "delete", boolean>>;
|
| 78 |
-
}
|
| 79 |
-
|
| 80 |
-
export interface MapRouteFolderDto {
|
| 81 |
-
id: string;
|
| 82 |
-
name: string;
|
| 83 |
-
parent: string | null;
|
| 84 |
-
order: number;
|
| 85 |
-
}
|
| 86 |
-
|
| 87 |
-
export type MapRouteUpdate = {
|
| 88 |
-
name?: string;
|
| 89 |
-
mapsUrl?: string;
|
| 90 |
-
starred?: boolean;
|
| 91 |
-
assignee?: string | null;
|
| 92 |
-
date?: string | null;
|
| 93 |
-
/** D-599. Absent inherits the stored Zone; an explicit null clears it. The server refuses an
|
| 94 |
-
* id no Zone on this database carries, with `unknown_zone`. */
|
| 95 |
-
zoneId?: string | null;
|
| 96 |
-
};
|
| 97 |
-
|
| 98 |
-
export interface RouteSelectionRequest { routeIds: string[]; viewState: Record<string, unknown>; }
|
| 99 |
-
|
| 100 |
-
export interface RouteSelectionResponse {
|
| 101 |
-
managedBy: "loopable";
|
| 102 |
-
viewState: Record<string, unknown>;
|
| 103 |
-
}
|
| 104 |
-
|
| 105 |
-
/** The
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Wave 44 Route / Zone wire model. MapView never writes a legacy Destination N field.
|
| 2 |
+
export type ZoneGeometry =
|
| 3 |
+
| { type: "Polygon"; coordinates: number[][][] }
|
| 4 |
+
| { type: "MultiPolygon"; coordinates: number[][][][] }
|
| 5 |
+
| { type: "Circle"; center: [number, number]; radiusMeters: number };
|
| 6 |
+
|
| 7 |
+
export interface MapZoneDto {
|
| 8 |
+
id: string; name: string; color: string; geometryGeoJson: ZoneGeometry | null;
|
| 9 |
+
zipCodes: string[]; visible: boolean; memberships: number[];
|
| 10 |
+
geographicField?: string;
|
| 11 |
+
membershipRevision?: number;
|
| 12 |
+
sourceViewId?: string | null;
|
| 13 |
+
createdBy?: string;
|
| 14 |
+
createdAt?: string;
|
| 15 |
+
permission?: { canEdit?: boolean; canDelete?: boolean };
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
export interface RouteDeliveryDto {
|
| 19 |
+
id: string;
|
| 20 |
+
name: string;
|
| 21 |
+
recipient: string;
|
| 22 |
+
schedule: { cron?: string; enabled?: boolean; timezone?: string };
|
| 23 |
+
snapshot: {
|
| 24 |
+
routeId: string;
|
| 25 |
+
sourceViewId: string;
|
| 26 |
+
sourceViewRevision: string;
|
| 27 |
+
sourceViewName: string;
|
| 28 |
+
timezone: string;
|
| 29 |
+
routeField: string;
|
| 30 |
+
orderedStopIds: number[];
|
| 31 |
+
mapsPerLink: number;
|
| 32 |
+
};
|
| 33 |
+
createdBy?: string;
|
| 34 |
+
created?: string;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
export interface RouteDeliveryRequest {
|
| 38 |
+
recipient: string;
|
| 39 |
+
timezone: string;
|
| 40 |
+
mapsPerLink: number;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
export interface RouteAssignee {
|
| 44 |
+
username: string;
|
| 45 |
+
name: string;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
export interface RouteAssigneeDirectory {
|
| 49 |
+
today: string;
|
| 50 |
+
people: RouteAssignee[];
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
export interface MapRouteDto {
|
| 54 |
+
id: string; name: string; color: string; number: number; visibleStopIds: number[];
|
| 55 |
+
outsideFilter: boolean;
|
| 56 |
+
permission: { canEdit: boolean; sourceViewId: string | null };
|
| 57 |
+
source: { viewId: string | null; revision: string | null };
|
| 58 |
+
/** Read-through of a saved route-order field. It remains visible without mutating on GET. */
|
| 59 |
+
compatibility?: "legacy-route-order";
|
| 60 |
+
mapsUrl?: string;
|
| 61 |
+
owner: string;
|
| 62 |
+
shared: boolean;
|
| 63 |
+
sharedOut: boolean;
|
| 64 |
+
hasShares: boolean;
|
| 65 |
+
sharedRole: "view" | "edit" | null;
|
| 66 |
+
/** Generic field bridge address consumed by the established Share dialog. */
|
| 67 |
+
shareId: string;
|
| 68 |
+
/** This reader's personal Route filing; it never changes the shared Route object. */
|
| 69 |
+
folderId: string | null;
|
| 70 |
+
navOrder: number;
|
| 71 |
+
assignee: string | null;
|
| 72 |
+
date: string | null;
|
| 73 |
+
/** D-599: the Zone this Route belongs to, or null. Always present on the wire; every Route
|
| 74 |
+
* saved before wave 46's hotfix legitimately has none, so null is data and not an error. */
|
| 75 |
+
zoneId: string | null;
|
| 76 |
+
starred?: boolean;
|
| 77 |
+
capabilities?: Partial<Record<"rename" | "duplicate" | "star" | "share" | "delete", boolean>>;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
export interface MapRouteFolderDto {
|
| 81 |
+
id: string;
|
| 82 |
+
name: string;
|
| 83 |
+
parent: string | null;
|
| 84 |
+
order: number;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
export type MapRouteUpdate = {
|
| 88 |
+
name?: string;
|
| 89 |
+
mapsUrl?: string;
|
| 90 |
+
starred?: boolean;
|
| 91 |
+
assignee?: string | null;
|
| 92 |
+
date?: string | null;
|
| 93 |
+
/** D-599. Absent inherits the stored Zone; an explicit null clears it. The server refuses an
|
| 94 |
+
* id no Zone on this database carries, with `unknown_zone`. */
|
| 95 |
+
zoneId?: string | null;
|
| 96 |
+
};
|
| 97 |
+
|
| 98 |
+
export interface RouteSelectionRequest { routeIds: string[]; viewState: Record<string, unknown>; }
|
| 99 |
+
|
| 100 |
+
export interface RouteSelectionResponse {
|
| 101 |
+
managedBy: "loopable";
|
| 102 |
+
viewState: Record<string, unknown>;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
/** The authored sources that can become a named Route.
|
| 106 |
+
* β W47-T06 (owner instruction 7) added `filtered`. The owner: *"The 'Create all X filtered
|
| 107 |
+
* records' we don't need this button under Routes navigation ... when we click Create route it
|
| 108 |
+
* should show 3 options instead of 2 now in the Route source section."* So the capability MOVED
|
| 109 |
+
* into the picker rather than being deleted; the standalone button is gone. */
|
| 110 |
+
export type MapRouteSource = {
|
| 111 |
+
id: "selection" | "zones" | "filtered";
|
| 112 |
+
label: string;
|
| 113 |
+
pids: number[];
|
| 114 |
+
};
|
| 115 |
+
|
| 116 |
+
/** A map may show one navigator at a time. The Routes rail wins when its host toggle is open. */
|
| 117 |
+
export function mapNavigatorMode(routeOpen: boolean, zoneOpen: boolean): "routes" | "zones" | null {
|
| 118 |
+
if (!routeOpen) return null;
|
| 119 |
+
return zoneOpen ? "zones" : "routes";
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
/** Toggle exactly one named Route while preserving the existing multi-selection. */
|
| 123 |
+
export function toggleRouteSelection(selected: ReadonlySet<string>, routeId: string): Set<string> {
|
| 124 |
+
const next = new Set(selected);
|
| 125 |
+
if (next.has(routeId)) next.delete(routeId);
|
| 126 |
+
else next.add(routeId);
|
| 127 |
+
return next;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
/** Route creation never submits duplicate, empty, or non-customer IDs from either source. */
|
| 131 |
+
export function routeSourceStopIds(pids: Iterable<number>): number[] {
|
| 132 |
+
return [...new Set([...pids].filter((pid) => Number.isSafeInteger(pid) && pid > 0))];
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
/** Only a bounded HTTPS Google Maps link may leave the in-app Route detail. */
|
| 136 |
+
export function boundedGoogleMapsUrl(value: string | undefined): string | null {
|
| 137 |
+
if (!value || value.length > 2_048) return null;
|
| 138 |
+
try {
|
| 139 |
+
const url = new URL(value);
|
| 140 |
+
return url.protocol === "https:" && /(^|\.)google\.[a-z.]+$/i.test(url.hostname) ? url.href : null;
|
| 141 |
+
} catch {
|
| 142 |
+
return null;
|
| 143 |
+
}
|
| 144 |
+
}
|
web/src/customer-grid/theme.ts
CHANGED
|
@@ -124,18 +124,39 @@ export const LP_BLUE_TEXT = "#4F6079";
|
|
| 124 |
so it is edge definition (15.42:1 on white) and the FILL is what carries the blue
|
| 125 |
semantic at every radius from R_MIN to R_MAX. Mirrored as `--lp-map-selected`. */
|
| 126 |
export const LP_MAP_SELECTED = "#1B4F9C";
|
| 127 |
-
/** β
|
| 128 |
-
* literal per DESIGN.md section 5. Owner: *"
|
| 129 |
-
*
|
| 130 |
-
*
|
| 131 |
-
*
|
| 132 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
* β MIRRORED as `--lp-zone-fill` in `styles/wave46/map-panels.css`, which is the CSS half of
|
| 134 |
-
* this one value. Change the two together or they drift
|
| 135 |
-
*
|
| 136 |
-
*
|
| 137 |
-
*
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
export const LP_YELLOW_DEEP = "#7E6428"; // 5.11:1 on its tint
|
| 140 |
export const LP_RED_DEEP = "#A3453C"; // 5.35:1 on its tint
|
| 141 |
export const LP_GREEN_DEEP = "#35754E"; // 4.98:1 on its tint
|
|
|
|
| 124 |
so it is edge definition (15.42:1 on white) and the FILL is what carries the blue
|
| 125 |
semantic at every radius from R_MIN to R_MAX. Mirrored as `--lp-map-selected`. */
|
| 126 |
export const LP_MAP_SELECTED = "#1B4F9C";
|
| 127 |
+
/** β W47-T01 (owner instruction 2) β HOW SOLID A MAP ZONE READS, as a token rather than a
|
| 128 |
+
* literal per DESIGN.md section 5. Owner: *"The zone color is still very hard to see, i am okay
|
| 129 |
+
* with like 10% opacity or something, we only need to see the dots on the records. No need to
|
| 130 |
+
* make the map visible. the zone needs to be more visible."*
|
| 131 |
+
* β THAT ASK IS TWO CHANGES, NOT ONE, AND IT ONLY LOOKS SELF-CONTRADICTORY. The 10 percent is
|
| 132 |
+
* the FILL, so the record dots read THROUGH a Zone; "more visible" is the Zone as an OBJECT,
|
| 133 |
+
* which at a near-transparent fill can only be carried by its BOUNDARY. W46-T28 had answered an
|
| 134 |
+
* earlier *"i can't se eshit"* by pushing this number 0.18 -> 0.4, which is the move this one
|
| 135 |
+
* reverses: a tint is the wrong instrument, because every `ZONE_COLOR_CHOICES` swatch is pastel
|
| 136 |
+
* and a pastel strong enough to outline a Zone is also strong enough to bury the pins under it.
|
| 137 |
* β MIRRORED as `--lp-zone-fill` in `styles/wave46/map-panels.css`, which is the CSS half of
|
| 138 |
+
* this one value. Change the two together or they drift (wave-47 contract C1). The
|
| 139 |
+
* `index.css :root` seam was NOT used, following the W46-T28 precedent recorded in
|
| 140 |
+
* `map-panels.css`: a lane declares the property beside the rule that reads it.
|
| 141 |
+
* β THIS IS NOT ONLY A MIRROR: it is READ at the keyboard-draft polygon in `MapView.tsx`
|
| 142 |
+
* (`fillOpacity={LP_ZONE_FILL_OPACITY}`), so editing it moves a painted surface too.
|
| 143 |
+
* β The fill is now deliberately near-invisible, and that is the design rather than a floor to
|
| 144 |
+
* be raised the next time a Zone reads faint. The legibility budget was moved to the stroke;
|
| 145 |
+
* anyone tempted to push this number back up is undoing instruction 2. */
|
| 146 |
+
export const LP_ZONE_FILL_OPACITY = 0.1;
|
| 147 |
+
/** β W47-T01 β THE OTHER HALF OF INSTRUCTION 2, AND THE HALF A FILL CHANGE ALONE LOSES.
|
| 148 |
+
* Dropping the fill to 0.1 makes a Zone read as almost nothing, so "the zone needs to be more
|
| 149 |
+
* visible" has to be paid at the boundary. This is the stroke weight passed to `hair()` at every
|
| 150 |
+
* Zone outline in `MapView.tsx`, raised from the literal 1.4 it used to carry.
|
| 151 |
+
* β IT IS A TS TOKEN, NOT A CSS `stroke-width`, AND THAT IS FORCED. Zone outlines render INSIDE
|
| 152 |
+
* `<g transform={tf}>`, so a CSS `stroke-width` would be in user units and would thicken as the
|
| 153 |
+
* camera zooms in; `hair()` exists precisely to divide by the zoom so a hairline stays a
|
| 154 |
+
* hairline. A CSS rule here would override the attribute (presentation attributes lose to author
|
| 155 |
+
* rules) and silently reintroduce the zoom-dependent stroke, which is the same trap W47-T03 hit
|
| 156 |
+
* with `stroke-dasharray`.
|
| 157 |
+
* β NO CSS MIRROR EXISTS ON PURPOSE: there is no second seam to drift against, because nothing
|
| 158 |
+
* outside `MapView.tsx` may set this. */
|
| 159 |
+
export const LP_ZONE_STROKE_WIDTH = 2.2;
|
| 160 |
export const LP_YELLOW_DEEP = "#7E6428"; // 5.11:1 on its tint
|
| 161 |
export const LP_RED_DEEP = "#A3453C"; // 5.35:1 on its tint
|
| 162 |
export const LP_GREEN_DEEP = "#35754E"; // 4.98:1 on its tint
|
web/src/customer-grid/viewModes.tsx
CHANGED
|
@@ -91,19 +91,51 @@ function IconDayCells() {
|
|
| 91 |
);
|
| 92 |
}
|
| 93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
function IconRouteZone() {
|
| 95 |
-
const s = {
|
| 96 |
-
stroke: "currentColor",
|
| 97 |
-
strokeWidth: 1.4,
|
| 98 |
-
strokeLinecap: "round" as const,
|
| 99 |
-
strokeLinejoin: "round" as const,
|
| 100 |
-
fill: "none",
|
| 101 |
-
};
|
| 102 |
return (
|
| 103 |
-
<svg
|
| 104 |
-
<path d="
|
| 105 |
-
<
|
| 106 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
</svg>
|
| 108 |
);
|
| 109 |
}
|
|
@@ -530,6 +562,9 @@ export function MapSettings({
|
|
| 530 |
<IconRouteZone />
|
| 531 |
<span>Routes and Zones{selectedCount >= 2 ? ` / ${selectedCount} selected` : ""}</span>
|
| 532 |
</button>
|
|
|
|
|
|
|
|
|
|
| 533 |
{coordChoices.length > 0 && (
|
| 534 |
<FieldSelectButton
|
| 535 |
className="cg-mode-field"
|
|
@@ -545,6 +580,9 @@ export function MapSettings({
|
|
| 545 |
]}
|
| 546 |
/>
|
| 547 |
)}
|
|
|
|
|
|
|
|
|
|
| 548 |
{sizeChoices.length > 0 && (
|
| 549 |
<FieldSelectButton
|
| 550 |
className="cg-mode-field"
|
|
|
|
| 91 |
);
|
| 92 |
}
|
| 93 |
|
| 94 |
+
/** β THE MAP SETTINGS ROW'S ICON VOCABULARY (owner instruction 5, ruling R10).
|
| 95 |
+
* Owner: *"The Routes/Zones / Location / No Size button needs to have icon. The routes/zones
|
| 96 |
+
* icon is really weird and uncanny, i need it changed."*
|
| 97 |
+
* β ONE DIALECT, NOT A SECOND ONE. These match `Toolbar.tsx`'s Filter / Sort / Group exactly:
|
| 98 |
+
* 14x14 rendered, `viewBox 0 0 16 16`, `fill: none`, `currentColor`, round cap and join, and
|
| 99 |
+
* stroke weight 1.5. The OLD `IconRouteZone` used 1.4 - a single off-spec weight in the whole
|
| 100 |
+
* row, which is part of why it read as foreign next to the toolbar above it. */
|
| 101 |
+
const mapIc = { width: 14, height: 14, viewBox: "0 0 16 16", fill: "none" } as const;
|
| 102 |
+
const mapStroke = {
|
| 103 |
+
stroke: "currentColor",
|
| 104 |
+
strokeWidth: 1.5,
|
| 105 |
+
strokeLinecap: "round" as const,
|
| 106 |
+
strokeLinejoin: "round" as const,
|
| 107 |
+
};
|
| 108 |
+
|
| 109 |
+
/** R10: a WAYPOINT PATH - two map pins joined by a curved line. It replaces a zigzag with dots on
|
| 110 |
+
* its ends, which read as a line chart rather than as a journey between two places. */
|
| 111 |
function IconRouteZone() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
return (
|
| 113 |
+
<svg {...mapIc} aria-hidden>
|
| 114 |
+
<path d="M4 2.4a2 2 0 0 1 2 2c0 1.5-2 3.7-2 3.7S2 5.9 2 4.4a2 2 0 0 1 2-2Z" {...mapStroke} />
|
| 115 |
+
<path d="M12 2.4a2 2 0 0 1 2 2c0 1.5-2 3.7-2 3.7s-2-2.2-2-3.7a2 2 0 0 1 2-2Z" {...mapStroke} />
|
| 116 |
+
<path d="M4.2 9.4c2.1 2.7 5.5 2.7 7.6 0" {...mapStroke} />
|
| 117 |
+
</svg>
|
| 118 |
+
);
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
/** R10: Location. A single map pin, the same pin the waypoint icon is built from, so the row
|
| 122 |
+
* reads as one family rather than three unrelated marks. */
|
| 123 |
+
function IconLocation() {
|
| 124 |
+
return (
|
| 125 |
+
<svg {...mapIc} aria-hidden>
|
| 126 |
+
<path d="M8 1.8a3.2 3.2 0 0 1 3.2 3.2c0 2.4-3.2 5.9-3.2 5.9S4.8 7.4 4.8 5A3.2 3.2 0 0 1 8 1.8Z" {...mapStroke} />
|
| 127 |
+
<circle cx="8" cy="5" r="1.15" {...mapStroke} />
|
| 128 |
+
</svg>
|
| 129 |
+
);
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
/** R10: Size. Two discs of different radius - the control sizes a pin BY a field, so the mark is
|
| 133 |
+
* the comparison itself. */
|
| 134 |
+
function IconSizeBy() {
|
| 135 |
+
return (
|
| 136 |
+
<svg {...mapIc} aria-hidden>
|
| 137 |
+
<circle cx="4.3" cy="8" r="1.6" {...mapStroke} />
|
| 138 |
+
<circle cx="11.2" cy="8" r="3.3" {...mapStroke} />
|
| 139 |
</svg>
|
| 140 |
);
|
| 141 |
}
|
|
|
|
| 562 |
<IconRouteZone />
|
| 563 |
<span>Routes and Zones{selectedCount >= 2 ? ` / ${selectedCount} selected` : ""}</span>
|
| 564 |
</button>
|
| 565 |
+
{coordChoices.length > 0 && (
|
| 566 |
+
<span className="cg-mode-field-mark" aria-hidden><IconLocation /></span>
|
| 567 |
+
)}
|
| 568 |
{coordChoices.length > 0 && (
|
| 569 |
<FieldSelectButton
|
| 570 |
className="cg-mode-field"
|
|
|
|
| 580 |
]}
|
| 581 |
/>
|
| 582 |
)}
|
| 583 |
+
{sizeChoices.length > 0 && (
|
| 584 |
+
<span className="cg-mode-field-mark" aria-hidden><IconSizeBy /></span>
|
| 585 |
+
)}
|
| 586 |
{sizeChoices.length > 0 && (
|
| 587 |
<FieldSelectButton
|
| 588 |
className="cg-mode-field"
|
web/src/filter-kit/FieldsHidePanel.tsx
CHANGED
|
@@ -341,6 +341,11 @@ export function brokenFieldReason(
|
|
| 341 |
* positioned BEFORE it mounts (there is nothing to measure yet), and a menu of at most two
|
| 342 |
* short items has a fixed size. They are a placement hint only; if they drift the menu lands a
|
| 343 |
* few pixels off, it never lands wrong.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 344 |
*/
|
| 345 |
const FIELD_MENU_WIDTH = 168;
|
| 346 |
const FIELD_MENU_HEIGHT = 76;
|
|
@@ -462,10 +467,14 @@ export function FieldsHidePanel({
|
|
| 462 |
* `FieldDeleteImpactDialog` with its exact-name typing; this menu only replaces the button
|
| 463 |
* that SET it. Folding a confirmation into a menu item would have traded a real guard for
|
| 464 |
* the appearance of one.
|
| 465 |
-
* β
|
| 466 |
-
*
|
| 467 |
-
*
|
| 468 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
| 469 |
*
|
| 470 |
* β KEY, POSITION AND TRIGGER, THREE PIECES. The key says which row is open; the position is
|
| 471 |
* VIEWPORT coordinates because `.cg-pop-list` is a 320px `overflow-y: auto` box and an
|
|
@@ -483,6 +492,10 @@ export function FieldsHidePanel({
|
|
| 483 |
const closeFieldMenu = (restoreFocus: boolean) => {
|
| 484 |
setMenuKey(null);
|
| 485 |
setMenuPos(null);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 486 |
const trigger = menuTriggerRef.current;
|
| 487 |
menuTriggerRef.current = null;
|
| 488 |
if (restoreFocus) trigger?.focus();
|
|
@@ -869,6 +882,24 @@ export function FieldsHidePanel({
|
|
| 869 |
// R6(c), as far as the payload allows. Counts and categories, and the
|
| 870 |
// helper's own closing clause is what keeps a tally from reading as a list.
|
| 871 |
const impactTitle = deleteImpactTitle(fc, usage);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 872 |
return (
|
| 873 |
<label
|
| 874 |
key={f.key}
|
|
@@ -1239,82 +1270,54 @@ export function FieldsHidePanel({
|
|
| 1239 |
</svg>
|
| 1240 |
</span>
|
| 1241 |
)}
|
| 1242 |
-
{/* ββ
|
| 1243 |
-
|
| 1244 |
-
|
| 1245 |
-
|
| 1246 |
-
|
| 1247 |
-
|
| 1248 |
-
|
| 1249 |
-
|
| 1250 |
-
|
| 1251 |
-
|
| 1252 |
-
|
| 1253 |
-
|
| 1254 |
-
|
| 1255 |
-
|
| 1256 |
-
|
| 1257 |
-
|
| 1258 |
-
|
| 1259 |
-
|
| 1260 |
-
? `${REMOVE_FIELD_LABEL}: ${rowLabel(f)}? ${REMOVE_FIELD_HINT}`
|
| 1261 |
-
: `${REMOVE_FIELD_LABEL}: ${rowLabel(f)}`
|
| 1262 |
-
}
|
| 1263 |
-
title={REMOVE_FIELD_HINT}
|
| 1264 |
-
onClick={(e) => {
|
| 1265 |
-
e.preventDefault();
|
| 1266 |
-
e.stopPropagation();
|
| 1267 |
-
if (!armed) {
|
| 1268 |
-
setConfirmKey(f.key);
|
| 1269 |
-
return;
|
| 1270 |
-
}
|
| 1271 |
-
setConfirmKey(null);
|
| 1272 |
-
// W41-T30 - `onRemoveField` is the FIRST term of the predicate that
|
| 1273 |
-
// gated this button (see `fieldRights`); hoisting that predicate out
|
| 1274 |
-
// of the row closure is what took the narrowing, not any new doubt.
|
| 1275 |
-
onRemoveField!(f.key);
|
| 1276 |
-
}}
|
| 1277 |
-
>
|
| 1278 |
-
{armed ? (
|
| 1279 |
-
`${REMOVE_FIELD_LABEL}?`
|
| 1280 |
-
) : (
|
| 1281 |
-
<svg width="14" height="14" viewBox="0 0 16 16" fill="none" aria-hidden>
|
| 1282 |
-
<circle cx="8" cy="8" r="5.7" stroke="currentColor" strokeWidth={1.3} />
|
| 1283 |
-
<path
|
| 1284 |
-
d="M5.5 8h5"
|
| 1285 |
-
stroke="currentColor"
|
| 1286 |
-
strokeWidth={1.3}
|
| 1287 |
-
strokeLinecap="round"
|
| 1288 |
-
/>
|
| 1289 |
-
</svg>
|
| 1290 |
-
)}
|
| 1291 |
-
</button>
|
| 1292 |
-
)}
|
| 1293 |
-
{/* ββ W46-T31 (owner instruction 21) β THE ONE TRAILING CONTROL. It renders when
|
| 1294 |
-
EITHER door is open to this viewer, so a delete-only mount (no `onEditField`)
|
| 1295 |
-
still has a way in and an edit-only row does not grow a second affordance.
|
| 1296 |
β Inside a <label>: every click here preventDefaults, or activating the label
|
| 1297 |
toggles the very column you came to edit. Same reason the old trash did.
|
| 1298 |
β The rect handed to `onEditField` is re-measured off the LIVE trigger at click
|
| 1299 |
time, never the one captured when the menu opened: the list can scroll between
|
| 1300 |
the two, and an editor anchored on a stale rect opens over the wrong row. */}
|
| 1301 |
-
{(onEditField || deletable) && (
|
| 1302 |
<span className={"w46-field-actions" + (menuKey === f.key ? " is-open" : "")}>
|
| 1303 |
<button
|
| 1304 |
type="button"
|
| 1305 |
className="cg-field-edit-trigger w46-field-actions-trigger"
|
| 1306 |
-
|
| 1307 |
-
|
| 1308 |
-
|
| 1309 |
-
|
|
|
|
|
|
|
|
|
|
| 1310 |
onClick={(event) => {
|
| 1311 |
event.preventDefault();
|
| 1312 |
event.stopPropagation();
|
| 1313 |
/* ββ W46-T31 β ONE AVAILABLE ACTION IS PERFORMED, NOT LISTED. A menu of a
|
| 1314 |
-
single item is a click the person did not need: when
|
| 1315 |
-
|
| 1316 |
-
once. The menu exists to put
|
| 1317 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1318 |
β THIS IS ALSO THE LIVE PATH `verify_grid_ux.py:4032` PINS. That check
|
| 1319 |
greps for the edit call made with the trigger's own measured rect, and the
|
| 1320 |
needle is a real path here rather than a decoy: `currentTarget` is THIS
|
|
@@ -1327,7 +1330,7 @@ export function FieldsHidePanel({
|
|
| 1327 |
The two-door path below anchors on the same element through
|
| 1328 |
`menuTriggerRef`, re-measured at click time because the list can scroll
|
| 1329 |
while the menu is open. */
|
| 1330 |
-
if (!
|
| 1331 |
if (onEditField) onEditField(f.key, event.currentTarget.getBoundingClientRect());
|
| 1332 |
return;
|
| 1333 |
}
|
|
@@ -1403,6 +1406,45 @@ export function FieldsHidePanel({
|
|
| 1403 |
Delete field
|
| 1404 |
</button>
|
| 1405 |
)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1406 |
</div>
|
| 1407 |
)}
|
| 1408 |
</span>
|
|
|
|
| 341 |
* positioned BEFORE it mounts (there is nothing to measure yet), and a menu of at most two
|
| 342 |
* short items has a fixed size. They are a placement hint only; if they drift the menu lands a
|
| 343 |
* few pixels off, it never lands wrong.
|
| 344 |
+
* β W47-T14 (R12) ADDED A THIRD ITEM AND NOT A THIRD ROW. Remove from my fields joined this
|
| 345 |
+
* menu, but `fieldRights` hands Delete and Remove to disjoint viewers (`deletable` requires
|
| 346 |
+
* `!canRemove`, `removable` requires `canRemove`), so "at most two short items" still holds and
|
| 347 |
+
* 76 still budgets the tallest menu this can produce. Derive it from the item count only if that
|
| 348 |
+
* ever stops being true.
|
| 349 |
*/
|
| 350 |
const FIELD_MENU_WIDTH = 168;
|
| 351 |
const FIELD_MENU_HEIGHT = 76;
|
|
|
|
| 467 |
* `FieldDeleteImpactDialog` with its exact-name typing; this menu only replaces the button
|
| 468 |
* that SET it. Folding a confirmation into a menu item would have traded a real guard for
|
| 469 |
* the appearance of one.
|
| 470 |
+
* β REMOVE-FROM-MY-FIELDS IS AN ITEM OF THIS MENU (W47-T14, R12, owner instruction 16).
|
| 471 |
+
* It had a button of its own, `cg-check-del--remove`, until R12 reversed that half of R6(b) on
|
| 472 |
+
* the owner's word; the ACT is unchanged and still `onRemoveField`, never a gentler Delete, and
|
| 473 |
+
* it brought R6(c)'s two-click arm onto the item rather than trading it for a menu that fires
|
| 474 |
+
* at once. `closeFieldMenu` disarms, so the arm cannot outlive the menu it lives in.
|
| 475 |
+
* β THE MENU STILL HOLDS AT MOST TWO ITEMS. Delete and Remove are never offered to the same
|
| 476 |
+
* viewer on the same field (`fieldRights`: `deletable` requires `!canRemove`, `removable`
|
| 477 |
+
* requires `canRemove`), which is why `FIELD_MENU_HEIGHT`'s two-item budget still fits.
|
| 478 |
*
|
| 479 |
* β KEY, POSITION AND TRIGGER, THREE PIECES. The key says which row is open; the position is
|
| 480 |
* VIEWPORT coordinates because `.cg-pop-list` is a 320px `overflow-y: auto` box and an
|
|
|
|
| 492 |
const closeFieldMenu = (restoreFocus: boolean) => {
|
| 493 |
setMenuKey(null);
|
| 494 |
setMenuPos(null);
|
| 495 |
+
// W47-T14 (R12) - the Remove item's two-click arm lives on this menu now, so closing it
|
| 496 |
+
// DISARMS. An arm that survived a closed menu would fire on a click the person reads as
|
| 497 |
+
// their first one, which is the guard inverted rather than kept.
|
| 498 |
+
setConfirmKey(null);
|
| 499 |
const trigger = menuTriggerRef.current;
|
| 500 |
menuTriggerRef.current = null;
|
| 501 |
if (restoreFocus) trigger?.focus();
|
|
|
|
| 882 |
// R6(c), as far as the payload allows. Counts and categories, and the
|
| 883 |
// helper's own closing clause is what keeps a tally from reading as a list.
|
| 884 |
const impactTitle = deleteImpactTitle(fc, usage);
|
| 885 |
+
/**
|
| 886 |
+
* ββ W47-T14 (R12, owner instruction 16) - HOW MANY DOORS THIS ROW HAS, COUNTED
|
| 887 |
+
* rather than inferred from one of them. R12 folded Remove from my fields into the
|
| 888 |
+
* trailing trigger, so `deletable` stopped being the same question as "is there more
|
| 889 |
+
* than one thing to offer here": a removable field has `deletable === false` and still
|
| 890 |
+
* needs the menu.
|
| 891 |
+
* β `menuDoors` NEVER REACHES 3. `fieldRights` makes `deletable` require `!canRemove`
|
| 892 |
+
* and `removable` require `canRemove`, so Delete and Remove are mutually exclusive for
|
| 893 |
+
* one viewer on one field and the tallest menu is still two items.
|
| 894 |
+
* β `opensMenu` IS NOT `deletable || removable` SPELLED LONGER, though it is equal to
|
| 895 |
+
* it today. The question it asks is "can the trigger just DO the single door", and only
|
| 896 |
+
* Edit can: Delete and Remove each carry a second-click guard that lives inside the
|
| 897 |
+
* menu, so a lone one of them still opens it - which is exactly how a delete-only mount
|
| 898 |
+
* already behaves. Simplifying this to `deletable` is the regression R12 introduces the
|
| 899 |
+
* opportunity for.
|
| 900 |
+
*/
|
| 901 |
+
const menuDoors = (onEditField ? 1 : 0) + (deletable ? 1 : 0) + (removable ? 1 : 0);
|
| 902 |
+
const opensMenu = menuDoors > 1 || (menuDoors === 1 && !onEditField);
|
| 903 |
return (
|
| 904 |
<label
|
| 905 |
key={f.key}
|
|
|
|
| 1270 |
</svg>
|
| 1271 |
</span>
|
| 1272 |
)}
|
| 1273 |
+
{/* ββ W47-T14 (R12, owner instruction 16) - REMOVE FROM MY FIELDS NO LONGER HAS A
|
| 1274 |
+
BUTTON OF ITS OWN. It is an item of the field-actions menu below. Owner: *"the
|
| 1275 |
+
remove from my fields under Hide Fields module should just be moved to the edit
|
| 1276 |
+
button under the Hide Fields module."* R12 REVERSES the R6(b) SEPARATION that
|
| 1277 |
+
W41-T29 recorded here, and this paragraph replaces that one rather than being
|
| 1278 |
+
left to contradict the code, which is how the next reader "fixes" it back.
|
| 1279 |
+
β WHAT R12 DID NOT REVERSE, and what a restoration would have to keep anyway:
|
| 1280 |
+
the act is still its own handler, `onRemoveField`, never `onDeleteField` wearing
|
| 1281 |
+
a gentler word; it still declines the destructive treatment, because dropping a
|
| 1282 |
+
share destroys nothing; it still carries R6(c)'s two-click arm; and the REFUSAL
|
| 1283 |
+
half of R6(b) is untouched, enforced by `fieldRights` before any of this renders.
|
| 1284 |
+
β `.cg-check-del--remove` in `styles/wave46/field-panels.css` has no element
|
| 1285 |
+
left. It is out of this ticket's fence, so it is reported rather than deleted. */}
|
| 1286 |
+
{/* ββ W46-T31 (owner instruction 21), widened by W47-T14 (R12) - THE ONE TRAILING
|
| 1287 |
+
CONTROL, and now the row's only trailing control at all. It renders when ANY of
|
| 1288 |
+
the three doors is open to this viewer (edit, delete, remove), so a delete-only
|
| 1289 |
+
mount (no `onEditField`) still has a way in and an edit-only row does not grow a
|
| 1290 |
+
second affordance.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1291 |
β Inside a <label>: every click here preventDefaults, or activating the label
|
| 1292 |
toggles the very column you came to edit. Same reason the old trash did.
|
| 1293 |
β The rect handed to `onEditField` is re-measured off the LIVE trigger at click
|
| 1294 |
time, never the one captured when the menu opened: the list can scroll between
|
| 1295 |
the two, and an editor anchored on a stale rect opens over the wrong row. */}
|
| 1296 |
+
{(onEditField || deletable || removable) && (
|
| 1297 |
<span className={"w46-field-actions" + (menuKey === f.key ? " is-open" : "")}>
|
| 1298 |
<button
|
| 1299 |
type="button"
|
| 1300 |
className="cg-field-edit-trigger w46-field-actions-trigger"
|
| 1301 |
+
// W47-T14 (R12) - keyed on whether a MENU OPENS, not on `deletable`. A
|
| 1302 |
+
// removable-only row opens a menu too, and announcing it as "Edit field"
|
| 1303 |
+
// would name the wrong act and promise no popup to a screen reader.
|
| 1304 |
+
aria-label={opensMenu ? `Field actions ${rowLabel(f)}` : `Edit field ${rowLabel(f)}`}
|
| 1305 |
+
aria-haspopup={opensMenu ? "true" : undefined}
|
| 1306 |
+
aria-expanded={opensMenu ? menuKey === f.key : undefined}
|
| 1307 |
+
title={opensMenu ? "Field actions" : "Edit field"}
|
| 1308 |
onClick={(event) => {
|
| 1309 |
event.preventDefault();
|
| 1310 |
event.stopPropagation();
|
| 1311 |
/* ββ W46-T31 β ONE AVAILABLE ACTION IS PERFORMED, NOT LISTED. A menu of a
|
| 1312 |
+
single item is a click the person did not need: when Edit is this
|
| 1313 |
+
viewer's ONLY door, the trigger IS the Edit button and opens the editor
|
| 1314 |
+
at once. The menu exists to put a GUARDED door behind a deliberate second
|
| 1315 |
+
click, so it earns its place whenever one of those is present.
|
| 1316 |
+
β W47-T14 (R12) - THE TEST IS `opensMenu`, NOT `!deletable`. Remove from
|
| 1317 |
+
my fields is a menu item now and a removable field has `deletable ===
|
| 1318 |
+
false`, so the old test would have sent that viewer straight into the
|
| 1319 |
+
editor with the remove act unreachable. `menuDoors` above says why the
|
| 1320 |
+
two questions stopped being the same one.
|
| 1321 |
β THIS IS ALSO THE LIVE PATH `verify_grid_ux.py:4032` PINS. That check
|
| 1322 |
greps for the edit call made with the trigger's own measured rect, and the
|
| 1323 |
needle is a real path here rather than a decoy: `currentTarget` is THIS
|
|
|
|
| 1330 |
The two-door path below anchors on the same element through
|
| 1331 |
`menuTriggerRef`, re-measured at click time because the list can scroll
|
| 1332 |
while the menu is open. */
|
| 1333 |
+
if (!opensMenu) {
|
| 1334 |
if (onEditField) onEditField(f.key, event.currentTarget.getBoundingClientRect());
|
| 1335 |
return;
|
| 1336 |
}
|
|
|
|
| 1406 |
Delete field
|
| 1407 |
</button>
|
| 1408 |
)}
|
| 1409 |
+
{/* ββ W47-T14 (R12, owner instruction 16) - REMOVE FROM MY FIELDS, THE
|
| 1410 |
+
THIRD ITEM AND DELIBERATELY NOT A THIRD VARIANT. No `--danger`: dropping
|
| 1411 |
+
a column somebody else shared destroys nothing, and pointing a benign
|
| 1412 |
+
word at a destructive treatment is worse than the control not existing
|
| 1413 |
+
(DESIGN Β§3, and W41-T29's button said the same before this replaced it).
|
| 1414 |
+
β R6(c)'S TWO-CLICK ARM CAME WITH IT. The first click ARMS and leaves the
|
| 1415 |
+
menu open; the second removes. An item that fired at once would have
|
| 1416 |
+
traded a real guard for the appearance of one, which is the mistake the
|
| 1417 |
+
Delete item's typed confirmation exists to avoid.
|
| 1418 |
+
β THE WORDS ARE THE SHARED CONSTANTS, not a retype: `REMOVE_FIELD_LABEL`
|
| 1419 |
+
and `REMOVE_FIELD_HINT` are what keep this menu and both ColumnMenu
|
| 1420 |
+
mounts saying the same four words for the same act. */}
|
| 1421 |
+
{removable && (
|
| 1422 |
+
<button
|
| 1423 |
+
type="button"
|
| 1424 |
+
className="w46-field-menu-item"
|
| 1425 |
+
aria-label={
|
| 1426 |
+
armed
|
| 1427 |
+
? `${REMOVE_FIELD_LABEL}: ${rowLabel(f)}? ${REMOVE_FIELD_HINT}`
|
| 1428 |
+
: `${REMOVE_FIELD_LABEL}: ${rowLabel(f)}`
|
| 1429 |
+
}
|
| 1430 |
+
title={REMOVE_FIELD_HINT}
|
| 1431 |
+
onClick={(e) => {
|
| 1432 |
+
e.preventDefault();
|
| 1433 |
+
e.stopPropagation();
|
| 1434 |
+
if (!armed) {
|
| 1435 |
+
setConfirmKey(f.key);
|
| 1436 |
+
return;
|
| 1437 |
+
}
|
| 1438 |
+
// W41-T30 - `onRemoveField` is the FIRST term of the predicate that
|
| 1439 |
+
// gated this item (see `fieldRights`); that hoist is what took the
|
| 1440 |
+
// narrowing, and no new doubt is expressed by the assertion.
|
| 1441 |
+
closeFieldMenu(true);
|
| 1442 |
+
onRemoveField!(f.key);
|
| 1443 |
+
}}
|
| 1444 |
+
>
|
| 1445 |
+
{armed ? `${REMOVE_FIELD_LABEL}?` : REMOVE_FIELD_LABEL}
|
| 1446 |
+
</button>
|
| 1447 |
+
)}
|
| 1448 |
</div>
|
| 1449 |
)}
|
| 1450 |
</span>
|
web/src/filter-kit/FilterBuilderPanel.tsx
CHANGED
|
@@ -37,6 +37,10 @@ import type { AnchorMode } from "../customer-grid/windows";
|
|
| 37 |
import { ANCHOR_LABELS, ANCHOR_MODES, MAX_N } from "../customer-grid/windows";
|
| 38 |
import { FieldSelectButton } from "../customer-grid/FieldSelect";
|
| 39 |
import type { FieldSelectItem } from "../customer-grid/FieldSelect";
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
// β W40-T18 β the deleted-column vocabulary. Same direction `filter-kit/FieldsHidePanel.tsx`
|
| 41 |
// already imports `metricLabel` / `presetHideFields` from: `settings/permsModel` is a PURE model
|
| 42 |
// module with no runtime import of its own, it is already in the grid bundle because that panel
|
|
@@ -890,13 +894,18 @@ function LeafRow({
|
|
| 890 |
onValue2={(v) => patch({ value2: v })}
|
| 891 |
/>
|
| 892 |
)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 893 |
<button
|
| 894 |
type="button"
|
| 895 |
className="cg-cond-x"
|
| 896 |
aria-label="Remove condition"
|
| 897 |
onClick={onRemove}
|
| 898 |
>
|
| 899 |
-
|
| 900 |
</button>
|
| 901 |
</span>
|
| 902 |
);
|
|
@@ -924,13 +933,14 @@ function GroupNode({
|
|
| 924 |
? groupSummary(group.conj)
|
| 925 |
: "Add a condition to this groupβ¦"}
|
| 926 |
</span>
|
|
|
|
| 927 |
<button
|
| 928 |
type="button"
|
| 929 |
className="cg-cond-x"
|
| 930 |
aria-label="Remove condition group"
|
| 931 |
onClick={onRemove}
|
| 932 |
>
|
| 933 |
-
|
| 934 |
</button>
|
| 935 |
</span>
|
| 936 |
<span className="cg-cond-group-body">
|
|
@@ -1008,18 +1018,14 @@ export interface FilterBuilderPanelProps {
|
|
| 1008 |
* serves an admin editor should know about.
|
| 1009 |
*/
|
| 1010 |
footerExtra?: ReactNode;
|
| 1011 |
-
/*
|
| 1012 |
-
*
|
| 1013 |
-
*
|
| 1014 |
-
*
|
| 1015 |
-
*
|
| 1016 |
-
*
|
| 1017 |
-
*
|
| 1018 |
-
* ancestor at all, and already owns a different way out β its own "Hide detail" disclosure.
|
| 1019 |
-
* Requiring this prop would force that surface to invent a second, competing closer. So the
|
| 1020 |
-
* control paints only where a closer genuinely exists, and its absence is a statement.
|
| 1021 |
*/
|
| 1022 |
-
onClose?: () => void;
|
| 1023 |
}
|
| 1024 |
|
| 1025 |
export function FilterBuilderPanel({
|
|
@@ -1033,7 +1039,6 @@ export function FilterBuilderPanel({
|
|
| 1033 |
statusValues,
|
| 1034 |
cohortLock,
|
| 1035 |
footerExtra,
|
| 1036 |
-
onClose,
|
| 1037 |
}: FilterBuilderPanelProps) {
|
| 1038 |
const nodes = filterTreeNodes(filters);
|
| 1039 |
const conj = filterTreeConj(filters);
|
|
@@ -1070,25 +1075,17 @@ export function FilterBuilderPanel({
|
|
| 1070 |
|
| 1071 |
return (
|
| 1072 |
<div className="cg-pop-body cg-builder">
|
| 1073 |
-
{/*
|
| 1074 |
-
|
| 1075 |
-
|
| 1076 |
-
|
| 1077 |
-
|
|
|
|
|
|
|
| 1078 |
The row deliberately does not wear the column menu's head rule; see `.cg-pop-head` in
|
| 1079 |
index.css for what borrowing that one would have done to this header. */}
|
| 1080 |
<div className="cg-pop-head">
|
| 1081 |
<div className="cg-pop-title">Filter</div>
|
| 1082 |
-
{onClose && (
|
| 1083 |
-
<button
|
| 1084 |
-
type="button"
|
| 1085 |
-
className="cg-icon-btn"
|
| 1086 |
-
onClick={onClose}
|
| 1087 |
-
aria-label="Close filter panel"
|
| 1088 |
-
>
|
| 1089 |
-
Γ
|
| 1090 |
-
</button>
|
| 1091 |
-
)}
|
| 1092 |
</div>
|
| 1093 |
{/* C-LOCK (item 12) β the lock is NOT a condition row: it cannot be written here and
|
| 1094 |
cannot be removed here (the view menu owns it). So it has to be SAID here, above
|
|
|
|
| 37 |
import { ANCHOR_LABELS, ANCHOR_MODES, MAX_N } from "../customer-grid/windows";
|
| 38 |
import { FieldSelectButton } from "../customer-grid/FieldSelect";
|
| 39 |
import type { FieldSelectItem } from "../customer-grid/FieldSelect";
|
| 40 |
+
// W47-T13 (owner instruction 15) β the remove-a-condition mark, taken from the ONE icon
|
| 41 |
+
// vocabulary rather than hand-drawn a second time. `filter-kit/FieldsHidePanel.tsx` already
|
| 42 |
+
// imports across this same boundary for `FieldTypeIcon`, so the direction is established.
|
| 43 |
+
import { MenuIcon } from "../customer-grid/icons";
|
| 44 |
// β W40-T18 β the deleted-column vocabulary. Same direction `filter-kit/FieldsHidePanel.tsx`
|
| 45 |
// already imports `metricLabel` / `presetHideFields` from: `settings/permsModel` is a PURE model
|
| 46 |
// module with no runtime import of its own, it is already in the grid bundle because that panel
|
|
|
|
| 894 |
onValue2={(v) => patch({ value2: v })}
|
| 895 |
/>
|
| 896 |
)}
|
| 897 |
+
{/* W47-T13 (owner instruction 15) β A TRASH MARK, NOT AN Γ. The glyph was ambiguous
|
| 898 |
+
against the panel's own closer; now the mark itself says "this destroys the row".
|
| 899 |
+
`.cg-cond-x` already hovers to `--lp-red-deep`, which is DESIGN.md Β§3's destructive
|
| 900 |
+
colour, so the 16px `currentColor` SVG needs no style of its own. The button keeps
|
| 901 |
+
its `aria-label`; the SVG is `aria-hidden` inside `MenuIcon`. */}
|
| 902 |
<button
|
| 903 |
type="button"
|
| 904 |
className="cg-cond-x"
|
| 905 |
aria-label="Remove condition"
|
| 906 |
onClick={onRemove}
|
| 907 |
>
|
| 908 |
+
<MenuIcon name="trash" />
|
| 909 |
</button>
|
| 910 |
</span>
|
| 911 |
);
|
|
|
|
| 933 |
? groupSummary(group.conj)
|
| 934 |
: "Add a condition to this groupβ¦"}
|
| 935 |
</span>
|
| 936 |
+
{/* Same control family as the row above, so the same mark: W47-T13. */}
|
| 937 |
<button
|
| 938 |
type="button"
|
| 939 |
className="cg-cond-x"
|
| 940 |
aria-label="Remove condition group"
|
| 941 |
onClick={onRemove}
|
| 942 |
>
|
| 943 |
+
<MenuIcon name="trash" />
|
| 944 |
</button>
|
| 945 |
</span>
|
| 946 |
<span className="cg-cond-group-body">
|
|
|
|
| 1018 |
* serves an admin editor should know about.
|
| 1019 |
*/
|
| 1020 |
footerExtra?: ReactNode;
|
| 1021 |
+
/*
|
| 1022 |
+
* β W47-T13 (owner instruction 15) DELETED `onClose` FROM THIS TYPE, and the deletion is the
|
| 1023 |
+
* point. W38-T02 had added a header close button behind an optional `onClose`; the owner has
|
| 1024 |
+
* since ruled that control redundant, because the panel is mounted inside an overlay that
|
| 1025 |
+
* already dismisses on an outside pointerdown. A prop kept "just in case" is how the button
|
| 1026 |
+
* comes back, so the prop went with it. If a future mount genuinely needs a closer of its own,
|
| 1027 |
+
* that mount owns it β this panel does not paint one.
|
|
|
|
|
|
|
|
|
|
| 1028 |
*/
|
|
|
|
| 1029 |
}
|
| 1030 |
|
| 1031 |
export function FilterBuilderPanel({
|
|
|
|
| 1039 |
statusValues,
|
| 1040 |
cohortLock,
|
| 1041 |
footerExtra,
|
|
|
|
| 1042 |
}: FilterBuilderPanelProps) {
|
| 1043 |
const nodes = filterTreeNodes(filters);
|
| 1044 |
const conj = filterTreeConj(filters);
|
|
|
|
| 1075 |
|
| 1076 |
return (
|
| 1077 |
<div className="cg-pop-body cg-builder">
|
| 1078 |
+
{/* β W47-T13 (owner instruction 15) β A TITLE ROW WITH NO CLOSER. It names the panel and
|
| 1079 |
+
nothing else: the only buttons inside this builder are the trash marks on the condition
|
| 1080 |
+
rows below, which DESTROY a row, so there is no longer a second meaning of a control up
|
| 1081 |
+
here to disambiguate. The way out is to click anywhere outside, which
|
| 1082 |
+
`OverlaySurface.tsx::AnchoredOverlay` has always provided on outside pointerdown
|
| 1083 |
+
regardless of what this header painted; Escape still works too. W38-T02's header Γ was
|
| 1084 |
+
the redundant third door and is deleted, prop and all.
|
| 1085 |
The row deliberately does not wear the column menu's head rule; see `.cg-pop-head` in
|
| 1086 |
index.css for what borrowing that one would have done to this header. */}
|
| 1087 |
<div className="cg-pop-head">
|
| 1088 |
<div className="cg-pop-title">Filter</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1089 |
</div>
|
| 1090 |
{/* C-LOCK (item 12) β the lock is NOT a condition row: it cannot be written here and
|
| 1091 |
cannot be removed here (the view menu owns it). So it has to be SAID here, above
|
web/src/manage-agent/ManageAgentPane.tsx
CHANGED
|
@@ -8,6 +8,12 @@
|
|
| 8 |
// configure this under a module called "Manage agent" which should be under
|
| 9 |
// "Manage user"."*
|
| 10 |
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
// β "EXACTLY LIKE" IS IMPLEMENTED, NOT IMITATED. The per-database list, its
|
| 12 |
// collapsed disclosure and its summary line are `settings/ModulePermsList` β the
|
| 13 |
// SAME component `PermsEditor` renders, not a copy of it. The permission payload
|
|
@@ -276,7 +282,7 @@ export function ManageAgentPane() {
|
|
| 276 |
// --- the list -------------------------------------------------------------
|
| 277 |
return (
|
| 278 |
<div className="set-pane">
|
| 279 |
-
<h3 className="set-h">Manage
|
| 280 |
<p className="set-perm-intro">
|
| 281 |
A bot per Slack channel, with the same per-database rules you set for a person.
|
| 282 |
The rules are enforced by the same engine, because a channel is simply another
|
|
|
|
| 8 |
// configure this under a module called "Manage agent" which should be under
|
| 9 |
// "Manage user"."*
|
| 10 |
//
|
| 11 |
+
// β WAVE 47, owner instruction 6 β the RENDERED LABEL is now "Manage slack",
|
| 12 |
+
// verbatim: *"Let's change the naming of Manage agent under setting to Manage
|
| 13 |
+
// slack"*. The wave-33 quotation above is the owner's original and stays as
|
| 14 |
+
// written. The file name, the component name and the tab id `agents` are all
|
| 15 |
+
// unchanged; only the two rendered strings moved.
|
| 16 |
+
//
|
| 17 |
// β "EXACTLY LIKE" IS IMPLEMENTED, NOT IMITATED. The per-database list, its
|
| 18 |
// collapsed disclosure and its summary line are `settings/ModulePermsList` β the
|
| 19 |
// SAME component `PermsEditor` renders, not a copy of it. The permission payload
|
|
|
|
| 282 |
// --- the list -------------------------------------------------------------
|
| 283 |
return (
|
| 284 |
<div className="set-pane">
|
| 285 |
+
<h3 className="set-h">Manage slack</h3>
|
| 286 |
<p className="set-perm-intro">
|
| 287 |
A bot per Slack channel, with the same per-database rules you set for a person.
|
| 288 |
The rules are enforced by the same engine, because a channel is simply another
|
web/src/settings/ManageDatabase.tsx
CHANGED
|
@@ -150,6 +150,89 @@ export function parseOverlay(body: unknown): ParsedOverlay {
|
|
| 150 |
return { fields, dropped };
|
| 151 |
}
|
| 152 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
/** One database's PATCH body: `{ "<field_key>": {hidden, label, order} }`. */
|
| 154 |
type FieldPatch = { hidden?: boolean; label?: string | null; order?: number | null };
|
| 155 |
|
|
@@ -193,6 +276,51 @@ async function callOverlay<T>(init?: RequestInit & { body?: string }): Promise<R
|
|
| 193 |
}
|
| 194 |
}
|
| 195 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
// ββ the pane ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 197 |
|
| 198 |
/** Sort by the overlay's order where it has one, then by label, so a database
|
|
@@ -221,6 +349,16 @@ export function ManageDatabasePane() {
|
|
| 221 |
const [open, setOpen] = useState<string | null>(null);
|
| 222 |
/** The unsaved relabel and reorder for the open database, keyed by field. */
|
| 223 |
const [draft, setDraft] = useState<Record<string, FieldPatch>>({});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
|
| 225 |
const load = useCallback(() => {
|
| 226 |
void callOverlay<unknown>().then((r) => {
|
|
@@ -239,6 +377,44 @@ export function ManageDatabasePane() {
|
|
| 239 |
|
| 240 |
useEffect(load, [load]);
|
| 241 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
const databases = useMemo(() => {
|
| 243 |
const byKey = new Map<string, { key: string; label: string; rows: OverlayField[] }>();
|
| 244 |
for (const f of parsed?.fields ?? []) {
|
|
@@ -253,28 +429,64 @@ export function ManageDatabasePane() {
|
|
| 253 |
return [...byKey.values()].sort((a, b) => a.label.localeCompare(b.label));
|
| 254 |
}, [parsed]);
|
| 255 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
const save = useCallback(
|
| 257 |
(database: string) => {
|
| 258 |
const patch = draft;
|
| 259 |
-
|
|
|
|
|
|
|
| 260 |
setSaving(true);
|
| 261 |
-
void
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
|
|
|
|
|
|
| 274 |
}
|
| 275 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
},
|
| 277 |
-
[draft],
|
| 278 |
);
|
| 279 |
|
| 280 |
if (parsed === null && !error)
|
|
@@ -329,7 +541,10 @@ export function ManageDatabasePane() {
|
|
| 329 |
setNotice("");
|
| 330 |
};
|
| 331 |
|
| 332 |
-
|
|
|
|
|
|
|
|
|
|
| 333 |
|
| 334 |
return (
|
| 335 |
<div className="set-pane">
|
|
@@ -355,6 +570,12 @@ export function ManageDatabasePane() {
|
|
| 355 |
|
| 356 |
{error ? <p className="set-error">{error}</p> : null}
|
| 357 |
{notice ? <p className="set-notice">{notice}</p> : null}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 358 |
|
| 359 |
<ul className="w46-db-fields">
|
| 360 |
{rows.map((f, i) => (
|
|
@@ -372,20 +593,62 @@ export function ManageDatabasePane() {
|
|
| 372 |
Always shown
|
| 373 |
</span>
|
| 374 |
) : null}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 375 |
</div>
|
| 376 |
-
<label className="w46-db-relabel">
|
| 377 |
-
<span className="set-label">Label</span>
|
| 378 |
-
<input
|
| 379 |
-
className="set-input"
|
| 380 |
-
type="text"
|
| 381 |
-
value={f.label}
|
| 382 |
-
onChange={(e) => {
|
| 383 |
-
const value = e.currentTarget.value;
|
| 384 |
-
setDraft((d) => ({ ...d, [f.field]: { ...d[f.field], label: value } }));
|
| 385 |
-
setNotice("");
|
| 386 |
-
}}
|
| 387 |
-
/>
|
| 388 |
-
</label>
|
| 389 |
<div className="w46-db-acts">
|
| 390 |
<label className="set-check">
|
| 391 |
<input
|
|
@@ -438,6 +701,7 @@ export function ManageDatabasePane() {
|
|
| 438 |
disabled={!dirty || saving}
|
| 439 |
onClick={() => {
|
| 440 |
setDraft({});
|
|
|
|
| 441 |
setNotice("");
|
| 442 |
}}
|
| 443 |
>
|
|
|
|
| 150 |
return { fields, dropped };
|
| 151 |
}
|
| 152 |
|
| 153 |
+
// ββ the SEMANTIC wire (owner instruction 8) βββββββββββββββββββββββββββββββββ
|
| 154 |
+
//
|
| 155 |
+
// ββ A SECOND DESCRIPTION STORE IS THE ONE THING THIS MUST NOT BUILD, and it is
|
| 156 |
+
// the obvious way to write it. The schema overlay above owns `label`, `hidden`
|
| 157 |
+
// and `order` and nothing else. The description and the governance state are the
|
| 158 |
+
// SEMANTIC REGISTRY's `purpose` and `state`, which already exist, are already
|
| 159 |
+
// admin-gated and are already persisted:
|
| 160 |
+
//
|
| 161 |
+
// GET /api/v1/query/semantics/{database} -> {database, fields:[...], router}
|
| 162 |
+
// PATCH /api/v1/query/semantics/{database}/{field} <- {purpose}
|
| 163 |
+
//
|
| 164 |
+
// Both halves shipped in an earlier wave and NOBODY EVER CONNECTED THEM to this
|
| 165 |
+
// pane, which is the whole of instruction 8 ("I don't see the semantic .md file
|
| 166 |
+
// or description per field under manage database"). So this reads and writes
|
| 167 |
+
// THOSE routes, and adds no key to the overlay document and none to `patch_field`.
|
| 168 |
+
//
|
| 169 |
+
// β THE MARKDOWN IS A GENERATED PROJECTION (`semantic_registry.generated_markdown`)
|
| 170 |
+
// and is never hand-edited, so no markdown editor is offered here. What an admin
|
| 171 |
+
// edits is `purpose`; the .md the instruction names is that value, rendered.
|
| 172 |
+
//
|
| 173 |
+
// β TWO STORES, TWO PERMISSION WALLS, AND THEY ARE NOT THE SAME WALL. The overlay
|
| 174 |
+
// sits behind the admin gate; the semantic routes sit behind Query's own source
|
| 175 |
+
// boundary plus `is_admin` inside the registry. A database with no semantic
|
| 176 |
+
// contract answers 404 by design. Neither refusal may be dressed as an empty
|
| 177 |
+
// list, so both are STATED and the description control still renders.
|
| 178 |
+
|
| 179 |
+
/** One field's governed meaning. `purpose` IS the description an admin edits. */
|
| 180 |
+
export interface SemanticField {
|
| 181 |
+
field: string;
|
| 182 |
+
purpose: string;
|
| 183 |
+
/** `draft` | `approved` | `disabled` β the registry's closed set. */
|
| 184 |
+
state: string;
|
| 185 |
+
role: string;
|
| 186 |
+
sensitivity: string;
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
/** The same boundary parse the overlay gets, for the same reason. */
|
| 190 |
+
export function parseSemantics(body: unknown): Record<string, SemanticField> {
|
| 191 |
+
const raw = (body as { fields?: unknown } | null)?.fields;
|
| 192 |
+
const out: Record<string, SemanticField> = {};
|
| 193 |
+
if (!Array.isArray(raw)) return out;
|
| 194 |
+
for (const item of raw) {
|
| 195 |
+
const r = item as Record<string, unknown> | null;
|
| 196 |
+
if (!r || typeof r !== "object") continue;
|
| 197 |
+
const field = str(r.field);
|
| 198 |
+
if (!field) continue;
|
| 199 |
+
out[field] = {
|
| 200 |
+
field,
|
| 201 |
+
purpose: str(r.purpose),
|
| 202 |
+
state: str(r.state, "draft"),
|
| 203 |
+
role: str(r.role),
|
| 204 |
+
sensitivity: str(r.sensitivity),
|
| 205 |
+
};
|
| 206 |
+
}
|
| 207 |
+
return out;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
/** The chip word for a governance state. Sentence case: DESIGN.md Β§2 forbids
|
| 211 |
+
* ALL-CAPS app chrome, and the registry's own values are lower case. */
|
| 212 |
+
function stateWord(state: string | undefined): string {
|
| 213 |
+
if (state === "approved") return "Approved";
|
| 214 |
+
if (state === "disabled") return "Disabled";
|
| 215 |
+
if (state === "draft") return "Draft";
|
| 216 |
+
return "No semantic record";
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
/** The explanation, in the tooltip rather than on the row (DESIGN.md Β§2). */
|
| 220 |
+
function stateHint(state: string | undefined): string {
|
| 221 |
+
if (state === "approved") return "This field is approved for retrieval by the assistant.";
|
| 222 |
+
if (state === "disabled") return "This field is withheld from retrieval.";
|
| 223 |
+
if (state === "draft")
|
| 224 |
+
return "This field is not approved for retrieval yet, so the assistant will not use it.";
|
| 225 |
+
return "This database publishes no governed meaning for this field.";
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
/** The chip tone. Blue is the interactive or affirmed state and red is the
|
| 229 |
+
* withheld one, per DESIGN.md Β§3; draft earns no colour, the way Member does not. */
|
| 230 |
+
function stateChipClass(state: string | undefined): string {
|
| 231 |
+
if (state === "approved") return "set-chip set-chip--admin";
|
| 232 |
+
if (state === "disabled") return "set-chip set-chip--off";
|
| 233 |
+
return "set-chip";
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
/** One database's PATCH body: `{ "<field_key>": {hidden, label, order} }`. */
|
| 237 |
type FieldPatch = { hidden?: boolean; label?: string | null; order?: number | null };
|
| 238 |
|
|
|
|
| 276 |
}
|
| 277 |
}
|
| 278 |
|
| 279 |
+
/**
|
| 280 |
+
* The semantic half's fetch, deliberately a sibling of `callOverlay` rather than
|
| 281 |
+
* a generalisation of it: the two speak different routes with different refusals,
|
| 282 |
+
* and one helper taking a path would make the 404 sentence below impossible to
|
| 283 |
+
* write honestly. Same credentials word, same "never surface a 5xx verbatim" rule.
|
| 284 |
+
*/
|
| 285 |
+
async function callSemantics<T>(
|
| 286 |
+
path: string,
|
| 287 |
+
init?: RequestInit & { body?: string },
|
| 288 |
+
): Promise<Result<T>> {
|
| 289 |
+
try {
|
| 290 |
+
const res = await fetch(`${API_V1}/query/semantics/${path}`, {
|
| 291 |
+
credentials: CREDENTIALS,
|
| 292 |
+
headers: init?.body ? { "Content-Type": "application/json" } : undefined,
|
| 293 |
+
...init,
|
| 294 |
+
});
|
| 295 |
+
let body: unknown = null;
|
| 296 |
+
try {
|
| 297 |
+
body = await res.json();
|
| 298 |
+
} catch {
|
| 299 |
+
/* an empty body is not fatal; the status below decides */
|
| 300 |
+
}
|
| 301 |
+
if (!res.ok) {
|
| 302 |
+
const err = (body as { error?: { message?: string } } | null)?.error;
|
| 303 |
+
const message =
|
| 304 |
+
// β 404 IS A REAL ANSWER HERE, NOT AN OUTAGE. Only a database with a
|
| 305 |
+
// declared topic contract has governed meanings, so a plain user table
|
| 306 |
+
// answers 404 and that is correct. Reporting it as a broken service
|
| 307 |
+
// would send an admin looking for a fault that is not there.
|
| 308 |
+
res.status === 404
|
| 309 |
+
? "This database publishes no semantic contract, so it carries no field descriptions."
|
| 310 |
+
: res.status >= 500
|
| 311 |
+
? "Something went wrong on our side. Try again in a moment."
|
| 312 |
+
: err?.message ||
|
| 313 |
+
(res.status === 403
|
| 314 |
+
? "Administrators only."
|
| 315 |
+
: "That description could not be saved.");
|
| 316 |
+
return { ok: false, message };
|
| 317 |
+
}
|
| 318 |
+
return { ok: true, data: body as T };
|
| 319 |
+
} catch {
|
| 320 |
+
return { ok: false, message: "The server could not be reached." };
|
| 321 |
+
}
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
// ββ the pane ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 325 |
|
| 326 |
/** Sort by the overlay's order where it has one, then by label, so a database
|
|
|
|
| 349 |
const [open, setOpen] = useState<string | null>(null);
|
| 350 |
/** The unsaved relabel and reorder for the open database, keyed by field. */
|
| 351 |
const [draft, setDraft] = useState<Record<string, FieldPatch>>({});
|
| 352 |
+
/**
|
| 353 |
+
* The open database's governed meanings, keyed by field. `null` is "not asked
|
| 354 |
+
* yet"; an empty object is "asked, and there are none", which is a different
|
| 355 |
+
* thing and the row renders differently for it.
|
| 356 |
+
*/
|
| 357 |
+
const [semantics, setSemantics] = useState<Record<string, SemanticField> | null>(null);
|
| 358 |
+
/** Why there are no descriptions, when there are none. Empty means there are. */
|
| 359 |
+
const [semNote, setSemNote] = useState("");
|
| 360 |
+
/** The unsaved description edits for the open database, keyed by field. */
|
| 361 |
+
const [semDraft, setSemDraft] = useState<Record<string, string>>({});
|
| 362 |
|
| 363 |
const load = useCallback(() => {
|
| 364 |
void callOverlay<unknown>().then((r) => {
|
|
|
|
| 377 |
|
| 378 |
useEffect(load, [load]);
|
| 379 |
|
| 380 |
+
/**
|
| 381 |
+
* The governed meanings are fetched PER DATABASE, when one is opened, because
|
| 382 |
+
* the route is per database and the list page shows no field rows to hang them
|
| 383 |
+
* on. Closing the takeover drops them, so re-opening a database cannot paint a
|
| 384 |
+
* previous one's descriptions for a moment.
|
| 385 |
+
*/
|
| 386 |
+
useEffect(() => {
|
| 387 |
+
if (!open) {
|
| 388 |
+
setSemantics(null);
|
| 389 |
+
setSemNote("");
|
| 390 |
+
setSemDraft({});
|
| 391 |
+
return;
|
| 392 |
+
}
|
| 393 |
+
let live = true;
|
| 394 |
+
setSemantics(null);
|
| 395 |
+
setSemNote("");
|
| 396 |
+
setSemDraft({});
|
| 397 |
+
void callSemantics<unknown>(encodeURIComponent(open)).then((r) => {
|
| 398 |
+
if (!live) return;
|
| 399 |
+
if (r.ok) {
|
| 400 |
+
setSemantics(parseSemantics(r.data));
|
| 401 |
+
setSemNote("");
|
| 402 |
+
} else {
|
| 403 |
+
// β NOT an error page, and NOT an empty list dressed as success. The
|
| 404 |
+
// rows still render their description control; what changes is that the
|
| 405 |
+
// pane SAYS why every one of them is empty. A refusal that removes the
|
| 406 |
+
// control would read as "this feature is missing" rather than as "this
|
| 407 |
+
// database has no governed meanings", which is the exact confusion
|
| 408 |
+
// instruction 8 reports about the previous wave.
|
| 409 |
+
setSemantics({});
|
| 410 |
+
setSemNote(r.message);
|
| 411 |
+
}
|
| 412 |
+
});
|
| 413 |
+
return () => {
|
| 414 |
+
live = false;
|
| 415 |
+
};
|
| 416 |
+
}, [open]);
|
| 417 |
+
|
| 418 |
const databases = useMemo(() => {
|
| 419 |
const byKey = new Map<string, { key: string; label: string; rows: OverlayField[] }>();
|
| 420 |
for (const f of parsed?.fields ?? []) {
|
|
|
|
| 429 |
return [...byKey.values()].sort((a, b) => a.label.localeCompare(b.label));
|
| 430 |
}, [parsed]);
|
| 431 |
|
| 432 |
+
/**
|
| 433 |
+
* ONE ACTION, TWO STORES, AND THE CODE SAYS SO. The overlay owns label, hidden
|
| 434 |
+
* and order; the semantic registry owns the description. An admin edits both in
|
| 435 |
+
* one row and saves once, but neither write is allowed to pretend to be the
|
| 436 |
+
* other, and a refusal on one must not silently discard the other's edits.
|
| 437 |
+
*/
|
| 438 |
const save = useCallback(
|
| 439 |
(database: string) => {
|
| 440 |
const patch = draft;
|
| 441 |
+
const notes = semDraft;
|
| 442 |
+
const noteFields = Object.keys(notes);
|
| 443 |
+
if (Object.keys(patch).length === 0 && noteFields.length === 0) return;
|
| 444 |
setSaving(true);
|
| 445 |
+
void (async () => {
|
| 446 |
+
let failure = "";
|
| 447 |
+
|
| 448 |
+
// 1. the overlay half.
|
| 449 |
+
if (Object.keys(patch).length) {
|
| 450 |
+
const r = await callOverlay<unknown>({
|
| 451 |
+
method: "PATCH",
|
| 452 |
+
body: JSON.stringify({ [database]: patch }),
|
| 453 |
+
});
|
| 454 |
+
if (r.ok) {
|
| 455 |
+
setParsed(parseOverlay(r.data));
|
| 456 |
+
setDraft({});
|
| 457 |
+
} else {
|
| 458 |
+
failure = r.message;
|
| 459 |
+
}
|
| 460 |
}
|
| 461 |
+
|
| 462 |
+
// 2. the semantic half, ONE FIELD AT A TIME because the route is per
|
| 463 |
+
// field. Only the fields the server actually accepted are cleared
|
| 464 |
+
// from the draft; a field it refused keeps the admin's text on screen
|
| 465 |
+
// rather than throwing away typing the row still appears to hold.
|
| 466 |
+
const stillDraft: Record<string, string> = {};
|
| 467 |
+
for (const field of noteFields) {
|
| 468 |
+
const one = await callSemantics<{ field?: unknown }>(
|
| 469 |
+
`${encodeURIComponent(database)}/${encodeURIComponent(field)}`,
|
| 470 |
+
{ method: "PATCH", body: JSON.stringify({ purpose: notes[field] }) },
|
| 471 |
+
);
|
| 472 |
+
if (one.ok) {
|
| 473 |
+
const written = parseSemantics({
|
| 474 |
+
fields: [(one.data as { field?: unknown } | null)?.field],
|
| 475 |
+
})[field];
|
| 476 |
+
if (written) setSemantics((s) => ({ ...(s ?? {}), [field]: written }));
|
| 477 |
+
} else {
|
| 478 |
+
stillDraft[field] = notes[field];
|
| 479 |
+
if (!failure) failure = one.message;
|
| 480 |
+
}
|
| 481 |
+
}
|
| 482 |
+
setSemDraft(stillDraft);
|
| 483 |
+
|
| 484 |
+
setSaving(false);
|
| 485 |
+
setError(failure);
|
| 486 |
+
setNotice(failure ? "" : "Saved.");
|
| 487 |
+
})();
|
| 488 |
},
|
| 489 |
+
[draft, semDraft],
|
| 490 |
);
|
| 491 |
|
| 492 |
if (parsed === null && !error)
|
|
|
|
| 541 |
setNotice("");
|
| 542 |
};
|
| 543 |
|
| 544 |
+
// Both stores count. A description edited on its own must arm Save and
|
| 545 |
+
// Discard exactly as a relabel does, or the row holds typing the page says
|
| 546 |
+
// there is nothing to save.
|
| 547 |
+
const dirty = Object.keys(draft).length > 0 || Object.keys(semDraft).length > 0;
|
| 548 |
|
| 549 |
return (
|
| 550 |
<div className="set-pane">
|
|
|
|
| 570 |
|
| 571 |
{error ? <p className="set-error">{error}</p> : null}
|
| 572 |
{notice ? <p className="set-notice">{notice}</p> : null}
|
| 573 |
+
{/* β STANDING RULE 1's SECOND SENTENCE, which is the half that gets
|
| 574 |
+
dropped: a limit that cannot be removed is REPORTED with its cause,
|
| 575 |
+
never silently enforced. Here the limit is that only a database with
|
| 576 |
+
a declared topic contract has governed meanings at all. Saying so is
|
| 577 |
+
what stops an empty Description column reading as a broken feature. */}
|
| 578 |
+
{semNote ? <p className="set-help">{semNote}</p> : null}
|
| 579 |
|
| 580 |
<ul className="w46-db-fields">
|
| 581 |
{rows.map((f, i) => (
|
|
|
|
| 593 |
Always shown
|
| 594 |
</span>
|
| 595 |
) : null}
|
| 596 |
+
{/* The GOVERNANCE state, in the chip vocabulary this row already
|
| 597 |
+
speaks. The explanation rides the tooltip rather than the row
|
| 598 |
+
(DESIGN.md Β§2: explanations go in a hover, not on screen). */}
|
| 599 |
+
<span
|
| 600 |
+
className={stateChipClass(semantics?.[f.field]?.state)}
|
| 601 |
+
title={stateHint(semantics?.[f.field]?.state)}
|
| 602 |
+
>
|
| 603 |
+
{stateWord(semantics?.[f.field]?.state)}
|
| 604 |
+
</span>
|
| 605 |
+
</div>
|
| 606 |
+
{/* ββ ONE GRID CHILD, NOT TWO, AND THAT IS STRUCTURAL RATHER THAN
|
| 607 |
+
TIDY. `.w46-db-field` is a THREE column grid declared in
|
| 608 |
+
`styles/wave46/manage-database.css`, and that sheet is in NO
|
| 609 |
+
lane's fence this wave β so a fourth child here would wrap into
|
| 610 |
+
an implicit fourth row and break every row on the page, with no
|
| 611 |
+
way to correct it from this file. The description therefore
|
| 612 |
+
sits INSIDE the relabel block, which stays the second column.
|
| 613 |
+
β `.set-field`'s 13px bottom margin is what separates the two
|
| 614 |
+
boxes; the second label deliberately carries no class, so the
|
| 615 |
+
block has no trailing margin to fight `align-items: end`. */}
|
| 616 |
+
<div className="w46-db-relabel">
|
| 617 |
+
<label className="set-field">
|
| 618 |
+
<span className="set-label">Label</span>
|
| 619 |
+
<input
|
| 620 |
+
className="set-input"
|
| 621 |
+
type="text"
|
| 622 |
+
value={f.label}
|
| 623 |
+
onChange={(e) => {
|
| 624 |
+
const value = e.currentTarget.value;
|
| 625 |
+
setDraft((d) => ({ ...d, [f.field]: { ...d[f.field], label: value } }));
|
| 626 |
+
setNotice("");
|
| 627 |
+
}}
|
| 628 |
+
/>
|
| 629 |
+
</label>
|
| 630 |
+
{/* β INSTRUCTION 8. Always rendered, including for a field with
|
| 631 |
+
no governed meaning and for a database with no contract at
|
| 632 |
+
all: the done-when is that an absent description "reads as
|
| 633 |
+
empty rather than as missing UI". The 500 character cap is
|
| 634 |
+
the registry's own (`semantic_registry._text(..., 500)`), so
|
| 635 |
+
the box refuses what the server would have truncated. */}
|
| 636 |
+
<label>
|
| 637 |
+
<span className="set-label">Description</span>
|
| 638 |
+
<input
|
| 639 |
+
className="set-input"
|
| 640 |
+
type="text"
|
| 641 |
+
maxLength={500}
|
| 642 |
+
placeholder="No description yet"
|
| 643 |
+
value={semDraft[f.field] ?? semantics?.[f.field]?.purpose ?? ""}
|
| 644 |
+
onChange={(e) => {
|
| 645 |
+
const value = e.currentTarget.value;
|
| 646 |
+
setSemDraft((d) => ({ ...d, [f.field]: value }));
|
| 647 |
+
setNotice("");
|
| 648 |
+
}}
|
| 649 |
+
/>
|
| 650 |
+
</label>
|
| 651 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 652 |
<div className="w46-db-acts">
|
| 653 |
<label className="set-check">
|
| 654 |
<input
|
|
|
|
| 701 |
disabled={!dirty || saving}
|
| 702 |
onClick={() => {
|
| 703 |
setDraft({});
|
| 704 |
+
setSemDraft({});
|
| 705 |
setNotice("");
|
| 706 |
}}
|
| 707 |
>
|
web/src/settings/PermsEditor.tsx
CHANGED
|
@@ -76,13 +76,10 @@ import {
|
|
| 76 |
setPassword,
|
| 77 |
} from "./settingsApi";
|
| 78 |
import type { AdminUser } from "./settingsApi";
|
| 79 |
-
import type {
|
| 80 |
import {
|
| 81 |
accessSummary,
|
| 82 |
-
copyDropped,
|
| 83 |
-
copyTargetRecord,
|
| 84 |
isDirty,
|
| 85 |
-
moduleSummary,
|
| 86 |
normalizeMetrics,
|
| 87 |
parsePermsPayload,
|
| 88 |
setAccess,
|
|
@@ -101,57 +98,21 @@ type Load =
|
|
| 101 |
/** What the confirm step is asking about. `null` = nothing is being confirmed. */
|
| 102 |
type Ask = null | { kind: "save" } | { kind: "discard" };
|
| 103 |
|
| 104 |
-
// --- C-PERMCOPY -----------------------
|
| 105 |
//
|
| 106 |
-
//
|
| 107 |
-
//
|
| 108 |
-
//
|
| 109 |
-
//
|
| 110 |
-
//
|
| 111 |
-
//
|
| 112 |
-
//
|
| 113 |
-
//
|
| 114 |
-
|
| 115 |
-
/** The UI's scope: the model's `CopyScope` plus the label this page shows. */
|
| 116 |
-
type CopyScopeUI = CopyScope & { label?: string };
|
| 117 |
-
|
| 118 |
-
/** One target, already fetched, with everything the confirm has to disclose. */
|
| 119 |
-
interface CopyPlan {
|
| 120 |
-
user: AdminUser;
|
| 121 |
-
payload: PermsPayload;
|
| 122 |
-
/** What that account's access says TODAY β the thing being overwritten. */
|
| 123 |
-
before: string;
|
| 124 |
-
/** Consequences beyond the overwrite itself, named per target. */
|
| 125 |
-
notes: string[];
|
| 126 |
-
}
|
| 127 |
-
|
| 128 |
-
type Copy =
|
| 129 |
-
| { phase: "pick"; scope: CopyScopeUI; picked: ReadonlySet<string> }
|
| 130 |
-
| { phase: "preparing"; scope: CopyScopeUI }
|
| 131 |
-
| {
|
| 132 |
-
phase: "confirm";
|
| 133 |
-
scope: CopyScopeUI;
|
| 134 |
-
plans: CopyPlan[];
|
| 135 |
-
/** Targets whose record could not be READ. Named, never dropped. */
|
| 136 |
-
refused: Array<{ username: string; why: string }>;
|
| 137 |
-
}
|
| 138 |
-
| { phase: "writing"; scope: CopyScopeUI };
|
| 139 |
-
|
| 140 |
-
/** "a", "a and b", "a, b and c" β a list a person reads, in a message that
|
| 141 |
-
* names every account it touched. */
|
| 142 |
-
function nameList(items: readonly string[]): string {
|
| 143 |
-
if (items.length <= 1) return items[0] ?? "";
|
| 144 |
-
return `${items.slice(0, -1).join(", ")} and ${items[items.length - 1]}`;
|
| 145 |
-
}
|
| 146 |
-
|
| 147 |
-
function scopeWords(scope: CopyScopeUI): string {
|
| 148 |
-
return scope.kind === "all" ? "this account's whole access" : `${scope.label} access`;
|
| 149 |
-
}
|
| 150 |
|
| 151 |
export function PermsEditor({
|
| 152 |
user,
|
| 153 |
userOptions,
|
| 154 |
-
copyTargets,
|
| 155 |
onBack,
|
| 156 |
onSaved,
|
| 157 |
}: {
|
|
@@ -167,10 +128,14 @@ export function PermsEditor({
|
|
| 167 |
* writes a rule that matches nothing and looks like it should match.
|
| 168 |
* β DISPLAY NAMES β the cells hold names. Not the copy targets below. */
|
| 169 |
userOptions?: string[];
|
| 170 |
-
/**
|
| 171 |
-
*
|
| 172 |
-
*
|
| 173 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
copyTargets?: readonly AdminUser[];
|
| 175 |
onBack: () => void;
|
| 176 |
/** "The server took a write" β the list behind this page reloads. It does NOT
|
|
@@ -190,7 +155,6 @@ export function PermsEditor({
|
|
| 190 |
const [saved, setSaved] = useState<PermsRecord>({});
|
| 191 |
const [draft, setDraft] = useState<PermsRecord>({});
|
| 192 |
const [ask, setAsk] = useState<Ask>(null);
|
| 193 |
-
const [copy, setCopy] = useState<Copy | null>(null);
|
| 194 |
const [busy, setBusy] = useState(false);
|
| 195 |
const [error, setError] = useState("");
|
| 196 |
/** What just happened, said ON THIS PAGE. The pane's own notice renders in the
|
|
@@ -307,6 +271,25 @@ export function PermsEditor({
|
|
| 307 |
const accountDirty =
|
| 308 |
name.trim() !== (user.name ?? "").trim() || role !== (user.role ?? "user");
|
| 309 |
const anyDirty = dirty || accountDirty;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 310 |
|
| 311 |
const goBack = useCallback(() => {
|
| 312 |
if (anyDirty) setAsk({ kind: "discard" });
|
|
@@ -334,8 +317,6 @@ export function PermsEditor({
|
|
| 334 |
dirtyRef.current = anyDirty;
|
| 335 |
const askRef = useRef(ask);
|
| 336 |
askRef.current = ask;
|
| 337 |
-
const copyRef = useRef(copy);
|
| 338 |
-
copyRef.current = copy;
|
| 339 |
// β W40-T14 β the FOURTH state Escape arbitrates. It tracks the RESOLVED drill-in, not the raw
|
| 340 |
// key: a stale key draws nothing, so Escape must not act as though a room were open over one.
|
| 341 |
const editingRef = useRef(false);
|
|
@@ -343,13 +324,9 @@ export function PermsEditor({
|
|
| 343 |
useEffect(() => {
|
| 344 |
const onKey = (e: KeyboardEvent) => {
|
| 345 |
if (e.key !== "Escape") return;
|
| 346 |
-
//
|
| 347 |
-
//
|
| 348 |
-
|
| 349 |
-
e.stopPropagation();
|
| 350 |
-
if (copyRef.current.phase !== "writing") setCopy(null);
|
| 351 |
-
return;
|
| 352 |
-
}
|
| 353 |
if (askRef.current) {
|
| 354 |
e.stopPropagation();
|
| 355 |
setAsk(null);
|
|
@@ -386,36 +363,73 @@ export function PermsEditor({
|
|
| 386 |
// nothing appears to happen. One module fits today; the second one does not.
|
| 387 |
const confirmRef = useRef<HTMLDivElement | null>(null);
|
| 388 |
useEffect(() => {
|
| 389 |
-
if (!ask
|
| 390 |
confirmRef.current?.scrollIntoView({ block: "center" });
|
| 391 |
// Focus follows the question, so Enter answers it and a screen reader is
|
| 392 |
// taken to the alert rather than left where the pointer was.
|
| 393 |
confirmRef.current?.querySelector<HTMLButtonElement>("button")?.focus();
|
| 394 |
-
}, [ask
|
| 395 |
|
| 396 |
-
|
| 397 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 398 |
setBusy(true);
|
| 399 |
setError("");
|
| 400 |
-
|
| 401 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 402 |
setBusy(false);
|
| 403 |
setAsk(null);
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 419 |
|
| 420 |
/** The account half's write. β THE PATCH STILL CARRIES NO `bus` (R1), and
|
| 421 |
* that is load-bearing rather than tidy: with the picker gone this form
|
|
@@ -440,155 +454,6 @@ export function PermsEditor({
|
|
| 440 |
[username, onSaved]
|
| 441 |
);
|
| 442 |
|
| 443 |
-
// --- C-PERMCOPY: prepare, then confirm, then write ------------------------
|
| 444 |
-
|
| 445 |
-
/**
|
| 446 |
-
* β THE TARGETS ARE FETCHED BEFORE THE CONFIRM, NOT AFTER IT. The contract
|
| 447 |
-
* asks for "a confirm that names the overwrite", and a confirm written from
|
| 448 |
-
* this page's knowledge alone can only name the SOURCE β it would say what is
|
| 449 |
-
* being copied and stay silent on what is being destroyed. Reading each
|
| 450 |
-
* target first lets the question state, per account, what that account's
|
| 451 |
-
* access says today and what else this write does to it. The payload fetched
|
| 452 |
-
* here is the same one the PUT is built from, so it costs nothing extra.
|
| 453 |
-
*/
|
| 454 |
-
const prepareCopy = useCallback(
|
| 455 |
-
async (scope: CopyScopeUI, picked: readonly string[]) => {
|
| 456 |
-
setCopy({ phase: "preparing", scope });
|
| 457 |
-
const plans: CopyPlan[] = [];
|
| 458 |
-
const refused: Array<{ username: string; why: string }> = [];
|
| 459 |
-
for (const target of copyTargets ?? []) {
|
| 460 |
-
if (!picked.includes(target.username)) continue;
|
| 461 |
-
const r = await getUserPerms(target.username);
|
| 462 |
-
if (!r.ok) {
|
| 463 |
-
refused.push({ username: target.username, why: r.message });
|
| 464 |
-
continue;
|
| 465 |
-
}
|
| 466 |
-
const p = parsePermsPayload(r.data);
|
| 467 |
-
if (!p) {
|
| 468 |
-
refused.push({
|
| 469 |
-
username: target.username,
|
| 470 |
-
why: "its permission record could not be read",
|
| 471 |
-
});
|
| 472 |
-
continue;
|
| 473 |
-
}
|
| 474 |
-
const notes: string[] = [];
|
| 475 |
-
// An admin bypasses `perms` entirely, so a copy onto one is stored and
|
| 476 |
-
// inert. Silently writing rules that do nothing is how an admin comes
|
| 477 |
-
// to believe an account is restricted when it is not.
|
| 478 |
-
if (p.isAdmin) {
|
| 479 |
-
notes.push(
|
| 480 |
-
"is an administrator, so the rules will be stored but stay inert until the account is changed to Member"
|
| 481 |
-
);
|
| 482 |
-
}
|
| 483 |
-
// β A COPY MIGRATES THE TARGET. An un-migrated record runs under the
|
| 484 |
-
// PREVIOUS wall; a PUT moves it to the per-module model, which changes
|
| 485 |
-
// what governs that account from that moment on. Fresh accounts are
|
| 486 |
-
// exactly the ones an admin reaches for the copy button over
|
| 487 |
-
// (`create_user` stamps no perms), so this is the common case, not the
|
| 488 |
-
// exotic one.
|
| 489 |
-
if (!p.migrated) {
|
| 490 |
-
notes.push(
|
| 491 |
-
"still uses the previous access model, and this write moves it to the per-module model"
|
| 492 |
-
);
|
| 493 |
-
}
|
| 494 |
-
// The same disclosure this page already makes for the account it has
|
| 495 |
-
// open. A whole-record replace drops what it does not name, and a copy
|
| 496 |
-
// does it to somebody the admin never opened.
|
| 497 |
-
if (p.orphanModules.length) {
|
| 498 |
-
notes.push(
|
| 499 |
-
`has rules for ${p.orphanModules.join(", ")}, which this deployment no longer offers, so those are removed`
|
| 500 |
-
);
|
| 501 |
-
}
|
| 502 |
-
// β DISCLOSED BEFORE THE WRITE, not only after it. `runCopy` also reports
|
| 503 |
-
// this, but a report arrives when the admin can no longer decide
|
| 504 |
-
// anything; the confirm is where the decision is. The payload needed to
|
| 505 |
-
// know it is already in hand, so there is no reason to make them find out
|
| 506 |
-
// the expensive way.
|
| 507 |
-
const cannot = copyDropped(p, saved, scope);
|
| 508 |
-
if (cannot.length) {
|
| 509 |
-
const named = cannot.map(
|
| 510 |
-
(k) => payload?.modules.find((m) => m.key === k)?.label ?? k
|
| 511 |
-
);
|
| 512 |
-
notes.push(
|
| 513 |
-
`does not offer ${named.join(", ")}, so that part of this copy cannot be written at all`
|
| 514 |
-
);
|
| 515 |
-
}
|
| 516 |
-
plans.push({
|
| 517 |
-
user: target,
|
| 518 |
-
payload: p,
|
| 519 |
-
before:
|
| 520 |
-
scope.kind === "all"
|
| 521 |
-
? accessSummary(p, p.entries) || "No access"
|
| 522 |
-
: moduleSummary(
|
| 523 |
-
p.entries[scope.key],
|
| 524 |
-
(p.modules.find((m) => m.key === scope.key)?.fields.length ?? 0) === 0
|
| 525 |
-
),
|
| 526 |
-
notes,
|
| 527 |
-
});
|
| 528 |
-
}
|
| 529 |
-
setCopy({ phase: "confirm", scope, plans, refused });
|
| 530 |
-
},
|
| 531 |
-
// `saved` and `payload`: the drop disclosure is computed against the record
|
| 532 |
-
// as STORED (what a copy actually sends) and labelled from this account's
|
| 533 |
-
// own module list, which is the only place a label for an undeclared-on-the-
|
| 534 |
-
// target module exists.
|
| 535 |
-
[copyTargets, saved, payload]
|
| 536 |
-
);
|
| 537 |
-
|
| 538 |
-
const runCopy = useCallback(
|
| 539 |
-
async (scope: CopyScopeUI, plans: readonly CopyPlan[]) => {
|
| 540 |
-
setCopy({ phase: "writing", scope });
|
| 541 |
-
setError("");
|
| 542 |
-
const done: string[] = [];
|
| 543 |
-
const failed: string[] = [];
|
| 544 |
-
const dropped = new Set<string>();
|
| 545 |
-
for (const plan of plans) {
|
| 546 |
-
// β THE COMPOSITION LIVES IN `permsModel`, NOT HERE β it is the second
|
| 547 |
-
// producer of a PUT body in the product and the first aimed at somebody
|
| 548 |
-
// else's record, so it belongs where the gate can reach it and where its
|
| 549 |
-
// negative control can prove it capable of going red. See
|
| 550 |
-
// `copyTargetRecord`'s own note for the whole-tree rule it enforces.
|
| 551 |
-
const merged = copyTargetRecord(plan.payload, saved, scope);
|
| 552 |
-
for (const k of copyDropped(plan.payload, saved, scope)) dropped.add(k);
|
| 553 |
-
const r = await putUserPerms(plan.user.username, toPutBody(plan.payload, merged));
|
| 554 |
-
if (r.ok) done.push(plan.user.username);
|
| 555 |
-
else failed.push(`${plan.user.username} (${r.message})`);
|
| 556 |
-
}
|
| 557 |
-
setCopy(null);
|
| 558 |
-
// β ONE MESSAGE PER OUTCOME, NEVER ONE MESSAGE FOR THE BATCH. Three
|
| 559 |
-
// targets with the second refused, reported as "that change could not be
|
| 560 |
-
// saved", is a sentence that lies about the two that took it β and the
|
| 561 |
-
// admin's only recovery is to re-copy onto accounts that already have it.
|
| 562 |
-
if (done.length) {
|
| 563 |
-
const msg = `Copied ${scopeWords(scope)} to ${nameList(done)}.`;
|
| 564 |
-
setSaid(msg);
|
| 565 |
-
onSaved(msg);
|
| 566 |
-
}
|
| 567 |
-
// β ONE MESSAGE, BUILT FROM WHAT ACTUALLY WENT WRONG β the refusals and
|
| 568 |
-
// the modules that could not ride the write are different failures and
|
| 569 |
-
// both have to survive into it. "Copied" alone over a dropped module would
|
| 570 |
-
// be a success message for a write that did not fully happen.
|
| 571 |
-
const problems: string[] = [];
|
| 572 |
-
if (failed.length) problems.push(`Not copied to ${nameList(failed)}.`);
|
| 573 |
-
if (dropped.size) {
|
| 574 |
-
const list = nameList([...dropped].sort());
|
| 575 |
-
problems.push(
|
| 576 |
-
`${list} could not be copied. The accounts you picked do not offer ${dropped.size === 1 ? "it" : "them"}.`
|
| 577 |
-
);
|
| 578 |
-
}
|
| 579 |
-
if (problems.length) setError(problems.join(" "));
|
| 580 |
-
},
|
| 581 |
-
[saved, onSaved]
|
| 582 |
-
);
|
| 583 |
-
|
| 584 |
-
const canCopy = (copyTargets?.length ?? 0) > 0 && !!payload && !dirty;
|
| 585 |
-
const openCopy = useCallback((scope: CopyScopeUI) => {
|
| 586 |
-
setAsk(null);
|
| 587 |
-
setError("");
|
| 588 |
-
setSaid("");
|
| 589 |
-
setCopy({ phase: "pick", scope, picked: new Set<string>() });
|
| 590 |
-
}, []);
|
| 591 |
-
|
| 592 |
/**
|
| 593 |
* β W40-T14 β WHO THIS PAGE IS ABOUT, plus whatever just happened, held ONCE. Both returns
|
| 594 |
* below render it: the account page and the per-database room are the same room with a
|
|
@@ -822,30 +687,12 @@ export function PermsEditor({
|
|
| 822 |
access rule set below.
|
| 823 |
</p>
|
| 824 |
) : null}
|
| 825 |
-
|
| 826 |
-
|
| 827 |
-
|
| 828 |
-
|
| 829 |
-
|
| 830 |
-
|
| 831 |
-
>
|
| 832 |
-
<Busy busy={busy} idle="Save account" doing="Saving" />
|
| 833 |
-
</button>
|
| 834 |
-
<button
|
| 835 |
-
type="button"
|
| 836 |
-
className="set-secondary"
|
| 837 |
-
disabled={busy}
|
| 838 |
-
onClick={() =>
|
| 839 |
-
applyAccount(
|
| 840 |
-
{ active: !user.active },
|
| 841 |
-
`${user.active ? "Deactivated" : "Reactivated"} ${username}.`
|
| 842 |
-
)
|
| 843 |
-
}
|
| 844 |
-
>
|
| 845 |
-
<Busy busy={busy} idle={user.active ? "Deactivate account" : "Reactivate account"}
|
| 846 |
-
doing={user.active ? "Deactivating" : "Reactivating"} />
|
| 847 |
-
</button>
|
| 848 |
-
</div>
|
| 849 |
|
| 850 |
{/* ββ W40-T15 (owner instruction 9) β ONE DELIBERATE GROUP, READ TOP TO BOTTOM. Owner,
|
| 851 |
verbatim: *"move the 'This signs <email> out everywhere immediately.' notice one line
|
|
@@ -956,63 +803,22 @@ export function PermsEditor({
|
|
| 956 |
</p>
|
| 957 |
) : null}
|
| 958 |
|
| 959 |
-
{/* β
|
| 960 |
-
|
| 961 |
-
|
| 962 |
-
|
| 963 |
-
|
| 964 |
-
|
| 965 |
-
|
| 966 |
-
|
| 967 |
-
|
| 968 |
-
|
| 969 |
-
β `
|
| 970 |
-
|
|
|
|
| 971 |
<div role="group" aria-labelledby="set-access-h">
|
| 972 |
<div className="set-perm-sect">
|
| 973 |
<h4 className="set-h4" id="set-access-h">Access</h4>
|
| 974 |
-
{/* β WRAPPED, NOT LEFT AS SIBLINGS β the same reason `.set-perm-headend` exists one
|
| 975 |
-
file over. `.set-perm-sect` is `space-between` and lives in index.css, which this
|
| 976 |
-
lane does not write; two trailing controls as bare children would be three flex
|
| 977 |
-
items pushed to the corners of the row. One flex child in, one flex child out. */}
|
| 978 |
-
<span className="set-perm-sectend">
|
| 979 |
-
{copyTargets?.length ? (
|
| 980 |
-
<button
|
| 981 |
-
type="button"
|
| 982 |
-
className="set-secondary set-copy-door"
|
| 983 |
-
disabled={!canCopy || busy}
|
| 984 |
-
title={
|
| 985 |
-
dirty
|
| 986 |
-
? "Save this account's access first. A copy sends what is stored, not what is on screen."
|
| 987 |
-
: undefined
|
| 988 |
-
}
|
| 989 |
-
onClick={() => openCopy({ kind: "all" })}
|
| 990 |
-
>
|
| 991 |
-
Apply this access toβ¦
|
| 992 |
-
</button>
|
| 993 |
-
) : null}
|
| 994 |
-
{/* ββ THE SAME HANDLER, NOT A COPY OF THE SAVE. It calls `setAsk({ kind: "save" })`
|
| 995 |
-
exactly as the bottom button does, so both open the one confirm and both commit
|
| 996 |
-
through the one `save()` β which is also the whole of the ticket's negative
|
| 997 |
-
control, "the top button must also navigate back exactly as the bottom one
|
| 998 |
-
does". It navigates back because `save()` is what passes `true` to `onSaved`,
|
| 999 |
-
and `verify_ui.py::saves_show_they_are_working` counts that call site and
|
| 1000 |
-
demands there be EXACTLY ONE (wave 17's R7 removed the blanket return on
|
| 1001 |
-
purpose). A second call passing `true` from here would undo a ruling nobody
|
| 1002 |
-
revisited, and the count is a REGEX over this file's RAW text: writing that
|
| 1003 |
-
call out even in a comment is enough to red the gate. Measured, here.
|
| 1004 |
-
β AND IT RENDERS `<Busy>`: leg 1 of that same check reds any `set-primary`
|
| 1005 |
-
gated on `busy` that shows no in-flight state, because greying out is
|
| 1006 |
-
indistinguishable from having nothing to save. */}
|
| 1007 |
-
<button
|
| 1008 |
-
type="button"
|
| 1009 |
-
className="set-primary set-perm-savetop"
|
| 1010 |
-
disabled={busy || !dirty}
|
| 1011 |
-
onClick={() => setAsk({ kind: "save" })}
|
| 1012 |
-
>
|
| 1013 |
-
<Busy busy={busy} idle="Save access" doing="Saving" />
|
| 1014 |
-
</button>
|
| 1015 |
-
</span>
|
| 1016 |
</div>
|
| 1017 |
|
| 1018 |
{/* β W40-T14 β WHAT THIS ACCOUNT CAN SEE, and nothing else. `DESIGN.md` Β§4 "never
|
|
@@ -1022,15 +828,9 @@ export function PermsEditor({
|
|
| 1022 |
reader cannot get by looking. */}
|
| 1023 |
<p className="set-help set-perm-intro">{accessSummary(payload, draft)}.</p>
|
| 1024 |
|
| 1025 |
-
{/*
|
| 1026 |
-
|
| 1027 |
-
|
| 1028 |
-
{dirty && copyTargets?.length ? (
|
| 1029 |
-
<p className="set-help set-copy-why">
|
| 1030 |
-
Copying is unavailable while there are unsaved changes. A copy sends
|
| 1031 |
-
what is stored, not what is on screen.
|
| 1032 |
-
</p>
|
| 1033 |
-
) : null}
|
| 1034 |
|
| 1035 |
{/* ββ W40-T15 (owner instruction 8) β TWO ROOMS, AND NEITHER OF THEM IS EMPTY.
|
| 1036 |
β A GROUP WITH NO MEMBERS RENDERS NO HEADING, which is the whole reason this is a
|
|
@@ -1060,24 +860,60 @@ export function PermsEditor({
|
|
| 1060 |
</>
|
| 1061 |
)}
|
| 1062 |
|
| 1063 |
-
<div className="set-actions set-perm-actions">
|
| 1064 |
-
<button
|
| 1065 |
-
type="button"
|
| 1066 |
-
className="set-primary"
|
| 1067 |
-
disabled={busy || !dirty}
|
| 1068 |
-
onClick={() => setAsk({ kind: "save" })}
|
| 1069 |
-
>
|
| 1070 |
-
<Busy busy={busy} idle="Save access" doing="Saving" />
|
| 1071 |
-
</button>
|
| 1072 |
-
<button type="button" className="set-secondary" disabled={busy} onClick={goBack}>
|
| 1073 |
-
Cancel
|
| 1074 |
-
</button>
|
| 1075 |
-
{dirty ? <span className="set-help set-perm-dirty">Unsaved changes</span> : null}
|
| 1076 |
-
</div>
|
| 1077 |
</div>
|
| 1078 |
</>
|
| 1079 |
) : null}
|
| 1080 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1081 |
{ask ? (
|
| 1082 |
<div className="set-confirm-wrap">
|
| 1083 |
<div
|
|
@@ -1085,13 +921,18 @@ export function PermsEditor({
|
|
| 1085 |
className="set-confirm"
|
| 1086 |
role="alertdialog"
|
| 1087 |
aria-modal="true"
|
| 1088 |
-
aria-label={ask.kind === "save" ? "Confirm
|
| 1089 |
>
|
| 1090 |
{ask.kind === "save" ? (
|
| 1091 |
<>
|
| 1092 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1093 |
<p className="set-help">
|
| 1094 |
-
|
|
|
|
| 1095 |
</p>
|
| 1096 |
</>
|
| 1097 |
) : (
|
|
@@ -1106,15 +947,47 @@ export function PermsEditor({
|
|
| 1106 |
</>
|
| 1107 |
)}
|
| 1108 |
<div className="set-actions">
|
| 1109 |
-
|
| 1110 |
-
|
| 1111 |
-
|
| 1112 |
-
|
| 1113 |
-
|
| 1114 |
-
|
| 1115 |
-
|
| 1116 |
-
|
| 1117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1118 |
<button
|
| 1119 |
type="button"
|
| 1120 |
className="set-secondary"
|
|
@@ -1127,130 +1000,6 @@ export function PermsEditor({
|
|
| 1127 |
</div>
|
| 1128 |
</div>
|
| 1129 |
) : null}
|
| 1130 |
-
|
| 1131 |
-
{copy ? (
|
| 1132 |
-
<div className="set-confirm-wrap">
|
| 1133 |
-
<div
|
| 1134 |
-
ref={confirmRef}
|
| 1135 |
-
className="set-confirm set-copy"
|
| 1136 |
-
role="alertdialog"
|
| 1137 |
-
aria-modal="true"
|
| 1138 |
-
aria-label={`Copy ${scopeWords(copy.scope)}`}
|
| 1139 |
-
>
|
| 1140 |
-
{copy.phase === "pick" ? (
|
| 1141 |
-
<>
|
| 1142 |
-
<h4 className="set-h4">Copy {scopeWords(copy.scope)} toβ¦</h4>
|
| 1143 |
-
<p className="set-help">
|
| 1144 |
-
{copy.scope.kind === "all"
|
| 1145 |
-
? `Every account you pick has its whole access record replaced with ${displayName}'s.`
|
| 1146 |
-
: `Every account you pick has its ${copy.scope.label} access replaced with ${displayName}'s. Their other modules are left alone.`}
|
| 1147 |
-
</p>
|
| 1148 |
-
<div className="set-copy-list">
|
| 1149 |
-
{(copyTargets ?? []).map((t) => (
|
| 1150 |
-
<label className="set-check set-copy-row" key={t.username}>
|
| 1151 |
-
<input
|
| 1152 |
-
type="checkbox"
|
| 1153 |
-
checked={copy.picked.has(t.username)}
|
| 1154 |
-
onChange={(e) => {
|
| 1155 |
-
const next = new Set(copy.picked);
|
| 1156 |
-
if (e.target.checked) next.add(t.username);
|
| 1157 |
-
else next.delete(t.username);
|
| 1158 |
-
setCopy({ ...copy, picked: next });
|
| 1159 |
-
}}
|
| 1160 |
-
/>
|
| 1161 |
-
<span className="set-copy-name">{t.name || t.username}</span>
|
| 1162 |
-
<span className="set-username set-copy-user">{t.username}</span>
|
| 1163 |
-
{t.role === "admin" ? (
|
| 1164 |
-
<span className="set-chip set-chip--admin">Admin</span>
|
| 1165 |
-
) : null}
|
| 1166 |
-
{t.active ? null : (
|
| 1167 |
-
<span className="set-chip set-chip--off">Deactivated</span>
|
| 1168 |
-
)}
|
| 1169 |
-
</label>
|
| 1170 |
-
))}
|
| 1171 |
-
</div>
|
| 1172 |
-
<div className="set-actions">
|
| 1173 |
-
<button
|
| 1174 |
-
type="button"
|
| 1175 |
-
className="set-primary"
|
| 1176 |
-
disabled={copy.picked.size === 0}
|
| 1177 |
-
onClick={() => void prepareCopy(copy.scope, [...copy.picked])}
|
| 1178 |
-
>
|
| 1179 |
-
Continue
|
| 1180 |
-
</button>
|
| 1181 |
-
<button type="button" className="set-secondary" onClick={() => setCopy(null)}>
|
| 1182 |
-
Cancel
|
| 1183 |
-
</button>
|
| 1184 |
-
</div>
|
| 1185 |
-
</>
|
| 1186 |
-
) : null}
|
| 1187 |
-
|
| 1188 |
-
{copy.phase === "preparing" || copy.phase === "writing" ? (
|
| 1189 |
-
<div className="set-loading">
|
| 1190 |
-
<span className="lp-spin lp-spin--lg" role="status" aria-label="Loading" />
|
| 1191 |
-
</div>
|
| 1192 |
-
) : null}
|
| 1193 |
-
|
| 1194 |
-
{copy.phase === "confirm" ? (
|
| 1195 |
-
<>
|
| 1196 |
-
<h4 className="set-h4">
|
| 1197 |
-
Replace {scopeWords(copy.scope)} for {copy.plans.length} account
|
| 1198 |
-
{copy.plans.length === 1 ? "" : "s"}?
|
| 1199 |
-
</h4>
|
| 1200 |
-
{copy.plans.length === 0 ? (
|
| 1201 |
-
<p className="set-help">
|
| 1202 |
-
None of the accounts picked could be read, so there is nothing to write.
|
| 1203 |
-
</p>
|
| 1204 |
-
) : (
|
| 1205 |
-
<ul className="set-copy-plans">
|
| 1206 |
-
{copy.plans.map((p) => (
|
| 1207 |
-
<li key={p.user.username}>
|
| 1208 |
-
{/* β THE OVERWRITE, NAMED PER TARGET. What is destroyed
|
| 1209 |
-
is what this account has TODAY, so the question shows
|
| 1210 |
-
it β a confirm that only describes the source asks
|
| 1211 |
-
the admin to remember the rest. */}
|
| 1212 |
-
<span className="set-copy-name">{p.user.name || p.user.username}</span>{" "}
|
| 1213 |
-
<span className="set-copy-before">now: {p.before}</span>
|
| 1214 |
-
{p.notes.map((n) => (
|
| 1215 |
-
<span className="set-copy-note" key={n}>
|
| 1216 |
-
{p.user.username} {n}
|
| 1217 |
-
</span>
|
| 1218 |
-
))}
|
| 1219 |
-
</li>
|
| 1220 |
-
))}
|
| 1221 |
-
</ul>
|
| 1222 |
-
)}
|
| 1223 |
-
{copy.refused.length ? (
|
| 1224 |
-
<p className="set-error">
|
| 1225 |
-
{/* β The reason comes from the API and ends in a full stop
|
| 1226 |
-
of its own ("Administrators only."), which read as
|
| 1227 |
-
"(Administrators only.) could not be read" β a stray
|
| 1228 |
-
period mid-sentence. Trimmed where the sentence is
|
| 1229 |
-
built, not in the message the API returns. */}
|
| 1230 |
-
{nameList(
|
| 1231 |
-
copy.refused.map((r) => `${r.username} (${r.why.replace(/\.\s*$/, "")})`)
|
| 1232 |
-
)}{" "}
|
| 1233 |
-
could not be read and will not be changed.
|
| 1234 |
-
</p>
|
| 1235 |
-
) : null}
|
| 1236 |
-
<div className="set-actions">
|
| 1237 |
-
<button
|
| 1238 |
-
type="button"
|
| 1239 |
-
className="set-primary"
|
| 1240 |
-
disabled={copy.plans.length === 0}
|
| 1241 |
-
onClick={() => void runCopy(copy.scope, copy.plans)}
|
| 1242 |
-
>
|
| 1243 |
-
Replace access
|
| 1244 |
-
</button>
|
| 1245 |
-
<button type="button" className="set-secondary" onClick={() => setCopy(null)}>
|
| 1246 |
-
Cancel
|
| 1247 |
-
</button>
|
| 1248 |
-
</div>
|
| 1249 |
-
</>
|
| 1250 |
-
) : null}
|
| 1251 |
-
</div>
|
| 1252 |
-
</div>
|
| 1253 |
-
) : null}
|
| 1254 |
</div>
|
| 1255 |
);
|
| 1256 |
}
|
|
|
|
| 76 |
setPassword,
|
| 77 |
} from "./settingsApi";
|
| 78 |
import type { AdminUser } from "./settingsApi";
|
| 79 |
+
import type { PermsModule, PermsPayload, PermsRecord } from "./permsModel";
|
| 80 |
import {
|
| 81 |
accessSummary,
|
|
|
|
|
|
|
| 82 |
isDirty,
|
|
|
|
| 83 |
normalizeMetrics,
|
| 84 |
parsePermsPayload,
|
| 85 |
setAccess,
|
|
|
|
| 98 |
/** What the confirm step is asking about. `null` = nothing is being confirmed. */
|
| 99 |
type Ask = null | { kind: "save" } | { kind: "discard" };
|
| 100 |
|
| 101 |
+
// --- C-PERMCOPY IS GONE (W47-T19, owner instruction 11) ----------------------
|
| 102 |
//
|
| 103 |
+
// Owner, verbatim: *"Delete the 'Copy this account access to' button, its not
|
| 104 |
+
// needed"*. Asked directly on 2026-08-30 whether the door should merely MOVE to
|
| 105 |
+
// the bottom bar (instruction 11 names it twice, once as a move and once as a
|
| 106 |
+
// deletion), the owner ruled: delete it entirely, the button AND the modal it
|
| 107 |
+
// opened. So the whole contract's client half went with it β the pick/confirm
|
| 108 |
+
// dialog, the per-target prepare, the write loop, and the `permsModel` helpers
|
| 109 |
+
// that only it called are no longer imported here. `permsModel` keeps
|
| 110 |
+
// `copyTargetRecord`/`copyDropped` and their gates; nothing in the UI reaches
|
| 111 |
+
// them now, which is a deliberate deletion rather than a seam left dangling.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
export function PermsEditor({
|
| 114 |
user,
|
| 115 |
userOptions,
|
|
|
|
| 116 |
onBack,
|
| 117 |
onSaved,
|
| 118 |
}: {
|
|
|
|
| 128 |
* writes a rule that matches nothing and looks like it should match.
|
| 129 |
* β DISPLAY NAMES β the cells hold names. Not the copy targets below. */
|
| 130 |
userOptions?: string[];
|
| 131 |
+
/** β ACCEPTED AND IGNORED SINCE WAVE 47 (W47-T19, owner instruction 11). It fed
|
| 132 |
+
* C-PERMCOPY's "Apply this access toβ¦" door, which the owner ruled deleted
|
| 133 |
+
* outright on 2026-08-30 β the button and the modal both. The MEMBER stays on
|
| 134 |
+
* this interface deliberately: `settings/SettingsModal.tsx` and
|
| 135 |
+
* `pages/_test/render.test.tsx` still pass it, and neither is this ticket's to
|
| 136 |
+
* edit, so removing it would red `tsc` in files the change does not own. It is
|
| 137 |
+
* read nowhere below; the next writer removing it must clear both call sites in
|
| 138 |
+
* the same change. */
|
| 139 |
copyTargets?: readonly AdminUser[];
|
| 140 |
onBack: () => void;
|
| 141 |
/** "The server took a write" β the list behind this page reloads. It does NOT
|
|
|
|
| 155 |
const [saved, setSaved] = useState<PermsRecord>({});
|
| 156 |
const [draft, setDraft] = useState<PermsRecord>({});
|
| 157 |
const [ask, setAsk] = useState<Ask>(null);
|
|
|
|
| 158 |
const [busy, setBusy] = useState(false);
|
| 159 |
const [error, setError] = useState("");
|
| 160 |
/** What just happened, said ON THIS PAGE. The pane's own notice renders in the
|
|
|
|
| 271 |
const accountDirty =
|
| 272 |
name.trim() !== (user.name ?? "").trim() || role !== (user.role ?? "user");
|
| 273 |
const anyDirty = dirty || accountDirty;
|
| 274 |
+
/**
|
| 275 |
+
* ββ W47-T19 (owner instruction 11) β WHAT THE ONE SAVE SAYS IT SAVES. With the two buttons
|
| 276 |
+
* merged there is a single control committing two different kinds of work, and a fixed label
|
| 277 |
+
* would be wrong half the time: "Save access" over a renamed account, or "Save account" over a
|
| 278 |
+
* pure permission edit. So it names the wider of the two whenever the account form is part of
|
| 279 |
+
* the write, and the narrower one when only the rules changed.
|
| 280 |
+
*
|
| 281 |
+
* β THE CONFIRM'S BUTTON READS THIS SAME VALUE, which is the point of holding it once: the
|
| 282 |
+
* control the admin clicks and the control they confirm with can never disagree about what is
|
| 283 |
+
* being written.
|
| 284 |
+
*
|
| 285 |
+
* β BOTH SPELLINGS ARE PINNED BY `verify_ui.py`, and neither is free to be reworded here.
|
| 286 |
+
* "Save account" is what the render smoke reads to prove wave 17's R7 (the account form, with
|
| 287 |
+
* its save, is on THIS page and not behind a second door), and its blanking is that check's
|
| 288 |
+
* negative control. "Save access" is the label whose in-flight component
|
| 289 |
+
* `saves_show_they_are_working`'s own NC strips to prove leg 1 can still fire. Changing either
|
| 290 |
+
* word means changing the gate that pins it, in the same commit, on purpose.
|
| 291 |
+
*/
|
| 292 |
+
const saveLabel = dirty && !accountDirty ? "Save access" : "Save account";
|
| 293 |
|
| 294 |
const goBack = useCallback(() => {
|
| 295 |
if (anyDirty) setAsk({ kind: "discard" });
|
|
|
|
| 317 |
dirtyRef.current = anyDirty;
|
| 318 |
const askRef = useRef(ask);
|
| 319 |
askRef.current = ask;
|
|
|
|
|
|
|
| 320 |
// β W40-T14 β the FOURTH state Escape arbitrates. It tracks the RESOLVED drill-in, not the raw
|
| 321 |
// key: a stale key draws nothing, so Escape must not act as though a room were open over one.
|
| 322 |
const editingRef = useRef(false);
|
|
|
|
| 324 |
useEffect(() => {
|
| 325 |
const onKey = (e: KeyboardEvent) => {
|
| 326 |
if (e.key !== "Escape") return;
|
| 327 |
+
// β W47-T19 β the copy dialog was the innermost thing Escape used to arbitrate and it is
|
| 328 |
+
// deleted, so the confirm below is the innermost thing left. Nothing else about this
|
| 329 |
+
// arbitration changed, and the order of the three survivors is still load-bearing.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 330 |
if (askRef.current) {
|
| 331 |
e.stopPropagation();
|
| 332 |
setAsk(null);
|
|
|
|
| 363 |
// nothing appears to happen. One module fits today; the second one does not.
|
| 364 |
const confirmRef = useRef<HTMLDivElement | null>(null);
|
| 365 |
useEffect(() => {
|
| 366 |
+
if (!ask) return;
|
| 367 |
confirmRef.current?.scrollIntoView({ block: "center" });
|
| 368 |
// Focus follows the question, so Enter answers it and a screen reader is
|
| 369 |
// taken to the alert rather than left where the pointer was.
|
| 370 |
confirmRef.current?.querySelector<HTMLButtonElement>("button")?.focus();
|
| 371 |
+
}, [ask]);
|
| 372 |
|
| 373 |
+
/**
|
| 374 |
+
* ββ W47-T19 (owner instruction 11) β ONE SAVE, BOTH HALVES, IN THE ORDER A FAILURE CAN BE
|
| 375 |
+
* REASONED ABOUT. Owner, verbatim: *"we should merge 'Save access' and 'Save account' and move
|
| 376 |
+
* those buttons at the bottom of the navigation."* So the page's two writes became one action:
|
| 377 |
+
* the account PATCH first, the permission PUT second, one success message.
|
| 378 |
+
*
|
| 379 |
+
* β THE ACCOUNT HALF GOES FIRST AND A FAILURE THERE STOPS THE WHOLE ACTION. The two writes
|
| 380 |
+
* cannot be one transaction β they are two routes β so the order decides what a half-failure
|
| 381 |
+
* leaves behind. Patching first means a refused PATCH writes nothing at all; doing it the other
|
| 382 |
+
* way round would leave the access committed under a role the admin believed they had changed,
|
| 383 |
+
* which is the one combination that misleads about who may see what.
|
| 384 |
+
*
|
| 385 |
+
* β THE ACCESS HALF IS SKIPPED WHEN THE RECORD NEVER LOADED, and that is not a shortcut: with
|
| 386 |
+
* `payload` null there is no baseline to build a whole-tree PUT from, and `dirty` is false by
|
| 387 |
+
* construction, so the only thing that can be dirty is the account form. Saving it anyway is
|
| 388 |
+
* what keeps the display name, role and deactivate usable while the perms GET is failing β
|
| 389 |
+
* the capability wave 17's R7 moved onto this page.
|
| 390 |
+
*/
|
| 391 |
+
const save = useCallback(async () => {
|
| 392 |
setBusy(true);
|
| 393 |
setError("");
|
| 394 |
+
if (accountDirty) {
|
| 395 |
+
const a = await patchUser(username, { name, role });
|
| 396 |
+
if (!a.ok) {
|
| 397 |
+
setBusy(false);
|
| 398 |
+
setAsk(null);
|
| 399 |
+
setError(a.message);
|
| 400 |
+
return;
|
| 401 |
+
}
|
| 402 |
+
}
|
| 403 |
+
if (!payload) {
|
| 404 |
setBusy(false);
|
| 405 |
setAsk(null);
|
| 406 |
+
const msg = `Saved ${username}.`;
|
| 407 |
+
setSaid(msg);
|
| 408 |
+
// Stays on the page: the access half is still unread, so this is not the terminal action.
|
| 409 |
+
onSaved(msg);
|
| 410 |
+
return;
|
| 411 |
+
}
|
| 412 |
+
const body = toPutBody(payload, draft);
|
| 413 |
+
const r = await putUserPerms(username, body);
|
| 414 |
+
setBusy(false);
|
| 415 |
+
setAsk(null);
|
| 416 |
+
if (r.ok) {
|
| 417 |
+
setSaved(body.perms);
|
| 418 |
+
const msg = accountDirty
|
| 419 |
+
? `Saved ${username} and their access.`
|
| 420 |
+
: `Saved access for ${username}.`;
|
| 421 |
+
setSaid(msg);
|
| 422 |
+
// β W37-T05 β the second argument = TAKE THE ADMIN BACK TO THE LIST. Only this write passes
|
| 423 |
+
// it, and that is the whole reconciliation with wave 17's R7: that ruling removed the return
|
| 424 |
+
// BECAUSE "a page with several things to save should not eject you after the first". It was
|
| 425 |
+
// right, and it stays right β `applyAccount` below still leaves you where you are. What
|
| 426 |
+
// changed is that the owner named THIS save, which is the page's terminal action: with the
|
| 427 |
+
// account and the access committed together there is nothing else on the pane to do.
|
| 428 |
+
onSaved(msg, true);
|
| 429 |
+
} else {
|
| 430 |
+
setError(r.message);
|
| 431 |
+
}
|
| 432 |
+
}, [payload, draft, username, onSaved, accountDirty, name, role]);
|
| 433 |
|
| 434 |
/** The account half's write. β THE PATCH STILL CARRIES NO `bus` (R1), and
|
| 435 |
* that is load-bearing rather than tidy: with the picker gone this form
|
|
|
|
| 454 |
[username, onSaved]
|
| 455 |
);
|
| 456 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 457 |
/**
|
| 458 |
* β W40-T14 β WHO THIS PAGE IS ABOUT, plus whatever just happened, held ONCE. Both returns
|
| 459 |
* below render it: the account page and the per-database room are the same room with a
|
|
|
|
| 687 |
access rule set below.
|
| 688 |
</p>
|
| 689 |
) : null}
|
| 690 |
+
{/* ββ W47-T19 (owner instruction 11) β THIS CARD HAS NO BUTTONS OF ITS OWN ANY MORE.
|
| 691 |
+
"Save account" and "Deactivate account" moved to the one action bar at the bottom of
|
| 692 |
+
the page, which is where the owner asked for every button on this pane to live. The
|
| 693 |
+
card is now what it describes: the account's fields. The password control below stays
|
| 694 |
+
HERE on purpose and is not part of that merge β it is a one-shot field with its own
|
| 695 |
+
immediate consequence, not a pending edit the bottom bar could commit. */}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 696 |
|
| 697 |
{/* ββ W40-T15 (owner instruction 9) β ONE DELIBERATE GROUP, READ TOP TO BOTTOM. Owner,
|
| 698 |
verbatim: *"move the 'This signs <email> out everywhere immediately.' notice one line
|
|
|
|
| 803 |
</p>
|
| 804 |
) : null}
|
| 805 |
|
| 806 |
+
{/* ββ W47-T19 (owner instruction 11) β THE SECOND SAVE IS GONE FROM THIS HEADING, AND
|
| 807 |
+
SO IS THE COPY DOOR. Owner, verbatim: *"We have two 'Save access' under Manage User,
|
| 808 |
+
one in the middle of the navigation and one at the bottom. Delete the one in the
|
| 809 |
+
middle."* W40-T15 offered the same command at both ends of the section on purpose;
|
| 810 |
+
the owner has now read that as one button too many, and the bottom bar is where every
|
| 811 |
+
button on this pane lives.
|
| 812 |
+
β THE `.set-perm-sectend` WRAPPER WENT WITH THEM. It existed only to keep those two
|
| 813 |
+
trailing controls to ONE flex child of `.set-perm-sect` (which is `space-between` and
|
| 814 |
+
lives in index.css, not this lane's file); with nothing to group it would be an empty
|
| 815 |
+
span holding a heading away from an edge.
|
| 816 |
+
β `role="group"` STAYS, and its reason narrowed rather than expired: the section is
|
| 817 |
+
still one named region, named by its own heading through `aria-labelledby` so there is
|
| 818 |
+
one copy of the word "Access" and it cannot drift. */}
|
| 819 |
<div role="group" aria-labelledby="set-access-h">
|
| 820 |
<div className="set-perm-sect">
|
| 821 |
<h4 className="set-h4" id="set-access-h">Access</h4>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 822 |
</div>
|
| 823 |
|
| 824 |
{/* β W40-T14 β WHAT THIS ACCOUNT CAN SEE, and nothing else. `DESIGN.md` Β§4 "never
|
|
|
|
| 828 |
reader cannot get by looking. */}
|
| 829 |
<p className="set-help set-perm-intro">{accessSummary(payload, draft)}.</p>
|
| 830 |
|
| 831 |
+
{/* β W47-T19 β the "copying is unavailable while there are unsaved changes" line went
|
| 832 |
+
with the copy door it explained. A sentence about a control the page no longer
|
| 833 |
+
offers is worse than no sentence. */}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 834 |
|
| 835 |
{/* ββ W40-T15 (owner instruction 8) β TWO ROOMS, AND NEITHER OF THEM IS EMPTY.
|
| 836 |
β A GROUP WITH NO MEMBERS RENDERS NO HEADING, which is the whole reason this is a
|
|
|
|
| 860 |
</>
|
| 861 |
)}
|
| 862 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 863 |
</div>
|
| 864 |
</>
|
| 865 |
) : null}
|
| 866 |
|
| 867 |
+
{/* ββ W47-T19 (owner instruction 11) β ONE BAR, AT THE BOTTOM, FOR EVERY BUTTON ON THIS
|
| 868 |
+
PAGE. Owner, verbatim: *"we should merge 'Save access' and 'Save account' and move those
|
| 869 |
+
buttons at the bottom of the navigation. Deactivate this account and apply access to
|
| 870 |
+
button should live at the bottom of the navigation too."* Three action groups became
|
| 871 |
+
this one: the Account card's pair, the mid-section save, and the old bottom row.
|
| 872 |
+
|
| 873 |
+
β IT SITS OUTSIDE THE `{payload ? β¦ : null}` BLOCK, AND THAT IS NOT A LAYOUT DETAIL. The
|
| 874 |
+
account half of this page is served by the `AdminUser` the accounts list already holds
|
| 875 |
+
and renders before the permission GET answers (wave 17 R7); the access half does not.
|
| 876 |
+
Put this bar inside the payload gate and a failing or slow perms read would take
|
| 877 |
+
Deactivate away with it β the one control an admin reaches for when an account is
|
| 878 |
+
misbehaving, and R7 deleted the other door to it. `save()` handles the same case on the
|
| 879 |
+
write side by skipping the access half when there is no record to build a PUT from.
|
| 880 |
+
|
| 881 |
+
β THE ORDER IS THE OWNER'S: the primary first, then the account-level action, then the
|
| 882 |
+
way out, then what is outstanding. */}
|
| 883 |
+
<div className="set-actions set-perm-actions">
|
| 884 |
+
<button
|
| 885 |
+
type="button"
|
| 886 |
+
className="set-primary"
|
| 887 |
+
disabled={busy || !anyDirty}
|
| 888 |
+
title="Saves the account details and the access rules together."
|
| 889 |
+
onClick={() => setAsk({ kind: "save" })}
|
| 890 |
+
>
|
| 891 |
+
<Busy busy={busy} idle={saveLabel} doing="Saving" />
|
| 892 |
+
</button>
|
| 893 |
+
{/* β NOT PART OF THE MERGE, AND DELIBERATELY STILL ITS OWN WRITE. Deactivating is not a
|
| 894 |
+
pending edit sitting in a form: it is an immediate, reversible switch on the account,
|
| 895 |
+
so it keeps `applyAccount` and leaves the admin where they are. Merging it into the
|
| 896 |
+
Save would mean a role change and a deactivation could only ever ship together. */}
|
| 897 |
+
<button
|
| 898 |
+
type="button"
|
| 899 |
+
className="set-secondary"
|
| 900 |
+
disabled={busy}
|
| 901 |
+
onClick={() =>
|
| 902 |
+
applyAccount(
|
| 903 |
+
{ active: !user.active },
|
| 904 |
+
`${user.active ? "Deactivated" : "Reactivated"} ${username}.`
|
| 905 |
+
)
|
| 906 |
+
}
|
| 907 |
+
>
|
| 908 |
+
<Busy busy={busy} idle={user.active ? "Deactivate account" : "Reactivate account"}
|
| 909 |
+
doing={user.active ? "Deactivating" : "Reactivating"} />
|
| 910 |
+
</button>
|
| 911 |
+
<button type="button" className="set-secondary" disabled={busy} onClick={goBack}>
|
| 912 |
+
Cancel
|
| 913 |
+
</button>
|
| 914 |
+
{anyDirty ? <span className="set-help set-perm-dirty">Unsaved changes</span> : null}
|
| 915 |
+
</div>
|
| 916 |
+
|
| 917 |
{ask ? (
|
| 918 |
<div className="set-confirm-wrap">
|
| 919 |
<div
|
|
|
|
| 921 |
className="set-confirm"
|
| 922 |
role="alertdialog"
|
| 923 |
aria-modal="true"
|
| 924 |
+
aria-label={ask.kind === "save" ? "Confirm these changes" : "Discard changes"}
|
| 925 |
>
|
| 926 |
{ask.kind === "save" ? (
|
| 927 |
<>
|
| 928 |
+
{/* β W47-T19 β THE QUESTION COVERS BOTH HALVES NOW, and it names which ones are
|
| 929 |
+
in the write through the same `unsavedWords` the discard question uses. One
|
| 930 |
+
Save commits the account form and the access rules together, so a confirm
|
| 931 |
+
that only asked about access would be understating what the click does. */}
|
| 932 |
+
<h4 className="set-h4">Save these changes for {displayName}?</h4>
|
| 933 |
<p className="set-help">
|
| 934 |
+
{unsavedWords(dirty, accountDirty)} are written now, and a change to access takes
|
| 935 |
+
effect the next time they load a page. {accessSummaryLine(payload, draft)}
|
| 936 |
</p>
|
| 937 |
</>
|
| 938 |
) : (
|
|
|
|
| 947 |
</>
|
| 948 |
)}
|
| 949 |
<div className="set-actions">
|
| 950 |
+
{/* β W47-T19 β THREE BRANCH-OWNED BUTTONS RATHER THAN ONE BUTTON WITH THREE
|
| 951 |
+
TERNARIES INSIDE IT. Each branch renders the whole control, so the label, the
|
| 952 |
+
in-flight words and the handler travel together and a reader sees one complete
|
| 953 |
+
button per answer. The save branches read `saveLabel`, so this dialog says
|
| 954 |
+
exactly what the bar behind it said.
|
| 955 |
+
β AND IT IS WHAT KEEPS `verify_ui.py`'s NC t05-bare ABLE TO FIRE: that control
|
| 956 |
+
strips the `<Busy>` element off the "Save access" spelling and requires the check
|
| 957 |
+
to go red. Fold these back into one `<button>` and the surviving `<Busy>` in the
|
| 958 |
+
other branch hides the stripped one from the check, which then passes over a bare
|
| 959 |
+
label and the negative control silently tests nothing. */}
|
| 960 |
+
{ask.kind !== "save" ? (
|
| 961 |
+
<button
|
| 962 |
+
type="button"
|
| 963 |
+
className="set-primary"
|
| 964 |
+
disabled={busy}
|
| 965 |
+
onClick={() => {
|
| 966 |
+
setAsk(null);
|
| 967 |
+
onBack();
|
| 968 |
+
}}
|
| 969 |
+
>
|
| 970 |
+
<Busy busy={busy} idle="Discard" doing="Discarding" />
|
| 971 |
+
</button>
|
| 972 |
+
) : saveLabel === "Save access" ? (
|
| 973 |
+
<button
|
| 974 |
+
type="button"
|
| 975 |
+
className="set-primary"
|
| 976 |
+
disabled={busy}
|
| 977 |
+
onClick={() => void save()}
|
| 978 |
+
>
|
| 979 |
+
<Busy busy={busy} idle="Save access" doing="Saving" />
|
| 980 |
+
</button>
|
| 981 |
+
) : (
|
| 982 |
+
<button
|
| 983 |
+
type="button"
|
| 984 |
+
className="set-primary"
|
| 985 |
+
disabled={busy}
|
| 986 |
+
onClick={() => void save()}
|
| 987 |
+
>
|
| 988 |
+
<Busy busy={busy} idle="Save account" doing="Saving" />
|
| 989 |
+
</button>
|
| 990 |
+
)}
|
| 991 |
<button
|
| 992 |
type="button"
|
| 993 |
className="set-secondary"
|
|
|
|
| 1000 |
</div>
|
| 1001 |
</div>
|
| 1002 |
) : null}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1003 |
</div>
|
| 1004 |
);
|
| 1005 |
}
|
web/src/settings/SettingsModal.tsx
CHANGED
|
@@ -154,7 +154,8 @@ const IconDatabase = (
|
|
| 154 |
<path d="M2.9 8c0 1.2 2.3 2.2 5.1 2.2s5.1-1 5.1-2.2" />
|
| 155 |
</RailIcon>
|
| 156 |
);
|
| 157 |
-
/** Manage
|
|
|
|
| 158 |
* principal here is a CHANNEL, and a rail that draws it as a user invites the
|
| 159 |
* per-person reading the pane's first sentence exists to correct. A speech
|
| 160 |
* bubble with a machine mark inside it, in the same stroke weight as the rest. */
|
|
@@ -791,7 +792,12 @@ export function SettingsModal({
|
|
| 791 |
// module called 'Manage agent' which should be under 'Manage user'"*.
|
| 792 |
// Immediately after `users`, so "under" is literal in the rail rather
|
| 793 |
// than a tab hidden inside the other room.
|
| 794 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 795 |
// Wave 18 (C7): the tenant's credential store + data-source status board.
|
| 796 |
["keychains", "Keychains", IconKey],
|
| 797 |
["connectors", "Connectors", IconPlug],
|
|
|
|
| 154 |
<path d="M2.9 8c0 1.2 2.3 2.2 5.1 2.2s5.1-1 5.1-2.2" />
|
| 155 |
</RailIcon>
|
| 156 |
);
|
| 157 |
+
/** Manage slack (labelled "Manage agent" until wave 47) β a channel bot.
|
| 158 |
+
* Deliberately NOT a second person glyph: the
|
| 159 |
* principal here is a CHANNEL, and a rail that draws it as a user invites the
|
| 160 |
* per-person reading the pane's first sentence exists to correct. A speech
|
| 161 |
* bubble with a machine mark inside it, in the same stroke weight as the rest. */
|
|
|
|
| 792 |
// module called 'Manage agent' which should be under 'Manage user'"*.
|
| 793 |
// Immediately after `users`, so "under" is literal in the rail rather
|
| 794 |
// than a tab hidden inside the other room.
|
| 795 |
+
// β WAVE 47, owner instruction 6 β RELABELLED, verbatim: *"Let's change
|
| 796 |
+
// the naming of Manage agent under setting to Manage slack"*. The wave-33
|
| 797 |
+
// wording above is left as written because it is the owner's original
|
| 798 |
+
// quotation. Only the rendered LABEL moved; the tab id stays `agents`,
|
| 799 |
+
// which `routes_slack.py`, `permsModel.ts` and every deep link name.
|
| 800 |
+
["agents", "Manage slack", IconAgent],
|
| 801 |
// Wave 18 (C7): the tenant's credential store + data-source status board.
|
| 802 |
["keychains", "Keychains", IconKey],
|
| 803 |
["connectors", "Connectors", IconPlug],
|
web/src/shell/NavExtras.tsx
CHANGED
|
@@ -500,14 +500,33 @@ function PlusIcon() {
|
|
| 500 |
* database, and R9 keeps the template door working here (see the Home card's own note
|
| 501 |
* on why exactly one of the two template doors is boarded).
|
| 502 |
*
|
| 503 |
-
* β
|
| 504 |
-
*
|
| 505 |
-
* 13.8125px / w500 / Inter /
|
| 506 |
-
*
|
| 507 |
-
*
|
| 508 |
-
* `--lp-muted`. Taking
|
| 509 |
-
*
|
| 510 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 511 |
*
|
| 512 |
* β THE `canFolder` GATE SURVIVES THE MOVE, and it has to. Wave 19's note: folders
|
| 513 |
* over an empty list are an empty gesture, but a freshly provisioned tenant must
|
|
@@ -579,13 +598,28 @@ export function CreateNewRow({
|
|
| 579 |
genuine choice, which is the property the label depends on. If a future
|
| 580 |
ruling takes the template row as well, this reasoning inverts and the
|
| 581 |
control has to become a plain button again. */}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 582 |
<button
|
| 583 |
type="button"
|
| 584 |
-
className="
|
| 585 |
aria-haspopup="menu"
|
|
|
|
| 586 |
onClick={(e) => openFrom(e.currentTarget)}
|
| 587 |
>
|
| 588 |
-
|
|
|
|
| 589 |
</button>
|
| 590 |
{at && (
|
| 591 |
<MenuShell at={at} menuRef={ref}>
|
|
|
|
| 500 |
* database, and R9 keeps the template door working here (see the Home card's own note
|
| 501 |
* on why exactly one of the two template doors is boarded).
|
| 502 |
*
|
| 503 |
+
* β WAVE 14's item 1 WAS ALSO A TYPOGRAPHY FIX, and it is worth keeping the
|
| 504 |
+
* measurement because wave 47 finished the job from the other end. MEASURED on
|
| 505 |
+
* staging v12: the six rail rows all rendered 13.8125px / w500 / Inter /
|
| 506 |
+
* rgb(32,36,51) β identical, `<a>` and `<button>` alike. The ONE row in that band
|
| 507 |
+
* that differed was this one, because `.shell-newfolder` declares `--lp-fs-2xs`
|
| 508 |
+
* (12.75px) with no `font-weight` (so 400, inherited) and `--lp-muted`. Taking the
|
| 509 |
+
* row OUT of the rail is what made that band read as one set.
|
| 510 |
+
*
|
| 511 |
+
* ββ WAVE 47 T10 (owner instruction 1) β THE EXPANDED ROW NO LONGER WEARS
|
| 512 |
+
* `.shell-newfolder` AT ALL, so do not read the paragraph above as a description of
|
| 513 |
+
* this button's current register. Once W46-T04 mounted this control inside the views
|
| 514 |
+
* rail's `.cg-data-create`, the person walking from a database into a folder path saw
|
| 515 |
+
* the SAME door twice in two different treatments: `.shell-newfolder`'s 12.75px /
|
| 516 |
+
* muted here, `.cg-create-btn`'s `--lp-fs-xs` / `--lp-ink` / w400 one level down. The
|
| 517 |
+
* owner named the second one as the keeper, so the expanded branch now renders
|
| 518 |
+
* `cg-link-btn cg-create-btn` with the same icon/label spans `ViewSidebar.tsx` uses.
|
| 519 |
+
* β `.shell-newfolder` SURVIVES IN `navExtras.css` AND IS STILL READ HERE, by the
|
| 520 |
+
* COLLAPSED branch alone: `is-collapsed` is a modifier that supplies only the grid
|
| 521 |
+
* centring and leans on the base rule for the reset, the radius and the hover. It is
|
| 522 |
+
* not dead CSS and a sweep must not take it.
|
| 523 |
+
* β `.shell-newfolder-form` is a SEPARATE selector, not a modifier of that base β the
|
| 524 |
+
* naming form wears `shell-navmenu-form shell-newfolder-form` and never wore
|
| 525 |
+
* `.shell-newfolder`. Reading the two as one rule is how a sweep deletes the wrong one.
|
| 526 |
+
* β RESIDUAL, and it is deliberate rather than missed: the view layer's wrapper
|
| 527 |
+
* `.cg-create-new` adds `padding: 2px 2px 0` that `.cg-data-create` does not carry, so
|
| 528 |
+
* the two doors still sit 2px apart horizontally. Closing it needs a CSS edit this
|
| 529 |
+
* ticket did not own; both wrappers already share `margin-top: 8px`.
|
| 530 |
*
|
| 531 |
* β THE `canFolder` GATE SURVIVES THE MOVE, and it has to. Wave 19's note: folders
|
| 532 |
* over an empty list are an empty gesture, but a freshly provisioned tenant must
|
|
|
|
| 598 |
genuine choice, which is the property the label depends on. If a future
|
| 599 |
ruling takes the template row as well, this reasoning inverts and the
|
| 600 |
control has to become a plain button again. */}
|
| 601 |
+
{/* β WAVE 47 T10 (owner instruction 1) β THIS ROW WEARS THE VIEW LAYER'S REGISTER,
|
| 602 |
+
not its own. Owner, verbatim: *"The '+ Create new...' format for the Database and
|
| 603 |
+
when we get to the folder path in the database is different visually. I like the one
|
| 604 |
+
that is formatted under the database, with the lighter color, fix it so it visually
|
| 605 |
+
doesn't jump"*.
|
| 606 |
+
`cg-link-btn cg-create-btn` + the `cg-create-icon` / `cg-create-label` spans are
|
| 607 |
+
LITERALLY the markup `ViewSidebar.tsx`'s own create door renders, and `index.css` is
|
| 608 |
+
the app-global sheet, so this is one class set read by two call sites rather than two
|
| 609 |
+
class sets kept in step by hand. That second shape is what drifted: see the register
|
| 610 |
+
comparison in this component's own doc block.
|
| 611 |
+
β `aria-expanded` is not decoration here. `.cg-create-btn[aria-expanded="true"]`
|
| 612 |
+
is what paints the HELD state while the menu is open, so the visual state is driven
|
| 613 |
+
off the accessible one and there is no second source of truth to forget. */}
|
| 614 |
<button
|
| 615 |
type="button"
|
| 616 |
+
className="cg-link-btn cg-create-btn"
|
| 617 |
aria-haspopup="menu"
|
| 618 |
+
aria-expanded={!!at}
|
| 619 |
onClick={(e) => openFrom(e.currentTarget)}
|
| 620 |
>
|
| 621 |
+
<span className="cg-create-icon" aria-hidden="true">+</span>
|
| 622 |
+
<span className="cg-create-label">Create newβ¦</span>
|
| 623 |
</button>
|
| 624 |
{at && (
|
| 625 |
<MenuShell at={at} menuRef={ref}>
|
web/src/styles/wave45/data-applications.css
CHANGED
|
@@ -1,152 +1,157 @@
|
|
| 1 |
-
/* Wave 45 Data, Map, Application, Fields, and Export surfaces.
|
| 2 |
-
This sheet consumes the root token dialect and is imported by CustomerGrid so lane D does not
|
| 3 |
-
create another global token seam. */
|
| 4 |
-
|
| 5 |
-
.cg-map-settings > .cg-map-route-toggle {
|
| 6 |
-
display: inline-flex;
|
| 7 |
-
align-items: center;
|
| 8 |
-
gap: 6px;
|
| 9 |
-
}
|
| 10 |
-
|
| 11 |
-
.cg-map-settings > .cg-map-route-toggle svg {
|
| 12 |
-
flex: 0 0 auto;
|
| 13 |
-
}
|
| 14 |
-
|
| 15 |
-
.cg-mapview > .cg-map-bar > .cg-route-popover.cg-route-nav-panel {
|
| 16 |
-
inset: 0 0 0 auto;
|
| 17 |
-
width: min(
|
| 18 |
-
border-left: 1px solid var(--lp-line);
|
| 19 |
-
border-right: 0;
|
| 20 |
-
border-radius: 0;
|
| 21 |
-
background: var(--lp-surface);
|
| 22 |
-
color: var(--lp-ink);
|
| 23 |
-
z-index: var(--cg-z-mapchrome);
|
| 24 |
-
}
|
| 25 |
-
|
| 26 |
-
.cg-map-navigator-tabs {
|
| 27 |
-
display: grid;
|
| 28 |
-
grid-template-columns: 1fr 1fr;
|
| 29 |
-
gap: 4px;
|
| 30 |
-
margin-bottom: 8px;
|
| 31 |
-
padding: 3px;
|
| 32 |
-
border: 1px solid var(--lp-line);
|
| 33 |
-
border-radius: var(--lp-r-sm);
|
| 34 |
-
background: var(--lp-surface-2);
|
| 35 |
-
}
|
| 36 |
-
|
| 37 |
-
.cg-map-navigator-tabs > button,
|
| 38 |
-
.cg-zone-shape-picker button {
|
| 39 |
-
border: 0;
|
| 40 |
-
background: transparent;
|
| 41 |
-
font: inherit;
|
| 42 |
-
color: inherit;
|
| 43 |
-
min-height: 32px;
|
| 44 |
-
border-radius: var(--lp-r-sm);
|
| 45 |
-
cursor: pointer;
|
| 46 |
-
}
|
| 47 |
-
|
| 48 |
-
.cg-map-navigator-tabs > button[aria-selected="true"],
|
| 49 |
-
.cg-zone-shape-picker button[aria-pressed="true"] {
|
| 50 |
-
background: var(--lp-primary-tint);
|
| 51 |
-
color: var(--lp-primary);
|
| 52 |
-
font-weight: 600;
|
| 53 |
-
}
|
| 54 |
-
|
| 55 |
-
.cg-map-navigator-tabs > button:focus-visible,
|
| 56 |
-
.cg-zone-shape-picker button:focus-visible {
|
| 57 |
-
outline: 2px solid var(--lp-blue-deep);
|
| 58 |
-
outline-offset: 2px;
|
| 59 |
-
}
|
| 60 |
-
|
| 61 |
-
.cg-map-zone-option {
|
| 62 |
-
min-height: 42px;
|
| 63 |
-
}
|
| 64 |
-
|
| 65 |
-
.cg-map-zone-edit {
|
| 66 |
-
border: 0;
|
| 67 |
-
background: transparent;
|
| 68 |
-
font: inherit;
|
| 69 |
-
color: var(--lp-blue-deep);
|
| 70 |
-
cursor: pointer;
|
| 71 |
-
}
|
| 72 |
-
|
| 73 |
-
.cg-map-zone-edit:focus-visible {
|
| 74 |
-
outline: 2px solid var(--lp-blue-deep);
|
| 75 |
-
outline-offset: 2px;
|
| 76 |
-
}
|
| 77 |
-
|
| 78 |
-
.cg-zone-shape-picker {
|
| 79 |
-
display: grid;
|
| 80 |
-
gap: 6px;
|
| 81 |
-
margin: 0;
|
| 82 |
-
padding: 0;
|
| 83 |
-
border: 0;
|
| 84 |
-
}
|
| 85 |
-
|
| 86 |
-
.cg-zone-shape-picker legend {
|
| 87 |
-
padding: 0;
|
| 88 |
-
font-size: var(--lp-fs-xs);
|
| 89 |
-
font-weight: 600;
|
| 90 |
-
}
|
| 91 |
-
|
| 92 |
-
.cg-zone-shape-picker > div {
|
| 93 |
-
display: grid;
|
| 94 |
-
grid-template-columns: 1fr 1fr;
|
| 95 |
-
gap: 4px;
|
| 96 |
-
padding: 3px;
|
| 97 |
-
border: 1px solid var(--lp-line);
|
| 98 |
-
border-radius: var(--lp-r-sm);
|
| 99 |
-
background: var(--lp-surface-2);
|
| 100 |
-
}
|
| 101 |
-
|
| 102 |
-
.cg-zone-shape-picker > span {
|
| 103 |
-
color: var(--lp-muted);
|
| 104 |
-
font-size: var(--lp-fs-2xs);
|
| 105 |
-
}
|
| 106 |
-
|
| 107 |
-
.cg-map-zone {
|
| 108 |
-
fill-opacity
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
.cg-map-zone
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
.cg-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
.cg-
|
| 134 |
-
.cg-
|
| 135 |
-
.cg-
|
| 136 |
-
.cg-
|
| 137 |
-
.cg-
|
| 138 |
-
.cg-
|
| 139 |
-
.cg-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
/*
|
| 147 |
-
.
|
| 148 |
-
.
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
.cg-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Wave 45 Data, Map, Application, Fields, and Export surfaces.
|
| 2 |
+
This sheet consumes the root token dialect and is imported by CustomerGrid so lane D does not
|
| 3 |
+
create another global token seam. */
|
| 4 |
+
|
| 5 |
+
.cg-map-settings > .cg-map-route-toggle {
|
| 6 |
+
display: inline-flex;
|
| 7 |
+
align-items: center;
|
| 8 |
+
gap: 6px;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
.cg-map-settings > .cg-map-route-toggle svg {
|
| 12 |
+
flex: 0 0 auto;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
.cg-mapview > .cg-map-bar > .cg-route-popover.cg-route-nav-panel {
|
| 16 |
+
inset: 0 0 0 auto;
|
| 17 |
+
width: min(440px, 100%);
|
| 18 |
+
border-left: 1px solid var(--lp-line);
|
| 19 |
+
border-right: 0;
|
| 20 |
+
border-radius: 0;
|
| 21 |
+
background: var(--lp-surface);
|
| 22 |
+
color: var(--lp-ink);
|
| 23 |
+
z-index: var(--cg-z-mapchrome);
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
.cg-map-navigator-tabs {
|
| 27 |
+
display: grid;
|
| 28 |
+
grid-template-columns: 1fr 1fr;
|
| 29 |
+
gap: 4px;
|
| 30 |
+
margin-bottom: 8px;
|
| 31 |
+
padding: 3px;
|
| 32 |
+
border: 1px solid var(--lp-line);
|
| 33 |
+
border-radius: var(--lp-r-sm);
|
| 34 |
+
background: var(--lp-surface-2);
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.cg-map-navigator-tabs > button,
|
| 38 |
+
.cg-zone-shape-picker button {
|
| 39 |
+
border: 0;
|
| 40 |
+
background: transparent;
|
| 41 |
+
font: inherit;
|
| 42 |
+
color: inherit;
|
| 43 |
+
min-height: 32px;
|
| 44 |
+
border-radius: var(--lp-r-sm);
|
| 45 |
+
cursor: pointer;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.cg-map-navigator-tabs > button[aria-selected="true"],
|
| 49 |
+
.cg-zone-shape-picker button[aria-pressed="true"] {
|
| 50 |
+
background: var(--lp-primary-tint);
|
| 51 |
+
color: var(--lp-primary);
|
| 52 |
+
font-weight: 600;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
.cg-map-navigator-tabs > button:focus-visible,
|
| 56 |
+
.cg-zone-shape-picker button:focus-visible {
|
| 57 |
+
outline: 2px solid var(--lp-blue-deep);
|
| 58 |
+
outline-offset: 2px;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
.cg-map-zone-option {
|
| 62 |
+
min-height: 42px;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
.cg-map-zone-edit {
|
| 66 |
+
border: 0;
|
| 67 |
+
background: transparent;
|
| 68 |
+
font: inherit;
|
| 69 |
+
color: var(--lp-blue-deep);
|
| 70 |
+
cursor: pointer;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
.cg-map-zone-edit:focus-visible {
|
| 74 |
+
outline: 2px solid var(--lp-blue-deep);
|
| 75 |
+
outline-offset: 2px;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
.cg-zone-shape-picker {
|
| 79 |
+
display: grid;
|
| 80 |
+
gap: 6px;
|
| 81 |
+
margin: 0;
|
| 82 |
+
padding: 0;
|
| 83 |
+
border: 0;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
.cg-zone-shape-picker legend {
|
| 87 |
+
padding: 0;
|
| 88 |
+
font-size: var(--lp-fs-xs);
|
| 89 |
+
font-weight: 600;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
.cg-zone-shape-picker > div {
|
| 93 |
+
display: grid;
|
| 94 |
+
grid-template-columns: 1fr 1fr;
|
| 95 |
+
gap: 4px;
|
| 96 |
+
padding: 3px;
|
| 97 |
+
border: 1px solid var(--lp-line);
|
| 98 |
+
border-radius: var(--lp-r-sm);
|
| 99 |
+
background: var(--lp-surface-2);
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
.cg-zone-shape-picker > span {
|
| 103 |
+
color: var(--lp-muted);
|
| 104 |
+
font-size: var(--lp-fs-2xs);
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
.cg-map-zone {
|
| 108 |
+
/* β `fill-opacity` DELETED by W47-T01 (contract C1). It was the wave-45 value 0.18, already
|
| 109 |
+
losing to `.cg-map-svg .cg-map-zone` in `styles/wave46/map-panels.css` on specificity
|
| 110 |
+
(0,2,0 against 0,1,0). Left in place it was a landmine: any future import-order or selector
|
| 111 |
+
shuffle would have restored a third opinion about one number. `stroke-opacity` here is
|
| 112 |
+
likewise superseded by that rule's flat 1 and is kept only as the pre-map fallback for a
|
| 113 |
+
`.cg-map-zone` rendered outside `.cg-map-svg`. */
|
| 114 |
+
stroke-opacity: 0.9;
|
| 115 |
+
cursor: grab;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
.cg-map-zone:active {
|
| 119 |
+
cursor: grabbing;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
@media (max-width: 1000px) {
|
| 123 |
+
.cg-mapview > .cg-map-bar > .cg-route-popover.cg-route-nav-panel {
|
| 124 |
+
width: min(420px, calc(100% - 48px));
|
| 125 |
+
}
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
@media (prefers-reduced-motion: reduce) {
|
| 129 |
+
.cg-mapview > .cg-map-bar > .cg-route-popover.cg-route-nav-panel {
|
| 130 |
+
transition: none;
|
| 131 |
+
}
|
| 132 |
+
}
|
| 133 |
+
.cg-date-boundary { display:grid; gap:6px; padding:10px 12px; font-size:var(--lp-fs-2xs); color:var(--lp-ink-muted); border-bottom:1px solid var(--lp-line); }
|
| 134 |
+
.cg-date-boundary .cg-input,.cg-date-boundary .cg-select { width:100%; box-sizing:border-box; }
|
| 135 |
+
.cg-top-n { display:flex; align-items:center; gap:10px; margin:0 0 10px; padding:8px 0; border:0; border-bottom:1px solid var(--lp-line); }
|
| 136 |
+
.cg-top-n legend { font-size:var(--lp-fs-3xs); font-weight:650; color:var(--lp-ink-muted); }
|
| 137 |
+
.cg-top-n label { display:flex; align-items:center; gap:4px; white-space:nowrap; }
|
| 138 |
+
.cg-top-n .cg-input { width:62px; }
|
| 139 |
+
.cg-drawer-launchers { position:absolute; z-index:3; right:12px; top:7px; display:flex; gap:6px; }
|
| 140 |
+
.cg-workspace-drawer { position:absolute; z-index:30; top:0; right:0; bottom:0; width:min(360px,42vw); padding:16px; box-sizing:border-box; overflow:auto; background:var(--lp-surface); border-left:1px solid var(--lp-line); box-shadow:-12px 0 30px rgb(34 25 74 / 12%); }
|
| 141 |
+
.cg-workspace-drawer header { display:flex; align-items:center; justify-content:space-between; margin-bottom:16px; }
|
| 142 |
+
.cg-workspace-drawer textarea { width:100%; min-height:220px; box-sizing:border-box; resize:vertical; margin-bottom:10px; }
|
| 143 |
+
.cg-history-list { display:grid; gap:8px; padding:0; list-style:none; }
|
| 144 |
+
.cg-history-list li { display:grid; grid-template-columns:1fr auto; gap:4px 10px; padding:10px; border:1px solid var(--lp-line); border-radius:8px; }
|
| 145 |
+
@media (max-width:1050px) { .cg-workspace-drawer { width:min(330px,48vw); } .cg-drawer-launchers .cg-btn { padding-inline:8px; } }
|
| 146 |
+
/* D-602 / W46-T10 (wave 46 hotfix, 2026-08-30) - the Applications RAIL's six rules are
|
| 147 |
+
deleted here. The rail itself was removed in wave 46 and its stylesheet outlived it:
|
| 148 |
+
`.cg-application-rail`, `-context`, `-list`, `-card`, `-open` and `-actions` matched
|
| 149 |
+
nothing in `src/` and nothing on the deployed build (0 `.cg-application-rail` nodes,
|
| 150 |
+
0 "Applications" text nodes). The rest of this sheet is live and untouched. */
|
| 151 |
+
/* W45-T14/C6: one folder, one meaning. Legacy shape/tone metadata never changes this glyph. */
|
| 152 |
+
.cg-folder-mark path { fill:var(--lp-purple-deep); stroke:var(--lp-purple-deep); }
|
| 153 |
+
.home-app-glyph { background:var(--lp-primary); color:#fff; font-weight:700; }
|
| 154 |
+
.cg-semantic-profile { margin:10px 12px 0; padding:8px 10px; border:1px solid var(--lp-line); border-radius:8px; font-size:var(--lp-fs-3xs); }
|
| 155 |
+
.cg-semantic-row { display:grid; grid-template-columns:minmax(100px,1fr) minmax(130px,1.3fr); gap:4px 12px; padding:7px 0; border-top:1px solid var(--lp-line); }
|
| 156 |
+
.cg-redacted { color:var(--lp-ink-muted); font-style:italic; }
|
| 157 |
+
.cg-formula-help { max-width:340px; color:var(--lp-ink-muted); font-size:var(--lp-fs-3xs); }
|
web/src/styles/wave46/map-panels.css
CHANGED
|
@@ -73,12 +73,31 @@
|
|
| 73 |
display: flex;
|
| 74 |
align-items: baseline;
|
| 75 |
gap: 8px;
|
| 76 |
-
width: 100%;
|
| 77 |
min-width: 0;
|
| 78 |
-
/*
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
text-overflow: clip;
|
| 81 |
-
white-space:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
}
|
| 83 |
|
| 84 |
/* `tabular-nums` plus the floor width keeps every name starting on the same x once the route
|
|
@@ -115,11 +134,20 @@
|
|
| 115 |
every gate stays green ([[a-lane-stylesheet-cannot-override-index-css]]). `.cg-map-svg
|
| 116 |
.cg-map-zone` wins on SPECIFICITY (0,2,0 against 0,1,0), which no import order can undo. */
|
| 117 |
:root {
|
| 118 |
-
--lp-zone-fill: 0.
|
| 119 |
}
|
| 120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
.cg-map-svg .cg-map-zone {
|
| 122 |
fill-opacity: var(--lp-zone-fill);
|
|
|
|
| 123 |
}
|
| 124 |
|
| 125 |
/* A vertex handle. It sits INSIDE the camera transform with the boundary it belongs to, and
|
|
@@ -151,6 +179,58 @@
|
|
| 151 |
align-items: center;
|
| 152 |
}
|
| 153 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
/* == W46-T29: the map toolbar wears the toolbar's own chrome, and its panels open right ======
|
| 155 |
Owner instruction 29: *"The formatting for Routes and zones / Location / No size should be
|
| 156 |
extremely similar to Filter/sort/group etc. With the coloring when its on etc. and icons, and
|
|
@@ -201,6 +281,37 @@
|
|
| 201 |
transition: background 0.12s ease, color 0.12s ease;
|
| 202 |
}
|
| 203 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
.cg-map-settings > .cg-map-route-toggle svg,
|
| 205 |
.cg-map-settings > .cg-mode-field svg {
|
| 206 |
color: var(--lp-muted);
|
|
@@ -277,6 +388,33 @@
|
|
| 277 |
left: auto;
|
| 278 |
}
|
| 279 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
/* βββββββββββββββββββ W46-T19 / R9 / C2 β the route timer and the drag grip βββββββββββββββββββ
|
| 281 |
|
| 282 |
THE TIMER SITS ABOVE THE STOPS IT IS ABOUT, which is what makes it readable as a property of
|
|
@@ -473,3 +611,33 @@
|
|
| 473 |
flex: 1 1 auto;
|
| 474 |
min-width: 0;
|
| 475 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
display: flex;
|
| 74 |
align-items: baseline;
|
| 75 |
gap: 8px;
|
|
|
|
| 76 |
min-width: 0;
|
| 77 |
+
/* β W47-T04: the button GROWS to fill the line and never wraps. `width: 100%` was the other
|
| 78 |
+
half of the wrapping defect - at 100 percent of a flex row it pushed the action cluster out
|
| 79 |
+
of the line entirely.
|
| 80 |
+
β THE BASIS IS 0, NOT `auto`, AND THAT IS THE WHOLE FIX. With `flex-basis: auto` the button
|
| 81 |
+
asks for its CONTENT width, and because the row may wrap, the browser grants it and pushes
|
| 82 |
+
the action cluster onto a second line instead of shrinking the button. A basis of 0 makes the
|
| 83 |
+
button claim only the space left after the grip and the controls, which is what finally lets
|
| 84 |
+
the name span's own ellipsis engage. Truncation still lives on the name, so the ordinal is
|
| 85 |
+
never the part that is clipped. */
|
| 86 |
+
flex: 1 1 0;
|
| 87 |
+
overflow: hidden;
|
| 88 |
text-overflow: clip;
|
| 89 |
+
white-space: nowrap;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
/* The name is the only part that may shrink, and it must be allowed to hit zero for the
|
| 93 |
+
ellipsis to appear at all. */
|
| 94 |
+
.cg-w46-stop-name {
|
| 95 |
+
flex: 1 1 0;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
/* The per-stop validation message is the ONE thing allowed a second line. */
|
| 99 |
+
.cg-w44-route-order-error {
|
| 100 |
+
flex: 1 0 100%;
|
| 101 |
}
|
| 102 |
|
| 103 |
/* `tabular-nums` plus the floor width keeps every name starting on the same x once the route
|
|
|
|
| 134 |
every gate stays green ([[a-lane-stylesheet-cannot-override-index-css]]). `.cg-map-svg
|
| 135 |
.cg-map-zone` wins on SPECIFICITY (0,2,0 against 0,1,0), which no import order can undo. */
|
| 136 |
:root {
|
| 137 |
+
--lp-zone-fill: 0.1;
|
| 138 |
}
|
| 139 |
|
| 140 |
+
/* β W47-T01 (owner instruction 2). The FILL drops to 0.1 so the record dots read through a
|
| 141 |
+
Zone, and the legibility that buys back is paid at the BOUNDARY: `stroke-opacity` goes to a
|
| 142 |
+
flat 1 here, and the stroke WEIGHT is raised in the TS seam as `LP_ZONE_STROKE_WIDTH`.
|
| 143 |
+
β THE WEIGHT CANNOT LIVE IN THIS FILE. Zone outlines render inside `<g transform={tf}>`, so a
|
| 144 |
+
CSS `stroke-width` would be in user units and would thicken as the camera zooms; `hair()` in
|
| 145 |
+
`MapView.tsx` divides by the zoom to stop exactly that. A rule here WOULD win over the
|
| 146 |
+
presentation attribute, which is what makes writing one a silent regression rather than a
|
| 147 |
+
no-op. */
|
| 148 |
.cg-map-svg .cg-map-zone {
|
| 149 |
fill-opacity: var(--lp-zone-fill);
|
| 150 |
+
stroke-opacity: 1;
|
| 151 |
}
|
| 152 |
|
| 153 |
/* A vertex handle. It sits INSIDE the camera transform with the boundary it belongs to, and
|
|
|
|
| 179 |
align-items: center;
|
| 180 |
}
|
| 181 |
|
| 182 |
+
/* ββ W47-T03: a finished Zone that has not been saved is a STATE, and it now looks like one ββ
|
| 183 |
+
Owner instruction 20: *"When I click 'Finish zone' under the Zone navigation, the zone just
|
| 184 |
+
disappear. Only when I save the zone does it actually reappear. This is really bad UI, i was
|
| 185 |
+
really confused whether I have made the zone or not."* The boundary was reaching
|
| 186 |
+
`drawnZoneGeometry` and no render path at all, so finishing a shape deleted it from the screen.
|
| 187 |
+
|
| 188 |
+
β THE FILL IS HALF `--lp-zone-fill` AND THAT RATIO IS THE POINT. "Lighter than a saved Zone"
|
| 189 |
+
has to survive somebody retuning the saved value β which already happened once, when
|
| 190 |
+
instruction 16's *"i can't se eshit"* took `--lp-zone-fill` from 0.18 to 0.4. A second hand
|
| 191 |
+
picked number would have silently stopped being lighter that day, and W47-T01 then retuned it
|
| 192 |
+
AGAIN in the other direction (0.4 -> 0.1 for instruction 2), which this ratio absorbed. Declared here rather than in
|
| 193 |
+
`index.css :root` for the same reason its twin above is: contract C6, no lane edits index.css.
|
| 194 |
+
|
| 195 |
+
β NO `stroke-dasharray` HERE, ON PURPOSE. The dash is a component attribute driven by
|
| 196 |
+
`hair()`, because this group renders inside the camera transform where a user-unit dash grows
|
| 197 |
+
with the zoom, and the usual cure β `vector-effect: non-scaling-stroke` β is exactly what
|
| 198 |
+
`verify_map.py`'s `map-css-no-non-scaling-stroke` leg reds the build over. */
|
| 199 |
+
:root {
|
| 200 |
+
--lp-zone-fill-unsaved: 0.05;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
.cg-map-svg .cg-map-zone-unsaved {
|
| 204 |
+
fill-opacity: var(--lp-zone-fill-unsaved);
|
| 205 |
+
/* A preview of a boundary is never a target. The pins, the saved Zones and the map beneath it
|
| 206 |
+
keep every click, the same way `.cg-zone-keyboard-draft` gives back the clicks that built it. */
|
| 207 |
+
pointer-events: none;
|
| 208 |
+
/* It ARRIVES rather than blinking into existence: 160ms of opacity reads as the shape settling
|
| 209 |
+
where the user just drew it. Opacity only, inside DESIGN.md section 4's 100-200ms ease-out
|
| 210 |
+
window, and off entirely for anyone who has asked for less motion. */
|
| 211 |
+
animation: cg-zone-unsaved-in 160ms ease-out;
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
@keyframes cg-zone-unsaved-in {
|
| 215 |
+
from { opacity: 0; }
|
| 216 |
+
to { opacity: 1; }
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
@media (prefers-reduced-motion: reduce) {
|
| 220 |
+
.cg-map-svg .cg-map-zone-unsaved {
|
| 221 |
+
animation: none;
|
| 222 |
+
}
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
/* The sentence under the pair. A dashed outline says "provisional" to a designer; it says nothing
|
| 226 |
+
to somebody who has drawn one Zone in their life, and it says nothing at all to a screen reader
|
| 227 |
+
over an `aria-hidden` group. So the state is also written down, in the panel, as text. */
|
| 228 |
+
.cg-zone-unsaved-note {
|
| 229 |
+
color: var(--lp-muted);
|
| 230 |
+
font-size: var(--lp-fs-3xs);
|
| 231 |
+
line-height: 1.4;
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
/* == W46-T29: the map toolbar wears the toolbar's own chrome, and its panels open right ======
|
| 235 |
Owner instruction 29: *"The formatting for Routes and zones / Location / No size should be
|
| 236 |
extremely similar to Filter/sort/group etc. With the coloring when its on etc. and icons, and
|
|
|
|
| 281 |
transition: background 0.12s ease, color 0.12s ease;
|
| 282 |
}
|
| 283 |
|
| 284 |
+
/* β W47-T05 / R10 β THE MARK FOR Location AND No size, AND WHY IT IS A SIBLING.
|
| 285 |
+
`FieldSelectButton` has no trigger-level icon prop; its only icon path is `FieldSelectItem.icon`,
|
| 286 |
+
which marks LIST ROWS, not the control itself. Adding one belongs in
|
| 287 |
+
`customer-grid/FieldSelect.tsx`, and that file is in NO lane's FILE OWNERSHIP fence this wave.
|
| 288 |
+
β AND THE OBVIOUS ALTERNATIVE IS WORSE: wrapping the control in a span would stop it being a
|
| 289 |
+
DIRECT child of `.cg-map-settings`, which is how every rule above selects it, so the whole row
|
| 290 |
+
would silently lose its height, padding, border and hover. The mark therefore sits beside the
|
| 291 |
+
control and is pulled into its rhythm, which is the same icon-then-label shape
|
| 292 |
+
`.cg-map-route-toggle` already renders internally. */
|
| 293 |
+
.cg-map-settings > .cg-mode-field-mark {
|
| 294 |
+
display: inline-flex;
|
| 295 |
+
align-items: center;
|
| 296 |
+
/* β THE ROW'S OWN `gap: 6px` (index.css:1437) SITS ON BOTH SIDES OF THE MARK, so a mark with
|
| 297 |
+
no margins floats midway between two controls and reads as belonging to neither. -6px
|
| 298 |
+
cancels the gap on the control's side entirely and +4px widens it on the other, which is
|
| 299 |
+
what makes the pair read as ONE control rather than as an icon adrift. */
|
| 300 |
+
margin-right: -6px;
|
| 301 |
+
margin-left: 4px;
|
| 302 |
+
color: var(--lp-muted);
|
| 303 |
+
pointer-events: none;
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
.cg-map-settings > .cg-mode-field-mark + .cg-mode-field {
|
| 307 |
+
padding-left: 5px;
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
.cg-map-settings > .cg-mode-field-mark svg {
|
| 311 |
+
display: block;
|
| 312 |
+
flex: 0 0 auto;
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
.cg-map-settings > .cg-map-route-toggle svg,
|
| 316 |
.cg-map-settings > .cg-mode-field svg {
|
| 317 |
color: var(--lp-muted);
|
|
|
|
| 388 |
left: auto;
|
| 389 |
}
|
| 390 |
|
| 391 |
+
/* βββββββ W47-T01/T04 β THE PANEL WIDTH, AND WHY IT IS DECLARED HERE AT 0,4,1 βββββββββββββββ
|
| 392 |
+
Owner instruction 4: *"maybe we can increase the width of the whole route/zone navigation."*
|
| 393 |
+
|
| 394 |
+
β THE TICKET'S NAMED SEAM WAS ALREADY DEAD. `styles/wave45/data-applications.css` declares
|
| 395 |
+
`width: min(440px, 100%)` for this panel, and it does NOT win: `styles/wave42/route-nav.css`
|
| 396 |
+
declares `width: min(380px, 100%)` on the IDENTICAL selector and, being a later sheet in the
|
| 397 |
+
bundle (byte 54691 against 48802 in the built CSS), takes the tie on source order. Measured,
|
| 398 |
+
not assumed: the live panel computed to exactly 380px while the wave45 sheet said 440.
|
| 399 |
+
|
| 400 |
+
β SO THIS RULE REPEATS `.cg-route-popover` TO REACH 0,4,1 AND WIN ON SPECIFICITY INSTEAD OF
|
| 401 |
+
ORDER, the same defence `.cg-map-svg .cg-map-zone` uses against its own stale twin. An import
|
| 402 |
+
reorder cannot undo it.
|
| 403 |
+
|
| 404 |
+
β THIS IS A PATCH OVER A DUPLICATE, NOT A FIX OF ONE. `styles/wave42/route-nav.css` is in NO
|
| 405 |
+
lane's FILE OWNERSHIP fence this wave, so its 380px cannot be deleted from here. Three sheets
|
| 406 |
+
now hold an opinion about one width. Collapsing them to one is integrator work, and it is
|
| 407 |
+
recorded in lanes/A/LANE_CONTEXT.md rather than left for somebody to rediscover. */
|
| 408 |
+
.cg-mapview > .cg-map-bar > .cg-route-popover.cg-route-popover.cg-route-nav-panel {
|
| 409 |
+
width: min(440px, 100%);
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
@media (max-width: 1000px) {
|
| 413 |
+
.cg-mapview > .cg-map-bar > .cg-route-popover.cg-route-popover.cg-route-nav-panel {
|
| 414 |
+
width: min(420px, calc(100% - 48px));
|
| 415 |
+
}
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
/* βββββββββββββββββββ W46-T19 / R9 / C2 β the route timer and the drag grip βββββββββββββββββββ
|
| 419 |
|
| 420 |
THE TIMER SITS ABOVE THE STOPS IT IS ABOUT, which is what makes it readable as a property of
|
|
|
|
| 611 |
flex: 1 1 auto;
|
| 612 |
min-width: 0;
|
| 613 |
}
|
| 614 |
+
|
| 615 |
+
/* βββββββββββββββ W47-T07 β THE TICKED ROUTES, AND THE CHECKBOX THAT TICKS THEM βββββββββββββββ
|
| 616 |
+
Owner instruction 9: *"we also need a checkbox for us to be able to see each route all together
|
| 617 |
+
on the map ... Each route should have a different color that is onbrand."*
|
| 618 |
+
|
| 619 |
+
β NO `stroke` HERE, ON PURPOSE. Every overlaid route wears its OWN persisted colour, set as an
|
| 620 |
+
attribute from `route.color`, so a stroke declared in this file would flatten all of them to one
|
| 621 |
+
and quietly undo the whole ticket. Weight and joins only.
|
| 622 |
+
β AND NO `stroke-width` EITHER: the line renders inside the camera transform, where a CSS width
|
| 623 |
+
is in user units and thickens with the zoom. `hair()` in `MapView.tsx` owns that number. This is
|
| 624 |
+
the third time in one wave the same trap has come up - see the note on `LP_ZONE_STROKE_WIDTH`. */
|
| 625 |
+
.cg-map-svg .cg-map-route-overlay {
|
| 626 |
+
fill: none;
|
| 627 |
+
stroke-linecap: round;
|
| 628 |
+
stroke-linejoin: round;
|
| 629 |
+
stroke-opacity: 0.95;
|
| 630 |
+
}
|
| 631 |
+
|
| 632 |
+
/* The swatch is now inside a label with the checkbox, so the pair needs to sit on one baseline. */
|
| 633 |
+
.cg-w44-route-toggle {
|
| 634 |
+
display: inline-flex;
|
| 635 |
+
align-items: center;
|
| 636 |
+
gap: 6px;
|
| 637 |
+
cursor: pointer;
|
| 638 |
+
}
|
| 639 |
+
|
| 640 |
+
.cg-w44-route-toggle input {
|
| 641 |
+
margin: 0;
|
| 642 |
+
cursor: pointer;
|
| 643 |
+
}
|