@sincpro/web-framework 2.4.0 → 2.6.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 +117 -86
- package/dist/core/cache.d.ts +19 -7
- package/dist/core/cache.js +81 -44
- package/dist/core/changes.d.ts +25 -0
- package/dist/core/changes.js +39 -0
- package/dist/core/edit.d.ts +19 -0
- package/dist/core/edit.js +46 -0
- package/dist/core/index.d.ts +3 -3
- package/dist/core/index.js +3 -3
- package/dist/core/list.d.ts +20 -0
- package/dist/core/list.js +32 -1
- package/dist/core/names.d.ts +25 -0
- package/dist/core/names.js +79 -0
- package/dist/core/present.d.ts +22 -0
- package/dist/core/present.js +51 -19
- package/dist/react/context.d.ts +15 -2
- package/dist/react/context.js +11 -4
- package/dist/react/index.d.ts +4 -0
- package/dist/react/index.js +4 -0
- package/dist/react/useCount.d.ts +18 -0
- package/dist/react/useCount.js +23 -0
- package/dist/react/useGroups.js +4 -1
- package/dist/react/useHistory.js +4 -1
- package/dist/react/useListing.js +9 -6
- package/dist/react/useNameOf.d.ts +5 -4
- package/dist/react/useNameOf.js +25 -26
- package/dist/react/usePivot.js +4 -1
- package/dist/react/useRecord.d.ts +4 -4
- package/dist/react/useRecord.js +20 -13
- package/dist/react/useService.d.ts +5 -1
- package/dist/react/useServiceReading.d.ts +35 -0
- package/dist/react/useServiceReading.js +75 -0
- package/dist/react/useTextOf.d.ts +16 -0
- package/dist/react/useTextOf.js +21 -0
- package/dist/react/useWrites.d.ts +19 -0
- package/dist/react/useWrites.js +35 -0
- package/dist/web/index.d.ts +1 -0
- package/dist/web/index.js +1 -0
- package/dist/web/list/EntityList.d.ts +4 -1
- package/dist/web/list/EntityList.js +6 -3
- package/dist/web/list/EntitySearchBar.d.ts +4 -1
- package/dist/web/list/EntitySearchBar.js +2 -2
- package/dist/web/list/groups.d.ts +13 -3
- package/dist/web/list/groups.js +21 -8
- package/dist/web/list/openIn.d.ts +4 -2
- package/dist/web/list/openIn.js +9 -2
- package/dist/web/record/ActionButton.d.ts +34 -0
- package/dist/web/record/ActionButton.js +41 -0
- package/dist/web/record/CommandButton.d.ts +5 -6
- package/dist/web/record/CommandButton.js +16 -33
- package/dist/web/record/ServiceButton.d.ts +31 -0
- package/dist/web/record/ServiceButton.js +40 -0
- package/dist/web/record/control.d.ts +9 -3
- package/dist/web/record/control.js +13 -4
- package/dist/web/record/edit.js +1 -1
- package/dist/web/record/lines.js +1 -1
- package/dist/web/record/record.js +36 -3
- package/dist/web/workspace/SincproApp.d.ts +8 -2
- package/dist/web/workspace/SincproApp.js +13 -7
- package/dist/web/workspace/composer.d.ts +6 -2
- package/dist/web/workspace/composer.js +31 -12
- package/dist/web/workspace/open.d.ts +1 -1
- package/dist/web/workspace/open.js +7 -1
- package/dist/web/workspace/record.d.ts +6 -2
- package/dist/web/workspace/record.js +6 -5
- package/dist/web/workspace/workspace.d.ts +7 -1
- package/dist/web/workspace/workspace.js +13 -4
- package/package.json +6 -6
|
@@ -3,10 +3,11 @@ import { type Entity } from "@sincpro/client-framework";
|
|
|
3
3
|
* The name of one record of an entity, by its key — what a field shows when it holds only the
|
|
4
4
|
* key (`EntityID[Tenant]`) and not the record it points at.
|
|
5
5
|
*
|
|
6
|
-
* Context:
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* Context: every name on screen is asked through the provider's book (`nameBook`): the keys asked
|
|
7
|
+
* in the same moment — a page of 50 rows naming 50 tenants — go in ONE request per entity, and a
|
|
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.
|
|
10
11
|
*
|
|
11
12
|
* const name = useNameOf(tenants, record.tenant_id) ?? record.tenant_id;
|
|
12
13
|
*/
|
package/dist/react/useNameOf.js
CHANGED
|
@@ -1,44 +1,43 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { listRoute } from "@sincpro/client-framework";
|
|
3
|
-
import { lookupOf } from "../core/lookup.js";
|
|
4
3
|
import { useFramework } from "./context.js";
|
|
4
|
+
import { useWrites } from "./useWrites.js";
|
|
5
5
|
import { useEffect, useState } from "react";
|
|
6
6
|
/**
|
|
7
7
|
* The name of one record of an entity, by its key — what a field shows when it holds only the
|
|
8
8
|
* key (`EntityID[Tenant]`) and not the record it points at.
|
|
9
9
|
*
|
|
10
|
-
* Context:
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
10
|
+
* Context: every name on screen is asked through the provider's book (`nameBook`): the keys asked
|
|
11
|
+
* in the same moment — a page of 50 rows naming 50 tenants — go in ONE request per entity, and a
|
|
12
|
+
* name already known is shared by every place that shows it. A write to the entity (a rename)
|
|
13
|
+
* asks again. Unnamed is no error — the field shows the key — and an entity listed under another
|
|
14
|
+
* record (`/tenants/{tenant_id}/members`) has no list to ask by key, so it stays unnamed.
|
|
14
15
|
*
|
|
15
16
|
* const name = useNameOf(tenants, record.tenant_id) ?? record.tenant_id;
|
|
16
17
|
*/
|
|
17
18
|
export function useNameOf(entity, id) {
|
|
18
|
-
const {
|
|
19
|
+
const { names, context } = useFramework();
|
|
19
20
|
const [named, setNamed] = useState(undefined);
|
|
21
|
+
const writes = useWrites(entity === undefined ? undefined : routeOf(entity));
|
|
20
22
|
useEffect(() => {
|
|
21
23
|
if (entity === undefined || id === "")
|
|
22
24
|
return;
|
|
23
|
-
let
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const key = known?.get_id || known?.identity || "id";
|
|
32
|
-
const aborter = new AbortController();
|
|
33
|
-
transport
|
|
34
|
-
.list(route, { selection: { field: key, operator: "=", value: id }, pagination: { limit: 1 } }, aborter.signal)
|
|
35
|
-
.then((page) => {
|
|
36
|
-
const [one] = lookupOf(page.meta ?? known ?? null, page.rows, entity.summary);
|
|
37
|
-
if (one !== undefined)
|
|
38
|
-
setNamed({ id, name: one.label });
|
|
39
|
-
})
|
|
40
|
-
.catch(() => undefined);
|
|
41
|
-
return () => aborter.abort();
|
|
42
|
-
}, [transport, metas, entity, id, context]);
|
|
25
|
+
let current = true;
|
|
26
|
+
void names.nameOf(entity, id).then((name) => {
|
|
27
|
+
if (current && name !== undefined)
|
|
28
|
+
setNamed({ id, name });
|
|
29
|
+
});
|
|
30
|
+
return () => void (current = false);
|
|
31
|
+
// `context` and `writes` ask again: another company, or a write to the entity (a rename).
|
|
32
|
+
}, [names, entity, id, context, writes]);
|
|
43
33
|
return named?.id === id ? named.name : undefined;
|
|
44
34
|
}
|
|
35
|
+
/** Where `entity` is listed — or nothing to follow when it is listed only under a record. */
|
|
36
|
+
function routeOf(entity) {
|
|
37
|
+
try {
|
|
38
|
+
return listRoute(entity.list);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
}
|
package/dist/react/usePivot.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { measuresOf, sumsOf } from "../core/measure.js";
|
|
3
3
|
import { useFramework } from "./context.js";
|
|
4
|
+
import { useWrites } from "./useWrites.js";
|
|
4
5
|
import { useEffect, useState } from "react";
|
|
5
6
|
/** The most groups an axis answers: a pivot of ten thousand rows is a list. */
|
|
6
7
|
const MAX_KEYS = 100;
|
|
@@ -18,6 +19,8 @@ export function usePivot(listing, axes) {
|
|
|
18
19
|
const sums = measures.join(",");
|
|
19
20
|
const shape = axes === null ? "" : JSON.stringify([axes.rows, axes.columns]);
|
|
20
21
|
const waiting = axes !== null && axes.measures === undefined && listing.meta === null;
|
|
22
|
+
// Written by anyone — a save, a use case, a panel beside: the crossing is counted again.
|
|
23
|
+
const writes = useWrites(listing.route);
|
|
21
24
|
useEffect(() => {
|
|
22
25
|
if (shape === "") {
|
|
23
26
|
setState({ status: "idle", crossed: [], columns: [], error: null });
|
|
@@ -53,6 +56,6 @@ export function usePivot(listing, axes) {
|
|
|
53
56
|
setState({ status: "failed", crossed: [], columns: [], error });
|
|
54
57
|
});
|
|
55
58
|
return () => aborter.abort();
|
|
56
|
-
}, [transport, listing.route, question, shape, sums, waiting, context]);
|
|
59
|
+
}, [transport, listing.route, question, shape, sums, waiting, context, writes]);
|
|
57
60
|
return { ...state, measures };
|
|
58
61
|
}
|
|
@@ -18,10 +18,10 @@ import { type Advice, type FieldState } from "../core/edit.js";
|
|
|
18
18
|
* - **drafts** — an edit kept between requests (sincpro_framework's `Drafts`) comes back with
|
|
19
19
|
* the record and is shown as restored; `keep()` stores the current one.
|
|
20
20
|
* - **`Edit`** — an entity that declares `edit` speaks sincpro_framework's `Edit` on it for all
|
|
21
|
-
* three: `keep()` is `save_draft`, `save()` is `save` — the
|
|
22
|
-
* the draft version read and the stored version it started
|
|
23
|
-
* `discard`, which drops the draft on the server too. Without it,
|
|
24
|
-
* fields and the version to `save`.
|
|
21
|
+
* three: `keep()` is `save_draft`, `save()` is `save` — the fields changed, without what the
|
|
22
|
+
* framework writes (`editedOf`), the draft version read and the stored version it started
|
|
23
|
+
* from — and `discard()` is `discard`, which drops the draft on the server too. Without it,
|
|
24
|
+
* a save sends the changed fields and the version to `save`.
|
|
25
25
|
* - **creating** — with no id it is a record that does not exist yet: it starts from the
|
|
26
26
|
* defaults the model publishes, previews like any other, and `save()` sends it to the
|
|
27
27
|
* entity's `create` route with an `Idempotency-Key` (a retry never creates two). When the
|
package/dist/react/useRecord.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { newEntityId, pathFor, retryKeys, startingValuesOf, TransportError, WITH_PARAM, } from "@sincpro/client-framework";
|
|
3
|
-
import { changesOf, computedLocally, creationOf, defaultsOf, errorsByField, fieldStateOf, lineStatesOf, missingOf, needsPreview, } from "../core/edit.js";
|
|
3
|
+
import { changesOf, computedLocally, creationOf, defaultsOf, editedOf, errorsByField, fieldStateOf, lineStatesOf, missingOf, needsPreview, } from "../core/edit.js";
|
|
4
4
|
import { linesAnswered } from "../core/lines.js";
|
|
5
5
|
import { useFramework } from "./context.js";
|
|
6
|
+
import { useWrites } from "./useWrites.js";
|
|
6
7
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
7
8
|
/** How long typing has to pause before the server is asked what the record becomes. */
|
|
8
9
|
const PREVIEW_PAUSE = 300;
|
|
@@ -138,16 +139,19 @@ export function useRecord(entity, opened) {
|
|
|
138
139
|
};
|
|
139
140
|
}, []);
|
|
140
141
|
const reload = useCallback(() => setRound((n) => n + 1), []);
|
|
141
|
-
// Another company (the process's context changed)
|
|
142
|
-
//
|
|
143
|
-
|
|
142
|
+
// Another company (the process's context changed), or a write to it — anyone's: a use case, a
|
|
143
|
+
// panel beside —: a record with nothing typed reads again; one being edited keeps what was
|
|
144
|
+
// typed — losing it is never the framework's decision, and its save still meets the version
|
|
145
|
+
// it read (a 409 when someone saved). Its own save reads it again by itself.
|
|
146
|
+
const writes = useWrites(isNew ? undefined : entity.one(id));
|
|
147
|
+
const askedFor = useRef({ context, writes });
|
|
144
148
|
useEffect(() => {
|
|
145
|
-
if (
|
|
149
|
+
if (askedFor.current.context === context && askedFor.current.writes === writes)
|
|
146
150
|
return;
|
|
147
|
-
|
|
151
|
+
askedFor.current = { context, writes };
|
|
148
152
|
if (Object.keys(typedNow.current).length === 0)
|
|
149
153
|
reload();
|
|
150
|
-
}, [context, reload]);
|
|
154
|
+
}, [context, writes, reload]);
|
|
151
155
|
const record = useMemo(() => (state.record ?? {}), [state.record]);
|
|
152
156
|
const values = useMemo(() => ({ ...record, ...computed, ...typed }), [record, computed, typed]);
|
|
153
157
|
const changed = useMemo(() => changesOf(record, typed), [record, typed]);
|
|
@@ -228,14 +232,17 @@ export function useRecord(entity, opened) {
|
|
|
228
232
|
else
|
|
229
233
|
setFailure(error);
|
|
230
234
|
};
|
|
231
|
-
// sincpro_framework's `Edit`:
|
|
232
|
-
//
|
|
233
|
-
//
|
|
235
|
+
// sincpro_framework's `Edit`: what the form writes; the fields changed; the draft version read
|
|
236
|
+
// (`0`: none) — another tab that kept first wins —, and the stored version the edit started
|
|
237
|
+
// from. Without an `action` it is the server's default, `save_draft`.
|
|
234
238
|
const editOf = (action) => ({
|
|
235
239
|
id: keyNow(),
|
|
236
|
-
//
|
|
237
|
-
//
|
|
238
|
-
|
|
240
|
+
// Never a field the framework writes (its id, its stamps, a line's version), which `Edit`
|
|
241
|
+
// refuses: a new record carries what a person may write, a stored one what changed — the
|
|
242
|
+
// server puts it over what it stored and the caller's draft.
|
|
243
|
+
values: isNew
|
|
244
|
+
? creationOf(state.meta, values)
|
|
245
|
+
: editedOf(state.meta, values, Object.keys(changed)),
|
|
239
246
|
changed: Object.keys(changed),
|
|
240
247
|
version: draft?.version ?? 0,
|
|
241
248
|
...(typeof version === "number" ? { origin_version: version } : {}),
|
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
* What a screen keeps of running one of the application's use cases.
|
|
3
3
|
*
|
|
4
4
|
* `run` answers what the use case answered, or `undefined` when it failed — the failure is in
|
|
5
|
-
* `error`, for the screen to say (`explain`, `Refused`); it never throws at the screen.
|
|
5
|
+
* `error`, for the screen to say (`explain`, `Refused`); it never throws at the screen. So a use
|
|
6
|
+
* case that answers nothing answers `null`, never `undefined`: a `DELETE` the server answers
|
|
7
|
+
* with 204 resolves `null` through the transport, and a Feature hands that on instead of typing
|
|
8
|
+
* itself `void` — or «done» and «failed» look the same to the screen
|
|
9
|
+
* (Sincpro-SRL/sincpro_client_framework#51).
|
|
6
10
|
*/
|
|
7
11
|
export type ServiceState<A extends unknown[], R> = {
|
|
8
12
|
run: (...args: A) => Promise<R | undefined>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type Entity } from "@sincpro/client-framework";
|
|
2
|
+
/** What a screen shows of a use case that reads: the answer to the arguments it asks with NOW. */
|
|
3
|
+
export type ServiceReading<R> = {
|
|
4
|
+
/** `loading` until the answer to these arguments arrives — never another's answer. */
|
|
5
|
+
status: "loading" | "ready" | "failed";
|
|
6
|
+
answer: R | undefined;
|
|
7
|
+
error: unknown;
|
|
8
|
+
/** Read again with the same arguments; the answer stays on screen until the new one. */
|
|
9
|
+
reload: () => void;
|
|
10
|
+
};
|
|
11
|
+
/** A use case as a screen reads with it: a method of a service, read from its bounded context. */
|
|
12
|
+
type UseCase<A extends unknown[], R> = (...args: A) => R | Promise<R>;
|
|
13
|
+
/**
|
|
14
|
+
* A use case that READS, run by the screen that shows it: on mount, again whenever its
|
|
15
|
+
* arguments change, when the process's context changes (another company), and when a write
|
|
16
|
+
* touches an entity it follows.
|
|
17
|
+
*
|
|
18
|
+
* const balance = useServiceReading(members.Accounts.balance, [{ member_id }], {
|
|
19
|
+
* follows: [payments],
|
|
20
|
+
* });
|
|
21
|
+
* balance.status === "ready" ? <Stat value={text.money(balance.answer)} /> : <Skeleton />
|
|
22
|
+
*
|
|
23
|
+
* Context: `useService` is an ACTION's — it runs when a person presses, never on mount — and a
|
|
24
|
+
* screen that read with it re-ran it by hand when a route param changed: easy to miss, and the
|
|
25
|
+
* screen kept showing the answer of the tab it left. Here a reading is keyed by its arguments
|
|
26
|
+
* (as JSON): the answer of other arguments is never shown — another member starts as `loading`,
|
|
27
|
+
* as `useRecord` does for another id — while reading the same ones again keeps the answer on
|
|
28
|
+
* screen until the new one lands. The last question wins: an answer to arguments no longer on
|
|
29
|
+
* screen is dropped. The use case is the latest the screen gave (a bounded context answers a new
|
|
30
|
+
* function per `scoped(…)`); its trace and report are the service's, never this hook's.
|
|
31
|
+
*/
|
|
32
|
+
export declare function useServiceReading<A extends unknown[], R>(useCase: UseCase<A, R>, args: A, options?: {
|
|
33
|
+
follows?: readonly Entity[];
|
|
34
|
+
}): ServiceReading<Awaited<R>>;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { listRoute } from "@sincpro/client-framework";
|
|
3
|
+
import { touches } from "../core/changes.js";
|
|
4
|
+
import { useFramework } from "./context.js";
|
|
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
|
+
/**
|
|
16
|
+
* A use case that READS, run by the screen that shows it: on mount, again whenever its
|
|
17
|
+
* arguments change, when the process's context changes (another company), and when a write
|
|
18
|
+
* touches an entity it follows.
|
|
19
|
+
*
|
|
20
|
+
* const balance = useServiceReading(members.Accounts.balance, [{ member_id }], {
|
|
21
|
+
* follows: [payments],
|
|
22
|
+
* });
|
|
23
|
+
* balance.status === "ready" ? <Stat value={text.money(balance.answer)} /> : <Skeleton />
|
|
24
|
+
*
|
|
25
|
+
* Context: `useService` is an ACTION's — it runs when a person presses, never on mount — and a
|
|
26
|
+
* screen that read with it re-ran it by hand when a route param changed: easy to miss, and the
|
|
27
|
+
* screen kept showing the answer of the tab it left. Here a reading is keyed by its arguments
|
|
28
|
+
* (as JSON): the answer of other arguments is never shown — another member starts as `loading`,
|
|
29
|
+
* as `useRecord` does for another id — while reading the same ones again keeps the answer on
|
|
30
|
+
* screen until the new one lands. The last question wins: an answer to arguments no longer on
|
|
31
|
+
* screen is dropped. The use case is the latest the screen gave (a bounded context answers a new
|
|
32
|
+
* function per `scoped(…)`); its trace and report are the service's, never this hook's.
|
|
33
|
+
*/
|
|
34
|
+
export function useServiceReading(useCase, args, options = {}) {
|
|
35
|
+
const { context, changes, entities } = useFramework();
|
|
36
|
+
const key = JSON.stringify(args);
|
|
37
|
+
const latest = useRef({ useCase, args });
|
|
38
|
+
latest.current = { useCase, args };
|
|
39
|
+
const [answered, setAnswered] = useState(null);
|
|
40
|
+
const [again, setAgain] = useState(0);
|
|
41
|
+
// A write anyone sends — a save, another use case, a panel beside — to what it follows.
|
|
42
|
+
const followed = (options.follows ?? [])
|
|
43
|
+
.map(routeOf)
|
|
44
|
+
.filter((route) => route !== undefined)
|
|
45
|
+
.join("\n");
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (followed === "")
|
|
48
|
+
return;
|
|
49
|
+
const routes = followed.split("\n");
|
|
50
|
+
return changes.follow((change) => {
|
|
51
|
+
if (routes.some((route) => touches(change, route, entities)))
|
|
52
|
+
setAgain((n) => n + 1);
|
|
53
|
+
});
|
|
54
|
+
}, [changes, entities, followed]);
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
let current = true;
|
|
57
|
+
const { useCase: read, args: now } = latest.current;
|
|
58
|
+
// Through the promise: a use case that throws before it answers is a failure like any other.
|
|
59
|
+
Promise.resolve()
|
|
60
|
+
.then(() => read(...now))
|
|
61
|
+
.then((answer) => {
|
|
62
|
+
if (current)
|
|
63
|
+
setAnswered({ key, status: "ready", answer: answer, error: null });
|
|
64
|
+
}, (error) => {
|
|
65
|
+
if (current)
|
|
66
|
+
setAnswered({ key, status: "failed", answer: undefined, error });
|
|
67
|
+
});
|
|
68
|
+
return () => void (current = false);
|
|
69
|
+
// `context` and `again` read again: another company, a followed write, a `reload()`.
|
|
70
|
+
}, [key, context, again]);
|
|
71
|
+
const reload = useCallback(() => setAgain((n) => n + 1), []);
|
|
72
|
+
if (answered === null || answered.key !== key)
|
|
73
|
+
return { status: "loading", answer: undefined, error: null, reload };
|
|
74
|
+
return { status: answered.status, answer: answered.answer, error: answered.error, reload };
|
|
75
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** What a value a screen holds reads as — each `null` when there is nothing to read. */
|
|
2
|
+
export type ValueTexts = {
|
|
3
|
+
number: (value: unknown) => string | null;
|
|
4
|
+
day: (value: unknown) => string | null;
|
|
5
|
+
instant: (value: unknown) => string | null;
|
|
6
|
+
money: (value: unknown) => string | null;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* The texts of `numberTextOf`, `dayTextOf`, `instantTextOf` and `moneyTextOf`, in the
|
|
10
|
+
* provider's locale and on the zone it installed — for what a screen of its own holds outside a
|
|
11
|
+
* model: a total it added up, a balance a use case answered.
|
|
12
|
+
*
|
|
13
|
+
* const text = useTextOf();
|
|
14
|
+
* <Stat label="Saldo" value={text.money(balance) ?? "—"} />
|
|
15
|
+
*/
|
|
16
|
+
export declare function useTextOf(): ValueTexts;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { dayTextOf, instantTextOf, moneyTextOf, numberTextOf, } from "../core/present.js";
|
|
3
|
+
import { useFramework } from "./context.js";
|
|
4
|
+
import { useMemo } from "react";
|
|
5
|
+
/**
|
|
6
|
+
* The texts of `numberTextOf`, `dayTextOf`, `instantTextOf` and `moneyTextOf`, in the
|
|
7
|
+
* provider's locale and on the zone it installed — for what a screen of its own holds outside a
|
|
8
|
+
* model: a total it added up, a balance a use case answered.
|
|
9
|
+
*
|
|
10
|
+
* const text = useTextOf();
|
|
11
|
+
* <Stat label="Saldo" value={text.money(balance) ?? "—"} />
|
|
12
|
+
*/
|
|
13
|
+
export function useTextOf() {
|
|
14
|
+
const { locale } = useFramework();
|
|
15
|
+
return useMemo(() => ({
|
|
16
|
+
number: (value) => numberTextOf(value, locale),
|
|
17
|
+
day: (value) => dayTextOf(value, locale),
|
|
18
|
+
instant: (value) => instantTextOf(value, locale),
|
|
19
|
+
money: (value) => moneyTextOf(value, locale),
|
|
20
|
+
}), [locale]);
|
|
21
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
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.
|
|
4
|
+
*
|
|
5
|
+
* const writes = useWrites(listRoute(entity.list));
|
|
6
|
+
* useEffect(() => { … transport.list(…) … }, [transport, route, writes]);
|
|
7
|
+
*
|
|
8
|
+
* 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.
|
|
16
|
+
*
|
|
17
|
+
* `undefined`: nothing is read yet, and nothing is counted.
|
|
18
|
+
*/
|
|
19
|
+
export declare function useWrites(route: string | undefined): number;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { touches } from "../core/changes.js";
|
|
3
|
+
import { useFramework } from "./context.js";
|
|
4
|
+
import { useEffect, useState } from "react";
|
|
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.
|
|
8
|
+
*
|
|
9
|
+
* const writes = useWrites(listRoute(entity.list));
|
|
10
|
+
* useEffect(() => { … transport.list(…) … }, [transport, route, writes]);
|
|
11
|
+
*
|
|
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.
|
|
20
|
+
*
|
|
21
|
+
* `undefined`: nothing is read yet, and nothing is counted.
|
|
22
|
+
*/
|
|
23
|
+
export function useWrites(route) {
|
|
24
|
+
const { changes, entities } = useFramework();
|
|
25
|
+
const [writes, setWrites] = useState(0);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (route === undefined)
|
|
28
|
+
return;
|
|
29
|
+
return changes.follow((change) => {
|
|
30
|
+
if (touches(change, route, entities))
|
|
31
|
+
setWrites((count) => count + 1);
|
|
32
|
+
});
|
|
33
|
+
}, [changes, entities, route]);
|
|
34
|
+
return writes;
|
|
35
|
+
}
|
package/dist/web/index.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export { type LineColumn, type LineControl, type LinesLook, RecordLinesEditor, }
|
|
|
19
19
|
export { type RecordOpening, RecordOpeningProvider, useRecordOpening, } from "./record/opening.js";
|
|
20
20
|
export { countOf, factsOf, RecordLines } from "./record/record.js";
|
|
21
21
|
export { RelatedList } from "./record/RelatedList.js";
|
|
22
|
+
export { ServiceButton } from "./record/ServiceButton.js";
|
|
22
23
|
export { cardOf, relationOf } from "./record/summary.js";
|
|
23
24
|
export { Refused } from "./Refused.js";
|
|
24
25
|
export { entityView, type EntityViewOptions, listView, type ListViewOptions, } from "./workspace/composer.js";
|
package/dist/web/index.js
CHANGED
|
@@ -19,6 +19,7 @@ export { RecordLinesEditor, } from "./record/lines.js";
|
|
|
19
19
|
export { RecordOpeningProvider, useRecordOpening, } from "./record/opening.js";
|
|
20
20
|
export { countOf, factsOf, RecordLines } from "./record/record.js";
|
|
21
21
|
export { RelatedList } from "./record/RelatedList.js";
|
|
22
|
+
export { ServiceButton } from "./record/ServiceButton.js";
|
|
22
23
|
export { cardOf, relationOf } from "./record/summary.js";
|
|
23
24
|
export { Refused } from "./Refused.js";
|
|
24
25
|
export { entityView, listView, } from "./workspace/composer.js";
|
|
@@ -89,6 +89,9 @@ export type EntityListProps<T extends AnyRecord, C extends CommandBodies = Comma
|
|
|
89
89
|
sums?: readonly string[] | false;
|
|
90
90
|
/** The cuts this list offers by name: «sólo pagadas», «vencidas». */
|
|
91
91
|
filters?: readonly NamedFilter<T>[];
|
|
92
|
+
/** The fields «Group by» offers, in this order — among those the model lets split the set.
|
|
93
|
+
* Without it, the list definition's, else every one the model does. */
|
|
94
|
+
groupable?: readonly string[];
|
|
92
95
|
/**
|
|
93
96
|
* Rows can be ticked. With `api`, what is ticked is PUBLISHED to the workspace
|
|
94
97
|
* (`api.select`): a panel beside it follows the selection without knowing this list.
|
|
@@ -129,4 +132,4 @@ export type EntityFace<T> = {
|
|
|
129
132
|
render: (set: ListSet<T>) => ReactNode;
|
|
130
133
|
};
|
|
131
134
|
export type View = "table" | "rows" | "board" | "sheet" | "pivot";
|
|
132
|
-
export declare function EntityList<T extends AnyRecord, C extends CommandBodies = CommandBodies>({ listing, api, columns: askedColumns, cells, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot: pivotAsked, empty, search, sums, filters: askedFilters, selectable, selectionActions, embedded, create, commands, rowActions: askedRowActions, faces, }: EntityListProps<T, C>): import("react").JSX.Element;
|
|
135
|
+
export declare function EntityList<T extends AnyRecord, C extends CommandBodies = CommandBodies>({ listing, api, columns: askedColumns, cells, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot: pivotAsked, empty, search, sums, filters: askedFilters, groupable: askedGroupable, selectable, selectionActions, embedded, create, commands, rowActions: askedRowActions, faces, }: EntityListProps<T, C>): import("react").JSX.Element;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { PICK_PARAM, QUERY_PARAM, TRAIL_PARAM, } from "@sincpro/client-framework";
|
|
4
4
|
import { nameOf } from "@sincpro/criteria";
|
|
5
|
-
import { RecordLink, useCrumbs } from "@sincpro/web-composer";
|
|
5
|
+
import { RecordLink, useCrumbs, usePhone } from "@sincpro/web-composer";
|
|
6
6
|
import { frameworkCopy } from "../../core/copy.js";
|
|
7
7
|
import { explain } from "../../core/explain.js";
|
|
8
8
|
import { textOf, viewOf } from "../../core/present.js";
|
|
@@ -23,6 +23,7 @@ const NO_TRAIL = [];
|
|
|
23
23
|
const NO_WORKSPACE = {
|
|
24
24
|
crumbs: () => NO_TRAIL,
|
|
25
25
|
context: { subscribe: () => () => undefined },
|
|
26
|
+
layout: { phone: () => false, subscribe: () => () => undefined },
|
|
26
27
|
};
|
|
27
28
|
/** How many lists' trails are kept: the records opened from the last fifty lists page on. */
|
|
28
29
|
const TRAILS = 50;
|
|
@@ -30,7 +31,7 @@ const TRAILS = 50;
|
|
|
30
31
|
const NO_COMMANDS = [];
|
|
31
32
|
/** What a list offers when nobody said: every face that needs no configuration. */
|
|
32
33
|
const EVERY_VIEW = ["table", "rows", "board", "sheet"];
|
|
33
|
-
export function EntityList({ listing, api, columns: askedColumns, cells, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot: pivotAsked, empty, search = "bar", sums, filters: askedFilters, selectable = false, selectionActions, embedded = false, create = true, commands = NO_COMMANDS, rowActions: askedRowActions, faces, }) {
|
|
34
|
+
export function EntityList({ listing, api, columns: askedColumns, cells, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot: pivotAsked, empty, search = "bar", sums, filters: askedFilters, groupable: askedGroupable, selectable = false, selectionActions, embedded = false, create = true, commands = NO_COMMANDS, rowActions: askedRowActions, faces, }) {
|
|
34
35
|
// A named list (`defineList`) brings its own columns, filters, faces and words; what the
|
|
35
36
|
// screen passes wins.
|
|
36
37
|
const definition = listing.definition;
|
|
@@ -39,6 +40,7 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
|
|
|
39
40
|
definition?.views ??
|
|
40
41
|
(embedded ? ["table"] : pivotAsked === undefined ? EVERY_VIEW : [...EVERY_VIEW, "pivot"]);
|
|
41
42
|
const filters = askedFilters ?? definition?.filters ?? [];
|
|
43
|
+
const groupable = askedGroupable ?? definition?.groupable;
|
|
42
44
|
const title = askedTitle ?? definition?.title;
|
|
43
45
|
const description = askedDescription ?? definition?.description;
|
|
44
46
|
const copy = frameworkCopy().list;
|
|
@@ -148,6 +150,7 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
|
|
|
148
150
|
// `useCrumbs`, not `api.crumbs()`: the crumb must follow a name given later (`setTitle`).
|
|
149
151
|
// Without a workspace it reads a trail that never changes — a hook cannot be skipped.
|
|
150
152
|
const following = useCrumbs(api ?? NO_WORKSPACE);
|
|
153
|
+
usePhone(api ?? NO_WORKSPACE); // where a row opens follows the mode (`targetsFor`)
|
|
151
154
|
const trail = crumbs ?? (embedded || api === undefined ? undefined : following);
|
|
152
155
|
const [ticked, setTicked] = useState(() => new Set());
|
|
153
156
|
const tick = (next) => {
|
|
@@ -315,7 +318,7 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
|
|
|
315
318
|
}, filtered: listing.selection !== undefined || listing.text !== "", empty: {
|
|
316
319
|
sentence: empty ?? copy.empty,
|
|
317
320
|
whenFiltered: { sentence: copy.emptyFiltered },
|
|
318
|
-
}, ...(selection === undefined ? {} : { selection }), ...(opening === undefined ? {} : { onOpen: opening }), ...(peeking === undefined ? {} : { onPeek: peeking, rowClick: "open" }), children: [_jsxs(List.Bar, { children: [trail === undefined || trail.length === 0 ? null : _jsx(List.Crumbs, { crumbs: trail }), embedded ? null : (_jsx(List.Identity, { title: title ?? nameOf(meta, locale), ...(description === undefined ? {} : { description }) })), search === "bar" ? (_jsx(List.Search, { children: _jsx(EntitySearchBar, { listing: listing, filters: filters, groups: groups, ...(asked === "" ? {} : { seed: asked }) }) })) : null, search === "box" && meta?.search != null ? (_jsx(List.Search, { children: _jsx(SearchField, { value: draft, onChange: (next) => {
|
|
321
|
+
}, ...(selection === undefined ? {} : { selection }), ...(opening === undefined ? {} : { onOpen: opening }), ...(peeking === undefined ? {} : { onPeek: peeking, rowClick: "open" }), children: [_jsxs(List.Bar, { children: [trail === undefined || trail.length === 0 ? null : _jsx(List.Crumbs, { crumbs: trail }), embedded ? null : (_jsx(List.Identity, { title: title ?? nameOf(meta, locale), ...(description === undefined ? {} : { description }) })), search === "bar" ? (_jsx(List.Search, { children: _jsx(EntitySearchBar, { listing: listing, filters: filters, groups: groups, ...(groupable === undefined ? {} : { groupable }), ...(asked === "" ? {} : { seed: asked }) }) })) : null, search === "box" && meta?.search != null ? (_jsx(List.Search, { children: _jsx(SearchField, { value: draft, onChange: (next) => {
|
|
319
322
|
setDraft(next);
|
|
320
323
|
// Emptied (or cleared with ×): the whole set again, at once.
|
|
321
324
|
if (next === "" && listing.text !== "")
|
|
@@ -23,12 +23,15 @@ import type { Listing } from "../../react/useListing.js";
|
|
|
23
23
|
* <List.Search><EntitySearchBar listing={listing} filters={…} /></List.Search>
|
|
24
24
|
*/
|
|
25
25
|
export type { NamedFilter };
|
|
26
|
-
export declare function EntitySearchBar<T extends AnyRecord>({ listing, filters, groups, seed, }: {
|
|
26
|
+
export declare function EntitySearchBar<T extends AnyRecord>({ listing, filters, groups, groupable: only, seed, }: {
|
|
27
27
|
listing: Listing<T>;
|
|
28
28
|
/** The cuts this set offers by name: «sólo pagadas», «vencidas». */
|
|
29
29
|
filters?: readonly NamedFilter<T>[];
|
|
30
30
|
/** The grouping of the same set (`useGroups(listing)`): offers «Group by». */
|
|
31
31
|
groups?: Groups<T>;
|
|
32
|
+
/** The fields «Group by» offers, in this order — among those the model lets split the set.
|
|
33
|
+
* Without it, every one it does. */
|
|
34
|
+
groupable?: readonly string[];
|
|
32
35
|
/** A text to start on, put as the literal search chip — what was typed in a picker whose
|
|
33
36
|
* «Buscar más…» opened this list. */
|
|
34
37
|
seed?: string;
|
|
@@ -8,14 +8,14 @@ import { CriteriaBuilder, describeFilter, Dialog, fillCopy, filterCriteria, Grou
|
|
|
8
8
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
9
9
|
/** No grouping: one constant, so the control is not handed a new array on every render. */
|
|
10
10
|
const NO_LEVELS = [];
|
|
11
|
-
export function EntitySearchBar({ listing, filters = [], groups, seed, }) {
|
|
11
|
+
export function EntitySearchBar({ listing, filters = [], groups, groupable: only, seed, }) {
|
|
12
12
|
const copy = frameworkCopy().list;
|
|
13
13
|
const { meta, locale } = listing;
|
|
14
14
|
const [put, setPut] = useState([]);
|
|
15
15
|
const [building, setBuilding] = useState(false);
|
|
16
16
|
const model = useMemo(() => (meta ? modelOf(meta, locale) : undefined), [meta, locale]);
|
|
17
17
|
const facets = useMemo(() => (meta ? facetsOf(meta, locale) : []), [meta, locale]);
|
|
18
|
-
const groupable = useMemo(() => groupableOf(meta, locale), [meta, locale]);
|
|
18
|
+
const groupable = useMemo(() => groupableOf(meta, locale, only), [meta, locale, only]);
|
|
19
19
|
const ui = useUiCopy();
|
|
20
20
|
const seeded = useRef(false);
|
|
21
21
|
useEffect(() => {
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import { type AnyRecord, type Bucket, type Meta } from "@sincpro/criteria";
|
|
2
2
|
import type { GroupLevel } from "../../react/useGroups.js";
|
|
3
3
|
import { type GroupableField, type Pile } from "@sincpro/web-ui";
|
|
4
|
-
/**
|
|
5
|
-
*
|
|
6
|
-
|
|
4
|
+
/**
|
|
5
|
+
* The fields the model says may split a set (`groupable`), in its words. The identity splits
|
|
6
|
+
* into groups of one, and the version means nothing to a person: neither is offered. With
|
|
7
|
+
* `only`, the screen's own choice among them, in its order — a name the model does not let
|
|
8
|
+
* split the set is still not offered.
|
|
9
|
+
*
|
|
10
|
+
* Context: sincpro_framework marks a field groupable by its TYPE, so a context's log offered
|
|
11
|
+
* «group by» `correlation_id` and `causation_id`. Which of them mean something to a person is
|
|
12
|
+
* the model's to say (ROADMAP); until it does, and wherever a screen knows better, the screen
|
|
13
|
+
* names them (`EntityList groupable`, `defineList({ groupable })`). Never a list of technical
|
|
14
|
+
* names kept here.
|
|
15
|
+
*/
|
|
16
|
+
export declare function groupableOf(meta: Meta | null, locale?: string, only?: readonly string[]): GroupableField[];
|
|
7
17
|
/**
|
|
8
18
|
* The server's groups as piles, with the words a person reads, and each pile's group so that
|
|
9
19
|
* opening one reads its rows. Rows sit only on the deepest level, once read.
|
package/dist/web/list/groups.js
CHANGED
|
@@ -13,16 +13,29 @@ import { dateLabel, pathKey, } from "@sincpro/web-ui";
|
|
|
13
13
|
*/
|
|
14
14
|
/** The cuts a date offers, coarse to fine — web-ui orders the levels by them. */
|
|
15
15
|
const DATE_GRAINS = ["year", "quarter", "month", "week", "day"];
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
|
|
16
|
+
/**
|
|
17
|
+
* The fields the model says may split a set (`groupable`), in its words. The identity splits
|
|
18
|
+
* into groups of one, and the version means nothing to a person: neither is offered. With
|
|
19
|
+
* `only`, the screen's own choice among them, in its order — a name the model does not let
|
|
20
|
+
* split the set is still not offered.
|
|
21
|
+
*
|
|
22
|
+
* Context: sincpro_framework marks a field groupable by its TYPE, so a context's log offered
|
|
23
|
+
* «group by» `correlation_id` and `causation_id`. Which of them mean something to a person is
|
|
24
|
+
* the model's to say (ROADMAP); until it does, and wherever a screen knows better, the screen
|
|
25
|
+
* names them (`EntityList groupable`, `defineList({ groupable })`). Never a list of technical
|
|
26
|
+
* names kept here.
|
|
27
|
+
*/
|
|
28
|
+
export function groupableOf(meta, locale, only) {
|
|
19
29
|
if (meta === null)
|
|
20
30
|
return [];
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
31
|
+
const names = only ?? Object.keys(meta.fields);
|
|
32
|
+
return names
|
|
33
|
+
.map((name) => [name, meta.fields[name]])
|
|
34
|
+
.filter((entry) => entry[1] !== undefined &&
|
|
35
|
+
entry[1].groupable === true &&
|
|
36
|
+
entry[1].kind === "scalar" &&
|
|
37
|
+
entry[0] !== meta.identity &&
|
|
38
|
+
entry[0] !== "version")
|
|
26
39
|
.map(([name, field]) => ({
|
|
27
40
|
field: name,
|
|
28
41
|
label: labelOf(meta, name, locale),
|
|
@@ -12,7 +12,9 @@ import { type OpenTarget } from "@sincpro/web-ui";
|
|
|
12
12
|
*
|
|
13
13
|
* The places allowed depend on where the list is: from inside a modal, no modal (a second one
|
|
14
14
|
* would replace the first and lose what was typed in it) — composer says where a view is
|
|
15
|
-
* (`api.over`).
|
|
15
|
+
* (`api.over`). On a phone a side panel and a window both open as the page (composer 1.7,
|
|
16
|
+
* `api.layout`), so neither is offered: three entries that do the same are a lie. A screen that
|
|
17
|
+
* draws the menu follows the mode (`usePhone(api)`) so it redraws when it changes.
|
|
16
18
|
*/
|
|
17
19
|
/** A record's form fits; a short task (register a payment) passes its own size. */
|
|
18
20
|
export declare const RECORD_SIZE: {
|
|
@@ -20,7 +22,7 @@ export declare const RECORD_SIZE: {
|
|
|
20
22
|
readonly h: 560;
|
|
21
23
|
};
|
|
22
24
|
/** Where a record may open from this view, the default first. */
|
|
23
|
-
export declare function targetsFor(api: Pick<WorkspaceApi, "over">): readonly OpenTarget[];
|
|
25
|
+
export declare function targetsFor(api: Pick<WorkspaceApi, "over"> & Partial<Pick<WorkspaceApi, "layout">>): readonly OpenTarget[];
|
|
24
26
|
/** web-ui's target as composer's options. Destinations share their names, so only the size is
|
|
25
27
|
* added — to the two that have one. */
|
|
26
28
|
export declare function openOptions(to: OpenTarget, size?: {
|