@phis/ui 0.6.4 → 0.6.5

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 (164) hide show
  1. package/components/cms/phi-cms-layout-renderer.js +11 -2
  2. package/components/controls/phi-multi-select-control.js +4 -2
  3. package/components/controls/phi-options-provider.d.ts +1 -0
  4. package/components/controls/phi-options-provider.js +1 -0
  5. package/components/controls/phi-select-control.d.ts +21 -0
  6. package/components/controls/phi-select-control.js +2 -2
  7. package/components/controls/phi-status-dot-control.d.ts +15 -0
  8. package/components/controls/phi-status-dot-control.js +25 -0
  9. package/components/controls/phi-table-control.js +8 -1
  10. package/components/controls/phi-tree-control.js +5 -4
  11. package/components/controls/phi-tree-select-control.js +1 -0
  12. package/components/layouts/clients/phi-split-card-half.d.ts +4 -1
  13. package/components/layouts/clients/phi-split-card-half.js +2 -2
  14. package/components/layouts/clients/phi-split-card-layout-client.d.ts +6 -3
  15. package/components/layouts/clients/phi-split-card-layout-client.js +5 -3
  16. package/components/layouts/clients/phi-three-column-layout-client.d.ts +20 -1
  17. package/components/layouts/clients/phi-three-column-layout-client.js +31 -15
  18. package/components/layouts/layout-definitions.d.ts +96 -0
  19. package/components/layouts/layout-definitions.js +40 -2
  20. package/components/layouts/plugins/split-card-layout-plugin.js +1 -1
  21. package/components/layouts/plugins/three-column-layout-plugin.js +1 -1
  22. package/components/layouts/split-card-geometry.d.ts +9 -4
  23. package/components/layouts/split-card-geometry.js +29 -13
  24. package/components/media/media-folder-options.d.ts +10 -0
  25. package/components/media/media-folder-options.js +14 -0
  26. package/components/shell/phi-antd-icon.d.ts +1 -0
  27. package/components/shell/phi-antd-icon.js +3 -0
  28. package/components/widgets/inspector-field-row.js +4 -1
  29. package/components/widgets/label-sets/admin-users.d.ts +3 -0
  30. package/components/widgets/label-sets/admin-users.js +8 -2
  31. package/components/widgets/label-sets/gallery.js +2 -2
  32. package/components/widgets/label-sets/inspector.js +4 -0
  33. package/components/widgets/label-sets/observability-logs.js +2 -2
  34. package/components/widgets/label-sets/profile.js +2 -1
  35. package/components/widgets/label-types/gallery.d.ts +2 -3
  36. package/components/widgets/label-types/gallery.js +1 -4
  37. package/components/widgets/label-types/inspector.d.ts +4 -0
  38. package/components/widgets/label-types/inspector.js +2 -0
  39. package/components/widgets/shared/markdown-image-vocabulary.js +1 -1
  40. package/constants/cms-layout-proportions.d.ts +6 -0
  41. package/constants/cms-layout-proportions.js +17 -0
  42. package/constants/runtime-module-ownership.js +1 -0
  43. package/helpers/page-reference-tree.js +8 -0
  44. package/helpers/table-action-links.d.ts +11 -0
  45. package/helpers/table-action-links.js +14 -0
  46. package/helpers/table-action-row-link.d.ts +8 -0
  47. package/helpers/table-action-row-link.js +14 -0
  48. package/package.json +2 -2
  49. package/plugins/factories/widget-renderers.d.ts +7 -1
  50. package/plugins/factories/widget-renderers.js +12 -2
  51. package/plugins/runtime-modules/asset/authoring-widgets.js +2 -2
  52. package/plugins/runtime-modules/asset/data-providers.js +1 -1
  53. package/plugins/runtime-modules/asset/services/options.js +7 -11
  54. package/plugins/runtime-modules/asset/widgets/area-upload/plugin.js +0 -2
  55. package/plugins/runtime-modules/asset/widgets/asset-focal-rect/plugin.js +0 -2
  56. package/plugins/runtime-modules/asset/widgets/image-inspector/plugin.js +0 -2
  57. package/plugins/runtime-modules/asset/widgets/media-picker/plugin.js +0 -2
  58. package/plugins/runtime-modules/asset/widgets.js +4 -4
  59. package/plugins/runtime-modules/auth/authoring-widgets.js +4 -8
  60. package/plugins/runtime-modules/auth/widgets/auth-workflow/plugin.js +0 -6
  61. package/plugins/runtime-modules/auth/widgets/logout/plugin.js +0 -2
  62. package/plugins/runtime-modules/auth/widgets/security/plugin.js +0 -2
  63. package/plugins/runtime-modules/auth/widgets.js +5 -3
  64. package/plugins/runtime-modules/avatar/authoring-widgets.js +2 -2
  65. package/plugins/runtime-modules/avatar/widgets/account-avatar/plugin.js +0 -2
  66. package/plugins/runtime-modules/avatar/widgets/account-avatar-picker/plugin.js +0 -2
  67. package/plugins/runtime-modules/avatar/widgets.js +2 -2
  68. package/plugins/runtime-modules/builder/authoring-widgets.js +1 -1
  69. package/plugins/runtime-modules/builder/clients/inspector-choice-cascader.d.ts +28 -0
  70. package/plugins/runtime-modules/builder/clients/inspector-choice-cascader.js +98 -0
  71. package/plugins/runtime-modules/builder/clients/inspector-config-field.js +27 -3
  72. package/plugins/runtime-modules/builder/clients/inspector-record-field-options.d.ts +17 -0
  73. package/plugins/runtime-modules/builder/clients/inspector-record-field-options.js +21 -0
  74. package/plugins/runtime-modules/builder/clients/inspector-translate-switch.d.ts +24 -0
  75. package/plugins/runtime-modules/builder/clients/inspector-translate-switch.js +29 -0
  76. package/plugins/runtime-modules/builder/clients/layout-inspector.d.ts +1 -1
  77. package/plugins/runtime-modules/builder/clients/layout-inspector.js +4 -2
  78. package/plugins/runtime-modules/builder/clients/widget-inspector.d.ts +1 -1
  79. package/plugins/runtime-modules/builder/clients/widget-inspector.js +6 -6
  80. package/plugins/runtime-modules/builder/plugin-meta-labels.js +17 -0
  81. package/plugins/runtime-modules/builder/render-root-node-scaffold.js +12 -2
  82. package/plugins/runtime-modules/builder/widgets/structure-region/plugin.js +0 -2
  83. package/plugins/runtime-modules/builder/widgets.js +3 -3
  84. package/plugins/runtime-modules/contracts.js +8 -4
  85. package/plugins/runtime-modules/core/authoring-widgets.js +2 -2
  86. package/plugins/runtime-modules/core/data-providers.d.ts +7 -3
  87. package/plugins/runtime-modules/core/data-providers.js +11 -1
  88. package/plugins/runtime-modules/core/definition.d.ts +7 -3
  89. package/plugins/runtime-modules/core/widgets/cascader/authoring.d.ts +1 -1
  90. package/plugins/runtime-modules/core/widgets/draft-status/client.d.ts +2 -1
  91. package/plugins/runtime-modules/core/widgets/draft-status/client.js +4 -3
  92. package/plugins/runtime-modules/core/widgets/gallery/authoring.js +6 -8
  93. package/plugins/runtime-modules/core/widgets/gallery/client.js +4 -0
  94. package/plugins/runtime-modules/core/widgets/gallery/config.js +1 -1
  95. package/plugins/runtime-modules/core/widgets/gallery/server.d.ts +5 -1
  96. package/plugins/runtime-modules/core/widgets/gallery/server.js +8 -4
  97. package/plugins/runtime-modules/core/widgets/image/config.js +1 -1
  98. package/plugins/runtime-modules/core/widgets/markdown/config.d.ts +11 -0
  99. package/plugins/runtime-modules/core/widgets/markdown/config.js +24 -22
  100. package/plugins/runtime-modules/core/widgets/simple-text/client.d.ts +9 -5
  101. package/plugins/runtime-modules/core/widgets/simple-text/client.js +5 -7
  102. package/plugins/runtime-modules/core/widgets/simple-text/config.d.ts +63 -4
  103. package/plugins/runtime-modules/core/widgets/simple-text/config.js +45 -11
  104. package/plugins/runtime-modules/core/widgets/simple-text/editor.js +2 -2
  105. package/plugins/runtime-modules/core/widgets/simple-text/plugin.d.ts +13 -0
  106. package/plugins/runtime-modules/core/widgets/simple-text/plugin.js +23 -4
  107. package/plugins/runtime-modules/core/widgets/simple-text/server.d.ts +4 -2
  108. package/plugins/runtime-modules/core/widgets/simple-text/server.js +7 -6
  109. package/plugins/runtime-modules/core/widgets/table/client.js +4 -4
  110. package/plugins/runtime-modules/core/widgets/table/config.js +11 -3
  111. package/plugins/runtime-modules/core/widgets/table/plugin.js +21 -1
  112. package/plugins/runtime-modules/core/widgets/thread-conversation/plugin.js +0 -2
  113. package/plugins/runtime-modules/core/widgets/tree/config.js +2 -1
  114. package/plugins/runtime-modules/core/widgets/tree/plugin.js +16 -1
  115. package/plugins/runtime-modules/core/widgets.js +1 -1
  116. package/plugins/runtime-modules/observability/data-providers.js +1 -1
  117. package/plugins/runtime-modules/theme/authoring-widgets.js +5 -5
  118. package/plugins/runtime-modules/theme/widgets/brand-controls/plugin.js +0 -5
  119. package/plugins/runtime-modules/theme/widgets.js +4 -4
  120. package/plugins/runtime-modules/user-management/addon-roles.d.ts +28 -7
  121. package/plugins/runtime-modules/user-management/addon-roles.js +42 -17
  122. package/plugins/runtime-modules/user-management/client-data-providers.js +6 -0
  123. package/plugins/runtime-modules/user-management/data-providers.js +11 -2
  124. package/plugins/runtime-modules/user-management/forms.js +40 -1
  125. package/plugins/runtime-modules/user-management/ids.d.ts +1 -0
  126. package/plugins/runtime-modules/user-management/ids.js +1 -0
  127. package/plugins/runtime-modules/user-management/services/options.d.ts +14 -3
  128. package/plugins/runtime-modules/user-management/services/options.js +52 -16
  129. package/plugins/runtime-modules/user-management/services/table.js +8 -24
  130. package/plugins/runtime-modules/user-management/services/users-query.d.ts +9 -0
  131. package/plugins/runtime-modules/user-management/services/users-query.js +29 -0
  132. package/plugins/runtime-modules/video/widgets/embed/plugin.js +0 -2
  133. package/plugins/runtime-modules/video/widgets.js +1 -1
  134. package/styles/layout.css +4 -4
  135. package/types/cms-config.d.ts +12 -4
  136. package/types/cms-config.js +3 -0
  137. package/types/cms-plugins.d.ts +26 -4
  138. package/types/core-widget-placements.d.ts +4 -4
  139. package/types/table-widget.d.ts +17 -1
  140. package/types/tree.d.ts +2 -0
  141. package/plugins/runtime-modules/asset/widgets/asset-focal-rect/authoring.d.ts +0 -2
  142. package/plugins/runtime-modules/asset/widgets/asset-focal-rect/authoring.js +0 -6
  143. package/plugins/runtime-modules/asset/widgets/image-inspector/authoring.d.ts +0 -2
  144. package/plugins/runtime-modules/asset/widgets/image-inspector/authoring.js +0 -6
  145. package/plugins/runtime-modules/auth/widgets/auth-methods/authoring.d.ts +0 -7
  146. package/plugins/runtime-modules/auth/widgets/auth-methods/authoring.js +0 -12
  147. package/plugins/runtime-modules/auth/widgets/auth-workflow/authoring.d.ts +0 -7
  148. package/plugins/runtime-modules/auth/widgets/auth-workflow/authoring.js +0 -12
  149. package/plugins/runtime-modules/auth/widgets/logout/authoring.d.ts +0 -3
  150. package/plugins/runtime-modules/auth/widgets/logout/authoring.js +0 -8
  151. package/plugins/runtime-modules/auth/widgets/security/authoring.d.ts +0 -3
  152. package/plugins/runtime-modules/auth/widgets/security/authoring.js +0 -8
  153. package/plugins/runtime-modules/avatar/widgets/account-avatar/authoring.d.ts +0 -2
  154. package/plugins/runtime-modules/avatar/widgets/account-avatar/authoring.js +0 -6
  155. package/plugins/runtime-modules/avatar/widgets/account-avatar-picker/authoring.d.ts +0 -2
  156. package/plugins/runtime-modules/avatar/widgets/account-avatar-picker/authoring.js +0 -6
  157. package/plugins/runtime-modules/builder/widgets/structure-region/internal-builder.d.ts +0 -22
  158. package/plugins/runtime-modules/builder/widgets/structure-region/internal-builder.js +0 -8
  159. package/plugins/runtime-modules/core/widgets/form-preview/authoring.d.ts +0 -10
  160. package/plugins/runtime-modules/core/widgets/form-preview/authoring.js +0 -15
  161. package/plugins/runtime-modules/core/widgets/thread-conversation/authoring.d.ts +0 -3
  162. package/plugins/runtime-modules/core/widgets/thread-conversation/authoring.js +0 -9
  163. package/plugins/runtime-modules/theme/widgets/brand-controls/authoring.d.ts +0 -76
  164. package/plugins/runtime-modules/theme/widgets/brand-controls/authoring.js +0 -30
@@ -4,8 +4,28 @@ import { phiRuntime } from "../../../../../server-helpers/phi-runtime";
4
4
  import { readPhiRuntimeTreeRenderMode } from "../../../render-mode";
5
5
  import { PHI_TABLE_WIDGET_DEFINITION } from "./config";
6
6
  import { PhiTableWidget } from "./server";
7
+ import { resolvePhiTableActionLinks } from "../../../../../helpers/table-action-links";
7
8
  import { getPhiTableWidgetLabels } from "../../../../../components/widgets/label-sets/table";
8
- async function PhiTableWidgetPluginServer({ widget, config, runtime, }) {
9
+ /** The config with every action's link target resolved to the address it leads to now. */
10
+ function resolvePhiTableConfigLinks(config, links) {
11
+ const actions = config.features.actions;
12
+ if (!actions)
13
+ return config;
14
+ return {
15
+ ...config,
16
+ features: {
17
+ ...config.features,
18
+ actions: {
19
+ ...actions,
20
+ toolbar: resolvePhiTableActionLinks(actions.toolbar, links),
21
+ row: resolvePhiTableActionLinks(actions.row, links),
22
+ bulk: resolvePhiTableActionLinks(actions.bulk, links),
23
+ },
24
+ },
25
+ };
26
+ }
27
+ async function PhiTableWidgetPluginServer({ widget, config: stored, runtime, links, }) {
28
+ const config = resolvePhiTableConfigLinks(stored, links);
9
29
  const rt = phiRuntime(runtime);
10
30
  const labels = await getPhiTableWidgetLabels({
11
31
  apiBaseUrl: rt.apiBaseUrl,
@@ -1,9 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { renderPhiWidgetPreviewPlaceholder } from "../../../../../plugins/factories/widget-renderers";
3
2
  import { PHI_THREAD_CONVERSATION_WIDGET_DEFINITION } from "./config";
4
3
  import { PhiThreadConversationWidget } from "./server";
5
4
  export const PHI_THREAD_CONVERSATION_WIDGET_PLUGIN = {
6
5
  ...PHI_THREAD_CONVERSATION_WIDGET_DEFINITION,
7
6
  render: ({ runtime, config }) => _jsx(PhiThreadConversationWidget, { runtime: runtime, config: config }),
8
- renderPreview: ({ widget }) => renderPhiWidgetPreviewPlaceholder(widget),
9
7
  };
@@ -1,4 +1,5 @@
1
1
  import { resolvePhiCmsWidgetPluginKey } from "../../../../../constants/cms-widget-types";
2
+ import { readPhiLinkTarget } from "../../../../../types/references";
2
3
  import { isPhiRuntimeDataProviderKey } from "../../../../../types/runtime-data-provider";
3
4
  import { PHI_SIGNAL_VALUE_SCHEMAS, readPhiSignalRouteSet } from "../../../../../types/signals";
4
5
  import { readPhiLengthValue } from "../../../../../types/length";
@@ -25,7 +26,7 @@ function readActions(value) {
25
26
  icon: readString(entry.icon),
26
27
  display: entry.display === "icon" || entry.display === "icon-label" ? entry.display : "label",
27
28
  mode: entry.mode === "primary" || entry.mode === "danger" ? entry.mode : "normal",
28
- href: readString(entry.href),
29
+ linkTarget: readPhiLinkTarget(entry.linkTarget) ?? undefined,
29
30
  hrefPath: readString(entry.hrefPath),
30
31
  newTab: readBoolean(entry.newTab),
31
32
  confirm: confirmTitle ? {
@@ -4,8 +4,23 @@ import { phiRuntime } from "../../../../../server-helpers/phi-runtime";
4
4
  import { readPhiRuntimeTreeRenderMode } from "../../../render-mode";
5
5
  import { PHI_TREE_WIDGET_DEFINITION } from "./config";
6
6
  import { PhiTreeWidget } from "./server";
7
+ import { resolvePhiTableActionLinks } from "../../../../../helpers/table-action-links";
7
8
  import { getPhiTreeWidgetLabels } from "../../../../../components/widgets/label-sets/tree";
8
- async function PhiTreeWidgetPluginServer({ widget, config, runtime }) {
9
+ async function PhiTreeWidgetPluginServer({ widget, config: stored, runtime, links }) {
10
+ // Where each action's target leads, resolved here: a Page reference means nothing in a browser.
11
+ const actions = stored.features.actions;
12
+ const config = !actions ? stored : {
13
+ ...stored,
14
+ features: {
15
+ ...stored.features,
16
+ actions: {
17
+ ...actions,
18
+ toolbar: resolvePhiTableActionLinks(actions.toolbar, links) ?? [],
19
+ node: resolvePhiTableActionLinks(actions.node, links) ?? [],
20
+ selection: resolvePhiTableActionLinks(actions.selection, links) ?? [],
21
+ },
22
+ },
23
+ };
9
24
  const rt = phiRuntime(runtime);
10
25
  const labels = await getPhiTreeWidgetLabels({ apiBaseUrl: rt.apiBaseUrl, internalToken: rt.internalToken, locale: runtime.locale.current });
11
26
  return _jsx(PhiTreeWidget, { config: config, labels: labels, renderMode: readPhiRuntimeTreeRenderMode(widget.config) });
@@ -395,7 +395,7 @@ export const PHI_RUNTIME_MODULE_WIDGETS = [
395
395
  definePhiFirstPartyWidget({
396
396
  definition: PHI_THREAD_CONVERSATION_WIDGET_DEFINITION,
397
397
  ownerModuleId: PHI_CORE_RUNTIME_MODULE_ID,
398
- renderPolicies: { runtime: "custom", preview: "custom", authoring: "custom" },
398
+ renderPolicies: { runtime: "custom", preview: "visualPlaceholder", authoring: "custom" },
399
399
  loadRuntime: () => import("./widgets/thread-conversation/plugin").then((module) => module.PHI_THREAD_CONVERSATION_WIDGET_PLUGIN),
400
400
  loadPreview: () => import("./widgets/thread-conversation/plugin").then((module) => module.PHI_THREAD_CONVERSATION_WIDGET_PLUGIN),
401
401
  }),
@@ -17,7 +17,7 @@ export const PHI_OBSERVABILITY_RUNTIME_DATA_PROVIDER_DESCRIPTORS = [
17
17
  { key: "id", title: "ID", type: "string", required: true },
18
18
  { key: "ts", title: "Timestamp", type: "datetime" },
19
19
  { key: "level", title: "Level", type: "string" },
20
- { key: "service", title: "Service", type: "string" },
20
+ { key: "service", title: "Source", type: "string" },
21
21
  { key: "event", title: "Event", type: "string" },
22
22
  { key: "area", title: "Area", type: "string" },
23
23
  { key: "userId", title: "User ID", type: "string" },
@@ -2,9 +2,9 @@
2
2
  import { PHI_BUILDER_BRAND_BACKGROUND_CONTROLS_WIDGET_DEFINITION, PHI_BUILDER_BRAND_IDENTITY_CONTROLS_WIDGET_DEFINITION, PHI_BUILDER_BRAND_STYLE_CONTROLS_WIDGET_DEFINITION, PHI_BUILDER_BRAND_THEME_CONTROLS_WIDGET_DEFINITION, PHI_BUILDER_BRAND_THEME_PREVIEW_WIDGET_DEFINITION, } from "./widgets/brand-controls/config";
3
3
  import { createPhiAuthoringWidgetModule, definePhiAuthoringWidgetModuleLoader, } from "../client-authoring-widget-module";
4
4
  export default createPhiAuthoringWidgetModule([
5
- definePhiAuthoringWidgetModuleLoader(PHI_BUILDER_BRAND_STYLE_CONTROLS_WIDGET_DEFINITION, () => import("./widgets/brand-controls/authoring").then((module) => module.PHI_BUILDER_BRAND_STYLE_CONTROLS_WIDGET_BUILDER_PLUGIN)),
6
- definePhiAuthoringWidgetModuleLoader(PHI_BUILDER_BRAND_THEME_CONTROLS_WIDGET_DEFINITION, () => import("./widgets/brand-controls/authoring").then((module) => module.PHI_BUILDER_BRAND_THEME_CONTROLS_WIDGET_BUILDER_PLUGIN)),
7
- definePhiAuthoringWidgetModuleLoader(PHI_BUILDER_BRAND_BACKGROUND_CONTROLS_WIDGET_DEFINITION, () => import("./widgets/brand-controls/authoring").then((module) => module.PHI_BUILDER_BRAND_BACKGROUND_CONTROLS_WIDGET_BUILDER_PLUGIN)),
8
- definePhiAuthoringWidgetModuleLoader(PHI_BUILDER_BRAND_IDENTITY_CONTROLS_WIDGET_DEFINITION, () => import("./widgets/brand-controls/authoring").then((module) => module.PHI_BUILDER_BRAND_IDENTITY_CONTROLS_WIDGET_BUILDER_PLUGIN)),
9
- definePhiAuthoringWidgetModuleLoader(PHI_BUILDER_BRAND_THEME_PREVIEW_WIDGET_DEFINITION, () => import("./widgets/brand-controls/authoring").then((module) => module.PHI_BUILDER_BRAND_THEME_PREVIEW_WIDGET_BUILDER_PLUGIN)),
5
+ definePhiAuthoringWidgetModuleLoader(PHI_BUILDER_BRAND_STYLE_CONTROLS_WIDGET_DEFINITION, () => Promise.resolve(PHI_BUILDER_BRAND_STYLE_CONTROLS_WIDGET_DEFINITION)),
6
+ definePhiAuthoringWidgetModuleLoader(PHI_BUILDER_BRAND_THEME_CONTROLS_WIDGET_DEFINITION, () => Promise.resolve(PHI_BUILDER_BRAND_THEME_CONTROLS_WIDGET_DEFINITION)),
7
+ definePhiAuthoringWidgetModuleLoader(PHI_BUILDER_BRAND_BACKGROUND_CONTROLS_WIDGET_DEFINITION, () => Promise.resolve(PHI_BUILDER_BRAND_BACKGROUND_CONTROLS_WIDGET_DEFINITION)),
8
+ definePhiAuthoringWidgetModuleLoader(PHI_BUILDER_BRAND_IDENTITY_CONTROLS_WIDGET_DEFINITION, () => Promise.resolve(PHI_BUILDER_BRAND_IDENTITY_CONTROLS_WIDGET_DEFINITION)),
9
+ definePhiAuthoringWidgetModuleLoader(PHI_BUILDER_BRAND_THEME_PREVIEW_WIDGET_DEFINITION, () => Promise.resolve(PHI_BUILDER_BRAND_THEME_PREVIEW_WIDGET_DEFINITION)),
10
10
  ]);
@@ -1,6 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { buildPhiWidgetLabelTranslatorOptions } from "../../../../../components/widgets/label-sets/runtime-options";
3
- import { PhiWidgetPreviewFallback } from "../../../../../components/widgets/built-in/widget-preview";
4
3
  import { PhiBuilderBrandBackgroundControlsWidgetClient, PhiBuilderBrandIdentityControlsWidgetClient, PhiBuilderBrandStyleControlsWidgetClient, PhiBuilderBrandThemeControlsWidgetClient, PhiBuilderBrandThemePreviewWidgetClient, } from "./client";
5
4
  import { PHI_BUILDER_BRAND_BACKGROUND_CONTROLS_WIDGET_DEFINITION, PHI_BUILDER_BRAND_IDENTITY_CONTROLS_WIDGET_DEFINITION, PHI_BUILDER_BRAND_STYLE_CONTROLS_WIDGET_DEFINITION, PHI_BUILDER_BRAND_THEME_CONTROLS_WIDGET_DEFINITION, PHI_BUILDER_BRAND_THEME_PREVIEW_WIDGET_DEFINITION, } from "./config";
6
5
  import { getPhiColorPickerLabels } from "../../../../../components/widgets/label-sets/color-picker";
@@ -9,7 +8,6 @@ import { PhiMediaPickerLabelsProvider } from "../../../../../components/media/ph
9
8
  export const PHI_BUILDER_BRAND_THEME_CONTROLS_WIDGET_PLUGIN = {
10
9
  ...PHI_BUILDER_BRAND_THEME_CONTROLS_WIDGET_DEFINITION,
11
10
  render: async ({ runtime, config }) => (_jsx(PhiBuilderBrandThemeControlsWidgetClient, { runtime: runtime, config: config, colorPickerLabels: await getPhiColorPickerLabels(buildPhiWidgetLabelTranslatorOptions(runtime)) })),
12
- renderPreview: ({ widget }) => (_jsx(PhiWidgetPreviewFallback, { widget: widget, pluginTitle: "Builder Brand Theme Controls", summary: "Brand theme controls are rendered live in the builder." })),
13
11
  };
14
12
  export const PHI_BUILDER_BRAND_THEME_PREVIEW_WIDGET_PLUGIN = {
15
13
  ...PHI_BUILDER_BRAND_THEME_PREVIEW_WIDGET_DEFINITION,
@@ -19,17 +17,14 @@ export const PHI_BUILDER_BRAND_THEME_PREVIEW_WIDGET_PLUGIN = {
19
17
  export const PHI_BUILDER_BRAND_STYLE_CONTROLS_WIDGET_PLUGIN = {
20
18
  ...PHI_BUILDER_BRAND_STYLE_CONTROLS_WIDGET_DEFINITION,
21
19
  render: ({ runtime, config }) => _jsx(PhiBuilderBrandStyleControlsWidgetClient, { runtime: runtime, config: config }),
22
- renderPreview: ({ widget }) => (_jsx(PhiWidgetPreviewFallback, { widget: widget, pluginTitle: "Builder Brand Style Controls", summary: "Brand style controls are rendered live in the builder." })),
23
20
  };
24
21
  export const PHI_BUILDER_BRAND_BACKGROUND_CONTROLS_WIDGET_PLUGIN = {
25
22
  ...PHI_BUILDER_BRAND_BACKGROUND_CONTROLS_WIDGET_DEFINITION,
26
23
  // The picker the Background Control opens says its words in the reader's language.
27
24
  render: async ({ runtime, config }) => (_jsx(PhiMediaPickerLabelsProvider, { labels: await getPhiMediaWidgetLabels(buildPhiWidgetLabelTranslatorOptions(runtime)), children: _jsx(PhiBuilderBrandBackgroundControlsWidgetClient, { runtime: runtime, config: config }) })),
28
- renderPreview: ({ widget }) => (_jsx(PhiWidgetPreviewFallback, { widget: widget, pluginTitle: "Builder Brand Background Controls", summary: "The Theme Root Background is authored live in the builder." })),
29
25
  };
30
26
  export const PHI_BUILDER_BRAND_IDENTITY_CONTROLS_WIDGET_PLUGIN = {
31
27
  ...PHI_BUILDER_BRAND_IDENTITY_CONTROLS_WIDGET_DEFINITION,
32
28
  // The picker the Logo field opens says its words in the reader's language.
33
29
  render: async ({ runtime, config }) => (_jsx(PhiMediaPickerLabelsProvider, { labels: await getPhiMediaWidgetLabels(buildPhiWidgetLabelTranslatorOptions(runtime)), children: _jsx(PhiBuilderBrandIdentityControlsWidgetClient, { runtime: runtime, config: config }) })),
34
- renderPreview: ({ widget }) => (_jsx(PhiWidgetPreviewFallback, { widget: widget, pluginTitle: "Builder Brand Identity Controls", summary: "The Logo and the Wordmark are authored live in the builder." })),
35
30
  };
@@ -5,28 +5,28 @@ export const PHI_RUNTIME_MODULE_WIDGETS = [
5
5
  definePhiFirstPartyWidget({
6
6
  definition: PHI_BUILDER_BRAND_STYLE_CONTROLS_WIDGET_DEFINITION,
7
7
  ownerModuleId: PHI_THEME_RUNTIME_MODULE_ID,
8
- renderPolicies: { "runtime": "custom", "preview": "custom", "authoring": "custom" },
8
+ renderPolicies: { "runtime": "custom", "preview": "visualPlaceholder", "authoring": "custom" },
9
9
  loadRuntime: () => import("./widgets/brand-controls/plugin").then((module) => module.PHI_BUILDER_BRAND_STYLE_CONTROLS_WIDGET_PLUGIN),
10
10
  loadPreview: () => import("./widgets/brand-controls/plugin").then((module) => module.PHI_BUILDER_BRAND_STYLE_CONTROLS_WIDGET_PLUGIN),
11
11
  }),
12
12
  definePhiFirstPartyWidget({
13
13
  definition: PHI_BUILDER_BRAND_THEME_CONTROLS_WIDGET_DEFINITION,
14
14
  ownerModuleId: PHI_THEME_RUNTIME_MODULE_ID,
15
- renderPolicies: { "runtime": "custom", "preview": "custom", "authoring": "custom" },
15
+ renderPolicies: { "runtime": "custom", "preview": "visualPlaceholder", "authoring": "custom" },
16
16
  loadRuntime: () => import("./widgets/brand-controls/plugin").then((module) => module.PHI_BUILDER_BRAND_THEME_CONTROLS_WIDGET_PLUGIN),
17
17
  loadPreview: () => import("./widgets/brand-controls/plugin").then((module) => module.PHI_BUILDER_BRAND_THEME_CONTROLS_WIDGET_PLUGIN),
18
18
  }),
19
19
  definePhiFirstPartyWidget({
20
20
  definition: PHI_BUILDER_BRAND_BACKGROUND_CONTROLS_WIDGET_DEFINITION,
21
21
  ownerModuleId: PHI_THEME_RUNTIME_MODULE_ID,
22
- renderPolicies: { "runtime": "custom", "preview": "custom", "authoring": "custom" },
22
+ renderPolicies: { "runtime": "custom", "preview": "visualPlaceholder", "authoring": "custom" },
23
23
  loadRuntime: () => import("./widgets/brand-controls/plugin").then((module) => module.PHI_BUILDER_BRAND_BACKGROUND_CONTROLS_WIDGET_PLUGIN),
24
24
  loadPreview: () => import("./widgets/brand-controls/plugin").then((module) => module.PHI_BUILDER_BRAND_BACKGROUND_CONTROLS_WIDGET_PLUGIN),
25
25
  }),
26
26
  definePhiFirstPartyWidget({
27
27
  definition: PHI_BUILDER_BRAND_IDENTITY_CONTROLS_WIDGET_DEFINITION,
28
28
  ownerModuleId: PHI_THEME_RUNTIME_MODULE_ID,
29
- renderPolicies: { "runtime": "custom", "preview": "custom", "authoring": "custom" },
29
+ renderPolicies: { "runtime": "custom", "preview": "visualPlaceholder", "authoring": "custom" },
30
30
  loadRuntime: () => import("./widgets/brand-controls/plugin").then((module) => module.PHI_BUILDER_BRAND_IDENTITY_CONTROLS_WIDGET_PLUGIN),
31
31
  loadPreview: () => import("./widgets/brand-controls/plugin").then((module) => module.PHI_BUILDER_BRAND_IDENTITY_CONTROLS_WIDGET_PLUGIN),
32
32
  }),
@@ -1,5 +1,8 @@
1
1
  export type PhiAddonRole = {
2
2
  name: string;
3
+ description?: string;
4
+ /** Whether the acting person may hand this role out, as the Core decided it for this request. */
5
+ grantable: boolean;
3
6
  };
4
7
  export type PhiAddonRoleCatalogEntry = {
5
8
  addonId: string;
@@ -23,13 +26,31 @@ export declare const PHI_USER_MANAGEMENT_ADDON_ALL_ROLES_TAG = "all";
23
26
  * are not listed (they apply when the person is no longer one; the dialog shows them).
24
27
  */
25
28
  export declare function buildPhiAddonRoleTags(row: Record<string, unknown>): string[];
26
- /** The filter's options: each Add-on (any role), then each of its roles. Values are `<addonId>` and `<addonId>:<role>`. */
27
- export declare function buildPhiAddonRoleFilterOptions(catalog: readonly PhiAddonRoleCatalogEntry[]): {
29
+ /**
30
+ * The users Table filter's options: one per Add-on, never a single role -- choosing one finds whoever holds
31
+ * any of its roles (the Core's `addonId` filter). The label is the Add-on's title; the id is the description,
32
+ * left out while the title is the id itself, so the list does not say everything twice.
33
+ */
34
+ export declare function buildPhiAddonFilterOptions(catalog: readonly PhiAddonRoleCatalogEntry[]): {
35
+ description?: string | undefined;
36
+ value: string;
37
+ label: string;
38
+ }[];
39
+ /**
40
+ * The edit form's Add-on role choices, under one heading per Add-on: every role the acting person may grant,
41
+ * and the ones the person edited holds that the actor may not grant, disabled.
42
+ *
43
+ * The save takes the whole list of roles the person is to hold afterwards and checks every difference to
44
+ * what is stored against the actor. A held role missing from the choices would be a value with no option,
45
+ * which the control lets anyone remove -- and the save would then ask to take back a role the actor has no
46
+ * standing over. As a disabled option it stays in the value as a tag nobody can remove, and the save sends it
47
+ * unchanged. `held` is null where the Core did not say what the person holds; every role the actor may not
48
+ * grant is listed disabled then, so whichever of them the person holds is kept the same way.
49
+ */
50
+ export declare function buildPhiAddonRoleChoiceOptions(catalog: readonly PhiAddonRoleCatalogEntry[], held: readonly PhiAddonRoleAssignment[] | null): {
51
+ disabled?: boolean | undefined;
52
+ group: string;
53
+ description?: string | undefined;
28
54
  value: string;
29
55
  label: string;
30
56
  }[];
31
- /** The Core's `addonId` and optional `addonRole` filters from the one value the Table filter holds. */
32
- export declare function parsePhiAddonRoleFilter(value: string): {
33
- addonId: string;
34
- addonRole: string | null;
35
- } | null;
@@ -18,7 +18,8 @@ export function readPhiAddonRoleCatalog(payload) {
18
18
  const name = readString(role.name);
19
19
  if (!name || !ROLE_NAME.test(name))
20
20
  return [];
21
- return [{ name }];
21
+ const description = readString(role.description);
22
+ return [{ name, ...(description ? { description } : {}), grantable: role.grantable === true }];
22
23
  });
23
24
  return roles.length > 0 ? [{ addonId, title: readString(addon.title) ?? addonId, roles }] : [];
24
25
  });
@@ -56,21 +57,45 @@ export function buildPhiAddonRoleTags(row) {
56
57
  }
57
58
  return [...byAddon].map(([addonId, roles]) => `${addonId}: ${roles.join(", ")}`);
58
59
  }
59
- /** The filter's options: each Add-on (any role), then each of its roles. Values are `<addonId>` and `<addonId>:<role>`. */
60
- export function buildPhiAddonRoleFilterOptions(catalog) {
61
- return catalog.flatMap((entry) => [
62
- { value: entry.addonId, label: entry.title },
63
- ...entry.roles.map((role) => ({ value: `${entry.addonId}:${role.name}`, label: `${entry.title}: ${role.name}` })),
64
- ]);
60
+ /**
61
+ * The users Table filter's options: one per Add-on, never a single role -- choosing one finds whoever holds
62
+ * any of its roles (the Core's `addonId` filter). The label is the Add-on's title; the id is the description,
63
+ * left out while the title is the id itself, so the list does not say everything twice.
64
+ */
65
+ export function buildPhiAddonFilterOptions(catalog) {
66
+ return catalog.map((entry) => ({
67
+ value: entry.addonId,
68
+ label: entry.title,
69
+ ...(entry.title === entry.addonId ? {} : { description: entry.addonId }),
70
+ }));
71
+ }
72
+ /** One role as the user save names it: `"<addonId>:<role>"`, which the Core splits at the last colon. */
73
+ function formatPhiAddonRoleValue(addonId, role) {
74
+ return `${addonId}:${role}`;
65
75
  }
66
- /** The Core's `addonId` and optional `addonRole` filters from the one value the Table filter holds. */
67
- export function parsePhiAddonRoleFilter(value) {
68
- const trimmed = value.trim();
69
- if (!trimmed)
70
- return null;
71
- const cut = trimmed.lastIndexOf(":");
72
- const role = cut > 0 ? trimmed.slice(cut + 1) : null;
73
- if (role !== null && ROLE_NAME.test(role))
74
- return { addonId: trimmed.slice(0, cut), addonRole: role };
75
- return { addonId: trimmed, addonRole: null };
76
+ /**
77
+ * The edit form's Add-on role choices, under one heading per Add-on: every role the acting person may grant,
78
+ * and the ones the person edited holds that the actor may not grant, disabled.
79
+ *
80
+ * The save takes the whole list of roles the person is to hold afterwards and checks every difference to
81
+ * what is stored against the actor. A held role missing from the choices would be a value with no option,
82
+ * which the control lets anyone remove -- and the save would then ask to take back a role the actor has no
83
+ * standing over. As a disabled option it stays in the value as a tag nobody can remove, and the save sends it
84
+ * unchanged. `held` is null where the Core did not say what the person holds; every role the actor may not
85
+ * grant is listed disabled then, so whichever of them the person holds is kept the same way.
86
+ */
87
+ export function buildPhiAddonRoleChoiceOptions(catalog, held) {
88
+ const heldValues = held ? new Set(held.map(({ addonId, role }) => formatPhiAddonRoleValue(addonId, role))) : null;
89
+ return catalog.flatMap((entry) => entry.roles.flatMap((role) => {
90
+ const value = formatPhiAddonRoleValue(entry.addonId, role.name);
91
+ if (!role.grantable && heldValues && !heldValues.has(value))
92
+ return [];
93
+ return [{
94
+ value,
95
+ label: role.name,
96
+ ...(role.description ? { description: role.description } : {}),
97
+ group: entry.title,
98
+ ...(role.grantable ? {} : { disabled: true }),
99
+ }];
100
+ }));
76
101
  }
@@ -8,6 +8,12 @@ export const PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_CLIENT_DEFINITIONS = [
8
8
  loadLive: async () => (await import("../../../plugins/runtime-modules/user-management/services/options"))
9
9
  .PhiUserManagementAddonRoleOptionsProviderClient,
10
10
  },
11
+ {
12
+ key: PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_KEYS.addonRoleChoiceOptions,
13
+ ownerModuleId: PHI_USER_MANAGEMENT_RUNTIME_MODULE_ID,
14
+ loadLive: async () => (await import("../../../plugins/runtime-modules/user-management/services/options"))
15
+ .PhiUserManagementAddonRoleChoiceOptionsProviderClient,
16
+ },
11
17
  {
12
18
  key: PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_KEYS.table,
13
19
  ownerModuleId: PHI_USER_MANAGEMENT_RUNTIME_MODULE_ID,
@@ -8,8 +8,17 @@ export const PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_DESCRIPTORS = [
8
8
  kind: "options",
9
9
  executionMode: "live",
10
10
  authoringMode: "none",
11
- title: "Add-on roles",
12
- description: "The Add-ons enabled for the Site and their declared roles, for filtering users by them.",
11
+ title: "Add-ons with roles",
12
+ description: "The Add-ons enabled for the Site that declare roles, for filtering users by them.",
13
+ },
14
+ {
15
+ key: PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_KEYS.addonRoleChoiceOptions,
16
+ ownerModuleId: PHI_USER_MANAGEMENT_RUNTIME_MODULE_ID,
17
+ kind: "options",
18
+ executionMode: "live",
19
+ authoringMode: "none",
20
+ title: "Add-on roles to grant",
21
+ description: "The Add-on roles the acting user may grant, and the ones the edited user holds, for assigning them.",
13
22
  },
14
23
  {
15
24
  key: PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_KEYS.table,
@@ -1,6 +1,6 @@
1
1
  import { createPhiFormLabelSetLoader } from "../../../components/forms/shared-form-loaders";
2
2
  import { PHI_BASE_ROLE_OPTIONS } from "../../../constants/phi-base-role-metadata";
3
- import { PHI_USER_MANAGEMENT_RUNTIME_MODULE_ID } from "../../../plugins/runtime-modules/user-management/ids";
3
+ import { PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_KEYS, PHI_USER_MANAGEMENT_RUNTIME_MODULE_ID, } from "../../../plugins/runtime-modules/user-management/ids";
4
4
  import { createPhiFormId } from "../../../types/form-id";
5
5
  import { PHI_SHARED_PACKAGE_NAME } from "../../../types/signals";
6
6
  import { PHI_FORM_FIELD_PROVIDER_KEYS, PHI_FORM_VALIDATION_PROVIDER_KEYS, createPhiSharedFormProviderKey, } from "../../../components/forms/form-provider-contract";
@@ -31,6 +31,17 @@ const selfRoleCondition = {
31
31
  operator: "truthy",
32
32
  reason: "Your own roles cannot be changed here.",
33
33
  };
34
+ /*
35
+ * A Site Admin holds every Add-on role whatever is stored, so choosing some says nothing. Read off the form's
36
+ * own Core roles rather than the record: whoever takes `admin` away in the same dialog may then choose.
37
+ */
38
+ const siteAdminTargetCondition = {
39
+ source: "form",
40
+ valuePath: "roles",
41
+ operator: "contains",
42
+ value: "admin",
43
+ reason: "A Site Admin holds every Add-on role.",
44
+ };
34
45
  const selfEnabledCondition = {
35
46
  source: "controller",
36
47
  controllerAddress,
@@ -111,7 +122,32 @@ function descriptor(formId, mode) {
111
122
  ? { match: "any", conditions: [readOnlyCondition, selfRoleCondition] }
112
123
  : readOnlyCondition,
113
124
  },
125
+ /*
126
+ * Edit only: the Core's create takes no Add-on roles. The value is the whole list the person is to hold
127
+ * afterwards; a held role the actor may not grant is a disabled option, so it stays in the value and is
128
+ * sent unchanged (`buildPhiAddonRoleChoiceOptions`).
129
+ */
114
130
  ...(edit ? [
131
+ {
132
+ key: "addonRoles",
133
+ fieldProviderKey: PHI_FORM_FIELD_PROVIDER_KEYS.multiSelect,
134
+ label: label("addonRoles", "Add-on roles"),
135
+ placeholder: label("addonRolesPlaceholder", "Choose Add-on roles"),
136
+ description: label("addonRolesHint", "A Site Admin holds every Add-on role. Your own Add-on roles cannot be changed here."),
137
+ optionsProvider: {
138
+ providerKey: PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_KEYS.addonRoleChoiceOptions,
139
+ /*
140
+ * Which roles the person holds decides which ones the actor may not grant are still listed. Required,
141
+ * so the catalog is asked once the record has filled the form, not once before it as well.
142
+ */
143
+ dependencies: [{ param: "userId", source: "form", valuePath: "userId", required: true }],
144
+ },
145
+ initialValue: [],
146
+ disabledWhen: {
147
+ match: "any",
148
+ conditions: [readOnlyCondition, selfRoleCondition, siteAdminTargetCondition],
149
+ },
150
+ },
115
151
  {
116
152
  key: "enabled",
117
153
  fieldProviderKey: PHI_FORM_FIELD_PROVIDER_KEYS.switch,
@@ -145,6 +181,9 @@ const loadLabels = createPhiFormLabelSetLoader(() => import("../../../components
145
181
  roles: labels.editor.roles,
146
182
  rolesPlaceholder: labels.editor.rolesPlaceholder,
147
183
  rolesHint: labels.editor.selfRoleHint,
184
+ addonRoles: labels.editor.addonRoles,
185
+ addonRolesPlaceholder: labels.editor.addonRolesPlaceholder,
186
+ addonRolesHint: labels.editor.addonRolesHint,
148
187
  authOnlyHint: labels.editor.authOnlyHint,
149
188
  createPasswordHint: labels.editor.createPasswordHint,
150
189
  enabled: labels.columns.enabled,
@@ -11,4 +11,5 @@ export declare const PHI_USER_MANAGEMENT_RUNTIME_MODULE_IDENTITY: {
11
11
  export declare const PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_KEYS: {
12
12
  readonly table: `${string}/${string}`;
13
13
  readonly addonRoleOptions: `${string}/${string}`;
14
+ readonly addonRoleChoiceOptions: `${string}/${string}`;
14
15
  };
@@ -13,4 +13,5 @@ export const PHI_USER_MANAGEMENT_RUNTIME_MODULE_IDENTITY = {
13
13
  export const PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_KEYS = {
14
14
  table: createPhiSharedRuntimeDataProviderKey("tables", "user-management"),
15
15
  addonRoleOptions: createPhiSharedRuntimeDataProviderKey("options", "user-management-addon-roles"),
16
+ addonRoleChoiceOptions: createPhiSharedRuntimeDataProviderKey("options", "user-management-addon-role-choices"),
16
17
  };
@@ -1,8 +1,19 @@
1
1
  /**
2
- * The Add-ons enabled for the Site and their roles, as one filter's options: an Add-on (any role) and each
3
- * role of it. The Core answers every signed-in caller (`GET /api/site/addon-roles`); who may see the users
4
- * list at all is settled by the users route itself.
2
+ * The Add-ons enabled for the Site that declare roles, as the users Table filter's options: one per Add-on,
3
+ * matching whoever holds any of its roles. The Core answers every signed-in caller
4
+ * (`GET /api/site/addon-roles`); who may see the users list at all is settled by the users route itself.
5
5
  */
6
6
  export declare const PhiUserManagementAddonRoleOptionsProviderClient: import("react").ComponentType<{
7
7
  children: import("react").ReactNode;
8
8
  }>;
9
+ /**
10
+ * The Add-on roles the edit form offers one user (`buildPhiAddonRoleChoiceOptions`): the catalog with what
11
+ * the person holds, from `GET /api/site/addon-roles?userId=`, asked once per user the form is opened on.
12
+ *
13
+ * The Core refuses that question to an actor who may grant no role at all; such an actor is offered nothing,
14
+ * and the plain catalog lists every role disabled, which keeps whatever the person holds. So does an answer
15
+ * without a user to ask about.
16
+ */
17
+ export declare const PhiUserManagementAddonRoleChoiceOptionsProviderClient: import("react").ComponentType<{
18
+ children: import("react").ReactNode;
19
+ }>;
@@ -1,25 +1,61 @@
1
1
  "use client";
2
2
  import { createPhiControlOptionsProviderClient } from "../../../../components/controls/phi-options-provider";
3
- import { buildPhiAddonRoleFilterOptions, readPhiAddonRoleCatalog } from "../addon-roles";
3
+ import { isPhiRecord } from "../../../../helpers/is-record";
4
+ import { buildPhiAddonFilterOptions, buildPhiAddonRoleChoiceOptions, readPhiAddonRoleAssignments, readPhiAddonRoleCatalog, } from "../addon-roles";
4
5
  import { PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_KEYS } from "../ids";
6
+ const ADDON_ROLES_PATH = "/api/site/addon-roles";
7
+ async function fetchAddonRoles(query) {
8
+ return await fetch(`${ADDON_ROLES_PATH}${query}`, {
9
+ cache: "no-store",
10
+ credentials: "include",
11
+ headers: { accept: "application/json" },
12
+ });
13
+ }
14
+ async function readAddonRolesAnswer(response) {
15
+ const payload = await response.json().catch(() => null);
16
+ if (!response.ok)
17
+ throw new Error("Failed to load the Add-on roles.");
18
+ return payload;
19
+ }
5
20
  /**
6
- * The Add-ons enabled for the Site and their roles, as one filter's options: an Add-on (any role) and each
7
- * role of it. The Core answers every signed-in caller (`GET /api/site/addon-roles`); who may see the users
8
- * list at all is settled by the users route itself.
21
+ * The Add-ons enabled for the Site that declare roles, as the users Table filter's options: one per Add-on,
22
+ * matching whoever holds any of its roles. The Core answers every signed-in caller
23
+ * (`GET /api/site/addon-roles`); who may see the users list at all is settled by the users route itself.
9
24
  */
10
25
  export const PhiUserManagementAddonRoleOptionsProviderClient = createPhiControlOptionsProviderClient({
11
26
  key: PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_KEYS.addonRoleOptions,
12
- load: async () => {
13
- const response = await fetch("/api/site/addon-roles", {
14
- cache: "no-store",
15
- credentials: "include",
16
- headers: { accept: "application/json" },
17
- });
18
- const payload = await response.json().catch(() => null);
19
- if (!response.ok)
20
- throw new Error("Failed to load the Add-on roles.");
21
- return payload;
22
- },
27
+ load: async () => await readAddonRolesAnswer(await fetchAddonRoles("")),
23
28
  resolveLoadKey: () => "user-management-addon-roles",
24
- resolve: (context) => ({ options: buildPhiAddonRoleFilterOptions(readPhiAddonRoleCatalog(context.asyncData)) }),
29
+ resolve: (context) => ({ options: buildPhiAddonFilterOptions(readPhiAddonRoleCatalog(context.asyncData)) }),
30
+ });
31
+ function readUserId(value) {
32
+ const text = typeof value === "number" ? String(value) : typeof value === "string" ? value.trim() : "";
33
+ return /^[1-9][0-9]*$/u.test(text) ? text : null;
34
+ }
35
+ /**
36
+ * The Add-on roles the edit form offers one user (`buildPhiAddonRoleChoiceOptions`): the catalog with what
37
+ * the person holds, from `GET /api/site/addon-roles?userId=`, asked once per user the form is opened on.
38
+ *
39
+ * The Core refuses that question to an actor who may grant no role at all; such an actor is offered nothing,
40
+ * and the plain catalog lists every role disabled, which keeps whatever the person holds. So does an answer
41
+ * without a user to ask about.
42
+ */
43
+ export const PhiUserManagementAddonRoleChoiceOptionsProviderClient = createPhiControlOptionsProviderClient({
44
+ key: PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_KEYS.addonRoleChoiceOptions,
45
+ load: async ({ dependencies }) => {
46
+ const userId = readUserId(dependencies.userId);
47
+ if (userId) {
48
+ const response = await fetchAddonRoles(`?${new URLSearchParams({ userId }).toString()}`);
49
+ if (response.status !== 403)
50
+ return await readAddonRolesAnswer(response);
51
+ }
52
+ return await readAddonRolesAnswer(await fetchAddonRoles(""));
53
+ },
54
+ resolveLoadKey: () => "user-management-addon-role-choices",
55
+ resolve: (context) => {
56
+ const held = isPhiRecord(context.asyncData) && Array.isArray(context.asyncData.held)
57
+ ? readPhiAddonRoleAssignments(context.asyncData.held)
58
+ : null;
59
+ return { options: buildPhiAddonRoleChoiceOptions(readPhiAddonRoleCatalog(context.asyncData), held) };
60
+ },
25
61
  });
@@ -1,8 +1,9 @@
1
1
  "use client";
2
2
  import { isPhiRecord } from "../../../../helpers/is-record";
3
3
  import { PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_KEYS } from "../ids";
4
- import { buildPhiAddonRoleTags, parsePhiAddonRoleFilter } from "../addon-roles";
5
- import { buildPhiTablePageParams, createPhiTableProviderRequestInit, readPhiPositiveInteger, readPhiTableRows, readPhiTableStringFilter, } from "../../../../components/widgets/client/shared/phi-table-provider-request";
4
+ import { buildPhiAddonRoleTags } from "../addon-roles";
5
+ import { createPhiTableProviderRequestInit, readPhiPositiveInteger, readPhiTableRows, } from "../../../../components/widgets/client/shared/phi-table-provider-request";
6
+ import { buildPhiUserManagementUsersQueryParams } from "./users-query";
6
7
  import { PhiTableProviderError, } from "../../../../types/table-widget";
7
8
  import { createPhiTableProviderClient } from "../../../../components/widgets/client/shared/phi-table-provider";
8
9
  import { PHI_USER_MANAGEMENT_RUNTIME_DATA_PROVIDER_DESCRIPTORS } from "../../../../plugins/runtime-modules/user-management/data-providers";
@@ -10,28 +11,7 @@ import { readPhiTableProviderResponse, } from "../../../../components/widgets/cl
10
11
  const API_PATH = "/api/site/admin/users";
11
12
  const RESPONSE_OPTIONS = { subject: "User Management" };
12
13
  async function loadUsers({ query, signal, }) {
13
- const params = buildPhiTablePageParams(query, 20);
14
- const search = query.search?.trim() ?? "";
15
- const accountType = readPhiTableStringFilter(query, "accountType");
16
- const addonRole = parsePhiAddonRoleFilter(readPhiTableStringFilter(query, "addonRole"));
17
- const enabled = readPhiTableStringFilter(query, "enabled");
18
- if (search)
19
- params.set("search", search);
20
- if (accountType)
21
- params.set("accountType", accountType);
22
- // The Core's two filters: an Add-on, and optionally one of its roles (`addonRole` needs `addonId`).
23
- if (addonRole) {
24
- params.set("addonId", addonRole.addonId);
25
- if (addonRole.addonRole)
26
- params.set("addonRole", addonRole.addonRole);
27
- }
28
- if (enabled)
29
- params.set("enabled", enabled);
30
- const primarySort = query.sorts?.[0];
31
- if (primarySort) {
32
- params.set("sortKey", primarySort.key);
33
- params.set("sortOrder", primarySort.direction === "descending" ? "descend" : "ascend");
34
- }
14
+ const params = buildPhiUserManagementUsersQueryParams(query);
35
15
  const result = await readPhiTableProviderResponse(await fetch(`${API_PATH}?${params.toString()}`, createPhiTableProviderRequestInit(signal)), RESPONSE_OPTIONS);
36
16
  const rows = readPhiTableRows(result?.rows).map((row) => ({ ...row, addonRoleTags: buildPhiAddonRoleTags(row) }));
37
17
  if (typeof result?.siteTotal !== "number" || !Number.isFinite(result.siteTotal) || result.siteTotal < 0) {
@@ -87,6 +67,10 @@ async function readUserRecord({ rowIdentity, signal }) {
87
67
  ...user,
88
68
  userId: String(userId),
89
69
  roles: Array.isArray(user.roleTags) ? user.roleTags : [],
70
+ // `"<addonId>:<role>"`, the form the save takes back.
71
+ addonRoles: Array.isArray(user.addonRoles)
72
+ ? user.addonRoles.filter((entry) => typeof entry === "string")
73
+ : [],
90
74
  changePassword: false,
91
75
  };
92
76
  }
@@ -0,0 +1,9 @@
1
+ import type { PhiTableQuery } from "../../../../types/table-widget";
2
+ /**
3
+ * The users route's query for one Table page: the page, the search, the filters and the sort. Apart from
4
+ * the Provider so what the Table asks the Core can be read without a request.
5
+ *
6
+ * The Add-on role filter holds an Add-on id and is sent as the Core's `addonId` alone: whoever holds any role
7
+ * of that Add-on. The Core's `addonRole` is not asked for.
8
+ */
9
+ export declare function buildPhiUserManagementUsersQueryParams(query: PhiTableQuery): URLSearchParams;