@entifix/react-integration 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/dist/hooks/use-entity-link-source/use-entity-link-source.d.ts +1 -1
- package/dist/hooks/use-entity-link-source/use-entity-link-source.d.ts.map +1 -1
- package/dist/hooks/use-entity-link-source/use-entity-link-source.js +35 -15
- package/dist/hooks/use-entity-link-source/use-entity-link-source.js.map +1 -1
- package/dist/hooks/use-entity-link-source/use-entity-link-source.types.d.ts +7 -1
- package/dist/hooks/use-entity-link-source/use-entity-link-source.types.d.ts.map +1 -1
- package/dist/hooks/use-entity-link-source/use-entity-link-source.types.js.map +1 -1
- package/package.json +5 -5
|
@@ -21,5 +21,5 @@ import type { EntityLinkSourceConfig, UseEntityLinkSourceOptions } from './use-e
|
|
|
21
21
|
* an id but no instance — a draft restored from storage — because a picked target
|
|
22
22
|
* already knows its own name.
|
|
23
23
|
*/
|
|
24
|
-
export declare function useEntityLinkSource<TTarget extends Entity, TContext>(config: EntityLinkSourceConfig<TTarget, TContext>, { descriptor, selectedId, selectedEntity, }: UseEntityLinkSourceOptions<TTarget>): EntityLinkSource<TTarget>;
|
|
24
|
+
export declare function useEntityLinkSource<TTarget extends Entity, TContext>(config: EntityLinkSourceConfig<TTarget, TContext>, { descriptor, selectedId, selectedEntity, locale, }: UseEntityLinkSourceOptions<TTarget>): EntityLinkSource<TTarget>;
|
|
25
25
|
//# sourceMappingURL=use-entity-link-source.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-entity-link-source.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-entity-link-source/use-entity-link-source.ts"],"names":[],"mappings":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"use-entity-link-source.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-entity-link-source/use-entity-link-source.ts"],"names":[],"mappings":"AAGA,OAAO,EAIL,KAAK,MAAM,EAEX,KAAK,gBAAgB,EAItB,MAAM,eAAe,CAAC;AAWvB,OAAO,KAAK,EACV,sBAAsB,EACtB,0BAA0B,EAC3B,MAAM,mCAAmC,CAAC;AAgC3C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,SAAS,MAAM,EAAE,QAAQ,EAClE,MAAM,EAAE,sBAAsB,CAAC,OAAO,EAAE,QAAQ,CAAC,EACjD,EACE,UAAU,EACV,UAAU,EACV,cAAc,EACd,MAAwB,GACzB,EAAE,0BAA0B,CAAC,OAAO,CAAC,GACrC,gBAAgB,CAAC,OAAO,CAAC,CA8K3B"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
3
3
|
import { EntityIdTag, EntityLoadRequestTag } from '@entifix/business';
|
|
4
|
-
import { describeEntityColumns } from '@entifix/core';
|
|
4
|
+
import { defaultLocale, describeEntityColumns, localizedQueryProperty } from '@entifix/core';
|
|
5
5
|
import { useQuery } from '@tanstack/react-query';
|
|
6
6
|
import { Context, Effect } from 'effect';
|
|
7
7
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
@@ -11,20 +11,17 @@ import { useDataLoading } from '../use-data-loading/index.js';
|
|
|
11
11
|
const DEFAULT_QUICK_PAGE_SIZE = 10;
|
|
12
12
|
const DEFAULT_DEBOUNCE_MS = 250;
|
|
13
13
|
/**
|
|
14
|
-
* Fails loudly on a search property the service will reject
|
|
14
|
+
* Fails loudly on a search property the service will reject, and returns its
|
|
15
|
+
* descriptor.
|
|
15
16
|
*
|
|
16
17
|
* A member's `filterable` metadata is also the server-side filter allowlist, so a
|
|
17
18
|
* quick search over a member that lacks it answers `400` — as an empty
|
|
18
19
|
* suggestion list, which reads to the user as "there are no brands". Better to
|
|
19
|
-
* break the developer's build than to lie to them.
|
|
20
|
+
* break the developer's build than to lie to them. A `localized` member is
|
|
21
|
+
* searchable like any other: it is queried in the reader's locale.
|
|
20
22
|
*/ function assertSearchable(config, searchProperty) {
|
|
21
23
|
const target = describeEntityColumns(config.entityConstructor).find((column)=>column.name === searchProperty);
|
|
22
|
-
if ((target == null ? void 0 : target.
|
|
23
|
-
// Queried one locale at a time, and this hook holds no locale: the bare
|
|
24
|
-
// member is what the service would refuse.
|
|
25
|
-
throw new Error(`Cannot search ${config.entityConstructor.name} by "${searchProperty}": ` + 'the member is localized, and a quick search has no locale to search ' + 'it in. Point the relation at a string member with `linkSearchProperty`.');
|
|
26
|
-
}
|
|
27
|
-
if ((target == null ? void 0 : target.filterable) === true) return;
|
|
24
|
+
if ((target == null ? void 0 : target.filterable) === true) return target;
|
|
28
25
|
throw new Error(`Cannot search ${config.entityConstructor.name} by "${searchProperty}": ` + 'the member is not filterable, so the service would reject the query. ' + 'Declare it `filterable` on the target entity, or point the relation at ' + 'another member with `linkSearchProperty`.');
|
|
29
26
|
}
|
|
30
27
|
/**
|
|
@@ -47,12 +44,17 @@ const DEFAULT_DEBOUNCE_MS = 250;
|
|
|
47
44
|
* all until the dialog opens; and the label is only looked up when the caller has
|
|
48
45
|
* an id but no instance — a draft restored from storage — because a picked target
|
|
49
46
|
* already knows its own name.
|
|
50
|
-
*/ export function useEntityLinkSource(config, { descriptor, selectedId, selectedEntity }) {
|
|
47
|
+
*/ export function useEntityLinkSource(config, { descriptor, selectedId, selectedEntity, locale = defaultLocale() }) {
|
|
51
48
|
var _ref, _quickQuery_error;
|
|
52
49
|
var _quickQuery_data;
|
|
53
50
|
const { entityConstructor, loadUc, getUc, ctx, baseFiltering, quickPageSize = DEFAULT_QUICK_PAGE_SIZE, debounceMs = DEFAULT_DEBOUNCE_MS } = config;
|
|
54
|
-
const
|
|
55
|
-
|
|
51
|
+
const searchDescriptor = assertSearchable(config, descriptor.linkSearchProperty);
|
|
52
|
+
// A localized member is filtered and sorted one locale at a time — the
|
|
53
|
+
// reader's — and its options read in that locale.
|
|
54
|
+
const search = localizedQueryProperty(searchDescriptor, locale);
|
|
55
|
+
const searchProperty = search.property;
|
|
56
|
+
const labelDescriptor = describeEntityColumns(entityConstructor).find((column)=>column.name === descriptor.linkLabelProperty);
|
|
57
|
+
const isLocalizedSearch = searchDescriptor.type === 'localized';
|
|
56
58
|
// Callers rebuild `loadUc`/`getUc`/`ctx` inline on every render, so the latest
|
|
57
59
|
// are held in refs and kept out of the query keys — keying on their identity
|
|
58
60
|
// would refetch on every render. Same reason and same shape as `useDataLoading`.
|
|
@@ -98,10 +100,23 @@ const DEFAULT_DEBOUNCE_MS = 250;
|
|
|
98
100
|
if (filtering) request.filtering = [
|
|
99
101
|
filtering
|
|
100
102
|
];
|
|
103
|
+
// Suggestions in one locale's order, so they do not reshuffle as records
|
|
104
|
+
// are rewritten — the service applies no order of its own.
|
|
105
|
+
if (isLocalizedSearch) {
|
|
106
|
+
request.sorting = [
|
|
107
|
+
{
|
|
108
|
+
0: {
|
|
109
|
+
property: searchProperty,
|
|
110
|
+
type: 'asc'
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
];
|
|
114
|
+
}
|
|
101
115
|
return request;
|
|
102
116
|
}, [
|
|
103
117
|
baseFiltering,
|
|
104
118
|
debouncedTerm,
|
|
119
|
+
isLocalizedSearch,
|
|
105
120
|
quickPageSize,
|
|
106
121
|
searchProperty
|
|
107
122
|
]);
|
|
@@ -136,10 +151,15 @@ const DEFAULT_DEBOUNCE_MS = 250;
|
|
|
136
151
|
// an unnamed row must still be distinguishable from the row above it.
|
|
137
152
|
const labelOf = useCallback((target)=>{
|
|
138
153
|
var _target_id;
|
|
139
|
-
const
|
|
140
|
-
|
|
154
|
+
const raw = target[descriptor.linkLabelProperty];
|
|
155
|
+
// A label member the target does not declare reads as nothing, so the
|
|
156
|
+
// option falls back to its id.
|
|
157
|
+
const label = labelDescriptor && localizedQueryProperty(labelDescriptor, locale).read(raw);
|
|
158
|
+
return label ? label : String((_target_id = target.id) != null ? _target_id : '');
|
|
141
159
|
}, [
|
|
142
|
-
descriptor.linkLabelProperty
|
|
160
|
+
descriptor.linkLabelProperty,
|
|
161
|
+
labelDescriptor,
|
|
162
|
+
locale
|
|
143
163
|
]);
|
|
144
164
|
const resolved = selectedEntity != null ? selectedEntity : labelQuery.data;
|
|
145
165
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/hooks/use-entity-link-source/use-entity-link-source.ts"],"sourcesContent":["'use client';\n\nimport { EntityIdTag, EntityLoadRequestTag } from '@entifix/business';\nimport {\n describeEntityColumns,\n type EntifixFailure,\n type Entity,\n type EntityLinkSource,\n type EntityLoadRequest,\n type EntityPage,\n} from '@entifix/core';\nimport { useQuery } from '@tanstack/react-query';\nimport { Context, Effect } from 'effect';\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\n\nimport { combineFilterGroups } from '../../query/combine-filtering.js';\nimport {\n entityQueryKey,\n entityQueryScope,\n} from '../../query/entity-query-key.js';\nimport { useDataLoading } from '../use-data-loading/index.js';\nimport type {\n EntityLinkSourceConfig,\n UseEntityLinkSourceOptions,\n} from './use-entity-link-source.types.js';\n\nconst DEFAULT_QUICK_PAGE_SIZE = 10;\nconst DEFAULT_DEBOUNCE_MS = 250;\n\n/**\n * Fails loudly on a search property the service will reject.\n *\n * A member's `filterable` metadata is also the server-side filter allowlist, so a\n * quick search over a member that lacks it answers `400` — as an empty\n * suggestion list, which reads to the user as \"there are no brands\". Better to\n * break the developer's build than to lie to them.\n */\nfunction assertSearchable<TTarget extends Entity>(\n config: EntityLinkSourceConfig<TTarget, unknown>,\n searchProperty: string,\n): void {\n const target = describeEntityColumns(config.entityConstructor).find(\n column => column.name === searchProperty,\n );\n if (target?.type === 'localized') {\n // Queried one locale at a time, and this hook holds no locale: the bare\n // member is what the service would refuse.\n throw new Error(\n `Cannot search ${config.entityConstructor.name} by \"${searchProperty}\": ` +\n 'the member is localized, and a quick search has no locale to search ' +\n 'it in. Point the relation at a string member with `linkSearchProperty`.',\n );\n }\n if (target?.filterable === true) return;\n\n throw new Error(\n `Cannot search ${config.entityConstructor.name} by \"${searchProperty}\": ` +\n 'the member is not filterable, so the service would reject the query. ' +\n 'Declare it `filterable` on the target entity, or point the relation at ' +\n 'another member with `linkSearchProperty`.',\n );\n}\n\n/**\n * Produces the {@link EntityLinkSource} a link editor runs on: the quick\n * type-ahead, the browse list, and the label of whatever key is currently held.\n *\n * This is the data half of the link mechanism. It exists as a hook — rather than\n * inside the input — because `@entifix/react-controls` may not import this package\n * (both are T3, and the tier register declares no sideways edge between them), so\n * the two meet at the framework-free port declared in `@entifix/core`. A form\n * wrapper calls it once per relation and hands the results to `EntityForm`'s\n * `linkSources`.\n *\n * What may be picked is never decided here: the caller's `loadUc` (and optional\n * `baseFiltering`) is what restricts the set, so a domain rule about assignable\n * targets lives in a use-case, not in the UI.\n *\n * Three requests, each held back until it means something: the quick search runs\n * a small page and re-runs on a debounced term; the browse list does not fetch at\n * all until the dialog opens; and the label is only looked up when the caller has\n * an id but no instance — a draft restored from storage — because a picked target\n * already knows its own name.\n */\nexport function useEntityLinkSource<TTarget extends Entity, TContext>(\n config: EntityLinkSourceConfig<TTarget, TContext>,\n {\n descriptor,\n selectedId,\n selectedEntity,\n }: UseEntityLinkSourceOptions<TTarget>,\n): EntityLinkSource<TTarget> {\n const {\n entityConstructor,\n loadUc,\n getUc,\n ctx,\n baseFiltering,\n quickPageSize = DEFAULT_QUICK_PAGE_SIZE,\n debounceMs = DEFAULT_DEBOUNCE_MS,\n } = config;\n\n const searchProperty = descriptor.linkSearchProperty;\n assertSearchable(\n config as unknown as EntityLinkSourceConfig<TTarget, unknown>,\n searchProperty,\n );\n\n // Callers rebuild `loadUc`/`getUc`/`ctx` inline on every render, so the latest\n // are held in refs and kept out of the query keys — keying on their identity\n // would refetch on every render. Same reason and same shape as `useDataLoading`.\n const effects = useRef({ loadUc, getUc, ctx });\n useEffect(() => {\n effects.current = { loadUc, getUc, ctx };\n });\n\n const [term, setTerm] = useState('');\n const [debouncedTerm, setDebouncedTerm] = useState('');\n const [isOpen, setOpen] = useState(false);\n\n // Typing is not a request per keystroke: the term settles first, and only the\n // settled value reaches the service.\n useEffect(() => {\n const timer = setTimeout(() => setDebouncedTerm(term), debounceMs);\n return () => clearTimeout(timer);\n }, [term, debounceMs]);\n\n const quickRequest = useMemo<EntityLoadRequest<TTarget>>(() => {\n const filtering = combineFilterGroups<TTarget>(\n baseFiltering,\n debouncedTerm === ''\n ? undefined\n : {\n operator: 'and',\n values: [\n {\n property: searchProperty as keyof TTarget,\n operator: 'like',\n value: debouncedTerm,\n },\n ],\n },\n );\n\n const request: EntityLoadRequest<TTarget> = {\n page: 1,\n pageSize: quickPageSize,\n };\n if (filtering) request.filtering = [filtering];\n return request;\n }, [baseFiltering, debouncedTerm, quickPageSize, searchProperty]);\n\n const quickQuery = useQuery<EntityPage<TTarget>, EntifixFailure>({\n queryKey: [\n ...entityQueryKey(entityConstructor, quickRequest),\n 'link-quick',\n ],\n queryFn: () =>\n Effect.runPromise(\n Effect.provide(\n effects.current.loadUc,\n effects.current.ctx.pipe(\n Context.add(\n EntityLoadRequestTag,\n // The tag carries no generic, so the entity-typed request crosses\n // it — the same cast `loadUCFactory` makes reading it back.\n quickRequest as unknown as EntityLoadRequest,\n ),\n ),\n ),\n ),\n });\n\n const browse = useDataLoading<TTarget, TContext>({\n uc: loadUc,\n ctx,\n queryKey: entityQueryScope(entityConstructor),\n baseFiltering,\n enabled: isOpen,\n });\n\n const needsLabel =\n selectedEntity === undefined && selectedId != null && getUc !== undefined;\n\n const labelQuery = useQuery<TTarget, EntifixFailure>({\n queryKey: [\n ...entityQueryScope(entityConstructor),\n 'link-label',\n String(selectedId),\n ],\n enabled: needsLabel,\n queryFn: () =>\n Effect.runPromise(\n Effect.provide(\n // Guarded by `enabled`: the query only runs when both are present.\n effects.current.getUc as NonNullable<typeof getUc>,\n effects.current.ctx.pipe(Context.add(EntityIdTag, selectedId)),\n ),\n ),\n });\n\n // A blank label is as useless as a missing one, so both fall back to the key —\n // an unnamed row must still be distinguishable from the row above it.\n const labelOf = useCallback(\n (target: TTarget) => {\n const label = (target as Record<string, unknown>)[\n descriptor.linkLabelProperty\n ];\n return label == null || label === ''\n ? String(target.id ?? '')\n : String(label);\n },\n [descriptor.linkLabelProperty],\n );\n\n const resolved = selectedEntity ?? labelQuery.data;\n\n return {\n entityConstructor,\n labelOf,\n selected: {\n label: resolved === undefined ? undefined : labelOf(resolved),\n // The whole target, not only its name. The lookup above already fetched\n // it, and a form restoring a draft has nothing else to rebuild an\n // `embedded` relation from — the draft kept the id and lost the instance.\n entity: resolved,\n isLoading: needsLabel && labelQuery.isFetching,\n },\n quick: {\n term,\n setTerm,\n options: quickQuery.data?.items ?? [],\n isLoading: quickQuery.isFetching,\n error: quickQuery.error ?? undefined,\n },\n browse: {\n ...browse,\n isOpen,\n open: () => setOpen(true),\n close: () => setOpen(false),\n },\n };\n}\n"],"names":["EntityIdTag","EntityLoadRequestTag","describeEntityColumns","useQuery","Context","Effect","useCallback","useEffect","useMemo","useRef","useState","combineFilterGroups","entityQueryKey","entityQueryScope","useDataLoading","DEFAULT_QUICK_PAGE_SIZE","DEFAULT_DEBOUNCE_MS","assertSearchable","config","searchProperty","target","entityConstructor","find","column","name","type","Error","filterable","useEntityLinkSource","descriptor","selectedId","selectedEntity","quickQuery","loadUc","getUc","ctx","baseFiltering","quickPageSize","debounceMs","linkSearchProperty","effects","current","term","setTerm","debouncedTerm","setDebouncedTerm","isOpen","setOpen","timer","setTimeout","clearTimeout","quickRequest","filtering","undefined","operator","values","property","value","request","page","pageSize","queryKey","queryFn","runPromise","provide","pipe","add","browse","uc","enabled","needsLabel","labelQuery","String","labelOf","label","linkLabelProperty","id","resolved","data","selected","entity","isLoading","isFetching","quick","options","items","error","open","close"],"mappings":"AAAA;;AAEA,SAASA,WAAW,EAAEC,oBAAoB,QAAQ,oBAAoB;AACtE,SACEC,qBAAqB,QAMhB,gBAAgB;AACvB,SAASC,QAAQ,QAAQ,wBAAwB;AACjD,SA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AElE,MAAMkB,aAAapE,SAAkC;QACnD0D,UAAU;eACLhD,iBAAiBQ;YACpB;YACAmD,OAAO1C;SACR;QACDuC,SAASC;QACTR,SAAS,IACPzD,OAAO0D,UAAU,CACf1D,OAAO2D,OAAO,CACZ,mEAAmE;YACnExB,QAAQC,OAAO,CAACP,KAAK,EACrBM,QAAQC,OAAO,CAACN,GAAG,CAAC8B,IAAI,CAAC7D,QAAQ8D,GAAG,CAAClE,aAAa8B;IAG1D;IAEA,+EAA+E;IAC/E,sEAAsE;IACtE,MAAM2C,UAAUnE,YACd,CAACc;YAKYA;QAJX,MAAMsD,QAAQ,AAACtD,MAAkC,CAC/CS,WAAW8C,iBAAiB,CAC7B;QACD,OAAOD,SAAS,QAAQA,UAAU,KAC9BF,QAAOpD,aAAAA,OAAOwD,EAAE,YAATxD,aAAa,MACpBoD,OAAOE;IACb,GACA;QAAC7C,WAAW8C,iBAAiB;KAAC;IAGhC,MAAME,WAAW9C,yBAAAA,iBAAkBwC,WAAWO,IAAI;IAElD,OAAO;QACLzD;QACAoD;QACAM,UAAU;YACRL,OAAOG,aAAaxB,YAAYA,YAAYoB,QAAQI;YACpD,wEAAwE;YACxE,kEAAkE;YAClE,0EAA0E;YAC1EG,QAAQH;YACRI,WAAWX,cAAcC,WAAWW,UAAU;QAChD;QACAC,OAAO;YACLzC;YACAC;YACAyC,OAAO,WAAEpD,mBAAAA,WAAW8C,IAAI,qBAAf9C,iBAAiBqD,KAAK,mBAAI,EAAE;YACrCJ,WAAWjD,WAAWkD,UAAU;YAChCI,KAAK,GAAEtD,oBAAAA,WAAWsD,KAAK,YAAhBtD,oBAAoBqB;QAC7B;QACAc,QAAQ,aACHA;YACHrB;YACAyC,MAAM,IAAMxC,QAAQ;YACpByC,OAAO,IAAMzC,QAAQ;;IAEzB;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/use-entity-link-source/use-entity-link-source.ts"],"sourcesContent":["'use client';\n\nimport { EntityIdTag, EntityLoadRequestTag } from '@entifix/business';\nimport {\n defaultLocale,\n describeEntityColumns,\n type EntifixFailure,\n type Entity,\n type EntityFieldDescriptor,\n type EntityLinkSource,\n type EntityLoadRequest,\n type EntityPage,\n localizedQueryProperty,\n} from '@entifix/core';\nimport { useQuery } from '@tanstack/react-query';\nimport { Context, Effect } from 'effect';\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\n\nimport { combineFilterGroups } from '../../query/combine-filtering.js';\nimport {\n entityQueryKey,\n entityQueryScope,\n} from '../../query/entity-query-key.js';\nimport { useDataLoading } from '../use-data-loading/index.js';\nimport type {\n EntityLinkSourceConfig,\n UseEntityLinkSourceOptions,\n} from './use-entity-link-source.types.js';\n\nconst DEFAULT_QUICK_PAGE_SIZE = 10;\nconst DEFAULT_DEBOUNCE_MS = 250;\n\n/**\n * Fails loudly on a search property the service will reject, and returns its\n * descriptor.\n *\n * A member's `filterable` metadata is also the server-side filter allowlist, so a\n * quick search over a member that lacks it answers `400` — as an empty\n * suggestion list, which reads to the user as \"there are no brands\". Better to\n * break the developer's build than to lie to them. A `localized` member is\n * searchable like any other: it is queried in the reader's locale.\n */\nfunction assertSearchable<TTarget extends Entity>(\n config: EntityLinkSourceConfig<TTarget, unknown>,\n searchProperty: string,\n): EntityFieldDescriptor {\n const target = describeEntityColumns(config.entityConstructor).find(\n column => column.name === searchProperty,\n );\n if (target?.filterable === true) return target;\n\n throw new Error(\n `Cannot search ${config.entityConstructor.name} by \"${searchProperty}\": ` +\n 'the member is not filterable, so the service would reject the query. ' +\n 'Declare it `filterable` on the target entity, or point the relation at ' +\n 'another member with `linkSearchProperty`.',\n );\n}\n\n/**\n * Produces the {@link EntityLinkSource} a link editor runs on: the quick\n * type-ahead, the browse list, and the label of whatever key is currently held.\n *\n * This is the data half of the link mechanism. It exists as a hook — rather than\n * inside the input — because `@entifix/react-controls` may not import this package\n * (both are T3, and the tier register declares no sideways edge between them), so\n * the two meet at the framework-free port declared in `@entifix/core`. A form\n * wrapper calls it once per relation and hands the results to `EntityForm`'s\n * `linkSources`.\n *\n * What may be picked is never decided here: the caller's `loadUc` (and optional\n * `baseFiltering`) is what restricts the set, so a domain rule about assignable\n * targets lives in a use-case, not in the UI.\n *\n * Three requests, each held back until it means something: the quick search runs\n * a small page and re-runs on a debounced term; the browse list does not fetch at\n * all until the dialog opens; and the label is only looked up when the caller has\n * an id but no instance — a draft restored from storage — because a picked target\n * already knows its own name.\n */\nexport function useEntityLinkSource<TTarget extends Entity, TContext>(\n config: EntityLinkSourceConfig<TTarget, TContext>,\n {\n descriptor,\n selectedId,\n selectedEntity,\n locale = defaultLocale(),\n }: UseEntityLinkSourceOptions<TTarget>,\n): EntityLinkSource<TTarget> {\n const {\n entityConstructor,\n loadUc,\n getUc,\n ctx,\n baseFiltering,\n quickPageSize = DEFAULT_QUICK_PAGE_SIZE,\n debounceMs = DEFAULT_DEBOUNCE_MS,\n } = config;\n\n const searchDescriptor = assertSearchable(\n config as unknown as EntityLinkSourceConfig<TTarget, unknown>,\n descriptor.linkSearchProperty,\n );\n // A localized member is filtered and sorted one locale at a time — the\n // reader's — and its options read in that locale.\n const search = localizedQueryProperty(searchDescriptor, locale);\n const searchProperty = search.property;\n const labelDescriptor = describeEntityColumns(entityConstructor).find(\n column => column.name === descriptor.linkLabelProperty,\n );\n const isLocalizedSearch = searchDescriptor.type === 'localized';\n\n // Callers rebuild `loadUc`/`getUc`/`ctx` inline on every render, so the latest\n // are held in refs and kept out of the query keys — keying on their identity\n // would refetch on every render. Same reason and same shape as `useDataLoading`.\n const effects = useRef({ loadUc, getUc, ctx });\n useEffect(() => {\n effects.current = { loadUc, getUc, ctx };\n });\n\n const [term, setTerm] = useState('');\n const [debouncedTerm, setDebouncedTerm] = useState('');\n const [isOpen, setOpen] = useState(false);\n\n // Typing is not a request per keystroke: the term settles first, and only the\n // settled value reaches the service.\n useEffect(() => {\n const timer = setTimeout(() => setDebouncedTerm(term), debounceMs);\n return () => clearTimeout(timer);\n }, [term, debounceMs]);\n\n const quickRequest = useMemo<EntityLoadRequest<TTarget>>(() => {\n const filtering = combineFilterGroups<TTarget>(\n baseFiltering,\n debouncedTerm === ''\n ? undefined\n : {\n operator: 'and',\n values: [\n {\n property: searchProperty as keyof TTarget,\n operator: 'like',\n value: debouncedTerm,\n },\n ],\n },\n );\n\n const request: EntityLoadRequest<TTarget> = {\n page: 1,\n pageSize: quickPageSize,\n };\n if (filtering) request.filtering = [filtering];\n // Suggestions in one locale's order, so they do not reshuffle as records\n // are rewritten — the service applies no order of its own.\n if (isLocalizedSearch) {\n request.sorting = [\n { 0: { property: searchProperty as keyof TTarget, type: 'asc' } },\n ];\n }\n return request;\n }, [\n baseFiltering,\n debouncedTerm,\n isLocalizedSearch,\n quickPageSize,\n searchProperty,\n ]);\n\n const quickQuery = useQuery<EntityPage<TTarget>, EntifixFailure>({\n queryKey: [\n ...entityQueryKey(entityConstructor, quickRequest),\n 'link-quick',\n ],\n queryFn: () =>\n Effect.runPromise(\n Effect.provide(\n effects.current.loadUc,\n effects.current.ctx.pipe(\n Context.add(\n EntityLoadRequestTag,\n // The tag carries no generic, so the entity-typed request crosses\n // it — the same cast `loadUCFactory` makes reading it back.\n quickRequest as unknown as EntityLoadRequest,\n ),\n ),\n ),\n ),\n });\n\n const browse = useDataLoading<TTarget, TContext>({\n uc: loadUc,\n ctx,\n queryKey: entityQueryScope(entityConstructor),\n baseFiltering,\n enabled: isOpen,\n });\n\n const needsLabel =\n selectedEntity === undefined && selectedId != null && getUc !== undefined;\n\n const labelQuery = useQuery<TTarget, EntifixFailure>({\n queryKey: [\n ...entityQueryScope(entityConstructor),\n 'link-label',\n String(selectedId),\n ],\n enabled: needsLabel,\n queryFn: () =>\n Effect.runPromise(\n Effect.provide(\n // Guarded by `enabled`: the query only runs when both are present.\n effects.current.getUc as NonNullable<typeof getUc>,\n effects.current.ctx.pipe(Context.add(EntityIdTag, selectedId)),\n ),\n ),\n });\n\n // A blank label is as useless as a missing one, so both fall back to the key —\n // an unnamed row must still be distinguishable from the row above it.\n const labelOf = useCallback(\n (target: TTarget) => {\n const raw = (target as Record<string, unknown>)[\n descriptor.linkLabelProperty\n ];\n // A label member the target does not declare reads as nothing, so the\n // option falls back to its id.\n const label =\n labelDescriptor &&\n localizedQueryProperty(labelDescriptor, locale).read(raw);\n return label ? label : String(target.id ?? '');\n },\n [descriptor.linkLabelProperty, labelDescriptor, locale],\n );\n\n const resolved = selectedEntity ?? labelQuery.data;\n\n return {\n entityConstructor,\n labelOf,\n selected: {\n label: resolved === undefined ? undefined : labelOf(resolved),\n // The whole target, not only its name. The lookup above already fetched\n // it, and a form restoring a draft has nothing else to rebuild an\n // `embedded` relation from — the draft kept the id and lost the instance.\n entity: resolved,\n isLoading: needsLabel && labelQuery.isFetching,\n },\n quick: {\n term,\n setTerm,\n options: quickQuery.data?.items ?? [],\n isLoading: quickQuery.isFetching,\n error: quickQuery.error ?? undefined,\n },\n browse: {\n ...browse,\n isOpen,\n open: () => setOpen(true),\n close: () => setOpen(false),\n },\n };\n}\n"],"names":["EntityIdTag","EntityLoadRequestTag","defaultLocale","describeEntityColumns","localizedQueryProperty","useQuery","Context","Effect","useCallback","useEffect","useMemo","useRef","useState","combineFilterGroups","entityQueryKey","entityQueryScope","useDataLoading","DEFAULT_QUICK_PAGE_SIZE","DEFAULT_DEBOUNCE_MS","assertSearchable","config","searchProperty","target","entityConstructor","find","column","name","filterable","Error","useEntityLinkSource","descriptor","selectedId","selectedEntity","locale","quickQuery","loadUc","getUc","ctx","baseFiltering","quickPageSize","debounceMs","searchDescriptor","linkSearchProperty","search","property","labelDescriptor","linkLabelProperty","isLocalizedSearch","type","effects","current","term","setTerm","debouncedTerm","setDebouncedTerm","isOpen","setOpen","timer","setTimeout","clearTimeout","quickRequest","filtering","undefined","operator","values","value","request","page","pageSize","sorting","queryKey","queryFn","runPromise","provide","pipe","add","browse","uc","enabled","needsLabel","labelQuery","String","labelOf","raw","label","read","id","resolved","data","selected","entity","isLoading","isFetching","quick","options","items","error","open","close"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AwE;YACxE,kEAAkE;YAClE,0EAA0E;YAC1EG,QAAQH;YACRI,WAAWZ,cAAcC,WAAWY,UAAU;QAChD;QACAC,OAAO;YACL1C;YACAC;YACA0C,OAAO,WAAE5D,mBAAAA,WAAWsD,IAAI,qBAAftD,iBAAiB6D,KAAK,mBAAI,EAAE;YACrCJ,WAAWzD,WAAW0D,UAAU;YAChCI,KAAK,GAAE9D,oBAAAA,WAAW8D,KAAK,YAAhB9D,oBAAoB4B;QAC7B;QACAc,QAAQ,aACHA;YACHrB;YACA0C,MAAM,IAAMzC,QAAQ;YACpB0C,OAAO,IAAM1C,QAAQ;;IAEzB;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EntityIdTag, EntityLoadRequestTag } from '@entifix/business';
|
|
2
|
-
import type { EntifixFailure, Entity, EntityConstructor, EntityFieldDescriptor, EntityId, EntityPage, FilterGroup } from '@entifix/core';
|
|
2
|
+
import type { EntifixFailure, Entity, EntityConstructor, EntityFieldDescriptor, EntityId, EntityPage, FilterGroup, Locale } from '@entifix/core';
|
|
3
3
|
import type { Context, Effect } from 'effect';
|
|
4
4
|
/**
|
|
5
5
|
* Where a picker's targets come from, and what may be picked.
|
|
@@ -45,5 +45,11 @@ export interface UseEntityLinkSourceOptions<TTarget extends Entity> {
|
|
|
45
45
|
* spares the label request entirely.
|
|
46
46
|
*/
|
|
47
47
|
selectedEntity?: TTarget;
|
|
48
|
+
/**
|
|
49
|
+
* The reader's locale. A `localized` search member is filtered and sorted
|
|
50
|
+
* in it (`name.es`), and a `localized` label reads in it. Defaults to the
|
|
51
|
+
* host's default locale.
|
|
52
|
+
*/
|
|
53
|
+
locale?: Locale;
|
|
48
54
|
}
|
|
49
55
|
//# sourceMappingURL=use-entity-link-source.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-entity-link-source.types.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-entity-link-source/use-entity-link-source.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC3E,OAAO,KAAK,EACV,cAAc,EACd,MAAM,EACN,iBAAiB,EACjB,qBAAqB,EACrB,QAAQ,EACR,UAAU,EACV,WAAW,
|
|
1
|
+
{"version":3,"file":"use-entity-link-source.types.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-entity-link-source/use-entity-link-source.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC3E,OAAO,KAAK,EACV,cAAc,EACd,MAAM,EACN,iBAAiB,EACjB,qBAAqB,EACrB,QAAQ,EACR,UAAU,EACV,WAAW,EACX,MAAM,EACP,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE9C;;;;;;;;GAQG;AACH,MAAM,WAAW,sBAAsB,CAAC,OAAO,SAAS,MAAM,EAAE,QAAQ;IACtE,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAC9C,4EAA4E;IAC5E,MAAM,EAAE,MAAM,CAAC,MAAM,CACnB,UAAU,CAAC,OAAO,CAAC,EACnB,cAAc,EACd,oBAAoB,GAAG,QAAQ,CAChC,CAAC;IACF;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,cAAc,EAAE,WAAW,GAAG,QAAQ,CAAC,CAAC;IACvE,GAAG,EAAE,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC/B;;;OAGG;IACH,aAAa,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IACrC,sEAAsE;IACtE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,0EAA0E;IAC1E,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,0BAA0B,CAAC,OAAO,SAAS,MAAM;IAChE;;;OAGG;IACH,UAAU,EAAE,qBAAqB,CAAC;IAClC,iDAAiD;IACjD,UAAU,CAAC,EAAE,QAAQ,CAAC;IACtB;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/hooks/use-entity-link-source/use-entity-link-source.types.ts"],"sourcesContent":["import type { EntityIdTag, EntityLoadRequestTag } from '@entifix/business';\nimport type {\n EntifixFailure,\n Entity,\n EntityConstructor,\n EntityFieldDescriptor,\n EntityId,\n EntityPage,\n FilterGroup,\n} from '@entifix/core';\nimport type { Context, Effect } from 'effect';\n\n/**\n * Where a picker's targets come from, and what may be picked.\n *\n * The use-cases are the parametrization seam: a domain that must restrict what is\n * assignable supplies its own list use-case (only active brands, only leaf\n * categories) instead of the generic `loadUCFactory`, and the picker never learns\n * the rule. {@link baseFiltering} is the lighter version of the same idea for a\n * restriction that needs no use-case of its own.\n */\nexport interface EntityLinkSourceConfig<TTarget extends Entity, TContext> {\n entityConstructor: EntityConstructor<TTarget>;\n /** Lists the targets. Supplies {@link EntityLoadRequestTag} per request. */\n loadUc: Effect.Effect<\n EntityPage<TTarget>,\n EntifixFailure,\n EntityLoadRequestTag | TContext\n >;\n /**\n * Loads one target by id — how a draft restored from storage turns its held\n * foreign key back into a name. Omit it and the input falls back to showing\n * the bare key.\n */\n getUc?: Effect.Effect<TTarget, EntifixFailure, EntityIdTag | TContext>;\n ctx: Context.Context<TContext>;\n /**\n * ANDed into every quick and browse request, so a caller can narrow the\n * selectable set without writing a use-case.\n */\n baseFiltering?: FilterGroup<TTarget>;\n /** How many suggestions the quick search asks for. Defaults to 10. */\n quickPageSize?: number;\n /** Milliseconds of quiet before a typed term is sent. Defaults to 250. */\n debounceMs?: number;\n}\n\nexport interface UseEntityLinkSourceOptions<TTarget extends Entity> {\n /**\n * The relation being edited. Its `linkSearchProperty` is what the quick search\n * filters on and its `linkLabelProperty` is what a target reads as.\n */\n descriptor: EntityFieldDescriptor;\n /** The foreign key the draft currently holds. */\n selectedId?: EntityId;\n /**\n * The instance behind {@link selectedId} when the caller already has it — the\n * one the user just picked, or the one a loaded record carried. Present, it\n * spares the label request entirely.\n */\n selectedEntity?: TTarget;\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/use-entity-link-source/use-entity-link-source.types.ts"],"sourcesContent":["import type { EntityIdTag, EntityLoadRequestTag } from '@entifix/business';\nimport type {\n EntifixFailure,\n Entity,\n EntityConstructor,\n EntityFieldDescriptor,\n EntityId,\n EntityPage,\n FilterGroup,\n Locale,\n} from '@entifix/core';\nimport type { Context, Effect } from 'effect';\n\n/**\n * Where a picker's targets come from, and what may be picked.\n *\n * The use-cases are the parametrization seam: a domain that must restrict what is\n * assignable supplies its own list use-case (only active brands, only leaf\n * categories) instead of the generic `loadUCFactory`, and the picker never learns\n * the rule. {@link baseFiltering} is the lighter version of the same idea for a\n * restriction that needs no use-case of its own.\n */\nexport interface EntityLinkSourceConfig<TTarget extends Entity, TContext> {\n entityConstructor: EntityConstructor<TTarget>;\n /** Lists the targets. Supplies {@link EntityLoadRequestTag} per request. */\n loadUc: Effect.Effect<\n EntityPage<TTarget>,\n EntifixFailure,\n EntityLoadRequestTag | TContext\n >;\n /**\n * Loads one target by id — how a draft restored from storage turns its held\n * foreign key back into a name. Omit it and the input falls back to showing\n * the bare key.\n */\n getUc?: Effect.Effect<TTarget, EntifixFailure, EntityIdTag | TContext>;\n ctx: Context.Context<TContext>;\n /**\n * ANDed into every quick and browse request, so a caller can narrow the\n * selectable set without writing a use-case.\n */\n baseFiltering?: FilterGroup<TTarget>;\n /** How many suggestions the quick search asks for. Defaults to 10. */\n quickPageSize?: number;\n /** Milliseconds of quiet before a typed term is sent. Defaults to 250. */\n debounceMs?: number;\n}\n\nexport interface UseEntityLinkSourceOptions<TTarget extends Entity> {\n /**\n * The relation being edited. Its `linkSearchProperty` is what the quick search\n * filters on and its `linkLabelProperty` is what a target reads as.\n */\n descriptor: EntityFieldDescriptor;\n /** The foreign key the draft currently holds. */\n selectedId?: EntityId;\n /**\n * The instance behind {@link selectedId} when the caller already has it — the\n * one the user just picked, or the one a loaded record carried. Present, it\n * spares the label request entirely.\n */\n selectedEntity?: TTarget;\n /**\n * The reader's locale. A `localized` search member is filtered and sorted\n * in it (`name.es`), and a `localized` label reads in it. Defaults to the\n * host's default locale.\n */\n locale?: Locale;\n}\n"],"names":[],"mappings":"AAgDA,WAoBC"}
|
package/package.json
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
|
-
"version": "0.
|
|
24
|
+
"version": "0.22.0",
|
|
25
25
|
"description": "React hooks that bind entities to data: TanStack Query and Form over the entity adapters, drafts, mutations and live invalidation.",
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"repository": {
|
|
@@ -65,16 +65,16 @@
|
|
|
65
65
|
"LICENSE"
|
|
66
66
|
],
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@entifix/business": "0.
|
|
69
|
-
"@entifix/core": "0.
|
|
70
|
-
"@entifix/transactions": "0.
|
|
68
|
+
"@entifix/business": "0.22.0",
|
|
69
|
+
"@entifix/core": "0.22.0",
|
|
70
|
+
"@entifix/transactions": "0.22.0"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@tanstack/react-form": "1.33.5",
|
|
74
74
|
"@tanstack/react-query": "^5.107.1",
|
|
75
75
|
"effect": "4.0.7",
|
|
76
76
|
"react": "19.3.1",
|
|
77
|
-
"@entifix/testing-unit": "0.
|
|
77
|
+
"@entifix/testing-unit": "0.22.0"
|
|
78
78
|
},
|
|
79
79
|
"peerDependencies": {
|
|
80
80
|
"@tanstack/react-form": ">=1.33 <2",
|