@sincpro/web-framework 3.2.0 → 3.3.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/dist/web/index.d.ts +3 -2
- package/dist/web/index.js +3 -2
- package/dist/web/list/presentation.d.ts +30 -0
- package/dist/web/list/presentation.js +24 -0
- package/dist/web/record/ActionButton.d.ts +13 -1
- package/dist/web/record/ActionButton.js +22 -6
- package/dist/web/record/CommandButton.d.ts +4 -1
- package/dist/web/record/CommandButton.js +3 -3
- package/dist/web/record/ServiceButton.d.ts +4 -2
- package/dist/web/record/ServiceButton.js +3 -3
- package/dist/web/record/ask.d.ts +21 -8
- package/dist/web/record/ask.js +36 -32
- package/dist/web/record/edit.js +2 -2
- package/dist/web/record/lines.d.ts +4 -0
- package/dist/web/record/lines.js +18 -3
- package/dist/web/record/record.d.ts +25 -1
- package/dist/web/record/record.js +38 -4
- package/dist/web/workspace/record.d.ts +1 -1
- package/package.json +1 -1
package/dist/web/index.d.ts
CHANGED
|
@@ -7,9 +7,10 @@ export { EntitySearchBar } from "./list/EntitySearchBar.js";
|
|
|
7
7
|
export { groupableOf, pilesOf } from "./list/groups.js";
|
|
8
8
|
export { OpenInMenu } from "./list/openIn.js";
|
|
9
9
|
export { pivotOf } from "./list/pivot.js";
|
|
10
|
-
export { type CardLook, type ChoiceTones, type OptionLook, type Presentation, presentationOf, type Presented, presented, type RowLook, } from "./list/presentation.js";
|
|
10
|
+
export { type CardLook, type ChoiceTones, type OptionLook, type PartLook, partLookOf, type PartLooks, type PartOf, type Presentation, presentationOf, type Presented, presented, type RowLook, tonesOver, } from "./list/presentation.js";
|
|
11
11
|
export { type RowCommand, type RowCommands, useRowCommands, } from "./list/rowCommands.js";
|
|
12
12
|
export { facetsOf, modelOf } from "./list/search.js";
|
|
13
|
+
export { type ActionDialog, type Asked, } from "./record/ActionButton.js";
|
|
13
14
|
export { type AskedField, type AskField, type AskForm, askFormOf, } from "./record/ask.js";
|
|
14
15
|
export { CommandButton } from "./record/CommandButton.js";
|
|
15
16
|
export { RelationPicker } from "./record/control.js";
|
|
@@ -18,7 +19,7 @@ export { EntityPicker } from "./record/EntityPicker.js";
|
|
|
18
19
|
export { EntityTags } from "./record/EntityTags.js";
|
|
19
20
|
export { type LineColumn, type LineControl, type LinesLook, RecordLinesEditor, } from "./record/lines.js";
|
|
20
21
|
export { type RecordOpening, RecordOpeningProvider, useRecordOpening, } from "./record/opening.js";
|
|
21
|
-
export { countOf, factsOf, RecordLines } from "./record/record.js";
|
|
22
|
+
export { countOf, factsOf, RecordLines, usePartLook, } from "./record/record.js";
|
|
22
23
|
export { RecordLifecycle } from "./record/RecordLifecycle.js";
|
|
23
24
|
export { RelatedList } from "./record/RelatedList.js";
|
|
24
25
|
export { ServiceButton } from "./record/ServiceButton.js";
|
package/dist/web/index.js
CHANGED
|
@@ -7,9 +7,10 @@ export { EntitySearchBar } from "./list/EntitySearchBar.js";
|
|
|
7
7
|
export { groupableOf, pilesOf } from "./list/groups.js";
|
|
8
8
|
export { OpenInMenu } from "./list/openIn.js";
|
|
9
9
|
export { pivotOf } from "./list/pivot.js";
|
|
10
|
-
export { presentationOf, presented, } from "./list/presentation.js";
|
|
10
|
+
export { partLookOf, presentationOf, presented, tonesOver, } from "./list/presentation.js";
|
|
11
11
|
export { useRowCommands, } from "./list/rowCommands.js";
|
|
12
12
|
export { facetsOf, modelOf } from "./list/search.js";
|
|
13
|
+
export {} from "./record/ActionButton.js";
|
|
13
14
|
export { askFormOf, } from "./record/ask.js";
|
|
14
15
|
export { CommandButton } from "./record/CommandButton.js";
|
|
15
16
|
export { RelationPicker } from "./record/control.js";
|
|
@@ -18,7 +19,7 @@ export { EntityPicker } from "./record/EntityPicker.js";
|
|
|
18
19
|
export { EntityTags } from "./record/EntityTags.js";
|
|
19
20
|
export { RecordLinesEditor, } from "./record/lines.js";
|
|
20
21
|
export { RecordOpeningProvider, useRecordOpening, } from "./record/opening.js";
|
|
21
|
-
export { countOf, factsOf, RecordLines } from "./record/record.js";
|
|
22
|
+
export { countOf, factsOf, RecordLines, usePartLook, } from "./record/record.js";
|
|
22
23
|
export { RecordLifecycle } from "./record/RecordLifecycle.js";
|
|
23
24
|
export { RelatedList } from "./record/RelatedList.js";
|
|
24
25
|
export { ServiceButton } from "./record/ServiceButton.js";
|
|
@@ -58,6 +58,28 @@ export type Presentation<T> = {
|
|
|
58
58
|
/** The fields a table of its records shows when the screen names none — on its own list and
|
|
59
59
|
* inside another record (a one2many) alike. Without it, every field but the stamps. */
|
|
60
60
|
columns?: readonly (keyof T & string)[];
|
|
61
|
+
/**
|
|
62
|
+
* How the parts its records hold look — the rows of a relation with no entity of its own (an
|
|
63
|
+
* issue's runs, a tenant's members), by the relation's name, typed by the part:
|
|
64
|
+
*
|
|
65
|
+
* presented(issues, { tones: { status: ISSUE_TONE }, parts: { runs: { tones: { status: RUN_TONE } } } })
|
|
66
|
+
*
|
|
67
|
+
* Context: a part has no route, so there is no `presented(runs, …)` to declare it with; its
|
|
68
|
+
* look belongs to the record that holds it. Declared here, every place that draws those rows
|
|
69
|
+
* reads it — `RecordLines`, the lines editor, a `RecordField` — and a screen passes its own
|
|
70
|
+
* only to change it.
|
|
71
|
+
*/
|
|
72
|
+
parts?: PartLooks<T>;
|
|
73
|
+
};
|
|
74
|
+
/** How a record's part looks: what `Presentation` says of an entity, for a row it holds. */
|
|
75
|
+
export type PartLook<P> = Pick<Presentation<P>, "tones" | "columns">;
|
|
76
|
+
/** The record a field holds many of — an `EntityCollection<Run>`, a `Run[]` — or `never`. */
|
|
77
|
+
export type PartOf<V> = unknown extends V ? AnyRecord : NonNullable<V> extends {
|
|
78
|
+
readonly items: readonly (infer P)[];
|
|
79
|
+
} ? P : NonNullable<V> extends readonly (infer P)[] ? P : never;
|
|
80
|
+
/** A part's look by the name of the field that holds it — only fields that hold many. */
|
|
81
|
+
export type PartLooks<T> = {
|
|
82
|
+
readonly [K in keyof T & string as [PartOf<T[K]>] extends [never] ? never : K]?: PartLook<PartOf<T[K]>>;
|
|
61
83
|
};
|
|
62
84
|
export type Presented<T extends AnyRecord, C extends CommandBodies = CommandBodies, A extends CommandAnswers = CommandAnswers> = Entity<T, C, A> & {
|
|
63
85
|
readonly presentation: Presentation<T>;
|
|
@@ -66,5 +88,13 @@ export type Presented<T extends AnyRecord, C extends CommandBodies = CommandBodi
|
|
|
66
88
|
export declare function presented<T extends AnyRecord, C extends CommandBodies = CommandBodies, A extends CommandAnswers = CommandAnswers>(entity: Entity<T, C, A>, presentation: Presentation<T>): Presented<T, C, A>;
|
|
67
89
|
/** The presentation an entity — or the entity of a named list — was declared with; none is `{}`. */
|
|
68
90
|
export declare function presentationOf<T extends AnyRecord>(source: Entity<T> | ListDefinition<T>): Presentation<T>;
|
|
91
|
+
/** How the parts an entity's records hold under `name` look; `{}` when it declares nothing. */
|
|
92
|
+
export declare function partLookOf(entity: Entity | ListDefinition<AnyRecord> | undefined, name: string): PartLook<AnyRecord>;
|
|
93
|
+
/**
|
|
94
|
+
* The tones of each layer over the one before, value by value — the entity's, then a part's
|
|
95
|
+
* declaration, then the screen's: a screen that colours `failed` keeps the declared `done`.
|
|
96
|
+
* `undefined` when no layer says anything.
|
|
97
|
+
*/
|
|
98
|
+
export declare function tonesOver<T>(...layers: readonly (ChoiceTones<T> | undefined)[]): ChoiceTones<T> | undefined;
|
|
69
99
|
/** `look` over `base`, leaving out what `look` sets to `undefined`: «no tags» is not a hole. */
|
|
70
100
|
export declare function over<B extends object, L extends object>(base: B, look: L | undefined): B;
|
|
@@ -10,6 +10,30 @@ export function presentationOf(source) {
|
|
|
10
10
|
const base = isList(source) ? source.entity : source;
|
|
11
11
|
return "presentation" in base ? base.presentation : {};
|
|
12
12
|
}
|
|
13
|
+
/** How the parts an entity's records hold under `name` look; `{}` when it declares nothing. */
|
|
14
|
+
export function partLookOf(entity, name) {
|
|
15
|
+
if (entity === undefined)
|
|
16
|
+
return {};
|
|
17
|
+
const parts = presentationOf(entity).parts;
|
|
18
|
+
return parts?.[name] ?? {};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The tones of each layer over the one before, value by value — the entity's, then a part's
|
|
22
|
+
* declaration, then the screen's: a screen that colours `failed` keeps the declared `done`.
|
|
23
|
+
* `undefined` when no layer says anything.
|
|
24
|
+
*/
|
|
25
|
+
export function tonesOver(...layers) {
|
|
26
|
+
const said = layers.filter((one) => one !== undefined);
|
|
27
|
+
if (said.length === 0)
|
|
28
|
+
return undefined;
|
|
29
|
+
if (said.length === 1)
|
|
30
|
+
return said[0];
|
|
31
|
+
const out = {};
|
|
32
|
+
for (const layer of said)
|
|
33
|
+
for (const [field, tones] of Object.entries(layer))
|
|
34
|
+
out[field] = { ...out[field], ...tones };
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
13
37
|
/** `look` over `base`, leaving out what `look` sets to `undefined`: «no tags» is not a hole. */
|
|
14
38
|
export function over(base, look) {
|
|
15
39
|
if (look === undefined)
|
|
@@ -2,6 +2,13 @@ import type { Rehearsal } from "../../react/useCommand.js";
|
|
|
2
2
|
import type { AskForm } from "./ask.js";
|
|
3
3
|
/** What a person filled in before the action runs, by field name. */
|
|
4
4
|
export type Asked = Readonly<Record<string, unknown>>;
|
|
5
|
+
/** What an action's window says, when the screen says it its way. */
|
|
6
|
+
export type ActionDialog = {
|
|
7
|
+
/** Its title — the button's label without the «…» that said a window would open. */
|
|
8
|
+
title?: string;
|
|
9
|
+
/** One sentence under the title: what the action does, or what it takes. */
|
|
10
|
+
subtitle?: string;
|
|
11
|
+
};
|
|
5
12
|
/**
|
|
6
13
|
* What a button needs of an action to draw it — whatever runs behind: an entity's Command
|
|
7
14
|
* (`useCommand`) or one of the application's use cases (`useService`).
|
|
@@ -31,14 +38,19 @@ export type ButtonAction<R> = {
|
|
|
31
38
|
* «Confirmar»; when it can rehearse, the first «Confirmar» asks what it would do with them and
|
|
32
39
|
* the second does it. A refusal stays in the dialog over the fields, so they can be put right.
|
|
33
40
|
*
|
|
41
|
+
* Its window is titled by the label without its «…», and says more only when the screen does
|
|
42
|
+
* (`dialog`: its own title, a sentence under it).
|
|
43
|
+
*
|
|
34
44
|
* Internal: the gesture is drawn here once; what runs behind is each button's own.
|
|
35
45
|
*/
|
|
36
|
-
export declare function ActionButton<R>({ action, label, role, disabled, ask: form, onDone, }: {
|
|
46
|
+
export declare function ActionButton<R>({ action, label, role, disabled, ask: form, dialog, onDone, }: {
|
|
37
47
|
action: ButtonAction<R>;
|
|
38
48
|
label: string;
|
|
39
49
|
role?: "primary" | "secondary" | "ghost";
|
|
40
50
|
disabled?: boolean;
|
|
41
51
|
/** What it asks for before it runs — `askFormOf`. */
|
|
42
52
|
ask?: AskForm;
|
|
53
|
+
/** What its window says, over the default. */
|
|
54
|
+
dialog?: ActionDialog;
|
|
43
55
|
onDone?: (answer: R) => void;
|
|
44
56
|
}): import("react").JSX.Element;
|
|
@@ -4,8 +4,18 @@ import { frameworkCopy } from "../../core/copy.js";
|
|
|
4
4
|
import { Refused } from "../Refused.js";
|
|
5
5
|
import { Button, Dialog, Field, FormSection } from "@sincpro/web-ui";
|
|
6
6
|
import { useState } from "react";
|
|
7
|
+
/**
|
|
8
|
+
* The words of an action's window. A button that opens one says so with «…» — «Agregar a un
|
|
9
|
+
* tenant…» —; the window is already open, so its title says it once, without them.
|
|
10
|
+
*/
|
|
11
|
+
function wordsOf(label, dialog) {
|
|
12
|
+
return {
|
|
13
|
+
title: dialog?.title ?? label.replace(/\s*(?:…|\.\.\.)$/u, ""),
|
|
14
|
+
...(dialog?.subtitle === undefined ? {} : { subtitle: dialog.subtitle }),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
7
17
|
/** The fields of an action that asks, its refusal over them and what its dry run said. */
|
|
8
|
-
function AskDialog({ action, form,
|
|
18
|
+
function AskDialog({ action, form, words, onClose, onDone, }) {
|
|
9
19
|
const copy = frameworkCopy().command;
|
|
10
20
|
const [values, setValues] = useState(() => ({ ...form.initial }));
|
|
11
21
|
const rehearsing = action.rehearse !== undefined;
|
|
@@ -18,7 +28,7 @@ function AskDialog({ action, form, label, onClose, onDone, }) {
|
|
|
18
28
|
if (answer !== undefined)
|
|
19
29
|
onDone(answer);
|
|
20
30
|
};
|
|
21
|
-
return (_jsxs(Dialog, { open: true,
|
|
31
|
+
return (_jsxs(Dialog, { open: true, ...words, onClose: onClose, footer: _jsxs("div", { className: "flex justify-end gap-2", children: [_jsx(Button, { size: "sm", role: "secondary", onClick: onClose, children: copy.cancel }), _jsx(Button, { size: "sm", role: "primary", disabled: action.busy, onClick: () => void confirm(), children: rehearsing && action.rehearsal !== null ? copy.confirm : copy.send })] }), children: [action.error === null ? null : _jsx(Refused, { error: action.error }), _jsx(FormSection, { children: form.fields.map((field) => {
|
|
22
32
|
const control = {
|
|
23
33
|
value: values[field.name],
|
|
24
34
|
set: (next) => {
|
|
@@ -31,7 +41,9 @@ function AskDialog({ action, form, label, onClose, onDone, }) {
|
|
|
31
41
|
invalid: false,
|
|
32
42
|
label: field.label,
|
|
33
43
|
};
|
|
34
|
-
|
|
44
|
+
// A control that names itself is not wrapped in a `Field` (its name would double):
|
|
45
|
+
// what is expected goes under it.
|
|
46
|
+
return field.labelled ? (_jsxs("div", { className: "flex flex-col gap-1", children: [field.draw(control), field.hint === undefined ? null : (_jsx("p", { className: "text-meta text-muted", children: field.hint }))] }, field.name)) : (_jsx(Field, { label: field.label, ...(field.hint === undefined ? {} : { hint: field.hint }), children: field.draw(control) }, field.name));
|
|
35
47
|
}) }), action.rehearsal === null ? null : _jsx("p", { className: "text-ink", children: action.rehearsal.text })] }));
|
|
36
48
|
}
|
|
37
49
|
/**
|
|
@@ -47,13 +59,17 @@ function AskDialog({ action, form, label, onClose, onDone, }) {
|
|
|
47
59
|
* «Confirmar»; when it can rehearse, the first «Confirmar» asks what it would do with them and
|
|
48
60
|
* the second does it. A refusal stays in the dialog over the fields, so they can be put right.
|
|
49
61
|
*
|
|
62
|
+
* Its window is titled by the label without its «…», and says more only when the screen does
|
|
63
|
+
* (`dialog`: its own title, a sentence under it).
|
|
64
|
+
*
|
|
50
65
|
* Internal: the gesture is drawn here once; what runs behind is each button's own.
|
|
51
66
|
*/
|
|
52
|
-
export function ActionButton({ action, label, role = "secondary", disabled = false, ask: form, onDone, }) {
|
|
67
|
+
export function ActionButton({ action, label, role = "secondary", disabled = false, ask: form, dialog, onDone, }) {
|
|
53
68
|
const copy = frameworkCopy().command;
|
|
54
69
|
const [open, setOpen] = useState(false);
|
|
70
|
+
const words = wordsOf(label, dialog);
|
|
55
71
|
if (form !== undefined)
|
|
56
|
-
return (_jsxs(_Fragment, { children: [_jsx(Button, { size: "sm", role: role, disabled: disabled || action.busy, onClick: () => setOpen(true), children: label }), open ? (_jsx(AskDialog, { action: action, form: form,
|
|
72
|
+
return (_jsxs(_Fragment, { children: [_jsx(Button, { size: "sm", role: role, disabled: disabled || action.busy, onClick: () => setOpen(true), children: label }), open ? (_jsx(AskDialog, { action: action, form: form, words: words, onClose: () => {
|
|
57
73
|
setOpen(false);
|
|
58
74
|
action.reset();
|
|
59
75
|
}, onDone: (answer) => {
|
|
@@ -80,5 +96,5 @@ export function ActionButton({ action, label, role = "secondary", disabled = fal
|
|
|
80
96
|
setOpen(false);
|
|
81
97
|
action.reset();
|
|
82
98
|
};
|
|
83
|
-
return (_jsxs(_Fragment, { children: [_jsx(Button, { size: "sm", role: destructive ? "secondary" : role, disabled: disabled || action.busy, onClick: () => void (destructive ? ask() : run()), children: label }), open ? (_jsx(Dialog, { open: true,
|
|
99
|
+
return (_jsxs(_Fragment, { children: [_jsx(Button, { size: "sm", role: destructive ? "secondary" : role, disabled: disabled || action.busy, onClick: () => void (destructive ? ask() : run()), children: label }), open ? (_jsx(Dialog, { open: true, ...words, onClose: close, footer: destructive && action.error === null ? (_jsxs("div", { className: "flex justify-end gap-2", children: [_jsx(Button, { size: "sm", role: "secondary", onClick: close, children: copy.cancel }), _jsx(Button, { size: "sm", role: "primary", disabled: action.busy || action.rehearsal === null, onClick: () => void run(), children: copy.confirm })] })) : undefined, children: action.error !== null ? (_jsx(Refused, { error: action.error })) : action.rehearsal === null ? (_jsx("p", { className: "text-meta text-muted", children: copy.rehearsing })) : (_jsx("p", { className: "text-ink", children: action.rehearsal.text })) })) : null] }));
|
|
84
100
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type CommandAnswers, type CommandBodies, type Entity } from "@sincpro/client-framework";
|
|
2
2
|
import type { AnyRecord } from "@sincpro/criteria";
|
|
3
3
|
import { type AnswerOf } from "../../react/useCommand.js";
|
|
4
|
+
import { type ActionDialog } from "./ActionButton.js";
|
|
4
5
|
import { type AskField } from "./ask.js";
|
|
5
6
|
/**
|
|
6
7
|
* An entity's Command as a button: sent as it is, over the screens' transport.
|
|
@@ -14,7 +15,7 @@ import { type AskField } from "./ask.js";
|
|
|
14
15
|
* record's fields of the same name, filled from `record`, and what is filled goes in the body
|
|
15
16
|
* beside `body`.
|
|
16
17
|
*/
|
|
17
|
-
export declare function CommandButton<T extends AnyRecord, R = unknown, C extends CommandBodies = CommandBodies, N extends keyof C & string = keyof C & string, A extends CommandAnswers = CommandAnswers>({ entity, command, id, body, label, destructive, role, disabled, ask, record, onDone, }: {
|
|
18
|
+
export declare function CommandButton<T extends AnyRecord, R = unknown, C extends CommandBodies = CommandBodies, N extends keyof C & string = keyof C & string, A extends CommandAnswers = CommandAnswers>({ entity, command, id, body, label, destructive, role, disabled, ask, record, dialog, onDone, }: {
|
|
18
19
|
entity: Entity<T, C, A>;
|
|
19
20
|
/** One the entity declares; a typed entity takes only its own names. */
|
|
20
21
|
command: N;
|
|
@@ -31,5 +32,7 @@ export declare function CommandButton<T extends AnyRecord, R = unknown, C extend
|
|
|
31
32
|
ask?: readonly AskField[];
|
|
32
33
|
/** The record it acts on: what the asked fields start with. */
|
|
33
34
|
record?: AnyRecord;
|
|
35
|
+
/** What its window says — its title (the label without «…» by default), a sentence under it. */
|
|
36
|
+
dialog?: ActionDialog;
|
|
34
37
|
onDone?: (answer: AnswerOf<R, A, N>) => void;
|
|
35
38
|
}): import("react").JSX.Element;
|
|
@@ -4,7 +4,7 @@ import {} from "@sincpro/client-framework";
|
|
|
4
4
|
import { entityFor } from "../../core/relation.js";
|
|
5
5
|
import { useFramework } from "../../react/context.js";
|
|
6
6
|
import { useCommand } from "../../react/useCommand.js";
|
|
7
|
-
import { ActionButton } from "./ActionButton.js";
|
|
7
|
+
import { ActionButton, } from "./ActionButton.js";
|
|
8
8
|
import { askFormOf } from "./ask.js";
|
|
9
9
|
/**
|
|
10
10
|
* An entity's Command as a button: sent as it is, over the screens' transport.
|
|
@@ -18,7 +18,7 @@ import { askFormOf } from "./ask.js";
|
|
|
18
18
|
* record's fields of the same name, filled from `record`, and what is filled goes in the body
|
|
19
19
|
* beside `body`.
|
|
20
20
|
*/
|
|
21
|
-
export function CommandButton({ entity, command, id, body, label, destructive = false, role = "secondary", disabled = false, ask, record, onDone, }) {
|
|
21
|
+
export function CommandButton({ entity, command, id, body, label, destructive = false, role = "secondary", disabled = false, ask, record, dialog, onDone, }) {
|
|
22
22
|
const sending = useCommand(entity, command);
|
|
23
23
|
const { metas, entities, locale } = useFramework();
|
|
24
24
|
const form = ask === undefined
|
|
@@ -30,7 +30,7 @@ export function CommandButton({ entity, command, id, body, label, destructive =
|
|
|
30
30
|
entityFor: (target) => entityFor(entities, target, metas.get),
|
|
31
31
|
});
|
|
32
32
|
const bodyWith = (asked) => (asked === undefined ? body : { ...body, ...asked });
|
|
33
|
-
return (_jsx(ActionButton, { ...(form === undefined ? {} : { ask: form }), action: {
|
|
33
|
+
return (_jsx(ActionButton, { ...(form === undefined ? {} : { ask: form }), ...(dialog === undefined ? {} : { dialog }), action: {
|
|
34
34
|
run: (asked) => sending.run(id, bodyWith(asked)),
|
|
35
35
|
...(destructive
|
|
36
36
|
? { rehearse: (asked) => sending.rehearse(id, bodyWith(asked)) }
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Entity } from "@sincpro/client-framework";
|
|
2
2
|
import type { AnyRecord } from "@sincpro/criteria";
|
|
3
3
|
import type { Rehearsal } from "../../react/useCommand.js";
|
|
4
|
-
import { type Asked } from "./ActionButton.js";
|
|
4
|
+
import { type ActionDialog, type Asked } from "./ActionButton.js";
|
|
5
5
|
import { type AskField } from "./ask.js";
|
|
6
6
|
/**
|
|
7
7
|
* One of the application's use cases as a button — its Feature or ApplicationService, run on its
|
|
@@ -28,7 +28,7 @@ import { type AskField } from "./ask.js";
|
|
|
28
28
|
* <ServiceButton label="Delegar áreas" entity={cuentas} record={cuenta} ask={["areas"]}
|
|
29
29
|
* run={(asked) => cuentaBoundedContext.execute(new CommandDelegarAreas(cuenta.id, asked.areas))} />
|
|
30
30
|
*/
|
|
31
|
-
export declare function ServiceButton<R>({ label, run, rehearse, role, disabled, ask, entity, record, onDone, }: {
|
|
31
|
+
export declare function ServiceButton<R>({ label, run, rehearse, role, disabled, ask, entity, record, dialog, onDone, }: {
|
|
32
32
|
label: string;
|
|
33
33
|
/** The use case, executed on its bounded context — with what was asked, when it asks. */
|
|
34
34
|
run: (asked: Asked) => Promise<R>;
|
|
@@ -43,5 +43,7 @@ export declare function ServiceButton<R>({ label, run, rehearse, role, disabled,
|
|
|
43
43
|
entity?: Entity;
|
|
44
44
|
/** The record it acts on: what the asked fields start with. */
|
|
45
45
|
record?: AnyRecord;
|
|
46
|
+
/** What its window says — its title (the label without «…» by default), a sentence under it. */
|
|
47
|
+
dialog?: ActionDialog;
|
|
46
48
|
onDone?: (answer: R) => void;
|
|
47
49
|
}): import("react").JSX.Element;
|
|
@@ -3,7 +3,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
3
3
|
import { entityFor } from "../../core/relation.js";
|
|
4
4
|
import { useFrameworkIfAny } from "../../react/context.js";
|
|
5
5
|
import { useService } from "../../react/useService.js";
|
|
6
|
-
import { ActionButton } from "./ActionButton.js";
|
|
6
|
+
import { ActionButton, } from "./ActionButton.js";
|
|
7
7
|
import { askFormOf } from "./ask.js";
|
|
8
8
|
/** What the button runs when there is no dry run: nothing. */
|
|
9
9
|
const NO_REHEARSAL = async (_asked) => undefined;
|
|
@@ -34,7 +34,7 @@ const NOTHING_ASKED = {};
|
|
|
34
34
|
* <ServiceButton label="Delegar áreas" entity={cuentas} record={cuenta} ask={["areas"]}
|
|
35
35
|
* run={(asked) => cuentaBoundedContext.execute(new CommandDelegarAreas(cuenta.id, asked.areas))} />
|
|
36
36
|
*/
|
|
37
|
-
export function ServiceButton({ label, run, rehearse, role = "secondary", disabled = false, ask, entity, record, onDone, }) {
|
|
37
|
+
export function ServiceButton({ label, run, rehearse, role = "secondary", disabled = false, ask, entity, record, dialog, onDone, }) {
|
|
38
38
|
const running = useService((asked) => run(asked ?? NOTHING_ASKED));
|
|
39
39
|
const rehearsing = useService((asked) => (rehearse ?? NO_REHEARSAL)(asked ?? NOTHING_ASKED));
|
|
40
40
|
// Outside a provider it still runs: the asked fields are then drawn by what `ask` says.
|
|
@@ -51,7 +51,7 @@ export function ServiceButton({ label, run, rehearse, role = "secondary", disabl
|
|
|
51
51
|
entityFor: (target) => entityFor(framework.entities, target, framework.metas.get),
|
|
52
52
|
}),
|
|
53
53
|
});
|
|
54
|
-
return (_jsx(ActionButton, { ...(form === undefined ? {} : { ask: form }), action: {
|
|
54
|
+
return (_jsx(ActionButton, { ...(form === undefined ? {} : { ask: form }), ...(dialog === undefined ? {} : { dialog }), action: {
|
|
55
55
|
run: running.run,
|
|
56
56
|
...(rehearse === undefined ? {} : { rehearse: rehearsing.run }),
|
|
57
57
|
busy: running.busy || rehearsing.busy,
|
package/dist/web/record/ask.d.ts
CHANGED
|
@@ -3,23 +3,28 @@ import { type AnyRecord, type Meta } from "@sincpro/criteria";
|
|
|
3
3
|
import { type FieldControl } from "./control.js";
|
|
4
4
|
import type { ReactNode } from "react";
|
|
5
5
|
/**
|
|
6
|
-
* A field an action asks for before it runs: a field of the entity by its name — `"areas"` —,
|
|
7
|
-
*
|
|
6
|
+
* A field an action asks for before it runs: a field of the entity by its name — `"areas"` —,
|
|
7
|
+
* or an object that says more about it — its starting value, a hint, its own control —, or
|
|
8
|
+
* describes one the entity does not have.
|
|
8
9
|
*
|
|
9
10
|
* <CommandButton entity={cuentas} command="delegar_areas" id={cuenta.id} record={cuenta}
|
|
10
|
-
* label="Delegar áreas" ask={["areas"]} />
|
|
11
|
+
* label="Delegar áreas…" ask={["areas"]} />
|
|
11
12
|
* ask={[{ name: "motivo", label: "Motivo", widget: "textarea" }]}
|
|
13
|
+
* ask={[{ name: "role", label: "Rol", choices: ROLES, initial: "member", hint: "Lo que podrá hacer" }]}
|
|
12
14
|
*
|
|
13
15
|
* Context: a Command that needs input could not live among a record's actions, so a screen drew
|
|
14
16
|
* its fields in the record's body with a button of their own. What the dialog shows is the
|
|
15
|
-
* screen's: the backend adds nothing for it. A field
|
|
16
|
-
*
|
|
17
|
+
* screen's: the backend adds nothing for it. A field is read as the entity's field of that name
|
|
18
|
+
* when it has one — its label, its choices in their words, its control, its help — and what the
|
|
19
|
+
* object says goes OVER that, key by key: `{ name: "areas", hint }` is the entity's field with a
|
|
20
|
+
* hint, `{ name: "motivo", label, widget }` a field the entity lacks. A control of the
|
|
17
21
|
* application's goes in with `as`, never a widget named in a string (`widget` takes only the
|
|
18
22
|
* framework's own).
|
|
19
23
|
*/
|
|
20
24
|
export type AskField = string | {
|
|
21
25
|
name: string;
|
|
22
|
-
label
|
|
26
|
+
/** Its word on screen — the entity's label for a field of that name when not given. */
|
|
27
|
+
label?: string;
|
|
23
28
|
/** The type of its value as the model writes it — `text` (the default), `number`, `date`,
|
|
24
29
|
* `boolean`, `text[]`. */
|
|
25
30
|
type?: string;
|
|
@@ -32,11 +37,18 @@ export type AskField = string | {
|
|
|
32
37
|
widget?: "textarea";
|
|
33
38
|
/** The application's own control. */
|
|
34
39
|
as?: (control: FieldControl) => ReactNode;
|
|
40
|
+
/** What it starts with when the record holds nothing under its name: a role that starts at
|
|
41
|
+
* «Miembro». What the record holds still wins — the action starts from the record. */
|
|
42
|
+
initial?: unknown;
|
|
43
|
+
/** What is expected, said by the field — over the backend's own help for it. */
|
|
44
|
+
hint?: string;
|
|
35
45
|
};
|
|
36
46
|
/** A field ready to draw: its name, its label, its control. */
|
|
37
47
|
export type AskedField = {
|
|
38
48
|
name: string;
|
|
39
49
|
label: string;
|
|
50
|
+
/** What is expected — the action's hint, or the model's help for the field. */
|
|
51
|
+
hint?: string | undefined;
|
|
40
52
|
/** It draws its own label — a yes/no, a list of checks —: not wrapped in a `Field`. */
|
|
41
53
|
labelled: boolean;
|
|
42
54
|
draw: (control: FieldControl) => ReactNode;
|
|
@@ -47,8 +59,9 @@ export type AskForm = {
|
|
|
47
59
|
initial: Readonly<Record<string, unknown>>;
|
|
48
60
|
};
|
|
49
61
|
/**
|
|
50
|
-
* The asked fields, drawn from the entity's model
|
|
51
|
-
*
|
|
62
|
+
* The asked fields, drawn from the entity's model with what each says over it, and what they
|
|
63
|
+
* start with: the record's own values, else the field's `initial`. Its key is never asked by
|
|
64
|
+
* name — the action already knows whose record it is.
|
|
52
65
|
*/
|
|
53
66
|
export declare function askFormOf(fields: readonly AskField[], options: {
|
|
54
67
|
meta: Meta | null | undefined;
|
package/dist/web/record/ask.js
CHANGED
|
@@ -9,8 +9,9 @@ function labels(type, choices) {
|
|
|
9
9
|
return type === "boolean" || (type.endsWith("[]") && choices.length > 0);
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
|
-
* The asked fields, drawn from the entity's model
|
|
13
|
-
*
|
|
12
|
+
* The asked fields, drawn from the entity's model with what each says over it, and what they
|
|
13
|
+
* start with: the record's own values, else the field's `initial`. Its key is never asked by
|
|
14
|
+
* name — the action already knows whose record it is.
|
|
14
15
|
*/
|
|
15
16
|
export function askFormOf(fields, options) {
|
|
16
17
|
const { meta, locale, record } = options;
|
|
@@ -18,42 +19,45 @@ export function askFormOf(fields, options) {
|
|
|
18
19
|
const asked = [];
|
|
19
20
|
const initial = {};
|
|
20
21
|
for (const one of fields) {
|
|
21
|
-
if (typeof one
|
|
22
|
-
const choices = [...(one.choices ?? [])];
|
|
23
|
-
const type = one.type ?? "text";
|
|
24
|
-
asked.push({
|
|
25
|
-
name: one.name,
|
|
26
|
-
label: one.label,
|
|
27
|
-
labelled: one.as === undefined && labels(type, choices),
|
|
28
|
-
draw: (control) => one.as?.(control) ?? controlFor(control, type, false, choices, one.widget),
|
|
29
|
-
});
|
|
30
|
-
if (record !== undefined && record[one.name] !== undefined)
|
|
31
|
-
initial[one.name] = record[one.name];
|
|
22
|
+
if (typeof one === "string" && (one === key || one === "id"))
|
|
32
23
|
continue;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const view = viewOf(meta,
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
24
|
+
const said = typeof one === "string" ? { name: one } : one;
|
|
25
|
+
const field = fieldMetaOf(meta, said.name);
|
|
26
|
+
// A field of the entity is read from the model; one it lacks only as the action says.
|
|
27
|
+
const view = field === undefined ? undefined : viewOf(meta, said.name, locale);
|
|
28
|
+
const relation = field === undefined ? undefined : relationFieldOf(meta, said.name);
|
|
29
|
+
// A many2one is chosen by its key, with the picker of the entity it points at — unless the
|
|
30
|
+
// action says how it is written: then it writes the name it gave.
|
|
31
|
+
const target = relation === undefined ||
|
|
32
|
+
relation.many ||
|
|
33
|
+
said.as !== undefined ||
|
|
34
|
+
said.type !== undefined ||
|
|
35
|
+
said.choices !== undefined
|
|
40
36
|
? undefined
|
|
41
37
|
: options.entityFor?.(relation.target);
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
const choices = choicesOf(meta,
|
|
38
|
+
const name = target === undefined || relation === undefined ? said.name : relation.key;
|
|
39
|
+
const type = said.type ?? view?.type ?? "text";
|
|
40
|
+
const choices = said.choices ?? (field === undefined ? [] : choicesOf(meta, said.name, locale));
|
|
41
|
+
const widget = said.widget ?? field?.widget;
|
|
42
|
+
const label = said.label ?? view?.label ?? said.name;
|
|
43
|
+
const hint = said.hint ?? view?.help;
|
|
45
44
|
asked.push({
|
|
46
45
|
name,
|
|
47
|
-
label
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
46
|
+
label,
|
|
47
|
+
hint,
|
|
48
|
+
labelled: said.as === undefined && target === undefined && labels(type, [...choices]),
|
|
49
|
+
draw: said.as ??
|
|
50
|
+
(target === undefined
|
|
51
|
+
? (control) => controlFor(control, type, field?.exact === true, [...choices], widget)
|
|
52
|
+
: (control) => (_jsx(RelationPicker, { target: target, value: control.value === null || control.value === undefined
|
|
53
|
+
? ""
|
|
54
|
+
: String(control.value), onChange: (id) => control.set(id), label: control.label, onClear: () => control.set(null) }))),
|
|
54
55
|
});
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
// What the record holds wins; a field it leaves empty starts at what the action says.
|
|
57
|
+
const held = record?.[name];
|
|
58
|
+
const start = held === undefined || held === null ? (said.initial ?? held) : held;
|
|
59
|
+
if (start !== undefined)
|
|
60
|
+
initial[name] = start;
|
|
57
61
|
}
|
|
58
62
|
return { fields: asked, initial };
|
|
59
63
|
}
|
package/dist/web/record/edit.js
CHANGED
|
@@ -108,14 +108,14 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
|
|
|
108
108
|
// A page of them stays read only, as a one2many's: written back whole it would drop what
|
|
109
109
|
// it did not bring.
|
|
110
110
|
const whole = editableLines(edit.values[name]);
|
|
111
|
-
const lines = whole === null ? (_jsx(RecordLines, { record: record.record ?? {}, meta: meta, name: name, locale: locale })) : (_jsx(RecordLinesEditor, { record: record, name: name, lines: whole, ...(look === undefined ? {} : { look }) }));
|
|
111
|
+
const lines = whole === null ? (_jsx(RecordLines, { record: record.record ?? {}, meta: meta, name: name, entity: record.entity, locale: locale, ...(look?.columns === undefined ? {} : { columns: look.columns }), ...(look?.tones === undefined ? {} : { tones: look.tones }) })) : (_jsx(RecordLinesEditor, { record: record, name: name, lines: whole, ...(look === undefined ? {} : { look }) }));
|
|
112
112
|
return bare ? lines : _jsx(FormSection, { title: view.label, children: lines });
|
|
113
113
|
}
|
|
114
114
|
if (as === undefined && relation?.field.type === "one2many" && target === undefined) {
|
|
115
115
|
// Editable when the record holds ALL its lines; a page of them stays read only, and so do
|
|
116
116
|
// the records it only references — nothing it saves writes them.
|
|
117
117
|
const whole = editableLines(edit.values[name], relation.field);
|
|
118
|
-
const lines = whole === null ? (_jsx(RecordLines, { record: record.record ?? {}, meta: meta, name: name, locale: locale })) : (_jsx(RecordLinesEditor, { record: record, name: name, lines: whole, ...(look === undefined ? {} : { look }) }));
|
|
118
|
+
const lines = whole === null ? (_jsx(RecordLines, { record: record.record ?? {}, meta: meta, name: name, entity: record.entity, locale: locale, ...(look?.columns === undefined ? {} : { columns: look.columns }), ...(look?.tones === undefined ? {} : { tones: look.tones }) })) : (_jsx(RecordLinesEditor, { record: record, name: name, lines: whole, ...(look === undefined ? {} : { look }) }));
|
|
119
119
|
return bare ? lines : _jsx(FormSection, { title: view.label, children: lines });
|
|
120
120
|
}
|
|
121
121
|
if (as === undefined && relation?.field.type === "one2many" && target !== undefined) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type AnyRecord } from "@sincpro/criteria";
|
|
2
2
|
import { type LineAdding } from "../../core/lines.js";
|
|
3
3
|
import type { RecordReading } from "../../react/useRecord.js";
|
|
4
|
+
import type { ChoiceTones } from "../list/presentation.js";
|
|
4
5
|
import { type FieldControl } from "./control.js";
|
|
5
6
|
import { type LineEditorState } from "@sincpro/web-ui";
|
|
6
7
|
import { type ReactNode } from "react";
|
|
@@ -39,6 +40,9 @@ export type LinesLook = {
|
|
|
39
40
|
columns?: readonly string[];
|
|
40
41
|
/** A field's cell drawn the screen's way, while it reads. */
|
|
41
42
|
cells?: Readonly<Partial<Record<string, (line: AnyRecord) => ReactNode>>>;
|
|
43
|
+
/** The colour of each value of a choice, read as a tag — over what the record's entity
|
|
44
|
+
* declared for these lines (`presented(…, { parts })`). */
|
|
45
|
+
tones?: ChoiceTones<AnyRecord>;
|
|
42
46
|
/** A field written with the screen's own widget — in its cell and in the dialog. */
|
|
43
47
|
controls?: Readonly<Partial<Record<string, (control: LineControl) => ReactNode>>>;
|
|
44
48
|
/** Columns that are not fields, after the fields. */
|
package/dist/web/record/lines.js
CHANGED
|
@@ -8,7 +8,8 @@ import { entityFor, relationFieldOf, } from "../../core/relation.js";
|
|
|
8
8
|
import { useEntityFor, useFramework } from "../../react/context.js";
|
|
9
9
|
import { controlFor, RelationPicker, } from "./control.js";
|
|
10
10
|
import { RecordOpeningProvider, useRecordOpening, } from "./opening.js";
|
|
11
|
-
import {
|
|
11
|
+
import { usePartLook } from "./record.js";
|
|
12
|
+
import { Field, LineItems, ReadValue, Tag, } from "@sincpro/web-ui";
|
|
12
13
|
import { useRef } from "react";
|
|
13
14
|
/** How a field of a line reads: a many2one's key by the name of what it points at. */
|
|
14
15
|
function textIn(definition, field, relation, line, locale) {
|
|
@@ -105,7 +106,13 @@ export function RecordLinesEditor({ record, name, lines, look = {}, }) {
|
|
|
105
106
|
? (definition?.identity ?? "")
|
|
106
107
|
: definition?.identity || "id";
|
|
107
108
|
const fields = lineFields(definition);
|
|
108
|
-
|
|
109
|
+
// What the record's entity declared for these lines, under what the screen says.
|
|
110
|
+
const part = usePartLook(meta, name, {
|
|
111
|
+
entity: record.entity,
|
|
112
|
+
columns: look.columns,
|
|
113
|
+
tones: look.tones,
|
|
114
|
+
});
|
|
115
|
+
const shown = part.columns === undefined ? fields : part.columns.filter((one) => fields.includes(one));
|
|
109
116
|
const controls = look.controls ?? {};
|
|
110
117
|
const own = new Set(Object.keys(controls));
|
|
111
118
|
const declared = (target) => entityFor(entities, target, metas.get) !== undefined;
|
|
@@ -139,12 +146,20 @@ export function RecordLinesEditor({ record, name, lines, look = {}, }) {
|
|
|
139
146
|
definition.fields[field]?.readonly !== true &&
|
|
140
147
|
(own.has(field) || writtenInCell(definition, field, declared));
|
|
141
148
|
const ownCell = look.cells?.[field];
|
|
149
|
+
const tones = part.tones?.[field];
|
|
150
|
+
const toned = tones !== undefined && (definition?.fields[field]?.choices?.length ?? 0) > 0
|
|
151
|
+
? (line) => {
|
|
152
|
+
const word = textIn(definition, field, relation, line, locale);
|
|
153
|
+
return word === "" ? null : (_jsx(Tag, { tone: tones[String(line[field])] ?? "neutral", children: word }));
|
|
154
|
+
}
|
|
155
|
+
: undefined;
|
|
142
156
|
return {
|
|
143
157
|
id: field,
|
|
144
158
|
header: view.label,
|
|
145
159
|
value: (line) => line[field],
|
|
146
160
|
// Drawn as read: «Cemento 50 kg», not «CEM-50»; «1.552,00», not «1552.00».
|
|
147
|
-
|
|
161
|
+
// A choice the record's entity coloured reads as its tag, as in a list.
|
|
162
|
+
cell: ownCell ?? toned ?? ((line) => textIn(definition, field, relation, line, locale)),
|
|
148
163
|
text: (line) => textIn(definition, field, relation, line, locale),
|
|
149
164
|
numeric: view.type === "number" || view.type === "integer",
|
|
150
165
|
...(inCell
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import type { Entity } from "@sincpro/client-framework";
|
|
1
2
|
import { type AnyRecord, type Meta } from "@sincpro/criteria";
|
|
3
|
+
import { type ChoiceTones, type PartLook } from "../list/presentation.js";
|
|
2
4
|
import { type RowAction, type SheetField } from "@sincpro/web-ui";
|
|
3
5
|
import type { ReactNode } from "react";
|
|
4
6
|
export declare function factsOf<T extends AnyRecord>(record: T, meta: Meta | null | undefined, names: readonly string[], options?: {
|
|
@@ -7,6 +9,19 @@ export declare function factsOf<T extends AnyRecord>(record: T, meta: Meta | nul
|
|
|
7
9
|
}): SheetField[];
|
|
8
10
|
/** How many records a relation of this record holds — the TOTAL, not the page it brought. */
|
|
9
11
|
export declare function countOf(record: AnyRecord, name: string): number;
|
|
12
|
+
/**
|
|
13
|
+
* How the rows of `name` look, layer over layer: the related entity's own presentation (when the
|
|
14
|
+
* relation points at a declared one), the parts the record's entity declared
|
|
15
|
+
* (`presented(issues, { parts: { runs: … } })`), and what the screen passes — each over the one
|
|
16
|
+
* before, so a screen changes one colour and keeps the rest.
|
|
17
|
+
*
|
|
18
|
+
* The record's entity is the one given, or the provider's entity of the model's aggregate.
|
|
19
|
+
*/
|
|
20
|
+
export declare function usePartLook<T extends AnyRecord>(meta: Meta | null | undefined, name: string, own: {
|
|
21
|
+
entity?: Entity | undefined;
|
|
22
|
+
columns?: readonly string[] | undefined;
|
|
23
|
+
tones?: ChoiceTones<T> | undefined;
|
|
24
|
+
}): PartLook<T>;
|
|
10
25
|
/**
|
|
11
26
|
* A one2many / many2many of the record, as an embedded list.
|
|
12
27
|
*
|
|
@@ -14,6 +29,10 @@ export declare function countOf(record: AnyRecord, name: string): number;
|
|
|
14
29
|
* read off the rows otherwise. When the record brought only one page of them, it says so —
|
|
15
30
|
* «se muestran 50 de 1000» — instead of drawing 50 as if they were all.
|
|
16
31
|
*
|
|
32
|
+
* A choice of a row — a run's state, a member's role — is a tag in the colour declared ONCE
|
|
33
|
+
* with the record's entity (`presented(issues, { parts: { runs: { tones } } })`); `tones` here
|
|
34
|
+
* changes it for this screen, value by value.
|
|
35
|
+
*
|
|
17
36
|
* `rowActions` acts on a part from its row — a group's member, a project's share — with a
|
|
18
37
|
* Command of the record (`useCommand(projects, "unshareProject")`): the parts have no route of
|
|
19
38
|
* their own, so what removes one is the record's, and the screen names it.
|
|
@@ -22,12 +41,17 @@ export declare function countOf(record: AnyRecord, name: string): number;
|
|
|
22
41
|
* rowActions={(share) => [{ id: "unshare", label: "Quitar", icon: X, tone: "danger",
|
|
23
42
|
* onSelect: () => unshare.run(project.id, { tenant_id: share.tenant_id }) }]} />
|
|
24
43
|
*/
|
|
25
|
-
export declare function RecordLines<T extends AnyRecord>({ record, meta, name, columns, cells, locale, onOpen, rowActions, }: {
|
|
44
|
+
export declare function RecordLines<T extends AnyRecord>({ record, meta, name, entity, columns, cells, tones, locale, onOpen, rowActions, }: {
|
|
26
45
|
record: AnyRecord;
|
|
27
46
|
meta: Meta | null | undefined;
|
|
28
47
|
name: string;
|
|
48
|
+
/** The record's entity, whose presentation says how these rows look (`parts`). Without it,
|
|
49
|
+
* the provider's entity of the model's aggregate. */
|
|
50
|
+
entity?: Entity | undefined;
|
|
29
51
|
columns?: readonly string[];
|
|
30
52
|
cells?: Readonly<Partial<Record<string, (row: T) => ReactNode>>>;
|
|
53
|
+
/** The colour of each value of a choice of a row, over what the entities declared. */
|
|
54
|
+
tones?: ChoiceTones<T> | undefined;
|
|
31
55
|
locale?: string | undefined;
|
|
32
56
|
onOpen?: (row: T) => void;
|
|
33
57
|
/** What a row's part can be acted on with — a Command of the record. */
|
|
@@ -4,10 +4,11 @@ import { describeRows } from "@sincpro/criteria";
|
|
|
4
4
|
import { frameworkCopy } from "../../core/copy.js";
|
|
5
5
|
import { textOf, valueAt, viewOf } from "../../core/present.js";
|
|
6
6
|
import { relatedOf } from "../../core/related.js";
|
|
7
|
-
import { relationFieldOf } from "../../core/relation.js";
|
|
8
|
-
import { useEntityFor } from "../../react/context.js";
|
|
7
|
+
import { entityFor, relationFieldOf, } from "../../core/relation.js";
|
|
8
|
+
import { useEntityFor, useFrameworkIfAny } from "../../react/context.js";
|
|
9
9
|
import { useNameOf } from "../../react/useNameOf.js";
|
|
10
10
|
import { columnsOf } from "../list/columns.js";
|
|
11
|
+
import { partLookOf, presentationOf, tonesOver, } from "../list/presentation.js";
|
|
11
12
|
import { useRecordOpening } from "./opening.js";
|
|
12
13
|
import { List, RelationValue, } from "@sincpro/web-ui";
|
|
13
14
|
/**
|
|
@@ -76,6 +77,30 @@ function RelationFact({ record, meta, name, relation, locale, }) {
|
|
|
76
77
|
export function countOf(record, name) {
|
|
77
78
|
return relatedOf(record[name]).count.value;
|
|
78
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* How the rows of `name` look, layer over layer: the related entity's own presentation (when the
|
|
82
|
+
* relation points at a declared one), the parts the record's entity declared
|
|
83
|
+
* (`presented(issues, { parts: { runs: … } })`), and what the screen passes — each over the one
|
|
84
|
+
* before, so a screen changes one colour and keeps the rest.
|
|
85
|
+
*
|
|
86
|
+
* The record's entity is the one given, or the provider's entity of the model's aggregate.
|
|
87
|
+
*/
|
|
88
|
+
export function usePartLook(meta, name, own) {
|
|
89
|
+
const framework = useFrameworkIfAny();
|
|
90
|
+
const find = (target) => target === undefined || framework === null
|
|
91
|
+
? undefined
|
|
92
|
+
: entityFor(framework.entities, target, framework.metas.get);
|
|
93
|
+
const declared = partLookOf(own.entity ?? find(meta?.aggregate), name);
|
|
94
|
+
const relation = relationFieldOf(meta, name);
|
|
95
|
+
const related = relation?.many === true ? find(relation.target) : undefined;
|
|
96
|
+
const itself = related === undefined ? {} : presentationOf(related);
|
|
97
|
+
const columns = own.columns ?? declared.columns ?? itself.columns;
|
|
98
|
+
const tones = tonesOver(itself.tones, declared.tones, own.tones);
|
|
99
|
+
return {
|
|
100
|
+
...(columns === undefined ? {} : { columns: columns }),
|
|
101
|
+
...(tones === undefined ? {} : { tones }),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
79
104
|
/**
|
|
80
105
|
* A one2many / many2many of the record, as an embedded list.
|
|
81
106
|
*
|
|
@@ -83,6 +108,10 @@ export function countOf(record, name) {
|
|
|
83
108
|
* read off the rows otherwise. When the record brought only one page of them, it says so —
|
|
84
109
|
* «se muestran 50 de 1000» — instead of drawing 50 as if they were all.
|
|
85
110
|
*
|
|
111
|
+
* A choice of a row — a run's state, a member's role — is a tag in the colour declared ONCE
|
|
112
|
+
* with the record's entity (`presented(issues, { parts: { runs: { tones } } })`); `tones` here
|
|
113
|
+
* changes it for this screen, value by value.
|
|
114
|
+
*
|
|
86
115
|
* `rowActions` acts on a part from its row — a group's member, a project's share — with a
|
|
87
116
|
* Command of the record (`useCommand(projects, "unshareProject")`): the parts have no route of
|
|
88
117
|
* their own, so what removes one is the record's, and the screen names it.
|
|
@@ -91,10 +120,15 @@ export function countOf(record, name) {
|
|
|
91
120
|
* rowActions={(share) => [{ id: "unshare", label: "Quitar", icon: X, tone: "danger",
|
|
92
121
|
* onSelect: () => unshare.run(project.id, { tenant_id: share.tenant_id }) }]} />
|
|
93
122
|
*/
|
|
94
|
-
export function RecordLines({ record, meta, name, columns, cells, locale, onOpen, rowActions, }) {
|
|
123
|
+
export function RecordLines({ record, meta, name, entity, columns, cells, tones, locale, onOpen, rowActions, }) {
|
|
124
|
+
const look = usePartLook(meta, name, { entity, columns, tones });
|
|
95
125
|
const related = relatedOf(record[name]);
|
|
96
126
|
const definition = meta?.fields[name]?.definition ?? describeRows(related.items);
|
|
97
127
|
const identity = definition.identity || "id";
|
|
98
128
|
const copy = frameworkCopy();
|
|
99
|
-
return (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(List, { embedded: true, items: related.items, keyOf: (row) => String(row[identity]), present: "table", empty: { sentence: copy.list.empty }, ...(onOpen === undefined ? {} : { onOpen }), children: _jsx(List.Table, { columns: columnsOf(definition, columns, {
|
|
129
|
+
return (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(List, { embedded: true, items: related.items, keyOf: (row) => String(row[identity]), present: "table", empty: { sentence: copy.list.empty }, ...(onOpen === undefined ? {} : { onOpen }), children: _jsx(List.Table, { columns: columnsOf(definition, look.columns, {
|
|
130
|
+
locale,
|
|
131
|
+
...(cells ? { cells } : {}),
|
|
132
|
+
...(look.tones === undefined ? {} : { tones: look.tones }),
|
|
133
|
+
}), ...(rowActions === undefined ? {} : { rowActions }) }) }), related.partial ? (_jsx("p", { className: "text-meta text-muted", children: copy.record.partial(related.items.length, related.count.value, related.count.exact) })) : null] }));
|
|
100
134
|
}
|
|
@@ -50,7 +50,7 @@ export declare function useRecordScreen<T extends AnyRecord>(entity: Entity<T>,
|
|
|
50
50
|
record: {
|
|
51
51
|
error?: string | undefined;
|
|
52
52
|
dirty?: import("@sincpro/web-ui").DirtyState | undefined;
|
|
53
|
-
placement: "
|
|
53
|
+
placement: "card" | "page";
|
|
54
54
|
identity: {
|
|
55
55
|
tag?: {
|
|
56
56
|
tone?: import("@sincpro/web-ui").Tone | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sincpro/web-framework",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.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",
|