@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
@@ -1,6 +1,6 @@
1
1
  "use client";
2
- import { newEntityId, pathFor, retryKeys, startingValuesOf, TransportError, WITH_PARAM, } from "@sincpro/client-framework";
3
- import { canCreate, changesOf, computedLocally, creationOf, defaultsOf, editedOf, errorsByField, fieldStateOf, lineStatesOf, missingOf, needsPreview, } from "../core/edit.js";
2
+ import { newEntityId, readRecord, retryKeys, startingValuesOf, TransportError, WITH_PARAM, } from "@sincpro/client-framework";
3
+ import { canCreate, changesOf, computedLocally, creationOf, defaultsOf, editedOf, errorsByField, fieldStateOf, lineStatesOf, missingOf, needsPreview, withTargetsOf, } from "../core/edit.js";
4
4
  import { linesAnswered } from "../core/lines.js";
5
5
  import { useFramework } from "./context.js";
6
6
  import { useWrites } from "./useWrites.js";
@@ -8,7 +8,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
8
8
  /** How long typing has to pause before the server is asked what the record becomes. */
9
9
  const PREVIEW_PAUSE = 300;
10
10
  export function useRecord(entity, opened, options = {}) {
11
- const { transport, locale, metas, context } = useFramework();
11
+ const { operations, locale, metas, context } = useFramework();
12
12
  const given = typeof opened === "string" ? opened : (opened.id ?? "");
13
13
  // As written in the reference: a text compares by value, so a new render with the same
14
14
  // reference is not a new start.
@@ -58,7 +58,7 @@ export function useRecord(entity, opened, options = {}) {
58
58
  // their order): on mount it is not asked again — nor in React's second mount of the same
59
59
  // question (StrictMode). Any other question (a `reload()`, another id, another transport)
60
60
  // reads as always.
61
- const answered = useRef(served === undefined ? null : [transport, metas, entity, given, given === "", start, 0]);
61
+ const answered = useRef(served === undefined ? null : [operations, metas, entity, given, given === "", start, 0]);
62
62
  // A server that answers the record FROM the draft (sincpro_framework) sends no values apart:
63
63
  // the record is the draft. One that sends them apart, they are what was typed.
64
64
  const [typed, setTyped] = useState(() => served?.draft?.values ?? {});
@@ -69,6 +69,8 @@ export function useRecord(entity, opened, options = {}) {
69
69
  const [advice, setAdvice] = useState([]);
70
70
  const [saving, setSaving] = useState(false);
71
71
  const [failure, setFailure] = useState(null);
72
+ // The fields written since the last refusal: what the server said of them no longer holds.
73
+ const [rewritten, setRewritten] = useState(() => new Set());
72
74
  const [conflict, setConflict] = useState(false);
73
75
  const [draft, setDraft] = useState(served?.draft ?? null);
74
76
  const pause = useRef(null);
@@ -93,7 +95,7 @@ export function useRecord(entity, opened, options = {}) {
93
95
  };
94
96
  useEffect(() => {
95
97
  // The server's question (`initial`) is answered already: nothing to read.
96
- const asked = [transport, metas, entity, id, isNew, start, round];
98
+ const asked = [operations, metas, entity, id, isNew, start, round];
97
99
  const before = answered.current;
98
100
  if (before !== null && asked.every((one, at) => Object.is(one, before[at])))
99
101
  return;
@@ -106,14 +108,8 @@ export function useRecord(entity, opened, options = {}) {
106
108
  if (!again)
107
109
  setState((now) => ({ status: "loading", record: null, meta: now.meta, error: null }));
108
110
  if (isNew) {
109
- // Nothing to read but the model: known already, or asked of the list with no rows.
110
- const known = metas.get(entity.key);
111
- const asked = known
112
- ? Promise.resolve(known)
113
- : transport
114
- .list(entity.list, { pagination: { limit: 1 } }, aborter.signal)
115
- .then((page) => page.meta);
116
- asked.then((meta) => {
111
+ // Nothing to read but the model: the contract's, or a face's (`ModelDefinitions`).
112
+ Promise.resolve(metas.get(entity.key) ?? null).then((meta) => {
117
113
  if (meta)
118
114
  metas.set(entity.key, meta);
119
115
  if (aborter.signal.aborted)
@@ -136,7 +132,10 @@ export function useRecord(entity, opened, options = {}) {
136
132
  });
137
133
  return () => aborter.abort();
138
134
  }
139
- transport.one(entity.one(id), aborter.signal).then((answer) => {
135
+ readRecord(operations, entity, id, {
136
+ signal: aborter.signal,
137
+ meta: metas.get(entity.key) ?? null,
138
+ }).then((answer) => {
140
139
  if (answer.meta)
141
140
  metas.set(entity.key, answer.meta);
142
141
  if (aborter.signal.aborted)
@@ -162,9 +161,9 @@ export function useRecord(entity, opened, options = {}) {
162
161
  });
163
162
  return () => aborter.abort();
164
163
  // `forget` only resets this hook's own state; listing it would reload the record on every
165
- // render. What reloads it is the transport, the entity, the id or an explicit `reload()`.
164
+ // render. What reloads it is the operations, the entity, the id or an explicit `reload()`.
166
165
  // eslint-disable-next-line react-hooks/exhaustive-deps
167
- }, [transport, metas, entity, id, isNew, start, round]);
166
+ }, [operations, metas, entity, id, isNew, start, round]);
168
167
  useEffect(() => {
169
168
  mounted.current = true;
170
169
  return () => {
@@ -177,7 +176,7 @@ export function useRecord(entity, opened, options = {}) {
177
176
  // panel beside —: a record with nothing typed reads again; one being edited keeps what was
178
177
  // typed — losing it is never the framework's decision, and its save still meets the version
179
178
  // it read (a 409 when someone saved). Its own save reads it again by itself.
180
- const writes = useWrites(isNew ? undefined : entity.one(id));
179
+ const writes = useWrites(isNew ? undefined : entity);
181
180
  const askedFor = useRef({ context, writes });
182
181
  useEffect(() => {
183
182
  if (askedFor.current.context === context && askedFor.current.writes === writes)
@@ -192,16 +191,15 @@ export function useRecord(entity, opened, options = {}) {
192
191
  const version = record["version"];
193
192
  // sincpro_framework's `Edit` names a record by `id`; a model keyed by another field (an
194
193
  // invoice's number, the server's to give) is still created through `create`.
194
+ const editing = entity.operations.edit;
195
195
  const byEdit = isNew &&
196
- entity.edit !== undefined &&
196
+ editing !== undefined &&
197
197
  (state.meta?.get_id || state.meta?.identity || "id") === "id";
198
198
  // Whether anything can store this record: a new one by `create` (or `Edit` under a minted
199
- // key), a stored one by `edit`/`save`. A payment or an order that only Commands move has
199
+ // key), a stored one by `edit`. A payment or an order that only Commands move has
200
200
  // neither — every field of it is read only, whatever the model's hints say: an input nothing
201
201
  // can save is an invitation that lies.
202
- const writable = isNew
203
- ? canCreate(entity, state.meta)
204
- : (entity.edit ?? entity.save) !== undefined;
202
+ const writable = isNew ? canCreate(entity, state.meta) : editing !== undefined;
205
203
  /** The record's key for a write: its own, or the one minted for it while it is new. */
206
204
  const keyNow = () => {
207
205
  if (!byEdit)
@@ -211,7 +209,7 @@ export function useRecord(entity, opened, options = {}) {
211
209
  return minted.current.key;
212
210
  };
213
211
  const ask = (next, name) => {
214
- const preview = entity.preview;
212
+ const preview = entity.operations.preview;
215
213
  const field = name.split(".")[0] ?? name;
216
214
  // What the server wrote down is computed here, as it would: a change whose every reach has
217
215
  // a formula needs the server only for a rule that judges it.
@@ -228,23 +226,16 @@ export function useRecord(entity, opened, options = {}) {
228
226
  return;
229
227
  cancelPreview();
230
228
  pause.current = setTimeout(() => {
231
- // A key of the route (`{tenant_id}`) is a field of the record on screen. One it lacks is
232
- // a preview not asked — never an error thrown out of a timer.
233
- let path;
234
- try {
235
- path = pathFor(preview, isNew ? undefined : id, { ...record, ...next });
236
- }
237
- catch {
238
- return;
239
- }
229
+ // What it names besides the edit (`tenant_id`) is a field of the record on screen; a
230
+ // preview the server cannot answer is a preview not shown — never an error out of a timer.
240
231
  const aborter = new AbortController();
241
232
  asking.current = aborter;
242
- transport
243
- .send(preview.method, path, {
233
+ operations
234
+ .call(preview, withTargetsOf(preview, { ...record, ...next }, {
244
235
  id: isNew ? null : id,
245
236
  values: isNew ? { ...record, ...next } : changesOf(record, next),
246
237
  changed: [name],
247
- }, aborter.signal)
238
+ }), { signal: aborter.signal })
248
239
  .then((answer) => {
249
240
  if (aborter.signal.aborted || !mounted.current)
250
241
  return;
@@ -270,8 +261,10 @@ export function useRecord(entity, opened, options = {}) {
270
261
  const refused = (error) => {
271
262
  if (error instanceof TransportError && error.problem?.kind === "conflict")
272
263
  setConflict(true);
273
- else
264
+ else {
274
265
  setFailure(error);
266
+ setRewritten(new Set());
267
+ }
275
268
  };
276
269
  // sincpro_framework's `Edit`: what the form writes; the fields changed; the draft version read
277
270
  // (`0`: none) — another tab that kept first wins —, and the stored version the edit started
@@ -299,6 +292,8 @@ export function useRecord(entity, opened, options = {}) {
299
292
  const next = { ...typedNow.current, [name]: value };
300
293
  typedNow.current = next;
301
294
  setTyped(next);
295
+ if (failure !== null && !rewritten.has(name))
296
+ setRewritten((before) => new Set(before).add(name));
302
297
  ask(next, name);
303
298
  },
304
299
  writable,
@@ -312,7 +307,11 @@ export function useRecord(entity, opened, options = {}) {
312
307
  const said = fieldStateOf(definition, field, line ?? {}, lineStatesOf(fromServer, name, line, index, definition?.identity || "id"));
313
308
  return writable ? said : { ...said, readonly: true, required: false };
314
309
  },
315
- errors: failure instanceof TransportError ? errorsByField(failure.problem?.errors) : {},
310
+ // A refusal's word on a field holds until the field is written again: corrected, it is
311
+ // the next save's to judge — a flow would otherwise stay blocked by what no longer holds.
312
+ errors: failure instanceof TransportError
313
+ ? Object.fromEntries(Object.entries(errorsByField(failure.problem?.errors)).filter(([at]) => !rewritten.has(at.split("/")[0] ?? at)))
314
+ : {},
316
315
  advice,
317
316
  missing: missingOf(state.meta, values, fromServer),
318
317
  saving,
@@ -325,23 +324,19 @@ export function useRecord(entity, opened, options = {}) {
325
324
  save: async () => {
326
325
  if (isNew && !byEdit)
327
326
  return create();
328
- const route = entity.edit ?? entity.save;
329
- if (route === undefined)
330
- throw new Error(`${entity.key} declares no save route`);
327
+ if (editing === undefined)
328
+ throw new Error(`${entity.key} has no edit`);
331
329
  cancelPreview();
332
330
  setSaving(true);
333
331
  setFailure(null);
334
- const key = keyNow();
335
332
  try {
336
- await transport.send(route.method, pathFor(route, key, values), entity.edit === undefined
337
- ? { ...changed, ...(version === undefined ? {} : { version }) }
338
- : editOf("save"));
333
+ await operations.call(editing, withTargetsOf(editing, values, editOf("save")));
339
334
  setDraft(null);
340
335
  // Stored under the key it was born with: the hook becomes that record and reads it.
341
336
  if (isNew) {
342
337
  if (mounted.current) {
343
338
  forget();
344
- setBorn({ from: given, id: key });
339
+ setBorn({ from: given, id: keyNow() });
345
340
  }
346
341
  }
347
342
  else
@@ -363,25 +358,22 @@ export function useRecord(entity, opened, options = {}) {
363
358
  discard: () => {
364
359
  forget();
365
360
  // The draft lives on the server: discarding only here would bring it back on the next read.
366
- const route = entity.edit;
367
- if (route === undefined || draft === null)
361
+ if (editing === undefined || draft === null)
368
362
  return;
369
363
  setDraft(null);
370
- // Through the promise: a route key the record lacks is refused like any failure.
371
- Promise.resolve()
372
- .then(() => transport.send(route.method, pathFor(route, keyNow(), values), editOf("discard")))
364
+ operations
365
+ .call(editing, withTargetsOf(editing, values, editOf("discard")))
373
366
  .then(() => mounted.current && reload())
374
367
  .catch((error) => mounted.current && refused(error));
375
368
  },
376
369
  created,
377
370
  // A draft is kept against a record: a stored one, or a new one born by `Edit` under its key.
378
- ...((entity.edit ?? entity.draft) === undefined || (isNew && !byEdit)
371
+ ...(editing === undefined || (isNew && !byEdit)
379
372
  ? {}
380
373
  : {
381
374
  keep: async () => {
382
- const route = (entity.edit ?? entity.draft);
383
375
  try {
384
- const kept = await transport.send(route.method, pathFor(route, keyNow(), values), entity.edit === undefined ? editOf() : editOf("save_draft"));
376
+ const kept = await operations.call(editing, withTargetsOf(editing, values, editOf("save_draft")));
385
377
  const now = kept.draft;
386
378
  if (now)
387
379
  setDraft({
@@ -399,9 +391,9 @@ export function useRecord(entity, opened, options = {}) {
399
391
  }),
400
392
  };
401
393
  async function create() {
402
- const route = entity.create;
403
- if (route === undefined)
404
- throw new Error(`${entity.key} declares no create route`);
394
+ const creator = entity.operations.commands?.create;
395
+ if (creator === undefined)
396
+ throw new Error(`${entity.key} has no create`);
405
397
  cancelPreview();
406
398
  setSaving(true);
407
399
  setFailure(null);
@@ -409,7 +401,7 @@ export function useRecord(entity, opened, options = {}) {
409
401
  const body = creationOf(state.meta, values);
410
402
  const idempotencyKey = creating.current.keyFor(body);
411
403
  try {
412
- const answer = await transport.send(route.method, pathFor(route, undefined, body), body, undefined, { idempotencyKey });
404
+ const answer = await operations.call(creator, body, { idempotencyKey });
413
405
  creating.current.settle(null);
414
406
  if (!mounted.current)
415
407
  return true;
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { useRouteCommand, } from "./useCommand.js";
2
+ import { useOperationCommand, } from "./useCommand.js";
3
3
  /**
4
4
  * The record's own lifecycle, as actions of ONE stored record: what its entity declares of
5
5
  * sincpro_framework's `Delete` (`entity.delete`) and its trash (`entity.archive`,
@@ -21,9 +21,10 @@ import { useRouteCommand, } from "./useCommand.js";
21
21
  */
22
22
  export function useRecordLifecycle(record) {
23
23
  const { entity } = record;
24
- const deletion = useRouteCommand(entity.delete, entity.key);
25
- const archival = useRouteCommand(entity.archive, entity.key);
26
- const restoral = useRouteCommand(entity.restore, entity.key);
24
+ const { delete: remove, archive, restore } = entity.operations;
25
+ const deletion = useOperationCommand(entity, remove);
26
+ const archival = useOperationCommand(entity, archive);
27
+ const restoral = useOperationCommand(entity, restore);
27
28
  const stored = !record.isNew && record.status === "ready";
28
29
  if (!stored)
29
30
  return {};
@@ -40,10 +41,8 @@ export function useRecordLifecycle(record) {
40
41
  reset: command.reset,
41
42
  });
42
43
  return {
43
- ...(entity.delete === undefined ? {} : { delete: action(deletion, true) }),
44
- ...(entity.archive === undefined || archived ? {} : { archive: action(archival, false) }),
45
- ...(entity.restore === undefined || !archived
46
- ? {}
47
- : { restore: action(restoral, false) }),
44
+ ...(remove === undefined ? {} : { delete: action(deletion, true) }),
45
+ ...(archive === undefined || archived ? {} : { archive: action(archival, false) }),
46
+ ...(restore === undefined || !archived ? {} : { restore: action(restoral, false) }),
48
47
  };
49
48
  }
@@ -1,17 +1,8 @@
1
1
  "use client";
2
- import { listRoute } from "@sincpro/client-framework";
2
+ import {} from "@sincpro/client-framework";
3
3
  import { touches } from "../core/changes.js";
4
4
  import { useFramework } from "./context.js";
5
5
  import { useCallback, useEffect, useRef, useState } from "react";
6
- /** Where `entity` is listed — or nothing to follow when it is listed only under a record. */
7
- function routeOf(entity) {
8
- try {
9
- return listRoute(entity.list);
10
- }
11
- catch {
12
- return undefined;
13
- }
14
- }
15
6
  /**
16
7
  * A use case that READS, run by the screen that shows it: on mount, again whenever its
17
8
  * arguments change, when the process's context changes (another company), and when a write
@@ -45,7 +36,7 @@ function routeOf(entity) {
45
36
  * const perfil = useServiceReading(cuentas.perfil, [usuario], { enabled: usuario !== "" });
46
37
  */
47
38
  export function useServiceReading(useCase, args, options = {}) {
48
- const { context, changes, entities } = useFramework();
39
+ const { context, changes } = useFramework();
49
40
  const key = JSON.stringify(args);
50
41
  const latest = useRef({ useCase, args });
51
42
  latest.current = { useCase, args };
@@ -57,19 +48,16 @@ export function useServiceReading(useCase, args, options = {}) {
57
48
  const [again, setAgain] = useState(0);
58
49
  const enabled = options.enabled ?? true;
59
50
  // A write anyone sends — a save, another use case, a panel beside — to what it follows.
60
- const followed = (options.follows ?? [])
61
- .map(routeOf)
62
- .filter((route) => route !== undefined)
63
- .join("\n");
51
+ const followed = (options.follows ?? []).map((one) => one.model).join("\n");
64
52
  useEffect(() => {
65
53
  if (followed === "")
66
54
  return;
67
- const routes = followed.split("\n");
55
+ const models = followed.split("\n");
68
56
  return changes.follow((change) => {
69
- if (routes.some((route) => touches(change, route, entities)))
57
+ if (models.some((model) => touches(change, { model })))
70
58
  setAgain((n) => n + 1);
71
59
  });
72
- }, [changes, entities, followed]);
60
+ }, [changes, followed]);
73
61
  useEffect(() => {
74
62
  if (!enabled)
75
63
  return;
@@ -27,7 +27,8 @@ export function useUpload(about, own) {
27
27
  useEffect(() => () => running.current?.abort(), []);
28
28
  const send = useCallback(async (file) => {
29
29
  const { about: target, uploads: where, transport: wire } = now.current;
30
- if (where === undefined)
30
+ // Where the bytes go is REST's transport: without it, nothing is sent.
31
+ if (where === undefined || wire === undefined)
31
32
  return undefined;
32
33
  running.current?.abort();
33
34
  const control = new AbortController();
@@ -65,5 +66,11 @@ export function useUpload(about, own) {
65
66
  }, []);
66
67
  const cancel = useCallback(() => running.current?.abort(), []);
67
68
  const retry = useCallback(() => (last.current === null ? Promise.resolve(undefined) : send(last.current)), [send]);
68
- return { available: uploads !== undefined, ...state, send, cancel, retry };
69
+ return {
70
+ available: uploads !== undefined && transport !== undefined,
71
+ ...state,
72
+ send,
73
+ cancel,
74
+ retry,
75
+ };
69
76
  }
@@ -1,19 +1,20 @@
1
+ import type { Entity } from "@sincpro/client-framework";
1
2
  /**
2
- * How many times what lies at `route` was written since this screen started reading it — a
3
- * dependency that makes a reading read again.
3
+ * How many times `entity` was written since this screen started reading it — a dependency that
4
+ * makes a reading read again.
4
5
  *
5
- * const writes = useWrites(listRoute(entity.list));
6
- * useEffect(() => { … transport.list(…) … }, [transport, route, writes]);
6
+ * const writes = useWrites(entity);
7
+ * useEffect(() => { … readPage(operations, entity, …) … }, [operations, entity, writes]);
7
8
  *
8
9
  * Context: a screen must show what is true now, whoever wrote it — its own save, a use case run
9
- * from a button, a panel beside it. Every write a transport of the framework sends is announced
10
- * on the process's change feed (`processChanges`, @sincpro/client-framework); this follows it and
11
- * counts the ones that touch `route` (`touches`: the collections a write names, and an entity's
12
- * history). A reading adds the count to what it reads by, as it adds the company it reads in: the
13
- * framework's own readings do (`useListing`, `useRecord`, `useHistory`, `useGroups`, `usePivot`,
14
- * `useNameOf`), and so may a screen's own. It reads again on the next render, when the cache under
15
- * it — following the same feed — has already forgotten the old answer.
10
+ * from a button, a panel beside it. Every write an operation adapter of the framework sends is
11
+ * announced on the process's change feed (`processChanges`, @sincpro/client-framework); this
12
+ * follows it and counts the ones that name the entity (`touches`) — its lists, its records and
13
+ * their history alike. A reading adds the count to what it reads by, as it adds the company it
14
+ * reads in: the framework's own readings do (`useListing`, `useRecord`, `useHistory`, `useGroups`,
15
+ * `usePivot`, `useNameOf`), and so may a screen's own. It reads again on the next render, when
16
+ * the cache under it — following the same feed — has already forgotten the old answer.
16
17
  *
17
18
  * `undefined`: nothing is read yet, and nothing is counted.
18
19
  */
19
- export declare function useWrites(route: string | undefined): number;
20
+ export declare function useWrites(entity: Pick<Entity, "model"> | undefined): number;
@@ -3,33 +3,34 @@ import { touches } from "../core/changes.js";
3
3
  import { useFramework } from "./context.js";
4
4
  import { useEffect, useState } from "react";
5
5
  /**
6
- * How many times what lies at `route` was written since this screen started reading it — a
7
- * dependency that makes a reading read again.
6
+ * How many times `entity` was written since this screen started reading it — a dependency that
7
+ * makes a reading read again.
8
8
  *
9
- * const writes = useWrites(listRoute(entity.list));
10
- * useEffect(() => { … transport.list(…) … }, [transport, route, writes]);
9
+ * const writes = useWrites(entity);
10
+ * useEffect(() => { … readPage(operations, entity, …) … }, [operations, entity, writes]);
11
11
  *
12
12
  * Context: a screen must show what is true now, whoever wrote it — its own save, a use case run
13
- * from a button, a panel beside it. Every write a transport of the framework sends is announced
14
- * on the process's change feed (`processChanges`, @sincpro/client-framework); this follows it and
15
- * counts the ones that touch `route` (`touches`: the collections a write names, and an entity's
16
- * history). A reading adds the count to what it reads by, as it adds the company it reads in: the
17
- * framework's own readings do (`useListing`, `useRecord`, `useHistory`, `useGroups`, `usePivot`,
18
- * `useNameOf`), and so may a screen's own. It reads again on the next render, when the cache under
19
- * it — following the same feed — has already forgotten the old answer.
13
+ * from a button, a panel beside it. Every write an operation adapter of the framework sends is
14
+ * announced on the process's change feed (`processChanges`, @sincpro/client-framework); this
15
+ * follows it and counts the ones that name the entity (`touches`) — its lists, its records and
16
+ * their history alike. A reading adds the count to what it reads by, as it adds the company it
17
+ * reads in: the framework's own readings do (`useListing`, `useRecord`, `useHistory`, `useGroups`,
18
+ * `usePivot`, `useNameOf`), and so may a screen's own. It reads again on the next render, when
19
+ * the cache under it — following the same feed — has already forgotten the old answer.
20
20
  *
21
21
  * `undefined`: nothing is read yet, and nothing is counted.
22
22
  */
23
- export function useWrites(route) {
24
- const { changes, entities } = useFramework();
23
+ export function useWrites(entity) {
24
+ const { changes } = useFramework();
25
25
  const [writes, setWrites] = useState(0);
26
+ const model = entity?.model;
26
27
  useEffect(() => {
27
- if (route === undefined)
28
+ if (model === undefined)
28
29
  return;
29
30
  return changes.follow((change) => {
30
- if (touches(change, route, entities))
31
+ if (touches(change, { model }))
31
32
  setWrites((count) => count + 1);
32
33
  });
33
- }, [changes, entities, route]);
34
+ }, [changes, model]);
34
35
  return writes;
35
36
  }
@@ -0,0 +1,112 @@
1
+ /**
2
+ * A dashboard: ONE period chosen above everything, and every tile reading its own entity over it
3
+ * — figures, charts —, each saying in its own place whether it is reading, ready or refused.
4
+ *
5
+ * <Dashboard title="Ventas y cobros" periods={PERIODS}
6
+ * stats={<>
7
+ * <Dashboard.Count entity={invoices} over="invoice_date" label="Facturas emitidas" />
8
+ * <Dashboard.Count entity={payments} over="sent_on" label="Pagos recibidos" />
9
+ * </>}>
10
+ * <Dashboard.Chart entity={invoices} over="invoice_date" title="Facturas por mes"
11
+ * rows={{ field: "invoice_date", grain: "month" }} columns={{ field: "state" }} />
12
+ * </Dashboard>
13
+ *
14
+ * Context: web-ui's `Board` draws the tiles and folds nothing; what it asks of the application —
15
+ * one filter row that scopes EVERY tile, one state per tile — is what every board wrote by hand,
16
+ * N readings that each built its own cut and mapped its own status (#30). Here the root holds the
17
+ * period and gives it to its parts by context; a tile names the field the period cuts on (`over`,
18
+ * each entity has its own date), and its reading ANDs that cut under its own criteria. A tile
19
+ * that names no `over` is not cut — said in code, never by accident. What a tile reads is counted
20
+ * and summed by the SERVER (`useListing`'s count, `usePivot`): never a page folded here.
21
+ *
22
+ * Three levels, as every root here: the root and its parts; the hooks (`useBoardListing`,
23
+ * `useBoardPeriod`, `boardStateOf`) for a tile of the application's own — a table, a list, a
24
+ * map — inside the same board; and web-ui's `Board` below them, for a board with no period.
25
+ */
26
+ import type { Entity, EntityOperations } from "@sincpro/client-framework";
27
+ import { type AnyRecord, type Criteria, type Expression, type Period } from "@sincpro/criteria";
28
+ import type { GroupLevel } from "../../core/list.js";
29
+ import { type Listing } from "../../react/useListing.js";
30
+ import { type BoardState, type ChartKind, type Tone } from "@sincpro/web-ui";
31
+ import type { LucideIcon } from "lucide-react";
32
+ import { type ReactNode } from "react";
33
+ /**
34
+ * A span a board may be read over: a period the server names (`dynamic.period("this_month")`,
35
+ * read on ITS calendar and zone) or two days, both included.
36
+ */
37
+ export type BoardPeriod = {
38
+ id: string;
39
+ label: string;
40
+ range: Period | readonly [string, string];
41
+ };
42
+ /** The period of the board around, or none outside a board. */
43
+ export declare function useBoardPeriod(): BoardPeriod | null;
44
+ /** The cut a period makes on a field: `field between range`. */
45
+ export declare function periodCut<T extends AnyRecord>(period: BoardPeriod, over: string): Expression<T>;
46
+ export type BoardReadingOptions<T> = {
47
+ /** The date the board's period cuts this reading on. Without it, the period does not. */
48
+ over?: string;
49
+ /** What this tile always asks: the period ANDs under it. */
50
+ criteria?: Criteria<T>;
51
+ };
52
+ /**
53
+ * A listing of `entity` as a board tile reads it: one row a page (the count and the question are
54
+ * what a tile wants), cut by the board's period over `over`.
55
+ */
56
+ export declare function useBoardListing<T extends AnyRecord, O extends EntityOperations = EntityOperations>(entity: Entity<T, O>, { over, criteria }?: BoardReadingOptions<T>): Listing<T, O>;
57
+ /**
58
+ * web-ui's state of a tile from a reading: reading while it asks, the refusal in the server's
59
+ * words when it failed — with «Reintentar» when there is a way to ask again.
60
+ */
61
+ export declare function boardStateOf(reading: {
62
+ status: string;
63
+ error: unknown;
64
+ }, retry?: () => void): BoardState;
65
+ export type DashboardProps = {
66
+ title: string;
67
+ description?: ReactNode;
68
+ /** The spans offered, in order; the first is read unless `defaultPeriod` says otherwise. */
69
+ periods?: readonly BoardPeriod[];
70
+ /** The period read first, by id, when the board holds it. */
71
+ defaultPeriod?: string;
72
+ /** The period on screen, by id, when the screen holds it (a window's `params`). */
73
+ period?: string;
74
+ onPeriodChange?: (id: string) => void;
75
+ /** The headline figures: `Dashboard.Count`s, read before the tiles. */
76
+ stats?: ReactNode;
77
+ /** The tiles: `Dashboard.Chart`, or a web-ui `BoardTile` the screen reads itself. */
78
+ children: ReactNode;
79
+ };
80
+ /** The root: the period row above every tile, and the period given to each. */
81
+ export declare function Dashboard({ title, description, periods, defaultPeriod, period: controlled, onPeriodChange, stats, children, }: DashboardProps): import("react").JSX.Element;
82
+ export declare namespace Dashboard {
83
+ var Count: <T extends AnyRecord>({ entity, over, criteria, label, icon, hint, hero, tone, }: BoardReadingOptions<T> & TileLook & {
84
+ entity: Entity<T>;
85
+ label: string;
86
+ /** The one figure the board leads with. */
87
+ hero?: boolean;
88
+ /** The state the figure means — say why in `hint`. */
89
+ tone?: Tone;
90
+ }) => import("react").JSX.Element;
91
+ var Chart: typeof ChartTile;
92
+ }
93
+ type TileLook = {
94
+ icon?: LucideIcon;
95
+ hint?: ReactNode;
96
+ };
97
+ /**
98
+ * A tile that crosses `entity` by two fields — the rows below, the columns as series — counted,
99
+ * or added up by `measure`, by the server over the board's period.
100
+ */
101
+ declare function ChartTile<T extends AnyRecord>({ entity, over, criteria, title, icon, hint, description, rows, columns, measure, kind, span, }: BoardReadingOptions<T> & TileLook & {
102
+ entity: Entity<T>;
103
+ title: string;
104
+ description?: ReactNode;
105
+ rows: GroupLevel;
106
+ columns: GroupLevel;
107
+ /** The field added up in each crossing; the count without it. */
108
+ measure?: string;
109
+ kind?: ChartKind;
110
+ span?: 1 | 2 | "full";
111
+ }): import("react").JSX.Element;
112
+ export {};