@entifix/next-shell 0.20.3 → 0.21.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 +16 -1
- package/dist/lib/crud/index.d.ts +1 -0
- package/dist/lib/crud/index.d.ts.map +1 -1
- package/dist/lib/crud/index.js +1 -0
- package/dist/lib/crud/index.js.map +1 -1
- package/dist/lib/crud/make-entity-crud.d.ts.map +1 -1
- package/dist/lib/crud/make-entity-crud.js +128 -58
- package/dist/lib/crud/make-entity-crud.js.map +1 -1
- package/dist/lib/crud/make-entity-crud.types.d.ts +68 -1
- package/dist/lib/crud/make-entity-crud.types.d.ts.map +1 -1
- package/dist/lib/crud/make-entity-crud.types.js.map +1 -1
- package/dist/lib/crud/reference-labels.d.ts +27 -0
- package/dist/lib/crud/reference-labels.d.ts.map +1 -0
- package/dist/lib/crud/reference-labels.js +159 -0
- package/dist/lib/crud/reference-labels.js.map +1 -0
- package/dist/lib/crud/regions.d.ts +25 -0
- package/dist/lib/crud/regions.d.ts.map +1 -0
- package/dist/lib/crud/regions.js +82 -0
- package/dist/lib/crud/regions.js.map +1 -0
- package/dist/lib/crud/related-columns.d.ts +29 -0
- package/dist/lib/crud/related-columns.d.ts.map +1 -0
- package/dist/lib/crud/related-columns.js +141 -0
- package/dist/lib/crud/related-columns.js.map +1 -0
- package/dist/lib/i18n/catalog/en.d.ts.map +1 -1
- package/dist/lib/i18n/catalog/en.js +6 -0
- package/dist/lib/i18n/catalog/en.js.map +1 -1
- package/dist/lib/i18n/catalog/es.d.ts +8 -0
- package/dist/lib/i18n/catalog/es.d.ts.map +1 -1
- package/dist/lib/i18n/catalog/es.js +7 -1
- package/dist/lib/i18n/catalog/es.js.map +1 -1
- package/dist/lib/i18n/catalog/index.d.ts +12 -0
- package/dist/lib/i18n/catalog/index.d.ts.map +1 -1
- package/package.json +9 -9
- package/dist/lib/crud/use-link-labels.d.ts +0 -32
- package/dist/lib/crud/use-link-labels.d.ts.map +0 -1
- package/dist/lib/crud/use-link-labels.js +0 -76
- package/dist/lib/crud/use-link-labels.js.map +0 -1
package/README.md
CHANGED
|
@@ -2,10 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
The Next.js application shell. `makeEntityCrud` derives the list, detail and edit screens for an entity from its metadata; `BackOfficeShell` and `WorkspaceShell` provide the chrome, sidebar navigation, breadcrumbs, workspace tabs and command palette around them. Drafts and pending writes persist in IndexedDB.
|
|
4
4
|
|
|
5
|
-
`makeEntityCrud` takes a `delete` policy (`confirm`, `undo` or `typed`) and a `facets` adapter, announces saves and deletions, names a
|
|
5
|
+
`makeEntityCrud` takes a `delete` policy (`confirm`, `undo` or `typed`) and a `facets` adapter, announces saves and deletions, names a record in its rows, toasts and breadcrumb rather than by its id, and keeps focus on a heading after every write. `ConfirmAction` asks before a Server Action acts, with or without JavaScript; the action guards itself with `whenConfirmed`. `AccountMenu` offers theme and density.
|
|
6
6
|
|
|
7
7
|
The `server` entry holds the route handlers a Next backend needs: a same-origin proxy to your services, session refresh and cookies, health, and record search across services — and `whenConfirmed` and `readThemeCookies`.
|
|
8
8
|
|
|
9
|
+
## Names, not ids
|
|
10
|
+
|
|
11
|
+
A member that holds another entity's id declares `@accessor({ references: { entity: 'domain:key' } })`, and an entity declares the member it is called by with `@entity({ labelMember })`. The host mounts `ReferenceLabelsHost` once, beside its other providers, with one registration per target entity:
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
const REFERENCE_LABELS: ReferenceLabelRegistration[] = [
|
|
15
|
+
[Customer, adapters.customers],
|
|
16
|
+
[Invoice, adapters.invoices, { labelProperty: 'number' }],
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
<ReferenceLabelsHost registrations={REFERENCE_LABELS}>{children}</ReferenceLabelsHost>;
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Every screen then shows the target's name where it would have shown the key, read in one request per target entity per page and cached per id, so a record's page reuses what its list read. A target's `id` must be `filterable`. An entity no registration reads shows its raw id, muted, and `onUnregistered` is told its key once, for the host to warn about in development.
|
|
23
|
+
|
|
9
24
|
## Install
|
|
10
25
|
|
|
11
26
|
```sh
|
package/dist/lib/crud/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './entity-crud-form.js';
|
|
2
2
|
export * from './make-entity-crud.js';
|
|
3
3
|
export * from './make-entity-crud.types.js';
|
|
4
|
+
export * from './reference-labels.js';
|
|
4
5
|
export * from './slug.js';
|
|
5
6
|
export * from './use-crud-render-link.js';
|
|
6
7
|
export * from './use-entity-affordances.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/crud/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,WAAW,CAAC;AAC1B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/crud/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,uBAAuB,CAAC;AACtC,cAAc,WAAW,CAAC;AAC1B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC"}
|
package/dist/lib/crud/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './entity-crud-form.js';
|
|
2
2
|
export * from './make-entity-crud.js';
|
|
3
3
|
export * from './make-entity-crud.types.js';
|
|
4
|
+
export * from './reference-labels.js';
|
|
4
5
|
export * from './slug.js';
|
|
5
6
|
export * from './use-crud-render-link.js';
|
|
6
7
|
export * from './use-entity-affordances.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/crud/index.ts"],"sourcesContent":["export * from './entity-crud-form.js';\nexport * from './make-entity-crud.js';\nexport * from './make-entity-crud.types.js';\nexport * from './slug.js';\nexport * from './use-crud-render-link.js';\nexport * from './use-entity-affordances.js';\nexport * from './use-entity-bulk.js';\nexport * from './use-entity-link-sources.js';\n"],"names":[],"mappings":"AAAA,cAAc,wBAAwB;AACtC,cAAc,wBAAwB;AACtC,cAAc,8BAA8B;AAC5C,cAAc,YAAY;AAC1B,cAAc,4BAA4B;AAC1C,cAAc,8BAA8B;AAC5C,cAAc,uBAAuB;AACrC,cAAc,+BAA+B"}
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/crud/index.ts"],"sourcesContent":["export * from './entity-crud-form.js';\nexport * from './make-entity-crud.js';\nexport * from './make-entity-crud.types.js';\nexport * from './reference-labels.js';\nexport * from './slug.js';\nexport * from './use-crud-render-link.js';\nexport * from './use-entity-affordances.js';\nexport * from './use-entity-bulk.js';\nexport * from './use-entity-link-sources.js';\n"],"names":[],"mappings":"AAAA,cAAc,wBAAwB;AACtC,cAAc,wBAAwB;AACtC,cAAc,8BAA8B;AAC5C,cAAc,wBAAwB;AACtC,cAAc,YAAY;AAC1B,cAAc,4BAA4B;AAC1C,cAAc,8BAA8B;AAC5C,cAAc,uBAAuB;AACrC,cAAc,+BAA+B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"make-entity-crud.d.ts","sourceRoot":"","sources":["../../../src/lib/crud/make-entity-crud.tsx"],"names":[],"mappings":"AAEA,OAAO,EAIL,KAAK,mBAAmB,EAKzB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAIL,KAAK,MAAM,EACX,KAAK,iBAAiB,EAevB,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"make-entity-crud.d.ts","sourceRoot":"","sources":["../../../src/lib/crud/make-entity-crud.tsx"],"names":[],"mappings":"AAEA,OAAO,EAIL,KAAK,mBAAmB,EAKzB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAIL,KAAK,MAAM,EACX,KAAK,iBAAiB,EAevB,MAAM,eAAe,CAAC;AAmBvB,OAAO,EAAS,OAAO,EAAgB,MAAM,QAAQ,CAAC;AAQtD,OAAO,KAAK,EAEV,UAAU,EAEV,iBAAiB,EAGlB,MAAM,6BAA6B,CAAC;AAmBrC;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,mBAAmB,CAAC;AAE9C;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,SAAS,EACrC,QAAQ,EAAE,SAAS,EACnB,UAAU,EAAE,MAAM,SAAS,GAC1B,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAE9B;AAsID,wBAAgB,cAAc,CAAC,OAAO,SAAS,MAAM,EAAE,SAAS,EAC9D,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,EAC7C,OAAO,EAAE,iBAAiB,CAAC,SAAS,EAAE,OAAO,CAAC,GAC7C,UAAU,CAAC,OAAO,CAAC,CA4oBrB"}
|
|
@@ -3,22 +3,24 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
|
3
3
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
4
|
import { deleteUCFactory, EntityIdTag, EntityTag, getUCFactory, loadUCFactory, saveUCFactory } from '@entifix/business';
|
|
5
5
|
import { coerceFiltering, describeEntityColumns, envelopeEntityName, extractMetaEntity, Internal, isFailure, parseRsql, serializeRsql, settled } from '@entifix/core';
|
|
6
|
-
import {
|
|
6
|
+
import { EntityTable, useCasesForSurface, useFocusOnArrival, useRecordLabel, useT, useToasts, useTranslateKey } from '@entifix/react-controls';
|
|
7
7
|
import { entityQueryScope, useDataLoading, useEntityRecord, useFacetCounts, useOptimisticMutation } from '@entifix/react-integration';
|
|
8
8
|
import { useQueryClient } from '@tanstack/react-query';
|
|
9
9
|
import { Cause, Context, Effect, Exit } from 'effect';
|
|
10
|
-
import { useParams, useRouter } from 'next/navigation';
|
|
11
|
-
import { useEffect, useRef } from 'react';
|
|
10
|
+
import { useParams, useRouter, useSearchParams } from 'next/navigation';
|
|
11
|
+
import { useEffect, useId, useMemo, useRef } from 'react';
|
|
12
12
|
import { useBreadcrumbLabel } from '../back-office/breadcrumb-labels.js';
|
|
13
13
|
import { useLocaleHref } from '../i18n/index.js';
|
|
14
14
|
import { useEntityNavHost } from '../workspace/entity-nav.js';
|
|
15
15
|
import { EntityCrudForm } from './entity-crud-form.js';
|
|
16
|
+
import { PREFILL_PARAM, readPrefill, RecordRegions, useRegion } from './regions.js';
|
|
17
|
+
import { planRelated, useRelatedColumns } from './related-columns.js';
|
|
16
18
|
import { CATALOG_NEW_SLUG, slugToEntityId } from './slug.js';
|
|
17
19
|
import { useCrudRenderLink } from './use-crud-render-link.js';
|
|
18
20
|
import { useEntityAffordances } from './use-entity-affordances.js';
|
|
19
21
|
import { useEntityBulk } from './use-entity-bulk.js';
|
|
20
|
-
import { LinkLabelCell, useLinkLabels } from './use-link-labels.js';
|
|
21
22
|
/** What a picker defaults to reading off its target. */ const TARGET_NAME_PROPERTY = 'name';
|
|
23
|
+
/** A prefilled create with no host draft store keeps nothing between visits. */ const ignoreDraft = ()=>undefined;
|
|
22
24
|
/**
|
|
23
25
|
* One repository adapter, by its key, as the context the use-cases run
|
|
24
26
|
* against.
|
|
@@ -126,7 +128,7 @@ import { LinkLabelCell, useLinkLabels } from './use-link-labels.js';
|
|
|
126
128
|
return links.map((link)=>link.useBaseFiltering == null ? void 0 : link.useBaseFiltering.call(link, record));
|
|
127
129
|
}
|
|
128
130
|
export function makeEntityCrud(entityConstructor, options) {
|
|
129
|
-
const { useAdapters, basePath, catalogKey, repository, hiddenFields = [], columns, toolbar, pageSize, initialFiltering, links = [], metadataSource: givenMetadataSource, metadata, useCases, write, delete: deletePolicy = 'confirm', facets } = options;
|
|
131
|
+
const { useAdapters, basePath, catalogKey, repository, hiddenFields = [], columns, toolbar, pageSize, initialFiltering, links = [], related = [], regions, metadataSource: givenMetadataSource, metadata, useCases, write, delete: deletePolicy = 'confirm', facets } = options;
|
|
130
132
|
if (givenMetadataSource !== undefined && metadata !== undefined) {
|
|
131
133
|
throw new Error(`${entityConstructor.name} was given both metadataSource and metadata; pass one`);
|
|
132
134
|
}
|
|
@@ -161,7 +163,6 @@ export function makeEntityCrud(entityConstructor, options) {
|
|
|
161
163
|
throw new Error(`${entityConstructor.name} must declare labelKey and pluralKey on @entity() to be generated`);
|
|
162
164
|
}
|
|
163
165
|
// Narrowed once, for the closures below that TypeScript cannot follow.
|
|
164
|
-
const labelKey = entityLabelKey;
|
|
165
166
|
const pluralKey = entityPluralKey;
|
|
166
167
|
// Computed once: a descriptor is a property of the class, so nothing about it
|
|
167
168
|
// depends on the record being edited. `linkLabelProperty`/`linkSearchProperty`
|
|
@@ -176,14 +177,7 @@ export function makeEntityCrud(entityConstructor, options) {
|
|
|
176
177
|
name,
|
|
177
178
|
key
|
|
178
179
|
}));
|
|
179
|
-
|
|
180
|
-
const named = descriptors.find((descriptor)=>{
|
|
181
|
-
if (descriptor.type === 'id' || hiddenFields.includes(descriptor.name)) return false;
|
|
182
|
-
const value = record == null ? void 0 : record[descriptor.name];
|
|
183
|
-
return value != null && String(value) !== '';
|
|
184
|
-
});
|
|
185
|
-
return named === undefined ? undefined : String(record[named.name]);
|
|
186
|
-
};
|
|
180
|
+
const relatedPlans = planRelated(entityConstructor, descriptors, related);
|
|
187
181
|
const linkPlans = links.map((link)=>{
|
|
188
182
|
var _link_labelProperty, _link_searchProperty;
|
|
189
183
|
const descriptor = descriptors.find((entry)=>entry.name === link.field);
|
|
@@ -197,7 +191,12 @@ export function makeEntityCrud(entityConstructor, options) {
|
|
|
197
191
|
})
|
|
198
192
|
});
|
|
199
193
|
});
|
|
200
|
-
|
|
194
|
+
/**
|
|
195
|
+
* The generated list itself — the table, its reads, its verbs — shared by the
|
|
196
|
+
* list page and by a related region on another record's page. A region holds
|
|
197
|
+
* it to a fixed filter that is not a removable chip and keeps its pager in
|
|
198
|
+
* component state, never in the URL.
|
|
199
|
+
*/ function ListBody({ baseFiltering, newHref: givenNewHref, listPageSize = pageSize, listInitialFiltering, onVerbSettled }) {
|
|
201
200
|
var _syncFailure;
|
|
202
201
|
var _affordances_metadata, _affordances_metadata1, _affordances_metadata2;
|
|
203
202
|
const adapters = useAdapters();
|
|
@@ -218,24 +217,15 @@ export function makeEntityCrud(entityConstructor, options) {
|
|
|
218
217
|
// the same prefix `useReactiveInvalidation`already targets, so a generated
|
|
219
218
|
// list now also refreshes on a reactive change event.
|
|
220
219
|
queryKey: scope
|
|
221
|
-
},
|
|
222
|
-
initialPageSize:
|
|
223
|
-
},
|
|
224
|
-
initialFiltering
|
|
220
|
+
}, listPageSize === undefined ? {} : {
|
|
221
|
+
initialPageSize: listPageSize
|
|
222
|
+
}, listInitialFiltering === undefined ? {} : {
|
|
223
|
+
initialFiltering: listInitialFiltering
|
|
224
|
+
}, baseFiltering === undefined ? {} : {
|
|
225
|
+
baseFiltering
|
|
225
226
|
}));
|
|
226
|
-
//
|
|
227
|
-
const
|
|
228
|
-
field: plan.field,
|
|
229
|
-
entityConstructor: plan.entityConstructor,
|
|
230
|
-
labelProperty: plan.descriptor.linkLabelProperty,
|
|
231
|
-
ctx: crudContextOf(adapters, plan.repository)
|
|
232
|
-
})), pager.items);
|
|
233
|
-
const linkColumns = linkPlans.map((plan)=>/*#__PURE__*/ _jsx(EntityColumn, {
|
|
234
|
-
field: plan.field,
|
|
235
|
-
render: (item)=>/*#__PURE__*/ _jsx(LinkLabelCell, {
|
|
236
|
-
label: linkLabel(plan.field, item)
|
|
237
|
-
})
|
|
238
|
-
}, plan.field));
|
|
227
|
+
// Values that live in another entity, one read per column per page.
|
|
228
|
+
const relatedColumns = useRelatedColumns(relatedPlans, pager.items, (plan)=>crudContextOf(adapters, plan.repository));
|
|
239
229
|
const facetCounts = useFacetCounts({
|
|
240
230
|
ctx: facets === undefined ? undefined : adapters[facets],
|
|
241
231
|
members: facetMembers,
|
|
@@ -281,6 +271,7 @@ export function makeEntityCrud(entityConstructor, options) {
|
|
|
281
271
|
void queryClient.invalidateQueries({
|
|
282
272
|
queryKey: scope
|
|
283
273
|
});
|
|
274
|
+
onVerbSettled == null ? void 0 : onVerbSettled();
|
|
284
275
|
});
|
|
285
276
|
// Called unconditionally and the *result* gated, the way the surfaces are
|
|
286
277
|
// read in `EntityForm`: the name begins with `use`, so short-circuiting it
|
|
@@ -291,6 +282,27 @@ export function makeEntityCrud(entityConstructor, options) {
|
|
|
291
282
|
if (item.id == null) return;
|
|
292
283
|
rowVerb.run(key, item.id);
|
|
293
284
|
} : undefined;
|
|
285
|
+
return /*#__PURE__*/ _jsxs(EntityTable, _extends({
|
|
286
|
+
entityConstructor: entityConstructor
|
|
287
|
+
}, pager, {
|
|
288
|
+
items: pager.items,
|
|
289
|
+
totalItems: pager.totalItems,
|
|
290
|
+
hrefFor: (id)=>withLocale(`${basePath}/${String(id)}`),
|
|
291
|
+
newHref: withLocale(givenNewHref != null ? givenNewHref : `${basePath}/${CATALOG_NEW_SLUG}`),
|
|
292
|
+
renderLink: renderLink
|
|
293
|
+
}, affordances, bulk.tableProps, {
|
|
294
|
+
onUseCase: handleRowUseCase,
|
|
295
|
+
onRetry: pager.refetch,
|
|
296
|
+
facets: facetCounts,
|
|
297
|
+
error: (_syncFailure = syncFailure(rowVerb.verb)) != null ? _syncFailure : pager.error,
|
|
298
|
+
children: [
|
|
299
|
+
columns,
|
|
300
|
+
relatedColumns,
|
|
301
|
+
toolbar
|
|
302
|
+
]
|
|
303
|
+
}));
|
|
304
|
+
}
|
|
305
|
+
function ListPage() {
|
|
294
306
|
// The list's heading, and where focus lands when a save or a delete
|
|
295
307
|
// brings the reader back here rather than falling to `<body>`.
|
|
296
308
|
const heading = useRef(null);
|
|
@@ -305,24 +317,52 @@ export function makeEntityCrud(entityConstructor, options) {
|
|
|
305
317
|
className: "m-0 text-step-2 font-semibold text-content focus-ring",
|
|
306
318
|
children: et(pluralKey.replace(/^entity:/, ''))
|
|
307
319
|
}),
|
|
308
|
-
/*#__PURE__*/
|
|
309
|
-
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
320
|
+
/*#__PURE__*/ _jsx(ListBody, _extends({}, initialFiltering === undefined ? {} : {
|
|
321
|
+
listInitialFiltering: initialFiltering
|
|
322
|
+
}))
|
|
323
|
+
]
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* This entity's records that refer to another record, as a region of that
|
|
328
|
+
* record's page
|
|
329
|
+
* ([ADR 0030](../../../../../../docs/adr/0030-a-reference-names-its-target-through-the-owners-read-port.md)):
|
|
330
|
+
* the generated list held to `filtering`, which is fixed and shown as no
|
|
331
|
+
* chip, under its own `h2`, with its own states and its own writes. A verb
|
|
332
|
+
* that settles inside it moves focus to that heading; nothing else on the
|
|
333
|
+
* page is re-read or touched. `prefill` names the members a "New" from here
|
|
334
|
+
* opens already set — the parent record's id.
|
|
335
|
+
*/ function RelatedList({ filtering, labelKey: headingKey, prefill, newHref, pageSize: regionPageSize }) {
|
|
336
|
+
const headingRef = useRef(null);
|
|
337
|
+
const id = useId();
|
|
338
|
+
const heading = useTranslateKey()(headingKey);
|
|
339
|
+
useRegion(id, heading);
|
|
340
|
+
const query = new URLSearchParams(Object.entries(prefill != null ? prefill : {}).map(([member, value])=>[
|
|
341
|
+
`${PREFILL_PARAM}${member}`,
|
|
342
|
+
value
|
|
343
|
+
])).toString();
|
|
344
|
+
return /*#__PURE__*/ _jsxs("section", {
|
|
345
|
+
id: id,
|
|
346
|
+
"aria-labelledby": `${id}-heading`,
|
|
347
|
+
className: "flex flex-col gap-s",
|
|
348
|
+
children: [
|
|
349
|
+
/*#__PURE__*/ _jsx("h2", {
|
|
350
|
+
id: `${id}-heading`,
|
|
351
|
+
ref: headingRef,
|
|
352
|
+
tabIndex: -1,
|
|
353
|
+
className: "m-0 text-step-1 font-semibold text-content focus-ring",
|
|
354
|
+
children: heading
|
|
355
|
+
}),
|
|
356
|
+
/*#__PURE__*/ _jsx(ListBody, _extends({
|
|
357
|
+
baseFiltering: filtering,
|
|
358
|
+
newHref: newHref != null ? newHref : `${basePath}/${CATALOG_NEW_SLUG}${query === '' ? '' : `?${query}`}`
|
|
359
|
+
}, regionPageSize === undefined ? {} : {
|
|
360
|
+
listPageSize: regionPageSize
|
|
361
|
+
}, {
|
|
362
|
+
onVerbSettled: ()=>{
|
|
363
|
+
var _headingRef_current;
|
|
364
|
+
return (_headingRef_current = headingRef.current) == null ? void 0 : _headingRef_current.focus();
|
|
365
|
+
}
|
|
326
366
|
}))
|
|
327
367
|
]
|
|
328
368
|
});
|
|
@@ -344,6 +384,23 @@ export function makeEntityCrud(entityConstructor, options) {
|
|
|
344
384
|
const params = useParams();
|
|
345
385
|
const mounted = useMounted();
|
|
346
386
|
const id = slugToEntityId(slug != null ? slug : params.slug);
|
|
387
|
+
// A create opened from a related region starts with the parent record set:
|
|
388
|
+
// `?prefill.<member>=<value>`, layered under any draft the host restores.
|
|
389
|
+
const searchParams = useSearchParams();
|
|
390
|
+
const prefill = id == null ? readPrefill(searchParams, descriptors) : undefined;
|
|
391
|
+
const prefillKey = prefill === undefined ? '' : JSON.stringify(prefill);
|
|
392
|
+
const formDraft = useMemo(()=>{
|
|
393
|
+
var _ref, _ref1;
|
|
394
|
+
return prefill === undefined ? draft : {
|
|
395
|
+
draft: _extends({}, prefill, draft == null ? void 0 : draft.draft),
|
|
396
|
+
save: (_ref = draft == null ? void 0 : draft.save) != null ? _ref : ignoreDraft,
|
|
397
|
+
clear: (_ref1 = draft == null ? void 0 : draft.clear) != null ? _ref1 : ignoreDraft
|
|
398
|
+
};
|
|
399
|
+
}, // Keyed on the values, not the object a render builds them into.
|
|
400
|
+
[
|
|
401
|
+
draft,
|
|
402
|
+
prefillKey
|
|
403
|
+
]);
|
|
347
404
|
const ctx = crudContextOf(adapters, repository);
|
|
348
405
|
const { entity, isLoading, error: loadError, reload } = useEntityRecord({
|
|
349
406
|
uc: getUCFactory(),
|
|
@@ -442,11 +499,11 @@ export function makeEntityCrud(entityConstructor, options) {
|
|
|
442
499
|
};
|
|
443
500
|
const toasts = useToasts();
|
|
444
501
|
const ct = useT('controls');
|
|
445
|
-
const
|
|
446
|
-
/**
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
502
|
+
const nameOf = useRecordLabel();
|
|
503
|
+
/**
|
|
504
|
+
* What an announcement names: the record, through the one derivation every
|
|
505
|
+
* surface shares, or the entity for one not loaded.
|
|
506
|
+
*/ const recordNoun = (record)=>nameOf(entityConstructor, record);
|
|
450
507
|
// The breadcrumb for this page's segment names the record, never its id:
|
|
451
508
|
// "Nuevo" for a create, the record once it has loaded.
|
|
452
509
|
useBreadcrumbLabel(slug != null ? slug : params.slug, id == null ? ct('form.new') : entity && recordNoun(entity));
|
|
@@ -504,7 +561,7 @@ export function makeEntityCrud(entityConstructor, options) {
|
|
|
504
561
|
*/ const verbs = verbsOf(useCases === undefined ? undefined : adapters[useCases], (_affordances_metadata = affordances.metadata) == null ? void 0 : _affordances_metadata.useCases);
|
|
505
562
|
const recordVerb = useVerb(verbs, ()=>void reload());
|
|
506
563
|
const handleUseCase = verbs === undefined || id == null ? undefined : (key)=>recordVerb.run(key, id);
|
|
507
|
-
|
|
564
|
+
const form = /*#__PURE__*/ _jsx(EntityCrudForm, {
|
|
508
565
|
entityConstructor: entityConstructor,
|
|
509
566
|
catalogKey: catalogKey,
|
|
510
567
|
metadataSource: metadataSource,
|
|
@@ -527,8 +584,20 @@ export function makeEntityCrud(entityConstructor, options) {
|
|
|
527
584
|
onUseCase: handleUseCase,
|
|
528
585
|
backHref: withLocale(basePath),
|
|
529
586
|
renderLink: renderLink,
|
|
530
|
-
draft:
|
|
587
|
+
draft: formDraft
|
|
531
588
|
}, String((_ref2 = entity == null ? void 0 : entity.id) != null ? _ref2 : CATALOG_NEW_SLUG));
|
|
589
|
+
// The records that refer to this one, under its form: an existing record
|
|
590
|
+
// only, since a record being created has nothing referring to it yet.
|
|
591
|
+
if (regions === undefined || id == null || entity === undefined) return form;
|
|
592
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
593
|
+
className: "flex flex-col gap-l",
|
|
594
|
+
children: [
|
|
595
|
+
form,
|
|
596
|
+
/*#__PURE__*/ _jsx(RecordRegions, {
|
|
597
|
+
children: regions(entity)
|
|
598
|
+
})
|
|
599
|
+
]
|
|
600
|
+
});
|
|
532
601
|
}
|
|
533
602
|
return {
|
|
534
603
|
entityConstructor,
|
|
@@ -537,7 +606,8 @@ export function makeEntityCrud(entityConstructor, options) {
|
|
|
537
606
|
entityPluralKey,
|
|
538
607
|
basePath,
|
|
539
608
|
ListPage,
|
|
540
|
-
SingleViewPage
|
|
609
|
+
SingleViewPage,
|
|
610
|
+
RelatedList
|
|
541
611
|
};
|
|
542
612
|
}
|
|
543
613
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/crud/make-entity-crud.tsx"],"sourcesContent":["'use client';\n\nimport {\n deleteUCFactory,\n type EntityFacetCounterTag,\n EntityIdTag,\n type EntityRepositoryTag,\n EntityTag,\n getUCFactory,\n loadUCFactory,\n saveUCFactory,\n} from '@entifix/business';\nimport {\n coerceFiltering,\n describeEntityColumns,\n type EntifixFailure,\n type Entity,\n type EntityConstructor,\n type EntityId,\n type EntityMetadataSource,\n type EntitySelection,\n type EntityUseCaseRunner,\n type EntityWriter,\n envelopeEntityName,\n extractMetaEntity,\n type FilterGroup,\n Internal,\n isFailure,\n parseRsql,\n serializeRsql,\n settled,\n type UseCaseDescriptor,\n} from '@entifix/core';\nimport {\n EntityColumn,\n EntityTable,\n useCasesForSurface,\n useFocusOnArrival,\n useT,\n useToasts,\n} from '@entifix/react-controls';\nimport {\n entityQueryScope,\n type OptimisticMutation,\n useDataLoading,\n useEntityRecord,\n useFacetCounts,\n useOptimisticMutation,\n} from '@entifix/react-integration';\nimport { useQueryClient } from '@tanstack/react-query';\nimport { Cause, Context, Effect, Exit } from 'effect';\nimport { useParams, useRouter } from 'next/navigation';\nimport { useEffect, useRef } from 'react';\n\nimport { useBreadcrumbLabel } from '../back-office/breadcrumb-labels.js';\nimport { useLocaleHref } from '../i18n/index.js';\nimport { useEntityNavHost } from '../workspace/entity-nav.js';\nimport { EntityCrudForm } from './entity-crud-form.js';\nimport type {\n AnyFilterGroup,\n EntityCrud,\n EntityCrudLinkSource,\n EntityCrudOptions,\n EntityCrudSingleViewProps,\n} from './make-entity-crud.types.js';\nimport { CATALOG_NEW_SLUG, slugToEntityId } from './slug.js';\nimport { useCrudRenderLink } from './use-crud-render-link.js';\nimport { useEntityAffordances } from './use-entity-affordances.js';\nimport { useEntityBulk } from './use-entity-bulk.js';\nimport { LinkLabelCell, useLinkLabels } from './use-link-labels.js';\n\n/** What a picker defaults to reading off its target. */\nconst TARGET_NAME_PROPERTY = 'name';\n\n/**\n * What the generated pages' use-cases run against: one repository adapter.\n * Exported because a hand-built screen — a wizard reading records and\n * resolving pickers — runs against exactly the same.\n */\nexport type CrudContext = EntityRepositoryTag;\n\n/**\n * One repository adapter, by its key, as the context the use-cases run\n * against.\n *\n * The cast is the price of naming adapters by key: `AdapterKey` narrows which\n * names may be *offered*, but TypeScript will not carry that narrowing through\n * an index access on a generic record.\n */\nexport function crudContextOf<TAdapters>(\n adapters: TAdapters,\n repository: keyof TAdapters,\n): Context.Context<CrudContext> {\n return adapters[repository] as Context.Context<EntityRepositoryTag>;\n}\n\n/**\n * Builds the list page and the single-record page for one entity.\n *\n * Every catalog entity used to cost ~10 files and ~300 lines whose only variable\n * was a class name: two organisms with a `.types.ts` each, two client pages, two\n * route files. The route files stay (Next needs a module per path); everything\n * between them is derived from the entity's own metadata, so a new reference\n * entity is this call plus a nav entry.\n *\n * Two things are checked here rather than at the call site, because both fail\n * silently otherwise. The catalog key must be the entity's own `@entity({ key })`\n * — they are the same string by convention, and a drifted one titles the form\n * after a different entity in a way only a reader of both catalogs would catch.\n * And a `links` entry must name a real member — a picker aimed at nothing renders\n * identically to a read-only field.\n *\n * **Serves compile-time `@entity()` classes only.** Operator reference data ships\n * with the code, so making this spec-driven would trade type safety for nothing;\n * a vendor-authored `EntitySpecification` renders through a separate path.\n */\n/**\n * A rejected write, as something the form's error slot can render.\n *\n * A typed failure is kept as it is: `useErrorMessage` translates its own code,\n * a business refusal and an outage alike. Anything else is a bug that reached\n * the screen, and is shown as `Internal` — never with its own text, which\n * nobody wrote for a user.\n */\nfunction asFailure(failure: unknown): EntifixFailure {\n return isFailure(failure) ? failure : new Internal();\n}\n\n/**\n * What a write failed with *synchronously* — before any flow took it — or\n * `undefined`. A flow's own failure is toasted by the `PendingFlowsProvider`\n * that settles it, so showing it in the error slot too would tell the operator\n * twice.\n */\nfunction syncFailure(\n mutation: OptimisticMutation<never, unknown>,\n): EntifixFailure | undefined {\n return mutation.status === 'failed' && mutation.flowId === undefined\n ? asFailure(mutation.failure)\n : undefined;\n}\n\n/**\n * A runner's verbs, looked up by the key the served `$metadata` named. A\n * single verb answers either settle mode, so it is run through the optimistic\n * API; a bulk run reports per row and is awaited as a promise whose rejection\n * carries the failure itself.\n */\nfunction verbsOf(\n runner: EntityUseCaseRunner | undefined,\n served: readonly UseCaseDescriptor[] | undefined,\n) {\n if (runner === undefined) return undefined;\n // The key always comes from the served document, so it names a verb in it.\n const descriptor = (key: string) =>\n served?.find(candidate => candidate.key === key) as UseCaseDescriptor;\n return {\n run: (key: string, id: EntityId) => runner.run(descriptor(key), id),\n bulk: (key: string, selection: EntitySelection<Entity>) =>\n Effect.runPromiseExit(runner.bulk(descriptor(key), selection)).then(\n exit =>\n Exit.isSuccess(exit)\n ? exit.value\n : Promise.reject(Cause.squash(exit.cause)),\n ),\n };\n}\n\ntype Verbs = NonNullable<ReturnType<typeof verbsOf>>;\n\n/**\n * One verb on one record, through the optimistic API: `done` runs once the\n * verb took effect — at once when it settled, or when the flow it was handed\n * to completed.\n */\nfunction useVerb(verbs: Verbs | undefined, done: () => void) {\n const verb = useOptimisticMutation<\n { readonly key: string; readonly id: EntityId },\n unknown\n >({\n // Only ever sent from a handler that exists because `verbs` does.\n write: ({ key, id }) => (verbs as Verbs).run(key, id),\n confirm: done,\n });\n const run = (key: string, id: EntityId) => {\n void verb.mutate({ key, id }).then(\n result => {\n if (result._tag === 'settled') done();\n },\n // Shown through `syncFailure`, from the mutation's own state.\n () => undefined,\n );\n };\n return { verb, run };\n}\n\n/** Whether the component is still mounted: a flow can settle after it left. */\nfunction useMounted() {\n const mounted = useRef(true);\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n };\n }, []);\n return mounted;\n}\n\n/**\n * Runs each link's `useBaseFiltering` against the record being edited, in link\n * order, with `undefined` for a link that declares none.\n *\n * Legal for the reason `useEntityLinkSources` gives: the links are a\n * factory-time array, and whether a link carries a rule is fixed with it, so\n * the same hooks run in the same order on every render. The lint rule cannot\n * see a hook called through a member, so there is nothing for it to flag.\n */\nfunction useLinkFilters<TEntity extends Entity>(\n links: readonly {\n readonly useBaseFiltering?: (\n record: TEntity | undefined,\n ) => AnyFilterGroup | undefined;\n }[],\n record: TEntity | undefined,\n): (AnyFilterGroup | undefined)[] {\n return links.map(link => link.useBaseFiltering?.(record));\n}\n\nexport function makeEntityCrud<TEntity extends Entity, TAdapters>(\n entityConstructor: EntityConstructor<TEntity>,\n options: EntityCrudOptions<TAdapters, TEntity>,\n): EntityCrud<TEntity> {\n const {\n useAdapters,\n basePath,\n catalogKey,\n repository,\n hiddenFields = [],\n columns,\n toolbar,\n pageSize,\n initialFiltering,\n links = [],\n metadataSource: givenMetadataSource,\n metadata,\n useCases,\n write,\n delete: deletePolicy = 'confirm',\n facets,\n } = options;\n\n if (givenMetadataSource !== undefined && metadata !== undefined) {\n throw new Error(\n `${entityConstructor.name} was given both metadataSource and metadata; pass one`,\n );\n }\n // An adapter value, so it is resolved per render from the same `useAdapters()`\n // the records come from — the host's composition, never the caller's module.\n const metadataSourceOf = (adapters: TAdapters) =>\n metadata === undefined\n ? givenMetadataSource\n : (adapters[metadata] as EntityMetadataSource);\n\n // Through the service's own trust boundary rather than a second walk of the\n // tree: serialized the way a load request carries it, then coerced against\n // the entity's `filterable` allowlist exactly as a service coerces a query.\n // Whatever would answer `400` on the wire throws here instead, when the\n // screen is generated, naming the member.\n // An emptied group serializes to nothing and filters nothing, so there is\n // nothing to check.\n const initialRsql =\n initialFiltering === undefined ? '' : serializeRsql([initialFiltering]);\n if (initialRsql !== '') {\n coerceFiltering(entityConstructor, parseRsql(initialRsql));\n }\n\n const meta = extractMetaEntity(entityConstructor);\n if (meta.key !== catalogKey) {\n throw new Error(\n `${entityConstructor.name} declares key \"${String(meta.key)}\" but was given catalog key \"${catalogKey}\"`,\n );\n }\n // Read off `@entity()` rather than rebuilt from `catalogKey`. Both spellings\n // produce the same string today, and that is exactly the problem: a second\n // place that knows how an entity's catalog subtree is laid out is a second\n // place to fix when one moves. `MetaEntityOptions` makes them optional, so an\n // entity that never declared them fails here — where a screen is generated —\n // rather than on the render that first tries to title a tab with `undefined`.\n const { labelKey: entityLabelKey, pluralKey: entityPluralKey } = meta;\n if (entityLabelKey === undefined || entityPluralKey === undefined) {\n throw new Error(\n `${entityConstructor.name} must declare labelKey and pluralKey on @entity() to be generated`,\n );\n }\n // Narrowed once, for the closures below that TypeScript cannot follow.\n const labelKey: string = entityLabelKey;\n const pluralKey: string = entityPluralKey;\n\n // Computed once: a descriptor is a property of the class, so nothing about it\n // depends on the record being edited. `linkLabelProperty`/`linkSearchProperty`\n // are overridden here because a scalar foreign key's `@accessor()` cannot name\n // the target's members — it may not import the target at all.\n // The wire name, which is also what a pending flow's intent records and what\n // `entityQueryScopeFor` keys on — one derivation, so the two can never\n // disagree about which entity they mean.\n const entityName = envelopeEntityName(entityConstructor);\n const descriptors = describeEntityColumns(entityConstructor);\n /** The members a filter panel offers choices for, and so counts. */\n const facetMembers = descriptors\n .filter(\n descriptor =>\n descriptor.filterable &&\n (descriptor.type === 'enum' || descriptor.type === 'boolean'),\n )\n .map(({ name, key }) => ({ name, key }));\n /** A record as the reader knows it: its first shown member that is filled in. */\n const recordLabelOf = (record: TEntity | undefined): string | undefined => {\n const named = descriptors.find(descriptor => {\n if (descriptor.type === 'id' || hiddenFields.includes(descriptor.name))\n return false;\n const value = (record as Record<string, unknown> | undefined)?.[\n descriptor.name\n ];\n return value != null && String(value) !== '';\n });\n return named === undefined\n ? undefined\n : String((record as Record<string, unknown>)[named.name]);\n };\n const linkPlans = links.map(link => {\n const descriptor = descriptors.find(entry => entry.name === link.field);\n if (descriptor === undefined) {\n throw new Error(\n `${entityConstructor.name} has no member \"${link.field}\" for a link source`,\n );\n }\n return {\n ...link,\n descriptor: {\n ...descriptor,\n linkLabelProperty: link.labelProperty ?? TARGET_NAME_PROPERTY,\n linkSearchProperty: link.searchProperty ?? TARGET_NAME_PROPERTY,\n },\n };\n });\n\n function ListPage() {\n const adapters = useAdapters();\n // Every internal href carries the locale. An unprefixed one still resolves —\n // the middleware redirects it — but the visitor pays a round trip per click.\n const withLocale = useLocaleHref();\n\n const queryClient = useQueryClient();\n const scope = entityQueryScope(entityConstructor);\n const metadataSource = metadataSourceOf(adapters);\n const affordances = useEntityAffordances(entityConstructor, metadataSource);\n const renderLink = useCrudRenderLink(catalogKey);\n\n const pager = useDataLoading<TEntity, CrudContext>({\n uc: loadUCFactory<TEntity>(),\n ctx: crudContextOf(adapters, repository),\n // Scoped rather than left to the per-instance fallback, which is correct\n // but unshared: with the entity's own scope one invalidation refreshes\n // every page and filter of it, which is what a bulk run needs — and it is\n // the same prefix `useReactiveInvalidation`already targets, so a generated\n // list now also refreshes on a reactive change event.\n queryKey: scope,\n ...(pageSize === undefined ? {} : { initialPageSize: pageSize }),\n ...(initialFiltering === undefined ? {} : { initialFiltering }),\n });\n\n // A member that holds another record's id reads as that record's name.\n const linkLabel = useLinkLabels(\n linkPlans.map(plan => ({\n field: plan.field,\n entityConstructor: plan.entityConstructor,\n labelProperty: plan.descriptor.linkLabelProperty,\n ctx: crudContextOf(adapters, plan.repository),\n })),\n pager.items,\n );\n const linkColumns = linkPlans.map(plan => (\n <EntityColumn<TEntity>\n key={plan.field}\n field={plan.field}\n render={item => <LinkLabelCell label={linkLabel(plan.field, item)} />}\n />\n ));\n\n const facetCounts = useFacetCounts<TEntity>({\n ctx:\n facets === undefined\n ? undefined\n : (adapters[facets] as Context.Context<EntityFacetCounterTag>),\n members: facetMembers,\n filtering: pager.filtering,\n scope,\n });\n\n // Only when this caller may actually run something over a selection.\n //\n // Measured live: an `admin` holds `catalog-reference:*:read` and no\n // `retire`, so the service filters the verb out of `$metadata` — but the\n // selection column still rendered, offering a set that no action could be\n // taken on. A checkbox that can lead nowhere is worse than no checkbox: it\n // reads as a permission the user does not have.\n //\n // Decided from the served document rather than from the runner, because\n // the runner is a property of the *shell* (it knows the route) and the\n // grant is a property of the *caller*. The column therefore appears when\n // the document lands, which is the asynchrony serving affordances accepts\n // for every action surface.\n const canRunBulk =\n useCasesForSurface('bulk-bar', affordances.metadata?.useCases).length > 0;\n\n const verbs = verbsOf(\n useCases === undefined\n ? undefined\n : (adapters[useCases] as EntityUseCaseRunner),\n affordances.metadata?.useCases,\n );\n\n const bulk = useEntityBulk<TEntity>({\n run:\n canRunBulk && verbs !== undefined\n ? (key, selection) =>\n verbs.bulk(key, selection as EntitySelection<Entity>)\n : undefined,\n // A bulk write changed the rows underneath the listing, so the page is\n // re-read; the selection deliberately survives it (\"the selection\n // is still there afterwards\"), because the operator's next act is usually\n // to retry the failures or run a second verb on the same rows.\n onCompleted: () => {\n void queryClient.invalidateQueries({ queryKey: scope });\n },\n });\n\n // What a row's overflow menu runs, and the one place the list reports a\n // verb that failed.\n //\n // ⚠️ **A row verb and the form's are the same runner with different\n // arguments.** `EntityTable` hands back the whole record, because that is\n // what it has; the runner takes an id, because that is what a route needs.\n // The list has no error slot of its own, so a failure lands in the\n // table's own error region — the same one a failed page read uses.\n const rowVerb = useVerb(verbs, () => {\n void queryClient.invalidateQueries({ queryKey: scope });\n });\n // Called unconditionally and the *result* gated, the way the surfaces are\n // read in `EntityForm`: the name begins with `use`, so short-circuiting it\n // reads to `react-hooks/rules-of-hooks` as a conditional hook.\n const rowUseCases = useCasesForSurface(\n 'row-menu',\n affordances.metadata?.useCases,\n );\n const canRunRowUseCase = verbs !== undefined && rowUseCases.length > 0;\n\n const handleRowUseCase = canRunRowUseCase\n ? (key: string, item: TEntity) => {\n if (item.id == null) return;\n rowVerb.run(key, item.id);\n }\n : undefined;\n\n // The list's heading, and where focus lands when a save or a delete\n // brings the reader back here rather than falling to `<body>`.\n const heading = useRef<HTMLHeadingElement>(null);\n useFocusOnArrival(heading);\n const et = useT('entity');\n\n return (\n <div className=\"flex flex-col gap-s\">\n <h1\n ref={heading}\n tabIndex={-1}\n className=\"m-0 text-step-2 font-semibold text-content focus-ring\"\n >\n {et(pluralKey.replace(/^entity:/, ''))}\n </h1>\n <EntityTable\n entityConstructor={entityConstructor}\n {...pager}\n items={pager.items}\n totalItems={pager.totalItems}\n hrefFor={id => withLocale(`${basePath}/${String(id)}`)}\n newHref={withLocale(`${basePath}/${CATALOG_NEW_SLUG}`)}\n renderLink={renderLink}\n {...affordances}\n {...bulk.tableProps}\n onUseCase={handleRowUseCase}\n onRetry={pager.refetch}\n facets={facetCounts}\n error={syncFailure(rowVerb.verb) ?? pager.error}\n >\n {columns}\n {/* After the host's own: a host column for the same member wins. */}\n {linkColumns}\n {toolbar}\n </EntityTable>\n </div>\n );\n }\n\n /**\n * Dual-host: as a route it reads its slug from the URL and returns to the list\n * on save; in a workspace tab it takes the slug and the post-save action as\n * props.\n */\n function SingleViewPage({\n slug,\n onSaved,\n onDeleted,\n draft,\n }: EntityCrudSingleViewProps = {}) {\n const adapters = useAdapters();\n const metadataSource = metadataSourceOf(adapters);\n // The same served document the form reads its buttons from, so a key the\n // form hands back always names a verb in it.\n const affordances = useEntityAffordances(entityConstructor, metadataSource);\n const router = useRouter();\n const withLocale = useLocaleHref();\n const params = useParams<{ slug: string }>();\n const mounted = useMounted();\n const id = slugToEntityId(slug ?? params.slug);\n\n const ctx = crudContextOf(adapters, repository);\n\n const {\n entity,\n isLoading,\n error: loadError,\n reload,\n } = useEntityRecord<TEntity, CrudContext>({\n uc: getUCFactory<TEntity>(),\n ctx,\n id,\n });\n\n // Against the record as loaded, not the draft: the rule is about which\n // record this is, not what the operator has typed into it.\n const linkFilters = useLinkFilters(linkPlans, entity);\n\n // Rebuilt inline on every render on purpose: `useEntityLinkSource` holds\n // these in a ref and keeps them out of its query keys, precisely so a caller\n // does not have to memoise them.\n const linkSources: EntityCrudLinkSource[] = linkPlans.map(\n (plan, index) => ({\n field: plan.field,\n descriptor: plan.descriptor,\n config: {\n entityConstructor: plan.entityConstructor,\n loadUc: loadUCFactory(),\n getUc: getUCFactory(),\n ctx: crudContextOf(adapters, plan.repository),\n // The config's target is erased to `Entity`, and the host's filter to\n // `any`; the two meet here, where neither type is the real target's.\n baseFiltering: linkFilters[index] as FilterGroup<Entity> | undefined,\n },\n }),\n );\n\n // Inside a workspace tab, \"back to the list\" is the list's tab, not a URL\n // that would leave the workspace. A host's own callbacks still win.\n const host = useEntityNavHost();\n const renderLink = useCrudRenderLink(catalogKey);\n const queryClient = useQueryClient();\n // The list this page returns to has its page cached, and it is no longer\n // true. Invalidated rather than patched: the service is the authority on\n // the row it stored.\n //\n // ⚠️ Invisible while every Open was a document load, which threw the cache\n // away anyway (#20): the first client-side navigation back to the list\n // showed the record as it was before the save.\n const refreshList = () =>\n queryClient.invalidateQueries({\n queryKey: entityQueryScope(entityConstructor),\n });\n const toList = () =>\n host === undefined\n ? router.push(withLocale(basePath))\n : host.toList(catalogKey);\n const afterSave = onSaved ?? toList;\n const afterDelete = onDeleted ?? toList;\n\n // Through the host's writer when it named one, which answers both settle\n // modes; otherwise through the repository, where every write settles.\n const writer =\n write === undefined ? undefined : (adapters[write] as EntityWriter);\n\n // The draft is spent once the write *commits*, and only here is that known:\n // `useEntityForm` neither fetches nor saves, so it cannot clear its own.\n // A failed write — or a failed flow — deliberately keeps the draft and the\n // form: the edit is still the user's only copy of what they typed.\n //\n // ⚠️ A flow can complete after the operator left this page, so leaving it\n // is guarded on still being here: a navigation from a form nobody is\n // looking at would pull them away from wherever they went.\n const saveMutation = useOptimisticMutation<TEntity, TEntity>({\n write: next =>\n writer === undefined\n ? Effect.map(\n Effect.provide(\n saveUCFactory<TEntity>(),\n ctx.pipe(Context.add(EntityTag, next)),\n ),\n settled,\n )\n : writer.save(next),\n intent: () => ({ entity: entityName, write: 'save' }),\n confirm: () => {\n draft?.clear();\n void refreshList();\n if (mounted.current) afterSave();\n },\n });\n const deleteMutation = useOptimisticMutation<EntityId, void>({\n write: target =>\n writer === undefined\n ? Effect.as(\n Effect.provide(\n deleteUCFactory<TEntity>(),\n ctx.pipe(Context.add(EntityIdTag, target)),\n ),\n settled(undefined),\n )\n : writer.delete(target),\n intent: () => ({ entity: entityName, write: 'delete' }),\n confirm: () => {\n draft?.clear();\n void refreshList();\n if (mounted.current) afterDelete();\n },\n });\n\n const handleSave = async (next: TEntity) => {\n const result = await saveMutation.mutate(next).catch(() => undefined);\n // Failed, or pending: the form stays, and the mutation says which. A\n // pending write leaves through the mutation's `confirm`, once its flow\n // completed.\n if (result?._tag !== 'settled') return;\n draft?.clear();\n void refreshList();\n // Said in the toast region every route shares, so it survives the\n // navigation that follows (ADR 0028).\n toasts?.show({\n tone: 'success',\n message: ct('state.saved', {\n object: recordNoun(next),\n }),\n });\n afterSave();\n };\n\n const toasts = useToasts();\n const ct = useT('controls');\n const et = useT('entity');\n /** What an announcement names: the record, or the entity for a blank one. */\n const recordNoun = (record: TEntity | undefined) =>\n recordLabelOf(record) ?? et(labelKey.replace(/^entity:/, ''));\n // The breadcrumb for this page's segment names the record, never its id:\n // \"Nuevo\" for a create, the record once it has loaded.\n useBreadcrumbLabel(\n slug ?? params.slug,\n id == null ? ct('form.new') : entity && recordNoun(entity),\n );\n /**\n * Saves a deleted record back under its id: what Undo runs under the\n * `undo` policy.\n */\n const restore = (record: TEntity) =>\n Effect.runPromise(\n writer === undefined\n ? Effect.asVoid(\n Effect.provide(\n saveUCFactory<TEntity>(),\n ctx.pipe(Context.add(EntityTag, record)),\n ),\n )\n : Effect.asVoid(writer.save(record)),\n ).then(\n () => refreshList(),\n (failure: unknown) => {\n toasts?.show({ tone: 'failure', failure: asFailure(failure) });\n },\n );\n\n const handleDelete = async () => {\n const snapshot = entity;\n const result = await deleteMutation.mutate(id).catch(() => undefined);\n if (result?._tag !== 'settled') return;\n draft?.clear();\n void refreshList();\n // Said once, in the toast region every route shares, so it survives the\n // navigation back to the list.\n const object = recordNoun(snapshot);\n const message = ct('confirm.deleted', { object });\n if (deletePolicy === 'undo' && snapshot !== undefined)\n toasts?.show({\n tone: 'undo',\n message,\n action: {\n label: ct('confirm.undo'),\n onAction: () => void restore(snapshot),\n },\n });\n else toasts?.show({ tone: 'success', message });\n afterDelete();\n };\n\n /**\n * An `entity`-bound verb, on the record being shown.\n *\n * It **reloads** — once the verb took effect, which for one the server\n * handed to a flow is when the flow completed — rather than patching what it has: the service decides the\n * resulting state — a `publish` may land on `published` from four different\n * places — and a client that assumed the new value would show the wrong one\n * the first time the rule changed. `id == null` means the create form,\n * where there is no record to act on and the form renders no verbs anyway.\n *\n * ⚠️ The rejection is **caught and shown**, never left to the promise.\n * `EntityForm`'s `onUseCase` returns `void`, so an uncaught rejection here\n * reaches the console and nothing else — measured on an offering refusing\n * `unpublish` from `draft`: the service answered `409` with a coded body,\n * the record correctly did not move, and the operator saw a button that\n * appeared to do nothing at all.\n */\n const verbs = verbsOf(\n useCases === undefined\n ? undefined\n : (adapters[useCases] as EntityUseCaseRunner),\n affordances.metadata?.useCases,\n );\n const recordVerb = useVerb(verbs, () => void reload());\n const handleUseCase =\n verbs === undefined || id == null\n ? undefined\n : (key: string) => recordVerb.run(key, id);\n\n return (\n <EntityCrudForm<TEntity>\n // Remounts (and reseeds the fields) once the record arrives.\n key={String(entity?.id ?? CATALOG_NEW_SLUG)}\n entityConstructor={entityConstructor}\n catalogKey={catalogKey}\n metadataSource={metadataSource}\n hiddenFields={hiddenFields}\n links={linkSources}\n entity={entity}\n isLoading={isLoading}\n isSaving={saveMutation.status === 'running'}\n isPending={[saveMutation, deleteMutation, recordVerb.verb].some(\n mutation => mutation.status === 'pending',\n )}\n isDeleting={deleteMutation.status === 'running'}\n error={\n loadError ??\n syncFailure(saveMutation) ??\n syncFailure(deleteMutation) ??\n syncFailure(recordVerb.verb)\n }\n onSave={handleSave}\n onRetry={loadError === undefined ? undefined : reload}\n onDelete={id == null ? undefined : handleDelete}\n deletePolicy={deletePolicy}\n onUseCase={handleUseCase}\n backHref={withLocale(basePath)}\n renderLink={renderLink}\n draft={draft}\n />\n );\n }\n\n return {\n entityConstructor,\n entityKey: catalogKey,\n entityLabelKey,\n entityPluralKey,\n basePath,\n ListPage,\n SingleViewPage,\n };\n}\n"],"names":["deleteUCFactory","EntityIdTag","EntityTag","getUCFactory","loadUCFactory","saveUCFactory","coerceFiltering","describeEntityColumns","envelopeEntityName","extractMetaEntity","Internal","isFailure","parseRsql","serializeRsql","settled","EntityColumn","EntityTable","useCasesForSurface","useFocusOnArrival","useT","useToasts","entityQueryScope","useDataLoading","useEntityRecord","useFacetCounts","useOptimisticMutation","useQueryClient","Cause","Context","Effect","Exit","useParams","useRouter","useEffect","useRef","useBreadcrumbLabel","useLocaleHref","useEntityNavHost","EntityCrudForm","CATALOG_NEW_SLUG","slugToEntityId","useCrudRenderLink","useEntityAffordances","useEntityBulk","LinkLabelCell","useLinkLabels","TARGET_NAME_PROPERTY","crudContextOf","adapters","repository","asFailure","failure","syncFailure","mutation","status","flowId","undefined","verbsOf","runner","served","descriptor","key","find","candidate","run","id","bulk","selection","runPromiseExit","then","exit","isSuccess","value","Promise","reject","squash","cause","useVerb","verbs","done","verb","write","confirm","mutate","result","_tag","useMounted","mounted","current","useLinkFilters","links","record","map","link","useBaseFiltering","makeEntityCrud","entityConstructor","options","useAdapters","basePath","catalogKey","hiddenFields","columns","toolbar","pageSize","initialFiltering","metadataSource","givenMetadataSource","metadata","useCases","delete","deletePolicy","facets","Error","name","metadataSourceOf","initialRsql","meta","String","labelKey","entityLabelKey","pluralKey","entityPluralKey","entityName","descriptors","facetMembers","filter","filterable","type","recordLabelOf","named","includes","linkPlans","entry","field","linkLabelProperty","labelProperty","linkSearchProperty","searchProperty","ListPage","affordances","withLocale","queryClient","scope","renderLink","pager","uc","ctx","queryKey","initialPageSize","linkLabel","plan","items","linkColumns","render","item","label","facetCounts","members","filtering","canRunBulk","length","onCompleted","invalidateQueries","rowVerb","rowUseCases","canRunRowUseCase","handleRowUseCase","heading","et","div","className","h1","ref","tabIndex","replace","totalItems","hrefFor","newHref","tableProps","onUseCase","onRetry","refetch","error","SingleViewPage","slug","onSaved","onDeleted","draft","loadError","router","params","entity","isLoading","reload","linkFilters","linkSources","index","config","loadUc","getUc","baseFiltering","host","refreshList","toList","push","afterSave","afterDelete","writer","saveMutation","next","provide","pipe","add","save","intent","clear","deleteMutation","target","as","handleSave","catch","toasts","show","tone","message","ct","object","recordNoun","restore","runPromise","asVoid","handleDelete","snapshot","action","onAction","recordVerb","handleUseCase","isSaving","isPending","some","isDeleting","onSave","onDelete","backHref","entityKey"],"mappings":"AAAA;;;AAEA,SACEA,eAAe,EAEfC,WAAW,EAEXC,SAAS,EACTC,YAAY,EACZC,aAAa,EACbC,aAAa,QACR,oBAAoB;AAC3B,SACEC,eAAe,EACfC,qBAAqB,EASrBC,kBAAkB,EAClBC,iBAAiB,EAEjBC,QAAQ,EACRC,SAAS,EACTC,SAAS,EACTC,aAAa,EACbC,OAAO,QA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Z4C,OAAOA;WA1BFtE,gBAAO0E,0BAAAA,OAAQ/H,EAAE,oBAAI1B;IA6BhC;IAEA,OAAO;QACLyD;QACAqJ,WAAWjJ;QACXoB;QACAE;QACAvB;QACAwC;QACA6C;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/crud/make-entity-crud.tsx"],"sourcesContent":["'use client';\n\nimport {\n deleteUCFactory,\n type EntityFacetCounterTag,\n EntityIdTag,\n type EntityRepositoryTag,\n EntityTag,\n getUCFactory,\n loadUCFactory,\n saveUCFactory,\n} from '@entifix/business';\nimport {\n coerceFiltering,\n describeEntityColumns,\n type EntifixFailure,\n type Entity,\n type EntityConstructor,\n type EntityId,\n type EntityMetadataSource,\n type EntitySelection,\n type EntityUseCaseRunner,\n type EntityWriter,\n envelopeEntityName,\n extractMetaEntity,\n type FilterGroup,\n Internal,\n isFailure,\n parseRsql,\n serializeRsql,\n settled,\n type UseCaseDescriptor,\n} from '@entifix/core';\nimport {\n EntityTable,\n useCasesForSurface,\n useFocusOnArrival,\n useRecordLabel,\n useT,\n useToasts,\n useTranslateKey,\n} from '@entifix/react-controls';\nimport {\n entityQueryScope,\n type OptimisticMutation,\n useDataLoading,\n useEntityRecord,\n useFacetCounts,\n useOptimisticMutation,\n} from '@entifix/react-integration';\nimport { useQueryClient } from '@tanstack/react-query';\nimport { Cause, Context, Effect, Exit } from 'effect';\nimport { useParams, useRouter, useSearchParams } from 'next/navigation';\nimport { useEffect, useId, useMemo, useRef } from 'react';\n\nimport { useBreadcrumbLabel } from '../back-office/breadcrumb-labels.js';\nimport { useLocaleHref } from '../i18n/index.js';\nimport { useEntityNavHost } from '../workspace/entity-nav.js';\nimport { EntityCrudForm } from './entity-crud-form.js';\nimport type {\n AnyFilterGroup,\n EntityCrud,\n EntityCrudLinkSource,\n EntityCrudOptions,\n EntityCrudRelatedListProps,\n EntityCrudSingleViewProps,\n} from './make-entity-crud.types.js';\nimport {\n PREFILL_PARAM,\n readPrefill,\n RecordRegions,\n useRegion,\n} from './regions.js';\nimport { planRelated, useRelatedColumns } from './related-columns.js';\nimport { CATALOG_NEW_SLUG, slugToEntityId } from './slug.js';\nimport { useCrudRenderLink } from './use-crud-render-link.js';\nimport { useEntityAffordances } from './use-entity-affordances.js';\nimport { useEntityBulk } from './use-entity-bulk.js';\n\n/** What a picker defaults to reading off its target. */\nconst TARGET_NAME_PROPERTY = 'name';\n\n/** A prefilled create with no host draft store keeps nothing between visits. */\nconst ignoreDraft = () => undefined;\n\n/**\n * What the generated pages' use-cases run against: one repository adapter.\n * Exported because a hand-built screen — a wizard reading records and\n * resolving pickers — runs against exactly the same.\n */\nexport type CrudContext = EntityRepositoryTag;\n\n/**\n * One repository adapter, by its key, as the context the use-cases run\n * against.\n *\n * The cast is the price of naming adapters by key: `AdapterKey` narrows which\n * names may be *offered*, but TypeScript will not carry that narrowing through\n * an index access on a generic record.\n */\nexport function crudContextOf<TAdapters>(\n adapters: TAdapters,\n repository: keyof TAdapters,\n): Context.Context<CrudContext> {\n return adapters[repository] as Context.Context<EntityRepositoryTag>;\n}\n\n/**\n * Builds the list page and the single-record page for one entity.\n *\n * Every catalog entity used to cost ~10 files and ~300 lines whose only variable\n * was a class name: two organisms with a `.types.ts` each, two client pages, two\n * route files. The route files stay (Next needs a module per path); everything\n * between them is derived from the entity's own metadata, so a new reference\n * entity is this call plus a nav entry.\n *\n * Two things are checked here rather than at the call site, because both fail\n * silently otherwise. The catalog key must be the entity's own `@entity({ key })`\n * — they are the same string by convention, and a drifted one titles the form\n * after a different entity in a way only a reader of both catalogs would catch.\n * And a `links` entry must name a real member — a picker aimed at nothing renders\n * identically to a read-only field.\n *\n * **Serves compile-time `@entity()` classes only.** Operator reference data ships\n * with the code, so making this spec-driven would trade type safety for nothing;\n * a vendor-authored `EntitySpecification` renders through a separate path.\n */\n/**\n * A rejected write, as something the form's error slot can render.\n *\n * A typed failure is kept as it is: `useErrorMessage` translates its own code,\n * a business refusal and an outage alike. Anything else is a bug that reached\n * the screen, and is shown as `Internal` — never with its own text, which\n * nobody wrote for a user.\n */\nfunction asFailure(failure: unknown): EntifixFailure {\n return isFailure(failure) ? failure : new Internal();\n}\n\n/**\n * What a write failed with *synchronously* — before any flow took it — or\n * `undefined`. A flow's own failure is toasted by the `PendingFlowsProvider`\n * that settles it, so showing it in the error slot too would tell the operator\n * twice.\n */\nfunction syncFailure(\n mutation: OptimisticMutation<never, unknown>,\n): EntifixFailure | undefined {\n return mutation.status === 'failed' && mutation.flowId === undefined\n ? asFailure(mutation.failure)\n : undefined;\n}\n\n/**\n * A runner's verbs, looked up by the key the served `$metadata` named. A\n * single verb answers either settle mode, so it is run through the optimistic\n * API; a bulk run reports per row and is awaited as a promise whose rejection\n * carries the failure itself.\n */\nfunction verbsOf(\n runner: EntityUseCaseRunner | undefined,\n served: readonly UseCaseDescriptor[] | undefined,\n) {\n if (runner === undefined) return undefined;\n // The key always comes from the served document, so it names a verb in it.\n const descriptor = (key: string) =>\n served?.find(candidate => candidate.key === key) as UseCaseDescriptor;\n return {\n run: (key: string, id: EntityId) => runner.run(descriptor(key), id),\n bulk: (key: string, selection: EntitySelection<Entity>) =>\n Effect.runPromiseExit(runner.bulk(descriptor(key), selection)).then(\n exit =>\n Exit.isSuccess(exit)\n ? exit.value\n : Promise.reject(Cause.squash(exit.cause)),\n ),\n };\n}\n\ntype Verbs = NonNullable<ReturnType<typeof verbsOf>>;\n\n/**\n * One verb on one record, through the optimistic API: `done` runs once the\n * verb took effect — at once when it settled, or when the flow it was handed\n * to completed.\n */\nfunction useVerb(verbs: Verbs | undefined, done: () => void) {\n const verb = useOptimisticMutation<\n { readonly key: string; readonly id: EntityId },\n unknown\n >({\n // Only ever sent from a handler that exists because `verbs` does.\n write: ({ key, id }) => (verbs as Verbs).run(key, id),\n confirm: done,\n });\n const run = (key: string, id: EntityId) => {\n void verb.mutate({ key, id }).then(\n result => {\n if (result._tag === 'settled') done();\n },\n // Shown through `syncFailure`, from the mutation's own state.\n () => undefined,\n );\n };\n return { verb, run };\n}\n\n/** Whether the component is still mounted: a flow can settle after it left. */\nfunction useMounted() {\n const mounted = useRef(true);\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n };\n }, []);\n return mounted;\n}\n\n/**\n * Runs each link's `useBaseFiltering` against the record being edited, in link\n * order, with `undefined` for a link that declares none.\n *\n * Legal for the reason `useEntityLinkSources` gives: the links are a\n * factory-time array, and whether a link carries a rule is fixed with it, so\n * the same hooks run in the same order on every render. The lint rule cannot\n * see a hook called through a member, so there is nothing for it to flag.\n */\nfunction useLinkFilters<TEntity extends Entity>(\n links: readonly {\n readonly useBaseFiltering?: (\n record: TEntity | undefined,\n ) => AnyFilterGroup | undefined;\n }[],\n record: TEntity | undefined,\n): (AnyFilterGroup | undefined)[] {\n return links.map(link => link.useBaseFiltering?.(record));\n}\n\nexport function makeEntityCrud<TEntity extends Entity, TAdapters>(\n entityConstructor: EntityConstructor<TEntity>,\n options: EntityCrudOptions<TAdapters, TEntity>,\n): EntityCrud<TEntity> {\n const {\n useAdapters,\n basePath,\n catalogKey,\n repository,\n hiddenFields = [],\n columns,\n toolbar,\n pageSize,\n initialFiltering,\n links = [],\n related = [],\n regions,\n metadataSource: givenMetadataSource,\n metadata,\n useCases,\n write,\n delete: deletePolicy = 'confirm',\n facets,\n } = options;\n\n if (givenMetadataSource !== undefined && metadata !== undefined) {\n throw new Error(\n `${entityConstructor.name} was given both metadataSource and metadata; pass one`,\n );\n }\n // An adapter value, so it is resolved per render from the same `useAdapters()`\n // the records come from — the host's composition, never the caller's module.\n const metadataSourceOf = (adapters: TAdapters) =>\n metadata === undefined\n ? givenMetadataSource\n : (adapters[metadata] as EntityMetadataSource);\n\n // Through the service's own trust boundary rather than a second walk of the\n // tree: serialized the way a load request carries it, then coerced against\n // the entity's `filterable` allowlist exactly as a service coerces a query.\n // Whatever would answer `400` on the wire throws here instead, when the\n // screen is generated, naming the member.\n // An emptied group serializes to nothing and filters nothing, so there is\n // nothing to check.\n const initialRsql =\n initialFiltering === undefined ? '' : serializeRsql([initialFiltering]);\n if (initialRsql !== '') {\n coerceFiltering(entityConstructor, parseRsql(initialRsql));\n }\n\n const meta = extractMetaEntity(entityConstructor);\n if (meta.key !== catalogKey) {\n throw new Error(\n `${entityConstructor.name} declares key \"${String(meta.key)}\" but was given catalog key \"${catalogKey}\"`,\n );\n }\n // Read off `@entity()` rather than rebuilt from `catalogKey`. Both spellings\n // produce the same string today, and that is exactly the problem: a second\n // place that knows how an entity's catalog subtree is laid out is a second\n // place to fix when one moves. `MetaEntityOptions` makes them optional, so an\n // entity that never declared them fails here — where a screen is generated —\n // rather than on the render that first tries to title a tab with `undefined`.\n const { labelKey: entityLabelKey, pluralKey: entityPluralKey } = meta;\n if (entityLabelKey === undefined || entityPluralKey === undefined) {\n throw new Error(\n `${entityConstructor.name} must declare labelKey and pluralKey on @entity() to be generated`,\n );\n }\n // Narrowed once, for the closures below that TypeScript cannot follow.\n const pluralKey: string = entityPluralKey;\n\n // Computed once: a descriptor is a property of the class, so nothing about it\n // depends on the record being edited. `linkLabelProperty`/`linkSearchProperty`\n // are overridden here because a scalar foreign key's `@accessor()` cannot name\n // the target's members — it may not import the target at all.\n // The wire name, which is also what a pending flow's intent records and what\n // `entityQueryScopeFor` keys on — one derivation, so the two can never\n // disagree about which entity they mean.\n const entityName = envelopeEntityName(entityConstructor);\n const descriptors = describeEntityColumns(entityConstructor);\n /** The members a filter panel offers choices for, and so counts. */\n const facetMembers = descriptors\n .filter(\n descriptor =>\n descriptor.filterable &&\n (descriptor.type === 'enum' || descriptor.type === 'boolean'),\n )\n .map(({ name, key }) => ({ name, key }));\n const relatedPlans = planRelated(\n entityConstructor as EntityConstructor<Entity>,\n descriptors,\n related,\n );\n const linkPlans = links.map(link => {\n const descriptor = descriptors.find(entry => entry.name === link.field);\n if (descriptor === undefined) {\n throw new Error(\n `${entityConstructor.name} has no member \"${link.field}\" for a link source`,\n );\n }\n return {\n ...link,\n descriptor: {\n ...descriptor,\n linkLabelProperty: link.labelProperty ?? TARGET_NAME_PROPERTY,\n linkSearchProperty: link.searchProperty ?? TARGET_NAME_PROPERTY,\n },\n };\n });\n\n /**\n * The generated list itself — the table, its reads, its verbs — shared by the\n * list page and by a related region on another record's page. A region holds\n * it to a fixed filter that is not a removable chip and keeps its pager in\n * component state, never in the URL.\n */\n function ListBody({\n baseFiltering,\n newHref: givenNewHref,\n listPageSize = pageSize,\n listInitialFiltering,\n onVerbSettled,\n }: {\n baseFiltering?: FilterGroup<TEntity>;\n newHref?: string;\n listPageSize?: number;\n listInitialFiltering?: FilterGroup<TEntity>;\n onVerbSettled?: () => void;\n }) {\n const adapters = useAdapters();\n // Every internal href carries the locale. An unprefixed one still resolves —\n // the middleware redirects it — but the visitor pays a round trip per click.\n const withLocale = useLocaleHref();\n\n const queryClient = useQueryClient();\n const scope = entityQueryScope(entityConstructor);\n const metadataSource = metadataSourceOf(adapters);\n const affordances = useEntityAffordances(entityConstructor, metadataSource);\n const renderLink = useCrudRenderLink(catalogKey);\n\n const pager = useDataLoading<TEntity, CrudContext>({\n uc: loadUCFactory<TEntity>(),\n ctx: crudContextOf(adapters, repository),\n // Scoped rather than left to the per-instance fallback, which is correct\n // but unshared: with the entity's own scope one invalidation refreshes\n // every page and filter of it, which is what a bulk run needs — and it is\n // the same prefix `useReactiveInvalidation`already targets, so a generated\n // list now also refreshes on a reactive change event.\n queryKey: scope,\n ...(listPageSize === undefined ? {} : { initialPageSize: listPageSize }),\n ...(listInitialFiltering === undefined\n ? {}\n : { initialFiltering: listInitialFiltering }),\n ...(baseFiltering === undefined ? {} : { baseFiltering }),\n });\n\n // Values that live in another entity, one read per column per page.\n const relatedColumns = useRelatedColumns<TAdapters, TEntity>(\n relatedPlans,\n pager.items,\n plan => crudContextOf(adapters, plan.repository),\n );\n\n const facetCounts = useFacetCounts<TEntity>({\n ctx:\n facets === undefined\n ? undefined\n : (adapters[facets] as Context.Context<EntityFacetCounterTag>),\n members: facetMembers,\n filtering: pager.filtering,\n scope,\n });\n\n // Only when this caller may actually run something over a selection.\n //\n // Measured live: an `admin` holds `catalog-reference:*:read` and no\n // `retire`, so the service filters the verb out of `$metadata` — but the\n // selection column still rendered, offering a set that no action could be\n // taken on. A checkbox that can lead nowhere is worse than no checkbox: it\n // reads as a permission the user does not have.\n //\n // Decided from the served document rather than from the runner, because\n // the runner is a property of the *shell* (it knows the route) and the\n // grant is a property of the *caller*. The column therefore appears when\n // the document lands, which is the asynchrony serving affordances accepts\n // for every action surface.\n const canRunBulk =\n useCasesForSurface('bulk-bar', affordances.metadata?.useCases).length > 0;\n\n const verbs = verbsOf(\n useCases === undefined\n ? undefined\n : (adapters[useCases] as EntityUseCaseRunner),\n affordances.metadata?.useCases,\n );\n\n const bulk = useEntityBulk<TEntity>({\n run:\n canRunBulk && verbs !== undefined\n ? (key, selection) =>\n verbs.bulk(key, selection as EntitySelection<Entity>)\n : undefined,\n // A bulk write changed the rows underneath the listing, so the page is\n // re-read; the selection deliberately survives it (\"the selection\n // is still there afterwards\"), because the operator's next act is usually\n // to retry the failures or run a second verb on the same rows.\n onCompleted: () => {\n void queryClient.invalidateQueries({ queryKey: scope });\n },\n });\n\n // What a row's overflow menu runs, and the one place the list reports a\n // verb that failed.\n //\n // ⚠️ **A row verb and the form's are the same runner with different\n // arguments.** `EntityTable` hands back the whole record, because that is\n // what it has; the runner takes an id, because that is what a route needs.\n // The list has no error slot of its own, so a failure lands in the\n // table's own error region — the same one a failed page read uses.\n const rowVerb = useVerb(verbs, () => {\n void queryClient.invalidateQueries({ queryKey: scope });\n onVerbSettled?.();\n });\n // Called unconditionally and the *result* gated, the way the surfaces are\n // read in `EntityForm`: the name begins with `use`, so short-circuiting it\n // reads to `react-hooks/rules-of-hooks` as a conditional hook.\n const rowUseCases = useCasesForSurface(\n 'row-menu',\n affordances.metadata?.useCases,\n );\n const canRunRowUseCase = verbs !== undefined && rowUseCases.length > 0;\n\n const handleRowUseCase = canRunRowUseCase\n ? (key: string, item: TEntity) => {\n if (item.id == null) return;\n rowVerb.run(key, item.id);\n }\n : undefined;\n\n return (\n <EntityTable\n entityConstructor={entityConstructor}\n {...pager}\n items={pager.items}\n totalItems={pager.totalItems}\n hrefFor={id => withLocale(`${basePath}/${String(id)}`)}\n newHref={withLocale(givenNewHref ?? `${basePath}/${CATALOG_NEW_SLUG}`)}\n renderLink={renderLink}\n {...affordances}\n {...bulk.tableProps}\n onUseCase={handleRowUseCase}\n onRetry={pager.refetch}\n facets={facetCounts}\n error={syncFailure(rowVerb.verb) ?? pager.error}\n >\n {columns}\n {relatedColumns}\n {/* After the host's own: a host column for the same member wins. */}\n {toolbar}\n </EntityTable>\n );\n }\n\n function ListPage() {\n // The list's heading, and where focus lands when a save or a delete\n // brings the reader back here rather than falling to `<body>`.\n const heading = useRef<HTMLHeadingElement>(null);\n useFocusOnArrival(heading);\n const et = useT('entity');\n\n return (\n <div className=\"flex flex-col gap-s\">\n <h1\n ref={heading}\n tabIndex={-1}\n className=\"m-0 text-step-2 font-semibold text-content focus-ring\"\n >\n {et(pluralKey.replace(/^entity:/, ''))}\n </h1>\n <ListBody\n {...(initialFiltering === undefined\n ? {}\n : { listInitialFiltering: initialFiltering })}\n />\n </div>\n );\n }\n\n /**\n * This entity's records that refer to another record, as a region of that\n * record's page\n * ([ADR 0030](../../../../../../docs/adr/0030-a-reference-names-its-target-through-the-owners-read-port.md)):\n * the generated list held to `filtering`, which is fixed and shown as no\n * chip, under its own `h2`, with its own states and its own writes. A verb\n * that settles inside it moves focus to that heading; nothing else on the\n * page is re-read or touched. `prefill` names the members a \"New\" from here\n * opens already set — the parent record's id.\n */\n function RelatedList({\n filtering,\n labelKey: headingKey,\n prefill,\n newHref,\n pageSize: regionPageSize,\n }: EntityCrudRelatedListProps<TEntity>) {\n const headingRef = useRef<HTMLHeadingElement>(null);\n const id = useId();\n const heading = useTranslateKey()(headingKey);\n useRegion(id, heading);\n const query = new URLSearchParams(\n Object.entries(prefill ?? {}).map(([member, value]): [string, string] => [\n `${PREFILL_PARAM}${member}`,\n value,\n ]),\n ).toString();\n return (\n <section\n id={id}\n aria-labelledby={`${id}-heading`}\n className=\"flex flex-col gap-s\"\n >\n <h2\n id={`${id}-heading`}\n ref={headingRef}\n tabIndex={-1}\n className=\"m-0 text-step-1 font-semibold text-content focus-ring\"\n >\n {heading}\n </h2>\n <ListBody\n baseFiltering={filtering}\n newHref={\n newHref ??\n `${basePath}/${CATALOG_NEW_SLUG}${query === '' ? '' : `?${query}`}`\n }\n {...(regionPageSize === undefined\n ? {}\n : { listPageSize: regionPageSize })}\n onVerbSettled={() => headingRef.current?.focus()}\n />\n </section>\n );\n }\n\n /**\n * Dual-host: as a route it reads its slug from the URL and returns to the list\n * on save; in a workspace tab it takes the slug and the post-save action as\n * props.\n */\n function SingleViewPage({\n slug,\n onSaved,\n onDeleted,\n draft,\n }: EntityCrudSingleViewProps = {}) {\n const adapters = useAdapters();\n const metadataSource = metadataSourceOf(adapters);\n // The same served document the form reads its buttons from, so a key the\n // form hands back always names a verb in it.\n const affordances = useEntityAffordances(entityConstructor, metadataSource);\n const router = useRouter();\n const withLocale = useLocaleHref();\n const params = useParams<{ slug: string }>();\n const mounted = useMounted();\n const id = slugToEntityId(slug ?? params.slug);\n\n // A create opened from a related region starts with the parent record set:\n // `?prefill.<member>=<value>`, layered under any draft the host restores.\n const searchParams = useSearchParams();\n const prefill =\n id == null ? readPrefill(searchParams, descriptors) : undefined;\n const prefillKey = prefill === undefined ? '' : JSON.stringify(prefill);\n const formDraft = useMemo(\n () =>\n prefill === undefined\n ? draft\n : {\n draft: { ...prefill, ...draft?.draft },\n save: draft?.save ?? ignoreDraft,\n clear: draft?.clear ?? ignoreDraft,\n },\n // Keyed on the values, not the object a render builds them into.\n [draft, prefillKey],\n );\n\n const ctx = crudContextOf(adapters, repository);\n\n const {\n entity,\n isLoading,\n error: loadError,\n reload,\n } = useEntityRecord<TEntity, CrudContext>({\n uc: getUCFactory<TEntity>(),\n ctx,\n id,\n });\n\n // Against the record as loaded, not the draft: the rule is about which\n // record this is, not what the operator has typed into it.\n const linkFilters = useLinkFilters(linkPlans, entity);\n\n // Rebuilt inline on every render on purpose: `useEntityLinkSource` holds\n // these in a ref and keeps them out of its query keys, precisely so a caller\n // does not have to memoise them.\n const linkSources: EntityCrudLinkSource[] = linkPlans.map(\n (plan, index) => ({\n field: plan.field,\n descriptor: plan.descriptor,\n config: {\n entityConstructor: plan.entityConstructor,\n loadUc: loadUCFactory(),\n getUc: getUCFactory(),\n ctx: crudContextOf(adapters, plan.repository),\n // The config's target is erased to `Entity`, and the host's filter to\n // `any`; the two meet here, where neither type is the real target's.\n baseFiltering: linkFilters[index] as FilterGroup<Entity> | undefined,\n },\n }),\n );\n\n // Inside a workspace tab, \"back to the list\" is the list's tab, not a URL\n // that would leave the workspace. A host's own callbacks still win.\n const host = useEntityNavHost();\n const renderLink = useCrudRenderLink(catalogKey);\n const queryClient = useQueryClient();\n // The list this page returns to has its page cached, and it is no longer\n // true. Invalidated rather than patched: the service is the authority on\n // the row it stored.\n //\n // ⚠️ Invisible while every Open was a document load, which threw the cache\n // away anyway (#20): the first client-side navigation back to the list\n // showed the record as it was before the save.\n const refreshList = () =>\n queryClient.invalidateQueries({\n queryKey: entityQueryScope(entityConstructor),\n });\n const toList = () =>\n host === undefined\n ? router.push(withLocale(basePath))\n : host.toList(catalogKey);\n const afterSave = onSaved ?? toList;\n const afterDelete = onDeleted ?? toList;\n\n // Through the host's writer when it named one, which answers both settle\n // modes; otherwise through the repository, where every write settles.\n const writer =\n write === undefined ? undefined : (adapters[write] as EntityWriter);\n\n // The draft is spent once the write *commits*, and only here is that known:\n // `useEntityForm` neither fetches nor saves, so it cannot clear its own.\n // A failed write — or a failed flow — deliberately keeps the draft and the\n // form: the edit is still the user's only copy of what they typed.\n //\n // ⚠️ A flow can complete after the operator left this page, so leaving it\n // is guarded on still being here: a navigation from a form nobody is\n // looking at would pull them away from wherever they went.\n const saveMutation = useOptimisticMutation<TEntity, TEntity>({\n write: next =>\n writer === undefined\n ? Effect.map(\n Effect.provide(\n saveUCFactory<TEntity>(),\n ctx.pipe(Context.add(EntityTag, next)),\n ),\n settled,\n )\n : writer.save(next),\n intent: () => ({ entity: entityName, write: 'save' }),\n confirm: () => {\n draft?.clear();\n void refreshList();\n if (mounted.current) afterSave();\n },\n });\n const deleteMutation = useOptimisticMutation<EntityId, void>({\n write: target =>\n writer === undefined\n ? Effect.as(\n Effect.provide(\n deleteUCFactory<TEntity>(),\n ctx.pipe(Context.add(EntityIdTag, target)),\n ),\n settled(undefined),\n )\n : writer.delete(target),\n intent: () => ({ entity: entityName, write: 'delete' }),\n confirm: () => {\n draft?.clear();\n void refreshList();\n if (mounted.current) afterDelete();\n },\n });\n\n const handleSave = async (next: TEntity) => {\n const result = await saveMutation.mutate(next).catch(() => undefined);\n // Failed, or pending: the form stays, and the mutation says which. A\n // pending write leaves through the mutation's `confirm`, once its flow\n // completed.\n if (result?._tag !== 'settled') return;\n draft?.clear();\n void refreshList();\n // Said in the toast region every route shares, so it survives the\n // navigation that follows (ADR 0028).\n toasts?.show({\n tone: 'success',\n message: ct('state.saved', {\n object: recordNoun(next),\n }),\n });\n afterSave();\n };\n\n const toasts = useToasts();\n const ct = useT('controls');\n const nameOf = useRecordLabel();\n /**\n * What an announcement names: the record, through the one derivation every\n * surface shares, or the entity for one not loaded.\n */\n const recordNoun = (record: TEntity | undefined) =>\n nameOf(entityConstructor, record);\n // The breadcrumb for this page's segment names the record, never its id:\n // \"Nuevo\" for a create, the record once it has loaded.\n useBreadcrumbLabel(\n slug ?? params.slug,\n id == null ? ct('form.new') : entity && recordNoun(entity),\n );\n /**\n * Saves a deleted record back under its id: what Undo runs under the\n * `undo` policy.\n */\n const restore = (record: TEntity) =>\n Effect.runPromise(\n writer === undefined\n ? Effect.asVoid(\n Effect.provide(\n saveUCFactory<TEntity>(),\n ctx.pipe(Context.add(EntityTag, record)),\n ),\n )\n : Effect.asVoid(writer.save(record)),\n ).then(\n () => refreshList(),\n (failure: unknown) => {\n toasts?.show({ tone: 'failure', failure: asFailure(failure) });\n },\n );\n\n const handleDelete = async () => {\n const snapshot = entity;\n const result = await deleteMutation.mutate(id).catch(() => undefined);\n if (result?._tag !== 'settled') return;\n draft?.clear();\n void refreshList();\n // Said once, in the toast region every route shares, so it survives the\n // navigation back to the list.\n const object = recordNoun(snapshot);\n const message = ct('confirm.deleted', { object });\n if (deletePolicy === 'undo' && snapshot !== undefined)\n toasts?.show({\n tone: 'undo',\n message,\n action: {\n label: ct('confirm.undo'),\n onAction: () => void restore(snapshot),\n },\n });\n else toasts?.show({ tone: 'success', message });\n afterDelete();\n };\n\n /**\n * An `entity`-bound verb, on the record being shown.\n *\n * It **reloads** — once the verb took effect, which for one the server\n * handed to a flow is when the flow completed — rather than patching what it has: the service decides the\n * resulting state — a `publish` may land on `published` from four different\n * places — and a client that assumed the new value would show the wrong one\n * the first time the rule changed. `id == null` means the create form,\n * where there is no record to act on and the form renders no verbs anyway.\n *\n * ⚠️ The rejection is **caught and shown**, never left to the promise.\n * `EntityForm`'s `onUseCase` returns `void`, so an uncaught rejection here\n * reaches the console and nothing else — measured on an offering refusing\n * `unpublish` from `draft`: the service answered `409` with a coded body,\n * the record correctly did not move, and the operator saw a button that\n * appeared to do nothing at all.\n */\n const verbs = verbsOf(\n useCases === undefined\n ? undefined\n : (adapters[useCases] as EntityUseCaseRunner),\n affordances.metadata?.useCases,\n );\n const recordVerb = useVerb(verbs, () => void reload());\n const handleUseCase =\n verbs === undefined || id == null\n ? undefined\n : (key: string) => recordVerb.run(key, id);\n\n const form = (\n <EntityCrudForm<TEntity>\n // Remounts (and reseeds the fields) once the record arrives.\n key={String(entity?.id ?? CATALOG_NEW_SLUG)}\n entityConstructor={entityConstructor}\n catalogKey={catalogKey}\n metadataSource={metadataSource}\n hiddenFields={hiddenFields}\n links={linkSources}\n entity={entity}\n isLoading={isLoading}\n isSaving={saveMutation.status === 'running'}\n isPending={[saveMutation, deleteMutation, recordVerb.verb].some(\n mutation => mutation.status === 'pending',\n )}\n isDeleting={deleteMutation.status === 'running'}\n error={\n loadError ??\n syncFailure(saveMutation) ??\n syncFailure(deleteMutation) ??\n syncFailure(recordVerb.verb)\n }\n onSave={handleSave}\n onRetry={loadError === undefined ? undefined : reload}\n onDelete={id == null ? undefined : handleDelete}\n deletePolicy={deletePolicy}\n onUseCase={handleUseCase}\n backHref={withLocale(basePath)}\n renderLink={renderLink}\n draft={formDraft}\n />\n );\n // The records that refer to this one, under its form: an existing record\n // only, since a record being created has nothing referring to it yet.\n if (regions === undefined || id == null || entity === undefined)\n return form;\n return (\n <div className=\"flex flex-col gap-l\">\n {form}\n <RecordRegions>{regions(entity)}</RecordRegions>\n </div>\n );\n }\n\n return {\n entityConstructor,\n entityKey: catalogKey,\n entityLabelKey,\n entityPluralKey,\n basePath,\n ListPage,\n SingleViewPage,\n RelatedList,\n };\n}\n"],"names":["deleteUCFactory","EntityIdTag","EntityTag","getUCFactory","loadUCFactory","saveUCFactory","coerceFiltering","describeEntityColumns","envelopeEntityName","extractMetaEntity","Internal","isFailure","parseRsql","serializeRsql","settled","EntityTable","useCasesForSurface","useFocusOnArrival","useRecordLabel","useT","useToasts","useTranslateKey","entityQueryScope","useDataLoading","useEntityRecord","useFacetCounts","useOptimisticMutation","useQueryClient","Cause","Context","Effect","Exit","useParams","useRouter","useSearchParams","useEffect","useId","useMemo","useRef","useBreadcrumbLabel","useLocaleHref","useEntityNavHost","EntityCrudForm","PREFILL_PARAM","readPrefill","RecordRegions","useRegion","planRelated","useRelatedColumns","CATALOG_NEW_SLUG","slugToEntityId","useCrudRenderLink","useEntityAffordances","useEntityBulk","TARGET_NAME_PROPERTY","ignoreDraft","undefined","crudContextOf","adapters","repository","asFailure","failure","syncFailure","mutation","status","flowId","verbsOf","runner","served","descriptor","key","find","candidate","run","id","bulk","selection","runPromiseExit","then","exit","isSuccess","value","Promise","reject","squash","cause","useVerb","verbs","done","verb","write","confirm","mutate","result","_tag","useMounted","mounted","current","useLinkFilters","links","record","map","link","useBaseFiltering","makeEntityCrud","entityConstructor","options","useAdapters","basePath","catalogKey","hiddenFields","columns","toolbar","pageSize","initialFiltering","related","regions","metadataSource","givenMetadataSource","metadata","useCases","delete","deletePolicy","facets","Error","name","metadataSourceOf","initialRsql","meta","String","labelKey","entityLabelKey","pluralKey","entityPluralKey","entityName","descriptors","facetMembers","filter","filterable","type","relatedPlans","linkPlans","entry","field","linkLabelProperty","labelProperty","linkSearchProperty","searchProperty","ListBody","baseFiltering","newHref","givenNewHref","listPageSize","listInitialFiltering","onVerbSettled","affordances","withLocale","queryClient","scope","renderLink","pager","uc","ctx","queryKey","initialPageSize","relatedColumns","items","plan","facetCounts","members","filtering","canRunBulk","length","onCompleted","invalidateQueries","rowVerb","rowUseCases","canRunRowUseCase","handleRowUseCase","item","totalItems","hrefFor","tableProps","onUseCase","onRetry","refetch","error","ListPage","heading","et","div","className","h1","ref","tabIndex","replace","RelatedList","headingKey","prefill","regionPageSize","headingRef","query","URLSearchParams","Object","entries","member","toString","section","aria-labelledby","h2","focus","SingleViewPage","slug","onSaved","onDeleted","draft","loadError","router","params","searchParams","prefillKey","JSON","stringify","formDraft","save","clear","entity","isLoading","reload","linkFilters","linkSources","index","config","loadUc","getUc","host","refreshList","toList","push","afterSave","afterDelete","writer","saveMutation","next","provide","pipe","add","intent","deleteMutation","target","as","handleSave","catch","toasts","show","tone","message","ct","object","recordNoun","nameOf","restore","runPromise","asVoid","handleDelete","snapshot","action","label","onAction","recordVerb","handleUseCase","form","isSaving","isPending","some","isDeleting","onSave","onDelete","backHref","entityKey"],"mappings":"AAAA;;;AAEA,SACEA,eAAe,EAEfC,WAAW,EAEXC,SAAS,EACTC,YAAY,EACZC,aAAa,EACbC,aAAa,QACR,oBAAoB;AAC3B,SACEC,eAAe,EACfC,qBAAqB,EASrBC,kBAAkB,EAClBC,iBAAiB,EAEjBC,QAAQ,EACRC,SAAS,EACTC,SAAS,EACTC,aAAa,EACbC,OAAO,QAEF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