@entifix/next-shell 0.20.3 → 0.22.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/command-palette/use-records-source.d.ts.map +1 -1
- package/dist/lib/command-palette/use-records-source.js +5 -2
- package/dist/lib/command-palette/use-records-source.js.map +1 -1
- package/dist/lib/crud/index.d.ts +2 -0
- package/dist/lib/crud/index.d.ts.map +1 -1
- package/dist/lib/crud/index.js +2 -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 +131 -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/crud/use-entity-link-sources.d.ts.map +1 -1
- package/dist/lib/crud/use-entity-link-sources.js +5 -1
- package/dist/lib/crud/use-entity-link-sources.js.map +1 -1
- package/dist/lib/crud/use-entity-total.d.ts +27 -0
- package/dist/lib/crud/use-entity-total.d.ts.map +1 -0
- package/dist/lib/crud/use-entity-total.js +39 -0
- package/dist/lib/crud/use-entity-total.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/dist/lib/search/record-search-route.d.ts +2 -0
- package/dist/lib/search/record-search-route.d.ts.map +1 -1
- package/dist/lib/search/record-search-route.js +21 -5
- package/dist/lib/search/record-search-route.js.map +1 -1
- package/dist/lib/search/record-search-source.d.ts +11 -4
- package/dist/lib/search/record-search-source.d.ts.map +1 -1
- package/dist/lib/search/record-search-source.js +17 -19
- package/dist/lib/search/record-search-source.js.map +1 -1
- package/dist/lib/search/record-search.types.d.ts +4 -3
- package/dist/lib/search/record-search.types.d.ts.map +1 -1
- package/dist/lib/search/record-search.types.js.map +1 -1
- package/dist/lib/search/search-records.d.ts +3 -1
- package/dist/lib/search/search-records.d.ts.map +1 -1
- package/dist/lib/search/search-records.js +2 -1
- package/dist/lib/search/search-records.js.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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-records-source.d.ts","sourceRoot":"","sources":["../../../src/lib/command-palette/use-records-source.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,aAAa,EAGd,MAAM,eAAe,CAAC;AA0CvB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,GACf,aAAa,
|
|
1
|
+
{"version":3,"file":"use-records-source.d.ts","sourceRoot":"","sources":["../../../src/lib/command-palette/use-records-source.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,aAAa,EAGd,MAAM,eAAe,CAAC;AA0CvB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,GACf,aAAa,CAiJf"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
3
|
-
import { useT, useTranslateKey } from '@entifix/react-controls';
|
|
3
|
+
import { useLocale, useT, useTranslateKey } from '@entifix/react-controls';
|
|
4
4
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
5
5
|
import { useLocaleHref } from '../i18n/index.js';
|
|
6
6
|
import { searchRecords } from '../search/search-records.js';
|
|
@@ -42,6 +42,7 @@ const NOTHING_YET = {
|
|
|
42
42
|
*/ export function useRecordsSource(term, enabled) {
|
|
43
43
|
const t = useT('shell');
|
|
44
44
|
const translateKey = useTranslateKey();
|
|
45
|
+
const locale = useLocale();
|
|
45
46
|
const withLocale = useLocaleHref();
|
|
46
47
|
const [state, setState] = useState(NOTHING_YET);
|
|
47
48
|
// The term the request in flight is for. A ref, not state: it changes on every
|
|
@@ -61,7 +62,8 @@ const NOTHING_YET = {
|
|
|
61
62
|
pending.current = term;
|
|
62
63
|
const timer = setTimeout(()=>{
|
|
63
64
|
void searchRecords(term, {
|
|
64
|
-
signal: controller.signal
|
|
65
|
+
signal: controller.signal,
|
|
66
|
+
locale
|
|
65
67
|
}).then((response)=>{
|
|
66
68
|
if (pending.current !== term) return;
|
|
67
69
|
setState({
|
|
@@ -85,6 +87,7 @@ const NOTHING_YET = {
|
|
|
85
87
|
};
|
|
86
88
|
}, [
|
|
87
89
|
active,
|
|
90
|
+
locale,
|
|
88
91
|
term
|
|
89
92
|
]);
|
|
90
93
|
return useMemo(()=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/command-palette/use-records-source.ts"],"sourcesContent":["'use client';\n\nimport type {\n CommandGroup,\n CommandSource,\n CommandUnavailableSeverity,\n FailureCategory,\n} from '@entifix/core';\nimport { useT, useTranslateKey } from '@entifix/react-controls';\nimport { useEffect, useMemo, useRef, useState } from 'react';\n\nimport { useLocaleHref } from '../i18n/index.js';\nimport type { RecordSearchResponse } from '../search/record-search.types.js';\nimport { searchRecords } from '../search/search-records.js';\nimport {\n RECORD_SEARCH_DEBOUNCE_MS,\n RECORD_SEARCH_MIN_TERM,\n} from './palette-command.js';\n\n/**\n * Which reasons are the caller's ordinary state, and which mean something broke.\n *\n * The split is the record search's, restated as severity because that is what the palette\n * renders. An operator holds no membership, so every tenant-plane source answers\n * `409` on every keystroke — painting that as an outage teaches them to ignore\n * the row entirely, and then the `timeout` that does matter goes unread too.\n */\nconst SCOPE_CODES: ReadonlySet<string> = new Set(['noActiveOrganization']);\n\nconst severityOf = (degraded: {\n readonly reason: string;\n readonly category: FailureCategory;\n}): CommandUnavailableSeverity =>\n degraded.category === 'unauthenticated' ||\n degraded.category === 'forbidden' ||\n SCOPE_CODES.has(degraded.reason)\n ? 'scope'\n : 'reachability';\n\n/** What the browser is currently showing for records. */\ninterface RecordsState {\n /** The term this answer is for, so a stale response cannot overwrite a newer one. */\n readonly term: string;\n readonly response?: RecordSearchResponse;\n readonly failed: boolean;\n}\n\nconst NOTHING_YET: RecordsState = { term: '', failed: false };\n\n/**\n * Records matching the term, one group per source, in the order the host\n * declared them.\n *\n * The whole of the *keystroke* policy lives here rather than in `searchRecords`,\n * which is deliberately a bare typed `fetch`: the palette is the thing that\n * knows a keystroke is not a query. So this owns the debounce, the abort and the\n * two-character floor, while the route owns the fan-out, the per-source timeout\n * and the authorization.\n *\n * **No index, ever.** Every option here came back from `/api/search` for this\n * principal and this organization, on this keystroke. A prefetched client index\n * is the shape that surfaces another organization's record the first time a\n * session's scope moves under it, so there is none, ever.\n *\n * Below the two-character floor the group is present and **says why** rather\n * than being empty or absent: empty would claim nothing matched a search that\n * never ran, and absent would leave someone wondering whether records are\n * searchable here at all.\n */\nexport function useRecordsSource(\n term: string,\n enabled: boolean,\n): CommandSource {\n const t = useT('shell');\n const translateKey = useTranslateKey();\n const withLocale = useLocaleHref();\n\n const [state, setState] = useState<RecordsState>(NOTHING_YET);\n // The term the request in flight is for. A ref, not state: it changes on every\n // keystroke and nothing renders from it.\n const pending = useRef<string | null>(null);\n\n const active = enabled && term.length >= RECORD_SEARCH_MIN_TERM;\n\n useEffect(() => {\n // Nothing is cleared here on purpose. A `setState` in an effect body is a\n // cascading render, and there is nothing to clear: the memo below returns no\n // groups while inactive, so a previous answer is unreachable rather than\n // stale — and the host empties the term when it opens the palette.\n if (!active) {\n pending.current = null;\n return;\n }\n\n const controller = new AbortController();\n pending.current = term;\n\n const timer = setTimeout(() => {\n void searchRecords(term, { signal: controller.signal })\n .then(response => {\n if (pending.current !== term) return;\n setState({ term, response, failed: false });\n })\n .catch(() => {\n // An abort lands here too and must not be shown: the term moved on,\n // so there is nothing to report about the request that did not finish.\n if (controller.signal.aborted || pending.current !== term) return;\n setState({ term, failed: true });\n });\n }, RECORD_SEARCH_DEBOUNCE_MS);\n\n return () => {\n clearTimeout(timer);\n controller.abort();\n };\n }, [active, term]);\n\n return useMemo(() => {\n const heading = t('commandPalette.groups.records');\n\n if (!active) {\n // Someone who has typed one character is mid-word, not looking at an\n // answer. Saying so is better than both alternatives: an empty group would\n // claim nothing matched a search that never ran, and an absent one would\n // leave them wondering whether records are searchable at all.\n if (!enabled || term.length === 0) return { key: 'records', groups: [] };\n return {\n key: 'records',\n groups: [\n {\n key: 'records',\n label: heading,\n options: [],\n isLoading: false,\n unavailable: {\n message: t('commandPalette.typeMore', {\n count: RECORD_SEARCH_MIN_TERM,\n }),\n severity: 'scope',\n },\n },\n ],\n };\n }\n // A newer term is in flight. The previous answer stays on screen with its\n // groups marked loading rather than blanking: a list that empties between\n // keystrokes flickers, and the rows it drops were correct a moment ago.\n const isLoading = state.term !== term;\n\n if (state.response === undefined) {\n return {\n key: 'records',\n groups: [\n {\n key: 'records',\n label: heading,\n options: [],\n isLoading: !state.failed,\n // The whole endpoint failed — a lapsed session or a `400`, both of\n // which arrive as a rejection rather than inside a `200`. It is\n // named for the same reason a single degraded source is.\n ...(state.failed\n ? {\n unavailable: {\n message: t('commandPalette.unavailableReach', {\n reason: translateKey('errors:unexpected'),\n }),\n severity: 'reachability' as const,\n },\n }\n : {}),\n },\n ],\n };\n }\n\n const groups: CommandGroup[] = state.response.groups.map(group => ({\n key: `record:${group.source}`,\n // The entity's own `pluralKey`, so record search introduces no copy of\n // its own and a group is titled exactly as its screen is.\n label: translateKey(group.labelKey),\n options: group.items.map(item => ({\n id: `record:${group.source}:${item.id}`,\n label: item.label,\n ...(item.sublabel === undefined ? {} : { sublabel: item.sublabel }),\n href: withLocale(item.href),\n })),\n total: group.total,\n isLoading,\n }));\n\n for (const degraded of state.response.unavailable) {\n const severity = severityOf(degraded);\n groups.push({\n key: `record:${degraded.source}`,\n // Derived from the entity rather than from the source key, which is an\n // identifier and would render as `product-specification`. Every\n // searchable entity declares a `pluralKey` — `catalogSurface` throws\n // without one — so this always resolves.\n label: translateKey(`entity:${degraded.entity}.plural`),\n options: [],\n isLoading: false,\n unavailable: {\n message: t(\n severity === 'scope'\n ? 'commandPalette.unavailableScope'\n : 'commandPalette.unavailableReach',\n { reason: translateKey(`errors:${degraded.reason}`) },\n ),\n severity,\n },\n });\n }\n\n return { key: 'records', groups };\n }, [active, enabled, state, term, t, translateKey, withLocale]);\n}\n"],"names":["useT","useTranslateKey","useEffect","useMemo","useRef","useState","useLocaleHref","searchRecords","RECORD_SEARCH_DEBOUNCE_MS","RECORD_SEARCH_MIN_TERM","SCOPE_CODES","Set","severityOf","degraded","category","has","reason","NOTHING_YET","term","failed","useRecordsSource","enabled","t","translateKey","withLocale","state","setState","pending","active","length","current","controller","AbortController","timer","setTimeout","signal","then","response","catch","aborted","clearTimeout","abort","heading","key","groups","label","options","isLoading","unavailable","message","count","severity","undefined","map","group","source","labelKey","items","item","id","sublabel","href","total","push","entity"],"mappings":"AAAA;;AAQA,SAASA,IAAI,EAAEC,eAAe,QAAQ,0BAA0B;AAChE,SAASC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAE7D,SAASC,aAAa,QAAQ,mBAAmB;AAEjD,SAASC,aAAa,QAAQ,8BAA8B;AAC5D,SACEC,yBAAyB,EACzBC,sBAAsB,QACjB,uBAAuB;AAE9B;;;;;;;CAOC,GACD,MAAMC,cAAmC,IAAIC,IAAI;IAAC;CAAuB;AAEzE,MAAMC,aAAa,CAACC,WAIlBA,SAASC,QAAQ,KAAK,qBACtBD,SAASC,QAAQ,KAAK,eACtBJ,YAAYK,GAAG,CAACF,SAASG,MAAM,IAC3B,UACA;AAUN,MAAMC,cAA4B;IAAEC,MAAM;IAAIC,QAAQ;AAAM;AAE5D;;;;;;;;;;;;;;;;;;;CAmBC,GACD,OAAO,SAASC,iBACdF,IAAY,EACZG,OAAgB;IAEhB,MAAMC,IAAItB,KAAK;IACf,MAAMuB,eAAetB;IACrB,MAAMuB,aAAalB;IAEnB,MAAM,CAACmB,OAAOC,SAAS,GAAGrB,SAAuBY;IACjD,+EAA+E;IAC/E,yCAAyC;IACzC,MAAMU,UAAUvB,OAAsB;IAEtC,MAAMwB,SAASP,WAAWH,KAAKW,MAAM,IAAIpB;IAEzCP,UAAU;QACR,0EAA0E;QAC1E,6EAA6E;QAC7E,yEAAyE;QACzE,mEAAmE;QACnE,IAAI,CAAC0B,QAAQ;YACXD,QAAQG,OAAO,GAAG;YAClB;QACF;QAEA,MAAMC,aAAa,IAAIC;QACvBL,QAAQG,OAAO,GAAGZ;QAElB,MAAMe,QAAQC,WAAW;YACvB,KAAK3B,cAAcW,MAAM;gBAAEiB,QAAQJ,WAAWI,MAAM;YAAC,GAClDC,IAA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/command-palette/use-records-source.ts"],"sourcesContent":["'use client';\n\nimport type {\n CommandGroup,\n CommandSource,\n CommandUnavailableSeverity,\n FailureCategory,\n} from '@entifix/core';\nimport { useLocale, useT, useTranslateKey } from '@entifix/react-controls';\nimport { useEffect, useMemo, useRef, useState } from 'react';\n\nimport { useLocaleHref } from '../i18n/index.js';\nimport type { RecordSearchResponse } from '../search/record-search.types.js';\nimport { searchRecords } from '../search/search-records.js';\nimport {\n RECORD_SEARCH_DEBOUNCE_MS,\n RECORD_SEARCH_MIN_TERM,\n} from './palette-command.js';\n\n/**\n * Which reasons are the caller's ordinary state, and which mean something broke.\n *\n * The split is the record search's, restated as severity because that is what the palette\n * renders. An operator holds no membership, so every tenant-plane source answers\n * `409` on every keystroke — painting that as an outage teaches them to ignore\n * the row entirely, and then the `timeout` that does matter goes unread too.\n */\nconst SCOPE_CODES: ReadonlySet<string> = new Set(['noActiveOrganization']);\n\nconst severityOf = (degraded: {\n readonly reason: string;\n readonly category: FailureCategory;\n}): CommandUnavailableSeverity =>\n degraded.category === 'unauthenticated' ||\n degraded.category === 'forbidden' ||\n SCOPE_CODES.has(degraded.reason)\n ? 'scope'\n : 'reachability';\n\n/** What the browser is currently showing for records. */\ninterface RecordsState {\n /** The term this answer is for, so a stale response cannot overwrite a newer one. */\n readonly term: string;\n readonly response?: RecordSearchResponse;\n readonly failed: boolean;\n}\n\nconst NOTHING_YET: RecordsState = { term: '', failed: false };\n\n/**\n * Records matching the term, one group per source, in the order the host\n * declared them.\n *\n * The whole of the *keystroke* policy lives here rather than in `searchRecords`,\n * which is deliberately a bare typed `fetch`: the palette is the thing that\n * knows a keystroke is not a query. So this owns the debounce, the abort and the\n * two-character floor, while the route owns the fan-out, the per-source timeout\n * and the authorization.\n *\n * **No index, ever.** Every option here came back from `/api/search` for this\n * principal and this organization, on this keystroke. A prefetched client index\n * is the shape that surfaces another organization's record the first time a\n * session's scope moves under it, so there is none, ever.\n *\n * Below the two-character floor the group is present and **says why** rather\n * than being empty or absent: empty would claim nothing matched a search that\n * never ran, and absent would leave someone wondering whether records are\n * searchable here at all.\n */\nexport function useRecordsSource(\n term: string,\n enabled: boolean,\n): CommandSource {\n const t = useT('shell');\n const translateKey = useTranslateKey();\n const locale = useLocale();\n const withLocale = useLocaleHref();\n\n const [state, setState] = useState<RecordsState>(NOTHING_YET);\n // The term the request in flight is for. A ref, not state: it changes on every\n // keystroke and nothing renders from it.\n const pending = useRef<string | null>(null);\n\n const active = enabled && term.length >= RECORD_SEARCH_MIN_TERM;\n\n useEffect(() => {\n // Nothing is cleared here on purpose. A `setState` in an effect body is a\n // cascading render, and there is nothing to clear: the memo below returns no\n // groups while inactive, so a previous answer is unreachable rather than\n // stale — and the host empties the term when it opens the palette.\n if (!active) {\n pending.current = null;\n return;\n }\n\n const controller = new AbortController();\n pending.current = term;\n\n const timer = setTimeout(() => {\n void searchRecords(term, { signal: controller.signal, locale })\n .then(response => {\n if (pending.current !== term) return;\n setState({ term, response, failed: false });\n })\n .catch(() => {\n // An abort lands here too and must not be shown: the term moved on,\n // so there is nothing to report about the request that did not finish.\n if (controller.signal.aborted || pending.current !== term) return;\n setState({ term, failed: true });\n });\n }, RECORD_SEARCH_DEBOUNCE_MS);\n\n return () => {\n clearTimeout(timer);\n controller.abort();\n };\n }, [active, locale, term]);\n\n return useMemo(() => {\n const heading = t('commandPalette.groups.records');\n\n if (!active) {\n // Someone who has typed one character is mid-word, not looking at an\n // answer. Saying so is better than both alternatives: an empty group would\n // claim nothing matched a search that never ran, and an absent one would\n // leave them wondering whether records are searchable at all.\n if (!enabled || term.length === 0) return { key: 'records', groups: [] };\n return {\n key: 'records',\n groups: [\n {\n key: 'records',\n label: heading,\n options: [],\n isLoading: false,\n unavailable: {\n message: t('commandPalette.typeMore', {\n count: RECORD_SEARCH_MIN_TERM,\n }),\n severity: 'scope',\n },\n },\n ],\n };\n }\n // A newer term is in flight. The previous answer stays on screen with its\n // groups marked loading rather than blanking: a list that empties between\n // keystrokes flickers, and the rows it drops were correct a moment ago.\n const isLoading = state.term !== term;\n\n if (state.response === undefined) {\n return {\n key: 'records',\n groups: [\n {\n key: 'records',\n label: heading,\n options: [],\n isLoading: !state.failed,\n // The whole endpoint failed — a lapsed session or a `400`, both of\n // which arrive as a rejection rather than inside a `200`. It is\n // named for the same reason a single degraded source is.\n ...(state.failed\n ? {\n unavailable: {\n message: t('commandPalette.unavailableReach', {\n reason: translateKey('errors:unexpected'),\n }),\n severity: 'reachability' as const,\n },\n }\n : {}),\n },\n ],\n };\n }\n\n const groups: CommandGroup[] = state.response.groups.map(group => ({\n key: `record:${group.source}`,\n // The entity's own `pluralKey`, so record search introduces no copy of\n // its own and a group is titled exactly as its screen is.\n label: translateKey(group.labelKey),\n options: group.items.map(item => ({\n id: `record:${group.source}:${item.id}`,\n label: item.label,\n ...(item.sublabel === undefined ? {} : { sublabel: item.sublabel }),\n href: withLocale(item.href),\n })),\n total: group.total,\n isLoading,\n }));\n\n for (const degraded of state.response.unavailable) {\n const severity = severityOf(degraded);\n groups.push({\n key: `record:${degraded.source}`,\n // Derived from the entity rather than from the source key, which is an\n // identifier and would render as `product-specification`. Every\n // searchable entity declares a `pluralKey` — `catalogSurface` throws\n // without one — so this always resolves.\n label: translateKey(`entity:${degraded.entity}.plural`),\n options: [],\n isLoading: false,\n unavailable: {\n message: t(\n severity === 'scope'\n ? 'commandPalette.unavailableScope'\n : 'commandPalette.unavailableReach',\n { reason: translateKey(`errors:${degraded.reason}`) },\n ),\n severity,\n },\n });\n }\n\n return { key: 'records', groups };\n }, [active, enabled, state, term, t, translateKey, withLocale]);\n}\n"],"names":["useLocale","useT","useTranslateKey","useEffect","useMemo","useRef","useState","useLocaleHref","searchRecords","RECORD_SEARCH_DEBOUNCE_MS","RECORD_SEARCH_MIN_TERM","SCOPE_CODES","Set","severityOf","degraded","category","has","reason","NOTHING_YET","term","failed","useRecordsSource","enabled","t","translateKey","locale","withLocale","state","setState","pending","active","length","current","controller","AbortController","timer","setTimeout","signal","then","response","catch","aborted","clearTimeout","abort","heading","key","groups","label","options","isLoading","unavailable","message","count","severity","undefined","map","group","source","labelKey","items","item","id","sublabel","href","total","push","entity"],"mappings":"AAAA;;AAQA,SAASA,SAAS,EAAEC,IAAI,EAAEC,eAAe,QAAQ,0BAA0B;AAC3E,SAASC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAE7D,SAASC,aAAa,QAAQ,mBAAmB;AAEjD,SAASC,aAAa,QAAQ,8BAA8B;AAC5D,SACEC,yBAAyB,EACzBC,sBAAsB,QACjB,uBAAuB;AAE9B;;;;;;;CAOC,GACD,MAAMC,cAAmC,IAAIC,IAAI;IAAC;CAAuB;AAEzE,MAAMC,aAAa,CAACC,WAIlBA,SAASC,QAAQ,KAAK,qBACtBD,SAASC,QAAQ,KAAK,eACtBJ,YAAYK,GAAG,CAACF,SAASG,MAAM,IAC3B,UACA;AAUN,MAAMC,cAA4B;IAAEC,MAAM;IAAIC,QAAQ;AAAM;AAE5D;;;;;;;;;;;;;;;;;;;CAmBC,GACD,OAAO,SAASC,iBACdF,IAAY,EACZG,OAAgB;IAEhB,MAAMC,IAAItB,KAAK;IACf,MAAMuB,eAAetB;IACrB,MAAMuB,SAASzB;IACf,MAAM0B,aAAanB;IAEnB,MAAM,CAACoB,OAAOC,SAAS,GAAGtB,SAAuBY;IACjD,+EAA+E;IAC/E,yCAAyC;IACzC,MAAMW,UAAUxB,OAAsB;IAEtC,MAAMyB,SAASR,WAAWH,KAAKY,MAAM,IAAIrB;IAEzCP,UAAU;QACR,0EAA0E;QAC1E,6EAA6E;QAC7E,yEAAyE;QACzE,mEAAmE;QACnE,IAAI,CAAC2B,QAAQ;YACXD,QAAQG,OAAO,GAAG;YAClB;QACF;QAEA,MAAMC,aAAa,IAAIC;QACvBL,QAAQG,OAAO,GAAGb;QAElB,MAAMgB,QAAQC,WAAW;YACvB,KAAK5B,cAAcW,MAAM;gBAAEkB,QAAQJ,WAAWI,MAAM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package/dist/lib/crud/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
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';
|
|
7
8
|
export * from './use-entity-bulk.js';
|
|
8
9
|
export * from './use-entity-link-sources.js';
|
|
10
|
+
export * from './use-entity-total.js';
|
|
9
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -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;AAC7C,cAAc,uBAAuB,CAAC"}
|
package/dist/lib/crud/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
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';
|
|
7
8
|
export * from './use-entity-bulk.js';
|
|
8
9
|
export * from './use-entity-link-sources.js';
|
|
10
|
+
export * from './use-entity-total.js';
|
|
9
11
|
|
|
10
12
|
//# sourceMappingURL=index.js.map
|
|
@@ -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';\nexport * from './use-entity-total.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;AAC7C,cAAc,wBAAwB"}
|
|
@@ -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,CAipBrB"}
|
|
@@ -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,55 @@ 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
|
+
// The row's menu hands focus back to its trigger as it closes, and
|
|
363
|
+
// a verb that settles fast settles before that. Focusing on the
|
|
364
|
+
// next frame lands after the menu's restore, never under it.
|
|
365
|
+
onVerbSettled: ()=>requestAnimationFrame(()=>{
|
|
366
|
+
var _headingRef_current;
|
|
367
|
+
return (_headingRef_current = headingRef.current) == null ? void 0 : _headingRef_current.focus();
|
|
368
|
+
})
|
|
326
369
|
}))
|
|
327
370
|
]
|
|
328
371
|
});
|
|
@@ -344,6 +387,23 @@ export function makeEntityCrud(entityConstructor, options) {
|
|
|
344
387
|
const params = useParams();
|
|
345
388
|
const mounted = useMounted();
|
|
346
389
|
const id = slugToEntityId(slug != null ? slug : params.slug);
|
|
390
|
+
// A create opened from a related region starts with the parent record set:
|
|
391
|
+
// `?prefill.<member>=<value>`, layered under any draft the host restores.
|
|
392
|
+
const searchParams = useSearchParams();
|
|
393
|
+
const prefill = id == null ? readPrefill(searchParams, descriptors) : undefined;
|
|
394
|
+
const prefillKey = prefill === undefined ? '' : JSON.stringify(prefill);
|
|
395
|
+
const formDraft = useMemo(()=>{
|
|
396
|
+
var _ref, _ref1;
|
|
397
|
+
return prefill === undefined ? draft : {
|
|
398
|
+
draft: _extends({}, prefill, draft == null ? void 0 : draft.draft),
|
|
399
|
+
save: (_ref = draft == null ? void 0 : draft.save) != null ? _ref : ignoreDraft,
|
|
400
|
+
clear: (_ref1 = draft == null ? void 0 : draft.clear) != null ? _ref1 : ignoreDraft
|
|
401
|
+
};
|
|
402
|
+
}, // Keyed on the values, not the object a render builds them into.
|
|
403
|
+
[
|
|
404
|
+
draft,
|
|
405
|
+
prefillKey
|
|
406
|
+
]);
|
|
347
407
|
const ctx = crudContextOf(adapters, repository);
|
|
348
408
|
const { entity, isLoading, error: loadError, reload } = useEntityRecord({
|
|
349
409
|
uc: getUCFactory(),
|
|
@@ -442,11 +502,11 @@ export function makeEntityCrud(entityConstructor, options) {
|
|
|
442
502
|
};
|
|
443
503
|
const toasts = useToasts();
|
|
444
504
|
const ct = useT('controls');
|
|
445
|
-
const
|
|
446
|
-
/**
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
505
|
+
const nameOf = useRecordLabel();
|
|
506
|
+
/**
|
|
507
|
+
* What an announcement names: the record, through the one derivation every
|
|
508
|
+
* surface shares, or the entity for one not loaded.
|
|
509
|
+
*/ const recordNoun = (record)=>nameOf(entityConstructor, record);
|
|
450
510
|
// The breadcrumb for this page's segment names the record, never its id:
|
|
451
511
|
// "Nuevo" for a create, the record once it has loaded.
|
|
452
512
|
useBreadcrumbLabel(slug != null ? slug : params.slug, id == null ? ct('form.new') : entity && recordNoun(entity));
|
|
@@ -504,7 +564,7 @@ export function makeEntityCrud(entityConstructor, options) {
|
|
|
504
564
|
*/ const verbs = verbsOf(useCases === undefined ? undefined : adapters[useCases], (_affordances_metadata = affordances.metadata) == null ? void 0 : _affordances_metadata.useCases);
|
|
505
565
|
const recordVerb = useVerb(verbs, ()=>void reload());
|
|
506
566
|
const handleUseCase = verbs === undefined || id == null ? undefined : (key)=>recordVerb.run(key, id);
|
|
507
|
-
|
|
567
|
+
const form = /*#__PURE__*/ _jsx(EntityCrudForm, {
|
|
508
568
|
entityConstructor: entityConstructor,
|
|
509
569
|
catalogKey: catalogKey,
|
|
510
570
|
metadataSource: metadataSource,
|
|
@@ -527,8 +587,20 @@ export function makeEntityCrud(entityConstructor, options) {
|
|
|
527
587
|
onUseCase: handleUseCase,
|
|
528
588
|
backHref: withLocale(basePath),
|
|
529
589
|
renderLink: renderLink,
|
|
530
|
-
draft:
|
|
590
|
+
draft: formDraft
|
|
531
591
|
}, String((_ref2 = entity == null ? void 0 : entity.id) != null ? _ref2 : CATALOG_NEW_SLUG));
|
|
592
|
+
// The records that refer to this one, under its form: an existing record
|
|
593
|
+
// only, since a record being created has nothing referring to it yet.
|
|
594
|
+
if (regions === undefined || id == null || entity === undefined) return form;
|
|
595
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
596
|
+
className: "flex flex-col gap-l",
|
|
597
|
+
children: [
|
|
598
|
+
form,
|
|
599
|
+
/*#__PURE__*/ _jsx(RecordRegions, {
|
|
600
|
+
children: regions(entity)
|
|
601
|
+
})
|
|
602
|
+
]
|
|
603
|
+
});
|
|
532
604
|
}
|
|
533
605
|
return {
|
|
534
606
|
entityConstructor,
|
|
@@ -537,7 +609,8 @@ export function makeEntityCrud(entityConstructor, options) {
|
|
|
537
609
|
entityPluralKey,
|
|
538
610
|
basePath,
|
|
539
611
|
ListPage,
|
|
540
|
-
SingleViewPage
|
|
612
|
+
SingleViewPage,
|
|
613
|
+
RelatedList
|
|
541
614
|
};
|
|
542
615
|
}
|
|
543
616
|
|