@sincpro/web-framework 2.6.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -31
- package/dist/core/copy.d.ts +8 -0
- package/dist/core/copy.js +8 -0
- package/dist/core/history.d.ts +7 -0
- package/dist/core/history.js +5 -0
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/list.d.ts +14 -16
- package/dist/core/list.js +18 -25
- package/dist/react/index.d.ts +2 -1
- package/dist/react/index.js +2 -1
- package/dist/react/useCommand.d.ts +7 -1
- package/dist/react/useCommand.js +12 -2
- package/dist/react/useRecord.d.ts +2 -2
- package/dist/react/useRecordLifecycle.d.ts +43 -0
- package/dist/react/useRecordLifecycle.js +49 -0
- package/dist/web/index.d.ts +1 -0
- package/dist/web/index.js +1 -0
- package/dist/web/list/EntityList.js +17 -3
- package/dist/web/list/rowCommands.d.ts +2 -0
- package/dist/web/list/rowCommands.js +6 -1
- package/dist/web/record/RecordLifecycle.d.ts +23 -0
- package/dist/web/record/RecordLifecycle.js +29 -0
- package/dist/web/record/opening.d.ts +2 -2
- package/dist/web/workspace/composer.d.ts +1 -1
- package/dist/web/workspace/composer.js +3 -4
- package/dist/web/workspace/record.js +10 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -442,37 +442,39 @@ const tickets = defineMeta({
|
|
|
442
442
|
Each answers one question, and each comes in the three levels — use the component, drop to the
|
|
443
443
|
hook and draw your own, or go straight to the loose piece.
|
|
444
444
|
|
|
445
|
-
| Question | Declarative
|
|
446
|
-
| -------------------------------- |
|
|
447
|
-
| Where is the data? | `entity()` (client-framework)
|
|
448
|
-
| The application's logic | its `Feature`s and `ApplicationService`s (client-framework)
|
|
449
|
-
| Read through a use case | its `Feature`s (client-framework)
|
|
450
|
-
| What every use case runs with | `processContext`, `project.context` (client-framework)
|
|
451
|
-
| What happened, what broke | `./telemetry`, `./errors` (optional)
|
|
452
|
-
| What is each field? | `Meta` from the server, or `defineMeta`
|
|
453
|
-
| A value outside a model | —
|
|
454
|
-
| What is a record, at any size? | `cardOf`, `relationOf`
|
|
455
|
-
| How does a record look? | `presented(entity, { option, row, card })`
|
|
456
|
-
| N records: search, filter, page | `EntityList`, `EntitySearchBar`
|
|
457
|
-
| A named slice (to collect, …) | `defineList` + `listView`
|
|
458
|
-
| A record's whole screen | `EntityRecord`, `entityView` without `record`
|
|
459
|
-
| Previous / next from a record | `EntityRecord` (from a list)
|
|
460
|
-
| How much each group adds up | `EntityList sums`
|
|
461
|
-
| One record: read, edit, save | `RecordField`, `factsOf`, `RecordLines`
|
|
462
|
-
| Its lines: add, edit, remove | `RecordField name="lines"` (`LineItems`)
|
|
463
|
-
| Its relations, inside it | `RelatedList`
|
|
464
|
-
| What other records hold of it | web-ui's `SmartButton` opening `
|
|
465
|
-
| Choose one (literal search) | `EntityPicker`, `chooserIn`
|
|
466
|
-
| Choose several (many2many) | `EntityTags`
|
|
467
|
-
| A relation, from the model alone | `RecordField name="customer_id"`
|
|
468
|
-
| Open it where it belongs | `RelatedRecord`, `entityView`, `EntityList openTargets`
|
|
469
|
-
| Look at the set several ways | `EntityList views` (table, rows, board, sheet)
|
|
470
|
-
| Cross it by two fields | `EntityList pivot`
|
|
471
|
-
| Order by several fields | the bar's criteria builder
|
|
472
|
-
| Act on it (with a dry run) | `ServiceButton` (a use case), `CommandButton`, row commands
|
|
473
|
-
|
|
|
474
|
-
|
|
|
475
|
-
|
|
|
445
|
+
| Question | Declarative | Hook | Loose piece |
|
|
446
|
+
| -------------------------------- | --------------------------------------------------------------- | ------------------------------------- | ----------------------------------------------------------- |
|
|
447
|
+
| Where is the data? | `entity()` (client-framework) | — | `restTransport`, `memoryTransport` |
|
|
448
|
+
| The application's logic | its `Feature`s and `ApplicationService`s (client-framework) | `useService` | `project.Issues.close(…)` |
|
|
449
|
+
| Read through a use case | its `Feature`s (client-framework) | `useServiceReading` | `project.Accounts.balance(…)` |
|
|
450
|
+
| What every use case runs with | `processContext`, `project.context` (client-framework) | `useContextValues` | `ContextStore` |
|
|
451
|
+
| What happened, what broke | `./telemetry`, `./errors` (optional) | — | `configureProcess({ tracer, reporter })` |
|
|
452
|
+
| What is each field? | `Meta` from the server, or `defineMeta` | — | `textOf`, `viewOf`, `metaFromSchema` |
|
|
453
|
+
| A value outside a model | — | `useTextOf` | `moneyTextOf`, `dayTextOf`, `instantTextOf`, `numberTextOf` |
|
|
454
|
+
| What is a record, at any size? | `cardOf`, `relationOf` | `useSummaryOf` | `summaryOf` |
|
|
455
|
+
| How does a record look? | `presented(entity, { option, row, card })` | — | `presentationOf` |
|
|
456
|
+
| N records: search, filter, page | `EntityList`, `EntitySearchBar` | `useListing`, `useGroups` | `transport.list(route, criteria)` |
|
|
457
|
+
| A named slice (to collect, …) | `defineList` + `listView` | `useListing(list)` | `scopeOf` |
|
|
458
|
+
| A record's whole screen | `EntityRecord`, `entityView` without `record` | `useRecordScreen` | `formOf` |
|
|
459
|
+
| Previous / next from a record | `EntityRecord` (from a list) | — | `placeOf`, `stepIn` (`Trail`) |
|
|
460
|
+
| How much each group adds up | `EntityList sums` | `useGroups` (`sums`) | `sumsOf`, `detailOf` |
|
|
461
|
+
| One record: read, edit, save | `RecordField`, `factsOf`, `RecordLines` | `useRecord` | `transport.one`, `transport.send` |
|
|
462
|
+
| Its lines: add, edit, remove | `RecordField name="lines"` (`LineItems`) | `useRecord` (`edit.cell`, `errorAt`) | `lineKey`, `editableLines`, `pathOf` |
|
|
463
|
+
| Its relations, inside it | `RelatedList` | `useRelated` | `relatedOf` |
|
|
464
|
+
| What other records hold of it | web-ui's `SmartButton` opening `entity.listRef(cut, name)` | `useCount` | `entity.listRef` (client-framework) |
|
|
465
|
+
| Choose one (literal search) | `EntityPicker`, `chooserIn` | `useLookup` | `lookupOf` + criteria's `matching` |
|
|
466
|
+
| Choose several (many2many) | `EntityTags` | `useLookup` (`values`) | `lookupOf` |
|
|
467
|
+
| A relation, from the model alone | `RecordField name="customer_id"` | `useEntityFor` | `relationFieldOf`, `entityFor` |
|
|
468
|
+
| Open it where it belongs | `RelatedRecord`, `entityView`, `EntityList openTargets` | — | `openIn`, `targetsFor`, `OpenInMenu` |
|
|
469
|
+
| Look at the set several ways | `EntityList views` (table, rows, board, sheet) | — | web-ui's `List.*` |
|
|
470
|
+
| Cross it by two fields | `EntityList pivot` | `usePivot` | `pivotOf` |
|
|
471
|
+
| Order by several fields | the bar's criteria builder | `listing.orderBy([...])` | criteria's `order` |
|
|
472
|
+
| Act on it (with a dry run) | `ServiceButton` (a use case), `CommandButton`, row commands | `useService`, `useCommand` | `transport.send` |
|
|
473
|
+
| Delete it | `EntityRecord` (`RecordLifecycle`) | `useRecordLifecycle` | `entity.delete`, `useRouteCommand` |
|
|
474
|
+
| Its trash | `EntityRecord` (`RecordLifecycle`), `listView(trashOf(entity))` | `useRecordLifecycle` | `entity.archive`, `entity.restore`, `trashOf` |
|
|
475
|
+
| Read again when it was written | every reading of this package, by itself | `useWrites` | `processChanges` (client-framework) |
|
|
476
|
+
| What happened to it | `Record.Activity` fed by `useHistory` | `useHistory` | `historyOf` |
|
|
477
|
+
| The application context | `SincproApp` | `useRecordInWorkspace`, `useFollowed` | `FrameworkProvider`, `webUiSkin` |
|
|
476
478
|
|
|
477
479
|
The rules behind them, in short:
|
|
478
480
|
|
package/dist/core/copy.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ export type FrameworkCopy = {
|
|
|
15
15
|
items: (count: number, exact: boolean) => string;
|
|
16
16
|
};
|
|
17
17
|
list: {
|
|
18
|
+
/** The entity's trash: its archived records (`trashOf`). */
|
|
19
|
+
trash: string;
|
|
18
20
|
loadMore: string;
|
|
19
21
|
loading: string;
|
|
20
22
|
/** «12 of 120»: what is on screen against what matches. */
|
|
@@ -57,6 +59,12 @@ export type FrameworkCopy = {
|
|
|
57
59
|
create: string;
|
|
58
60
|
/** A record's one2many: the button that opens the form of a new related record. */
|
|
59
61
|
add: string;
|
|
62
|
+
/** The record's own `Delete` (its dry run is shown before it runs). */
|
|
63
|
+
delete: string;
|
|
64
|
+
/** Into the entity's trash (`Archive`): out of every reading, nothing lost. */
|
|
65
|
+
archive: string;
|
|
66
|
+
/** Out of the trash (`Restore`): read again. */
|
|
67
|
+
restore: string;
|
|
60
68
|
};
|
|
61
69
|
picker: {
|
|
62
70
|
/** The button beside a many2one that opens the chooser over the whole set. */
|
package/dist/core/copy.js
CHANGED
|
@@ -5,6 +5,7 @@ export const ENGLISH_FRAMEWORK_COPY = {
|
|
|
5
5
|
items: (count, exact) => `${count}${exact ? "" : "+"} ${count === 1 ? "item" : "items"}`,
|
|
6
6
|
},
|
|
7
7
|
list: {
|
|
8
|
+
trash: "Trash",
|
|
8
9
|
loadMore: "Load more",
|
|
9
10
|
loading: "Loading…",
|
|
10
11
|
shown: (shown, total, exact) => `${shown} of ${total}${exact ? "" : "+"}`,
|
|
@@ -30,6 +31,9 @@ export const ENGLISH_FRAMEWORK_COPY = {
|
|
|
30
31
|
creating: (name) => (name ? `${name} · new` : "New"),
|
|
31
32
|
create: "New",
|
|
32
33
|
add: "Add",
|
|
34
|
+
delete: "Delete",
|
|
35
|
+
archive: "Move to the trash",
|
|
36
|
+
restore: "Restore",
|
|
33
37
|
},
|
|
34
38
|
picker: {
|
|
35
39
|
browse: "Search all",
|
|
@@ -75,6 +79,7 @@ export const SPANISH_FRAMEWORK_COPY = {
|
|
|
75
79
|
items: (count, exact) => `${count}${exact ? "" : "+"} ${count === 1 ? "elemento" : "elementos"}`,
|
|
76
80
|
},
|
|
77
81
|
list: {
|
|
82
|
+
trash: "Papelera",
|
|
78
83
|
loadMore: "Cargar más",
|
|
79
84
|
loading: "Cargando…",
|
|
80
85
|
shown: (shown, total, exact) => `${shown} de ${total}${exact ? "" : "+"}`,
|
|
@@ -100,6 +105,9 @@ export const SPANISH_FRAMEWORK_COPY = {
|
|
|
100
105
|
creating: (name) => (name ? `${name} · nuevo` : "Nuevo"),
|
|
101
106
|
create: "Nuevo",
|
|
102
107
|
add: "Agregar",
|
|
108
|
+
delete: "Eliminar",
|
|
109
|
+
archive: "Mover a la papelera",
|
|
110
|
+
restore: "Restaurar",
|
|
103
111
|
},
|
|
104
112
|
picker: {
|
|
105
113
|
browse: "Buscar en todos",
|
package/dist/core/history.d.ts
CHANGED
|
@@ -11,11 +11,18 @@ import { type AnyRecord, type Meta } from "@sincpro/criteria";
|
|
|
11
11
|
*
|
|
12
12
|
* These are business facts («Factura confirmada»), never technical logs: those belong to the
|
|
13
13
|
* observability stack, not to a record's screen.
|
|
14
|
+
*
|
|
15
|
+
* Since sincpro_framework 3.37 every fact also says which one it is (`name`, `billing.v1.deleted`),
|
|
16
|
+
* who did it (`actor`, the context's user) and who the record was then (`entity_display`), and
|
|
17
|
+
* the contract labels a subclass's own fields (`reason` → «Motivo»). Who did it is the entry's
|
|
18
|
+
* `by` — web-ui's activity draws it —; the rest of the envelope never repeats in its detail.
|
|
14
19
|
*/
|
|
15
20
|
export type HistoryEntry = {
|
|
16
21
|
id: string;
|
|
17
22
|
label: string;
|
|
18
23
|
at: string;
|
|
24
|
+
/** Who did it, as the fact says (`actor`); absent: the system, or a backend before 3.37. */
|
|
25
|
+
by?: string;
|
|
19
26
|
detail?: string;
|
|
20
27
|
};
|
|
21
28
|
export declare function historyOf(rows: readonly AnyRecord[], meta: Meta | null | undefined, locale?: string): HistoryEntry[];
|
package/dist/core/history.js
CHANGED
|
@@ -3,13 +3,16 @@ import { frameworkCopy } from "./copy.js";
|
|
|
3
3
|
/** What every fact carries: what remains is what this fact says. */
|
|
4
4
|
const ENVELOPE = new Set([
|
|
5
5
|
"id",
|
|
6
|
+
"name",
|
|
6
7
|
"created_at",
|
|
7
8
|
"updated_at",
|
|
8
9
|
"version",
|
|
9
10
|
"label",
|
|
10
11
|
"entity_type",
|
|
11
12
|
"entity_id",
|
|
13
|
+
"entity_display",
|
|
12
14
|
"entity_version",
|
|
15
|
+
"actor",
|
|
13
16
|
"correlation_id",
|
|
14
17
|
"causation_id",
|
|
15
18
|
]);
|
|
@@ -34,10 +37,12 @@ export function historyOf(rows, meta, locale) {
|
|
|
34
37
|
.map(([key, value]) => [key, said(value)])
|
|
35
38
|
.filter(([, value]) => value !== null && value !== row["entity_id"])
|
|
36
39
|
.map(([key, value]) => `${labelOf(meta, key, locale)}: ${value}`);
|
|
40
|
+
const actor = said(row["actor"]);
|
|
37
41
|
return {
|
|
38
42
|
id: String(row["id"]),
|
|
39
43
|
label: word,
|
|
40
44
|
at: String(row["created_at"] ?? ""),
|
|
45
|
+
...(actor === null ? {} : { by: actor }),
|
|
41
46
|
...(parts.length === 0 ? {} : { detail: parts.join(" · ") }),
|
|
42
47
|
};
|
|
43
48
|
});
|
package/dist/core/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export { explain } from "./explain.js";
|
|
|
14
14
|
export { type FormLayout, formOf } from "./form.js";
|
|
15
15
|
export { type HistoryEntry, historyOf } from "./history.js";
|
|
16
16
|
export { addingOf, type AddingRule, blankLine, type Declared, editableLines, isReference, type LineAdding, lineFields, lineKey, linesAnswered, moved, sameLine, writtenInCell, } from "./lines.js";
|
|
17
|
-
export { defineList, type GroupLevel, isList, type ListDefinition, type ListSpec, type NamedFilter,
|
|
17
|
+
export { defineList, type GroupLevel, isList, type ListDefinition, type ListSpec, type NamedFilter, scopeOf, trashOf, } from "./list.js";
|
|
18
18
|
export { lookupOf, type LookupOption } from "./lookup.js";
|
|
19
19
|
export { detailOf, measuresOf, sumsOf } from "./measure.js";
|
|
20
20
|
export { BOOKKEEPING, dayTextOf, defaultFields, type FieldView, instantTextOf, moneyTextOf, numberTextOf, sortKeyOf, textOf, viewOf, } from "./present.js";
|
package/dist/core/index.js
CHANGED
|
@@ -14,7 +14,7 @@ export { explain } from "./explain.js";
|
|
|
14
14
|
export { formOf } from "./form.js";
|
|
15
15
|
export { historyOf } from "./history.js";
|
|
16
16
|
export { addingOf, blankLine, editableLines, isReference, lineFields, lineKey, linesAnswered, moved, sameLine, writtenInCell, } from "./lines.js";
|
|
17
|
-
export { defineList, isList,
|
|
17
|
+
export { defineList, isList, scopeOf, trashOf, } from "./list.js";
|
|
18
18
|
export { lookupOf } from "./lookup.js";
|
|
19
19
|
export { detailOf, measuresOf, sumsOf } from "./measure.js";
|
|
20
20
|
export { BOOKKEEPING, dayTextOf, defaultFields, instantTextOf, moneyTextOf, numberTextOf, sortKeyOf, textOf, viewOf, } from "./present.js";
|
package/dist/core/list.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Entity, type
|
|
1
|
+
import { type Entity, type ResourceRef } from "@sincpro/client-framework";
|
|
2
2
|
import type { AnyRecord, Criteria, Expression, Grain, Sort } from "@sincpro/criteria";
|
|
3
3
|
/**
|
|
4
4
|
* A named way of looking at an entity: «Por cobrar», «Borradores», «Mis tickets».
|
|
@@ -29,7 +29,7 @@ export type ListDefinition<T extends AnyRecord = AnyRecord> = {
|
|
|
29
29
|
/** `domain:kind-id` — how the workspace and the definitions store refer to it. */
|
|
30
30
|
key: string;
|
|
31
31
|
/** Where the workspace opens it: a kind of its own, so ⌘K can offer it by name. */
|
|
32
|
-
ref: () =>
|
|
32
|
+
ref: () => ResourceRef;
|
|
33
33
|
title: string;
|
|
34
34
|
description?: string;
|
|
35
35
|
/** The fixed cut, ANDed under everything a person searches or filters. */
|
|
@@ -46,6 +46,8 @@ export type ListDefinition<T extends AnyRecord = AnyRecord> = {
|
|
|
46
46
|
groupBy?: readonly GroupLevel[];
|
|
47
47
|
/** The fields «Group by» offers, in this order — among those the model lets split the set. */
|
|
48
48
|
groupable?: readonly string[];
|
|
49
|
+
/** The entity's trash (`trashOf`): each row offers «Restore» when the entity declares it. */
|
|
50
|
+
trash?: boolean;
|
|
49
51
|
};
|
|
50
52
|
/** A cut offered by name in the search bar: «sólo pagadas», «vencidas». */
|
|
51
53
|
export type NamedFilter<T> = {
|
|
@@ -65,21 +67,17 @@ export declare function defineList<T extends AnyRecord>(entity: Entity<T>, spec:
|
|
|
65
67
|
export declare function isList<T extends AnyRecord>(given: Entity<T> | ListDefinition<T>): given is ListDefinition<T>;
|
|
66
68
|
/** The criteria a definition always asks: its scope, in its order. */
|
|
67
69
|
export declare function scopeOf<T extends AnyRecord>(list: ListDefinition<T>): Criteria<T>;
|
|
68
|
-
/** What a list opened under a cut is named by — «María» of «Pagos · María». */
|
|
69
|
-
export declare const SCOPE_NAME_PARAM = "of";
|
|
70
70
|
/**
|
|
71
|
-
* An entity's
|
|
72
|
-
*
|
|
73
|
-
* heading, the tab and the breadcrumb — a cut that travels without one reads as the whole list.
|
|
71
|
+
* An entity's trash, as a named list: its archived records (sincpro_framework's `Archive`,
|
|
72
|
+
* `ArchivableMixin`), each row offering «Restore» when the entity declares `restore`.
|
|
74
73
|
*
|
|
75
|
-
*
|
|
74
|
+
* listView(trashOf(banners)) // «Papelera» in the workspace and ⌘K
|
|
76
75
|
*
|
|
77
|
-
* Context:
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* by hand. It narrows what is shown; the server still decides what may be read.
|
|
76
|
+
* Context: every other reading leaves an archived record out; the backend's trash is a `Search`
|
|
77
|
+
* that names `archived_at` — the list route itself, under `archived_at` not null. So this is the
|
|
78
|
+
* entity's own list under that cut, never a route of its own, and the server still decides what
|
|
79
|
+
* comes back.
|
|
82
80
|
*/
|
|
83
|
-
export declare function
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
export declare function trashOf<T extends AnyRecord>(entity: Entity<T>, options?: {
|
|
82
|
+
title?: string;
|
|
83
|
+
}): ListDefinition<T>;
|
package/dist/core/list.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {} from "@sincpro/client-framework";
|
|
2
|
+
import { frameworkCopy } from "./copy.js";
|
|
2
3
|
export function defineList(entity, spec) {
|
|
3
4
|
if (!/^[a-z0-9][a-z0-9-]*$/.test(spec.id))
|
|
4
5
|
throw new Error(`list id "${spec.id}" is not kebab-case: it becomes a workspace kind`);
|
|
@@ -21,34 +22,26 @@ export function scopeOf(list) {
|
|
|
21
22
|
...(list.order === undefined ? {} : { order: [list.order] }),
|
|
22
23
|
};
|
|
23
24
|
}
|
|
24
|
-
/** What a list opened under a cut is named by — «María» of «Pagos · María». */
|
|
25
|
-
export const SCOPE_NAME_PARAM = "of";
|
|
26
25
|
/**
|
|
27
|
-
* An entity's
|
|
28
|
-
*
|
|
29
|
-
* heading, the tab and the breadcrumb — a cut that travels without one reads as the whole list.
|
|
26
|
+
* An entity's trash, as a named list: its archived records (sincpro_framework's `Archive`,
|
|
27
|
+
* `ArchivableMixin`), each row offering «Restore» when the entity declares `restore`.
|
|
30
28
|
*
|
|
31
|
-
*
|
|
29
|
+
* listView(trashOf(banners)) // «Papelera» in the workspace and ⌘K
|
|
32
30
|
*
|
|
33
|
-
* Context:
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* by hand. It narrows what is shown; the server still decides what may be read.
|
|
31
|
+
* Context: every other reading leaves an archived record out; the backend's trash is a `Search`
|
|
32
|
+
* that names `archived_at` — the list route itself, under `archived_at` not null. So this is the
|
|
33
|
+
* entity's own list under that cut, never a route of its own, and the server still decides what
|
|
34
|
+
* comes back.
|
|
38
35
|
*/
|
|
39
|
-
export function
|
|
40
|
-
const list = entity.ref();
|
|
36
|
+
export function trashOf(entity, options = {}) {
|
|
41
37
|
return {
|
|
42
|
-
...
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
38
|
+
...defineList(entity, {
|
|
39
|
+
id: "trash",
|
|
40
|
+
title: options.title ?? frameworkCopy().list.trash,
|
|
41
|
+
scope: {
|
|
42
|
+
selection: { field: "archived_at", operator: "is null", value: false },
|
|
43
|
+
},
|
|
44
|
+
}),
|
|
45
|
+
trash: true,
|
|
48
46
|
};
|
|
49
47
|
}
|
|
50
|
-
/** The name a reference's cut carries (`scopedRef(…, name)`), or nothing. */
|
|
51
|
-
export function scopeNameOf(ref) {
|
|
52
|
-
const name = ref.params?.[SCOPE_NAME_PARAM];
|
|
53
|
-
return name === undefined || name === "" ? undefined : name;
|
|
54
|
-
}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export { FrameworkProvider, useEntityFor, useFramework, } from "./context.js";
|
|
7
7
|
export { type ListScope, ListScopeProvider, useListScope, } from "./scope.js";
|
|
8
|
-
export { type AnswerOf, type CommandState, type Rehearsal, useCommand, } from "./useCommand.js";
|
|
8
|
+
export { type AnswerOf, type CommandState, type Rehearsal, useCommand, useRouteCommand, } from "./useCommand.js";
|
|
9
9
|
export { useContextValues } from "./useContextValues.js";
|
|
10
10
|
export { useCount } from "./useCount.js";
|
|
11
11
|
export { type Groups, useGroups } from "./useGroups.js";
|
|
@@ -15,6 +15,7 @@ export { excluding, type Lookup, useLookup } from "./useLookup.js";
|
|
|
15
15
|
export { useNameOf } from "./useNameOf.js";
|
|
16
16
|
export { type PivotAxes, type PivotReading, usePivot, } from "./usePivot.js";
|
|
17
17
|
export { type Editing, type RecordReading, type RecordState, useRecord, } from "./useRecord.js";
|
|
18
|
+
export { type LifecycleAction, type RecordLifecycleActions, useRecordLifecycle, } from "./useRecordLifecycle.js";
|
|
18
19
|
export { useRelated } from "./useRelated.js";
|
|
19
20
|
export { type ServiceState, useService } from "./useService.js";
|
|
20
21
|
export { type ServiceReading, useServiceReading, } from "./useServiceReading.js";
|
package/dist/react/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export { FrameworkProvider, useEntityFor, useFramework, } from "./context.js";
|
|
7
7
|
export { ListScopeProvider, useListScope, } from "./scope.js";
|
|
8
|
-
export { useCommand, } from "./useCommand.js";
|
|
8
|
+
export { useCommand, useRouteCommand, } from "./useCommand.js";
|
|
9
9
|
export { useContextValues } from "./useContextValues.js";
|
|
10
10
|
export { useCount } from "./useCount.js";
|
|
11
11
|
export { useGroups } from "./useGroups.js";
|
|
@@ -15,6 +15,7 @@ export { excluding, useLookup } from "./useLookup.js";
|
|
|
15
15
|
export { useNameOf } from "./useNameOf.js";
|
|
16
16
|
export { usePivot, } from "./usePivot.js";
|
|
17
17
|
export { useRecord, } from "./useRecord.js";
|
|
18
|
+
export { useRecordLifecycle, } from "./useRecordLifecycle.js";
|
|
18
19
|
export { useRelated } from "./useRelated.js";
|
|
19
20
|
export { useService } from "./useService.js";
|
|
20
21
|
export { useServiceReading, } from "./useServiceReading.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type CommandAnswers, type CommandBodies, type Entity } from "@sincpro/client-framework";
|
|
1
|
+
import { type CommandAnswers, type CommandBodies, type Entity, type WriteRoute } from "@sincpro/client-framework";
|
|
2
2
|
import type { AnyRecord } from "@sincpro/criteria";
|
|
3
3
|
/**
|
|
4
4
|
* One Command of an entity: run it, or ask first what it would do.
|
|
@@ -38,3 +38,9 @@ export type CommandState<R, B extends AnyRecord = AnyRecord> = {
|
|
|
38
38
|
*/
|
|
39
39
|
export type AnswerOf<R, A, N> = unknown extends R ? (N extends keyof A ? A[N] : unknown) : R;
|
|
40
40
|
export declare function useCommand<T extends AnyRecord, R = unknown, C extends CommandBodies = CommandBodies, N extends keyof C & string = keyof C & string, A extends CommandAnswers = CommandAnswers>(entity: Entity<T, C, A>, name: N): CommandState<AnswerOf<R, A, N>, C[N]>;
|
|
41
|
+
/**
|
|
42
|
+
* One write route of an entity run as a Command — what `useCommand` runs for a declared Command,
|
|
43
|
+
* and `useRecordLifecycle` for the record's own `delete`. `route` may be absent (an entity that
|
|
44
|
+
* declares none): the hook is still called, and running it is refused naming the entity.
|
|
45
|
+
*/
|
|
46
|
+
export declare function useRouteCommand<R, B extends AnyRecord = AnyRecord>(route: WriteRoute | undefined, owner: string): CommandState<R, B>;
|
package/dist/react/useCommand.js
CHANGED
|
@@ -3,11 +3,19 @@ import { bodyFor, pathFor, retryKeys, } from "@sincpro/client-framework";
|
|
|
3
3
|
import { useFramework } from "./context.js";
|
|
4
4
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
5
5
|
export function useCommand(entity, name) {
|
|
6
|
-
const { transport } = useFramework();
|
|
7
6
|
// A name outside the declared ones still reaches here from untyped code: say which.
|
|
8
7
|
const route = entity.commands[name];
|
|
9
8
|
if (route === undefined)
|
|
10
9
|
throw new Error(`${entity.key} declares no command "${name}"`);
|
|
10
|
+
return useRouteCommand(route, entity.key);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* One write route of an entity run as a Command — what `useCommand` runs for a declared Command,
|
|
14
|
+
* and `useRecordLifecycle` for the record's own `delete`. `route` may be absent (an entity that
|
|
15
|
+
* declares none): the hook is still called, and running it is refused naming the entity.
|
|
16
|
+
*/
|
|
17
|
+
export function useRouteCommand(route, owner) {
|
|
18
|
+
const { transport } = useFramework();
|
|
11
19
|
const [busy, setBusy] = useState(false);
|
|
12
20
|
const [error, setError] = useState(null);
|
|
13
21
|
const [rehearsal, setRehearsal] = useState(null);
|
|
@@ -22,6 +30,8 @@ export function useCommand(entity, name) {
|
|
|
22
30
|
// not run it twice. A dry run touches nothing, so each one gets a key of its own.
|
|
23
31
|
const keys = useRef(retryKeys());
|
|
24
32
|
const send = useCallback(async (id, body, gesture) => {
|
|
33
|
+
if (route === undefined)
|
|
34
|
+
throw new Error(`${owner} declares no route for this`);
|
|
25
35
|
setBusy(true);
|
|
26
36
|
setError(null);
|
|
27
37
|
const idempotencyKey = gesture.keyFor({ id, body });
|
|
@@ -42,7 +52,7 @@ export function useCommand(entity, name) {
|
|
|
42
52
|
if (mounted.current)
|
|
43
53
|
setBusy(false);
|
|
44
54
|
}
|
|
45
|
-
}, [transport, route]);
|
|
55
|
+
}, [transport, route, owner]);
|
|
46
56
|
return {
|
|
47
57
|
run: (id, body) => send(id, body ?? {}, keys.current),
|
|
48
58
|
rehearse: async (id, body) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Draft, type Entity, type
|
|
1
|
+
import { type Draft, type Entity, type ResourceRef } from "@sincpro/client-framework";
|
|
2
2
|
import type { AnyRecord, Meta } from "@sincpro/criteria";
|
|
3
3
|
import { type Advice, type FieldState } from "../core/edit.js";
|
|
4
4
|
/**
|
|
@@ -101,4 +101,4 @@ export type RecordReading<T> = RecordState<T> & {
|
|
|
101
101
|
reload: () => void;
|
|
102
102
|
edit: Editing;
|
|
103
103
|
};
|
|
104
|
-
export declare function useRecord<T extends AnyRecord>(entity: Entity<T>, opened: string |
|
|
104
|
+
export declare function useRecord<T extends AnyRecord>(entity: Entity<T>, opened: string | ResourceRef): RecordReading<T>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { AnyRecord } from "@sincpro/criteria";
|
|
2
|
+
import { type Rehearsal } from "./useCommand.js";
|
|
3
|
+
import type { RecordReading } from "./useRecord.js";
|
|
4
|
+
/** An action on the record itself — what `RecordLifecycle` draws with `ActionButton`'s gesture:
|
|
5
|
+
* one that destroys can `rehearse` first; one that can be undone runs on the click. It answers
|
|
6
|
+
* `null` when done, `undefined` when refused. */
|
|
7
|
+
export type LifecycleAction = {
|
|
8
|
+
run: () => Promise<null | undefined>;
|
|
9
|
+
rehearse?: () => Promise<Rehearsal | undefined>;
|
|
10
|
+
busy: boolean;
|
|
11
|
+
error: unknown;
|
|
12
|
+
rehearsal: Rehearsal | null;
|
|
13
|
+
reset: () => void;
|
|
14
|
+
};
|
|
15
|
+
/** What the record's entity lets be done to the record itself, each only when declared. */
|
|
16
|
+
export type RecordLifecycleActions = {
|
|
17
|
+
/** sincpro_framework's `Delete`: gone, its fact kept in the history. Rehearsed first. */
|
|
18
|
+
delete?: LifecycleAction;
|
|
19
|
+
/** `Archive`: into the trash — out of every reading, nothing lost. On a record not archived. */
|
|
20
|
+
archive?: LifecycleAction;
|
|
21
|
+
/** `Restore`: out of the trash. On an archived record (`archived_at` set). */
|
|
22
|
+
restore?: LifecycleAction;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* The record's own lifecycle, as actions of ONE stored record: what its entity declares of
|
|
26
|
+
* sincpro_framework's `Delete` (`entity.delete`) and its trash (`entity.archive`,
|
|
27
|
+
* `entity.restore`, client-framework 2.0) — `archive` on a record outside the trash, `restore` on
|
|
28
|
+
* one in it (`archived_at` set).
|
|
29
|
+
*
|
|
30
|
+
* const lifecycle = useRecordLifecycle(member);
|
|
31
|
+
* lifecycle.delete?.rehearse() // «Se eliminará Ana Pérez»: nothing touched
|
|
32
|
+
* lifecycle.delete?.run() // null: gone
|
|
33
|
+
*
|
|
34
|
+
* Context: an application wrote a Command and a Feature per aggregate to delete one, and a
|
|
35
|
+
* confirm of its own. The backend publishes the generic `Delete` (3.37): a `DryRunnable` whose
|
|
36
|
+
* dry run answers what would go, refused when the record moved past the version read
|
|
37
|
+
* (`origin_version`), answering nothing. So each action sends the version this screen read and
|
|
38
|
+
* a deletion rehearses with the same body: the confirmation is the server's word on THIS version.
|
|
39
|
+
* Putting a record in the trash, or taking it out, can be undone: it runs on the click. A new
|
|
40
|
+
* record, or one not read yet, has none. Over REST a `DELETE`'s fields travel in its query string
|
|
41
|
+
* (client-framework 1.12): sent in a body, a dry run would run the real delete.
|
|
42
|
+
*/
|
|
43
|
+
export declare function useRecordLifecycle<T extends AnyRecord>(record: RecordReading<T>): RecordLifecycleActions;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useRouteCommand, } from "./useCommand.js";
|
|
3
|
+
/**
|
|
4
|
+
* The record's own lifecycle, as actions of ONE stored record: what its entity declares of
|
|
5
|
+
* sincpro_framework's `Delete` (`entity.delete`) and its trash (`entity.archive`,
|
|
6
|
+
* `entity.restore`, client-framework 2.0) — `archive` on a record outside the trash, `restore` on
|
|
7
|
+
* one in it (`archived_at` set).
|
|
8
|
+
*
|
|
9
|
+
* const lifecycle = useRecordLifecycle(member);
|
|
10
|
+
* lifecycle.delete?.rehearse() // «Se eliminará Ana Pérez»: nothing touched
|
|
11
|
+
* lifecycle.delete?.run() // null: gone
|
|
12
|
+
*
|
|
13
|
+
* Context: an application wrote a Command and a Feature per aggregate to delete one, and a
|
|
14
|
+
* confirm of its own. The backend publishes the generic `Delete` (3.37): a `DryRunnable` whose
|
|
15
|
+
* dry run answers what would go, refused when the record moved past the version read
|
|
16
|
+
* (`origin_version`), answering nothing. So each action sends the version this screen read and
|
|
17
|
+
* a deletion rehearses with the same body: the confirmation is the server's word on THIS version.
|
|
18
|
+
* Putting a record in the trash, or taking it out, can be undone: it runs on the click. A new
|
|
19
|
+
* record, or one not read yet, has none. Over REST a `DELETE`'s fields travel in its query string
|
|
20
|
+
* (client-framework 1.12): sent in a body, a dry run would run the real delete.
|
|
21
|
+
*/
|
|
22
|
+
export function useRecordLifecycle(record) {
|
|
23
|
+
const { entity } = record;
|
|
24
|
+
const deletion = useRouteCommand(entity.delete, entity.key);
|
|
25
|
+
const archival = useRouteCommand(entity.archive, entity.key);
|
|
26
|
+
const restoral = useRouteCommand(entity.restore, entity.key);
|
|
27
|
+
const stored = !record.isNew && record.status === "ready";
|
|
28
|
+
if (!stored)
|
|
29
|
+
return {};
|
|
30
|
+
const held = record.record;
|
|
31
|
+
const version = held["version"];
|
|
32
|
+
const checked = typeof version === "number" ? { origin_version: version } : {};
|
|
33
|
+
const archived = held["archived_at"] !== null && held["archived_at"] !== undefined;
|
|
34
|
+
const action = (command, rehearsed) => ({
|
|
35
|
+
run: () => command.run(record.id, checked),
|
|
36
|
+
...(rehearsed ? { rehearse: () => command.rehearse(record.id, checked) } : {}),
|
|
37
|
+
busy: command.busy,
|
|
38
|
+
error: command.error,
|
|
39
|
+
rehearsal: command.rehearsal,
|
|
40
|
+
reset: command.reset,
|
|
41
|
+
});
|
|
42
|
+
return {
|
|
43
|
+
...(entity.delete === undefined ? {} : { delete: action(deletion, true) }),
|
|
44
|
+
...(entity.archive === undefined || archived ? {} : { archive: action(archival, false) }),
|
|
45
|
+
...(entity.restore === undefined || !archived
|
|
46
|
+
? {}
|
|
47
|
+
: { restore: action(restoral, false) }),
|
|
48
|
+
};
|
|
49
|
+
}
|
package/dist/web/index.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export { EntityTags } from "./record/EntityTags.js";
|
|
|
18
18
|
export { type LineColumn, type LineControl, type LinesLook, RecordLinesEditor, } from "./record/lines.js";
|
|
19
19
|
export { type RecordOpening, RecordOpeningProvider, useRecordOpening, } from "./record/opening.js";
|
|
20
20
|
export { countOf, factsOf, RecordLines } from "./record/record.js";
|
|
21
|
+
export { RecordLifecycle } from "./record/RecordLifecycle.js";
|
|
21
22
|
export { RelatedList } from "./record/RelatedList.js";
|
|
22
23
|
export { ServiceButton } from "./record/ServiceButton.js";
|
|
23
24
|
export { cardOf, relationOf } from "./record/summary.js";
|
package/dist/web/index.js
CHANGED
|
@@ -18,6 +18,7 @@ export { EntityTags } from "./record/EntityTags.js";
|
|
|
18
18
|
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
|
+
export { RecordLifecycle } from "./record/RecordLifecycle.js";
|
|
21
22
|
export { RelatedList } from "./record/RelatedList.js";
|
|
22
23
|
export { ServiceButton } from "./record/ServiceButton.js";
|
|
23
24
|
export { cardOf, relationOf } from "./record/summary.js";
|
|
@@ -15,8 +15,9 @@ import { pilesOf } from "./groups.js";
|
|
|
15
15
|
import { OpenInMenu, openOptions, targetsFor } from "./openIn.js";
|
|
16
16
|
import { pivotOf } from "./pivot.js";
|
|
17
17
|
import { over, presentationOf } from "./presentation.js";
|
|
18
|
-
import { useRowCommands } from "./rowCommands.js";
|
|
18
|
+
import { RESTORE, useRowCommands, } from "./rowCommands.js";
|
|
19
19
|
import { Button, Callout, List, Pagination, pathKey, RecordCard, SearchField, Tag, } from "@sincpro/web-ui";
|
|
20
|
+
import { RotateCcw } from "lucide-react";
|
|
20
21
|
import { useEffect, useId, useMemo, useRef, useState } from "react";
|
|
21
22
|
/** What `useCrumbs` reads when the list is not in a workspace: no trail, and nothing to follow. */
|
|
22
23
|
const NO_TRAIL = [];
|
|
@@ -290,8 +291,21 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
|
|
|
290
291
|
: {};
|
|
291
292
|
const records = groups.buckets.reduce((sum, bucket) => sum + bucket.count, 0);
|
|
292
293
|
// A row's actions: the entity's Commands, then whatever else the screen offers.
|
|
293
|
-
|
|
294
|
-
|
|
294
|
+
// The trash (`trashOf`): each row is brought back from where it is, with the entity's own
|
|
295
|
+
// `restore` — it can be undone, so it runs on the click; the list reads again after.
|
|
296
|
+
const restoring = listing.definition?.trash === true && listing.entity.restore !== undefined;
|
|
297
|
+
const offered = useMemo(() => restoring
|
|
298
|
+
? [
|
|
299
|
+
...commands,
|
|
300
|
+
{
|
|
301
|
+
command: RESTORE,
|
|
302
|
+
label: frameworkCopy().record.restore,
|
|
303
|
+
icon: RotateCcw,
|
|
304
|
+
},
|
|
305
|
+
]
|
|
306
|
+
: commands, [restoring, commands]);
|
|
307
|
+
const rowCommands = useRowCommands(listing, offered);
|
|
308
|
+
const rowActions = offered.length === 0 && askedRowActions === undefined
|
|
295
309
|
? undefined
|
|
296
310
|
: (row) => [...rowCommands.rowActions(row), ...(askedRowActions?.(row) ?? [])];
|
|
297
311
|
const refused = rowCommands.error === null ? null : explain(rowCommands.error);
|
|
@@ -36,6 +36,8 @@ export type RowCommand<T, C extends CommandBodies = CommandBodies> = {
|
|
|
36
36
|
body?: (row: T) => C[N];
|
|
37
37
|
};
|
|
38
38
|
}[keyof C & string];
|
|
39
|
+
/** The row action of the trash (`trashOf`): the entity's `restore` route, run from the row. */
|
|
40
|
+
export declare const RESTORE = "restore";
|
|
39
41
|
export type RowCommands<T> = {
|
|
40
42
|
rowActions: (row: T) => readonly RowAction[];
|
|
41
43
|
/** The last refusal, until `dismiss`. */
|
|
@@ -3,6 +3,8 @@ import { bodyFor, pathFor, retryKeys } from "@sincpro/client-framework";
|
|
|
3
3
|
import { matches } from "@sincpro/criteria";
|
|
4
4
|
import { useFramework } from "../../react/context.js";
|
|
5
5
|
import { useCallback, useState } from "react";
|
|
6
|
+
/** The row action of the trash (`trashOf`): the entity's `restore` route, run from the row. */
|
|
7
|
+
export const RESTORE = "restore";
|
|
6
8
|
export function useRowCommands(listing, commands) {
|
|
7
9
|
const { transport } = useFramework();
|
|
8
10
|
const [running, setRunning] = useState(new Set());
|
|
@@ -12,7 +14,10 @@ export function useRowCommands(listing, commands) {
|
|
|
12
14
|
const { entity, meta } = listing;
|
|
13
15
|
const key = meta?.get_id || meta?.identity || "id";
|
|
14
16
|
const run = useCallback(async (one, row) => {
|
|
15
|
-
|
|
17
|
+
// «Restore» on a row of the trash runs the entity's own `restore` route (`trashOf`), unless
|
|
18
|
+
// the entity declares a Command of that name.
|
|
19
|
+
const route = entity.commands[one.command] ??
|
|
20
|
+
(one.command === RESTORE ? entity.restore : undefined);
|
|
16
21
|
if (route === undefined)
|
|
17
22
|
throw new Error(`${entity.key} declares no command "${one.command}"`);
|
|
18
23
|
const id = String(row[key]);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AnyRecord } from "@sincpro/criteria";
|
|
2
|
+
import type { RecordReading } from "../../react/useRecord.js";
|
|
3
|
+
/**
|
|
4
|
+
* The record's own lifecycle as buttons — «Mover a la papelera» / «Restaurar» and «Eliminar»,
|
|
5
|
+
* each when its entity declares sincpro_framework's `Archive`, `Restore`, `Delete` — a deletion
|
|
6
|
+
* asking the server first what it would do (its dry run) and doing it on «Hacerlo», the trash's
|
|
7
|
+
* two on the click (they can be undone). Nothing when the entity declares none, or the record is
|
|
8
|
+
* new.
|
|
9
|
+
*
|
|
10
|
+
* <Record.Actions>
|
|
11
|
+
* <RecordLifecycle record={member} onDone={() => api.close()} />
|
|
12
|
+
* </Record.Actions>
|
|
13
|
+
*
|
|
14
|
+
* Context: `EntityRecord` draws it; a screen of its own draws it the same, or drops to
|
|
15
|
+
* `useRecordLifecycle` and draws its own. What happens after is the screen's (`onDone`): in a
|
|
16
|
+
* workspace the surface closes — the record is gone —, and every list that showed it reads
|
|
17
|
+
* again by itself (the write is announced).
|
|
18
|
+
*/
|
|
19
|
+
export declare function RecordLifecycle<T extends AnyRecord>({ record, onDone, }: {
|
|
20
|
+
record: RecordReading<T>;
|
|
21
|
+
/** Done: which action — after `delete` and `archive` the record is out of every reading. */
|
|
22
|
+
onDone?: (action: "delete" | "archive" | "restore") => void;
|
|
23
|
+
}): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { frameworkCopy } from "../../core/copy.js";
|
|
4
|
+
import { useRecordLifecycle } from "../../react/useRecordLifecycle.js";
|
|
5
|
+
import { ActionButton } from "./ActionButton.js";
|
|
6
|
+
/**
|
|
7
|
+
* The record's own lifecycle as buttons — «Mover a la papelera» / «Restaurar» and «Eliminar»,
|
|
8
|
+
* each when its entity declares sincpro_framework's `Archive`, `Restore`, `Delete` — a deletion
|
|
9
|
+
* asking the server first what it would do (its dry run) and doing it on «Hacerlo», the trash's
|
|
10
|
+
* two on the click (they can be undone). Nothing when the entity declares none, or the record is
|
|
11
|
+
* new.
|
|
12
|
+
*
|
|
13
|
+
* <Record.Actions>
|
|
14
|
+
* <RecordLifecycle record={member} onDone={() => api.close()} />
|
|
15
|
+
* </Record.Actions>
|
|
16
|
+
*
|
|
17
|
+
* Context: `EntityRecord` draws it; a screen of its own draws it the same, or drops to
|
|
18
|
+
* `useRecordLifecycle` and draws its own. What happens after is the screen's (`onDone`): in a
|
|
19
|
+
* workspace the surface closes — the record is gone —, and every list that showed it reads
|
|
20
|
+
* again by itself (the write is announced).
|
|
21
|
+
*/
|
|
22
|
+
export function RecordLifecycle({ record, onDone, }) {
|
|
23
|
+
const lifecycle = useRecordLifecycle(record);
|
|
24
|
+
const copy = frameworkCopy().record;
|
|
25
|
+
const shown = ["archive", "restore", "delete"].filter((one) => lifecycle[one] !== undefined);
|
|
26
|
+
if (shown.length === 0)
|
|
27
|
+
return null;
|
|
28
|
+
return (_jsx(_Fragment, { children: shown.map((one) => (_jsx(ActionButton, { action: lifecycle[one], label: copy[one], onDone: () => onDone?.(one) }, one))) }));
|
|
29
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Entity, type
|
|
1
|
+
import { type Entity, type ResourceRef } from "@sincpro/client-framework";
|
|
2
2
|
import { type AnyRecord, type Criteria, type Expression } from "@sincpro/criteria";
|
|
3
3
|
import { type ListDefinition } from "../../core/list.js";
|
|
4
4
|
import type { OpenTarget } from "@sincpro/web-ui";
|
|
@@ -20,7 +20,7 @@ import { type ReactNode } from "react";
|
|
|
20
20
|
* that already committed — the holder gives an opening without `choose`.
|
|
21
21
|
*/
|
|
22
22
|
export type RecordOpening = {
|
|
23
|
-
open: (ref:
|
|
23
|
+
open: (ref: ResourceRef, to: OpenTarget) => void;
|
|
24
24
|
/** Where it may open from here, the default first. */
|
|
25
25
|
targets: readonly OpenTarget[];
|
|
26
26
|
/** The form is not on a page — a panel, a peek, a modal: a list inside it starts as rows
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Entity, type Transport } from "@sincpro/client-framework";
|
|
2
2
|
import { type AnyRecord, type Meta } from "@sincpro/criteria";
|
|
3
3
|
import { type ViewProps, type ViewSpec } from "@sincpro/web-composer";
|
|
4
|
-
import {
|
|
4
|
+
import type { ListDefinition } from "../../core/list.js";
|
|
5
5
|
import { type ComponentType } from "react";
|
|
6
6
|
/**
|
|
7
7
|
* An entity as the composer's view: one `ViewSpec` for its list (a reference without an id)
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { isEntityId, listRoute, NEW_PARAM, scopeOfRef, } from "@sincpro/client-framework";
|
|
3
|
+
import { isEntityId, listRoute, NEW_PARAM, scopeNameOf, scopeOfRef, } from "@sincpro/client-framework";
|
|
4
4
|
import { matching } from "@sincpro/criteria";
|
|
5
5
|
import { usePhone, } from "@sincpro/web-composer";
|
|
6
|
-
import { scopeNameOf } from "../../core/list.js";
|
|
7
6
|
import { lookupOf } from "../../core/lookup.js";
|
|
8
7
|
import { ListScopeProvider } from "../../react/scope.js";
|
|
9
8
|
import { useListing } from "../../react/useListing.js";
|
|
@@ -52,7 +51,7 @@ function recordOf(entity, title) {
|
|
|
52
51
|
}
|
|
53
52
|
/**
|
|
54
53
|
* What a reference reads as before its view names it — a crumb whose view is not mounted, a
|
|
55
|
-
* record still loading: the list is the view's name (with its cut's, `
|
|
54
|
+
* record still loading: the list is the view's name (with its cut's, `entity.listRef`); a record
|
|
56
55
|
* its key when the key is something a person reads (`F-2026-0004`), the view's name when it is
|
|
57
56
|
* a machine's (a UUID v7, `isEntityId`).
|
|
58
57
|
*/
|
|
@@ -73,7 +72,7 @@ export function entityView(entity, options) {
|
|
|
73
72
|
return function EntityView(props) {
|
|
74
73
|
const record = props.resource.id !== undefined || props.resource.params?.[NEW_PARAM] !== undefined;
|
|
75
74
|
// A chooser opened by a picker offers only what the picker may choose, and a list opened
|
|
76
|
-
// under a cut (`
|
|
75
|
+
// under a cut (`entity.listRef`) shows only what it cuts: the cut travels in the reference, and
|
|
77
76
|
// the list — the application's own too — reads under it.
|
|
78
77
|
const cut = record ? undefined : scopeOfRef(props.resource);
|
|
79
78
|
const list = cut === undefined ? (_jsx(List, { ...props })) : (_jsx(ListScopeProvider, { value: { key: entity.key, selection: cut }, children: _jsx(List, { ...props }) }));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { TRAIL_PARAM } from "@sincpro/client-framework";
|
|
4
4
|
import { labelOf, nameOf } from "@sincpro/criteria";
|
|
5
5
|
import { useCrumbs } from "@sincpro/web-composer";
|
|
@@ -12,6 +12,7 @@ import { useHistory } from "../../react/useHistory.js";
|
|
|
12
12
|
import { useRecord } from "../../react/useRecord.js";
|
|
13
13
|
import { useSummaryOf } from "../../react/useSummary.js";
|
|
14
14
|
import { dirtyOf, RecordField } from "../record/edit.js";
|
|
15
|
+
import { RecordLifecycle } from "../record/RecordLifecycle.js";
|
|
15
16
|
import { Refused } from "../Refused.js";
|
|
16
17
|
import { useRecordInWorkspace } from "./workspace.js";
|
|
17
18
|
import { Button, Callout, FormSection, Record, Skeleton } from "@sincpro/web-ui";
|
|
@@ -147,7 +148,14 @@ export function EntityRecord({ api, resource, entity, fields, pages, actions, ti
|
|
|
147
148
|
const { meta, locale, edit } = reading;
|
|
148
149
|
const layout = formOf(meta, entity.summary);
|
|
149
150
|
const shown = fields ?? layout.fields;
|
|
150
|
-
|
|
151
|
+
// The record's own lifecycle (its `Delete`, its trash) beside the screen's commands; once it is
|
|
152
|
+
// out of every reading the surface closes — every list that showed it reads again by itself.
|
|
153
|
+
const lifecycle = reading.isNew ||
|
|
154
|
+
(entity.delete === undefined &&
|
|
155
|
+
entity.archive === undefined &&
|
|
156
|
+
entity.restore === undefined) ? null : (_jsx(RecordLifecycle, { record: reading, onDone: (done) => (done === "restore" ? reading.reload() : api.close()) }));
|
|
157
|
+
const own = actions?.(reading) ?? null;
|
|
158
|
+
const ownActions = own === null && lifecycle === null ? null : (_jsxs(_Fragment, { children: [own, lifecycle] }));
|
|
151
159
|
const tabs = pages ?? layout.pages;
|
|
152
160
|
return (_jsxs(Record, { ...screen.record, children: [crumbs.length === 0 && pager === undefined && ownActions === null ? null : (_jsxs(Record.Rail, { children: [crumbs.length === 0 ? null : _jsx(Record.Crumbs, { crumbs: crumbs }), pager === undefined ? null : _jsx(Record.Pager, { ...pager }), ownActions === null ? null : _jsx(Record.Actions, { children: ownActions })] })), _jsxs(Record.Paper, { layout: "horizontal", children: [edit.conflict || edit.restored ? (_jsxs("div", { className: "flex flex-col gap-3", children: [edit.conflict ? (_jsx(Callout, { tone: "warn", title: copy.conflict, children: _jsx(Button, { size: "sm", role: "secondary", onClick: reading.reload, children: copy.reload }) })) : null, edit.restored ? (_jsx(Callout, { tone: "info", title: copy.restored, children: null })) : null] })) : null, _jsx(FormSection, { columns: api.surface === "page" || api.surface === "modal" ? 2 : 1, children: shown.map((name) => (_jsx(RecordField, { record: reading, name: name }, name))) }), edit.advice
|
|
153
161
|
.filter((one) => (one.path?.length ?? 0) <= 1)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sincpro/web-framework",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.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",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@opentelemetry/resources": "^3.1.0",
|
|
41
41
|
"@opentelemetry/sdk-trace": "^3.1.0",
|
|
42
42
|
"@sentry/browser": "^11.11.0",
|
|
43
|
-
"@sincpro/client-framework": "^
|
|
43
|
+
"@sincpro/client-framework": "^2.0.0",
|
|
44
44
|
"@sincpro/criteria": "^2.1.0",
|
|
45
45
|
"@sincpro/criteria-react": "^2.1.0",
|
|
46
46
|
"@sincpro/web-composer": "^1.7.0",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"@opentelemetry/resources": "3.1.0",
|
|
73
73
|
"@opentelemetry/sdk-trace": "3.1.0",
|
|
74
74
|
"@sentry/browser": "11.11.0",
|
|
75
|
-
"@sincpro/client-framework": "^
|
|
75
|
+
"@sincpro/client-framework": "^2.0.0",
|
|
76
76
|
"@sincpro/criteria": "^2.1.0",
|
|
77
77
|
"@sincpro/criteria-react": "^2.1.0",
|
|
78
78
|
"@sincpro/web-composer": "^1.7.0",
|