@sincpro/web-framework 3.21.0 → 4.0.0

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.
Files changed (88) hide show
  1. package/README.md +114 -112
  2. package/dist/core/cache.d.ts +20 -23
  3. package/dist/core/cache.js +37 -52
  4. package/dist/core/changes.d.ts +10 -18
  5. package/dist/core/changes.js +11 -30
  6. package/dist/core/command.d.ts +25 -11
  7. package/dist/core/command.js +9 -12
  8. package/dist/core/copy.d.ts +4 -0
  9. package/dist/core/copy.js +2 -0
  10. package/dist/core/edit.d.ts +16 -2
  11. package/dist/core/edit.js +13 -2
  12. package/dist/core/groups.d.ts +3 -2
  13. package/dist/core/groups.js +4 -3
  14. package/dist/core/index.d.ts +2 -2
  15. package/dist/core/index.js +2 -2
  16. package/dist/core/list.d.ts +17 -11
  17. package/dist/core/list.js +17 -11
  18. package/dist/core/names.d.ts +8 -6
  19. package/dist/core/names.js +14 -18
  20. package/dist/core/server.d.ts +9 -7
  21. package/dist/core/server.js +17 -21
  22. package/dist/core/trail.d.ts +6 -3
  23. package/dist/core/trail.js +2 -2
  24. package/dist/react/context.d.ts +13 -6
  25. package/dist/react/context.js +11 -9
  26. package/dist/react/index.d.ts +1 -1
  27. package/dist/react/index.js +1 -1
  28. package/dist/react/useBatchCommand.d.ts +5 -5
  29. package/dist/react/useBatchCommand.js +10 -12
  30. package/dist/react/useCommand.d.ts +11 -15
  31. package/dist/react/useCommand.js +15 -13
  32. package/dist/react/useCount.d.ts +2 -2
  33. package/dist/react/useCounts.js +10 -9
  34. package/dist/react/useGroups.d.ts +1 -1
  35. package/dist/react/useGroups.js +22 -13
  36. package/dist/react/useHistory.js +7 -7
  37. package/dist/react/useListing.d.ts +14 -7
  38. package/dist/react/useListing.js +33 -9
  39. package/dist/react/useLookup.js +5 -7
  40. package/dist/react/useNameOf.d.ts +2 -2
  41. package/dist/react/useNameOf.js +4 -13
  42. package/dist/react/usePivot.d.ts +1 -1
  43. package/dist/react/usePivot.js +13 -7
  44. package/dist/react/useRecord.js +49 -57
  45. package/dist/react/useRecordLifecycle.js +8 -9
  46. package/dist/react/useServiceReading.js +6 -18
  47. package/dist/react/useUpload.js +9 -2
  48. package/dist/react/useWrites.d.ts +13 -12
  49. package/dist/react/useWrites.js +17 -16
  50. package/dist/web/board/Dashboard.d.ts +112 -0
  51. package/dist/web/board/Dashboard.js +106 -0
  52. package/dist/web/board/index.d.ts +1 -0
  53. package/dist/web/board/index.js +1 -0
  54. package/dist/web/index.d.ts +2 -0
  55. package/dist/web/index.js +2 -0
  56. package/dist/web/list/EntityList.d.ts +2 -2
  57. package/dist/web/list/entityList/choosing.d.ts +3 -3
  58. package/dist/web/list/entityList/faces.d.ts +6 -6
  59. package/dist/web/list/entityList/grouping.d.ts +3 -3
  60. package/dist/web/list/entityList/opening.d.ts +4 -4
  61. package/dist/web/list/entityList/opening.js +2 -1
  62. package/dist/web/list/entityList/paging.d.ts +3 -3
  63. package/dist/web/list/entityList/props.d.ts +4 -4
  64. package/dist/web/list/entityList/rowActions.d.ts +4 -4
  65. package/dist/web/list/entityList/rowActions.js +1 -1
  66. package/dist/web/list/export.d.ts +2 -2
  67. package/dist/web/list/export.js +7 -8
  68. package/dist/web/list/presentation.d.ts +3 -3
  69. package/dist/web/list/records.d.ts +13 -10
  70. package/dist/web/list/records.js +23 -44
  71. package/dist/web/list/reorder.d.ts +1 -1
  72. package/dist/web/list/reorder.js +8 -6
  73. package/dist/web/list/rowCommands.d.ts +10 -9
  74. package/dist/web/list/rowCommands.js +14 -15
  75. package/dist/web/list/useEntityList.d.ts +4 -4
  76. package/dist/web/record/CommandButton.d.ts +8 -8
  77. package/dist/web/record/EntityTags.js +4 -4
  78. package/dist/web/record/RelatedList.js +2 -2
  79. package/dist/web/record/Wizard.d.ts +65 -0
  80. package/dist/web/record/Wizard.js +90 -0
  81. package/dist/web/record/lines.js +4 -4
  82. package/dist/web/record/richText.js +1 -1
  83. package/dist/web/workspace/SincproApp.d.ts +8 -6
  84. package/dist/web/workspace/SincproApp.js +17 -19
  85. package/dist/web/workspace/composer.d.ts +14 -9
  86. package/dist/web/workspace/composer.js +29 -8
  87. package/dist/web/workspace/record.js +2 -2
  88. package/package.json +3 -3
@@ -3,6 +3,7 @@ import { resumingFrom } from "@sincpro/criteria";
3
3
  import { areGroups, groupKeyOf, isGroupedAnswer, levelQuestion, nextGroups, NotGrouped, rowsQuestion, } from "../core/groups.js";
4
4
  import { measuresOf, sumsOf } from "../core/measure.js";
5
5
  import { useFramework } from "./context.js";
6
+ import { listingKeyOf, readerOf, } from "./useListing.js";
6
7
  import { useWrites } from "./useWrites.js";
7
8
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
8
9
  const IDLE = {
@@ -22,7 +23,7 @@ const without = (map, above) => {
22
23
  return kept.length === map.size ? map : new Map(kept);
23
24
  };
24
25
  export function useGroups(listing, options = {}) {
25
- const { transport, context } = useFramework();
26
+ const { operations, context } = useFramework();
26
27
  // A named list may open grouped (`groupBy`); a person regroups from there.
27
28
  const [levels, setLevels] = useState(() => listing.definition?.groupBy ?? []);
28
29
  const [root, setRoot] = useState(IDLE);
@@ -38,9 +39,13 @@ export function useGroups(listing, options = {}) {
38
39
  // The question without what pages it: a cursor or a limit of rows has no meaning for groups.
39
40
  const { pagination: _page, ...asked } = listing.question;
40
41
  const question = JSON.stringify(asked);
41
- const route = listing.route;
42
+ const entityKey = listing.entity.key;
43
+ const read = useMemo(() => readerOf(operations, listing),
44
+ // What it reads is its entity and input (`listingKeyOf`) under its definition.
45
+ // eslint-disable-next-line react-hooks/exhaustive-deps
46
+ [operations, listingKeyOf(listing), listing.meta]);
42
47
  // Written by anyone — a save, a use case, a panel beside: the groups are counted again.
43
- const writes = useWrites(route);
48
+ const writes = useWrites(listing.entity);
44
49
  const sums = (options.sums ?? sumsOf(listing.meta)).join(",");
45
50
  // Each by the function the model adds it up with (`total`), as text: compared by content.
46
51
  const measured = sums === "" ? "" : JSON.stringify(measuresOf(sums.split(","), listing.meta));
@@ -95,7 +100,7 @@ export function useGroups(listing, options = {}) {
95
100
  const criteria = at === null ? first : resumingFrom(first, at);
96
101
  if (had !== undefined)
97
102
  setRows((map) => new Map(map).set(key, { ...had, reading: true, error: null }));
98
- transport.list(route, criteria, signal).then((page) => {
103
+ read(criteria, signal).then((page) => {
99
104
  inFlight.current.delete(tag);
100
105
  if (generation.current.id !== id)
101
106
  return;
@@ -140,7 +145,7 @@ export function useGroups(listing, options = {}) {
140
145
  error,
141
146
  }));
142
147
  });
143
- }, [transport, route, pageSize, maxRows]);
148
+ }, [read, pageSize, maxRows]);
144
149
  /**
145
150
  * What arrived at a level, under `above`: each bucket learns its path, an open one reads what
146
151
  * it holds again, and a closed one forgets it — reopened later, it reads it fresh.
@@ -167,12 +172,12 @@ export function useGroups(listing, options = {}) {
167
172
  reading: true,
168
173
  error: null,
169
174
  }));
170
- transport.list(route, criteria, signal).then((page) => {
175
+ read(criteria, signal).then((page) => {
171
176
  inFlight.current.delete(tag);
172
177
  if (generation.current.id !== id)
173
178
  return;
174
179
  if (!areGroups(page.rows)) {
175
- const error = new NotGrouped(route);
180
+ const error = new NotGrouped(entityKey);
176
181
  setBelow((map) => new Map(map).set(key, {
177
182
  ...(map.get(key) ?? { path, buckets: [], count: null }),
178
183
  reading: false,
@@ -202,7 +207,7 @@ export function useGroups(listing, options = {}) {
202
207
  error,
203
208
  }));
204
209
  });
205
- }, [transport, route, groupPageSize, ordered]);
210
+ }, [read, entityKey, groupPageSize, ordered]);
206
211
  arrived.current = (buckets, above) => {
207
212
  const deepest = above.length === now.current.levels.length - 1;
208
213
  const closed = [];
@@ -281,13 +286,17 @@ export function useGroups(listing, options = {}) {
281
286
  const shown = fresh ? 0 : now.current.root.buckets.length;
282
287
  const measures = measuresNow();
283
288
  const criteria = levelQuestion(JSON.parse(question), first, { limit: Math.max(groupPageSize, shown) }, { ...ordered, counted: true, ...(measures === undefined ? {} : { measures }) });
284
- transport.list(route, criteria, aborter.signal).then((page) => {
289
+ read(criteria, aborter.signal).then((page) => {
285
290
  if (generation.current.id !== id)
286
291
  return;
287
292
  // Records answered to a grouped question are not groups: the list's failure, never a
288
293
  // table drawing piles without a count.
289
294
  if (!isGroupedAnswer(page)) {
290
- setRoot({ ...IDLE, status: "failed", error: new NotGrouped(route) });
295
+ setRoot({
296
+ ...IDLE,
297
+ status: "failed",
298
+ error: new NotGrouped(entityKey),
299
+ });
291
300
  return;
292
301
  }
293
302
  const buckets = page.rows;
@@ -307,7 +316,7 @@ export function useGroups(listing, options = {}) {
307
316
  return () => aborter.abort();
308
317
  // `listing.question` is read through `question`, its content.
309
318
  // eslint-disable-next-line react-hooks/exhaustive-deps
310
- }, [transport, route, question, split, measured, waiting, context, writes, groupPageSize]);
319
+ }, [read, entityKey, question, split, measured, waiting, context, writes, groupPageSize]);
311
320
  /** The first page of the root, more of it: offset past what is in hand. */
312
321
  const moreRoot = () => {
313
322
  const first = levels[0];
@@ -321,12 +330,12 @@ export function useGroups(listing, options = {}) {
321
330
  const measures = measuresNow();
322
331
  const criteria = levelQuestion(JSON.parse(question), first, { limit: groupPageSize, offset: root.buckets.length }, { ...ordered, ...(measures === undefined ? {} : { measures }) });
323
332
  setRoot((was) => ({ ...was, status: "loading" }));
324
- transport.list(route, criteria, signal).then((page) => {
333
+ read(criteria, signal).then((page) => {
325
334
  inFlight.current.delete(tag);
326
335
  if (generation.current.id !== id)
327
336
  return;
328
337
  if (!areGroups(page.rows)) {
329
- setRoot((was) => ({ ...was, status: "failed", error: new NotGrouped(route) }));
338
+ setRoot((was) => ({ ...was, status: "failed", error: new NotGrouped(entityKey) }));
330
339
  return;
331
340
  }
332
341
  const arriving = page.rows;
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { listRoute } from "@sincpro/client-framework";
2
+ import { readHistory } from "@sincpro/client-framework";
3
3
  import { historyOf, } from "../core/history.js";
4
4
  import { useFramework } from "./context.js";
5
5
  import { useWrites } from "./useWrites.js";
@@ -22,7 +22,7 @@ import { useEffect, useState } from "react";
22
22
  */
23
23
  const SHOWN = 100;
24
24
  export function useHistory(entity, id, deps = [], options = {}) {
25
- const { transport, locale, context, metas, events, dateStyle, currency } = useFramework();
25
+ const { operations, locale, context, metas, events, dateStyle, currency } = useFramework();
26
26
  const tones = options.tones;
27
27
  // By content: a screen passes its tones as a literal, a new object on every render.
28
28
  const toned = tones === undefined ? "" : JSON.stringify(tones);
@@ -31,9 +31,9 @@ export function useHistory(entity, id, deps = [], options = {}) {
31
31
  // How its texts are written: another tone, event, date style or currency writes them again.
32
32
  const written = `${toned}\u0000${named}\u0000${dateStyle}\u0000${currency ?? ""}`;
33
33
  const [entries, setEntries] = useState(undefined);
34
- const history = entity.history;
35
- // A write under the record — anyone's — adds a fact to its history: read it again.
36
- const writes = useWrites(history === undefined || id === "" ? undefined : listRoute(history, { id }));
34
+ const history = entity.operations.events;
35
+ // A write to the entity — anyone's — may add a fact to its history: read it again.
36
+ const writes = useWrites(history === undefined || id === "" ? undefined : entity);
37
37
  useEffect(() => {
38
38
  if (history === undefined || id === "") {
39
39
  setEntries(undefined);
@@ -44,7 +44,7 @@ export function useHistory(entity, id, deps = [], options = {}) {
44
44
  order: [{ field: "created_at", descending: true }],
45
45
  pagination: { limit: SHOWN },
46
46
  };
47
- transport.list(listRoute(history, { id }), criteria, aborter.signal).then((page) => aborter.signal.aborted ||
47
+ readHistory(operations, entity, id, criteria, { signal: aborter.signal }).then((page) => aborter.signal.aborted ||
48
48
  setEntries(historyOf(page.rows, page.meta, locale, {
49
49
  record: metas.get(entity.key),
50
50
  events,
@@ -52,6 +52,6 @@ export function useHistory(entity, id, deps = [], options = {}) {
52
52
  })), () => aborter.signal.aborted || setEntries(undefined));
53
53
  return () => aborter.abort();
54
54
  // eslint-disable-next-line react-hooks/exhaustive-deps -- the caller names what reloads it
55
- }, [transport, history, id, locale, context, writes, written, ...deps]);
55
+ }, [operations, history, id, locale, context, writes, written, ...deps]);
56
56
  return entries;
57
57
  }
@@ -1,4 +1,4 @@
1
- import { type CommandBodies, type Entity } from "@sincpro/client-framework";
1
+ import { type Entity, type EntityOperations, type OperationTransport } from "@sincpro/client-framework";
2
2
  import { type AnyRecord, type Count, type Criteria, type Dropped, type Expression, type Meta, type Page, type ReadingStatus, type Sort } from "@sincpro/criteria";
3
3
  import { type ListDefinition } from "../core/list.js";
4
4
  /**
@@ -17,14 +17,14 @@ import { type ListDefinition } from "../core/list.js";
17
17
  * All three refine the same reading instead of starting another. It holds state and draws
18
18
  * nothing: `EntityList` draws it, and a screen that needs another shape draws it itself.
19
19
  */
20
- export type Listing<T, C extends CommandBodies = CommandBodies> = {
21
- /** Its entity, with the Commands it types (`entity<T, C>`): what `useRowCommands` checks. */
22
- entity: Entity<T & AnyRecord, C>;
20
+ export type Listing<T, O extends EntityOperations = EntityOperations> = {
21
+ /** Its entity, with the Commands its operations type: what `useRowCommands` checks. */
22
+ entity: Entity<T & AnyRecord, O>;
23
23
  /** The named list it reads, when it was handed one (`defineList`): what `EntityList` draws
24
24
  * by default — its columns, filters, faces, title — and how `useGroups` starts. */
25
25
  definition?: ListDefinition<T & AnyRecord>;
26
- /** The route this list reads, with its own parameters (`/projects?tenant_id=acme`). */
27
- route: string;
26
+ /** What its search takes beside the criteria — the record it lives under (`{ tenant_id }`). */
27
+ input: Readonly<Record<string, string>>;
28
28
  /**
29
29
  * The question on screen — scope, search, filter and order — without a page: what a grouping
30
30
  * of the same set asks with (`useGroups`), so groups and rows never disagree.
@@ -116,4 +116,11 @@ export type ListingOptions<T> = {
116
116
  */
117
117
  page?: Page<T>;
118
118
  };
119
- export declare function useListing<T extends AnyRecord, C extends CommandBodies = CommandBodies>(given: Entity<T, C> | ListDefinition<T>, own?: ListingOptions<T>): Listing<T, C>;
119
+ export declare function useListing<T extends AnyRecord, O extends EntityOperations = EntityOperations>(given: Entity<T, O> | ListDefinition<T>, own?: ListingOptions<T>): Listing<T, O>;
120
+ /**
121
+ * How a reading beside a listing — its groups, its pivot — asks the same set: the listing's
122
+ * entity through its `search`, beside the listing's input, with its definition.
123
+ */
124
+ export declare function readerOf<T extends AnyRecord>(operations: OperationTransport, listing: Pick<Listing<T>, "entity" | "input" | "meta">): <R = T>(criteria: Criteria<R>, signal?: AbortSignal) => Promise<Page<R>>;
125
+ /** A text that names what a listing reads — its entity and its input —, for an effect's deps. */
126
+ export declare function listingKeyOf(listing: Pick<Listing<unknown>, "entity" | "input">): string;
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import {} from "@sincpro/client-framework";
2
+ import { readPage, } from "@sincpro/client-framework";
3
3
  import { merge, resource, resumingFrom, searchOver, } from "@sincpro/criteria";
4
4
  import { useReading } from "@sincpro/criteria-react";
5
5
  import { isList, listingAsk } from "../core/list.js";
@@ -10,19 +10,28 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
10
10
  /** How long typing has to pause before the search goes out. */
11
11
  const TYPING_PAUSE = 200;
12
12
  export function useListing(given, own = {}) {
13
- const { transport, locale, metas, context } = useFramework();
13
+ const { operations, locale, metas, context } = useFramework();
14
14
  // A named list is its entity under a fixed scope: the scope ANDs under the caller's own.
15
15
  const definition = isList(given) ? given : undefined;
16
- // A named list's entity has no typed Commands of its own: the default, as `C` then is.
16
+ // A named list's entity has no typed Commands of its own: the default, as `O` then is.
17
17
  const entity = (definition?.entity ?? given);
18
18
  // The screen's cut for this entity (a chooser's, `ListScopeProvider`) ANDs like a scope.
19
19
  const cut = useListScope(entity.key);
20
20
  // The first page's question — the list's scope, the cut, the caller's criteria, the page
21
21
  // size —: the same `readListing` asks on a server, so a page read there is this one.
22
- const { route, criteria: asked } = listingAsk(given, own, cut);
23
- const source = useMemo(() => resource((criteria, signal) => transport.list(route, criteria, signal)), [transport, route]);
24
- // A definition already known draws the columns before the first page arrives; the one the
25
- // transport reads from the discovery document comes with it.
22
+ const { input, criteria: asked } = listingAsk(given, own, cut);
23
+ const inputKey = JSON.stringify(input);
24
+ const source = useMemo(() => resource((criteria, signal) => readPage(operations, entity, criteria, {
25
+ signal,
26
+ input,
27
+ // Read when asked: a definition a face brought later (`ModelDefinitions`) counts.
28
+ meta: metas.get(entity.key) ?? null,
29
+ })),
30
+ // `input` is the caller's literal: its content is what counts.
31
+ // eslint-disable-next-line react-hooks/exhaustive-deps
32
+ [operations, entity, metas, inputKey]);
33
+ // A definition already known — the contract's, a face's — draws the columns before the first
34
+ // page arrives.
26
35
  const [preloaded] = useState(() => metas.get(entity.key));
27
36
  const paging = own.paging ?? "pages";
28
37
  const size = asked.pagination?.limit ?? 50;
@@ -48,7 +57,7 @@ export function useListing(given, own = {}) {
48
57
  // Another company (the process's context changed), or a write to what it lists — anyone's: a
49
58
  // save, a use case, a panel beside —: the same question read again, its filter, order and page
50
59
  // kept, never a reading started over.
51
- const writes = useWrites(route);
60
+ const writes = useWrites(entity);
52
61
  const askedFor = useRef({ context, writes });
53
62
  // Held while another reading answers for the set (`hold`): what would have been asked is only
54
63
  // marked, and asked once when the hold ends.
@@ -141,7 +150,7 @@ export function useListing(given, own = {}) {
141
150
  return {
142
151
  entity,
143
152
  ...(definition === undefined ? {} : { definition }),
144
- route,
153
+ input,
145
154
  question: narrowed(narrowing),
146
155
  rows: reading.rows,
147
156
  meta,
@@ -191,3 +200,18 @@ export function useListing(given, own = {}) {
191
200
  hold,
192
201
  };
193
202
  }
203
+ /**
204
+ * How a reading beside a listing — its groups, its pivot — asks the same set: the listing's
205
+ * entity through its `search`, beside the listing's input, with its definition.
206
+ */
207
+ export function readerOf(operations, listing) {
208
+ return (criteria, signal) => readPage(operations, listing.entity, criteria, {
209
+ input: listing.input,
210
+ meta: listing.meta,
211
+ ...(signal === undefined ? {} : { signal }),
212
+ });
213
+ }
214
+ /** A text that names what a listing reads — its entity and its input —, for an effect's deps. */
215
+ export function listingKeyOf(listing) {
216
+ return `${listing.entity.key} ${JSON.stringify(listing.input)}`;
217
+ }
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import {} from "@sincpro/client-framework";
2
+ import { readPage } from "@sincpro/client-framework";
3
3
  import { merge } from "@sincpro/criteria";
4
4
  import { isList } from "../core/list.js";
5
5
  import { lookupOf } from "../core/lookup.js";
@@ -24,7 +24,7 @@ export function excluding(criteria, exclude, meta) {
24
24
  export function useLookup(
25
25
  /** The entity, or a named list of it: «active customers» chooses only those. */
26
26
  entity, options = {}) {
27
- const { transport, metas, context } = useFramework();
27
+ const { operations, metas, context } = useFramework();
28
28
  const base = isList(entity) ? entity.entity : entity;
29
29
  // The key field to exclude by comes with the definition: known already, or with the first
30
30
  // answer — then this renders again and the reading starts over without the excluded.
@@ -55,7 +55,6 @@ entity, options = {}) {
55
55
  const missing = wanted.filter((id) => !seen.current.has(id));
56
56
  const missingKey = missing.join("\u0000");
57
57
  // Chosen but never seen (a form opened on a saved record): their names, asked ONCE by key.
58
- const route = base.list;
59
58
  const meta = listing.meta;
60
59
  useEffect(() => {
61
60
  if (missingKey === "" || meta === null)
@@ -63,13 +62,12 @@ entity, options = {}) {
63
62
  const keys = missingKey.split("\u0000");
64
63
  const key = meta.get_id || meta.identity || "id";
65
64
  const aborter = new AbortController();
66
- transport
67
- .list(route, {
65
+ readPage(operations, base, {
68
66
  selection: keys.length === 1
69
67
  ? { field: key, operator: "=", value: keys[0] ?? "" }
70
68
  : { field: key, operator: "in", value: keys },
71
69
  pagination: { limit: keys.length },
72
- }, aborter.signal)
70
+ }, { signal: aborter.signal, meta })
73
71
  .then((page) => {
74
72
  for (const one of lookupOf(meta, page.rows, base.summary))
75
73
  seen.current.set(one.id, one);
@@ -77,7 +75,7 @@ entity, options = {}) {
77
75
  })
78
76
  .catch(() => undefined); // unnamed is not an error: the field shows its key
79
77
  return () => aborter.abort();
80
- }, [transport, route, meta, missingKey, base.summary, context]);
78
+ }, [operations, base, meta, missingKey, context]);
81
79
  const known = value === "" ? undefined : seen.current.get(value);
82
80
  const chosenAll = wanted.map((id) => seen.current.get(id) ?? { id, label: id });
83
81
  return {
@@ -6,8 +6,8 @@ import { type Entity } from "@sincpro/client-framework";
6
6
  * Context: every name on screen is asked through the provider's book (`nameBook`): the keys asked
7
7
  * in the same moment — a page of 50 rows naming 50 tenants — go in ONE request per entity, and a
8
8
  * name already known is shared by every place that shows it. A write to the entity (a rename)
9
- * asks again. Unnamed is no error — the field shows the key — and an entity listed under another
10
- * record (`/tenants/{tenant_id}/members`) has no list to ask by key, so it stays unnamed.
9
+ * asks again. Unnamed is no error — the field shows the key — and an entity searched only under
10
+ * another record (its `search` names one) has no list to ask by key, so it stays unnamed.
11
11
  *
12
12
  * const name = useNameOf(tenants, record.tenant_id) ?? record.tenant_id;
13
13
  */
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { listRoute } from "@sincpro/client-framework";
2
+ import {} from "@sincpro/client-framework";
3
3
  import { entityFor } from "../core/relation.js";
4
4
  import { useFramework } from "./context.js";
5
5
  import { useWrites } from "./useWrites.js";
@@ -11,15 +11,15 @@ import { useEffect, useState } from "react";
11
11
  * Context: every name on screen is asked through the provider's book (`nameBook`): the keys asked
12
12
  * in the same moment — a page of 50 rows naming 50 tenants — go in ONE request per entity, and a
13
13
  * name already known is shared by every place that shows it. A write to the entity (a rename)
14
- * asks again. Unnamed is no error — the field shows the key — and an entity listed under another
15
- * record (`/tenants/{tenant_id}/members`) has no list to ask by key, so it stays unnamed.
14
+ * asks again. Unnamed is no error — the field shows the key — and an entity searched only under
15
+ * another record (its `search` names one) has no list to ask by key, so it stays unnamed.
16
16
  *
17
17
  * const name = useNameOf(tenants, record.tenant_id) ?? record.tenant_id;
18
18
  */
19
19
  export function useNameOf(entity, id) {
20
20
  const { names, context } = useFramework();
21
21
  const [named, setNamed] = useState(undefined);
22
- const writes = useWrites(entity === undefined ? undefined : routeOf(entity));
22
+ const writes = useWrites(entity);
23
23
  useEffect(() => {
24
24
  if (entity === undefined || id === "")
25
25
  return;
@@ -64,12 +64,3 @@ export function useNamesOf(asked) {
64
64
  return (target, id) => named.get(nameKey(target, id));
65
65
  }
66
66
  const nameKey = (target, id) => `${target}\u0000${id}`;
67
- /** Where `entity` is listed — or nothing to follow when it is listed only under a record. */
68
- function routeOf(entity) {
69
- try {
70
- return listRoute(entity.list);
71
- }
72
- catch {
73
- return undefined;
74
- }
75
- }
@@ -1,6 +1,6 @@
1
1
  import type { AnyRecord, Bucket } from "@sincpro/criteria";
2
2
  import type { GroupLevel } from "../core/list.js";
3
- import type { Listing } from "./useListing.js";
3
+ import { type Listing } from "./useListing.js";
4
4
  /**
5
5
  * A list's set crossed by two fields — state by month, customer by payment — counted and added
6
6
  * up by the SERVER over every row that matches, never the page.
@@ -2,12 +2,13 @@
2
2
  import { areGroups, NotGrouped } from "../core/groups.js";
3
3
  import { measuresOf, sumsOf } from "../core/measure.js";
4
4
  import { useFramework } from "./context.js";
5
+ import { listingKeyOf, readerOf, } from "./useListing.js";
5
6
  import { useWrites } from "./useWrites.js";
6
- import { useEffect, useState } from "react";
7
+ import { useEffect, useMemo, useState } from "react";
7
8
  /** The most groups an axis answers: a pivot of ten thousand rows is a list. */
8
9
  const MAX_KEYS = 100;
9
10
  export function usePivot(listing, axes) {
10
- const { transport, context } = useFramework();
11
+ const { operations, context } = useFramework();
11
12
  const [state, setState] = useState({
12
13
  status: "idle",
13
14
  crossed: [],
@@ -23,7 +24,12 @@ export function usePivot(listing, axes) {
23
24
  const shape = axes === null ? "" : JSON.stringify([axes.rows, axes.columns]);
24
25
  const waiting = axes !== null && axes.measures === undefined && listing.meta === null;
25
26
  // Written by anyone — a save, a use case, a panel beside: the crossing is counted again.
26
- const writes = useWrites(listing.route);
27
+ const writes = useWrites(listing.entity);
28
+ const entityKey = listing.entity.key;
29
+ const read = useMemo(() => readerOf(operations, listing),
30
+ // What it reads is its entity and input (`listingKeyOf`) under its definition.
31
+ // eslint-disable-next-line react-hooks/exhaustive-deps
32
+ [operations, listingKeyOf(listing), listing.meta]);
27
33
  useEffect(() => {
28
34
  if (shape === "") {
29
35
  setState({ status: "idle", crossed: [], columns: [], error: null });
@@ -46,8 +52,8 @@ export function usePivot(listing, axes) {
46
52
  pagination: { limit: 1 },
47
53
  });
48
54
  Promise.all([
49
- transport.list(listing.route, grouped([rows, columns]), aborter.signal),
50
- transport.list(listing.route, grouped([columns]), aborter.signal),
55
+ read(grouped([rows, columns]), aborter.signal),
56
+ read(grouped([columns]), aborter.signal),
51
57
  ]).then(([crossed, byColumn]) => {
52
58
  if (aborter.signal.aborted)
53
59
  return;
@@ -57,7 +63,7 @@ export function usePivot(listing, axes) {
57
63
  status: "failed",
58
64
  crossed: [],
59
65
  columns: [],
60
- error: new NotGrouped(listing.route),
66
+ error: new NotGrouped(entityKey),
61
67
  });
62
68
  else
63
69
  setState({
@@ -71,6 +77,6 @@ export function usePivot(listing, axes) {
71
77
  setState({ status: "failed", crossed: [], columns: [], error });
72
78
  });
73
79
  return () => aborter.abort();
74
- }, [transport, listing.route, question, shape, measured, waiting, context, writes]);
80
+ }, [read, entityKey, question, shape, measured, waiting, context, writes]);
75
81
  return { ...state, measures };
76
82
  }