@kivacore/ui-pro-shared 0.0.9 → 0.0.10

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 (145) hide show
  1. package/package.json +187 -21
  2. package/src/.kiva/config.json +27 -0
  3. package/src/components/avatar-group.tsx +222 -0
  4. package/src/components/kiva/bulk-update-dialog/bulk-update-dialog.tsx +240 -0
  5. package/src/components/kiva/bulk-update-dialog/index.tsx +6 -0
  6. package/src/components/kiva/bulk-update-dialog/types.ts +33 -0
  7. package/src/components/kiva/calendar/animations.ts +40 -0
  8. package/src/components/kiva/calendar/calendar-body.tsx +106 -0
  9. package/src/components/kiva/calendar/calendar-sidebar.tsx +103 -0
  10. package/src/components/kiva/calendar/calendar.tsx +243 -0
  11. package/src/components/kiva/calendar/constants.ts +12 -0
  12. package/src/components/kiva/calendar/contexts/calendar-context.tsx +696 -0
  13. package/src/components/kiva/calendar/contexts/dnd-context.tsx +173 -0
  14. package/src/components/kiva/calendar/dialogs/add-edit-event-dialog.tsx +287 -0
  15. package/src/components/kiva/calendar/dialogs/delete-event-dialog.tsx +73 -0
  16. package/src/components/kiva/calendar/dialogs/event-details-dialog.tsx +163 -0
  17. package/src/components/kiva/calendar/dialogs/events-list-dialog.tsx +122 -0
  18. package/src/components/kiva/calendar/dnd/draggable-event.tsx +66 -0
  19. package/src/components/kiva/calendar/dnd/droppable-area.tsx +53 -0
  20. package/src/components/kiva/calendar/dnd/resizable-event.tsx +190 -0
  21. package/src/components/kiva/calendar/header/calendar-header.tsx +84 -0
  22. package/src/components/kiva/calendar/header/date-navigator.tsx +188 -0
  23. package/src/components/kiva/calendar/header/filter.tsx +80 -0
  24. package/src/components/kiva/calendar/header/today-button.tsx +49 -0
  25. package/src/components/kiva/calendar/header/user-select.tsx +111 -0
  26. package/src/components/kiva/calendar/header/view-tabs.tsx +144 -0
  27. package/src/components/kiva/calendar/helpers.ts +617 -0
  28. package/src/components/kiva/calendar/hooks/use-disclosure.ts +19 -0
  29. package/src/components/kiva/calendar/hooks/use-local-storage.ts +40 -0
  30. package/src/components/kiva/calendar/hooks/use-media-query.ts +25 -0
  31. package/src/components/kiva/calendar/hooks.ts +5 -0
  32. package/src/components/kiva/calendar/index.tsx +27 -0
  33. package/src/components/kiva/calendar/interfaces.ts +35 -0
  34. package/src/components/kiva/calendar/schemas.ts +20 -0
  35. package/src/components/kiva/calendar/settings/settings.tsx +116 -0
  36. package/src/components/kiva/calendar/skeletons/calendar-header-skeleton.tsx +27 -0
  37. package/src/components/kiva/calendar/skeletons/calendar-skeleton.tsx +19 -0
  38. package/src/components/kiva/calendar/skeletons/day-view-skeleton.tsx +40 -0
  39. package/src/components/kiva/calendar/skeletons/month-view-skeleton.tsx +36 -0
  40. package/src/components/kiva/calendar/skeletons/week-view-skeleton.tsx +48 -0
  41. package/src/components/kiva/calendar/skeletons/year-view-skeleton.tsx +42 -0
  42. package/src/components/kiva/calendar/types.ts +25 -0
  43. package/src/components/kiva/calendar/views/agenda-view/agenda-events.tsx +150 -0
  44. package/src/components/kiva/calendar/views/month-view/calendar-month-view.tsx +82 -0
  45. package/src/components/kiva/calendar/views/month-view/day-cell.tsx +218 -0
  46. package/src/components/kiva/calendar/views/month-view/event-bullet.tsx +46 -0
  47. package/src/components/kiva/calendar/views/month-view/month-event-badge.tsx +154 -0
  48. package/src/components/kiva/calendar/views/timeline/calendar-timeline-view.tsx +100 -0
  49. package/src/components/kiva/calendar/views/timeline/lib/timeline-layout.ts +130 -0
  50. package/src/components/kiva/calendar/views/timeline/lib/timeline-model.ts +504 -0
  51. package/src/components/kiva/calendar/views/timeline/timeline-event-bar.tsx +68 -0
  52. package/src/components/kiva/calendar/views/timeline/timeline-grid-header.tsx +125 -0
  53. package/src/components/kiva/calendar/views/timeline/timeline-row.tsx +159 -0
  54. package/src/components/kiva/calendar/views/timeline/timeline-section.tsx +61 -0
  55. package/src/components/kiva/calendar/views/timeline/use-timeline-sections.ts +278 -0
  56. package/src/components/kiva/calendar/views/week-and-day-view/calendar-day-view.tsx +277 -0
  57. package/src/components/kiva/calendar/views/week-and-day-view/calendar-time-line.tsx +47 -0
  58. package/src/components/kiva/calendar/views/week-and-day-view/calendar-week-view.tsx +229 -0
  59. package/src/components/kiva/calendar/views/week-and-day-view/day-view-multi-day-events-row.tsx +79 -0
  60. package/src/components/kiva/calendar/views/week-and-day-view/event-block.tsx +116 -0
  61. package/src/components/kiva/calendar/views/week-and-day-view/render-grouped-events.tsx +54 -0
  62. package/src/components/kiva/calendar/views/week-and-day-view/week-view-multi-day-events-row.tsx +159 -0
  63. package/src/components/kiva/calendar/views/year-view/calendar-year-view.tsx +159 -0
  64. package/src/components/kiva/data-table-side-filters/components/side-filter-active-chips.tsx +137 -0
  65. package/src/components/kiva/data-table-side-filters/components/side-filter-clear.tsx +34 -0
  66. package/src/components/kiva/data-table-side-filters/components/side-filter-search.tsx +67 -0
  67. package/src/components/kiva/data-table-side-filters/components/side-filter-section.tsx +77 -0
  68. package/src/components/kiva/data-table-side-filters/controllers/side-filter-async-options.tsx +354 -0
  69. package/src/components/kiva/data-table-side-filters/controllers/side-filter-boolean.tsx +66 -0
  70. package/src/components/kiva/data-table-side-filters/controllers/side-filter-checkbox-list.tsx +137 -0
  71. package/src/components/kiva/data-table-side-filters/controllers/side-filter-date-range.tsx +204 -0
  72. package/src/components/kiva/data-table-side-filters/controllers/side-filter-numeric-range.tsx +162 -0
  73. package/src/components/kiva/data-table-side-filters/controllers/side-filter-options-dropdown.tsx +191 -0
  74. package/src/components/kiva/data-table-side-filters/controllers/side-filter-text.tsx +53 -0
  75. package/src/components/kiva/data-table-side-filters/core/query-translator.ts +367 -0
  76. package/src/components/kiva/data-table-side-filters/core/types.ts +81 -0
  77. package/src/components/kiva/data-table-side-filters/data-table-side-filters.tsx +483 -0
  78. package/src/components/kiva/data-table-side-filters/hooks/use-data-table-side-filters.tsx +160 -0
  79. package/src/components/kiva/data-table-side-filters/hooks/use-show-more.tsx +62 -0
  80. package/src/components/kiva/data-table-side-filters/index.tsx +44 -0
  81. package/src/components/kiva/data-table-side-filters/lib/render-mode.ts +62 -0
  82. package/src/components/kiva/date-time-picker.tsx +163 -0
  83. package/src/components/kiva/editable-record-detail.tsx +809 -0
  84. package/src/components/kiva/enum-option-editor/enum-option-editor.tsx +891 -0
  85. package/src/components/kiva/enum-option-editor/index.tsx +26 -0
  86. package/src/components/kiva/enum-option-editor/kiva-enum-option-editor.tsx +320 -0
  87. package/src/components/kiva/enum-option-editor/types.ts +90 -0
  88. package/src/components/kiva/kanban.tsx +1376 -0
  89. package/src/components/kiva/kiva-data-export-menu.tsx +543 -0
  90. package/src/components/kiva/map.tsx +1631 -0
  91. package/src/components/kiva/pivot-calendar/components/group-sidebar.tsx +95 -0
  92. package/src/components/kiva/pivot-calendar/components/pivot-calendar-toolbar.tsx +113 -0
  93. package/src/components/kiva/pivot-calendar/components/stats-cell.tsx +126 -0
  94. package/src/components/kiva/pivot-calendar/helpers.ts +374 -0
  95. package/src/components/kiva/pivot-calendar/hooks/use-pivot-calendar.ts +222 -0
  96. package/src/components/kiva/pivot-calendar/index.tsx +32 -0
  97. package/src/components/kiva/pivot-calendar/pivot-calendar.tsx +107 -0
  98. package/src/components/kiva/pivot-calendar/types.ts +154 -0
  99. package/src/components/kiva/pivot-calendar/views/days-of-month-view.tsx +37 -0
  100. package/src/components/kiva/pivot-calendar/views/days-of-week-view.tsx +37 -0
  101. package/src/components/kiva/pivot-calendar/views/month-calendar-view.tsx +154 -0
  102. package/src/components/kiva/pivot-calendar/views/months-of-year-view.tsx +40 -0
  103. package/src/components/kiva/pivot-calendar/views/pivot-grid-view.tsx +251 -0
  104. package/src/components/kiva/pivot-filter/index.tsx +9 -0
  105. package/src/components/kiva/pivot-filter/pivot-filter-item.tsx +159 -0
  106. package/src/components/kiva/pivot-filter/pivot-filter-settings.tsx +161 -0
  107. package/src/components/kiva/pivot-filter/pivot-filter.tsx +187 -0
  108. package/src/components/kiva/pivot-filter/types.ts +82 -0
  109. package/src/components/kiva/pivot-grid/hooks/use-pivot-grid.ts +683 -0
  110. package/src/components/kiva/pivot-grid/index.tsx +23 -0
  111. package/src/components/kiva/pivot-grid/lib/pivot-grid-color-rules.ts +98 -0
  112. package/src/components/kiva/pivot-grid/lib/pivot-grid-export.ts +265 -0
  113. package/src/components/kiva/pivot-grid/lib/pivot-grid-model.ts +1110 -0
  114. package/src/components/kiva/pivot-grid/pivot-grid-demo-data.ts +200 -0
  115. package/src/components/kiva/pivot-grid/pivot-grid-export-menu.tsx +66 -0
  116. package/src/components/kiva/pivot-grid/pivot-grid-toolbar.tsx +85 -0
  117. package/src/components/kiva/pivot-grid/pivot-grid.tsx +601 -0
  118. package/src/components/kiva/pivot-grid/types.ts +195 -0
  119. package/src/components/kiva/place-autocomplete.tsx +484 -0
  120. package/src/components/kiva/record-delete-confirm-dialog/index.tsx +10 -0
  121. package/src/components/kiva/record-delete-confirm-dialog/record-delete-confirm-dialog.tsx +266 -0
  122. package/src/components/kiva/record-delete-confirm-dialog/types.ts +25 -0
  123. package/src/hooks/kiva/_internal/autonumber-setting.ts +112 -0
  124. package/src/hooks/kiva/_internal/form-layout-to-view.ts +665 -0
  125. package/src/hooks/kiva/_internal/kiva-hook-utils.ts +143 -0
  126. package/src/hooks/kiva/_internal/use-computed-field-evaluator.tsx +310 -0
  127. package/src/hooks/kiva/_internal/use-field-actions-evaluator.tsx +398 -0
  128. package/src/hooks/kiva/_internal/use-form-actions-evaluator.tsx +363 -0
  129. package/src/hooks/kiva/_internal/use-form-view-engine.tsx +2200 -0
  130. package/src/hooks/kiva/_internal/use-kiva-form-view-fields.tsx +190 -0
  131. package/src/hooks/kiva/_internal/use-kiva-kanban-cards.tsx +311 -0
  132. package/src/hooks/kiva/use-data-export.tsx +265 -0
  133. package/src/hooks/kiva/use-kiva-calendar.tsx +992 -0
  134. package/src/hooks/kiva/use-kiva-data-export.tsx +173 -0
  135. package/src/hooks/kiva/use-kiva-data-grid.tsx +4750 -0
  136. package/src/hooks/kiva/use-kiva-data-view-select.tsx +1273 -0
  137. package/src/hooks/kiva/use-kiva-form-view.tsx +1581 -0
  138. package/src/hooks/kiva/use-kiva-inventory.tsx +184 -0
  139. package/src/hooks/kiva/use-kiva-kanban.tsx +1750 -0
  140. package/src/hooks/kiva/use-kiva-map-view.tsx +2255 -0
  141. package/src/hooks/kiva/use-kiva-pivot-calendar.tsx +759 -0
  142. package/src/hooks/kiva/use-kiva-pivot-filter.tsx +1523 -0
  143. package/src/hooks/kiva/use-kiva-pivot-grid.tsx +543 -0
  144. package/src/hooks/kiva/use-kiva-tenant.tsx +313 -0
  145. package/src/hooks/kiva/use-parameter-persistence.ts +191 -0
@@ -0,0 +1,26 @@
1
+ // @ts-nocheck
2
+ /* eslint-disable */
3
+ export {
4
+ EnumOptionEditor,
5
+ EnumOptionEditorDialog
6
+ } from './enum-option-editor';
7
+
8
+ export {
9
+ KivaEnumOptionEditor,
10
+ useKivaEnumEditorPermission,
11
+ ADMIN_ROLE_ID,
12
+ ARCHITECT_ROLE_ID
13
+ } from './kiva-enum-option-editor';
14
+
15
+ export type {
16
+ EnumEditorOption,
17
+ EnumOptionOrigin,
18
+ EnumOptionInput,
19
+ EnumOptionEditorProps,
20
+ EnumOptionEditorDialogProps
21
+ } from './types';
22
+
23
+ export type {
24
+ KivaEnumOptionEditorProps,
25
+ UseKivaEnumEditorPermissionOptions
26
+ } from './kiva-enum-option-editor';
@@ -0,0 +1,320 @@
1
+ 'use client';
2
+
3
+ // @ts-nocheck
4
+ /* eslint-disable */
5
+ import {
6
+ useCallback,
7
+ useMemo,
8
+ useState,
9
+ type ReactNode
10
+ } from 'react';
11
+
12
+ import { type RestApiClient } from '@kivacore/api-client';
13
+ import { useQuery, useQueryClient } from '@tanstack/react-query';
14
+
15
+ import { useUiTranslation } from '@kivacore/ui-pro-shared/hooks/kiva/use-ui-translation';
16
+ import { getSharedKivaInventory } from '@kivacore/ui-pro-shared/hooks/kiva/use-kiva-inventory';
17
+
18
+ import { EnumOptionEditorDialog } from './enum-option-editor';
19
+ import {
20
+ type EnumEditorOption,
21
+ type EnumOptionInput
22
+ } from './types';
23
+
24
+ /**
25
+ * ADMIN / ARCHITECT role UUIDs — mirror `libs/shared/src/auth/constants.ts` in
26
+ * kiva-core. The enum admin API (`/v1/dev/.../enums`) is gated by the
27
+ * `Architect.ReadWrite.All` scope AND one of these roles (see `api.guard.ts`),
28
+ * so the manage action is shown only to users who actually hold one — otherwise
29
+ * the write would 403. Override via the `adminRoleIds` option when a tenant uses
30
+ * custom role ids.
31
+ */
32
+ export const ADMIN_ROLE_ID = 'e37ea658-8cfa-11ed-a098-7703de2a84b1';
33
+ export const ARCHITECT_ROLE_ID = '61672102-b5c8-11ee-b08a-23d1fbdaaa6a';
34
+
35
+ const DEFAULT_ME_ENDPOINT = '/v1/users/me';
36
+
37
+ function unwrap<T>(res: unknown): T {
38
+ const r = res as { data?: unknown } | undefined;
39
+
40
+ return (r && typeof r === 'object' && 'data' in r ? r.data : res) as T;
41
+ }
42
+
43
+ interface MeRole { uid?: string }
44
+ interface MePayload {
45
+ primary_role?: string;
46
+ primaryRole?: MeRole;
47
+ roles?: Array<MeRole>;
48
+ }
49
+
50
+ export interface UseKivaEnumEditorPermissionOptions {
51
+ /** Gate the `/v1/users/me` fetch (default `true`). */
52
+ enabled?: boolean;
53
+ /** Role ids that may manage options (default ADMIN + ARCHITECT). */
54
+ adminRoleIds?: Array<string>;
55
+ /** Override the profile endpoint (default `/v1/users/me`). */
56
+ meEndpoint?: string;
57
+ }
58
+
59
+ /**
60
+ * Reads the current user's roles from `/v1/users/me` and reports whether they
61
+ * may manage enum options (hold ADMIN or ARCHITECT). Cached under a shared
62
+ * `['kiva-me']` key (5-min stale) so every form reuses one fetch.
63
+ */
64
+ export function useKivaEnumEditorPermission(
65
+ client: RestApiClient | undefined,
66
+ { enabled = true, adminRoleIds, meEndpoint = DEFAULT_ME_ENDPOINT }: UseKivaEnumEditorPermissionOptions = {}
67
+ ): { canManage: boolean; isLoading: boolean } {
68
+ const allowedKey = (adminRoleIds ?? [ADMIN_ROLE_ID, ARCHITECT_ROLE_ID]).join(',');
69
+
70
+ const query = useQuery({
71
+ queryKey: ['kiva-me', meEndpoint] as const,
72
+ enabled: enabled && !!client,
73
+ staleTime: 5 * 60 * 1000,
74
+ queryFn: async () => {
75
+ if (!client) throw new Error('client is required');
76
+
77
+ return unwrap<MePayload>(await client.get(meEndpoint));
78
+ }
79
+ });
80
+
81
+ const canManage = useMemo(() => {
82
+ const me = query.data;
83
+
84
+ if (!me) return false;
85
+ const allowed = allowedKey.split(',');
86
+ const ids = [me.primary_role, me.primaryRole?.uid, ...(me.roles ?? []).map(r => r.uid)].filter(Boolean) as Array<string>;
87
+
88
+ return ids.some(id => allowed.includes(id));
89
+ }, [query.data, allowedKey]);
90
+
91
+ return { canManage, isLoading: query.isLoading };
92
+ }
93
+
94
+ interface ApiEnum {
95
+ id: string;
96
+ name: string;
97
+ slug?: string;
98
+ color?: string | null;
99
+ icon?: string | null;
100
+ sortOrder?: number | null;
101
+ isFinalOption?: boolean;
102
+ ownership?: string;
103
+ isCustomized?: boolean;
104
+ }
105
+
106
+ function mapApiEnum(raw: ApiEnum, origin: 'custom' | 'inherited'): EnumEditorOption {
107
+ return {
108
+ id: raw.id,
109
+ name: raw.name,
110
+ slug: raw.slug,
111
+ color: raw.color ?? undefined,
112
+ icon: raw.icon ?? undefined,
113
+ sort_order: raw.sortOrder ?? undefined,
114
+ is_final_option: raw.isFinalOption ?? undefined,
115
+ active: true,
116
+ origin,
117
+ isCustomized: raw.isCustomized
118
+ };
119
+ }
120
+
121
+ function toApiInput(input: EnumOptionInput): Record<string, unknown> {
122
+ const out: Record<string, unknown> = { name: input.name };
123
+
124
+ if (input.slug !== undefined) out.slug = input.slug;
125
+ if (input.color !== undefined) out.color = input.color;
126
+ if (input.icon !== undefined) out.icon = input.icon;
127
+ if (input.description !== undefined) out.description = input.description;
128
+ if (input.sort_order !== undefined) out.sortOrder = input.sort_order;
129
+ if (input.active !== undefined) out.active = input.active;
130
+ if (input.is_final_option !== undefined) out.isFinalOption = input.is_final_option;
131
+ if (input.force_description !== undefined) out.forceDescription = input.force_description;
132
+ if (input.force_followup_date !== undefined) out.forceFollowupDate = input.force_followup_date;
133
+ if (input.parent !== undefined) out.parent = input.parent;
134
+
135
+ return out;
136
+ }
137
+
138
+ export interface KivaEnumOptionEditorProps {
139
+ /** Authenticated Kiva REST client. */
140
+ client: RestApiClient;
141
+ /** App id (UUID `tenant_app_id`) or slug — the `{appId}` path segment. */
142
+ appId: string;
143
+ /** Data-source id (UUID). */
144
+ dataSourceId: string;
145
+ /** Field id (UUID) whose options are managed. */
146
+ fieldId: string;
147
+ /** Field display name (dialog title). */
148
+ fieldName?: string;
149
+ /** Custom trigger. Pass `null` for fully-controlled. */
150
+ trigger?: ReactNode;
151
+ open?: boolean;
152
+ onOpenChange?: (open: boolean) => void;
153
+ /** Called after any successful write (used to refresh the owning form's schema). */
154
+ onChanged?: () => void;
155
+ disabled?: boolean;
156
+ title?: string;
157
+ }
158
+
159
+ interface FieldEnumsResult {
160
+ readOnly: boolean;
161
+ enumSetId: string | null;
162
+ options: Array<EnumEditorOption>;
163
+ }
164
+
165
+ export function KivaEnumOptionEditor({
166
+ client,
167
+ appId,
168
+ dataSourceId,
169
+ fieldId,
170
+ fieldName,
171
+ trigger,
172
+ open: controlledOpen,
173
+ onOpenChange,
174
+ onChanged,
175
+ disabled,
176
+ title
177
+ }: KivaEnumOptionEditorProps) {
178
+ const { t } = useUiTranslation();
179
+ const queryClient = useQueryClient();
180
+
181
+ /*
182
+ * Own the open state (tri-state) so the enum fetch is gated on the dialog
183
+ * actually being open — even when the caller renders us uncontrolled (the
184
+ * form-view footer injection does).
185
+ */
186
+ const [internalOpen, setInternalOpen] = useState(false);
187
+ const isControlled = controlledOpen !== undefined;
188
+ const open = isControlled ? controlledOpen : internalOpen;
189
+
190
+ const handleOpenChange = useCallback(
191
+ (next: boolean) => {
192
+ if (!isControlled) setInternalOpen(next);
193
+ onOpenChange?.(next);
194
+ },
195
+ [isControlled, onOpenChange]
196
+ );
197
+
198
+ const base = `/v1/dev/apps/${appId}/data-sources/${dataSourceId}/fields/${fieldId}/enums`;
199
+ const queryKey = useMemo(
200
+ () => ['kiva-enum-options', dataSourceId, fieldId] as const,
201
+ [dataSourceId, fieldId]
202
+ );
203
+
204
+ const enumsQuery = useQuery<FieldEnumsResult>({
205
+ queryKey,
206
+ enabled: open,
207
+ staleTime: 30 * 1000,
208
+ queryFn: async () => {
209
+ const fieldData = unwrap<{ enumSetId: string | null; enums: Array<ApiEnum> }>(await client.get(base));
210
+
211
+ if (fieldData.enumSetId) {
212
+ return {
213
+ readOnly: true,
214
+ enumSetId: fieldData.enumSetId,
215
+ options: (fieldData.enums ?? []).map(e => mapApiEnum(e, 'inherited'))
216
+ };
217
+ }
218
+
219
+ /*
220
+ * 2. Per-field options — the workspace lookup adds ownership / isCustomized
221
+ * so we can show Delete (custom) vs Revert (inherited).
222
+ */
223
+ let rich: Array<ApiEnum> = [];
224
+
225
+ try {
226
+ rich = unwrap<Array<ApiEnum>>(await client.get('/v1/dev/data-sources/enums', { fieldId, limit: 200 }));
227
+ } catch {
228
+ rich = [];
229
+ }
230
+
231
+ const byId = new Map(rich.map(r => [r.id, r]));
232
+ const options = (fieldData.enums ?? []).map((e) => {
233
+ const meta = byId.get(e.id);
234
+ const origin = meta?.ownership && meta.ownership !== 'CUSTOM' ? 'inherited' : 'custom';
235
+
236
+ return mapApiEnum({ ...e, ...meta }, origin);
237
+ });
238
+
239
+ return { readOnly: false, enumSetId: null, options };
240
+ }
241
+ });
242
+
243
+ const refresh = useCallback(async () => {
244
+ await queryClient.invalidateQueries({ queryKey });
245
+ getSharedKivaInventory(client)?.invalidateDataSources();
246
+ onChanged?.();
247
+ }, [
248
+ queryClient,
249
+ queryKey,
250
+ client,
251
+ onChanged
252
+ ]);
253
+
254
+ const onCreateOption = useCallback(
255
+ async (input: EnumOptionInput): Promise<EnumEditorOption> => {
256
+ const res = unwrap<{ enums: Array<{ enumId: string; name: string }> }>(
257
+ await client.post(base, { enums: [toApiInput(input)] })
258
+ );
259
+ const created = res.enums?.[0];
260
+
261
+ await refresh();
262
+
263
+ return { id: created?.enumId ?? `tmp_${input.name}`, origin: 'custom', ...input };
264
+ },
265
+ [client, base, refresh]
266
+ );
267
+
268
+ const onUpdateOption = useCallback(
269
+ async (id: string, patch: Partial<EnumOptionInput>) => {
270
+ await client.patch(base, { enums: [{ enumId: id, ...toApiInput(patch as EnumOptionInput) }] });
271
+ await refresh();
272
+ },
273
+ [client, base, refresh]
274
+ );
275
+
276
+ const onDeleteOption = useCallback(
277
+ async (id: string) => {
278
+ await client.delete(base, { enumIds: [id] });
279
+ await refresh();
280
+ },
281
+ [client, base, refresh]
282
+ );
283
+
284
+ const onRevertOption = useCallback(
285
+ async (id: string) => {
286
+ await client.delete(`${base}/${id}/customization`);
287
+ await refresh();
288
+ },
289
+ [client, base, refresh]
290
+ );
291
+
292
+ const onReorder = useCallback(
293
+ async (orderedIds: Array<string>) => {
294
+ await client.patch(base, {
295
+ enums: orderedIds.map((enumId, i) => ({ enumId, sortOrder: (i + 1) * 10 }))
296
+ });
297
+ await refresh();
298
+ },
299
+ [client, base, refresh]
300
+ );
301
+
302
+ const readOnly = enumsQuery.data?.readOnly ?? false;
303
+
304
+ return (
305
+ <EnumOptionEditorDialog
306
+ options={enumsQuery.data?.options ?? []}
307
+ readOnly={readOnly}
308
+ noticeText={readOnly ? t('ui.enumEditor.sharedSetNotice', 'These options are shared through an enum set — edit them in Enum Set settings.') : undefined}
309
+ onCreateOption={onCreateOption}
310
+ onUpdateOption={onUpdateOption}
311
+ onDeleteOption={onDeleteOption}
312
+ onRevertOption={onRevertOption}
313
+ onReorder={onReorder}
314
+ trigger={trigger}
315
+ open={open}
316
+ onOpenChange={handleOpenChange}
317
+ disabled={disabled}
318
+ title={title ?? fieldName} />
319
+ );
320
+ }
@@ -0,0 +1,90 @@
1
+ // @ts-nocheck
2
+ /* eslint-disable */
3
+ import { type ReactNode } from 'react';
4
+
5
+ import { type EnumOption } from '@kivacore/ui-pro-shared/components/kiva/form-fields/types';
6
+
7
+ /**
8
+ * Ownership origin of an option, mirroring the Kiva enum ownership tiers.
9
+ * - `custom` → created by this workspace; fully editable + deletable.
10
+ * - `inherited` → shipped by the platform / an app (SYSTEM / APP / PRODUCT / USER);
11
+ * the original is read-only, edits are stored as a workspace override and the
12
+ * row shows **Revert** instead of **Delete**.
13
+ */
14
+ export type EnumOptionOrigin = 'custom' | 'inherited';
15
+
16
+ /** An option as rendered/edited by {@link EnumOptionEditor}. */
17
+ export interface EnumEditorOption extends EnumOption {
18
+ origin?: EnumOptionOrigin;
19
+ /** True when an `inherited` option currently carries a workspace override. */
20
+ isCustomized?: boolean;
21
+ }
22
+
23
+ /**
24
+ * Editable attributes of an option. Field names are the frontend snake_case
25
+ * shape (`sort_order`, `is_final_option`, …); the Kiva wrapper maps these to
26
+ * the enum admin API's camelCase (`sortOrder`, `isFinalOption`, …).
27
+ */
28
+ export interface EnumOptionInput {
29
+ name: string;
30
+ slug?: string;
31
+ color?: string;
32
+ icon?: string;
33
+ description?: string;
34
+ sort_order?: number;
35
+ active?: boolean;
36
+ is_final_option?: boolean;
37
+ force_description?: boolean;
38
+ force_followup_date?: boolean;
39
+ parent?: string;
40
+ }
41
+
42
+ /**
43
+ * Props for the pure, backend-agnostic {@link EnumOptionEditor}.
44
+ *
45
+ * The editor keeps an internal working copy seeded from `options` and applies
46
+ * every change **optimistically** (live model — no draft / Save button). Each
47
+ * mutation fires the matching callback; if the callback rejects, the row is
48
+ * rolled back. Omit the callbacks to get a purely local editor (demos / tests).
49
+ */
50
+ export interface EnumOptionEditorProps {
51
+ /** Initial options (rendered by `sort_order` then name). */
52
+ options: EnumEditorOption[];
53
+ /** Persist a new option. Must resolve to the created option (with its real id). */
54
+ onCreateOption?: (input: EnumOptionInput) => Promise<EnumEditorOption> | EnumEditorOption;
55
+ /** Persist an edit to an existing option (commit on blur / Enter — not per keystroke). */
56
+ onUpdateOption?: (id: string, patch: Partial<EnumOptionInput>) => Promise<void> | void;
57
+ /** Permanently delete a `custom` option. */
58
+ onDeleteOption?: (id: string) => Promise<void> | void;
59
+ /** Drop the workspace override of an `inherited` option (reset to shipped defaults). */
60
+ onRevertOption?: (id: string) => Promise<void> | void;
61
+ /** Persist a new order after a drag-drop (receives the full ordered id list). */
62
+ onReorder?: (orderedIds: string[]) => Promise<void> | void;
63
+ /** Render everything read-only (e.g. options managed via a shared set). */
64
+ readOnly?: boolean;
65
+ /** Toggle the add-option row (default `true`). */
66
+ allowCreate?: boolean;
67
+ /** Toggle per-row delete/revert (default `true`). */
68
+ allowDelete?: boolean;
69
+ /** Toggle drag-drop reordering (default `true`). */
70
+ allowReorder?: boolean;
71
+ /** Optional banner text above the list (e.g. the shared-set warning). */
72
+ noticeText?: string;
73
+ /** Empty-state copy. */
74
+ emptyText?: string;
75
+ className?: string;
76
+ }
77
+
78
+ /** Props for the {@link EnumOptionEditorDialog} launcher. */
79
+ export interface EnumOptionEditorDialogProps extends EnumOptionEditorProps {
80
+ /** Custom trigger. Defaults to a "Manage options" button. Pass `null` for fully-controlled. */
81
+ trigger?: ReactNode;
82
+ /** Controlled open state. */
83
+ open?: boolean;
84
+ onOpenChange?: (open: boolean) => void;
85
+ /** Dialog title / description copy. */
86
+ title?: string;
87
+ description?: string;
88
+ /** Disable the default trigger button. */
89
+ disabled?: boolean;
90
+ }