@phis/ui 0.7.4 → 0.7.7

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.
Files changed (124) hide show
  1. package/components/controls/phi-form-control.d.ts +3 -1
  2. package/components/controls/phi-form-control.js +5 -4
  3. package/components/controls/phi-options-provider.d.ts +14 -1
  4. package/components/controls/phi-options-provider.js +73 -2
  5. package/components/forms/auth-admin-settings-labels.d.ts +1 -1
  6. package/components/forms/auth-admin-settings-labels.js +2 -2
  7. package/components/forms/form-descriptor-contract.d.ts +1 -1
  8. package/components/forms/form-descriptor-contract.js +1 -1
  9. package/components/forms/form-descriptor-runtime-client.d.ts +4 -1
  10. package/components/forms/form-descriptor-runtime-client.js +33 -11
  11. package/components/forms/form-media-limits.d.ts +12 -0
  12. package/components/forms/form-media-limits.js +14 -0
  13. package/components/forms/form-provider-registry.d.ts +8 -0
  14. package/components/forms/form-record-title.d.ts +14 -0
  15. package/components/forms/form-record-title.js +38 -0
  16. package/components/forms/form-widget-config.d.ts +3 -0
  17. package/components/forms/form-widget-config.js +2 -0
  18. package/components/forms/phi-form-widget.d.ts +1 -1
  19. package/components/forms/phi-form-widget.js +4 -0
  20. package/components/overlays/phi-overlay-container-client.js +8 -8
  21. package/components/overlays/phi-overlay-title.d.ts +7 -0
  22. package/components/overlays/phi-overlay-title.js +21 -0
  23. package/components/tables/client/phi-table-binding.d.ts +3 -1
  24. package/components/tables/client/phi-table-binding.js +90 -49
  25. package/components/tables/client/phi-table-filter-options.d.ts +27 -0
  26. package/components/tables/client/phi-table-filter-options.js +35 -0
  27. package/components/widgets/accessible-areas.d.ts +1 -1
  28. package/components/widgets/accessible-areas.js +1 -1
  29. package/components/widgets/client/shared/phi-choice-controller.js +22 -15
  30. package/components/widgets/client/shared/phi-rendered-value.d.ts +10 -0
  31. package/components/widgets/client/shared/phi-rendered-value.js +49 -1
  32. package/components/widgets/client/shared/phi-table-provider.d.ts +10 -1
  33. package/components/widgets/client/shared/phi-table-provider.js +22 -0
  34. package/components/widgets/label-sets/admin-users.d.ts +15 -0
  35. package/components/widgets/label-sets/admin-users.js +31 -0
  36. package/constants/core-data-provider-keys.d.ts +7 -0
  37. package/constants/core-data-provider-keys.js +7 -0
  38. package/constants/phi-base-role-metadata.d.ts +2 -2
  39. package/constants/phi-base-role-metadata.js +1 -1
  40. package/constants/runtime-module-ownership.js +3 -0
  41. package/forms.d.ts +1 -1
  42. package/forms.js +1 -1
  43. package/gateway/capability-media-limits.d.ts +10 -0
  44. package/gateway/capability-media-limits.js +40 -0
  45. package/gateway/server-capabilities.js +4 -0
  46. package/helpers/preset-tree-contract-check.d.ts +3 -2
  47. package/helpers/preset-tree-contract-check.js +60 -0
  48. package/helpers/record-title.d.ts +7 -0
  49. package/helpers/record-title.js +25 -0
  50. package/helpers/record-widget.d.ts +15 -0
  51. package/helpers/record-widget.js +57 -0
  52. package/package.json +2 -2
  53. package/plugins/runtime-modules/accounting/client-data-providers.d.ts +7 -0
  54. package/plugins/runtime-modules/accounting/client-data-providers.js +9 -0
  55. package/plugins/runtime-modules/accounting/data-providers.d.ts +63 -0
  56. package/plugins/runtime-modules/accounting/data-providers.js +127 -0
  57. package/plugins/runtime-modules/accounting/definition.d.ts +54 -2
  58. package/plugins/runtime-modules/accounting/definition.js +5 -3
  59. package/plugins/runtime-modules/accounting/ids.d.ts +20 -0
  60. package/plugins/runtime-modules/accounting/ids.js +27 -0
  61. package/plugins/runtime-modules/accounting/module.d.ts +52 -0
  62. package/plugins/runtime-modules/accounting/presets.js +23 -4
  63. package/plugins/runtime-modules/accounting/services/products-table.d.ts +93 -0
  64. package/plugins/runtime-modules/accounting/services/products-table.js +158 -0
  65. package/plugins/runtime-modules/accounting/trees/accounting-products-label-set.d.ts +86 -0
  66. package/plugins/runtime-modules/accounting/trees/accounting-products-label-set.js +123 -0
  67. package/plugins/runtime-modules/accounting/trees/phi-default-accounting-products-page-tree.d.ts +21 -0
  68. package/plugins/runtime-modules/accounting/trees/phi-default-accounting-products-page-tree.js +435 -0
  69. package/plugins/runtime-modules/area-definitions.js +2 -2
  70. package/plugins/runtime-modules/asset/media-asset-field.d.ts +15 -0
  71. package/plugins/runtime-modules/asset/media-asset-field.js +21 -0
  72. package/plugins/runtime-modules/asset/media-asset-form-control.d.ts +4 -0
  73. package/plugins/runtime-modules/asset/media-asset-form-control.js +10 -5
  74. package/plugins/runtime-modules/asset/media-assets-field.d.ts +8 -0
  75. package/plugins/runtime-modules/asset/media-assets-field.js +10 -0
  76. package/plugins/runtime-modules/asset/media-assets-form-control.d.ts +5 -0
  77. package/plugins/runtime-modules/asset/media-assets-form-control.js +15 -6
  78. package/plugins/runtime-modules/auth/admin-settings-forms.js +1 -1
  79. package/plugins/runtime-modules/builder/clients/inspector-config-field.js +11 -6
  80. package/plugins/runtime-modules/client-manifests/accounting.js +5 -1
  81. package/plugins/runtime-modules/core/cards.js +2 -2
  82. package/plugins/runtime-modules/core/client-data-providers.js +5 -0
  83. package/plugins/runtime-modules/core/data-providers.js +14 -0
  84. package/plugins/runtime-modules/core/services/site-members-options.d.ts +27 -0
  85. package/plugins/runtime-modules/core/services/site-members-options.js +55 -0
  86. package/plugins/runtime-modules/core/widgets/cascader/client.js +13 -12
  87. package/plugins/runtime-modules/core/widgets/checkbox-group/client.js +5 -4
  88. package/plugins/runtime-modules/core/widgets/form/config.d.ts +5 -0
  89. package/plugins/runtime-modules/core/widgets/form/config.js +3 -0
  90. package/plugins/runtime-modules/core/widgets/multi-select/client.js +6 -4
  91. package/plugins/runtime-modules/core/widgets/record/actions.d.ts +20 -0
  92. package/plugins/runtime-modules/core/widgets/record/actions.js +77 -0
  93. package/plugins/runtime-modules/core/widgets/record/client.js +71 -8
  94. package/plugins/runtime-modules/core/widgets/record/config.d.ts +66 -1
  95. package/plugins/runtime-modules/core/widgets/record/config.js +71 -2
  96. package/plugins/runtime-modules/core/widgets/table/client.js +33 -29
  97. package/plugins/runtime-modules/core/widgets/table/config.js +5 -1
  98. package/plugins/runtime-modules/groups/data-providers.js +1 -1
  99. package/plugins/runtime-modules/groups/definition.js +1 -1
  100. package/plugins/runtime-modules/groups/page-visibility.d.ts +1 -1
  101. package/plugins/runtime-modules/groups/page-visibility.js +1 -1
  102. package/plugins/runtime-modules/groups/presets.js +1 -1
  103. package/plugins/runtime-modules/groups/services/options.js +1 -1
  104. package/plugins/runtime-modules/groups/services/table.js +1 -1
  105. package/plugins/runtime-modules/groups/trees/phi-default-app-groups-page-tree.js +2 -2
  106. package/plugins/runtime-modules/user-management/addon-roles.d.ts +60 -4
  107. package/plugins/runtime-modules/user-management/addon-roles.js +92 -8
  108. package/plugins/runtime-modules/user-management/addresses.d.ts +1 -1
  109. package/plugins/runtime-modules/user-management/controller/client.js +1 -1
  110. package/plugins/runtime-modules/user-management/data-providers.js +1 -0
  111. package/plugins/runtime-modules/user-management/forms.js +22 -0
  112. package/plugins/runtime-modules/user-management/presets.js +2 -2
  113. package/plugins/runtime-modules/user-management/services/options.d.ts +4 -0
  114. package/plugins/runtime-modules/user-management/services/options.js +14 -6
  115. package/plugins/runtime-modules/user-management/services/table.js +12 -3
  116. package/plugins/runtime-modules/user-management/trees/phi-default-admin-users-page-tree.js +9 -4
  117. package/types/access.d.ts +1 -1
  118. package/types/access.js +7 -7
  119. package/types/core-widget-placements.d.ts +7 -0
  120. package/types/form-descriptor.d.ts +1 -1
  121. package/types/record-widget.d.ts +35 -0
  122. package/types/server-capabilities.d.ts +1 -1
  123. package/types/table-widget.d.ts +20 -0
  124. package/types/table-widget.js +44 -0
@@ -0,0 +1,77 @@
1
+ "use client";
2
+ import { useCallback, useEffect, useRef, useState } from "react";
3
+ import { usePhiConfirmDialog } from "../../../../../components/controls/phi-confirm-dialog";
4
+ import { requestPhiTableProviderMutation, } from "../../../../../components/widgets/client/shared/phi-table-provider";
5
+ import { formatPhiRecordWidgetLabel } from "../../../../../components/widgets/label-types/record";
6
+ import { checkPhiTableProviderActionRequest, readPhiTableProviderError, } from "../../../../../types/table-widget";
7
+ /*
8
+ * Running a Provider action on the record shown (TABLES.md, "The record Widget").
9
+ *
10
+ * The record Widget holds a row identity and a bound source, which is all a row action of that source
11
+ * needs: the same request the Table's Binding sends (`checkPhiTableProviderActionRequest`, then
12
+ * `requestPhiTableProviderMutation`), with the identity it holds rather than one a signal names, and no
13
+ * query, because a record is not a view of rows. A key it does not list, a press while nothing is shown,
14
+ * and a second press while the first runs do nothing. A refusal -- the Provider's `rejected`, or a
15
+ * failure on the way -- is said above the record as the Table says it above its rows, and stands until the
16
+ * next press or the next record.
17
+ */
18
+ export function usePhiRecordWidgetActions({ actions, provider, resource, source, rowIdentity, onAccepted, }) {
19
+ const { confirm, confirmDialog } = usePhiConfirmDialog();
20
+ const [error, setError] = useState(null);
21
+ const runningRef = useRef(null);
22
+ useEffect(() => () => runningRef.current?.abort(), []);
23
+ const run = useCallback(async (action, identity, correlationId) => {
24
+ // Without a binding no record was read, so nothing is shown to act on.
25
+ if (runningRef.current || !provider || !source)
26
+ return;
27
+ const request = { kind: "action", actionKey: action.key, rowIdentity: identity, selectedRowIdentities: [], query: {} };
28
+ const requestError = checkPhiTableProviderActionRequest(resource, request);
29
+ setError(requestError?.message ?? null);
30
+ if (requestError)
31
+ return;
32
+ const abortController = new AbortController();
33
+ runningRef.current = abortController;
34
+ try {
35
+ const result = await requestPhiTableProviderMutation(provider, source, request, abortController.signal);
36
+ if (abortController.signal.aborted)
37
+ return;
38
+ if (result.status === "rejected") {
39
+ setError(result.message ?? "Table change was rejected.");
40
+ return;
41
+ }
42
+ onAccepted(result, action, identity, correlationId);
43
+ }
44
+ catch (runError) {
45
+ if (!abortController.signal.aborted)
46
+ setError(readPhiTableProviderError(runError).message);
47
+ }
48
+ finally {
49
+ if (runningRef.current === abortController)
50
+ runningRef.current = null;
51
+ }
52
+ }, [onAccepted, provider, resource, source]);
53
+ const activate = useCallback((actionKey, correlationId) => {
54
+ const action = actions.find((candidate) => candidate.key === actionKey);
55
+ if (!action || rowIdentity == null || runningRef.current)
56
+ return;
57
+ if (!action.confirm) {
58
+ void run(action, rowIdentity, correlationId);
59
+ return;
60
+ }
61
+ confirm({
62
+ title: formatPhiRecordWidgetLabel(action.confirm.title, rowIdentity),
63
+ content: action.confirm.description ? formatPhiRecordWidgetLabel(action.confirm.description, rowIdentity) : undefined,
64
+ confirmLabel: action.confirm.okText,
65
+ cancelLabel: action.confirm.cancelText,
66
+ danger: action.mode === "danger",
67
+ onConfirm: () => run(action, rowIdentity, correlationId),
68
+ });
69
+ }, [actions, confirm, rowIdentity, run]);
70
+ /** A new record, or none: what was said of the last one is not said of it. */
71
+ const forget = useCallback(() => {
72
+ runningRef.current?.abort();
73
+ runningRef.current = null;
74
+ setError(null);
75
+ }, []);
76
+ return { activate, error, forget, confirmDialog };
77
+ }
@@ -1,19 +1,26 @@
1
1
  "use client";
2
- import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
4
4
  import { readPhiDotPath } from "../../../../../helpers/dot-path";
5
+ import { PhiAlertControl } from "../../../../../components/controls/phi-alert-control";
5
6
  import { PhiDescriptionListControl } from "../../../../../components/controls/phi-description-list-control";
6
7
  import { PhiEmptyControl } from "../../../../../components/controls/phi-empty-control";
8
+ import { PhiFlexControl } from "../../../../../components/controls/phi-flex-control";
9
+ import { usePhiConfig } from "../../../../../components/root/phi-config-provider";
7
10
  import { PhiSkeletonControl } from "../../../../../components/controls/phi-skeleton-control";
8
11
  import { usePhiIntlLocale, usePhiIntlTimeZone } from "../../../../../components/root/phi-intl-locale";
9
12
  import { usePhiSignalListener } from "../../../../../components/runtime/runtime-signal-bus";
10
- import { usePhiSignalIdentity } from "../../../../../components/runtime/runtime-signal-identity";
13
+ import { emitPhiSignalCapability, usePhiSignalEmitter, usePhiSignalIdentity, } from "../../../../../components/runtime/runtime-signal-identity";
14
+ import { usePhiApplicationFeedback } from "../../../../../components/runtime/use-phi-application-feedback";
11
15
  import { renderPhiValueContent } from "../../../../../components/widgets/client/shared/phi-rendered-value";
12
16
  import { usePhiTableProvider } from "../../../../../components/widgets/client/shared/phi-table-provider";
13
17
  import { PHI_RECORD_WIDGET_DEFAULT_LABELS, formatPhiRecordWidgetLabel, } from "../../../../../components/widgets/label-types/record";
14
18
  import { PhiWidgetFailure } from "../../../../../components/widgets/shared/widget-failure-client";
15
19
  import { PhiCmsWidgetType } from "../../../../../constants/cms-widget-types";
20
+ import { fillPhiRecordTitle } from "../../../../../helpers/record-title";
21
+ import { validatePhiRecordWidgetBinding } from "../../../../../helpers/record-widget";
16
22
  import { readPhiTableActionSignalValue } from "../../../../../types/table-signal-values";
23
+ import { usePhiRecordWidgetActions } from "./actions";
17
24
  export function PhiRecordWidgetClient({ config, labels = PHI_RECORD_WIDGET_DEFAULT_LABELS, renderMode, }) {
18
25
  /*
19
26
  * Which record to show arrives as a signal, and is not read out of a store this Widget knows about.
@@ -24,13 +31,20 @@ export function PhiRecordWidgetClient({ config, labels = PHI_RECORD_WIDGET_DEFAU
24
31
  * first open, so the row action that opens it is addressed to a Widget that does not exist yet, and
25
32
  * the bus holds an addressed signal until its receiver appears.
26
33
  */
34
+ const { token } = usePhiConfig();
27
35
  const signalIdentity = usePhiSignalIdentity();
28
36
  /*
29
37
  * Memoised because the `?? []` hands out a fresh array whenever no routes are declared, and the
30
38
  * subscription below is keyed on it: without this the Widget would resubscribe on every render.
31
39
  */
32
40
  const listenRoutes = useMemo(() => config.signalRoutes?.listens ?? [], [config.signalRoutes?.listens]);
41
+ const emitRoutes = useMemo(() => config.signalRoutes?.emits ?? [], [config.signalRoutes?.emits]);
42
+ const emitSignal = usePhiSignalEmitter(signalIdentity.sender);
43
+ const emitCapability = useCallback((capabilityId, value, correlationId) => emitPhiSignalCapability(emitSignal, emitRoutes, capabilityId, value, correlationId), [emitRoutes, emitSignal]);
44
+ const { showMessage } = usePhiApplicationFeedback();
33
45
  const { provider, resource, bindingError } = usePhiTableProvider(config.source);
46
+ // The actions measured against the resource, said where the record would stand (Table: contractError).
47
+ const contractError = useMemo(() => resource ? validatePhiRecordWidgetBinding(config, resource)[0] ?? null : null, [config, resource]);
34
48
  // Sent with the read and part of what makes one new: an open record is read again after a switch.
35
49
  const locale = usePhiIntlLocale();
36
50
  const timeZone = usePhiIntlTimeZone();
@@ -38,7 +52,25 @@ export function PhiRecordWidgetClient({ config, labels = PHI_RECORD_WIDGET_DEFAU
38
52
  const [record, setRecord] = useState(null);
39
53
  const [loading, setLoading] = useState(false);
40
54
  const [error, setError] = useState(null);
55
+ /*
56
+ * Asks for the shown record again: after an action went through, what it shows has changed. A count
57
+ * beside the identity rather than a call, so a record closed in the meantime is not read for nobody.
58
+ */
59
+ const [readSequence, setReadSequence] = useState(0);
41
60
  const requestRef = useRef(null);
61
+ // The exchange the record was opened in, which its title answers.
62
+ const openCorrelationRef = useRef(undefined);
63
+ /*
64
+ * The title the record gives the dialog, where the placement takes one (`titleFromRecord`): announced
65
+ * after every read, and empty as a row is asked for, so the last row's name does not stand over the
66
+ * next one while it loads. Empty is the Overlay's own title.
67
+ */
68
+ const titleFromRecord = config.titleFromRecord;
69
+ const announceRecordTitle = useCallback((loaded, correlationId) => {
70
+ if (!titleFromRecord)
71
+ return;
72
+ emitCapability("recordTitle", fillPhiRecordTitle(titleFromRecord.template, loaded ? readPhiDotPath(loaded, titleFromRecord.field) : undefined), correlationId);
73
+ }, [emitCapability, titleFromRecord]);
42
74
  useEffect(() => () => requestRef.current?.abort(), []);
43
75
  const loadRecord = useCallback(async (rowIdentity) => {
44
76
  requestRef.current?.abort();
@@ -73,6 +105,7 @@ export function PhiRecordWidgetClient({ config, labels = PHI_RECORD_WIDGET_DEFAU
73
105
  });
74
106
  if (!abortController.signal.aborted) {
75
107
  setRecord(loaded);
108
+ announceRecordTitle(loaded, openCorrelationRef.current);
76
109
  }
77
110
  }
78
111
  catch (readError) {
@@ -91,7 +124,24 @@ export function PhiRecordWidgetClient({ config, labels = PHI_RECORD_WIDGET_DEFAU
91
124
  setLoading(false);
92
125
  }
93
126
  }
94
- }, [bindingError, config.source, labels, locale, provider, resource?.recordRead, timeZone]);
127
+ }, [announceRecordTitle, bindingError, config.source, labels, locale, provider, resource?.recordRead, timeZone]);
128
+ const onActionAccepted = useCallback((result, action, rowIdentity, correlationId) => {
129
+ // What the Provider has to say about what it did, as the Table says it: only where it says something.
130
+ if (result.message?.trim())
131
+ showMessage({ level: "info", content: result.message.trim() });
132
+ emitCapability("actionSuccess", { actionKey: action.key, rowIdentity, selectedRowIdentities: [] }, correlationId);
133
+ setReadSequence((current) => current + 1);
134
+ }, [emitCapability, showMessage]);
135
+ const recordActions = usePhiRecordWidgetActions({
136
+ actions: config.actions,
137
+ provider,
138
+ resource,
139
+ source: config.source,
140
+ rowIdentity: record ? selectedRowIdentity : null,
141
+ onAccepted: onActionAccepted,
142
+ });
143
+ const forgetActionOutcome = recordActions.forget;
144
+ const activateAction = recordActions.activate;
95
145
  usePhiSignalListener(useCallback((signal) => {
96
146
  const route = listenRoutes.find((candidate) => candidate.channel === signal.channel &&
97
147
  candidate.action === signal.action &&
@@ -103,14 +153,21 @@ export function PhiRecordWidgetClient({ config, labels = PHI_RECORD_WIDGET_DEFAU
103
153
  const action = readPhiTableActionSignalValue(signal.value);
104
154
  if (!action || action.actionKey !== config.openActionKey || action.rowIdentity == null)
105
155
  return;
156
+ openCorrelationRef.current = signal.correlationId;
157
+ announceRecordTitle(null, signal.correlationId);
158
+ forgetActionOutcome();
106
159
  setSelectedRowIdentity(action.rowIdentity);
107
160
  }
108
161
  else if (route.capabilityId === "close" && signal.value === false) {
162
+ forgetActionOutcome();
109
163
  setSelectedRowIdentity(null);
110
164
  setRecord(null);
111
165
  setError(null);
112
166
  }
113
- }, [config.openActionKey, listenRoutes, signalIdentity.receiver]), useMemo(() => {
167
+ else if (route.capabilityId === "actionActivate" && typeof signal.value === "string") {
168
+ activateAction(signal.value.trim(), signal.correlationId);
169
+ }
170
+ }, [activateAction, announceRecordTitle, config.openActionKey, forgetActionOutcome, listenRoutes, signalIdentity.receiver]), useMemo(() => {
114
171
  if (listenRoutes.length === 0)
115
172
  return null;
116
173
  return {
@@ -125,7 +182,7 @@ export function PhiRecordWidgetClient({ config, labels = PHI_RECORD_WIDGET_DEFAU
125
182
  }
126
183
  const timer = window.setTimeout(() => void loadRecord(selectedRowIdentity), 0);
127
184
  return () => window.clearTimeout(timer);
128
- }, [loadRecord, selectedRowIdentity]);
185
+ }, [loadRecord, readSequence, selectedRowIdentity]);
129
186
  if (loading) {
130
187
  return _jsx(PhiSkeletonControl, { lines: config.presentation.fields.length || 7, withTitle: true });
131
188
  }
@@ -133,16 +190,22 @@ export function PhiRecordWidgetClient({ config, labels = PHI_RECORD_WIDGET_DEFAU
133
190
  * Every error here is the source's -- no binding, a resource that reads no single records, a read that
134
191
  * failed -- and none of them is the reader's to fix, so it goes the way of every such failure.
135
192
  */
136
- if (error) {
137
- return _jsx(PhiWidgetFailure, { renderMode: renderMode, widgetType: PhiCmsWidgetType.Record, title: error });
193
+ const failure = contractError ?? error;
194
+ if (failure) {
195
+ return _jsx(PhiWidgetFailure, { renderMode: renderMode, widgetType: PhiCmsWidgetType.Record, title: failure });
138
196
  }
139
197
  if (!record) {
140
198
  return _jsx(PhiEmptyControl, { description: labels.empty });
141
199
  }
142
- return (_jsx(PhiDescriptionListControl, { presentation: config.presentation.appearance, columns: config.presentation.columns, items: config.presentation.fields.map((field) => ({
200
+ /*
201
+ * A refused action is not the source's failure: the record still stands, and the person who pressed
202
+ * reads why above it, as a Table says a refused action above its rows.
203
+ */
204
+ const list = (_jsx(PhiDescriptionListControl, { presentation: config.presentation.appearance, columns: config.presentation.columns, items: config.presentation.fields.map((field) => ({
143
205
  key: field.key,
144
206
  label: field.label,
145
207
  full: field.full,
146
208
  value: renderPhiValueContent(readPhiDotPath(record, field.fieldKey), field, labels, "block"),
147
209
  })) }));
210
+ return config.actions.length === 0 ? list : (_jsxs(PhiFlexControl, { vertical: true, gap: token.paddingSM, style: { minWidth: 0, width: "100%" }, children: [recordActions.confirmDialog, recordActions.error ? _jsx(PhiAlertControl, { level: "error", showIcon: true, title: recordActions.error }) : null, list] }));
148
211
  }
@@ -11,7 +11,17 @@ export declare const PHI_RECORD_WIDGET_DEFINITION: {
11
11
  icon: string;
12
12
  slotSizePolicy: "fill-inline";
13
13
  runtimeSignals: {
14
- emits: never[];
14
+ emits: ({
15
+ id: string;
16
+ action: "activate";
17
+ valueType: "json";
18
+ valueSchema: `${string}/signals/${string}`;
19
+ } | {
20
+ id: string;
21
+ action: "change";
22
+ valueType: "string";
23
+ valueSchema?: undefined;
24
+ })[];
15
25
  listens: ({
16
26
  id: string;
17
27
  channel: string;
@@ -24,6 +34,12 @@ export declare const PHI_RECORD_WIDGET_DEFINITION: {
24
34
  action: "change";
25
35
  valueType: "boolean";
26
36
  valueSchema?: undefined;
37
+ } | {
38
+ id: string;
39
+ channel: string;
40
+ action: "activate";
41
+ valueType: "string";
42
+ valueSchema?: undefined;
27
43
  })[];
28
44
  };
29
45
  fields: ({
@@ -121,6 +137,7 @@ export declare const PHI_RECORD_WIDGET_DEFINITION: {
121
137
  label: string;
122
138
  renderer: string;
123
139
  full: boolean;
140
+ mode?: undefined;
124
141
  };
125
142
  itemFields: ({
126
143
  key: string;
@@ -171,10 +188,58 @@ export declare const PHI_RECORD_WIDGET_DEFINITION: {
171
188
  min?: undefined;
172
189
  max?: undefined;
173
190
  precision?: undefined;
191
+ } | {
192
+ key: string;
193
+ type: "collection";
194
+ presentation: "overlay";
195
+ label: string;
196
+ description: string;
197
+ itemKeyField: string;
198
+ itemLabelField: string;
199
+ addLabel: string;
200
+ emptyLabel: string;
201
+ editLabel: string;
202
+ defaultItem: {
203
+ key: string;
204
+ mode: string;
205
+ fieldKey?: undefined;
206
+ label?: undefined;
207
+ renderer?: undefined;
208
+ full?: undefined;
209
+ };
210
+ itemFields: ({
211
+ key: string;
212
+ type: "string";
213
+ label: string;
214
+ required: true;
215
+ options?: undefined;
216
+ } | {
217
+ key: string;
218
+ type: "choice";
219
+ label: string;
220
+ options: {
221
+ value: string;
222
+ label: string;
223
+ }[];
224
+ required?: undefined;
225
+ } | {
226
+ key: string;
227
+ type: "string";
228
+ label: string;
229
+ required?: undefined;
230
+ options?: undefined;
231
+ })[];
232
+ providerKind?: undefined;
233
+ required?: undefined;
234
+ options?: undefined;
235
+ min?: undefined;
236
+ max?: undefined;
237
+ precision?: undefined;
174
238
  })[];
175
239
  defaultConfig: {
176
240
  source: null;
177
241
  openActionKey: string;
242
+ actions: never[];
178
243
  presentation: {
179
244
  appearance: "grid";
180
245
  columns: number;
@@ -1,5 +1,7 @@
1
1
  import { resolvePhiCmsWidgetPluginKey } from "../../../../../constants/cms-widget-types";
2
2
  import { readBoolean, readInteger, readString } from "../../../../../components/widgets/config/parser-primitives";
3
+ import { createPhiConfigReader } from "../../../../../components/widgets/config/strict-config-reader";
4
+ import { readPhiRecordWidgetTitleFromRecord } from "../../../../../helpers/record-widget";
3
5
  import { isPhiRuntimeDataProviderKey } from "../../../../../types/runtime-data-provider";
4
6
  import { PHI_SIGNAL_VALUE_SCHEMAS, readPhiSignalRouteSet } from "../../../../../types/signals";
5
7
  import { PHI_TABLE_TAG_VARIANTS, } from "../../../../../types/table-widget";
@@ -17,6 +19,7 @@ const PHI_RECORD_VALUE_RENDERERS = [
17
19
  "switch",
18
20
  "checkbox",
19
21
  "icon",
22
+ "image",
20
23
  "money",
21
24
  "interval",
22
25
  ];
@@ -59,12 +62,31 @@ function readRecordField(value) {
59
62
  full: readBoolean(value.full),
60
63
  };
61
64
  }
65
+ /** A required text: absent is as wrong as the wrong type, because the entry means nothing without it. */
66
+ function requireText(reader, key) {
67
+ return reader.string(key)?.trim() || reader.fail(key, "a text", reader.record[key]);
68
+ }
69
+ function readRecordAction(reader) {
70
+ const confirm = reader.object("confirm", (confirmReader) => ({
71
+ title: requireText(confirmReader, "title"),
72
+ description: confirmReader.string("description"),
73
+ okText: confirmReader.string("okText"),
74
+ cancelText: confirmReader.string("cancelText"),
75
+ }));
76
+ return {
77
+ key: requireText(reader, "key"),
78
+ mode: reader.oneOf("mode", ["normal", "danger"]) ?? "normal",
79
+ ...(confirm ? { confirm } : {}),
80
+ };
81
+ }
62
82
  function parsePhiRecordWidgetConfig(rawConfig) {
63
83
  const source = isPhiRecord(rawConfig.source) ? rawConfig.source : {};
64
84
  const providerKey = typeof source.providerKey === "string" ? source.providerKey : "";
65
85
  const resourceKey = readString(source.resourceKey)?.trim() ?? "";
66
86
  const presentation = isPhiRecord(rawConfig.presentation) ? rawConfig.presentation : {};
67
87
  const columns = readInteger(presentation.columns);
88
+ // Strict, as every newer key: an action stated wrong is the author's to correct, not to drop.
89
+ const reader = createPhiConfigReader(rawConfig);
68
90
  return {
69
91
  source: isPhiRuntimeDataProviderKey(providerKey) && resourceKey
70
92
  ? {
@@ -85,6 +107,8 @@ function parsePhiRecordWidgetConfig(rawConfig) {
85
107
  })
86
108
  : [],
87
109
  },
110
+ actions: reader.list("actions", readRecordAction) ?? [],
111
+ titleFromRecord: readPhiRecordWidgetTitleFromRecord(rawConfig.titleFromRecord),
88
112
  signalRoutes: readPhiSignalRouteSet(rawConfig.signalRoutes),
89
113
  };
90
114
  }
@@ -93,13 +117,22 @@ export const PHI_RECORD_WIDGET_DEFINITION = {
93
117
  pluginKey: resolvePhiCmsWidgetPluginKey("record"),
94
118
  typeKey: "record",
95
119
  title: "Record",
96
- description: "Shows one row of a Table Provider as named values, opened by a row action.",
120
+ description: "Shows one row of a Table Provider as named values, opened by a row action, and runs its Provider row actions on a press.",
97
121
  category: "data",
98
122
  tags: ["record", "detail", "data"],
99
123
  icon: "antd:profile",
100
124
  slotSizePolicy: "fill-inline",
101
125
  runtimeSignals: {
102
- emits: [],
126
+ emits: [
127
+ /*
128
+ * An action of `actions` went through on the record shown: which one, on which row. A dialog
129
+ * closes on it and the Table beside it reads again -- each a route of its own, `dialog/close:none`
130
+ * and `reload/activate:none`, which carry nothing of the value.
131
+ */
132
+ { id: "actionSuccess", action: "activate", valueType: "json", valueSchema: PHI_SIGNAL_VALUE_SCHEMAS.tableAction },
133
+ // The title the record gives the dialog, after every read (`titleFromRecord`), for the Overlay's `title`.
134
+ { id: "recordTitle", action: "change", valueType: "string" },
135
+ ],
103
136
  listens: [
104
137
  {
105
138
  id: "recordOpen",
@@ -109,6 +142,11 @@ export const PHI_RECORD_WIDGET_DEFINITION = {
109
142
  valueSchema: PHI_SIGNAL_VALUE_SCHEMAS.tableAction,
110
143
  },
111
144
  { id: "close", channel: "state", action: "change", valueType: "boolean" },
145
+ /*
146
+ * Run one of `actions` on the record shown: the value is the action's key, the words this command
147
+ * channel answers. A footer button sends it; the row is the one the Widget holds.
148
+ */
149
+ { id: "actionActivate", channel: "action", action: "activate", valueType: "string" },
112
150
  ],
113
151
  },
114
152
  fields: [
@@ -181,6 +219,7 @@ export const PHI_RECORD_WIDGET_DEFINITION = {
181
219
  { value: "switch", label: "Switch" },
182
220
  { value: "checkbox", label: "Checkbox" },
183
221
  { value: "icon", label: "Icon" },
222
+ { value: "image", label: "Image" },
184
223
  { value: "money", label: "Money" },
185
224
  { value: "interval", label: "Interval" },
186
225
  ],
@@ -204,10 +243,40 @@ export const PHI_RECORD_WIDGET_DEFINITION = {
204
243
  },
205
244
  ],
206
245
  },
246
+ {
247
+ key: "actions",
248
+ type: "collection",
249
+ presentation: "overlay",
250
+ label: "Actions",
251
+ description: "Provider row actions of the source, run on the record shown when their key arrives on action/activate.",
252
+ itemKeyField: "key",
253
+ itemLabelField: "key",
254
+ addLabel: "Add action",
255
+ emptyLabel: "No actions",
256
+ editLabel: "Edit actions",
257
+ defaultItem: { key: "action", mode: "normal" },
258
+ itemFields: [
259
+ { key: "key", type: "string", label: "Provider Action", required: true },
260
+ {
261
+ key: "mode",
262
+ type: "choice",
263
+ label: "Mode",
264
+ options: [
265
+ { value: "normal", label: "Normal" },
266
+ { value: "danger", label: "Danger" },
267
+ ],
268
+ },
269
+ { key: "confirm.title", type: "string", label: "Confirm Title" },
270
+ { key: "confirm.description", type: "string", label: "Confirm Description" },
271
+ { key: "confirm.okText", type: "string", label: "Confirm OK Text" },
272
+ { key: "confirm.cancelText", type: "string", label: "Confirm Cancel Text" },
273
+ ],
274
+ },
207
275
  ],
208
276
  defaultConfig: {
209
277
  source: null,
210
278
  openActionKey: "view",
279
+ actions: [],
211
280
  presentation: {
212
281
  appearance: "grid",
213
282
  columns: 2,
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { Fragment as _Fragment, jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
3
3
  import { PHI_TABLE_WIDGET_DEFAULT_LABELS } from "../../../../../components/widgets/label-types/table";
4
4
  import { formatPhiTableWidgetLabel } from "../../../../../components/widgets/label-types/table";
5
5
  import { PhiNameControl } from "../../../../../components/controls/phi-name-control";
@@ -34,8 +34,9 @@ import { usePhiVisualAnchorParts } from "../../../../../components/runtime/runti
34
34
  import { usePhiApplicationFeedback } from "../../../../../components/runtime/use-phi-application-feedback";
35
35
  import { usePhiTableBinding } from "../../../../../components/tables/client/phi-table-binding";
36
36
  import { PhiTableBindingControl } from "../../../../../components/tables/client/phi-table-binding-control";
37
+ import { usePhiTableFilterOptions } from "../../../../../components/tables/client/phi-table-filter-options";
37
38
  import { clearPhiDataDragPayload, readPhiDataDragPayload } from "../../../../../components/runtime/client/phi-data-dnd";
38
- import { renderPhiValueContent } from "../../../../../components/widgets/client/shared/phi-rendered-value";
39
+ import { renderPhiValueContent, renderPhiValueWithLead, } from "../../../../../components/widgets/client/shared/phi-rendered-value";
39
40
  import { formatPhiTranslation } from "../../../../../helpers/translation-format";
40
41
  import { readPhiTableFilters, readPhiTableQuery, readPhiTableRowOptions, validatePhiTableWidgetBinding, } from "../../../../../types/table-widget";
41
42
  import { readPhiTableColumnOrderSignalValue, readPhiTableBindingParamsSignalValue, readPhiTableExpansionSignalValue, readPhiTableActionSignalValue, isPhiTableQueryValue, } from "../../../../../types/table-signal-values";
@@ -60,14 +61,10 @@ function formatTableActionTemplate(value, templateValue) {
60
61
  }
61
62
  function renderTableValue(value, column, row, labels) {
62
63
  const content = renderPhiValueContent(value, column, labels);
63
- if (!column.iconFieldKey) {
64
- return content;
65
- }
66
- const iconName = row?.[column.iconFieldKey];
67
- if (typeof iconName !== "string" || !iconName.trim()) {
68
- return content;
69
- }
70
- return (_jsxs(PhiFlexControl, { align: "center", gap: 6, style: { display: "inline-flex" }, children: [_jsx(PhiIcon, { name: iconName }), content] }));
64
+ return renderPhiValueWithLead(content, {
65
+ icon: column.iconFieldKey ? row?.[column.iconFieldKey] : undefined,
66
+ image: column.imageFieldKey ? row?.[column.imageFieldKey] : undefined,
67
+ });
71
68
  }
72
69
  function renderTableSummaryItem(item, value) {
73
70
  const renderedValue = value == null ? "—" : String(value);
@@ -120,11 +117,20 @@ function buildQueryFilters(filters, values) {
120
117
  else if ((typeof value === "string" && value !== "") ||
121
118
  typeof value === "boolean" ||
122
119
  (Array.isArray(value) && value.length > 0)) {
123
- result[filter.key] = Array.isArray(value) ? [...value] : value;
120
+ result[filter.key] = Array.isArray(value) ? value.slice() : value;
124
121
  }
125
122
  }
126
123
  return result;
127
124
  }
125
+ /** A multiple select filter's values, all of one kind as the query holds a list. */
126
+ function readTableFilterChoices(value) {
127
+ if (!Array.isArray(value))
128
+ return [];
129
+ const numbers = value.filter((entry) => typeof entry === "number" && Number.isFinite(entry));
130
+ return numbers.length > 0 && numbers.length === value.length
131
+ ? numbers
132
+ : value.filter((entry) => typeof entry === "string");
133
+ }
128
134
  function readTableFilterValue(filter, filters) {
129
135
  if (filter.type === "dateRange") {
130
136
  const start = filters?.[filter.startKey];
@@ -137,9 +143,10 @@ function readTableFilterValue(filter, filters) {
137
143
  const value = filters?.[filter.key];
138
144
  if (filter.type === "boolean")
139
145
  return typeof value === "boolean" ? value : undefined;
140
- if (filter.type === "select" && filter.multiple) {
141
- return Array.isArray(value) ? value.filter((entry) => typeof entry === "string") : [];
142
- }
146
+ if (filter.type === "select" && filter.multiple)
147
+ return readTableFilterChoices(value);
148
+ if (filter.type === "select" && typeof value === "number" && Number.isFinite(value))
149
+ return value;
143
150
  return typeof value === "string" ? value : undefined;
144
151
  }
145
152
  function updateTableQueryFilters(current, filter, value) {
@@ -159,9 +166,10 @@ function updateTableQueryFilters(current, filter, value) {
159
166
  return next;
160
167
  }
161
168
  if ((typeof value === "string" && value !== "") ||
169
+ (typeof value === "number" && Number.isFinite(value)) ||
162
170
  typeof value === "boolean" ||
163
171
  (Array.isArray(value) && value.length > 0)) {
164
- next[filter.key] = Array.isArray(value) ? [...value] : value;
172
+ next[filter.key] = Array.isArray(value) ? value.slice() : value;
165
173
  }
166
174
  else {
167
175
  delete next[filter.key];
@@ -310,7 +318,7 @@ export function PhiTableWidgetClient({ config: inputConfig, renderMode, external
310
318
  },
311
319
  validateResource,
312
320
  });
313
- const { resource, bindingError, contractError, rows, total, hasMore, summary, loading, error, queryError, query, resolvedQuery, setQuery, selectedRowIdentities, setSelectedRowIdentities, expandedRowIdentities, setExpandedRowIdentities, reload, executeAction, commitField, commitRow, isFieldMutationPending, moveRow, drop, } = binding;
321
+ const { resource, bindingError, contractError, rows, total, hasMore, summary, loading, error, queryError, query, resolvedQuery, setQuery, changePage, selectedRowIdentities, setSelectedRowIdentities, expandedRowIdentities, setExpandedRowIdentities, reload, executeAction, commitField, commitRow, isFieldMutationPending, moveRow, drop, } = binding;
314
322
  const toolbarActions = useMemo(() => resolveTableActions(features.actions?.toolbar, resource?.actions), [features.actions?.toolbar, resource?.actions]);
315
323
  const rowActions = useMemo(() => resolveTableActions(features.actions?.row, resource?.actions), [features.actions?.row, resource?.actions]);
316
324
  const bulkActions = useMemo(() => resolveTableActions(features.actions?.bulk, resource?.actions), [features.actions?.bulk, resource?.actions]);
@@ -843,11 +851,15 @@ export function PhiTableWidgetClient({ config: inputConfig, renderMode, external
843
851
  } : undefined, pagination: features.pagination?.enabled === false ? false : {
844
852
  page: resolvedQuery.page ?? 1,
845
853
  pageSize: resolvedQuery.pageSize ?? 20,
846
- total: total ?? undefined,
854
+ /*
855
+ * A cursor-paged list is paged back and forward even where it is counted: a count says how many
856
+ * pages there are, not where page 7 begins, so no page number past the next is offered.
857
+ */
858
+ total: resource?.query.pagination === "cursor" ? undefined : total ?? undefined,
847
859
  hasMore,
848
860
  pageSizeOptions: features.pagination?.pageSizes,
849
861
  showSizeChanger: (features.pagination?.pageSizes?.length ?? 0) > 0,
850
- onChange: (page, pageSize) => setQuery((current) => ({ ...current, page, pageSize, cursor: null })),
862
+ onChange: changePage,
851
863
  }, tree: structure ? {
852
864
  parentRowIdentityPath: structure.parentRowIdentityPath,
853
865
  expandColumnKey: structure.expandColumnKey,
@@ -1021,18 +1033,10 @@ function TableFilter({ filter, field, sourceConfig, value, size, onChange, label
1021
1033
  // A label with nowhere to go still has something to say: it becomes the Control's placeholder, so a
1022
1034
  // cleared filter reads as the question it asks rather than as an empty box.
1023
1035
  const hiddenLabelPlaceholder = filter.labelPlacement === "none" ? filter.label : undefined;
1024
- const fieldWithOptions = field?.type === "enum" || field?.type === "enum[]" ? field : null;
1025
- const resolvedOptions = usePhiControlOptionsProvider({
1026
- options: filter.type === "select" && (filter.options?.length ?? 0) > 0
1027
- ? filter.options
1028
- : fieldWithOptions?.options,
1029
- optionsProvider: filter.type === "select"
1030
- ? filter.optionsProvider ?? fieldWithOptions?.optionsProvider
1031
- : undefined,
1032
- sourceConfig,
1033
- });
1036
+ // Searched and named as a Form field's choices are (`usePhiTableFilterOptions`).
1037
+ const resolvedOptions = usePhiTableFilterOptions({ filter, field, sourceConfig, value });
1034
1038
  if (filter.type === "select") {
1035
- return filter.multiple ? (_jsx(PhiMultiSelectControl, { allowClear: true, value: Array.isArray(value) ? value.filter((entry) => typeof entry === "string") : [], disabled: Boolean(resolvedOptions.warning), options: resolvedOptions.options, size: size, placeholder: hiddenLabelPlaceholder, onChange: onChange, style: { minWidth: 180 } })) : (_jsx(PhiSelectControl, { allowClear: true, value: typeof value === "string" ? value : undefined, disabled: Boolean(resolvedOptions.warning), options: resolvedOptions.options, size: size, placeholder: hiddenLabelPlaceholder, onChange: onChange, style: { minWidth: 180 } }));
1039
+ return filter.multiple ? (_jsx(PhiMultiSelectControl, { allowClear: true, value: readTableFilterChoices(value), disabled: Boolean(resolvedOptions.warning), options: resolvedOptions.options, size: size, placeholder: hiddenLabelPlaceholder, onChange: (next) => onChange(readTableFilterChoices(next)), style: { minWidth: 180 } })) : (_jsx(PhiSelectControl, { allowClear: true, value: typeof value === "string" || typeof value === "number" ? value : undefined, disabled: Boolean(resolvedOptions.warning), options: resolvedOptions.options, size: size, onSearch: resolvedOptions.onSearch, filterOptionsLocally: resolvedOptions.filterOptionsLocally, placeholder: hiddenLabelPlaceholder, onChange: onChange, style: { minWidth: 180 } }));
1036
1040
  }
1037
1041
  if (filter.type === "boolean") {
1038
1042
  if (filter.control === "switch") {
@@ -131,7 +131,7 @@ const PHI_TABLE_ACTION_CONFIG_FIELDS = [
131
131
  ];
132
132
  const PHI_TABLE_COLUMN_RENDERERS = [
133
133
  "text", "email", "date", "datetime", "badge", "tags", "link", "code", "json", "switch", "checkbox", "icon",
134
- "money", "interval",
134
+ "image", "money", "interval",
135
135
  ];
136
136
  const PHI_TABLE_COLUMN_EDITOR_CONTROLS = [
137
137
  "switch", "checkbox", "select", "radio", "segmented", "multi-select", "checkbox-group", "icon-picker", "textarea",
@@ -267,6 +267,7 @@ function readColumn(reader) {
267
267
  fieldKey: requireString(reader, "fieldKey"),
268
268
  sortField: reader.string("sortField"),
269
269
  iconFieldKey: reader.string("iconFieldKey"),
270
+ imageFieldKey: reader.string("imageFieldKey"),
270
271
  titleIcon: reader.string("titleIcon"),
271
272
  titleDisplay: reader.oneOf("titleDisplay", ["icon"]),
272
273
  description: reader.string("description"),
@@ -625,6 +626,8 @@ export const PHI_TABLE_WIDGET_DEFINITION = {
625
626
  { key: "title", type: "string", label: "Title", required: true },
626
627
  { key: "description", type: "string", label: "Hint" },
627
628
  { key: "sortField", type: "string", label: "Provider Sort Field" },
629
+ { key: "iconFieldKey", type: "string", label: "Icon Field" },
630
+ { key: "imageFieldKey", type: "string", label: "Image Field" },
628
631
  {
629
632
  key: "renderer",
630
633
  type: "choice",
@@ -642,6 +645,7 @@ export const PHI_TABLE_WIDGET_DEFINITION = {
642
645
  { value: "switch", label: "Switch" },
643
646
  { value: "checkbox", label: "Checkbox" },
644
647
  { value: "icon", label: "Icon" },
648
+ { value: "image", label: "Image" },
645
649
  { value: "money", label: "Money" },
646
650
  { value: "interval", label: "Interval" },
647
651
  ],