toga-ai 1.0.252 → 1.0.253

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,69 @@
1
+ ---
2
+ type: session
3
+ slug: surface-section-migration-fe
4
+ title: Surface action-bar + SalesOrders section migration — FE fixes
5
+ author: apeterson
6
+ repos: [toga25-supply]
7
+ framework: "2.0"
8
+ client: shared
9
+ status: active
10
+ created: 2026-06-30
11
+ updated: 2026-06-30
12
+ ---
13
+
14
+ # Session: surface-section-migration-fe
15
+ **Date:** 2026-06-30
16
+ **Project/Repo:** toga25-supply (2.0)
17
+ **Task:** Make the Surface presentation layer actually render in the SalesOrders record modal — fix the action-bar (BUTTON_BAR) rendering, the grouped section fetch/extraction, Tier-1 rule evaluation, icons, and add a meta-driven custom-component path — all in the toga25-supply React frontend (no backend/DB this session).
18
+
19
+ ---
20
+
21
+ ## What WORKED
22
+ <!-- Include specific file paths and evidence -->
23
+ - **`extractBundle` single-meta decoy fix** — `src/surface/useFetchSurfaceMeta.ts`. The single-meta envelope `{ surfaces: { meta: <bundle> }, elements: [] }` has a decoy empty top-level `elements: []`. Tightened `looksLikeBundle` to require BOTH an `elements` array AND a `surface` object; replaced hard-coded raw/data probing with recursive `findBundle(raw, predicate, depth=4)`; `extractBundle(raw, slug)` now PREFERS the bundle whose `surface.slug === slug`, falling back to first-found. Trace verified: action-bar payload → 5 elements (was 0); direct/`data`/`data.meta` shapes still resolve. Type-check clean.
24
+ - **Grouped fetch `extractGroup` double-nesting fix** — `src/surface/useFetchSurfaceMeta.ts`. The meta-group envelope double-nests the slug-keyed `surfaces` map under an OUTER route-keyed `surfaces` slot: `{ surfaces: { "meta-group": { group, surfaces: { "order-details": bundle, ... } } } }`. Old `extractGroup` grabbed the outer (route-keyed) map → `surfaces["order-details"]` undefined → `surfaceBundleToTenantFields` returned `{}`. Replaced `looksLikeGroup` + the data-probe with recursive `findSurfaceMap(raw, depth=5)` that returns the `surfaces` map whose VALUES look like bundles (or null/empty). Trace verified across 6 shapes (double-nested, resolver-return-at-top, simple, data-wrapped, null-child, empty). Type-check clean.
25
+ - **Tier-1 rule record envelope** — `src/pages/SalesOrders/view/SalesOrderRecordModalLayout/view/sections/SalesOrderTopBar.tsx`. Rules use field `order._status`, but the component passed the bare order; `getByPath(order,"order._status")` → undefined → all gates false. Fixed by passing `record={order ? { order } : null}`. Trace: `{order:{_status:"pendingApproval"}}` → true; `fulfilled` → false. `evaluateSurfaceRule.ts` was NOT the bug.
26
+ - **Icon resolution** — `src/surface/SurfaceActionBar.tsx`. `tokens.icon` is a literal FontAwesome name, not a theme-token slug; running it through `resolveThemeToken` (theme map has only color/bg keys) made every icon fall back to "check". Fixed to `element.tokens?.icon ?? "check"`; removed the now-unused `resolveThemeToken` import.
27
+ - **Meta-driven component registry** — NEW `src/surface/componentRegistry.tsx` (presentation sibling of `actionRegistry`, keyed by `action.key`). `"salesOrder.viewLog"` → `<ViewLogButton label onOpenLog={onActivate} />`. `SurfaceActionBar.renderElement` calls `getSurfaceComponent(element.action?.key)` and renders it (keyed Fragment) before the default icon button. Type-check clean.
28
+ - **Section migration verified end-to-end (adapter seam)** — data path: `useFetchSurfaceMetaGroup(SALES_ORDER_SURFACE_SLUGS)` → `surfaceBundleToTenantFields(surfaces)` → merged into `tenantFields` (migrated clients only) → `buildPatchedTenantFields` (only overrides `recordActionFields`, so it PRESERVES all surface section keys) → `SalesOrderView` → `SalesOrderSummaryGrid` (renders by `section.type` cardType) + `getDetailSections` (reads `section.isVisible`). Full project type-check: zero errors.
29
+ - **Debug cleanup** — removed all debug `console.log`s from the viewModel (×3), `SalesOrderRecordModalLayout.tsx`, and `getDetailSections.tsx`. `grep` confirms none remain; type-check clean.
30
+ - **Two `/capture` runs PUSHED** to team `_main`, updating `2.0/apps/toga25-supply/features/surface-frontend.md` (owners `[jcardinal, apeterson]`), including corrections of two stale notes from the first capture.
31
+
32
+ ## What did NOT work — DO NOT RETRY THESE
33
+ <!-- Exact failure reasons — do not vague-ify -->
34
+ - **Requiring a `group` discriminator key in `looksLikeGroup`** — added during the review pass to disambiguate single-vs-group. It RETURNED `{}` for the grouped fetch because the V2 envelope does not carry a top-level `group` at the probed level (the single-meta envelope has none either). Reverted, then `looksLikeGroup` removed entirely in favor of `findSurfaceMap`. DO NOT re-add a `group`-key requirement.
35
+ - **Matching the bundle/group on `elements` array ALONE** — the original `looksLikeBundle`/`looksLikeGroup` fingerprint. An empty `elements: []` decoy (single) and the outer route-keyed `surfaces` (group) both satisfied it, returning the wrong node. Must additionally require a `surface` descriptor (bundle) / match by bundle-shaped values (group).
36
+ - **Branching the custom component on `renderType === "BUTTON"`** — rejected by the user as "not driven by surface meta" — it hardcodes a component to a whole render category. Use the `action.key`-keyed `componentRegistry` instead (the chosen approach).
37
+
38
+ ## Not tried yet (candidates for next session)
39
+ - **Seed/ACL fixes for the display-section surfaces** (`additional-order-details`, `admin-notes`, `notes`) — if still missing at runtime, their surface resolves `surface: null` and the adapter drops the key (no JSON fallback for migrated clients). This is the paused Track B (prod cross-cluster seed work), NOT an FE fix. See session `surface-layer` (jcardinal) for the prod cross-cluster blocker.
40
+ - **Re-enable `shipments`** — currently permanently hidden: `useShipments` is commented out and the viewModel hardcodes `shipmentsData: []`; `getDetailSections` gates on `shipmentsData.length > 0`. Re-wire `useShipments` if shipments need to render.
41
+ - **Runtime verification on a migrated client** — confirm on a `COMPASS`/`COMPASSCANADA`/`QUAD` hostname that the cards + detail sections render from Surface and the action bar shows all five buttons with correct icons.
42
+ - **Backend: stabilize the single-meta / meta-group envelope contract** so the FE shape-probing (`findBundle`/`findSurfaceMap`) can eventually relax.
43
+
44
+ ## Current file state
45
+ | File | Status | Notes |
46
+ |------|--------|-------|
47
+ | src/surface/useFetchSurfaceMeta.ts | modified | `findBundle` + slug-preferred `extractBundle`; `findSurfaceMap` + `extractGroup`; `looksLikeGroup` removed. Type-check clean. |
48
+ | src/surface/SurfaceActionBar.tsx | modified | renames (element/surfaceMeta/recordSurfaceState); literal `tokens.icon`; `componentRegistry` branch; debug logs gone. |
49
+ | src/surface/componentRegistry.tsx | created | NEW presentation registry keyed by `action.key`; `salesOrder.viewLog` → ViewLogButton. |
50
+ | src/pages/.../view/sections/SalesOrderTopBar.tsx | modified | `record={order ? { order } : null}` envelope for Tier-1 rules. |
51
+ | src/pages/.../viewModel/useSalesOrderRecordModalLayoutModel.tsx | modified | debug logs removed; surface→tenantFields merge intact (unchanged logic). |
52
+ | src/pages/.../SalesOrderRecordModalLayout.tsx | modified | removed stray `console.log(error)`. |
53
+ | src/pages/.../helpers/getDetailSections.tsx | modified | removed `console.log(tenantFields)`. |
54
+ | src/pages/SalesOrders/viewModel/useSalesOrdersPageViewModel.tsx | modified | PRE-EXISTING change from session start — NOT touched this session; review separately. |
55
+ | .claude/ | untracked | local harness mirror; not part of this work. |
56
+
57
+ ## Decisions made
58
+ - **Keep the adapter seam for section migration; do NOT replace with direct `<SurfaceSection>`** (user-confirmed). Rationale: the adapter (`surfaceBundleToTenantFields` → `tenantFields` → existing renderers) is complete and keeps business logic (the `_totalLease` recurring gate, card styling) in code; a direct-`<SurfaceSection>` rewrite would re-home all that for no functional gain. Rejected: per-section `<SurfaceSection surfaceSlug record/>` like SurfaceActionBar.
59
+ - **Custom components via an `action.key`-keyed `componentRegistry`** (sibling of `actionRegistry`), not a `renderType` branch. Rationale: fully meta-driven, same extensibility model as the existing registries; adding a custom button = one surface element + one registry entry.
60
+ - **Shape-probe by value, not by key/path** — both `findBundle` and `findSurfaceMap` identify the target by structural shape (bundle = `surface` + `elements`; slug-keyed map = values are bundles) and walk the tree, rather than hard-coding the V2 envelope nesting. Rationale: robust across route/version envelope changes.
61
+
62
+ ## Blockers
63
+ - **Display-section surfaces may not be seeded/granted** for the migrated clients — if `additional-order-details`/`admin-notes`/`notes` are still missing at runtime, that is a seed/ACL (Track B) gap, not FE. Track B (prod cross-cluster Client seed rewrite) remains user-paused pending prod Core ids (see session `surface-layer`).
64
+
65
+ ## Exact next step
66
+ > On a migrated-client hostname (`clientSlug` === `COMPASS`/`COMPASSCANADA`/`QUAD`), open a sales order and inspect the network response for `GET /v2/surfaces/meta-group` plus the resolved `surfaces` object: confirm the slug-keyed bundles for `order-details`, `ship-to`, `bill-to`, `order-summary`, `order-recurring`, `invoices`, `notes`, `admin-notes`, `additional-order-details`. For any whose bundle is `surface: null`, that slug is a seed/ACL gap (Track B) — list them and hand off to the backend seed pass; everything that resolves should now render via the verified adapter path.
67
+
68
+ ---
69
+ _Saved by /session-save on 2026-06-30_
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toga-ai",
3
- "version": "1.0.252",
3
+ "version": "1.0.253",
4
4
  "description": "TOGA Technology Team Claude Knowledge System — shared AI coding harness with skills, knowledge base CLI, and project installer for Claude Code.",
5
5
  "keywords": [
6
6
  "claude",