@entifix/next-shell 0.18.2 → 0.20.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 +7 -5
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/back-office/account-menu.d.ts +10 -1
- package/dist/lib/back-office/account-menu.d.ts.map +1 -1
- package/dist/lib/back-office/account-menu.js +27 -3
- package/dist/lib/back-office/account-menu.js.map +1 -1
- package/dist/lib/back-office/back-office-shell.d.ts +0 -19
- package/dist/lib/back-office/back-office-shell.d.ts.map +1 -1
- package/dist/lib/back-office/back-office-shell.js +75 -59
- package/dist/lib/back-office/back-office-shell.js.map +1 -1
- package/dist/lib/back-office/breadcrumb-labels.d.ts +20 -0
- package/dist/lib/back-office/breadcrumb-labels.d.ts.map +1 -0
- package/dist/lib/back-office/breadcrumb-labels.js +52 -0
- package/dist/lib/back-office/breadcrumb-labels.js.map +1 -0
- package/dist/lib/back-office/breadcrumbs.d.ts.map +1 -1
- package/dist/lib/back-office/breadcrumbs.js +8 -1
- package/dist/lib/back-office/breadcrumbs.js.map +1 -1
- package/dist/lib/back-office/index.d.ts +1 -0
- package/dist/lib/back-office/index.d.ts.map +1 -1
- package/dist/lib/back-office/index.js +1 -0
- package/dist/lib/back-office/index.js.map +1 -1
- package/dist/lib/back-office/sidebar-nav.d.ts.map +1 -1
- package/dist/lib/back-office/sidebar-nav.js +31 -36
- package/dist/lib/back-office/sidebar-nav.js.map +1 -1
- package/dist/lib/command-palette/command-palette-host.d.ts.map +1 -1
- package/dist/lib/command-palette/command-palette-host.js +2 -9
- package/dist/lib/command-palette/command-palette-host.js.map +1 -1
- package/dist/lib/command-palette/use-use-cases-source.d.ts.map +1 -1
- package/dist/lib/command-palette/use-use-cases-source.js +3 -1
- package/dist/lib/command-palette/use-use-cases-source.js.map +1 -1
- package/dist/lib/confirm-action/confirm-action-state.d.ts +33 -0
- package/dist/lib/confirm-action/confirm-action-state.d.ts.map +1 -0
- package/dist/lib/confirm-action/confirm-action-state.js +33 -0
- package/dist/lib/confirm-action/confirm-action-state.js.map +1 -0
- package/dist/lib/confirm-action/confirm-action.d.ts +28 -0
- package/dist/lib/confirm-action/confirm-action.d.ts.map +1 -0
- package/dist/lib/confirm-action/confirm-action.js +129 -0
- package/dist/lib/confirm-action/confirm-action.js.map +1 -0
- package/dist/lib/confirm-action/index.d.ts +3 -0
- package/dist/lib/confirm-action/index.d.ts.map +1 -0
- package/dist/lib/confirm-action/index.js +3 -0
- package/dist/lib/confirm-action/index.js.map +1 -0
- package/dist/lib/crud/entity-crud-form.d.ts +5 -1
- package/dist/lib/crud/entity-crud-form.d.ts.map +1 -1
- package/dist/lib/crud/entity-crud-form.js +5 -10
- package/dist/lib/crud/entity-crud-form.js.map +1 -1
- package/dist/lib/crud/make-entity-crud.d.ts.map +1 -1
- package/dist/lib/crud/make-entity-crud.js +120 -20
- package/dist/lib/crud/make-entity-crud.js.map +1 -1
- package/dist/lib/crud/make-entity-crud.types.d.ts +18 -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/use-link-labels.d.ts +32 -0
- package/dist/lib/crud/use-link-labels.d.ts.map +1 -0
- package/dist/lib/crud/use-link-labels.js +76 -0
- package/dist/lib/crud/use-link-labels.js.map +1 -0
- package/dist/lib/i18n/catalog/en.d.ts.map +1 -1
- package/dist/lib/i18n/catalog/en.js +4 -4
- package/dist/lib/i18n/catalog/en.js.map +1 -1
- package/dist/lib/i18n/catalog/es.d.ts +4 -2
- package/dist/lib/i18n/catalog/es.d.ts.map +1 -1
- package/dist/lib/i18n/catalog/es.js +4 -4
- package/dist/lib/i18n/catalog/es.js.map +1 -1
- package/dist/lib/i18n/catalog/index.d.ts +4 -4
- package/dist/lib/theme/theme-cookies.d.ts +27 -0
- package/dist/lib/theme/theme-cookies.d.ts.map +1 -0
- package/dist/lib/theme/theme-cookies.js +18 -0
- package/dist/lib/theme/theme-cookies.js.map +1 -0
- package/dist/lib/workspace/pending-flows.d.ts.map +1 -1
- package/dist/lib/workspace/pending-flows.js +15 -6
- package/dist/lib/workspace/pending-flows.js.map +1 -1
- package/dist/lib/workspace/workspace-shell.d.ts.map +1 -1
- package/dist/lib/workspace/workspace-shell.js +24 -5
- package/dist/lib/workspace/workspace-shell.js.map +1 -1
- package/dist/server.d.ts +2 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +5 -0
- package/dist/server.js.map +1 -1
- package/package.json +9 -9
- package/dist/lib/crud/validation-messages.d.ts +0 -13
- package/dist/lib/crud/validation-messages.d.ts.map +0 -1
- package/dist/lib/crud/validation-messages.js +0 -36
- package/dist/lib/crud/validation-messages.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/confirm-action/confirm-action.tsx"],"sourcesContent":["'use client';\n\nimport { Button, type ConfirmDialogProps, useT } from '@entifix/react-controls';\nimport { type ReactNode, useActionState, useId, useRef } from 'react';\n\nimport {\n CANCEL_FIELD,\n CONFIRM_ACTION_IDLE,\n CONFIRM_FIELD,\n type ConfirmActionState,\n} from './confirm-action-state.js';\n\n/** A Server Action written with `whenConfirmed`, as `useActionState` calls it. */\nexport type ConfirmActionHandler = (\n state: ConfirmActionState,\n formData: FormData,\n) => Promise<ConfirmActionState>;\n\nexport interface ConfirmActionProps extends Pick<\n ConfirmDialogProps,\n 'title' | 'message' | 'tone' | 'confirmLabel' | 'cancelLabel'\n> {\n /** The Server Action, guarded by `whenConfirmed`. */\n action: ConfirmActionHandler;\n /** Posted with both steps as hidden inputs — the record's id, typically. */\n fields?: Readonly<Record<string, string>>;\n /** The trigger's label: the verb, as the page offers it. */\n children: ReactNode;\n}\n\n/**\n * A Server Action form that asks before it acts, with or without JavaScript\n * ([ADR 0026](../../../../../../docs/adr/0026-actions-hierarchy-overflow-and-destructive-verbs.md)).\n *\n * - **Without JavaScript** the trigger posts, the action answers with the\n * confirmation step (`whenConfirmed` sees no confirmation field), and the\n * page renders an interstitial with the title, the consequence and the verb.\n * Its button posts again, carrying the field, and only that post acts.\n * - **With JavaScript** the trigger opens a native `<dialog>` with the same\n * copy, Cancel focused, and its button posts the confirmed form.\n *\n * The copy is `ConfirmDialog`'s text slots, already resolved by the page.\n */\nexport function ConfirmAction({\n action,\n fields = {},\n title,\n message,\n tone = 'neutral',\n confirmLabel,\n cancelLabel,\n children,\n}: ConfirmActionProps) {\n const t = useT();\n const [state, formAction, pending] = useActionState(\n action,\n CONFIRM_ACTION_IDLE,\n );\n const dialog = useRef<HTMLDialogElement>(null);\n const titleId = useId();\n const messageId = useId();\n\n const hidden = Object.entries(fields).map(([name, value]) => (\n <input key={name} type=\"hidden\" name={name} value={value} />\n ));\n const cancelText = cancelLabel ?? t('confirm.cancel');\n const confirmButton = (\n <Button\n type=\"submit\"\n name={CONFIRM_FIELD}\n value=\"1\"\n variant={tone === 'destructive' ? 'destructive' : 'primary'}\n disabled={pending}\n onClick={() => dialog.current?.close()}\n >\n {confirmLabel ?? t('confirm.confirm')}\n </Button>\n );\n const copy = (\n <>\n <h2 id={titleId} className=\"text-step-1 font-semibold text-content\">\n {title}\n </h2>\n <p id={messageId} className=\"mt-2xs text-step-sm text-content-muted\">\n {message}\n </p>\n </>\n );\n\n if (state.step === 'confirm')\n return (\n <section\n aria-labelledby={titleId}\n data-testid=\"confirm-action-step\"\n className=\"max-w-md rounded-lg border border-border bg-surface p-s\"\n >\n {copy}\n <form action={formAction} className=\"mt-s flex justify-end gap-xs\">\n {hidden}\n <Button\n type=\"submit\"\n name={CANCEL_FIELD}\n value=\"1\"\n variant=\"ghost\"\n disabled={pending}\n >\n {cancelText}\n </Button>\n {confirmButton}\n </form>\n </section>\n );\n\n return (\n <form\n action={formAction}\n onSubmit={event => {\n const submitter = (event.nativeEvent as SubmitEvent).submitter;\n if (submitter?.getAttribute('name') === CONFIRM_FIELD) return;\n // Asked here, before the post; the action asks again if this is skipped.\n event.preventDefault();\n dialog.current?.showModal();\n dialog.current\n ?.querySelector<HTMLElement>('[data-confirm-cancel]')\n ?.focus();\n }}\n >\n {hidden}\n <Button\n type=\"submit\"\n variant={tone === 'destructive' ? 'destructive' : 'secondary'}\n disabled={pending}\n >\n {children}\n </Button>\n <dialog\n ref={dialog}\n role=\"alertdialog\"\n aria-labelledby={titleId}\n aria-describedby={messageId}\n className=\"max-w-md m-auto w-full rounded-lg border border-border bg-surface p-s text-content shadow-overlay backdrop:bg-scrim\"\n >\n {copy}\n <div className=\"mt-s flex justify-end gap-xs\">\n <Button\n data-confirm-cancel\n type=\"button\"\n variant=\"ghost\"\n onClick={() => dialog.current?.close()}\n >\n {cancelText}\n </Button>\n {confirmButton}\n </div>\n </dialog>\n </form>\n );\n}\n"],"names":["Button","useT","useActionState","useId","useRef","CANCEL_FIELD","CONFIRM_ACTION_IDLE","CONFIRM_FIELD","ConfirmAction","action","fields","title","message","tone","confirmLabel","cancelLabel","children","t","state","formAction","pending","dialog","titleId","messageId","hidden","Object","entries","map","name","value","input","type","cancelText","confirmButton","variant","disabled","onClick","current","close","copy","h2","id","className","p","step","section","aria-labelledby","data-testid","form","onSubmit","event","submitter","nativeEvent","getAttribute","preventDefault","showModal","querySelector","focus","ref","role","aria-describedby","div","data-confirm-cancel"],"mappings":"AAAA;;AAEA,SAASA,MAAM,EAA2BC,IAAI,QAAQ,0BAA0B;AAChF,SAAyBC,cAAc,EAAEC,KAAK,EAAEC,MAAM,QAAQ,QAAQ;AAEtE,SACEC,YAAY,EACZC,mBAAmB,EACnBC,aAAa,QAER,4BAA4B;AAoBnC;;;;;;;;;;;;CAYC,GACD,OAAO,SAASC,cAAc,EAC5BC,MAAM,EACNC,SAAS,CAAC,CAAC,EACXC,KAAK,EACLC,OAAO,EACPC,OAAO,SAAS,EAChBC,YAAY,EACZC,WAAW,EACXC,QAAQ,EACW;IACnB,MAAMC,IAAI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BAAdhB,gBAAgBkC,SAAS;aACzBlC,mBAAAA,OAAOgB,OAAO,sBAAdhB,gCAAAA,iBACImC,aAAa,CAAc,6CAD/BnC,8BAEIoC,KAAK;QACX;;YAECjC;0BACD,KAACxB;gBACC+B,MAAK;gBACLG,SAASrB,SAAS,gBAAgB,gBAAgB;gBAClDsB,UAAUf;0BAETJ;;0BAEH,MAACK;gBACCqC,KAAKrC;gBACLsC,MAAK;gBACLb,mBAAiBxB;gBACjBsC,oBAAkBrC;gBAClBmB,WAAU;;oBAETH;kCACD,MAACsB;wBAAInB,WAAU;;0CACb,KAAC1C;gCACC8D,qBAAmB;gCACnB/B,MAAK;gCACLG,SAAQ;gCACRE,SAAS;wCAAMf;4CAAAA,kBAAAA,OAAOgB,OAAO,qBAAdhB,gBAAgBiB,KAAK;;0CAEnCN;;4BAEFC;;;;;;;AAKX"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/confirm-action/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,YAAY,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/confirm-action/index.ts"],"sourcesContent":["export * from './confirm-action.js';\nexport type { ConfirmActionState } from './confirm-action-state.js';\n"],"names":[],"mappings":"AAAA,cAAc,sBAAsB"}
|
|
@@ -15,9 +15,13 @@ export interface EntityCrudFormProps<TEntity extends Entity> {
|
|
|
15
15
|
readonly isPending?: boolean;
|
|
16
16
|
readonly isDeleting?: boolean;
|
|
17
17
|
readonly error?: EntifixFailure;
|
|
18
|
+
/** Loads the record again — offered as Retry on a failed load. */
|
|
19
|
+
readonly onRetry?: () => void;
|
|
18
20
|
readonly onSave: (entity: TEntity) => void;
|
|
19
21
|
/** Omitted for a create — there is nothing to delete yet. */
|
|
20
22
|
readonly onDelete?: () => void;
|
|
23
|
+
/** How Delete is made safe — see `EntityCrudOptions.delete`. */
|
|
24
|
+
readonly deletePolicy?: 'confirm' | 'undo' | 'typed';
|
|
21
25
|
readonly backHref: string;
|
|
22
26
|
/** Renders the Back link; see `useCrudRenderLink`. */
|
|
23
27
|
readonly renderLink?: RenderLink;
|
|
@@ -50,5 +54,5 @@ export interface EntityCrudFormProps<TEntity extends Entity> {
|
|
|
50
54
|
* `useEntityForm` owns the draft and seeds it once, so the page keys this
|
|
51
55
|
* component by the record id to reseed when the record arrives.
|
|
52
56
|
*/
|
|
53
|
-
export declare function EntityCrudForm<TEntity extends Entity>({ entityConstructor, catalogKey, hiddenFields, links, entity, isLoading, isSaving, isPending, isDeleting, error, onSave, onDelete, backHref, renderLink, draft, metadataSource, onUseCase, }: EntityCrudFormProps<TEntity>): import("react").JSX.Element;
|
|
57
|
+
export declare function EntityCrudForm<TEntity extends Entity>({ entityConstructor, catalogKey, hiddenFields, links, entity, isLoading, isSaving, isPending, isDeleting, error, onRetry, onSave, onDelete, deletePolicy, backHref, renderLink, draft, metadataSource, onUseCase, }: EntityCrudFormProps<TEntity>): import("react").JSX.Element;
|
|
54
58
|
//# sourceMappingURL=entity-crud-form.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-crud-form.d.ts","sourceRoot":"","sources":["../../../src/lib/crud/entity-crud-form.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,MAAM,EACX,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EAE1B,MAAM,eAAe,CAAC;AACvB,OAAO,EAGL,KAAK,UAAU,EAGhB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,KAAK,gBAAgB,EAEtB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,KAAK,EACV,gBAAgB,EAChB,oBAAoB,EACrB,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"entity-crud-form.d.ts","sourceRoot":"","sources":["../../../src/lib/crud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AG,OAAO,CAAC;IACrD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,sDAAsD;IACtD,QAAQ,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC;IACjC;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,gBAAgB,CAAC;IAClC;;;;OAIG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,oBAAoB,CAAC;IAC/C,sEAAsE;IACtE,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CAC5C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,OAAO,SAAS,MAAM,EAAE,EACrD,iBAAiB,EACjB,UAAU,EACV,YAAY,EACZ,KAAK,EACL,MAAM,EACN,SAAiB,EACjB,QAAgB,EAChB,SAAiB,EACjB,UAAkB,EAClB,KAAK,EACL,OAAO,EACP,MAAM,EACN,QAAQ,EACR,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,KAAK,EACL,cAAc,EACd,SAAS,GACV,EAAE,mBAAmB,CAAC,OAAO,CAAC,+BA+G9B"}
|
|
@@ -4,10 +4,9 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
4
4
|
import { reconstructEntity } from '@entifix/core';
|
|
5
5
|
import { EntityField, EntityForm, useT, useTranslateKey } from '@entifix/react-controls';
|
|
6
6
|
import { useEntityForm } from '@entifix/react-integration';
|
|
7
|
-
import { useEffect
|
|
7
|
+
import { useEffect } from 'react';
|
|
8
8
|
import { useEntityAffordances } from './use-entity-affordances.js';
|
|
9
9
|
import { useEntityLinkSources } from './use-entity-link-sources.js';
|
|
10
|
-
import { validationMessagesFor } from './validation-messages.js';
|
|
11
10
|
/**
|
|
12
11
|
* The generated create/update form. A thin wrapper over the agnostic
|
|
13
12
|
* {@link EntityForm}: every field, label and validation rule comes from the
|
|
@@ -22,13 +21,8 @@ import { validationMessagesFor } from './validation-messages.js';
|
|
|
22
21
|
*
|
|
23
22
|
* `useEntityForm` owns the draft and seeds it once, so the page keys this
|
|
24
23
|
* component by the record id to reseed when the record arrives.
|
|
25
|
-
*/ export function EntityCrudForm({ entityConstructor, catalogKey, hiddenFields, links, entity, isLoading = false, isSaving = false, isPending = false, isDeleting = false, error, onSave, onDelete, backHref, renderLink, draft, metadataSource, onUseCase }) {
|
|
24
|
+
*/ export function EntityCrudForm({ entityConstructor, catalogKey, hiddenFields, links, entity, isLoading = false, isSaving = false, isPending = false, isDeleting = false, error, onRetry, onSave, onDelete, deletePolicy, backHref, renderLink, draft, metadataSource, onUseCase }) {
|
|
26
25
|
const et = useT('entity');
|
|
27
|
-
const ct = useT('controls');
|
|
28
|
-
// `controls` copy, resolved here and handed down; see validationMessagesFor.
|
|
29
|
-
const validationMessages = useMemo(()=>validationMessagesFor(ct), [
|
|
30
|
-
ct
|
|
31
|
-
]);
|
|
32
26
|
// A runtime-key translator, so a message names the field by its catalog word
|
|
33
27
|
// (`labelKey`) and a schema's keyed message resolves at all. Without it both
|
|
34
28
|
// fell back to untranslated text inside an otherwise Spanish sentence.
|
|
@@ -36,7 +30,6 @@ import { validationMessagesFor } from './validation-messages.js';
|
|
|
36
30
|
const form = useEntityForm({
|
|
37
31
|
entityConstructor,
|
|
38
32
|
entity,
|
|
39
|
-
validationMessages,
|
|
40
33
|
translateKey,
|
|
41
34
|
draft,
|
|
42
35
|
onSubmit: (values)=>onSave(reconstructEntity(entityConstructor, values, {
|
|
@@ -105,7 +98,8 @@ import { validationMessagesFor } from './validation-messages.js';
|
|
|
105
98
|
errors: form.errors,
|
|
106
99
|
formError: form.formError,
|
|
107
100
|
onSubmit: form.submit,
|
|
108
|
-
onDelete: onDelete
|
|
101
|
+
onDelete: onDelete,
|
|
102
|
+
deletePolicy: deletePolicy
|
|
109
103
|
}, affordances, {
|
|
110
104
|
onUseCase: onUseCase,
|
|
111
105
|
isLoading: isLoading,
|
|
@@ -113,6 +107,7 @@ import { validationMessagesFor } from './validation-messages.js';
|
|
|
113
107
|
isPending: isPending,
|
|
114
108
|
isDeleting: isDeleting,
|
|
115
109
|
error: error,
|
|
110
|
+
onRetry: onRetry,
|
|
116
111
|
backHref: backHref,
|
|
117
112
|
renderLink: renderLink,
|
|
118
113
|
// `entity` is undefined until the record lands, so testing it alone
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/crud/entity-crud-form.tsx"],"sourcesContent":["'use client';\n\nimport {\n type EntifixFailure,\n type Entity,\n type EntityConstructor,\n type EntityMetadataSource,\n reconstructEntity,\n} from '@entifix/core';\nimport {\n EntityField,\n EntityForm,\n type RenderLink,\n useT,\n useTranslateKey,\n} from '@entifix/react-controls';\nimport {\n type EntityDraftStore,\n useEntityForm,\n} from '@entifix/react-integration';\nimport { useEffect, useMemo } from 'react';\n\nimport type {\n EntityCatalogKey,\n EntityCrudLinkSource,\n} from './make-entity-crud.types.js';\nimport { useEntityAffordances } from './use-entity-affordances.js';\nimport { useEntityLinkSources } from './use-entity-link-sources.js';\nimport { validationMessagesFor } from './validation-messages.js';\n\nexport interface EntityCrudFormProps<TEntity extends Entity> {\n readonly entityConstructor: EntityConstructor<TEntity>;\n readonly catalogKey: EntityCatalogKey;\n readonly hiddenFields: readonly string[];\n readonly links: readonly EntityCrudLinkSource[];\n /** The record being edited; `undefined` means this is a create. */\n readonly entity?: TEntity;\n readonly isLoading?: boolean;\n readonly isSaving?: boolean;\n /** A write handed to a flow that has not settled: the form waits, keeping its input. */\n readonly isPending?: boolean;\n readonly isDeleting?: boolean;\n readonly error?: EntifixFailure;\n readonly onSave: (entity: TEntity) => void;\n /** Omitted for a create — there is nothing to delete yet. */\n readonly onDelete?: () => void;\n readonly backHref: string;\n /** Renders the Back link; see `useCrudRenderLink`. */\n readonly renderLink?: RenderLink;\n /**\n * Where to autosave this form's draft. Omitted by a route host, which is what\n * keeps a plain route ephemeral; the workspace tab host supplies one.\n */\n readonly draft?: EntityDraftStore;\n /**\n * Where this caller's affordances come from. Absent keeps the pre-ADR-0026\n * behaviour: Save and Delete render unconditionally and no declared verb\n * appears — which is what every generated catalog did before it existed.\n */\n readonly metadataSource?: EntityMetadataSource;\n /** Runs a declared `entity`-bound verb on this record, by its key. */\n readonly onUseCase?: (key: string) => void;\n}\n\n/**\n * The generated create/update form. A thin wrapper over the agnostic\n * {@link EntityForm}: every field, label and validation rule comes from the\n * entity's own accessor metadata, and `reconstructEntity` derives the submit\n * rebuild from that same metadata — so nothing here is per-entity but the\n * constructor, the catalog key and the hidden-field list.\n *\n * A hidden member still round-trips. `code` is assigned by the create\n * transaction and never shown, but it is a plain writable member, so the rebuild\n * picks it out of the seeded draft; dropping it from the rendered fields is not\n * dropping it from the draft.\n *\n * `useEntityForm` owns the draft and seeds it once, so the page keys this\n * component by the record id to reseed when the record arrives.\n */\nexport function EntityCrudForm<TEntity extends Entity>({\n entityConstructor,\n catalogKey,\n hiddenFields,\n links,\n entity,\n isLoading = false,\n isSaving = false,\n isPending = false,\n isDeleting = false,\n error,\n onSave,\n onDelete,\n backHref,\n renderLink,\n draft,\n metadataSource,\n onUseCase,\n}: EntityCrudFormProps<TEntity>) {\n const et = useT('entity');\n const ct = useT('controls');\n\n // `controls` copy, resolved here and handed down; see validationMessagesFor.\n const validationMessages = useMemo(() => validationMessagesFor(ct), [ct]);\n\n // A runtime-key translator, so a message names the field by its catalog word\n // (`labelKey`) and a schema's keyed message resolves at all. Without it both\n // fell back to untranslated text inside an otherwise Spanish sentence.\n const translateKey = useTranslateKey();\n\n const form = useEntityForm<TEntity>({\n entityConstructor,\n entity,\n validationMessages,\n translateKey,\n draft,\n onSubmit: values =>\n onSave(\n reconstructEntity(entityConstructor, values, { existing: entity }),\n ),\n });\n\n const linkSources = useEntityLinkSources(links, {\n values: form.values,\n selection: form.links,\n });\n\n // Refill the relation sidecar from the ids the draft did keep.\n //\n // A draft is JSON, so it holds ids and nothing else; the instances behind them\n // die with the page. Each picker already resolves its id — that is how a\n // restored draft shows a brand's name instead of its key — so the instance is\n // in hand and only has to be handed back. Without this, a member declared\n // `linkSerialization: 'embedded'` reaches `applyEntityLinks` with an id and no\n // target, which it refuses rather than writing the wrong wire shape.\n //\n // `hydrateLink`, not `setLink`: this is a lookup landing, not a pick, so it\n // must leave the draft — and the form's dirty flag — alone.\n const { links: selection, hydrateLink } = form;\n useEffect(() => {\n for (const [field, source] of Object.entries(linkSources)) {\n const resolved = source.selected.entity;\n if (resolved !== undefined && selection[field] === undefined) {\n hydrateLink(field, resolved);\n }\n }\n }, [linkSources, selection, hydrateLink]);\n\n const affordances = useEntityAffordances(entityConstructor, metadataSource);\n\n /**\n * May this caller write the record in front of them?\n *\n * The **same authority that withholds Save**, applied one step earlier.\n * Absent metadata keeps the pre-ADR-0026 behaviour, so an un-migrated call\n * site is untouched; present metadata is authoritative, because it is what\n * the service already decided.\n *\n * ⚠️ Without this the form rendered inputs nobody could submit. Measured on\n * the stock surface: `stock-item` answers `[\"read\"]` — no role holds\n * `stock-item:write` and there is no save route — so Save was correctly\n * absent while `onHand` and `reserved` still rendered as **enabled number\n * inputs**. A vendor could type a new quantity into a field that is only ever\n * moved by a ledger, and nothing would happen and nothing would say why.\n *\n * A create is exempt: there is no record yet, so there is nothing to read and\n * a `read` mode would render an empty form with no way to fill it.\n */\n const mayWrite =\n entity === undefined ||\n affordances.metadata === undefined ||\n affordances.metadata.actions.includes('write');\n\n return (\n <EntityForm<TEntity>\n entityConstructor={entityConstructor}\n entity={entity}\n // Driven by the served descriptor rather than fixed: `edit` for a caller\n // who may write, `read` for one who may not. Passing it at all is what\n // suppresses the built-in Ver/Editar toggle, which would otherwise offer\n // a way back into inputs the service will refuse.\n mode={mayWrite ? 'edit' : 'read'}\n values={form.values}\n onFieldChange={form.setField}\n linkSources={linkSources}\n onLinkChange={form.setLink}\n errors={form.errors}\n formError={form.formError}\n onSubmit={form.submit}\n onDelete={onDelete}\n {...affordances}\n onUseCase={onUseCase}\n isLoading={isLoading}\n isSaving={isSaving}\n isPending={isPending}\n isDeleting={isDeleting}\n error={error}\n backHref={backHref}\n renderLink={renderLink}\n // `entity` is undefined until the record lands, so testing it alone\n // titled a loading edit form \"New\" and then relabelled it.\n title={et(\n entity || isLoading\n ? `${catalogKey}.form.editTitle`\n : `${catalogKey}.form.newTitle`,\n )}\n >\n {hiddenFields.map(field => (\n <EntityField<TEntity> key={field} field={field} hidden />\n ))}\n </EntityForm>\n );\n}\n"],"names":["reconstructEntity","EntityField","EntityForm","useT","useTranslateKey","useEntityForm","useEffect","useMemo","useEntityAffordances","useEntityLinkSources","validationMessagesFor","EntityCrudForm","entityConstructor","catalogKey","hiddenFields","links","entity","isLoading","isSaving","isPending","isDeleting","error","onSave","onDelete","backHref","renderLink","draft","metadataSource","onUseCase","et","ct","validationMessages","translateKey","form","onSubmit","values","existing","linkSources","selection","hydrateLink","field","source","Object","entries","resolved","selected","undefined","affordances","mayWrite","metadata","actions","includes","mode","onFieldChange","setField","onLinkChange","setLink","errors","formError","submit","title","map","hidden"],"mappings":"AAAA;;;AAEA,SAKEA,iBAAiB,QACZ,gBAAgB;AACvB,SACEC,WAAW,EACXC,UAAU,EAEVC,IAAI,EACJC,eAAe,QACV,0BAA0B;AACjC,SAEEC,aAAa,QACR,6BAA6B;AACpC,SAASC,SAAS,EAAEC,OAAO,QAAQ,QAAQ;AAM3C,SAASC,oBAAoB,QAAQ,8BAA8B;AACnE,SAASC,oBAAoB,QAAQ,+BAA+B;AACpE,SAASC,qBAAqB,QAAQ,2BAA2B;AAoCjE;;;;;;;;;;;;;;CAcC,GACD,OAAO,SAASC,eAAuC,EACrDC,iBAAiB,EACjBC,UAAU,EACVC,YAAY,EACZC,KAAK,EACLC,MAAM,EACNC,YAAY,KAAK,EACjBC,WAAW,KAAK,EAChBC,YAAY,KAAK,EACjBC,aAAa,KAAK,EAClBC,KAAK,EACLC,MAAM,EACNC,QAAQ,EACRC,QAAQ,EACRC,UAAU,EACVC,KAAK,EACLC,cAAc,EACdC,SAAS,EACoB;IAC7B,MAAMC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QAClDoC,MAAMJ,WAAW,SAAS;QAC1Bb,QAAQF,KAAKE,MAAM;QACnBkB,eAAepB,KAAKqB,QAAQ;QAC5BjB,aAAaA;QACbkB,cAActB,KAAKuB,OAAO;QAC1BC,QAAQxB,KAAKwB,MAAM;QACnBC,WAAWzB,KAAKyB,SAAS;QACzBxB,UAAUD,KAAK0B,MAAM;QACrBpC,UAAUA;OACNwB;QACJnB,WAAWA;QACXX,WAAWA;QACXC,UAAUA;QACVC,WAAWA;QACXC,YAAYA;QACZC,OAAOA;QACPG,UAAUA;QACVC,YAAYA;QACZ,oEAAoE;QACpE,2DAA2D;QAC3DmC,OAAO/B,GACLb,UAAUC,YACN,GAAGJ,WAAW,eAAe,CAAC,GAC9B,GAAGA,WAAW,cAAc,CAAC;kBAGlCC,aAAa+C,GAAG,CAACrB,CAAAA,sBAChB,KAACvC;gBAAiCuC,OAAOA;gBAAOsB,MAAM;eAA3BtB;;AAInC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/crud/entity-crud-form.tsx"],"sourcesContent":["'use client';\n\nimport {\n type EntifixFailure,\n type Entity,\n type EntityConstructor,\n type EntityMetadataSource,\n reconstructEntity,\n} from '@entifix/core';\nimport {\n EntityField,\n EntityForm,\n type RenderLink,\n useT,\n useTranslateKey,\n} from '@entifix/react-controls';\nimport {\n type EntityDraftStore,\n useEntityForm,\n} from '@entifix/react-integration';\nimport { useEffect } from 'react';\n\nimport type {\n EntityCatalogKey,\n EntityCrudLinkSource,\n} from './make-entity-crud.types.js';\nimport { useEntityAffordances } from './use-entity-affordances.js';\nimport { useEntityLinkSources } from './use-entity-link-sources.js';\n\nexport interface EntityCrudFormProps<TEntity extends Entity> {\n readonly entityConstructor: EntityConstructor<TEntity>;\n readonly catalogKey: EntityCatalogKey;\n readonly hiddenFields: readonly string[];\n readonly links: readonly EntityCrudLinkSource[];\n /** The record being edited; `undefined` means this is a create. */\n readonly entity?: TEntity;\n readonly isLoading?: boolean;\n readonly isSaving?: boolean;\n /** A write handed to a flow that has not settled: the form waits, keeping its input. */\n readonly isPending?: boolean;\n readonly isDeleting?: boolean;\n readonly error?: EntifixFailure;\n /** Loads the record again — offered as Retry on a failed load. */\n readonly onRetry?: () => void;\n readonly onSave: (entity: TEntity) => void;\n /** Omitted for a create — there is nothing to delete yet. */\n readonly onDelete?: () => void;\n /** How Delete is made safe — see `EntityCrudOptions.delete`. */\n readonly deletePolicy?: 'confirm' | 'undo' | 'typed';\n readonly backHref: string;\n /** Renders the Back link; see `useCrudRenderLink`. */\n readonly renderLink?: RenderLink;\n /**\n * Where to autosave this form's draft. Omitted by a route host, which is what\n * keeps a plain route ephemeral; the workspace tab host supplies one.\n */\n readonly draft?: EntityDraftStore;\n /**\n * Where this caller's affordances come from. Absent keeps the pre-ADR-0026\n * behaviour: Save and Delete render unconditionally and no declared verb\n * appears — which is what every generated catalog did before it existed.\n */\n readonly metadataSource?: EntityMetadataSource;\n /** Runs a declared `entity`-bound verb on this record, by its key. */\n readonly onUseCase?: (key: string) => void;\n}\n\n/**\n * The generated create/update form. A thin wrapper over the agnostic\n * {@link EntityForm}: every field, label and validation rule comes from the\n * entity's own accessor metadata, and `reconstructEntity` derives the submit\n * rebuild from that same metadata — so nothing here is per-entity but the\n * constructor, the catalog key and the hidden-field list.\n *\n * A hidden member still round-trips. `code` is assigned by the create\n * transaction and never shown, but it is a plain writable member, so the rebuild\n * picks it out of the seeded draft; dropping it from the rendered fields is not\n * dropping it from the draft.\n *\n * `useEntityForm` owns the draft and seeds it once, so the page keys this\n * component by the record id to reseed when the record arrives.\n */\nexport function EntityCrudForm<TEntity extends Entity>({\n entityConstructor,\n catalogKey,\n hiddenFields,\n links,\n entity,\n isLoading = false,\n isSaving = false,\n isPending = false,\n isDeleting = false,\n error,\n onRetry,\n onSave,\n onDelete,\n deletePolicy,\n backHref,\n renderLink,\n draft,\n metadataSource,\n onUseCase,\n}: EntityCrudFormProps<TEntity>) {\n const et = useT('entity');\n\n // A runtime-key translator, so a message names the field by its catalog word\n // (`labelKey`) and a schema's keyed message resolves at all. Without it both\n // fell back to untranslated text inside an otherwise Spanish sentence.\n const translateKey = useTranslateKey();\n\n const form = useEntityForm<TEntity>({\n entityConstructor,\n entity,\n translateKey,\n draft,\n onSubmit: values =>\n onSave(\n reconstructEntity(entityConstructor, values, { existing: entity }),\n ),\n });\n\n const linkSources = useEntityLinkSources(links, {\n values: form.values,\n selection: form.links,\n });\n\n // Refill the relation sidecar from the ids the draft did keep.\n //\n // A draft is JSON, so it holds ids and nothing else; the instances behind them\n // die with the page. Each picker already resolves its id — that is how a\n // restored draft shows a brand's name instead of its key — so the instance is\n // in hand and only has to be handed back. Without this, a member declared\n // `linkSerialization: 'embedded'` reaches `applyEntityLinks` with an id and no\n // target, which it refuses rather than writing the wrong wire shape.\n //\n // `hydrateLink`, not `setLink`: this is a lookup landing, not a pick, so it\n // must leave the draft — and the form's dirty flag — alone.\n const { links: selection, hydrateLink } = form;\n useEffect(() => {\n for (const [field, source] of Object.entries(linkSources)) {\n const resolved = source.selected.entity;\n if (resolved !== undefined && selection[field] === undefined) {\n hydrateLink(field, resolved);\n }\n }\n }, [linkSources, selection, hydrateLink]);\n\n const affordances = useEntityAffordances(entityConstructor, metadataSource);\n\n /**\n * May this caller write the record in front of them?\n *\n * The **same authority that withholds Save**, applied one step earlier.\n * Absent metadata keeps the pre-ADR-0026 behaviour, so an un-migrated call\n * site is untouched; present metadata is authoritative, because it is what\n * the service already decided.\n *\n * ⚠️ Without this the form rendered inputs nobody could submit. Measured on\n * the stock surface: `stock-item` answers `[\"read\"]` — no role holds\n * `stock-item:write` and there is no save route — so Save was correctly\n * absent while `onHand` and `reserved` still rendered as **enabled number\n * inputs**. A vendor could type a new quantity into a field that is only ever\n * moved by a ledger, and nothing would happen and nothing would say why.\n *\n * A create is exempt: there is no record yet, so there is nothing to read and\n * a `read` mode would render an empty form with no way to fill it.\n */\n const mayWrite =\n entity === undefined ||\n affordances.metadata === undefined ||\n affordances.metadata.actions.includes('write');\n\n return (\n <EntityForm<TEntity>\n entityConstructor={entityConstructor}\n entity={entity}\n // Driven by the served descriptor rather than fixed: `edit` for a caller\n // who may write, `read` for one who may not. Passing it at all is what\n // suppresses the built-in Ver/Editar toggle, which would otherwise offer\n // a way back into inputs the service will refuse.\n mode={mayWrite ? 'edit' : 'read'}\n values={form.values}\n onFieldChange={form.setField}\n linkSources={linkSources}\n onLinkChange={form.setLink}\n errors={form.errors}\n formError={form.formError}\n onSubmit={form.submit}\n onDelete={onDelete}\n deletePolicy={deletePolicy}\n {...affordances}\n onUseCase={onUseCase}\n isLoading={isLoading}\n isSaving={isSaving}\n isPending={isPending}\n isDeleting={isDeleting}\n error={error}\n onRetry={onRetry}\n backHref={backHref}\n renderLink={renderLink}\n // `entity` is undefined until the record lands, so testing it alone\n // titled a loading edit form \"New\" and then relabelled it.\n title={et(\n entity || isLoading\n ? `${catalogKey}.form.editTitle`\n : `${catalogKey}.form.newTitle`,\n )}\n >\n {hiddenFields.map(field => (\n <EntityField<TEntity> key={field} field={field} hidden />\n ))}\n </EntityForm>\n );\n}\n"],"names":["reconstructEntity","EntityField","EntityForm","useT","useTranslateKey","useEntityForm","useEffect","useEntityAffordances","useEntityLinkSources","EntityCrudForm","entityConstructor","catalogKey","hiddenFields","links","entity","isLoading","isSaving","isPending","isDeleting","error","onRetry","onSave","onDelete","deletePolicy","backHref","renderLink","draft","metadataSource","onUseCase","et","translateKey","form","onSubmit","values","existing","linkSources","selection","hydrateLink","field","source","Object","entries","resolved","selected","undefined","affordances","mayWrite","metadata","actions","includes","mode","onFieldChange","setField","onLinkChange","setLink","errors","formError","submit","title","map","hidden"],"mappings":"AAAA;;;AAEA,SAKEA,iBAAiB,QACZ,gBAAgB;AACvB,SACEC,WAAW,EACXC,UAAU,EAEVC,IAAI,EACJC,eAAe,QACV,0BAA0B;AACjC,SAEEC,aAAa,QACR,6BAA6B;AACpC,SAASC,SAAS,QAAQ,QAAQ;AAMlC,SAASC,oBAAoB,QAAQ,8B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BG,mBAAmBiB;IAE5D;;;;;;;;;;;;;;;;;GAiBC,GACD,MAAMmB,WACJhC,WAAW8B,aACXC,YAAYE,QAAQ,KAAKH,aACzBC,YAAYE,QAAQ,CAACC,OAAO,CAACC,QAAQ,CAAC;IAExC,qBACE,KAAC/C;QACCQ,mBAAmBA;QACnBI,QAAQA;QACR,yEAAyE;QACzE,uEAAuE;QACvE,yEAAyE;QACzE,kDAAkD;QAClDoC,MAAMJ,WAAW,SAAS;QAC1Bb,QAAQF,KAAKE,MAAM;QACnBkB,eAAepB,KAAKqB,QAAQ;QAC5BjB,aAAaA;QACbkB,cAActB,KAAKuB,OAAO;QAC1BC,QAAQxB,KAAKwB,MAAM;QACnBC,WAAWzB,KAAKyB,SAAS;QACzBxB,UAAUD,KAAK0B,MAAM;QACrBnC,UAAUA;QACVC,cAAcA;OACVsB;QACJjB,WAAWA;QACXb,WAAWA;QACXC,UAAUA;QACVC,WAAWA;QACXC,YAAYA;QACZC,OAAOA;QACPC,SAASA;QACTI,UAAUA;QACVC,YAAYA;QACZ,oEAAoE;QACpE,2DAA2D;QAC3DiC,OAAO7B,GACLf,UAAUC,YACN,GAAGJ,WAAW,eAAe,CAAC,GAC9B,GAAGA,WAAW,cAAc,CAAC;kBAGlCC,aAAa+C,GAAG,CAACrB,CAAAA,sBAChB,KAACrC;gBAAiCqC,OAAOA;gBAAOsB,MAAM;eAA3BtB;;AAInC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"make-entity-crud.d.ts","sourceRoot":"","sources":["../../../src/lib/crud/make-entity-crud.tsx"],"names":[],"mappings":"AAEA,OAAO,
|
|
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;AAkBvB,OAAO,EAAS,OAAO,EAAgB,MAAM,QAAQ,CAAC;AAQtD,OAAO,KAAK,EAEV,UAAU,EAEV,iBAAiB,EAElB,MAAM,6BAA6B,CAAC;AAUrC;;;;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,CAsiBrB"}
|
|
@@ -3,12 +3,13 @@ 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 { EntityTable, useCasesForSurface } from '@entifix/react-controls';
|
|
7
|
-
import { entityQueryScope, useDataLoading, useEntityRecord, useOptimisticMutation } from '@entifix/react-integration';
|
|
6
|
+
import { EntityColumn, EntityTable, useCasesForSurface, useFocusOnArrival, useT, useToasts } from '@entifix/react-controls';
|
|
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
10
|
import { useParams, useRouter } from 'next/navigation';
|
|
11
11
|
import { useEffect, useRef } from 'react';
|
|
12
|
+
import { useBreadcrumbLabel } from '../back-office/breadcrumb-labels.js';
|
|
12
13
|
import { useLocaleHref } from '../i18n/index.js';
|
|
13
14
|
import { useEntityNavHost } from '../workspace/entity-nav.js';
|
|
14
15
|
import { EntityCrudForm } from './entity-crud-form.js';
|
|
@@ -16,6 +17,7 @@ import { CATALOG_NEW_SLUG, slugToEntityId } from './slug.js';
|
|
|
16
17
|
import { useCrudRenderLink } from './use-crud-render-link.js';
|
|
17
18
|
import { useEntityAffordances } from './use-entity-affordances.js';
|
|
18
19
|
import { useEntityBulk } from './use-entity-bulk.js';
|
|
20
|
+
import { LinkLabelCell, useLinkLabels } from './use-link-labels.js';
|
|
19
21
|
/** What a picker defaults to reading off its target. */ const TARGET_NAME_PROPERTY = 'name';
|
|
20
22
|
/**
|
|
21
23
|
* One repository adapter, by its key, as the context the use-cases run
|
|
@@ -124,7 +126,7 @@ import { useEntityBulk } from './use-entity-bulk.js';
|
|
|
124
126
|
return links.map((link)=>link.useBaseFiltering == null ? void 0 : link.useBaseFiltering.call(link, record));
|
|
125
127
|
}
|
|
126
128
|
export function makeEntityCrud(entityConstructor, options) {
|
|
127
|
-
const { useAdapters, basePath, catalogKey, repository, hiddenFields = [], columns, toolbar, pageSize, initialFiltering, links = [], metadataSource: givenMetadataSource, metadata, useCases, write } = options;
|
|
129
|
+
const { useAdapters, basePath, catalogKey, repository, hiddenFields = [], columns, toolbar, pageSize, initialFiltering, links = [], metadataSource: givenMetadataSource, metadata, useCases, write, delete: deletePolicy = 'confirm', facets } = options;
|
|
128
130
|
if (givenMetadataSource !== undefined && metadata !== undefined) {
|
|
129
131
|
throw new Error(`${entityConstructor.name} was given both metadataSource and metadata; pass one`);
|
|
130
132
|
}
|
|
@@ -158,6 +160,9 @@ export function makeEntityCrud(entityConstructor, options) {
|
|
|
158
160
|
if (entityLabelKey === undefined || entityPluralKey === undefined) {
|
|
159
161
|
throw new Error(`${entityConstructor.name} must declare labelKey and pluralKey on @entity() to be generated`);
|
|
160
162
|
}
|
|
163
|
+
// Narrowed once, for the closures below that TypeScript cannot follow.
|
|
164
|
+
const labelKey = entityLabelKey;
|
|
165
|
+
const pluralKey = entityPluralKey;
|
|
161
166
|
// Computed once: a descriptor is a property of the class, so nothing about it
|
|
162
167
|
// depends on the record being edited. `linkLabelProperty`/`linkSearchProperty`
|
|
163
168
|
// are overridden here because a scalar foreign key's `@accessor()` cannot name
|
|
@@ -167,6 +172,18 @@ export function makeEntityCrud(entityConstructor, options) {
|
|
|
167
172
|
// disagree about which entity they mean.
|
|
168
173
|
const entityName = envelopeEntityName(entityConstructor);
|
|
169
174
|
const descriptors = describeEntityColumns(entityConstructor);
|
|
175
|
+
/** The members a filter panel offers choices for, and so counts. */ const facetMembers = descriptors.filter((descriptor)=>descriptor.filterable && (descriptor.type === 'enum' || descriptor.type === 'boolean')).map(({ name, key })=>({
|
|
176
|
+
name,
|
|
177
|
+
key
|
|
178
|
+
}));
|
|
179
|
+
/** A record as the reader knows it: its first shown member that is filled in. */ const recordLabelOf = (record)=>{
|
|
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
|
+
};
|
|
170
187
|
const linkPlans = links.map((link)=>{
|
|
171
188
|
var _link_labelProperty, _link_searchProperty;
|
|
172
189
|
const descriptor = descriptors.find((entry)=>entry.name === link.field);
|
|
@@ -206,6 +223,25 @@ export function makeEntityCrud(entityConstructor, options) {
|
|
|
206
223
|
}, initialFiltering === undefined ? {} : {
|
|
207
224
|
initialFiltering
|
|
208
225
|
}));
|
|
226
|
+
// A member that holds another record's id reads as that record's name.
|
|
227
|
+
const linkLabel = useLinkLabels(linkPlans.map((plan)=>({
|
|
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));
|
|
239
|
+
const facetCounts = useFacetCounts({
|
|
240
|
+
ctx: facets === undefined ? undefined : adapters[facets],
|
|
241
|
+
members: facetMembers,
|
|
242
|
+
filtering: pager.filtering,
|
|
243
|
+
scope
|
|
244
|
+
});
|
|
209
245
|
// Only when this caller may actually run something over a selection.
|
|
210
246
|
//
|
|
211
247
|
// Measured live: an `admin` holds `catalog-reference:*:read` and no
|
|
@@ -255,24 +291,40 @@ export function makeEntityCrud(entityConstructor, options) {
|
|
|
255
291
|
if (item.id == null) return;
|
|
256
292
|
rowVerb.run(key, item.id);
|
|
257
293
|
} : undefined;
|
|
258
|
-
|
|
294
|
+
// The list's heading, and where focus lands when a save or a delete
|
|
295
|
+
// brings the reader back here rather than falling to `<body>`.
|
|
296
|
+
const heading = useRef(null);
|
|
297
|
+
useFocusOnArrival(heading);
|
|
298
|
+
const et = useT('entity');
|
|
299
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
259
300
|
className: "flex flex-col gap-s",
|
|
260
|
-
children:
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
301
|
+
children: [
|
|
302
|
+
/*#__PURE__*/ _jsx("h1", {
|
|
303
|
+
ref: heading,
|
|
304
|
+
tabIndex: -1,
|
|
305
|
+
className: "m-0 text-step-2 font-semibold text-content focus-ring",
|
|
306
|
+
children: et(pluralKey.replace(/^entity:/, ''))
|
|
307
|
+
}),
|
|
308
|
+
/*#__PURE__*/ _jsxs(EntityTable, _extends({
|
|
309
|
+
entityConstructor: entityConstructor
|
|
310
|
+
}, pager, {
|
|
311
|
+
items: pager.items,
|
|
312
|
+
totalItems: pager.totalItems,
|
|
313
|
+
hrefFor: (id)=>withLocale(`${basePath}/${String(id)}`),
|
|
314
|
+
newHref: withLocale(`${basePath}/${CATALOG_NEW_SLUG}`),
|
|
315
|
+
renderLink: renderLink
|
|
316
|
+
}, affordances, bulk.tableProps, {
|
|
317
|
+
onUseCase: handleRowUseCase,
|
|
318
|
+
onRetry: pager.refetch,
|
|
319
|
+
facets: facetCounts,
|
|
320
|
+
error: (_syncFailure = syncFailure(rowVerb.verb)) != null ? _syncFailure : pager.error,
|
|
321
|
+
children: [
|
|
322
|
+
columns,
|
|
323
|
+
linkColumns,
|
|
324
|
+
toolbar
|
|
325
|
+
]
|
|
326
|
+
}))
|
|
327
|
+
]
|
|
276
328
|
});
|
|
277
329
|
}
|
|
278
330
|
/**
|
|
@@ -378,13 +430,59 @@ export function makeEntityCrud(entityConstructor, options) {
|
|
|
378
430
|
if ((result == null ? void 0 : result._tag) !== 'settled') return;
|
|
379
431
|
draft == null ? void 0 : draft.clear();
|
|
380
432
|
void refreshList();
|
|
433
|
+
// Said in the toast region every route shares, so it survives the
|
|
434
|
+
// navigation that follows (ADR 0028).
|
|
435
|
+
toasts == null ? void 0 : toasts.show({
|
|
436
|
+
tone: 'success',
|
|
437
|
+
message: ct('state.saved', {
|
|
438
|
+
object: recordNoun(next)
|
|
439
|
+
})
|
|
440
|
+
});
|
|
381
441
|
afterSave();
|
|
382
442
|
};
|
|
443
|
+
const toasts = useToasts();
|
|
444
|
+
const ct = useT('controls');
|
|
445
|
+
const et = useT('entity');
|
|
446
|
+
/** What an announcement names: the record, or the entity for a blank one. */ const recordNoun = (record)=>{
|
|
447
|
+
var _recordLabelOf;
|
|
448
|
+
return (_recordLabelOf = recordLabelOf(record)) != null ? _recordLabelOf : et(labelKey.replace(/^entity:/, ''));
|
|
449
|
+
};
|
|
450
|
+
// The breadcrumb for this page's segment names the record, never its id:
|
|
451
|
+
// "Nuevo" for a create, the record once it has loaded.
|
|
452
|
+
useBreadcrumbLabel(slug != null ? slug : params.slug, id == null ? ct('form.new') : entity && recordNoun(entity));
|
|
453
|
+
/**
|
|
454
|
+
* Saves a deleted record back under its id: what Undo runs under the
|
|
455
|
+
* `undo` policy.
|
|
456
|
+
*/ const restore = (record)=>Effect.runPromise(writer === undefined ? Effect.asVoid(Effect.provide(saveUCFactory(), ctx.pipe(Context.add(EntityTag, record)))) : Effect.asVoid(writer.save(record))).then(()=>refreshList(), (failure)=>{
|
|
457
|
+
toasts == null ? void 0 : toasts.show({
|
|
458
|
+
tone: 'failure',
|
|
459
|
+
failure: asFailure(failure)
|
|
460
|
+
});
|
|
461
|
+
});
|
|
383
462
|
const handleDelete = async ()=>{
|
|
463
|
+
const snapshot = entity;
|
|
384
464
|
const result = await deleteMutation.mutate(id).catch(()=>undefined);
|
|
385
465
|
if ((result == null ? void 0 : result._tag) !== 'settled') return;
|
|
386
466
|
draft == null ? void 0 : draft.clear();
|
|
387
467
|
void refreshList();
|
|
468
|
+
// Said once, in the toast region every route shares, so it survives the
|
|
469
|
+
// navigation back to the list.
|
|
470
|
+
const object = recordNoun(snapshot);
|
|
471
|
+
const message = ct('confirm.deleted', {
|
|
472
|
+
object
|
|
473
|
+
});
|
|
474
|
+
if (deletePolicy === 'undo' && snapshot !== undefined) toasts == null ? void 0 : toasts.show({
|
|
475
|
+
tone: 'undo',
|
|
476
|
+
message,
|
|
477
|
+
action: {
|
|
478
|
+
label: ct('confirm.undo'),
|
|
479
|
+
onAction: ()=>void restore(snapshot)
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
else toasts == null ? void 0 : toasts.show({
|
|
483
|
+
tone: 'success',
|
|
484
|
+
message
|
|
485
|
+
});
|
|
388
486
|
afterDelete();
|
|
389
487
|
};
|
|
390
488
|
/**
|
|
@@ -423,7 +521,9 @@ export function makeEntityCrud(entityConstructor, options) {
|
|
|
423
521
|
isDeleting: deleteMutation.status === 'running',
|
|
424
522
|
error: (_ref = (_ref1 = loadError != null ? loadError : syncFailure(saveMutation)) != null ? _ref1 : syncFailure(deleteMutation)) != null ? _ref : syncFailure(recordVerb.verb),
|
|
425
523
|
onSave: handleSave,
|
|
524
|
+
onRetry: loadError === undefined ? undefined : reload,
|
|
426
525
|
onDelete: id == null ? undefined : handleDelete,
|
|
526
|
+
deletePolicy: deletePolicy,
|
|
427
527
|
onUseCase: handleUseCase,
|
|
428
528
|
backHref: withLocale(basePath),
|
|
429
529
|
renderLink: renderLink,
|