@sincpro/web-framework 3.20.0 → 3.22.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.
- package/README.md +59 -58
- package/dist/core/copy.d.ts +4 -0
- package/dist/core/copy.js +2 -0
- package/dist/react/useRecord.js +12 -2
- package/dist/web/board/Dashboard.d.ts +112 -0
- package/dist/web/board/Dashboard.js +106 -0
- package/dist/web/board/index.d.ts +1 -0
- package/dist/web/board/index.js +1 -0
- package/dist/web/index.d.ts +3 -1
- package/dist/web/index.js +3 -1
- package/dist/web/record/Wizard.d.ts +65 -0
- package/dist/web/record/Wizard.js +90 -0
- package/dist/web/workspace/RecordScreen.d.ts +17 -1
- package/dist/web/workspace/RecordScreen.js +33 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -702,64 +702,65 @@ find .next/static -name '*.map' -delete
|
|
|
702
702
|
Each answers one question, and each comes in the three levels — use the component, drop to the
|
|
703
703
|
hook and draw your own, or go straight to the loose piece.
|
|
704
704
|
|
|
705
|
-
| Question
|
|
706
|
-
|
|
|
707
|
-
| Where is the data?
|
|
708
|
-
| The application's logic
|
|
709
|
-
| Read through a use case
|
|
710
|
-
| Read it on the server first
|
|
711
|
-
| A record read on the server
|
|
712
|
-
| What every use case runs with
|
|
713
|
-
| What happened, what broke
|
|
714
|
-
| What happened, on the server
|
|
715
|
-
| What broke, on the server
|
|
716
|
-
| A page that broke
|
|
717
|
-
| What is each field?
|
|
718
|
-
| A value outside a model
|
|
719
|
-
| A file or a photo it holds
|
|
720
|
-
| A file given in the record
|
|
721
|
-
| Formatted text
|
|
722
|
-
| A person, read
|
|
723
|
-
| A choice's tag outside a list
|
|
724
|
-
| What is a record, at any size?
|
|
725
|
-
| How does a record look?
|
|
726
|
-
| N records: search, filter, page
|
|
727
|
-
| A named slice (to collect, …)
|
|
728
|
-
| A record's whole screen
|
|
729
|
-
| One region of a record screen
|
|
730
|
-
| One region of a list
|
|
731
|
-
| The models a face brings
|
|
732
|
-
| What a record screen says of it
|
|
733
|
-
| What hangs off a record, counted
|
|
734
|
-
|
|
|
735
|
-
|
|
|
736
|
-
|
|
|
737
|
-
|
|
|
738
|
-
|
|
|
739
|
-
|
|
|
740
|
-
|
|
|
741
|
-
|
|
|
742
|
-
|
|
|
743
|
-
| Its
|
|
744
|
-
|
|
|
745
|
-
|
|
|
746
|
-
| Choose
|
|
747
|
-
|
|
|
748
|
-
|
|
|
749
|
-
|
|
|
750
|
-
|
|
|
751
|
-
|
|
|
752
|
-
|
|
|
753
|
-
|
|
|
754
|
-
|
|
|
755
|
-
|
|
|
756
|
-
| A
|
|
757
|
-
| A
|
|
758
|
-
|
|
|
759
|
-
|
|
|
760
|
-
|
|
|
761
|
-
|
|
|
762
|
-
|
|
|
705
|
+
| Question | Declarative | Hook | Loose piece |
|
|
706
|
+
| ------------------------------------- | -------------------------------------------------------------------------- | ------------------------------------- | ------------------------------------------------------------ |
|
|
707
|
+
| Where is the data? | `entity()` (client-framework) | — | `restTransport`, `memoryTransport` |
|
|
708
|
+
| The application's logic | its `Feature`s and `ApplicationService`s (client-framework) | `useService` | `project.Issues.close(…)` |
|
|
709
|
+
| Read through a use case | its `Feature`s (client-framework) | `useServiceReading` | `project.Accounts.balance(…)` |
|
|
710
|
+
| Read it on the server first | the same use case, before the page is drawn | `useServiceReading(…, { initial })` | `readOnServer`, `ServerRead` |
|
|
711
|
+
| A record read on the server | `EntityRecord initial` | `useRecord(…, { initial })` | `readRecordOnServer`, `RecordRead` |
|
|
712
|
+
| What every use case runs with | `processContext`, `project.context` (client-framework) | `useContextValues` | `ContextStore` |
|
|
713
|
+
| What happened, what broke | `./telemetry`, `./errors` (optional) | — | `configureProcess({ tracer, reporter })` |
|
|
714
|
+
| What happened, on the server | `configureServerProcess` (`./telemetry/server`, optional) | — | `registerServerTracing`, `serverTracer` |
|
|
715
|
+
| What broke, on the server | `reportRequestError` (`./errors/server`, optional) | — | `registerServerErrors`, `serverReporter` |
|
|
716
|
+
| A page that broke | `RouteError`, in the route's error boundary | — | `reportError` (client-framework) |
|
|
717
|
+
| What is each field? | `Meta` from the server, or `defineMeta` | — | `textOf`, `viewOf`, `metaFromSchema` |
|
|
718
|
+
| A value outside a model | — | `useTextOf` | `moneyTextOf`, `dayTextOf`, `instantTextOf`, `numberTextOf` |
|
|
719
|
+
| A file or a photo it holds | `EntityList`, `RecordField`: by its widget, as a `FileValue` | — | `attachmentOf`, `storedFileOf`, `renditionUrl` |
|
|
720
|
+
| A file given in the record | `RecordField` with `uploads`: `FileControl` (`DropZone`) | `useUpload` | `sendFile`, `uploadRefusalOf` |
|
|
721
|
+
| Formatted text | `RecordField` (`widget: "html"`), `factsOf`: `RichTextControl` | — | `richTextPlainOf`, `holdsRichText` |
|
|
722
|
+
| A person, read | `RecordField`, `factsOf`: `PersonValue` (`UserChip`) | `useSummaryOf` | `isPersonEntity` |
|
|
723
|
+
| A choice's tag outside a list | `ChoiceTag` | — | `choiceTagOf` |
|
|
724
|
+
| What is a record, at any size? | `cardOf`, `relationOf` | `useSummaryOf` | `summaryOf` |
|
|
725
|
+
| How does a record look? | `presented(entity, { option, row, card, tile })` | — | `presentationOf` |
|
|
726
|
+
| N records: search, filter, page | `EntityList`, `EntitySearchBar` | `useListing`, `useGroups` | `transport.list(route, criteria)` |
|
|
727
|
+
| A named slice (to collect, …) | `defineList` + `listView` | `useListing(list)` | `scopeOf` |
|
|
728
|
+
| A record's whole screen | `EntityRecord`, `entityView` without `record` | `useRecordScreen` | `formOf` |
|
|
729
|
+
| One region of a record screen | `RecordScreen.*` (`Rail`, `Paper`, `Fields`, `Pages`, `Audit`…) | `useScreenRecord` | web-ui's `Record.*` |
|
|
730
|
+
| One region of a list | `EntityList.*` (`Bar`, `Search`, `Table`, `Board`, `Pager`…) | `useScreenListing`, `useEntityList` | web-ui's `List.*` |
|
|
731
|
+
| The models a face brings | `ModelDefinitions entities metas events`; `SincproApp` without `transport` | — | `metasOf`, `eventMetasOf` (client-framework) |
|
|
732
|
+
| What a record screen says of it | `RecordScreen title subtitle tag creating moment actions` | `useRecordScreen` (same options) | web-ui's `Record identity`, `Record.Dock moment` |
|
|
733
|
+
| What hangs off a record, counted | `RecordScreen links` (`RelatedLink`: entity, `where`, title) | `useCounts` | `listRef` |
|
|
734
|
+
| The notices, on a hand-written screen | — | `useRecordNotices` | web-ui's `Record.Notice` |
|
|
735
|
+
| A block laid out as the form | — | `useScreenColumns` | — |
|
|
736
|
+
| Who is who in a history | `SincproApp people`, `FrameworkProvider people`, `ModelDefinitions people` | `usePeopleOf` | the application's use case |
|
|
737
|
+
| «New» in the business's words | `EntityList create="Nueva noticia"` | — | `canCreate` (`create` or `Edit`) |
|
|
738
|
+
| The list as a spreadsheet | `EntityList` «Exportar» (the entity's `export`) | — | `csvOf`, `exportColumnsOf`; `exportRoute` (client-framework) |
|
|
739
|
+
| Spanish in tú | `SincproApp voice="tú"` | — | `SPANISH_FRAMEWORK_COPY_TU`, web-ui's `SPANISH_COPY_TU` |
|
|
740
|
+
| Previous / next from a record | `EntityRecord` (from a list) | — | `placeOf`, `stepIn` (`Trail`) |
|
|
741
|
+
| How much each group adds up | `EntityList sums` | `useGroups` (`sums`) | `sumsOf`, `detailOf` |
|
|
742
|
+
| One record: read, edit, save | `RecordField`, `factsOf`, `RecordLines` | `useRecord` | `transport.one`, `transport.send` |
|
|
743
|
+
| Its lines: add, edit, remove | `RecordField name="lines"` (`LineItems`) | `useRecord` (`edit.cell`, `errorAt`) | `lineKey`, `editableLines`, `pathOf` |
|
|
744
|
+
| Its relations, inside it | `RelatedList` | `useRelated` | `relatedOf` |
|
|
745
|
+
| What other records hold of it | web-ui's `SmartButton` opening `entity.listRef(cut, name)` | `useCount` | `entity.listRef` (client-framework) |
|
|
746
|
+
| Choose one (literal search) | `EntityPicker`, `chooserIn` | `useLookup` | `lookupOf` + criteria's `matching` |
|
|
747
|
+
| Choose several (many2many) | `EntityTags` | `useLookup` (`values`) | `lookupOf` |
|
|
748
|
+
| A relation, from the model alone | `RecordField name="customer_id"` | `useEntityFor` | `relationFieldOf`, `entityFor` |
|
|
749
|
+
| Open it where it belongs | `RelatedRecord`, `entityView`, `EntityList openTargets` | — | `openIn`, `targetsFor`, `OpenInMenu` |
|
|
750
|
+
| Look at the set several ways | `EntityList views` (table, rows, board, sheet, tiles) | — | web-ui's `List.*` |
|
|
751
|
+
| Cross it by two fields | `EntityList pivot` | `usePivot` | `pivotOf` |
|
|
752
|
+
| Order by several fields | the bar's criteria builder | `listing.orderBy([...])` | criteria's `order` |
|
|
753
|
+
| Act on it (with a dry run) | `ServiceButton` (a use case), `CommandButton`, row commands | `useService`, `useCommand` | `transport.send` |
|
|
754
|
+
| What is chosen in a list | `EntityList selectable selection` | `useSelection` | `Selection`, `chosen`, `allMatching` (client-framework) |
|
|
755
|
+
| Act on each chosen one | `BatchProgress`, `selectionActions={(chosen) => …}` | `useBatchCommand` | `runBatch`, `keysOf` (client-framework), `sendRoute` |
|
|
756
|
+
| A list's actions, by the style | `EntityList actions`, `selectionActions` (`DockAction`s) | — | web-ui's `List.Dock`, `ViewStyleProvider` |
|
|
757
|
+
| A record's actions, by the style | `EntityRecord actions`, web-ui's `Record.Dock` | `useRecordLifecycleActions` | `DockedAction`, `ActionLook` |
|
|
758
|
+
| A use case or a Command, there | `ServiceButton`, `CommandButton` (as buttons) | `useServiceAction`/`useCommandAction` | — |
|
|
759
|
+
| Delete it | `EntityRecord` (`RecordLifecycle`) | `useRecordLifecycle` | `entity.delete`, `useRouteCommand` |
|
|
760
|
+
| Its trash | `EntityRecord` (`RecordLifecycle`), `listView(trashOf(entity))` | `useRecordLifecycle` | `entity.archive`, `entity.restore`, `trashOf` |
|
|
761
|
+
| Read again when it was written | every reading of this package, by itself | `useWrites` | `processChanges` (client-framework) |
|
|
762
|
+
| What happened to it | `Record.Activity` fed by `useHistory` | `useHistory` | `historyOf` |
|
|
763
|
+
| The application context | `SincproApp` | `useRecordInWorkspace`, `useFollowed` | `FrameworkProvider`, `webUiSkin` |
|
|
763
764
|
|
|
764
765
|
The rules behind them, in short:
|
|
765
766
|
|
package/dist/core/copy.d.ts
CHANGED
|
@@ -122,6 +122,10 @@ export type FrameworkCopy = {
|
|
|
122
122
|
/** More were chosen than a Command runs on at once. */
|
|
123
123
|
tooMany: (size: number | null, limit: number) => string;
|
|
124
124
|
};
|
|
125
|
+
board: {
|
|
126
|
+
/** The name of a board's period row: what every tile reads over. */
|
|
127
|
+
period: string;
|
|
128
|
+
};
|
|
125
129
|
failure: {
|
|
126
130
|
/** The server could not be reached at all — nothing it said is known. */
|
|
127
131
|
unreachable: string;
|
package/dist/core/copy.js
CHANGED
|
@@ -88,6 +88,7 @@ export const ENGLISH_FRAMEWORK_COPY = {
|
|
|
88
88
|
stop: "Stop",
|
|
89
89
|
tooMany: (size, limit) => `${size === null ? "More than " + limit : size} records are chosen; at most ${limit} at once. Narrow the search.`,
|
|
90
90
|
},
|
|
91
|
+
board: { period: "Period" },
|
|
91
92
|
failure: {
|
|
92
93
|
unreachable: "The server could not be reached",
|
|
93
94
|
unexpected: "The server answered something else",
|
|
@@ -197,6 +198,7 @@ export const SPANISH_FRAMEWORK_COPY = {
|
|
|
197
198
|
stop: "Detener",
|
|
198
199
|
tooMany: (size, limit) => `${size === null ? "Son más de " + limit : "Son " + size} registros elegidos; a la vez, como mucho ${limit}. Acotá la búsqueda.`,
|
|
199
200
|
},
|
|
201
|
+
board: { period: "Período" },
|
|
200
202
|
failure: {
|
|
201
203
|
unreachable: "No se pudo hablar con el servidor",
|
|
202
204
|
unexpected: "El servidor contestó otra cosa",
|
package/dist/react/useRecord.js
CHANGED
|
@@ -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);
|
|
@@ -270,8 +272,10 @@ export function useRecord(entity, opened, options = {}) {
|
|
|
270
272
|
const refused = (error) => {
|
|
271
273
|
if (error instanceof TransportError && error.problem?.kind === "conflict")
|
|
272
274
|
setConflict(true);
|
|
273
|
-
else
|
|
275
|
+
else {
|
|
274
276
|
setFailure(error);
|
|
277
|
+
setRewritten(new Set());
|
|
278
|
+
}
|
|
275
279
|
};
|
|
276
280
|
// sincpro_framework's `Edit`: what the form writes; the fields changed; the draft version read
|
|
277
281
|
// (`0`: none) — another tab that kept first wins —, and the stored version the edit started
|
|
@@ -299,6 +303,8 @@ export function useRecord(entity, opened, options = {}) {
|
|
|
299
303
|
const next = { ...typedNow.current, [name]: value };
|
|
300
304
|
typedNow.current = next;
|
|
301
305
|
setTyped(next);
|
|
306
|
+
if (failure !== null && !rewritten.has(name))
|
|
307
|
+
setRewritten((before) => new Set(before).add(name));
|
|
302
308
|
ask(next, name);
|
|
303
309
|
},
|
|
304
310
|
writable,
|
|
@@ -312,7 +318,11 @@ export function useRecord(entity, opened, options = {}) {
|
|
|
312
318
|
const said = fieldStateOf(definition, field, line ?? {}, lineStatesOf(fromServer, name, line, index, definition?.identity || "id"));
|
|
313
319
|
return writable ? said : { ...said, readonly: true, required: false };
|
|
314
320
|
},
|
|
315
|
-
|
|
321
|
+
// A refusal's word on a field holds until the field is written again: corrected, it is
|
|
322
|
+
// the next save's to judge — a flow would otherwise stay blocked by what no longer holds.
|
|
323
|
+
errors: failure instanceof TransportError
|
|
324
|
+
? Object.fromEntries(Object.entries(errorsByField(failure.problem?.errors)).filter(([at]) => !rewritten.has(at.split("/")[0] ?? at)))
|
|
325
|
+
: {},
|
|
316
326
|
advice,
|
|
317
327
|
missing: missingOf(state.meta, values, fromServer),
|
|
318
328
|
saving,
|
|
@@ -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 { CommandBodies, Entity } 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, C extends CommandBodies = CommandBodies>(entity: Entity<T, C>, { over, criteria }?: BoardReadingOptions<T>): Listing<T, C>;
|
|
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 {};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { merge, } from "@sincpro/criteria";
|
|
4
|
+
import { frameworkCopy } from "../../core/copy.js";
|
|
5
|
+
import { explain } from "../../core/explain.js";
|
|
6
|
+
import { useFramework } from "../../react/context.js";
|
|
7
|
+
import { useListing } from "../../react/useListing.js";
|
|
8
|
+
import { usePivot } from "../../react/usePivot.js";
|
|
9
|
+
import { pivotOf } from "../list/pivot.js";
|
|
10
|
+
import { Board, BoardStat, BoardStats, BoardTile, Chart, chartFromPivot, COUNT_MEASURE, SegmentedControl, } from "@sincpro/web-ui";
|
|
11
|
+
import { createContext, useContext, useMemo, useState } from "react";
|
|
12
|
+
const Scope = createContext(null);
|
|
13
|
+
/** The period of the board around, or none outside a board. */
|
|
14
|
+
export function useBoardPeriod() {
|
|
15
|
+
return useContext(Scope);
|
|
16
|
+
}
|
|
17
|
+
/** The cut a period makes on a field: `field between range`. */
|
|
18
|
+
export function periodCut(period, over) {
|
|
19
|
+
return { field: over, operator: "between", value: period.range };
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A listing of `entity` as a board tile reads it: one row a page (the count and the question are
|
|
23
|
+
* what a tile wants), cut by the board's period over `over`.
|
|
24
|
+
*/
|
|
25
|
+
export function useBoardListing(entity, { over, criteria } = {}) {
|
|
26
|
+
const period = useBoardPeriod();
|
|
27
|
+
const cut = period === null || over === undefined
|
|
28
|
+
? undefined
|
|
29
|
+
: { selection: periodCut(period, over) };
|
|
30
|
+
const asked = cut === undefined ? criteria : criteria === undefined ? cut : merge(criteria, cut);
|
|
31
|
+
return useListing(entity, {
|
|
32
|
+
pageSize: 1,
|
|
33
|
+
...(asked === undefined ? {} : { criteria: asked }),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* web-ui's state of a tile from a reading: reading while it asks, the refusal in the server's
|
|
38
|
+
* words when it failed — with «Reintentar» when there is a way to ask again.
|
|
39
|
+
*/
|
|
40
|
+
export function boardStateOf(reading, retry) {
|
|
41
|
+
if (reading.status === "failed") {
|
|
42
|
+
const said = explain(reading.error);
|
|
43
|
+
return {
|
|
44
|
+
status: "failed",
|
|
45
|
+
sentence: said.sentence || said.heading,
|
|
46
|
+
...(retry === undefined ? {} : { onRetry: retry }),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return reading.status === "ready" ? { status: "ready" } : { status: "loading" };
|
|
50
|
+
}
|
|
51
|
+
/** The root: the period row above every tile, and the period given to each. */
|
|
52
|
+
export function Dashboard({ title, description, periods = [], defaultPeriod, period: controlled, onPeriodChange, stats, children, }) {
|
|
53
|
+
const [own, setOwn] = useState(defaultPeriod ?? periods[0]?.id);
|
|
54
|
+
const id = controlled ?? own;
|
|
55
|
+
const period = useMemo(() => periods.find((one) => one.id === id) ?? periods[0] ?? null, [periods, id]);
|
|
56
|
+
const choose = (next) => {
|
|
57
|
+
if (controlled === undefined)
|
|
58
|
+
setOwn(next);
|
|
59
|
+
onPeriodChange?.(next);
|
|
60
|
+
};
|
|
61
|
+
return (_jsx(Scope.Provider, { value: period, children: _jsx(Board, { title: title, ...(description === undefined ? {} : { description }), ...(periods.length < 2 || period === null
|
|
62
|
+
? {}
|
|
63
|
+
: {
|
|
64
|
+
filters: (_jsx(SegmentedControl, { "aria-label": frameworkCopy().board.period, size: "sm", value: period.id, onChange: choose, options: periods.map((one) => ({ value: one.id, label: one.label })) })),
|
|
65
|
+
}), ...(stats === undefined ? {} : { metrics: _jsx(BoardStats, { children: stats }) }), children: children }) }));
|
|
66
|
+
}
|
|
67
|
+
/** A headline figure: how many records of `entity` the period holds, counted by the server. */
|
|
68
|
+
function Count({ entity, over, criteria, label, icon, hint, hero, tone, }) {
|
|
69
|
+
const listing = useBoardListing(entity, {
|
|
70
|
+
...(over === undefined ? {} : { over }),
|
|
71
|
+
...(criteria === undefined ? {} : { criteria }),
|
|
72
|
+
});
|
|
73
|
+
const state = boardStateOf(listing, listing.reload);
|
|
74
|
+
return (_jsx(BoardStat, { label: label, state: state, ...(listing.count === null ? {} : { value: listing.count.value }), ...(icon === undefined ? {} : { icon }), ...(hint === undefined ? {} : { hint }), ...(hero === undefined ? {} : { hero }), ...(tone === undefined ? {} : { tone }) }));
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* A tile that crosses `entity` by two fields — the rows below, the columns as series — counted,
|
|
78
|
+
* or added up by `measure`, by the server over the board's period.
|
|
79
|
+
*/
|
|
80
|
+
function ChartTile({ entity, over, criteria, title, icon, hint, description, rows, columns, measure, kind, span, }) {
|
|
81
|
+
const { locale } = useFramework();
|
|
82
|
+
const listing = useBoardListing(entity, {
|
|
83
|
+
...(over === undefined ? {} : { over }),
|
|
84
|
+
...(criteria === undefined ? {} : { criteria }),
|
|
85
|
+
});
|
|
86
|
+
const measures = measure === undefined ? [] : [measure];
|
|
87
|
+
const pivot = usePivot(listing, { rows, columns, measures });
|
|
88
|
+
// The listing refused is the tile refused: the crossing never asks then.
|
|
89
|
+
const state = listing.status === "failed"
|
|
90
|
+
? boardStateOf(listing, listing.reload)
|
|
91
|
+
: boardStateOf(pivot.status === "idle" ? { ...pivot, status: "loading" } : pivot);
|
|
92
|
+
const data = pivot.status !== "ready"
|
|
93
|
+
? null
|
|
94
|
+
: chartFromPivot(pivotOf({
|
|
95
|
+
crossed: pivot.crossed,
|
|
96
|
+
byColumn: pivot.columns,
|
|
97
|
+
rows,
|
|
98
|
+
columns,
|
|
99
|
+
measures: pivot.measures,
|
|
100
|
+
meta: listing.meta,
|
|
101
|
+
locale,
|
|
102
|
+
}), { measure: measure ?? COUNT_MEASURE });
|
|
103
|
+
return (_jsx(BoardTile, { title: title, state: state, ...(icon === undefined ? {} : { icon }), ...(hint === undefined ? {} : { hint }), ...(description === undefined ? {} : { description }), ...(span === undefined ? {} : { span }), children: data === null ? null : (_jsx(Chart, { data: data, label: title, ...(kind === undefined ? {} : { kind }) })) }));
|
|
104
|
+
}
|
|
105
|
+
Dashboard.Count = Count;
|
|
106
|
+
Dashboard.Chart = ChartTile;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { type BoardPeriod, type BoardReadingOptions, boardStateOf, Dashboard, type DashboardProps, periodCut, useBoardListing, useBoardPeriod, } from "./Dashboard.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { boardStateOf, Dashboard, periodCut, useBoardListing, useBoardPeriod, } from "./Dashboard.js";
|
package/dist/web/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The web bindings: what draws a `Listing` and a record with `@sincpro/web-ui`.
|
|
3
3
|
*/
|
|
4
|
+
export * from "./board/index.js";
|
|
4
5
|
export { attachmentOf } from "./files.js";
|
|
5
6
|
export { BatchProgress } from "./list/BatchProgress.js";
|
|
6
7
|
export { aggregateOf, type ColumnOptions, columnsOf, } from "./list/columns.js";
|
|
@@ -35,12 +36,13 @@ export { RelatedList } from "./record/RelatedList.js";
|
|
|
35
36
|
export { RichTextControl, richTextControl, RichTextFact, } from "./record/richText.js";
|
|
36
37
|
export { type ServiceActionProps, ServiceButton, useServiceAction, } from "./record/ServiceButton.js";
|
|
37
38
|
export { cardOf, relationOf } from "./record/summary.js";
|
|
39
|
+
export { useWizardRecord, Wizard, type WizardProps, type WizardStepProps, } from "./record/Wizard.js";
|
|
38
40
|
export { Refused } from "./Refused.js";
|
|
39
41
|
export { RouteError, type RouteErrorProps } from "./RouteError.js";
|
|
40
42
|
export { entityView, type EntityViewOptions, listView, type ListViewOptions, } from "./workspace/composer.js";
|
|
41
43
|
export { openIn, openOptions, RECORD_SIZE, RelatedRecord, targetsFor, } from "./workspace/open.js";
|
|
42
44
|
export { type RecordTag, type Stamp, useRecordScreen, } from "./workspace/record.js";
|
|
43
|
-
export { EntityRecord, type FieldDrawn, type ReadyRecord, RecordScreen, type RecordScreenProps, type RelatedLink, useScreenColumns, useScreenRecord, } from "./workspace/RecordScreen.js";
|
|
45
|
+
export { EntityRecord, type FieldDrawn, type ReadyRecord, RecordScreen, type RecordScreenProps, type RelatedLink, useRecordNotices, useScreenColumns, useScreenRecord, } from "./workspace/RecordScreen.js";
|
|
44
46
|
export { SincproApp } from "./workspace/SincproApp.js";
|
|
45
47
|
export { webUiSkin } from "./workspace/skin.js";
|
|
46
48
|
export { chooserIn, useFollowed, useRecordInWorkspace, } from "./workspace/workspace.js";
|
package/dist/web/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The web bindings: what draws a `Listing` and a record with `@sincpro/web-ui`.
|
|
3
3
|
*/
|
|
4
|
+
export * from "./board/index.js";
|
|
4
5
|
export { attachmentOf } from "./files.js";
|
|
5
6
|
export { BatchProgress } from "./list/BatchProgress.js";
|
|
6
7
|
export { aggregateOf, columnsOf, } from "./list/columns.js";
|
|
@@ -35,12 +36,13 @@ export { RelatedList } from "./record/RelatedList.js";
|
|
|
35
36
|
export { RichTextControl, richTextControl, RichTextFact, } from "./record/richText.js";
|
|
36
37
|
export { ServiceButton, useServiceAction, } from "./record/ServiceButton.js";
|
|
37
38
|
export { cardOf, relationOf } from "./record/summary.js";
|
|
39
|
+
export { useWizardRecord, Wizard, } from "./record/Wizard.js";
|
|
38
40
|
export { Refused } from "./Refused.js";
|
|
39
41
|
export { RouteError } from "./RouteError.js";
|
|
40
42
|
export { entityView, listView, } from "./workspace/composer.js";
|
|
41
43
|
export { openIn, openOptions, RECORD_SIZE, RelatedRecord, targetsFor, } from "./workspace/open.js";
|
|
42
44
|
export { useRecordScreen, } from "./workspace/record.js";
|
|
43
|
-
export { EntityRecord, RecordScreen, useScreenColumns, useScreenRecord, } from "./workspace/RecordScreen.js";
|
|
45
|
+
export { EntityRecord, RecordScreen, useRecordNotices, useScreenColumns, useScreenRecord, } from "./workspace/RecordScreen.js";
|
|
44
46
|
export { SincproApp } from "./workspace/SincproApp.js";
|
|
45
47
|
export { webUiSkin } from "./workspace/skin.js";
|
|
46
48
|
export { chooserIn, useFollowed, useRecordInWorkspace, } from "./workspace/workspace.js";
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A wizard: ONE record filled in steps. Each step names its fields; «Next» stays off while one of
|
|
3
|
+
* them lacks something — the reason beside it, in the model's words —; the last step names what
|
|
4
|
+
* finishing does, and finishing saves the record. What the server refuses then takes the person
|
|
5
|
+
* back to the step that holds the field, its message on it.
|
|
6
|
+
*
|
|
7
|
+
* <Wizard entity={invoices} resource={invoices.newRef()} onDone={(invoice) => …}>
|
|
8
|
+
* <Wizard.Step id="customer" title="Cliente" fields={["customer_id", "invoice_date"]} />
|
|
9
|
+
* <Wizard.Step id="payment" title="Cobro" fields={["payment"]} nextLabel="Registrar factura">
|
|
10
|
+
* <Summary />
|
|
11
|
+
* </Wizard.Step>
|
|
12
|
+
* </Wizard>
|
|
13
|
+
*
|
|
14
|
+
* Context: a flow over one entity is that entity's record, not a state of its own — the draft,
|
|
15
|
+
* the preview, the rules and the refusals are `useRecord`'s, and what may move on is what the
|
|
16
|
+
* backend publishes (a required field, a field's error), never a rule written here. web-ui's
|
|
17
|
+
* `StepFlow` draws the strip, the buttons and the blocked reason; its `Step` is a slot, so a
|
|
18
|
+
* `Wizard.Step` is a MARK the root resolves (`web/parts.tsx`), never a component that draws one.
|
|
19
|
+
* The step on screen can be the screen's (`step` / `onStepChange`: a window's `params`, so a
|
|
20
|
+
* reload lands on it). Inside a step, a part of the application's reads the record with
|
|
21
|
+
* `useWizardRecord()`.
|
|
22
|
+
*/
|
|
23
|
+
import type { Entity, ResourceRef } from "@sincpro/client-framework";
|
|
24
|
+
import { type AnyRecord } from "@sincpro/criteria";
|
|
25
|
+
import { type RecordReading } from "../../react/useRecord.js";
|
|
26
|
+
import { type Part } from "../parts.js";
|
|
27
|
+
import { type ReactNode } from "react";
|
|
28
|
+
export type WizardStepProps = {
|
|
29
|
+
/** Who the step is: what `step` and `onStepChange` speak. */
|
|
30
|
+
id: string;
|
|
31
|
+
title: string;
|
|
32
|
+
/** One sentence under the title: what this step asks for. */
|
|
33
|
+
description?: string;
|
|
34
|
+
/** The record's fields this step writes, drawn as the record draws them, in this order. */
|
|
35
|
+
fields?: readonly string[];
|
|
36
|
+
/** What the forward button says from this step: on the last, what finishing does. */
|
|
37
|
+
nextLabel?: string;
|
|
38
|
+
/** What the step adds under its fields: a summary, a block of the application's. */
|
|
39
|
+
children?: ReactNode;
|
|
40
|
+
};
|
|
41
|
+
type WizardState = {
|
|
42
|
+
reading: RecordReading<AnyRecord>;
|
|
43
|
+
blockedOf: (fields: readonly string[]) => string | undefined;
|
|
44
|
+
};
|
|
45
|
+
/** The record the wizard around is filling — for a part of the application's inside a step. */
|
|
46
|
+
export declare function useWizardRecord<T extends AnyRecord = AnyRecord>(): RecordReading<T>;
|
|
47
|
+
export type WizardProps<T extends AnyRecord> = {
|
|
48
|
+
entity: Entity<T>;
|
|
49
|
+
/** The record it fills: `entity.newRef()` to create one, its id or reference to go on one. */
|
|
50
|
+
resource: string | ResourceRef;
|
|
51
|
+
/** The step on screen, when the screen holds it (a window's `params`). */
|
|
52
|
+
step?: string;
|
|
53
|
+
onStepChange?: (id: string) => void;
|
|
54
|
+
/** Saved: the record as the server answered it. */
|
|
55
|
+
onDone?: (record: unknown) => void;
|
|
56
|
+
/** Leave without finishing. Without it there is no «Cancel» — the window has its own way out. */
|
|
57
|
+
onCancel?: () => void;
|
|
58
|
+
/** `Wizard.Step`s, in order. */
|
|
59
|
+
children: ReactNode;
|
|
60
|
+
};
|
|
61
|
+
export declare function Wizard<T extends AnyRecord>({ entity, resource, step, onStepChange, onDone, onCancel, children, }: WizardProps<T>): import("react").JSX.Element | null;
|
|
62
|
+
export declare namespace Wizard {
|
|
63
|
+
var Step: Part<WizardStepProps, WizardState>;
|
|
64
|
+
}
|
|
65
|
+
export {};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { labelOf } from "@sincpro/criteria";
|
|
4
|
+
import { frameworkCopy } from "../../core/copy.js";
|
|
5
|
+
import { useRecord } from "../../react/useRecord.js";
|
|
6
|
+
import { part, resolveParts } from "../parts.js";
|
|
7
|
+
import { RecordField } from "./edit.js";
|
|
8
|
+
import { FormSection, StepFlow } from "@sincpro/web-ui";
|
|
9
|
+
import { Children, createContext, isValidElement, useContext, useEffect, useRef, useState, } from "react";
|
|
10
|
+
const Held = createContext(null);
|
|
11
|
+
/** The record the wizard around is filling — for a part of the application's inside a step. */
|
|
12
|
+
export function useWizardRecord() {
|
|
13
|
+
const reading = useContext(Held);
|
|
14
|
+
if (reading === null)
|
|
15
|
+
throw new Error("useWizardRecord is read inside a Wizard.");
|
|
16
|
+
return reading;
|
|
17
|
+
}
|
|
18
|
+
const Step = part("Wizard.Step", ({ id, title, description, fields = [], nextLabel, children }, { reading, blockedOf }) => {
|
|
19
|
+
const blocked = blockedOf(fields);
|
|
20
|
+
return (_jsxs(StepFlow.Step, { id: id, title: title, ...(description === undefined ? {} : { description }), ...(blocked === undefined ? {} : { blocked }), ...(nextLabel === undefined ? {} : { nextLabel }), children: [fields.length === 0 ? null : (_jsx(FormSection, { children: fields.map((name) => (_jsx(RecordField, { record: reading, name: name }, name))) })), children] }, id));
|
|
21
|
+
});
|
|
22
|
+
/** The steps written under the root, as marks: which fields each one holds. */
|
|
23
|
+
function stepsIn(children) {
|
|
24
|
+
return Children.toArray(children)
|
|
25
|
+
.filter((child) => isValidElement(child) && child.type === Step)
|
|
26
|
+
.map((child) => child.props);
|
|
27
|
+
}
|
|
28
|
+
export function Wizard({ entity, resource, step, onStepChange, onDone, onCancel, children, }) {
|
|
29
|
+
const reading = useRecord(entity, resource);
|
|
30
|
+
const { edit, meta, locale } = reading;
|
|
31
|
+
const [own, setOwn] = useState(undefined);
|
|
32
|
+
const go = (id) => {
|
|
33
|
+
if (step === undefined)
|
|
34
|
+
setOwn(id);
|
|
35
|
+
onStepChange?.(id);
|
|
36
|
+
};
|
|
37
|
+
// Finishing is a save; what it ends in arrives in the renders after it.
|
|
38
|
+
const finishing = useRef(false);
|
|
39
|
+
const [finished, setFinished] = useState(false);
|
|
40
|
+
const reported = useRef(false);
|
|
41
|
+
const steps = stepsIn(children);
|
|
42
|
+
// Refused: back to the first step that holds a field the server named.
|
|
43
|
+
const failing = Object.keys(edit.errors).join(",");
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (!finishing.current || failing === "")
|
|
46
|
+
return;
|
|
47
|
+
finishing.current = false;
|
|
48
|
+
const named = failing.split(",");
|
|
49
|
+
const back = steps.find((one) => (one.fields ?? []).some((f) => named.includes(f)));
|
|
50
|
+
if (back !== undefined)
|
|
51
|
+
go(back.id);
|
|
52
|
+
// Only a new refusal moves the flow; the steps are read as written now.
|
|
53
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
54
|
+
}, [failing]);
|
|
55
|
+
// Saved: the record the hook became, or what a create answered without an identity.
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (!finished || reported.current)
|
|
58
|
+
return;
|
|
59
|
+
if (!reading.isNew && reading.status === "ready") {
|
|
60
|
+
reported.current = true;
|
|
61
|
+
onDone?.(reading.record);
|
|
62
|
+
}
|
|
63
|
+
else if (reading.isNew && edit.created !== null) {
|
|
64
|
+
reported.current = true;
|
|
65
|
+
onDone?.(edit.created);
|
|
66
|
+
}
|
|
67
|
+
}, [finished, reading.isNew, reading.status, reading.record, edit.created, onDone]);
|
|
68
|
+
if (reading.status !== "ready")
|
|
69
|
+
return null;
|
|
70
|
+
const copy = frameworkCopy().record;
|
|
71
|
+
const blockedOf = (fields) => {
|
|
72
|
+
const wrong = fields.find((name) => edit.errors[name] !== undefined);
|
|
73
|
+
if (wrong !== undefined)
|
|
74
|
+
return edit.errors[wrong];
|
|
75
|
+
const missing = fields.filter((name) => edit.missing.includes(name));
|
|
76
|
+
return missing.length === 0
|
|
77
|
+
? undefined
|
|
78
|
+
: copy.missing(missing.map((name) => labelOf(meta, name, locale ?? "en")));
|
|
79
|
+
};
|
|
80
|
+
const finish = async () => {
|
|
81
|
+
finishing.current = true;
|
|
82
|
+
if (await edit.save()) {
|
|
83
|
+
finishing.current = false;
|
|
84
|
+
setFinished(true);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const current = step ?? own;
|
|
88
|
+
return (_jsx(Held.Provider, { value: reading, children: _jsx(StepFlow, { ...(current === undefined ? {} : { current }), onCurrentChange: go, onFinish: () => void finish(), ...(onCancel === undefined ? {} : { onCancel }), busy: edit.saving, children: resolveParts(children, { reading, blockedOf }) }) }));
|
|
89
|
+
}
|
|
90
|
+
Wizard.Step = Step;
|
|
@@ -93,6 +93,19 @@ export declare function useScreenRecord<T extends AnyRecord>(_entity?: Entity<T>
|
|
|
93
93
|
* asks the workspace where it opened.
|
|
94
94
|
*/
|
|
95
95
|
export declare function useScreenColumns(): 1 | 2;
|
|
96
|
+
/**
|
|
97
|
+
* The record's notices for a screen that writes web-ui's `Record` itself (`useRecordScreen`):
|
|
98
|
+
* the edit's and the server's advice, as `RecordScreen.Notices` and `.Advice` draw them —
|
|
99
|
+
* elements of web-ui's slot, written straight among `Record`'s children. Nothing while the record
|
|
100
|
+
* is not read.
|
|
101
|
+
*
|
|
102
|
+
* const notices = useRecordNotices(screen.reading);
|
|
103
|
+
* <Record {...screen.record}>{notices}<Record.Rail>…</Record.Rail>…</Record>
|
|
104
|
+
*
|
|
105
|
+
* Context: a screen at the hooks level copied the framework's notices — as `Callout`s among the
|
|
106
|
+
* fields, which web-ui says not to do (#112).
|
|
107
|
+
*/
|
|
108
|
+
export declare function useRecordNotices<T extends AnyRecord>(reading: RecordReading<T>): ReactNode[];
|
|
96
109
|
/** A field drawn the screen's way inside `RecordScreen.Fields`: its control, and the record. */
|
|
97
110
|
export type FieldDrawn = (control: FieldControl, record: ReadyRecord<AnyRecord>) => ReactNode;
|
|
98
111
|
/**
|
|
@@ -158,7 +171,10 @@ export declare const RecordScreen: typeof RecordScreenRoot & {
|
|
|
158
171
|
Crumbs: import("../parts.js").Part<NoProps, RecordScreenState>;
|
|
159
172
|
Pager: import("../parts.js").Part<NoProps, RecordScreenState>;
|
|
160
173
|
Smart: import("../parts.js").Part<NoProps, RecordScreenState>;
|
|
161
|
-
Actions: import("../parts.js").Part<
|
|
174
|
+
Actions: import("../parts.js").Part<{
|
|
175
|
+
visible?: number | undefined;
|
|
176
|
+
children?: never;
|
|
177
|
+
}, RecordScreenState>;
|
|
162
178
|
Paper: import("../parts.js").Part<{
|
|
163
179
|
children?: ReactNode;
|
|
164
180
|
layout?: "horizontal" | "stacked";
|
|
@@ -57,12 +57,12 @@ const Crumbs = screenPart("Crumbs", (_props, { screen }) => screen.crumbs.length
|
|
|
57
57
|
const Pager = screenPart("Pager", (_props, { screen }) => screen.pager === undefined ? null : _jsx(Record.Pager, { ...screen.pager }));
|
|
58
58
|
/** The screen's actions and the record's lifecycle — floating in the dock, or in the rail when
|
|
59
59
|
* the screen draws them by hand. The application's word on the record's moment goes with them. */
|
|
60
|
-
const Actions = screenPart("Actions", (
|
|
60
|
+
const Actions = screenPart("Actions", ({ visible }, state) => {
|
|
61
61
|
const { docked, drawn, screen } = state;
|
|
62
62
|
const moment = screen.moment;
|
|
63
63
|
return [
|
|
64
64
|
drawn === null ? null : _jsx(Record.Actions, { children: drawn }, "actions"),
|
|
65
|
-
docked.length === 0 && moment === undefined ? null : (_jsx(Record.Dock, { actions: docked, ...(moment === undefined ? {} : { moment }) }, "dock")),
|
|
65
|
+
docked.length === 0 && moment === undefined ? null : (_jsx(Record.Dock, { actions: docked, ...(moment === undefined ? {} : { moment }), ...(visible === undefined ? {} : { visible }) }, "dock")),
|
|
66
66
|
];
|
|
67
67
|
});
|
|
68
68
|
/** What hangs off the record — its payments, its members —, as web-ui's smart buttons. */
|
|
@@ -95,24 +95,48 @@ const Pages = screenPart("Pages", ({ names }, state) => {
|
|
|
95
95
|
* What happened to the edit itself, as web-ui's notices of the record — never among the fields:
|
|
96
96
|
* someone else saved first (`bad`: it blocks, so it stays in view between the rail and the
|
|
97
97
|
* paper, with «Read it again»), or a kept draft came back (`info`: into the rail's indicator,
|
|
98
|
-
* and it can be put away).
|
|
98
|
+
* and it can be put away). Elements of web-ui's slot, written straight into `Record` or its paper.
|
|
99
99
|
*/
|
|
100
|
-
|
|
101
|
-
const { reading, restoredAway, putRestoredAway } = state;
|
|
100
|
+
function noticesOf(reading, restoredAway, putRestoredAway) {
|
|
102
101
|
const copy = frameworkCopy().record;
|
|
103
102
|
const { conflict, restored } = reading.edit;
|
|
104
103
|
return [
|
|
105
104
|
conflict ? (_jsx(Record.Notice, { tone: "bad", action: _jsx(Button, { size: "sm", role: "secondary", onClick: reading.reload, children: copy.reload }), children: copy.conflict }, "conflict")) : null,
|
|
106
105
|
restored && !restoredAway ? (_jsx(Record.Notice, { tone: "info", onDismiss: putRestoredAway, children: copy.restored }, "restored")) : null,
|
|
107
106
|
];
|
|
108
|
-
}
|
|
107
|
+
}
|
|
109
108
|
/**
|
|
110
109
|
* What the server advised about the record or one of its fields, as notices of the record: one
|
|
111
110
|
* the save will refuse while it holds is a warning. A line's warning goes on its line.
|
|
112
111
|
*/
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
112
|
+
function adviceOf(reading) {
|
|
113
|
+
return reading.edit.advice
|
|
114
|
+
.filter((one) => (one.path?.length ?? 0) <= 1)
|
|
115
|
+
.map((one) => (_jsx(Record.Notice, { tone: one.blocks_save === true ? "warn" : "info", children: one.message }, one.message)));
|
|
116
|
+
}
|
|
117
|
+
/** The edit's notices, at the top of the screen or inside the paper (`noticesOf`). */
|
|
118
|
+
const Notices = screenPart("Notices", (_props, state) => noticesOf(state.reading, state.restoredAway, state.putRestoredAway));
|
|
119
|
+
/** The server's advice, as notices of the record (`adviceOf`). */
|
|
120
|
+
const Advice = screenPart("Advice", (_props, { reading }) => adviceOf(reading));
|
|
121
|
+
/**
|
|
122
|
+
* The record's notices for a screen that writes web-ui's `Record` itself (`useRecordScreen`):
|
|
123
|
+
* the edit's and the server's advice, as `RecordScreen.Notices` and `.Advice` draw them —
|
|
124
|
+
* elements of web-ui's slot, written straight among `Record`'s children. Nothing while the record
|
|
125
|
+
* is not read.
|
|
126
|
+
*
|
|
127
|
+
* const notices = useRecordNotices(screen.reading);
|
|
128
|
+
* <Record {...screen.record}>{notices}<Record.Rail>…</Record.Rail>…</Record>
|
|
129
|
+
*
|
|
130
|
+
* Context: a screen at the hooks level copied the framework's notices — as `Callout`s among the
|
|
131
|
+
* fields, which web-ui says not to do (#112).
|
|
132
|
+
*/
|
|
133
|
+
export function useRecordNotices(reading) {
|
|
134
|
+
const [restoredAway, setRestoredAway] = useState(false);
|
|
135
|
+
if (reading.status !== "ready")
|
|
136
|
+
return [];
|
|
137
|
+
const read = reading;
|
|
138
|
+
return [...noticesOf(read, restoredAway, () => setRestoredAway(true)), ...adviceOf(read)];
|
|
139
|
+
}
|
|
116
140
|
/**
|
|
117
141
|
* The record's fields in web-ui's form grid: two columns on a page and in a modal, one in a
|
|
118
142
|
* panel, a peek or a phone. `names` chooses and orders them; `title` heads the section and
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sincpro/web-framework",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.22.0",
|
|
4
4
|
"description": "The web client of sincpro_framework: entities, lists and records bound to the metadata the server publishes, drawn with @sincpro/web-ui and arranged with @sincpro/web-composer.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|