@sincpro/web-framework 3.6.0 → 3.7.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 +3 -0
- package/dist/core/crumbs.d.ts +4 -0
- package/dist/core/crumbs.js +24 -0
- package/dist/web/index.d.ts +5 -3
- package/dist/web/index.js +5 -3
- package/dist/web/list/EntityList.d.ts +23 -6
- package/dist/web/list/EntityList.js +89 -21
- package/dist/web/list/columns.d.ts +4 -1
- package/dist/web/list/columns.js +14 -6
- package/dist/web/list/dock.d.ts +19 -0
- package/dist/web/list/dock.js +20 -0
- package/dist/web/list/groups.d.ts +7 -1
- package/dist/web/list/groups.js +25 -5
- package/dist/web/record/ActionButton.d.ts +25 -0
- package/dist/web/record/ActionButton.js +39 -18
- package/dist/web/record/CommandButton.d.ts +22 -2
- package/dist/web/record/CommandButton.js +43 -17
- package/dist/web/record/RecordLifecycle.d.ts +28 -7
- package/dist/web/record/RecordLifecycle.js +63 -10
- package/dist/web/record/ServiceButton.d.ts +20 -2
- package/dist/web/record/ServiceButton.js +35 -27
- package/dist/web/record/dock.d.ts +31 -0
- package/dist/web/record/dock.js +14 -0
- package/dist/web/record/record.d.ts +14 -3
- package/dist/web/record/record.js +39 -6
- package/dist/web/workspace/record.d.ts +8 -3
- package/dist/web/workspace/record.js +20 -16
- package/package.json +3 -3
|
@@ -65,36 +65,57 @@ function AskDialog({ action, form, words, onClose, onDone, }) {
|
|
|
65
65
|
* Internal: the gesture is drawn here once; what runs behind is each button's own.
|
|
66
66
|
*/
|
|
67
67
|
export function ActionButton({ action, label, role = "secondary", disabled = false, ask: form, dialog, onDone, }) {
|
|
68
|
+
const gesture = useActionGesture(action, {
|
|
69
|
+
label,
|
|
70
|
+
...(form === undefined ? {} : { ask: form }),
|
|
71
|
+
...(dialog === undefined ? {} : { dialog }),
|
|
72
|
+
...(onDone === undefined ? {} : { onDone }),
|
|
73
|
+
});
|
|
74
|
+
// One that destroys is never the gold button: what it would do is read first.
|
|
75
|
+
const destructive = form === undefined && action.rehearse !== undefined;
|
|
76
|
+
return (_jsxs(_Fragment, { children: [_jsx(Button, { size: "sm", role: destructive ? "secondary" : role, disabled: disabled || gesture.busy, onClick: gesture.start, children: label }), gesture.dialog] }));
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* `ActionButton`'s gesture without the button: started by anything, its window put where the
|
|
80
|
+
* screen puts it.
|
|
81
|
+
*
|
|
82
|
+
* Context: web-ui's dock (`Record.Dock`, the modern style's floating pill) takes actions as
|
|
83
|
+
* data — a label and an `onSelect` —, not buttons. The gesture is the same: `start` is the
|
|
84
|
+
* button's click, and `dialog` the window it opened.
|
|
85
|
+
*/
|
|
86
|
+
export function useActionGesture(action, { label, ask: form, dialog, onDone, }) {
|
|
68
87
|
const copy = frameworkCopy().command;
|
|
69
88
|
const [open, setOpen] = useState(false);
|
|
70
89
|
const words = wordsOf(label, dialog);
|
|
90
|
+
const close = () => {
|
|
91
|
+
setOpen(false);
|
|
92
|
+
action.reset();
|
|
93
|
+
};
|
|
94
|
+
const done = (answer) => {
|
|
95
|
+
close();
|
|
96
|
+
onDone?.(answer);
|
|
97
|
+
};
|
|
71
98
|
if (form !== undefined)
|
|
72
|
-
return
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
action.reset();
|
|
78
|
-
onDone?.(answer);
|
|
79
|
-
} })) : null] }));
|
|
99
|
+
return {
|
|
100
|
+
start: () => setOpen(true),
|
|
101
|
+
busy: action.busy,
|
|
102
|
+
dialog: open ? (_jsx(AskDialog, { action: action, form: form, words: words, onClose: close, onDone: done })) : null,
|
|
103
|
+
};
|
|
80
104
|
const destructive = action.rehearse !== undefined;
|
|
81
105
|
const run = async () => {
|
|
82
106
|
const answer = await action.run();
|
|
83
|
-
if (answer !== undefined)
|
|
84
|
-
|
|
85
|
-
action.reset();
|
|
86
|
-
onDone?.(answer);
|
|
87
|
-
}
|
|
107
|
+
if (answer !== undefined)
|
|
108
|
+
done(answer);
|
|
88
109
|
else
|
|
89
110
|
setOpen(true);
|
|
90
111
|
};
|
|
91
|
-
const
|
|
112
|
+
const rehearse = async () => {
|
|
92
113
|
setOpen(true);
|
|
93
114
|
await action.rehearse?.();
|
|
94
115
|
};
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
action.
|
|
116
|
+
return {
|
|
117
|
+
start: () => void (destructive ? rehearse() : run()),
|
|
118
|
+
busy: action.busy,
|
|
119
|
+
dialog: 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,
|
|
98
120
|
};
|
|
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] }));
|
|
100
121
|
}
|
|
@@ -3,6 +3,7 @@ import type { AnyRecord } from "@sincpro/criteria";
|
|
|
3
3
|
import { type AnswerOf } from "../../react/useCommand.js";
|
|
4
4
|
import { type ActionDialog } from "./ActionButton.js";
|
|
5
5
|
import { type AskField } from "./ask.js";
|
|
6
|
+
import { type ActionLook, type DockedAction } from "./dock.js";
|
|
6
7
|
/**
|
|
7
8
|
* An entity's Command as a button: sent as it is, over the screens' transport.
|
|
8
9
|
*
|
|
@@ -15,7 +16,8 @@ import { type AskField } from "./ask.js";
|
|
|
15
16
|
* record's fields of the same name, filled from `record`, and what is filled goes in the body
|
|
16
17
|
* beside `body`.
|
|
17
18
|
*/
|
|
18
|
-
|
|
19
|
+
/** What a Command's button and dock action are given. */
|
|
20
|
+
export type CommandActionProps<T extends AnyRecord, R, C extends CommandBodies, N extends keyof C & string, A extends CommandAnswers> = {
|
|
19
21
|
entity: Entity<T, C, A>;
|
|
20
22
|
/** One the entity declares; a typed entity takes only its own names. */
|
|
21
23
|
command: N;
|
|
@@ -25,7 +27,6 @@ export declare function CommandButton<T extends AnyRecord, R = unknown, C extend
|
|
|
25
27
|
label: string;
|
|
26
28
|
/** Asks the server what it would do before doing it. */
|
|
27
29
|
destructive?: boolean;
|
|
28
|
-
role?: "primary" | "secondary" | "ghost";
|
|
29
30
|
/** Not offered right now — «Mover» with no other tenant chosen. The server still decides. */
|
|
30
31
|
disabled?: boolean;
|
|
31
32
|
/** The fields it asks for before it runs, sent in its body: `["areas"]`. */
|
|
@@ -35,4 +36,23 @@ export declare function CommandButton<T extends AnyRecord, R = unknown, C extend
|
|
|
35
36
|
/** What its window says — its title (the label without «…» by default), a sentence under it. */
|
|
36
37
|
dialog?: ActionDialog;
|
|
37
38
|
onDone?: (answer: AnswerOf<R, A, N>) => void;
|
|
39
|
+
};
|
|
40
|
+
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>({ role, ...props }: CommandActionProps<T, R, C, N, A> & {
|
|
41
|
+
role?: "primary" | "secondary" | "ghost";
|
|
38
42
|
}): import("react").JSX.Element;
|
|
43
|
+
/**
|
|
44
|
+
* An entity's Command as an action of a dock — what `CommandButton` is as a button, for web-ui's
|
|
45
|
+
* `Record.Dock`: the view style draws it, and its window is put on the screen by whoever uses
|
|
46
|
+
* it. One that destroys (`destructive`: asked first what it would do) is drawn as such — apart,
|
|
47
|
+
* in red — unless `danger` says otherwise.
|
|
48
|
+
*
|
|
49
|
+
* const anular = useCommandAction({
|
|
50
|
+
* entity: invoices, command: "cancel", id: invoice.id, label: "Anular", destructive: true,
|
|
51
|
+
* });
|
|
52
|
+
* <Record.Dock actions={[confirmar.action, anular.action]} />
|
|
53
|
+
* {anular.dialog}
|
|
54
|
+
*/
|
|
55
|
+
export declare function useCommandAction<T extends AnyRecord, R = unknown, C extends CommandBodies = CommandBodies, N extends keyof C & string = keyof C & string, A extends CommandAnswers = CommandAnswers>({ icon, primary, danger, tucked, shortcut, hint, actionId, ...props }: CommandActionProps<T, R, C, N, A> & Omit<ActionLook, "id"> & {
|
|
56
|
+
/** The dock's id for it — the record's is `id`. Defaults to the label. */
|
|
57
|
+
actionId?: string;
|
|
58
|
+
}): DockedAction;
|
|
@@ -4,21 +4,46 @@ 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";
|
|
8
|
-
import { askFormOf } from "./ask.js";
|
|
7
|
+
import { ActionButton, useActionGesture, } from "./ActionButton.js";
|
|
8
|
+
import { askFormOf, } from "./ask.js";
|
|
9
|
+
import { dockedOf, } from "./dock.js";
|
|
10
|
+
export function CommandButton({ role = "secondary", ...props }) {
|
|
11
|
+
const { action, form } = useCommandBehind(props);
|
|
12
|
+
return (_jsx(ActionButton, { ...(form === undefined ? {} : { ask: form }), ...(props.dialog === undefined ? {} : { dialog: props.dialog }), action: action, label: props.label, role: role, disabled: props.disabled ?? false, ...(props.onDone === undefined ? {} : { onDone: props.onDone }) }));
|
|
13
|
+
}
|
|
9
14
|
/**
|
|
10
|
-
* An entity's Command as a
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* one of the application's own use cases — logic of its own, composed, traced as
|
|
15
|
-
* `<context>/<Service>` — is a `ServiceButton`.
|
|
15
|
+
* An entity's Command as an action of a dock — what `CommandButton` is as a button, for web-ui's
|
|
16
|
+
* `Record.Dock`: the view style draws it, and its window is put on the screen by whoever uses
|
|
17
|
+
* it. One that destroys (`destructive`: asked first what it would do) is drawn as such — apart,
|
|
18
|
+
* in red — unless `danger` says otherwise.
|
|
16
19
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
+
* const anular = useCommandAction({
|
|
21
|
+
* entity: invoices, command: "cancel", id: invoice.id, label: "Anular", destructive: true,
|
|
22
|
+
* });
|
|
23
|
+
* <Record.Dock actions={[confirmar.action, anular.action]} />
|
|
24
|
+
* {anular.dialog}
|
|
20
25
|
*/
|
|
21
|
-
export function
|
|
26
|
+
export function useCommandAction({ icon, primary, danger, tucked, shortcut, hint, actionId, ...props }) {
|
|
27
|
+
const { action, form } = useCommandBehind(props);
|
|
28
|
+
const gesture = useActionGesture(action, {
|
|
29
|
+
label: props.label,
|
|
30
|
+
...(form === undefined ? {} : { ask: form }),
|
|
31
|
+
...(props.dialog === undefined ? {} : { dialog: props.dialog }),
|
|
32
|
+
...(props.onDone === undefined ? {} : { onDone: props.onDone }),
|
|
33
|
+
});
|
|
34
|
+
const look = {
|
|
35
|
+
icon,
|
|
36
|
+
primary,
|
|
37
|
+
danger: danger ?? props.destructive,
|
|
38
|
+
tucked,
|
|
39
|
+
shortcut,
|
|
40
|
+
hint,
|
|
41
|
+
id: actionId,
|
|
42
|
+
};
|
|
43
|
+
return dockedOf(gesture, props.label, look, props.disabled);
|
|
44
|
+
}
|
|
45
|
+
/** What runs behind a Command's button or dock action: sending it, its dry run, what it asks. */
|
|
46
|
+
function useCommandBehind({ entity, command, id, body, destructive = false, ask, record, }) {
|
|
22
47
|
const sending = useCommand(entity, command);
|
|
23
48
|
const { metas, entities, locale } = useFramework();
|
|
24
49
|
const form = ask === undefined
|
|
@@ -30,14 +55,15 @@ export function CommandButton({ entity, command, id, body, label, destructive =
|
|
|
30
55
|
entityFor: (target) => entityFor(entities, target, metas.get),
|
|
31
56
|
});
|
|
32
57
|
const bodyWith = (asked) => (asked === undefined ? body : { ...body, ...asked });
|
|
33
|
-
return
|
|
58
|
+
return {
|
|
59
|
+
action: {
|
|
34
60
|
run: (asked) => sending.run(id, bodyWith(asked)),
|
|
35
|
-
...(destructive
|
|
36
|
-
? { rehearse: (asked) => sending.rehearse(id, bodyWith(asked)) }
|
|
37
|
-
: {}),
|
|
61
|
+
...(destructive ? { rehearse: (asked) => sending.rehearse(id, bodyWith(asked)) } : {}),
|
|
38
62
|
busy: sending.busy,
|
|
39
63
|
error: sending.error,
|
|
40
64
|
rehearsal: sending.rehearsal,
|
|
41
65
|
reset: sending.reset,
|
|
42
|
-
},
|
|
66
|
+
},
|
|
67
|
+
form,
|
|
68
|
+
};
|
|
43
69
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { AnyRecord } from "@sincpro/criteria";
|
|
2
2
|
import type { RecordReading } from "../../react/useRecord.js";
|
|
3
|
+
import { type DockAction } from "@sincpro/web-ui";
|
|
4
|
+
import type { ReactNode } from "react";
|
|
5
|
+
/** What the record's lifecycle did: after `delete` and `archive` it is out of every reading. */
|
|
6
|
+
export type LifecycleDone = "delete" | "archive" | "restore";
|
|
3
7
|
/**
|
|
4
8
|
* The record's own lifecycle as buttons — «Mover a la papelera» / «Restaurar» and «Eliminar»,
|
|
5
9
|
* each when its entity declares sincpro_framework's `Archive`, `Restore`, `Delete` — a deletion
|
|
@@ -11,13 +15,30 @@ import type { RecordReading } from "../../react/useRecord.js";
|
|
|
11
15
|
* <RecordLifecycle record={member} onDone={() => api.close()} />
|
|
12
16
|
* </Record.Actions>
|
|
13
17
|
*
|
|
14
|
-
* Context: `EntityRecord` draws it; a screen of its own draws it the same, or
|
|
15
|
-
* `
|
|
16
|
-
*
|
|
17
|
-
* again by itself (the write is announced).
|
|
18
|
+
* Context: `EntityRecord` draws it; a screen of its own draws it the same, or takes them as a
|
|
19
|
+
* dock's actions (`useRecordLifecycleActions`), or drops to `useRecordLifecycle` and draws its
|
|
20
|
+
* own. What happens after is the screen's (`onDone`): in a workspace the surface closes — the
|
|
21
|
+
* record is gone —, and every list that showed it reads again by itself (the write is announced).
|
|
18
22
|
*/
|
|
19
23
|
export declare function RecordLifecycle<T extends AnyRecord>({ record, onDone, }: {
|
|
20
24
|
record: RecordReading<T>;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
onDone?: (done: LifecycleDone) => void;
|
|
26
|
+
}): import("react").JSX.Element;
|
|
27
|
+
/** The lifecycle's actions as the rail's buttons — beside actions a screen drew by hand. */
|
|
28
|
+
export declare function LifecycleButtons({ actions }: {
|
|
29
|
+
actions: readonly DockAction[];
|
|
30
|
+
}): import("react").JSX.Element;
|
|
31
|
+
/**
|
|
32
|
+
* The record's own lifecycle as actions of a dock (web-ui's `Record.Dock`) — what
|
|
33
|
+
* `RecordLifecycle` draws as buttons: the view style draws them (the rail's buttons, or the
|
|
34
|
+
* modern style's floating pill, «Eliminar» apart and in red), and their window — what a deletion
|
|
35
|
+
* would do, a refusal — is put on the screen by whoever uses them.
|
|
36
|
+
*
|
|
37
|
+
* const lifecycle = useRecordLifecycleActions(member, () => api.close());
|
|
38
|
+
* <Record.Dock actions={[...own, ...lifecycle.actions]} />
|
|
39
|
+
* {lifecycle.dialog}
|
|
40
|
+
*/
|
|
41
|
+
export declare function useRecordLifecycleActions<T extends AnyRecord>(record: RecordReading<T>, onDone?: (done: LifecycleDone) => void): {
|
|
42
|
+
actions: readonly DockAction[];
|
|
43
|
+
dialog: ReactNode;
|
|
44
|
+
};
|
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { frameworkCopy } from "../../core/copy.js";
|
|
4
4
|
import { useRecordLifecycle } from "../../react/useRecordLifecycle.js";
|
|
5
|
-
import {
|
|
5
|
+
import { useActionGesture, } from "./ActionButton.js";
|
|
6
|
+
import { dockedOf } from "./dock.js";
|
|
7
|
+
import { Button } from "@sincpro/web-ui";
|
|
8
|
+
import { Archive, RotateCcw, Trash2 } from "lucide-react";
|
|
9
|
+
/** In place of an action the entity does not declare: never offered, never started. */
|
|
10
|
+
const NOT_DECLARED = {
|
|
11
|
+
run: async () => undefined,
|
|
12
|
+
busy: false,
|
|
13
|
+
error: null,
|
|
14
|
+
rehearsal: null,
|
|
15
|
+
reset: () => { },
|
|
16
|
+
};
|
|
6
17
|
/**
|
|
7
18
|
* The record's own lifecycle as buttons — «Mover a la papelera» / «Restaurar» and «Eliminar»,
|
|
8
19
|
* each when its entity declares sincpro_framework's `Archive`, `Restore`, `Delete` — a deletion
|
|
@@ -14,16 +25,58 @@ import { ActionButton } from "./ActionButton.js";
|
|
|
14
25
|
* <RecordLifecycle record={member} onDone={() => api.close()} />
|
|
15
26
|
* </Record.Actions>
|
|
16
27
|
*
|
|
17
|
-
* Context: `EntityRecord` draws it; a screen of its own draws it the same, or
|
|
18
|
-
* `
|
|
19
|
-
*
|
|
20
|
-
* again by itself (the write is announced).
|
|
28
|
+
* Context: `EntityRecord` draws it; a screen of its own draws it the same, or takes them as a
|
|
29
|
+
* dock's actions (`useRecordLifecycleActions`), or drops to `useRecordLifecycle` and draws its
|
|
30
|
+
* own. What happens after is the screen's (`onDone`): in a workspace the surface closes — the
|
|
31
|
+
* record is gone —, and every list that showed it reads again by itself (the write is announced).
|
|
21
32
|
*/
|
|
22
33
|
export function RecordLifecycle({ record, onDone, }) {
|
|
34
|
+
const lifecycle = useRecordLifecycleActions(record, onDone);
|
|
35
|
+
return (_jsxs(_Fragment, { children: [_jsx(LifecycleButtons, { actions: lifecycle.actions }), lifecycle.dialog] }));
|
|
36
|
+
}
|
|
37
|
+
/** The lifecycle's actions as the rail's buttons — beside actions a screen drew by hand. */
|
|
38
|
+
export function LifecycleButtons({ actions }) {
|
|
39
|
+
return (_jsx(_Fragment, { children: actions.map((one) => (_jsx(Button, { size: "sm", role: "secondary", disabled: one.disabled ?? false, onClick: () => one.onSelect?.(), children: one.label }, one.id))) }));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The record's own lifecycle as actions of a dock (web-ui's `Record.Dock`) — what
|
|
43
|
+
* `RecordLifecycle` draws as buttons: the view style draws them (the rail's buttons, or the
|
|
44
|
+
* modern style's floating pill, «Eliminar» apart and in red), and their window — what a deletion
|
|
45
|
+
* would do, a refusal — is put on the screen by whoever uses them.
|
|
46
|
+
*
|
|
47
|
+
* const lifecycle = useRecordLifecycleActions(member, () => api.close());
|
|
48
|
+
* <Record.Dock actions={[...own, ...lifecycle.actions]} />
|
|
49
|
+
* {lifecycle.dialog}
|
|
50
|
+
*/
|
|
51
|
+
export function useRecordLifecycleActions(record, onDone) {
|
|
23
52
|
const lifecycle = useRecordLifecycle(record);
|
|
24
53
|
const copy = frameworkCopy().record;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
54
|
+
// Always the three, in this order: a hook is not skipped. One not declared is not offered.
|
|
55
|
+
const archive = useActionGesture(lifecycle.archive ?? NOT_DECLARED, {
|
|
56
|
+
label: copy.archive,
|
|
57
|
+
onDone: () => onDone?.("archive"),
|
|
58
|
+
});
|
|
59
|
+
const restore = useActionGesture(lifecycle.restore ?? NOT_DECLARED, {
|
|
60
|
+
label: copy.restore,
|
|
61
|
+
onDone: () => onDone?.("restore"),
|
|
62
|
+
});
|
|
63
|
+
const remove = useActionGesture(lifecycle.delete ?? NOT_DECLARED, {
|
|
64
|
+
label: copy.delete,
|
|
65
|
+
onDone: () => onDone?.("delete"),
|
|
66
|
+
});
|
|
67
|
+
const offered = [
|
|
68
|
+
lifecycle.archive === undefined
|
|
69
|
+
? null
|
|
70
|
+
: dockedOf(archive, copy.archive, { id: "archive", icon: Archive }),
|
|
71
|
+
lifecycle.restore === undefined
|
|
72
|
+
? null
|
|
73
|
+
: dockedOf(restore, copy.restore, { id: "restore", icon: RotateCcw }),
|
|
74
|
+
lifecycle.delete === undefined
|
|
75
|
+
? null
|
|
76
|
+
: dockedOf(remove, copy.delete, { id: "delete", icon: Trash2, danger: true }),
|
|
77
|
+
].filter((one) => one !== null);
|
|
78
|
+
return {
|
|
79
|
+
actions: offered.map((one) => one.action),
|
|
80
|
+
dialog: offered.map((one) => one.dialog),
|
|
81
|
+
};
|
|
29
82
|
}
|
|
@@ -3,6 +3,7 @@ import type { AnyRecord } from "@sincpro/criteria";
|
|
|
3
3
|
import type { Rehearsal } from "../../react/useCommand.js";
|
|
4
4
|
import { type ActionDialog, type Asked } from "./ActionButton.js";
|
|
5
5
|
import { type AskField } from "./ask.js";
|
|
6
|
+
import { type ActionLook, type DockedAction } from "./dock.js";
|
|
6
7
|
/**
|
|
7
8
|
* One of the application's use cases as a button — its Feature or ApplicationService, run on its
|
|
8
9
|
* bounded context.
|
|
@@ -28,13 +29,13 @@ import { type AskField } from "./ask.js";
|
|
|
28
29
|
* <ServiceButton label="Delegar áreas" entity={cuentas} record={cuenta} ask={["areas"]}
|
|
29
30
|
* run={(asked) => cuentaBoundedContext.execute(new CommandDelegarAreas(cuenta.id, asked.areas))} />
|
|
30
31
|
*/
|
|
31
|
-
|
|
32
|
+
/** What a use case's button and dock action are given. */
|
|
33
|
+
export type ServiceActionProps<R> = {
|
|
32
34
|
label: string;
|
|
33
35
|
/** The use case, executed on its bounded context — with what was asked, when it asks. */
|
|
34
36
|
run: (asked: Asked) => Promise<R>;
|
|
35
37
|
/** The same use case run dry — what it would do, nothing touched —, asked before `run`. */
|
|
36
38
|
rehearse?: (asked: Asked) => Promise<Rehearsal>;
|
|
37
|
-
role?: "primary" | "secondary" | "ghost";
|
|
38
39
|
/** Not offered right now. The use case still decides. */
|
|
39
40
|
disabled?: boolean;
|
|
40
41
|
/** The fields it asks for before it runs: `["areas"]`. */
|
|
@@ -46,4 +47,21 @@ export declare function ServiceButton<R>({ label, run, rehearse, role, disabled,
|
|
|
46
47
|
/** What its window says — its title (the label without «…» by default), a sentence under it. */
|
|
47
48
|
dialog?: ActionDialog;
|
|
48
49
|
onDone?: (answer: R) => void;
|
|
50
|
+
};
|
|
51
|
+
export declare function ServiceButton<R>({ role, ...props }: ServiceActionProps<R> & {
|
|
52
|
+
role?: "primary" | "secondary" | "ghost";
|
|
49
53
|
}): import("react").JSX.Element;
|
|
54
|
+
/**
|
|
55
|
+
* One of the application's use cases as an action of a dock — what `ServiceButton` is as a
|
|
56
|
+
* button, for web-ui's `Record.Dock`: the view style draws it (a rail's button, or the modern
|
|
57
|
+
* style's floating pill), and its window — what it asks, what it would do, a refusal — is put
|
|
58
|
+
* on the screen by whoever uses it.
|
|
59
|
+
*
|
|
60
|
+
* const aprobar = useServiceAction({
|
|
61
|
+
* label: "Aprobar", icon: Check, primary: true,
|
|
62
|
+
* run: () => pagosBoundedContext.execute(new CommandAprobarPago(pago.id)),
|
|
63
|
+
* });
|
|
64
|
+
* <Record.Dock actions={[aprobar.action]} />
|
|
65
|
+
* {aprobar.dialog}
|
|
66
|
+
*/
|
|
67
|
+
export declare function useServiceAction<R>({ icon, primary, danger, tucked, shortcut, hint, id, ...props }: ServiceActionProps<R> & ActionLook): DockedAction;
|
|
@@ -3,38 +3,43 @@ 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";
|
|
7
|
-
import { askFormOf } from "./ask.js";
|
|
6
|
+
import { ActionButton, useActionGesture, } from "./ActionButton.js";
|
|
7
|
+
import { askFormOf, } from "./ask.js";
|
|
8
|
+
import { dockedOf, } from "./dock.js";
|
|
8
9
|
/** What the button runs when there is no dry run: nothing. */
|
|
9
10
|
const NO_REHEARSAL = async (_asked) => undefined;
|
|
10
11
|
/** What a use case that asks nothing receives. */
|
|
11
12
|
const NOTHING_ASKED = {};
|
|
13
|
+
export function ServiceButton({ role = "secondary", ...props }) {
|
|
14
|
+
const { action, form } = useServiceBehind(props);
|
|
15
|
+
return (_jsx(ActionButton, { ...(form === undefined ? {} : { ask: form }), ...(props.dialog === undefined ? {} : { dialog: props.dialog }), action: action, label: props.label, role: role, disabled: props.disabled ?? false, ...(props.onDone === undefined ? {} : { onDone: props.onDone }) }));
|
|
16
|
+
}
|
|
12
17
|
/**
|
|
13
|
-
* One of the application's use cases as a
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* label="Cancelar"
|
|
18
|
-
* run={() => projectBoundedContext.execute(new CommandCancelIssue(issue.id))}
|
|
19
|
-
* rehearse={() => projectBoundedContext.execute(new CommandCancelIssue(issue.id, true))}
|
|
20
|
-
* />
|
|
21
|
-
*
|
|
22
|
-
* Context: an action of an application is a use case — its logic, its composition, its span
|
|
23
|
-
* `<context>/<Service>`, its request carrying the run's trace to the server —, never a request a
|
|
24
|
-
* screen sends; what the screen adds is the state of running it (`useService`). The gesture is
|
|
25
|
-
* `CommandButton`'s, drawn once by `ActionButton`: run on the click, off while it runs, a refusal
|
|
26
|
-
* where it happened; and an action that destroys asks first (`rehearse`, the use case run dry)
|
|
27
|
-
* and shows what it would do. What it changed, every screen hears by itself: the use case's
|
|
28
|
-
* client announces its write (`processChanges`), so `onDone` is for what only this screen does
|
|
29
|
-
* next — a toast, closing a window —, never to read again.
|
|
18
|
+
* One of the application's use cases as an action of a dock — what `ServiceButton` is as a
|
|
19
|
+
* button, for web-ui's `Record.Dock`: the view style draws it (a rail's button, or the modern
|
|
20
|
+
* style's floating pill), and its window — what it asks, what it would do, a refusal — is put
|
|
21
|
+
* on the screen by whoever uses it.
|
|
30
22
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
23
|
+
* const aprobar = useServiceAction({
|
|
24
|
+
* label: "Aprobar", icon: Check, primary: true,
|
|
25
|
+
* run: () => pagosBoundedContext.execute(new CommandAprobarPago(pago.id)),
|
|
26
|
+
* });
|
|
27
|
+
* <Record.Dock actions={[aprobar.action]} />
|
|
28
|
+
* {aprobar.dialog}
|
|
36
29
|
*/
|
|
37
|
-
export function
|
|
30
|
+
export function useServiceAction({ icon, primary, danger, tucked, shortcut, hint, id, ...props }) {
|
|
31
|
+
const { action, form } = useServiceBehind(props);
|
|
32
|
+
const gesture = useActionGesture(action, {
|
|
33
|
+
label: props.label,
|
|
34
|
+
...(form === undefined ? {} : { ask: form }),
|
|
35
|
+
...(props.dialog === undefined ? {} : { dialog: props.dialog }),
|
|
36
|
+
...(props.onDone === undefined ? {} : { onDone: props.onDone }),
|
|
37
|
+
});
|
|
38
|
+
const look = { icon, primary, danger, tucked, shortcut, hint, id };
|
|
39
|
+
return dockedOf(gesture, props.label, look, props.disabled);
|
|
40
|
+
}
|
|
41
|
+
/** What runs behind a use case's button or dock action: the run, its dry run, what it asks. */
|
|
42
|
+
function useServiceBehind({ run, rehearse, ask, entity, record }) {
|
|
38
43
|
const running = useService((asked) => run(asked ?? NOTHING_ASKED));
|
|
39
44
|
const rehearsing = useService((asked) => (rehearse ?? NO_REHEARSAL)(asked ?? NOTHING_ASKED));
|
|
40
45
|
// Outside a provider it still runs: the asked fields are then drawn by what `ask` says.
|
|
@@ -51,7 +56,8 @@ export function ServiceButton({ label, run, rehearse, role = "secondary", disabl
|
|
|
51
56
|
entityFor: (target) => entityFor(framework.entities, target, framework.metas.get),
|
|
52
57
|
}),
|
|
53
58
|
});
|
|
54
|
-
return
|
|
59
|
+
return {
|
|
60
|
+
action: {
|
|
55
61
|
run: running.run,
|
|
56
62
|
...(rehearse === undefined ? {} : { rehearse: rehearsing.run }),
|
|
57
63
|
busy: running.busy || rehearsing.busy,
|
|
@@ -61,5 +67,7 @@ export function ServiceButton({ label, run, rehearse, role = "secondary", disabl
|
|
|
61
67
|
running.reset();
|
|
62
68
|
rehearsing.reset();
|
|
63
69
|
},
|
|
64
|
-
},
|
|
70
|
+
},
|
|
71
|
+
form,
|
|
72
|
+
};
|
|
65
73
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ActionGesture } from "./ActionButton.js";
|
|
2
|
+
import type { DockAction } from "@sincpro/web-ui";
|
|
3
|
+
import type { ReactNode } from "react";
|
|
4
|
+
/**
|
|
5
|
+
* An action for a dock — web-ui's `Record.Dock` and `List.Dock`, which the application's view
|
|
6
|
+
* style draws: the rail's buttons in `traditional`, one pill floating at the bottom in `modern`
|
|
7
|
+
* — and the window its gesture opens (what it asks, what it would do, a refusal).
|
|
8
|
+
*
|
|
9
|
+
* const aprobar = useServiceAction({ label: "Aprobar", primary: true, run: aprobarPago });
|
|
10
|
+
* <Record.Rail>
|
|
11
|
+
* <Record.Dock actions={[aprobar.action]} />
|
|
12
|
+
* </Record.Rail>
|
|
13
|
+
* {aprobar.dialog}
|
|
14
|
+
*/
|
|
15
|
+
export type DockedAction = {
|
|
16
|
+
action: DockAction;
|
|
17
|
+
/** Put it anywhere on the screen — it opens over everything —; `null` while closed. */
|
|
18
|
+
dialog: ReactNode;
|
|
19
|
+
};
|
|
20
|
+
/** How an action is drawn in a dock — everything but its words and what it does. Its `id`
|
|
21
|
+
* defaults to its label. */
|
|
22
|
+
export type ActionLook = Pick<DockAction, "icon" | "primary" | "danger" | "tucked" | "shortcut" | "hint"> & {
|
|
23
|
+
id?: string;
|
|
24
|
+
};
|
|
25
|
+
/** A look as a hook receives it: a field the screen left out is `undefined`. */
|
|
26
|
+
type LookGiven = {
|
|
27
|
+
[K in keyof ActionLook]?: ActionLook[K] | undefined;
|
|
28
|
+
};
|
|
29
|
+
/** The dock's action started by a gesture: off while it runs. */
|
|
30
|
+
export declare function dockedOf(gesture: ActionGesture, label: string, look: LookGiven, disabled?: boolean): DockedAction;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** The dock's action started by a gesture: off while it runs. */
|
|
2
|
+
export function dockedOf(gesture, label, look, disabled = false) {
|
|
3
|
+
const { id, ...drawn } = Object.fromEntries(Object.entries(look).filter(([, value]) => value !== undefined));
|
|
4
|
+
return {
|
|
5
|
+
action: {
|
|
6
|
+
...drawn,
|
|
7
|
+
id: id ?? label,
|
|
8
|
+
label,
|
|
9
|
+
disabled: disabled || gesture.busy,
|
|
10
|
+
onSelect: gesture.start,
|
|
11
|
+
},
|
|
12
|
+
dialog: gesture.dialog,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Entity } from "@sincpro/client-framework";
|
|
2
2
|
import { type AnyRecord, type Meta } from "@sincpro/criteria";
|
|
3
3
|
import { type ChoiceTones, type PartLook } from "../list/presentation.js";
|
|
4
|
-
import { type RowAction, type SheetField } from "@sincpro/web-ui";
|
|
5
|
-
import type
|
|
4
|
+
import { type DockAction, type RowAction, type SheetField } from "@sincpro/web-ui";
|
|
5
|
+
import { type ReactNode } from "react";
|
|
6
6
|
export declare function factsOf<T extends AnyRecord>(record: T, meta: Meta | null | undefined, names: readonly string[], options?: {
|
|
7
7
|
locale?: string | undefined;
|
|
8
8
|
cells?: Readonly<Partial<Record<string, (record: T) => ReactNode>>>;
|
|
@@ -40,8 +40,16 @@ export declare function usePartLook<T extends AnyRecord>(meta: Meta | null | und
|
|
|
40
40
|
* <RecordLines record={project} meta={meta} name="shares"
|
|
41
41
|
* rowActions={(share) => [{ id: "unshare", label: "Quitar", icon: X, tone: "danger",
|
|
42
42
|
* onSelect: () => unshare.run(project.id, { tenant_id: share.tenant_id }) }]} />
|
|
43
|
+
*
|
|
44
|
+
* `selectionActions` acts on SEVERAL: the parts get ticks, and what is done to the chosen ones
|
|
45
|
+
* is web-ui's dock — in the collection's line in the traditional style, floating in the modern
|
|
46
|
+
* one, where it takes the record's place while parts are chosen. It is handed the chosen parts
|
|
47
|
+
* and a way to clear the choice once done.
|
|
48
|
+
*
|
|
49
|
+
* selectionActions={(chosen, clear) => [{ id: "unshare", label: `Quitar ${chosen.length}`,
|
|
50
|
+
* icon: X, onSelect: () => { void unshareAll(chosen); clear(); } }]}
|
|
43
51
|
*/
|
|
44
|
-
export declare function RecordLines<T extends AnyRecord>({ record, meta, name, entity, columns, cells, tones, locale, onOpen, rowActions, }: {
|
|
52
|
+
export declare function RecordLines<T extends AnyRecord>({ record, meta, name, entity, columns, cells, tones, locale, onOpen, rowActions, selectionActions, }: {
|
|
45
53
|
record: AnyRecord;
|
|
46
54
|
meta: Meta | null | undefined;
|
|
47
55
|
name: string;
|
|
@@ -56,4 +64,7 @@ export declare function RecordLines<T extends AnyRecord>({ record, meta, name, e
|
|
|
56
64
|
onOpen?: (row: T) => void;
|
|
57
65
|
/** What a row's part can be acted on with — a Command of the record. */
|
|
58
66
|
rowActions?: (row: T) => readonly RowAction[];
|
|
67
|
+
/** What is done to several parts at once; giving it makes the parts choosable. Handed the
|
|
68
|
+
* chosen parts, and `clear` to drop the choice once done. */
|
|
69
|
+
selectionActions?: (chosen: readonly T[], clear: () => void) => readonly DockAction[];
|
|
59
70
|
}): import("react").JSX.Element;
|
|
@@ -11,6 +11,7 @@ import { columnsOf } from "../list/columns.js";
|
|
|
11
11
|
import { partLookOf, presentationOf, tonesOver, } from "../list/presentation.js";
|
|
12
12
|
import { useRecordOpening } from "./opening.js";
|
|
13
13
|
import { List, RelationValue, } from "@sincpro/web-ui";
|
|
14
|
+
import { useState } from "react";
|
|
14
15
|
/**
|
|
15
16
|
* The parts of ONE record, from the model.
|
|
16
17
|
*
|
|
@@ -119,16 +120,48 @@ export function usePartLook(meta, name, own) {
|
|
|
119
120
|
* <RecordLines record={project} meta={meta} name="shares"
|
|
120
121
|
* rowActions={(share) => [{ id: "unshare", label: "Quitar", icon: X, tone: "danger",
|
|
121
122
|
* onSelect: () => unshare.run(project.id, { tenant_id: share.tenant_id }) }]} />
|
|
123
|
+
*
|
|
124
|
+
* `selectionActions` acts on SEVERAL: the parts get ticks, and what is done to the chosen ones
|
|
125
|
+
* is web-ui's dock — in the collection's line in the traditional style, floating in the modern
|
|
126
|
+
* one, where it takes the record's place while parts are chosen. It is handed the chosen parts
|
|
127
|
+
* and a way to clear the choice once done.
|
|
128
|
+
*
|
|
129
|
+
* selectionActions={(chosen, clear) => [{ id: "unshare", label: `Quitar ${chosen.length}`,
|
|
130
|
+
* icon: X, onSelect: () => { void unshareAll(chosen); clear(); } }]}
|
|
122
131
|
*/
|
|
123
|
-
export function RecordLines({ record, meta, name, entity, columns, cells, tones, locale, onOpen, rowActions, }) {
|
|
132
|
+
export function RecordLines({ record, meta, name, entity, columns, cells, tones, locale, onOpen, rowActions, selectionActions, }) {
|
|
124
133
|
const look = usePartLook(meta, name, { entity, columns, tones });
|
|
125
134
|
const related = relatedOf(record[name]);
|
|
126
135
|
const definition = meta?.fields[name]?.definition ?? describeRows(related.items);
|
|
127
136
|
const identity = definition.identity || "id";
|
|
128
137
|
const copy = frameworkCopy();
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
138
|
+
const keyOf = (row) => String(row[identity]);
|
|
139
|
+
// The choice is the screen's moment, not the record's: held here, by key, and dropped of the
|
|
140
|
+
// keys no longer among the parts (a part the Command removed is not chosen any more).
|
|
141
|
+
const [picked, setPicked] = useState(() => new Set());
|
|
142
|
+
const present = new Set(related.items.map(keyOf));
|
|
143
|
+
const chosenKeys = [...picked].filter((key) => present.has(key));
|
|
144
|
+
const clear = () => setPicked(new Set());
|
|
145
|
+
const chosen = related.items.filter((row) => picked.has(keyOf(row)));
|
|
146
|
+
return (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsxs(List, { embedded: true, items: related.items, keyOf: keyOf, present: "table", empty: { sentence: copy.list.empty }, ...(onOpen === undefined ? {} : { onOpen }), ...(selectionActions === undefined
|
|
147
|
+
? {}
|
|
148
|
+
: {
|
|
149
|
+
selection: {
|
|
150
|
+
has: (key) => picked.has(key),
|
|
151
|
+
toggle: (key) => setPicked((now) => {
|
|
152
|
+
const next = new Set(now);
|
|
153
|
+
if (next.has(key))
|
|
154
|
+
next.delete(key);
|
|
155
|
+
else
|
|
156
|
+
next.add(key);
|
|
157
|
+
return next;
|
|
158
|
+
}),
|
|
159
|
+
count: chosenKeys.length,
|
|
160
|
+
clear,
|
|
161
|
+
},
|
|
162
|
+
}), children: [selectionActions === undefined || chosen.length === 0 ? null : (_jsx(List.Bar, { children: _jsx(List.Dock, { selection: selectionActions(chosen, clear) }) })), _jsx(List.Table, { columns: columnsOf(definition, look.columns, {
|
|
163
|
+
locale,
|
|
164
|
+
...(cells ? { cells } : {}),
|
|
165
|
+
...(look.tones === undefined ? {} : { tones: look.tones }),
|
|
166
|
+
}), ...(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] }));
|
|
134
167
|
}
|