fsanyoto commited on
Commit
f709e48
·
verified ·
1 Parent(s): 88f1d34

Deploy AIOS web (React glide grid + FastAPI slice)

Browse files
RELEASES.json CHANGED
@@ -1,4 +1,4 @@
1
  {
2
- "current": "eaf53db9bc885c13238a222bfa2949734eb48fa0 (eaf53db9bc)",
3
  "releases": []
4
  }
 
1
  {
2
+ "current": "0e94627c5cb5c2fe503cceb788b3edbae2e6840c (0e94627c)",
3
  "releases": []
4
  }
VERSION CHANGED
@@ -1 +1 @@
1
- eaf53db9bc885c13238a222bfa2949734eb48fa0 (eaf53db9bc)
 
1
+ 0e94627c5cb5c2fe503cceb788b3edbae2e6840c (0e94627c)
web/public/AIOS_DEPLOY_RECEIPT CHANGED
@@ -1 +1 @@
1
- 1ec274f4fab6e18c77283b3d69adcf671ac3359ce22efa4a439692beafa6a0b8
 
1
+ 21a93028ecd37b571f230689f952526047874727d2db4bf3399b80a4a146263d
web/src/customer-grid/CustomerGrid.tsx CHANGED
@@ -83,10 +83,13 @@ import { SUMMARY_BAR_PX, SummaryBar } from "./summary/SummaryBar";
83
  import type { CohortSets } from "./useVisibleRows";
84
  import type { MeasureSets } from "./useVisibleRows";
85
  import { useGetCellContent } from "./useGetCellContent";
 
86
  import type { GroupRowPlaceholder } from "./useGetCellContent";
87
  import { useGridSelection } from "./useGridSelection";
88
  import Toolbar from "./Toolbar";
89
  import { useSaveState } from "./SaveState";
 
 
90
  import { cellNoteText, editOutbox, gridEditScope, patchCellNote, pendingCellEdits, pendingCellNotes } from "./apiBridge";
91
  import CellNoteMenu, { cellNoteRefusal, drawCellNoteMarker } from "./CellNoteMenu";
92
  import type { OutboxEdit, OutboxFailure } from "./editOutbox";
@@ -178,7 +181,7 @@ import type { Tombstones } from "./liveWorkspace";
178
  import type { CustomersPayload, GridFolder, VisibleRow } from "./types";
179
  import type { ShowAs, SummaryChoice, SummaryMap } from "./types";
180
  import type { FieldStamps } from "./optimism";
181
- import { evalFormula, orderFormulas, parseFormula } from "./formulaEngine";
182
  import type { FormulaAst } from "./formulaEngine";
183
  import { applicationTemplateSurface, CalendarSettings, CalendarView, KanbanView, ListView, MapSettings, ModeSwitch, TemplateApplicationView, TimelineSettings } from "./viewModes";
184
  import { SwipeView } from "./SwipeView";
@@ -2701,16 +2704,6 @@ function CustomerGridSurface({
2701
  const pending = cellNoteDrafts.get(JSON.stringify([record.pid, key]));
2702
  return pending ? pending.text : cellNoteText(record, key);
2703
  }, [cellNoteDrafts]);
2704
- const cellSaveFailures = useMemo(() => {
2705
- const cells = new Map<string, { id: string; pid: number; key: string; failure?: OutboxFailure }>();
2706
- if (embedded) return cells;
2707
- for (const edit of pendingCellEdits(scope)) for (const key of Object.keys(edit.updates))
2708
- cells.set(JSON.stringify([edit.pid, key]), { id: edit.id, pid: edit.pid, key, failure: edit.failure });
2709
- for (const edit of cellNoteDrafts.values())
2710
- cells.set(JSON.stringify([edit.pid, edit.field, "note"]),
2711
- { id: edit.id, pid: edit.pid, key: edit.field, failure: edit.failure });
2712
- return cells;
2713
- }, [saveStatus, embedded, scope, cellNoteDrafts]);
2714
  const emitHostEvent = useMemo(() => {
2715
  const emit = bindHostEvent(scope, !embedded);
2716
  // C3: a hosted grid never moves the database's saved resume View, so it drops `view_select`.
@@ -2870,6 +2863,21 @@ function CustomerGridSurface({
2870
  firstView: hosted ? hostedFirstView(hostedAddress.path) : undefined,
2871
  ...(selectionWindow ? { embeddedPayload: idWindow.payload } : {}),
2872
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2873
  const windowPending = embeddedIds !== undefined ? idWindow.pending : selectionWindow ? idWindow.pending : ordinaryWindowPending;
2874
  const requestWindow = embeddedIds !== undefined ? idWindow.requestWindow
2875
  : selectionWindow ? idWindow.requestWindow : ordinaryRequestWindow;
@@ -4816,25 +4824,14 @@ function CustomerGridSurface({
4816
  () => fields.filter((f) => f.type === "created_time").map((f) => f.key),
4817
  [fields]
4818
  );
4819
- const computedRows = useMemo(() => {
4820
- if (formulaAsts.length === 0 && createdTimeKeys.length === 0) return rawRows;
4821
- const env = { today: payload?.today };
4822
- return rawRows.map((r) => {
4823
- const edits = overlayEdits[r.pid];
4824
- const scope: Row = edits ? { ...r, ...edits } : { ...r };
4825
- const out: Row = { ...r };
4826
- for (const k of createdTimeKeys) {
4827
- out[k] = (r._created as string | undefined) ?? null;
4828
- scope[k] = out[k];
4829
- }
4830
- for (const { key, ast } of formulaAsts) {
4831
- const v = evalFormula(ast, (k) => scope[k], env);
4832
- out[key] = v;
4833
- scope[key] = v; // later formulas read this one's result — the topo order above
4834
- }
4835
- return out;
4836
- });
4837
- }, [rawRows, overlayEdits, formulaAsts, createdTimeKeys, payload?.today]);
4838
 
4839
  /**
4840
  * ⭐⭐ W37-T26 / CONTRACT C4 — `view id -> the pids that view resolves to`, for the VIEW
@@ -11936,13 +11933,15 @@ function CustomerGridSurface({
11936
  {secondaryToolbar}
11937
  {filterRemovalNote && <div className="cg-state-note" role="status">{filterRemovalNote}</div>}
11938
  {duplicateLimitNote && <div className="cg-state-note" role="status">{duplicateLimitNote.full}</div>}
 
 
11939
  {[...cellSaveFailures.values()].some((cell) => cell.failure) && (
11940
  <div className="cg-cell-failures" aria-label="Unsaved cells">
11941
- {[...cellSaveFailures.values()].filter((cell) => cell.failure).map(({ id, pid, key, failure }) => (
11942
  <div className="cg-cell-failure" key={JSON.stringify([pid, key, id])} data-pid={pid} data-field={key}>
11943
  <span className="cg-cell-failure-label">{fieldByKey.get(key)?.label ?? key}, record {pid}: Not saved</span>
11944
  <span className="cg-cell-failure-reason">{failure!.cells?.[key] ?? failure!.message}</span>
11945
- <button type="button" className="cg-save-retry" aria-label={`Retry ${fieldByKey.get(key)?.label ?? key}, record ${pid}`}
11946
  onClick={() => void editOutbox.retryNow((edit) => edit.id === id)}>Retry</button>
11947
  </div>
11948
  ))}
 
83
  import type { CohortSets } from "./useVisibleRows";
84
  import type { MeasureSets } from "./useVisibleRows";
85
  import { useGetCellContent } from "./useGetCellContent";
86
+ import { effectiveGridRows, savedValuePredicateNote } from "./effectiveGridRows";
87
  import type { GroupRowPlaceholder } from "./useGetCellContent";
88
  import { useGridSelection } from "./useGridSelection";
89
  import Toolbar from "./Toolbar";
90
  import { useSaveState } from "./SaveState";
91
+ import PendingEdits from "./PendingEdits";
92
+ import { reviewPendingEdits } from "./pendingEdits";
93
  import { cellNoteText, editOutbox, gridEditScope, patchCellNote, pendingCellEdits, pendingCellNotes } from "./apiBridge";
94
  import CellNoteMenu, { cellNoteRefusal, drawCellNoteMarker } from "./CellNoteMenu";
95
  import type { OutboxEdit, OutboxFailure } from "./editOutbox";
 
181
  import type { CustomersPayload, GridFolder, VisibleRow } from "./types";
182
  import type { ShowAs, SummaryChoice, SummaryMap } from "./types";
183
  import type { FieldStamps } from "./optimism";
184
+ import { orderFormulas, parseFormula } from "./formulaEngine";
185
  import type { FormulaAst } from "./formulaEngine";
186
  import { applicationTemplateSurface, CalendarSettings, CalendarView, KanbanView, ListView, MapSettings, ModeSwitch, TemplateApplicationView, TimelineSettings } from "./viewModes";
187
  import { SwipeView } from "./SwipeView";
 
2704
  const pending = cellNoteDrafts.get(JSON.stringify([record.pid, key]));
2705
  return pending ? pending.text : cellNoteText(record, key);
2706
  }, [cellNoteDrafts]);
 
 
 
 
 
 
 
 
 
 
2707
  const emitHostEvent = useMemo(() => {
2708
  const emit = bindHostEvent(scope, !embedded);
2709
  // C3: a hosted grid never moves the database's saved resume View, so it drops `view_select`.
 
2863
  firstView: hosted ? hostedFirstView(hostedAddress.path) : undefined,
2864
  ...(selectionWindow ? { embeddedPayload: idWindow.payload } : {}),
2865
  });
2866
+ const cellSaveFailures = useMemo(() => {
2867
+ const cells = new Map<string, { id: string; pid: number; key: string; failure?: OutboxFailure; retryable?: boolean }>();
2868
+ if (embedded || accessRefused) return cells;
2869
+ for (const edit of reviewPendingEdits(pendingCellEdits(scope), payloadFieldsRaw)) for (const change of edit.changes) {
2870
+ const cell = JSON.stringify([edit.pid, change.field]);
2871
+ const failure = edit.failure ? { message: change.failure ?? edit.failure } : undefined;
2872
+ if (!cells.get(cell)?.failure || failure)
2873
+ cells.set(cell, { id: edit.id, pid: edit.pid, key: change.field, failure, retryable: edit.retryable });
2874
+ }
2875
+ const permitted = new Set(payloadFieldsRaw.map((field) => field.key));
2876
+ for (const edit of cellNoteDrafts.values()) if (permitted.has(edit.field))
2877
+ cells.set(JSON.stringify([edit.pid, edit.field, "note"]),
2878
+ { id: edit.id, pid: edit.pid, key: edit.field, failure: edit.failure });
2879
+ return cells;
2880
+ }, [saveStatus, embedded, accessRefused, scope, cellNoteDrafts, payloadFieldsRaw]);
2881
  const windowPending = embeddedIds !== undefined ? idWindow.pending : selectionWindow ? idWindow.pending : ordinaryWindowPending;
2882
  const requestWindow = embeddedIds !== undefined ? idWindow.requestWindow
2883
  : selectionWindow ? idWindow.requestWindow : ordinaryRequestWindow;
 
4824
  () => fields.filter((f) => f.type === "created_time").map((f) => f.key),
4825
  [fields]
4826
  );
4827
+ const computedRows = useMemo(
4828
+ () => effectiveGridRows(rawRows, fields, overlayEdits, formulaAsts, createdTimeKeys, payload?.today),
4829
+ [rawRows, fields, overlayEdits, formulaAsts, createdTimeKeys, payload?.today]
4830
+ );
4831
+ const draftPredicateNote = useMemo(
4832
+ () => savedValuePredicateNote(serverWindowed, fields, pendingCellEdits(scope), config, search),
4833
+ [serverWindowed, fields, saveStatus, scope, config, search]
4834
+ );
 
 
 
 
 
 
 
 
 
 
 
4835
 
4836
  /**
4837
  * ⭐⭐ W37-T26 / CONTRACT C4 — `view id -> the pids that view resolves to`, for the VIEW
 
11933
  {secondaryToolbar}
11934
  {filterRemovalNote && <div className="cg-state-note" role="status">{filterRemovalNote}</div>}
11935
  {duplicateLimitNote && <div className="cg-state-note" role="status">{duplicateLimitNote.full}</div>}
11936
+ {draftPredicateNote && <div className="cg-state-note" role="status">{draftPredicateNote}</div>}
11937
+ {!embedded && !loading && !accessRefused && <PendingEdits key={scope} scope={scope} fields={payloadFieldsRaw} />}
11938
  {[...cellSaveFailures.values()].some((cell) => cell.failure) && (
11939
  <div className="cg-cell-failures" aria-label="Unsaved cells">
11940
+ {[...cellSaveFailures.values()].filter((cell) => cell.failure && fieldByKey.has(cell.key)).map(({ id, pid, key, failure, retryable = true }) => (
11941
  <div className="cg-cell-failure" key={JSON.stringify([pid, key, id])} data-pid={pid} data-field={key}>
11942
  <span className="cg-cell-failure-label">{fieldByKey.get(key)?.label ?? key}, record {pid}: Not saved</span>
11943
  <span className="cg-cell-failure-reason">{failure!.cells?.[key] ?? failure!.message}</span>
11944
+ <button type="button" className="cg-save-retry" disabled={!retryable} aria-label={`Retry ${fieldByKey.get(key)?.label ?? key}, record ${pid}`}
11945
  onClick={() => void editOutbox.retryNow((edit) => edit.id === id)}>Retry</button>
11946
  </div>
11947
  ))}
web/src/customer-grid/PendingEdits.css ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .cg-pending-summary { flex: 0 0 auto; padding: 4px 12px; font-size: var(--lp-fs-sm); }
2
+ .cg-pending-tools, .cg-pending-heading { display: flex; align-items: baseline; flex-wrap: wrap; gap: 8px; }
3
+ .cg-pending-tools { justify-content: space-between; }
4
+ .cg-pending-list { margin: 0; padding-left: 24px; font-size: var(--lp-fs-sm); }
5
+ .cg-pending-list > li { padding: 16px 0; border-bottom: 1px solid var(--lp-line); }
6
+ .cg-pending-heading > span { color: var(--lp-muted); }
7
+ .cg-pending-heading strong { color: var(--lp-ink); font-weight: var(--lp-fw-semibold); font-variant-numeric: tabular-nums; }
8
+ .cg-pending-change { margin-top: 8px; }
9
+ .cg-pending-change > span:first-child { color: var(--lp-muted); }
10
+ .cg-pending-change pre { margin: 4px 0; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--lp-ink); font: inherit; font-variant-numeric: tabular-nums; }
11
+ .cg-pending-failure { color: var(--lp-red-deep); }
12
+ .cg-pending-list p { margin: 8px 0 0; }
13
+ .cg-pending-heading .cg-save-retry:disabled { opacity: var(--lp-home-disabled-opacity); cursor: not-allowed; }
web/src/customer-grid/PendingEdits.tsx ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useCallback, useEffect, useState } from "react";
2
+ import { ConfirmDialog } from "../ui/ConfirmDialog";
3
+ import { editOutbox, gridEditScope, pendingCellEdits } from "./apiBridge";
4
+ import { pendingEditsCopy, pendingValueText, reviewPendingEdits } from "./pendingEdits";
5
+ import { useSaveState } from "./SaveState";
6
+ import type { Field } from "./types";
7
+ import "./PendingEdits.css";
8
+
9
+ export default function PendingEdits({ scope, fields }: { scope: string; fields: readonly Field[] }) {
10
+ const includes = useCallback((edit: Parameters<typeof gridEditScope>[0]) => gridEditScope(edit, scope), [scope]);
11
+ useSaveState(includes);
12
+ const [open, setOpen] = useState(false);
13
+ const [feedback, setFeedback] = useState("");
14
+ const read = () => reviewPendingEdits(pendingCellEdits(scope), fields);
15
+ const edits = read();
16
+ useEffect(() => {
17
+ if (!edits.length) { setOpen(false); setFeedback(""); }
18
+ }, [edits.length]);
19
+ const copy = async () => {
20
+ try {
21
+ const current = read();
22
+ if (!current.length) return;
23
+ await navigator.clipboard.writeText(pendingEditsCopy(current));
24
+ setFeedback("Pending changes copied");
25
+ } catch {
26
+ setFeedback("Copy failed. Download a copy instead.");
27
+ }
28
+ };
29
+ const download = () => {
30
+ let url: string | undefined;
31
+ let link: HTMLAnchorElement | undefined;
32
+ try {
33
+ const current = read();
34
+ if (!current.length) return;
35
+ url = URL.createObjectURL(new Blob([pendingEditsCopy(current)], { type: "application/json" }));
36
+ link = document.createElement("a");
37
+ link.href = url;
38
+ link.download = "pending-changes.json";
39
+ document.body.append(link);
40
+ link.click();
41
+ setFeedback("Pending changes downloaded");
42
+ } catch {
43
+ setFeedback("Download failed. Try copying the changes.");
44
+ } finally {
45
+ link?.remove();
46
+ if (url) setTimeout(() => URL.revokeObjectURL(url!), 1000);
47
+ }
48
+ };
49
+ const retry = async (id: string) => {
50
+ const current = read().find((edit) => edit.id === id);
51
+ if (!current?.retryable) return;
52
+ setFeedback("");
53
+ await editOutbox.retryNow((edit) => edit.id === current.id && gridEditScope(edit, scope));
54
+ };
55
+ if (!edits.length) return null;
56
+ return <>
57
+ <div className="cg-pending-summary">
58
+ <button type="button" className="cg-save-retry" onClick={() => { setFeedback(""); setOpen(true); }}>
59
+ Review pending changes ({edits.length})
60
+ </button>
61
+ </div>
62
+ <ConfirmDialog open={open} title="Pending changes" cancelLabel="Close" confirmLabel="Copy pending changes"
63
+ tone="primary" onCancel={() => setOpen(false)} onConfirm={() => void copy()} body={<>
64
+ <div className="cg-pending-tools">
65
+ <span>These changes have not been saved</span>
66
+ <button type="button" className="cg-save-retry" onClick={download}>Download a copy</button>
67
+ </div>
68
+ <ol className="cg-pending-list">{edits.map((edit) => <li key={edit.id}>
69
+ <div className="cg-pending-heading">
70
+ <strong>Record {edit.pid}</strong>
71
+ <span>{edit.failure ? "Not saved" : "Waiting to save"}</span>
72
+ <button type="button" className="cg-save-retry" disabled={!edit.retryable}
73
+ aria-label={`Retry change ${edit.order}, record ${edit.pid}`} onClick={() => void retry(edit.id)}>Retry</button>
74
+ </div>
75
+ {edit.changes.map((change) => <div className="cg-pending-change" key={change.field}>
76
+ <span>{change.label}</span>
77
+ <pre aria-label={`Pending value for ${change.label}`}>{pendingValueText(change.value)}</pre>
78
+ {change.failure && <span className="cg-pending-failure">{change.failure}</span>}
79
+ </div>)}
80
+ {edit.failure && <p className="cg-pending-failure">{edit.failure}</p>}
81
+ {edit.code === "out_of_scope" && <p>{scope === "product"
82
+ ? "Product unavailable. Ask an administrator to check the source catalogue and your access, then retry."
83
+ : "Record unavailable. Ask an administrator to check your access, then retry."}</p>}
84
+ </li>)}</ol>
85
+ <span role="status" aria-live="polite">{feedback}</span>
86
+ </>} />
87
+ </>;
88
+ }
web/src/customer-grid/apiBridge.ts CHANGED
@@ -2917,10 +2917,20 @@ export function gridEditScope(edit: OutboxEdit, scope: string): boolean {
2917
  && topicForScope(edit.scope).scope === topicForScope(scope).scope;
2918
  }
2919
 
2920
- export function pendingCellEdits(scope: string): { id: string; failure?: OutboxFailure; pid: number; updates: Partial<Row> }[] {
2921
- return editOutbox.snapshot().pending.flatMap((edit) => {
 
 
 
 
 
 
 
 
 
 
2922
  if (!gridEditScope(edit, scope)) return [];
2923
- const evidence = { id: edit.id, failure: editOutbox.snapshot().failures[edit.id] };
2924
  if (edit.kind === "row") return [{ ...edit.payload as { pid: number; updates: Partial<Row> }, ...evidence }];
2925
  const event = edit.payload as HostEvent;
2926
  return edit.kind === "event" && event.type === "overlay_patch"
 
2917
  && topicForScope(edit.scope).scope === topicForScope(scope).scope;
2918
  }
2919
 
2920
+ export interface PendingCellEdit {
2921
+ id: string;
2922
+ kind: string;
2923
+ scope: string;
2924
+ failure?: OutboxFailure;
2925
+ pid: number;
2926
+ updates: Partial<Row>;
2927
+ }
2928
+
2929
+ export function pendingCellEdits(scope: string): PendingCellEdit[] {
2930
+ const snapshot = editOutbox.snapshot();
2931
+ return snapshot.pending.flatMap((edit) => {
2932
  if (!gridEditScope(edit, scope)) return [];
2933
+ const evidence = { id: edit.id, kind: edit.kind, scope: edit.scope, failure: snapshot.failures[edit.id] };
2934
  if (edit.kind === "row") return [{ ...edit.payload as { pid: number; updates: Partial<Row> }, ...evidence }];
2935
  const event = edit.payload as HostEvent;
2936
  return edit.kind === "event" && event.type === "overlay_patch"
web/src/customer-grid/effectiveGridRows.ts ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { Field, Row, ViewConfig } from "./types";
2
+ import { evalFormula } from "./formulaEngine";
3
+ import type { FormulaAst } from "./formulaEngine";
4
+
5
+ /** A present draft wins, including a cleared or falsy value. */
6
+ export function effectiveCellValue(row: Row, key: string, edits?: Partial<Row>): Row[string] {
7
+ return key !== "pid" && edits && Object.prototype.hasOwnProperty.call(edits, key)
8
+ ? edits[key] : row[key];
9
+ }
10
+
11
+ /** Project admitted drafts and computed cells without changing source rows or membership. */
12
+ export function effectiveGridRows(
13
+ rawRows: Row[],
14
+ fields: readonly Field[],
15
+ overlayEdits: Record<number, Partial<Row>>,
16
+ formulaAsts: readonly { key: string; ast: FormulaAst }[] = [],
17
+ createdTimeKeys: readonly string[] = [],
18
+ today?: string,
19
+ ): Row[] {
20
+ const admitted = new Set(fields.map((field) => field.key));
21
+ return rawRows.map((row) => {
22
+ let out = row;
23
+ const edits = overlayEdits[row.pid];
24
+ for (const key of Object.keys(edits ?? {})) {
25
+ if (key === "pid" || !admitted.has(key)) continue;
26
+ if (out === row) out = { ...row };
27
+ out[key] = effectiveCellValue(row, key, edits);
28
+ }
29
+ if (createdTimeKeys.length || formulaAsts.length) {
30
+ if (out === row) out = { ...row };
31
+ for (const key of createdTimeKeys) if (key !== "pid" && admitted.has(key))
32
+ out[key] = row._created ?? null;
33
+ for (const { key, ast } of formulaAsts) if (key !== "pid" && admitted.has(key))
34
+ out[key] = evalFormula(ast, (operand) => admitted.has(operand) ? out[operand] : undefined, { today });
35
+ }
36
+ return out;
37
+ });
38
+ }
39
+
40
+ /** A server predicate cannot include this browser's pending cell values. */
41
+ export function savedValuePredicateNote(
42
+ serverWindowed: boolean,
43
+ fields: readonly Field[],
44
+ pending: readonly { updates: Partial<Row> }[],
45
+ config: Pick<ViewConfig, "filters" | "sorts" | "groupBy">,
46
+ search: string,
47
+ ): string | null {
48
+ if (!serverWindowed || !(config.filters.length || config.sorts.length || config.groupBy || search.trim()))
49
+ return null;
50
+ const admitted = new Set(fields.map((field) => field.key).filter((key) => key !== "pid"));
51
+ return pending.some(({ updates }) => Object.keys(updates).some((key) => admitted.has(key)))
52
+ ? "Filters, search, sort and groups use saved values until edits are saved." : null;
53
+ }
web/src/customer-grid/pendingEdits.ts ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { PendingCellEdit } from "./apiBridge";
2
+ import type { Field } from "./types";
3
+
4
+ export interface ReviewedEdit {
5
+ id: string;
6
+ kind: string;
7
+ scope: string;
8
+ order: number;
9
+ pid: number;
10
+ changes: { field: string; label: string; value: unknown; failure?: string }[];
11
+ failure?: string;
12
+ code?: string;
13
+ retryable: boolean;
14
+ }
15
+
16
+ /** Field admission applies to drafts even when their record no longer loads. */
17
+ export function reviewPendingEdits(edits: readonly PendingCellEdit[], fields: readonly Pick<Field, "key" | "label">[]): ReviewedEdit[] {
18
+ const admitted = new Map(fields.filter((field) => field.key !== "pid").map((field) => [field.key, field.label]));
19
+ return edits.flatMap((edit, index) => {
20
+ const keys = Object.keys(edit.updates);
21
+ const permitted = keys.filter((key) => admitted.has(key));
22
+ if (!permitted.length) return [];
23
+ const retryable = permitted.length === keys.length;
24
+ return [{ id: edit.id, kind: edit.kind, scope: edit.scope, order: index + 1, pid: edit.pid,
25
+ changes: permitted.map((field) => ({ field, label: admitted.get(field)!, value: edit.updates[field],
26
+ failure: edit.failure?.cells?.[field] })),
27
+ failure: retryable ? edit.failure?.message : "Some fields are unavailable. Ask an administrator to check access.",
28
+ code: retryable ? edit.failure?.code : undefined, retryable }];
29
+ });
30
+ }
31
+
32
+ export function pendingValueText(value: unknown): string {
33
+ return JSON.stringify(value, null, 2) ?? "undefined";
34
+ }
35
+
36
+ /** An ordered list preserves repeated edits without exposing unpermitted payload fields. */
37
+ export function pendingEditsCopy(edits: readonly ReviewedEdit[]): string {
38
+ return JSON.stringify({ pendingChanges: edits.map((edit) => ({
39
+ order: edit.order, id: edit.id, kind: edit.kind, scope: edit.scope,
40
+ ...(edit.kind === "event" ? { type: "overlay_patch" } : {}),
41
+ pid: edit.pid, updates: Object.fromEntries(edit.changes.map((change) => [change.field, change.value])),
42
+ undefinedFields: edit.changes.filter((change) => change.value === undefined).map((change) => change.field),
43
+ failure: edit.failure, code: edit.code,
44
+ cellFailures: Object.fromEntries(edit.changes.filter((change) => change.failure !== undefined)
45
+ .map((change) => [change.field, change.failure])),
46
+ ...(edit.retryable ? {} : { incomplete: true }),
47
+ })) }, null, 2);
48
+ }
web/src/customer-grid/useCustomerData.ts CHANGED
@@ -634,23 +634,25 @@ export function useCustomerData(
634
  current.set(JSON.stringify([pid, key]), { pid, key, value });
635
  committedEdits.current.set(JSON.stringify([scope, pid, key]), value);
636
  }
 
637
  setOverlayEdits((previous) => {
638
  let next = previous;
639
- for (const [id, { pid, key, value }] of restored) {
640
- if (current.has(id) || next[pid]?.[key] !== value
 
641
  || cellVersions.current.has(JSON.stringify([scope, pid, key]))) continue;
642
  const row = { ...next[pid] };
643
  delete row[key];
644
  next = { ...next, [pid]: row };
645
  }
646
- for (const { pid, updates } of pending) {
647
- const waiting = Object.fromEntries(Object.entries(updates).filter(([key, value]) => {
648
- if (cellVersions.current.has(JSON.stringify([scope, pid, key])) || next[pid]?.[key] === value) return false;
649
- const previous = restored.get(JSON.stringify([pid, key]));
650
- return !previous || next[pid]?.[key] === previous.value;
651
- }));
652
- if (!Object.keys(waiting).length) continue;
653
- next = { ...next, [pid]: { ...next[pid], ...waiting } };
654
  }
655
  return next;
656
  });
 
634
  current.set(JSON.stringify([pid, key]), { pid, key, value });
635
  committedEdits.current.set(JSON.stringify([scope, pid, key]), value);
636
  }
637
+ const previouslyRestored = restored;
638
  setOverlayEdits((previous) => {
639
  let next = previous;
640
+ for (const [id, { pid, key, value }] of previouslyRestored) {
641
+ if (current.has(id) || !Object.prototype.hasOwnProperty.call(previous[pid] ?? {}, key)
642
+ || previous[pid]?.[key] !== value
643
  || cellVersions.current.has(JSON.stringify([scope, pid, key]))) continue;
644
  const row = { ...next[pid] };
645
  delete row[key];
646
  next = { ...next, [pid]: row };
647
  }
648
+ // Compare each cell's final queued value against the same restored snapshot.
649
+ for (const [id, { pid, key, value }] of current) {
650
+ const present = Object.prototype.hasOwnProperty.call(previous[pid] ?? {}, key);
651
+ if (cellVersions.current.has(JSON.stringify([scope, pid, key]))
652
+ || (present && previous[pid]?.[key] === value)) continue;
653
+ const prior = previouslyRestored.get(id);
654
+ if (prior && (!present || previous[pid]?.[key] !== prior.value)) continue;
655
+ next = { ...next, [pid]: { ...next[pid], [key]: value } };
656
  }
657
  return next;
658
  });
web/src/customer-grid/useGetCellContent.ts CHANGED
@@ -20,6 +20,7 @@ import { TOTAL_GROUP_KEY } from "./types";
20
  import type { Field, Row, VisibleRow } from "./types";
21
  import type { OverlayEdits } from "./useCustomerData";
22
  import { makeCell } from "./cells";
 
23
  import { fitGroupLabel, GROUP_HEADER_FONT, GROUP_LABEL_PAD } from "./overlayPlacement";
24
 
25
  const EMPTY_CELL: GridCell = {
@@ -337,7 +338,7 @@ export function useGetCellContent(
337
  if (!field) return EMPTY_CELL;
338
  const pid = (vr.record as Row).pid;
339
  // Overlay edits win over the raw record (edit shows immediately).
340
- const raw = overlayEdits[pid]?.[field.key] ?? vr.record[field.key];
341
  // owner item 2 — still being calculated. Tested on the VALUE too, not on the column
342
  // alone: the moment the server's answer lands the cell must show it, and a column-only
343
  // test would keep skeletons over real numbers until the field echo caught up separately.
 
20
  import type { Field, Row, VisibleRow } from "./types";
21
  import type { OverlayEdits } from "./useCustomerData";
22
  import { makeCell } from "./cells";
23
+ import { effectiveCellValue } from "./effectiveGridRows";
24
  import { fitGroupLabel, GROUP_HEADER_FONT, GROUP_LABEL_PAD } from "./overlayPlacement";
25
 
26
  const EMPTY_CELL: GridCell = {
 
338
  if (!field) return EMPTY_CELL;
339
  const pid = (vr.record as Row).pid;
340
  // Overlay edits win over the raw record (edit shows immediately).
341
+ const raw = effectiveCellValue(vr.record, field.key, overlayEdits[pid]);
342
  // owner item 2 — still being calculated. Tested on the VALUE too, not on the column
343
  // alone: the moment the server's answer lands the cell must show it, and a column-only
344
  // test would keep skeletons over real numbers until the field echo caught up separately.