@kelpie/ui 0.26.0 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/dist/api/resources/account.d.ts +7 -1
  2. package/dist/api/resources/account.d.ts.map +1 -1
  3. package/dist/api/resources/account.js +17 -1
  4. package/dist/api/resources/account.js.map +1 -1
  5. package/dist/api/resources/bulkActions.d.ts +50 -0
  6. package/dist/api/resources/bulkActions.d.ts.map +1 -0
  7. package/dist/api/resources/bulkActions.js +192 -0
  8. package/dist/api/resources/bulkActions.js.map +1 -0
  9. package/dist/api/resources/forms.d.ts +26 -1
  10. package/dist/api/resources/forms.d.ts.map +1 -1
  11. package/dist/api/resources/forms.js +98 -1
  12. package/dist/api/resources/forms.js.map +1 -1
  13. package/dist/app/KelpieApp.d.ts.map +1 -1
  14. package/dist/app/KelpieApp.js +3 -1
  15. package/dist/app/KelpieApp.js.map +1 -1
  16. package/dist/components/ActivitiesPanel.d.ts.map +1 -1
  17. package/dist/components/ActivitiesPanel.js +3 -12
  18. package/dist/components/ActivitiesPanel.js.map +1 -1
  19. package/dist/components/BulkActions.d.ts +61 -0
  20. package/dist/components/BulkActions.d.ts.map +1 -0
  21. package/dist/components/BulkActions.js +351 -0
  22. package/dist/components/BulkActions.js.map +1 -0
  23. package/dist/components/BulkParamFields.d.ts +13 -0
  24. package/dist/components/BulkParamFields.d.ts.map +1 -0
  25. package/dist/components/BulkParamFields.js +177 -0
  26. package/dist/components/BulkParamFields.js.map +1 -0
  27. package/dist/components/CellLinks.d.ts +38 -0
  28. package/dist/components/CellLinks.d.ts.map +1 -0
  29. package/dist/components/CellLinks.js +58 -0
  30. package/dist/components/CellLinks.js.map +1 -0
  31. package/dist/components/CustomFieldsPanel.d.ts +12 -1
  32. package/dist/components/CustomFieldsPanel.d.ts.map +1 -1
  33. package/dist/components/CustomFieldsPanel.js +5 -1
  34. package/dist/components/CustomFieldsPanel.js.map +1 -1
  35. package/dist/components/DataTable.d.ts +42 -1
  36. package/dist/components/DataTable.d.ts.map +1 -1
  37. package/dist/components/DataTable.js +51 -16
  38. package/dist/components/DataTable.js.map +1 -1
  39. package/dist/components/NotesPanel.d.ts.map +1 -1
  40. package/dist/components/NotesPanel.js +2 -15
  41. package/dist/components/NotesPanel.js.map +1 -1
  42. package/dist/components/PhonesField.d.ts.map +1 -1
  43. package/dist/components/PhonesField.js +1 -3
  44. package/dist/components/PhonesField.js.map +1 -1
  45. package/dist/components/Shell.d.ts.map +1 -1
  46. package/dist/components/Shell.js +16 -6
  47. package/dist/components/Shell.js.map +1 -1
  48. package/dist/components/TagInput.d.ts.map +1 -1
  49. package/dist/components/TagInput.js +5 -0
  50. package/dist/components/TagInput.js.map +1 -1
  51. package/dist/components/bulkActionParams.d.ts +71 -0
  52. package/dist/components/bulkActionParams.d.ts.map +1 -0
  53. package/dist/components/bulkActionParams.js +241 -0
  54. package/dist/components/bulkActionParams.js.map +1 -0
  55. package/dist/components/bulkActionSummary.d.ts +22 -0
  56. package/dist/components/bulkActionSummary.d.ts.map +1 -0
  57. package/dist/components/bulkActionSummary.js +68 -0
  58. package/dist/components/bulkActionSummary.js.map +1 -0
  59. package/dist/components/bulkJobStatus.d.ts +4 -0
  60. package/dist/components/bulkJobStatus.d.ts.map +1 -0
  61. package/dist/components/bulkJobStatus.js +10 -0
  62. package/dist/components/bulkJobStatus.js.map +1 -0
  63. package/dist/index.d.ts +2 -2
  64. package/dist/index.d.ts.map +1 -1
  65. package/dist/index.js +1 -1
  66. package/dist/index.js.map +1 -1
  67. package/dist/lib/attribution.d.ts +31 -0
  68. package/dist/lib/attribution.d.ts.map +1 -0
  69. package/dist/lib/attribution.js +48 -0
  70. package/dist/lib/attribution.js.map +1 -0
  71. package/dist/lib/bulkSelection.d.ts +43 -0
  72. package/dist/lib/bulkSelection.d.ts.map +1 -0
  73. package/dist/lib/bulkSelection.js +70 -0
  74. package/dist/lib/bulkSelection.js.map +1 -0
  75. package/dist/lib/contactLinks.d.ts +15 -0
  76. package/dist/lib/contactLinks.d.ts.map +1 -0
  77. package/dist/lib/contactLinks.js +22 -0
  78. package/dist/lib/contactLinks.js.map +1 -0
  79. package/dist/pages/BulkJobsPage.d.ts +3 -0
  80. package/dist/pages/BulkJobsPage.d.ts.map +1 -0
  81. package/dist/pages/BulkJobsPage.js +92 -0
  82. package/dist/pages/BulkJobsPage.js.map +1 -0
  83. package/dist/pages/CompaniesPage.d.ts.map +1 -1
  84. package/dist/pages/CompaniesPage.js +9 -5
  85. package/dist/pages/CompaniesPage.js.map +1 -1
  86. package/dist/pages/CompanyDetail.d.ts.map +1 -1
  87. package/dist/pages/CompanyDetail.js +4 -3
  88. package/dist/pages/CompanyDetail.js.map +1 -1
  89. package/dist/pages/DealsPage.d.ts.map +1 -1
  90. package/dist/pages/DealsPage.js +15 -4
  91. package/dist/pages/DealsPage.js.map +1 -1
  92. package/dist/pages/DecisionsPage.d.ts.map +1 -1
  93. package/dist/pages/DecisionsPage.js +11 -1
  94. package/dist/pages/DecisionsPage.js.map +1 -1
  95. package/dist/pages/EnquiriesPage.d.ts.map +1 -1
  96. package/dist/pages/EnquiriesPage.js +15 -6
  97. package/dist/pages/EnquiriesPage.js.map +1 -1
  98. package/dist/pages/EventDetail.d.ts.map +1 -1
  99. package/dist/pages/EventDetail.js +14 -6
  100. package/dist/pages/EventDetail.js.map +1 -1
  101. package/dist/pages/EventsPage.d.ts.map +1 -1
  102. package/dist/pages/EventsPage.js +22 -5
  103. package/dist/pages/EventsPage.js.map +1 -1
  104. package/dist/pages/FormsPage.d.ts.map +1 -1
  105. package/dist/pages/FormsPage.js +2 -2
  106. package/dist/pages/FormsPage.js.map +1 -1
  107. package/dist/pages/FundraisingPage.d.ts.map +1 -1
  108. package/dist/pages/FundraisingPage.js +15 -4
  109. package/dist/pages/FundraisingPage.js.map +1 -1
  110. package/dist/pages/HiringPage.d.ts.map +1 -1
  111. package/dist/pages/HiringPage.js +2 -1
  112. package/dist/pages/HiringPage.js.map +1 -1
  113. package/dist/pages/ListDetail.d.ts.map +1 -1
  114. package/dist/pages/ListDetail.js +39 -7
  115. package/dist/pages/ListDetail.js.map +1 -1
  116. package/dist/pages/ListsPage.d.ts.map +1 -1
  117. package/dist/pages/ListsPage.js +2 -1
  118. package/dist/pages/ListsPage.js.map +1 -1
  119. package/dist/pages/OpportunitiesPage.d.ts.map +1 -1
  120. package/dist/pages/OpportunitiesPage.js +15 -6
  121. package/dist/pages/OpportunitiesPage.js.map +1 -1
  122. package/dist/pages/PartnershipsPage.d.ts.map +1 -1
  123. package/dist/pages/PartnershipsPage.js +15 -4
  124. package/dist/pages/PartnershipsPage.js.map +1 -1
  125. package/dist/pages/PeoplePage.d.ts.map +1 -1
  126. package/dist/pages/PeoplePage.js +10 -9
  127. package/dist/pages/PeoplePage.js.map +1 -1
  128. package/dist/pages/PlanningPage.d.ts.map +1 -1
  129. package/dist/pages/PlanningPage.js +15 -4
  130. package/dist/pages/PlanningPage.js.map +1 -1
  131. package/dist/pages/RoleDetail.d.ts.map +1 -1
  132. package/dist/pages/RoleDetail.js +12 -4
  133. package/dist/pages/RoleDetail.js.map +1 -1
  134. package/dist/pages/dashboard/sections.d.ts.map +1 -1
  135. package/dist/pages/dashboard/sections.js +8 -10
  136. package/dist/pages/dashboard/sections.js.map +1 -1
  137. package/dist/pages/forms/BlockedSendersPage.d.ts +10 -0
  138. package/dist/pages/forms/BlockedSendersPage.d.ts.map +1 -0
  139. package/dist/pages/forms/BlockedSendersPage.js +65 -0
  140. package/dist/pages/forms/BlockedSendersPage.js.map +1 -0
  141. package/dist/pages/forms/MarkSpamPanel.d.ts +19 -0
  142. package/dist/pages/forms/MarkSpamPanel.d.ts.map +1 -0
  143. package/dist/pages/forms/MarkSpamPanel.js +62 -0
  144. package/dist/pages/forms/MarkSpamPanel.js.map +1 -0
  145. package/dist/pages/forms/SubmissionDetail.d.ts.map +1 -1
  146. package/dist/pages/forms/SubmissionDetail.js +41 -11
  147. package/dist/pages/forms/SubmissionDetail.js.map +1 -1
  148. package/dist/pages/forms/SubmissionsTable.d.ts +1 -1
  149. package/dist/pages/forms/SubmissionsTable.d.ts.map +1 -1
  150. package/dist/pages/forms/SubmissionsTable.js +6 -4
  151. package/dist/pages/forms/SubmissionsTable.js.map +1 -1
  152. package/dist/pages/forms/markSpamChoices.d.ts +51 -0
  153. package/dist/pages/forms/markSpamChoices.d.ts.map +1 -0
  154. package/dist/pages/forms/markSpamChoices.js +96 -0
  155. package/dist/pages/forms/markSpamChoices.js.map +1 -0
  156. package/dist/pages/positionDirectory.d.ts +5 -0
  157. package/dist/pages/positionDirectory.d.ts.map +1 -1
  158. package/dist/pages/positionDirectory.js +11 -3
  159. package/dist/pages/positionDirectory.js.map +1 -1
  160. package/dist/registry/context.d.ts +3 -1
  161. package/dist/registry/context.d.ts.map +1 -1
  162. package/dist/registry/context.js +4 -0
  163. package/dist/registry/context.js.map +1 -1
  164. package/dist/registry/contributions.d.ts +23 -0
  165. package/dist/registry/contributions.d.ts.map +1 -1
  166. package/dist/registry/contributions.js.map +1 -1
  167. package/dist/registry/registry.d.ts +4 -1
  168. package/dist/registry/registry.d.ts.map +1 -1
  169. package/dist/registry/registry.js +6 -0
  170. package/dist/registry/registry.js.map +1 -1
  171. package/dist/registry/visibleNav.d.ts.map +1 -1
  172. package/dist/registry/visibleNav.js +1 -0
  173. package/dist/registry/visibleNav.js.map +1 -1
  174. package/package.json +3 -3
  175. package/src/api/resources/account.ts +20 -0
  176. package/src/api/resources/bulkActions.ts +267 -0
  177. package/src/api/resources/forms.ts +135 -0
  178. package/src/app/KelpieApp.tsx +5 -0
  179. package/src/components/ActivitiesPanel.tsx +3 -14
  180. package/src/components/BulkActions.tsx +961 -0
  181. package/src/components/BulkParamFields.tsx +524 -0
  182. package/src/components/CellLinks.tsx +138 -0
  183. package/src/components/CustomFieldsPanel.tsx +6 -2
  184. package/src/components/DataTable.tsx +142 -2
  185. package/src/components/NotesPanel.tsx +2 -17
  186. package/src/components/PhonesField.tsx +2 -4
  187. package/src/components/Shell.tsx +23 -6
  188. package/src/components/TagInput.tsx +5 -0
  189. package/src/components/bulkActionParams.ts +405 -0
  190. package/src/components/bulkActionSummary.ts +104 -0
  191. package/src/components/bulkJobStatus.ts +11 -0
  192. package/src/index.ts +3 -0
  193. package/src/lib/attribution.ts +59 -0
  194. package/src/lib/bulkSelection.ts +128 -0
  195. package/src/lib/contactLinks.ts +25 -0
  196. package/src/pages/BulkJobsPage.tsx +206 -0
  197. package/src/pages/CompaniesPage.tsx +21 -6
  198. package/src/pages/CompanyDetail.tsx +4 -3
  199. package/src/pages/DealsPage.tsx +30 -2
  200. package/src/pages/DecisionsPage.tsx +21 -1
  201. package/src/pages/EnquiriesPage.tsx +33 -5
  202. package/src/pages/EventDetail.tsx +43 -16
  203. package/src/pages/EventsPage.tsx +35 -4
  204. package/src/pages/FormsPage.tsx +7 -1
  205. package/src/pages/FundraisingPage.tsx +30 -2
  206. package/src/pages/HiringPage.tsx +6 -1
  207. package/src/pages/ListDetail.tsx +69 -5
  208. package/src/pages/ListsPage.tsx +6 -1
  209. package/src/pages/OpportunitiesPage.tsx +33 -5
  210. package/src/pages/PartnershipsPage.tsx +30 -2
  211. package/src/pages/PeoplePage.tsx +26 -21
  212. package/src/pages/PlanningPage.tsx +65 -24
  213. package/src/pages/RoleDetail.tsx +35 -7
  214. package/src/pages/dashboard/sections.tsx +13 -14
  215. package/src/pages/forms/BlockedSendersPage.tsx +155 -0
  216. package/src/pages/forms/MarkSpamPanel.tsx +193 -0
  217. package/src/pages/forms/SubmissionDetail.tsx +73 -18
  218. package/src/pages/forms/SubmissionsTable.tsx +7 -5
  219. package/src/pages/forms/markSpamChoices.ts +141 -0
  220. package/src/pages/positionDirectory.ts +16 -4
  221. package/src/registry/context.ts +6 -0
  222. package/src/registry/contributions.ts +25 -0
  223. package/src/registry/registry.ts +12 -0
  224. package/src/registry/visibleNav.ts +1 -0
@@ -0,0 +1,405 @@
1
+ import {
2
+ CUSTOM_FIELD_OBJECT_TYPES,
3
+ EVENT_STATUS_LABELS,
4
+ RECORD_TARGET_TYPES,
5
+ TAG_TARGET_TYPES,
6
+ customFieldValuesBody,
7
+ } from '@kelpie/schemas'
8
+ import type {
9
+ BulkActionCatalogEntry,
10
+ BulkActionTargetType,
11
+ CustomFieldObjectType,
12
+ CustomFieldValue,
13
+ PipelineKind,
14
+ RecordTargetType,
15
+ TagTargetType,
16
+ } from '@kelpie/schemas'
17
+
18
+ import { labelize } from '../pages/fields.ts'
19
+
20
+ /**
21
+ * How the form for a bulk action's params is drawn.
22
+ *
23
+ * The catalog gives each action's params as JSON Schema. Core's own params
24
+ * are drawn from a small table keyed by param name: a name such as
25
+ * `owner_id` or `stage_id` already says which of the app's pickers it needs,
26
+ * and a picker is what a person expects, not a raw text box for an id. The
27
+ * schema still decides what the table cannot know: the values of an enum,
28
+ * and whether a field may be cleared.
29
+ *
30
+ * A param the table does not know, such as one a module's action adds, is
31
+ * drawn from its schema alone: a string, an enum, a boolean, a number, or a
32
+ * date by `format`. An action is left out of the menu only when one of its
33
+ * params is a shape none of these fit, such as an object, an array other
34
+ * than core's tags, or a known param whose schema has the wrong shape.
35
+ *
36
+ * `field_id` and `value` are a pair: a custom field, then a value that fits
37
+ * that field's type. `value` is only read as a custom field value when its
38
+ * schema allows the several shapes one can take; a module's plain `value`
39
+ * param is drawn from its schema like any other.
40
+ */
41
+
42
+ type ParamKind =
43
+ | 'tags'
44
+ | 'member'
45
+ | 'stage'
46
+ | 'list'
47
+ | 'date'
48
+ | 'text'
49
+ | 'enum'
50
+ | 'boolean'
51
+ | 'record'
52
+ | 'customField'
53
+ | 'customValue'
54
+
55
+ /** The records a param can name by id and pick through a search. */
56
+ export type PickedRecordType = 'event' | 'role' | 'company'
57
+
58
+ interface ParamSpec {
59
+ readonly kind: ParamKind
60
+ readonly label: string
61
+ readonly recordType?: PickedRecordType
62
+ }
63
+
64
+ const PARAM_SPECS: Readonly<Record<string, ParamSpec>> = {
65
+ tags: { kind: 'tags', label: 'Tags' },
66
+ owner_id: { kind: 'member', label: 'Owner' },
67
+ stage_id: { kind: 'stage', label: 'Stage' },
68
+ list_id: { kind: 'list', label: 'List' },
69
+ event_id: { kind: 'record', label: 'Event', recordType: 'event' },
70
+ role_id: { kind: 'record', label: 'Role', recordType: 'role' },
71
+ company_id: { kind: 'record', label: 'Company', recordType: 'company' },
72
+ field_id: { kind: 'customField', label: 'Field' },
73
+ value: { kind: 'customValue', label: 'Value' },
74
+ expected_close: { kind: 'date', label: 'Expected close' },
75
+ next_touchpoint: { kind: 'date', label: 'Next touchpoint' },
76
+ // A plan item's date: the server checks it with a pattern, not `format: date`.
77
+ date: { kind: 'date', label: 'Date' },
78
+ title: { kind: 'text', label: 'Title' },
79
+ relationship: { kind: 'enum', label: 'Relationship warmth' },
80
+ influence: { kind: 'enum', label: 'Influence' },
81
+ preferred_channel: { kind: 'enum', label: 'Preferred channel' },
82
+ stage: { kind: 'enum', label: 'Stage' },
83
+ account_type: { kind: 'enum', label: 'Account type' },
84
+ icp_fit: { kind: 'enum', label: 'ICP fit' },
85
+ status: { kind: 'enum', label: 'Status' },
86
+ do_not_contact: { kind: 'boolean', label: 'Do not contact' },
87
+ industry: { kind: 'text', label: 'Industry' },
88
+ kind: { kind: 'text', label: 'Kind' },
89
+ pass_reason: { kind: 'text', label: 'Pass reason' },
90
+ }
91
+
92
+ /** Enum labels the UI already shows elsewhere, by `type.param`. Others are labelized. */
93
+ const ENUM_LABELS: Readonly<Record<string, Readonly<Record<string, string>>>> = {
94
+ 'event.status': EVENT_STATUS_LABELS,
95
+ }
96
+
97
+ const PIPELINE_OF: Partial<Readonly<Record<BulkActionTargetType, PipelineKind>>> = {
98
+ deal: 'deal',
99
+ opportunity: 'opportunity',
100
+ partnership: 'partnership',
101
+ raise: 'raise',
102
+ enquiry: 'enquiry',
103
+ }
104
+
105
+ export interface EnumOption {
106
+ readonly value: string
107
+ readonly label: string
108
+ }
109
+
110
+ interface FieldBase {
111
+ readonly name: string
112
+ readonly label: string
113
+ /** Set when the schema does not require the param. Left empty, it is not sent. */
114
+ readonly optional?: true
115
+ }
116
+
117
+ export type ParamField =
118
+ | (FieldBase & { readonly kind: 'tags'; readonly tagType: TagTargetType })
119
+ | (FieldBase & { readonly kind: 'member'; readonly nullable: boolean })
120
+ | (FieldBase & { readonly kind: 'stage'; readonly pipeline: PipelineKind })
121
+ | (FieldBase & { readonly kind: 'list'; readonly listType: RecordTargetType })
122
+ | (FieldBase & { readonly kind: 'date'; readonly nullable: boolean })
123
+ | (FieldBase & { readonly kind: 'text'; readonly nullable: boolean })
124
+ | (FieldBase & { readonly kind: 'enum'; readonly options: readonly EnumOption[] })
125
+ | (FieldBase & { readonly kind: 'boolean' })
126
+ | (FieldBase & { readonly kind: 'number'; readonly integer: boolean; readonly nullable: boolean })
127
+ | (FieldBase & { readonly kind: 'record'; readonly recordType: PickedRecordType })
128
+ | (FieldBase & { readonly kind: 'customField'; readonly objectType: CustomFieldObjectType })
129
+ | (FieldBase & {
130
+ readonly kind: 'customValue'
131
+ readonly objectType: CustomFieldObjectType
132
+ /** The param that names the field this value is for. */
133
+ readonly fieldParam: string
134
+ })
135
+
136
+ /**
137
+ * What a field holds while the form is open. `''` and an empty list are
138
+ * "not chosen yet". `null` is "clear this field", offered only where the
139
+ * schema allows null. A custom field value can also be a number or a
140
+ * currency amount.
141
+ */
142
+ export type ParamValue = CustomFieldValue | null
143
+
144
+ export type ParamValues = Readonly<Record<string, ParamValue>>
145
+
146
+ type JsonSchema = Readonly<Record<string, unknown>>
147
+
148
+ function isSchema(value: unknown): value is JsonSchema {
149
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
150
+ }
151
+
152
+ /** The non-null shapes a property allows, and whether it allows null. */
153
+ function variantsOf(property: JsonSchema): { readonly core: readonly JsonSchema[]; readonly nullable: boolean } {
154
+ const all = Array.isArray(property.anyOf) ? property.anyOf.filter(isSchema) : [property]
155
+
156
+ return {
157
+ core: all.filter((variant) => variant.type !== 'null'),
158
+ nullable: all.some((variant) => variant.type === 'null'),
159
+ }
160
+ }
161
+
162
+ function isStringArray(value: unknown): value is readonly string[] {
163
+ return Array.isArray(value) && value.every((item) => typeof item === 'string')
164
+ }
165
+
166
+ function isTagType(targetType: BulkActionTargetType): targetType is TagTargetType {
167
+ return (TAG_TARGET_TYPES as readonly string[]).includes(targetType)
168
+ }
169
+
170
+ function isRecordType(targetType: BulkActionTargetType): targetType is RecordTargetType {
171
+ return (RECORD_TARGET_TYPES as readonly string[]).includes(targetType)
172
+ }
173
+
174
+ function isCustomFieldType(targetType: BulkActionTargetType): targetType is CustomFieldObjectType {
175
+ return (CUSTOM_FIELD_OBJECT_TYPES as readonly string[]).includes(targetType)
176
+ }
177
+
178
+ /** The param a `customValue` field reads its field from. */
179
+ const CUSTOM_FIELD_PARAM = 'field_id'
180
+
181
+ function fieldFor(
182
+ name: string,
183
+ property: JsonSchema,
184
+ targetType: BulkActionTargetType,
185
+ ): ParamField | undefined {
186
+ const spec = PARAM_SPECS[name]
187
+ const { core, nullable } = variantsOf(property)
188
+ const shape = core.length === 1 ? core[0] : undefined
189
+
190
+ // A custom field value is a union of every shape a field can hold. Zod
191
+ // writes `union.nullable()` as a union nested in one with null.
192
+ const isUnion = core.length > 1 || (shape !== undefined && Array.isArray(shape.anyOf))
193
+
194
+ if (spec?.kind === 'customValue' && isUnion) {
195
+ return nullable && isCustomFieldType(targetType)
196
+ ? { name, label: spec.label, kind: 'customValue', objectType: targetType, fieldParam: CUSTOM_FIELD_PARAM }
197
+ : undefined
198
+ }
199
+
200
+ if (shape === undefined) {
201
+ return undefined
202
+ }
203
+
204
+ if (spec === undefined || spec.kind === 'customValue') {
205
+ return genericField(name, shape, nullable)
206
+ }
207
+
208
+ const base = { name, label: spec.label }
209
+ const isString = shape.type === 'string'
210
+
211
+ switch (spec.kind) {
212
+ case 'tags': {
213
+ const items = isSchema(shape.items) ? shape.items : undefined
214
+
215
+ return shape.type === 'array' && items?.type === 'string' && !nullable && isTagType(targetType)
216
+ ? { ...base, kind: 'tags', tagType: targetType }
217
+ : undefined
218
+ }
219
+ case 'member':
220
+ return isString ? { ...base, kind: 'member', nullable } : undefined
221
+ case 'stage': {
222
+ const pipeline = PIPELINE_OF[targetType]
223
+
224
+ return isString && !nullable && pipeline !== undefined ? { ...base, kind: 'stage', pipeline } : undefined
225
+ }
226
+ case 'list':
227
+ return isString && !nullable && isRecordType(targetType)
228
+ ? { ...base, kind: 'list', listType: targetType }
229
+ : undefined
230
+ case 'date':
231
+ return isString ? { ...base, kind: 'date', nullable } : undefined
232
+ case 'text':
233
+ return isString && shape.enum === undefined ? { ...base, kind: 'text', nullable } : undefined
234
+ case 'enum': {
235
+ if (!isString || nullable || !isStringArray(shape.enum)) {
236
+ return undefined
237
+ }
238
+
239
+ const labels = ENUM_LABELS[`${targetType}.${name}`] ?? {}
240
+
241
+ return {
242
+ ...base,
243
+ kind: 'enum',
244
+ options: shape.enum.map((value) => ({ value, label: labels[value] ?? labelize(value) })),
245
+ }
246
+ }
247
+ case 'boolean':
248
+ return shape.type === 'boolean' && !nullable ? { ...base, kind: 'boolean' } : undefined
249
+ case 'record':
250
+ return isString && !nullable && spec.recordType !== undefined
251
+ ? { ...base, kind: 'record', recordType: spec.recordType }
252
+ : undefined
253
+ case 'customField':
254
+ return isString && !nullable && isCustomFieldType(targetType)
255
+ ? { ...base, kind: 'customField', objectType: targetType }
256
+ : undefined
257
+ }
258
+ }
259
+
260
+ /** `audience_id` reads as "Audience id". A schema `title` wins when the module gave one. */
261
+ function genericLabel(name: string, shape: JsonSchema): string {
262
+ if (typeof shape.title === 'string' && shape.title.length > 0) {
263
+ return shape.title
264
+ }
265
+
266
+ const words = labelize(name)
267
+
268
+ return words.charAt(0).toUpperCase() + words.slice(1)
269
+ }
270
+
271
+ /** A param core does not know, drawn from its JSON Schema alone. */
272
+ function genericField(name: string, shape: JsonSchema, nullable: boolean): ParamField | undefined {
273
+ const base = { name, label: genericLabel(name, shape) }
274
+
275
+ switch (shape.type) {
276
+ case 'string':
277
+ if (shape.enum !== undefined) {
278
+ return isStringArray(shape.enum) && !nullable
279
+ ? {
280
+ ...base,
281
+ kind: 'enum',
282
+ options: shape.enum.map((value) => ({ value, label: labelize(value) })),
283
+ }
284
+ : undefined
285
+ }
286
+
287
+ return shape.format === 'date'
288
+ ? { ...base, kind: 'date', nullable }
289
+ : { ...base, kind: 'text', nullable }
290
+ case 'boolean':
291
+ return nullable ? undefined : { ...base, kind: 'boolean' }
292
+ case 'number':
293
+ case 'integer':
294
+ return { ...base, kind: 'number', integer: shape.type === 'integer', nullable }
295
+ default:
296
+ return undefined
297
+ }
298
+ }
299
+
300
+ /**
301
+ * The form fields for an action's params, or undefined when the UI cannot
302
+ * draw one of them. An action with no params has no fields.
303
+ */
304
+ export function paramFieldsFor(
305
+ entry: BulkActionCatalogEntry,
306
+ targetType: BulkActionTargetType,
307
+ ): readonly ParamField[] | undefined {
308
+ const schema = entry.paramsSchema
309
+
310
+ if (schema.type !== 'object') {
311
+ return undefined
312
+ }
313
+
314
+ const properties = isSchema(schema.properties) ? schema.properties : {}
315
+ const required = isStringArray(schema.required) ? schema.required : []
316
+ const fields: ParamField[] = []
317
+
318
+ for (const [name, property] of Object.entries(properties)) {
319
+ const field = isSchema(property) ? fieldFor(name, property, targetType) : undefined
320
+
321
+ if (field === undefined) {
322
+ return undefined
323
+ }
324
+
325
+ fields.push(required.includes(name) ? field : { ...field, optional: true })
326
+ }
327
+
328
+ // A value for a custom field cannot be drawn without the field it is for.
329
+ const orphanValue = fields.some(
330
+ (field) =>
331
+ field.kind === 'customValue' &&
332
+ !fields.some((other) => other.kind === 'customField' && other.name === field.fieldParam),
333
+ )
334
+
335
+ return orphanValue ? undefined : fields
336
+ }
337
+
338
+ /** Every field starts unchosen, except a checkbox, which has no third state. */
339
+ export function initialParamValues(fields: readonly ParamField[]): ParamValues {
340
+ return Object.fromEntries(
341
+ fields.map((field): [string, ParamValue] => [
342
+ field.name,
343
+ field.kind === 'tags' ? [] : field.kind === 'boolean' ? false : '',
344
+ ]),
345
+ )
346
+ }
347
+
348
+ /** The params to send, or undefined while a required field is still empty. */
349
+ export function paramsFromValues(
350
+ fields: readonly ParamField[],
351
+ values: ParamValues,
352
+ ): Readonly<Record<string, unknown>> | undefined {
353
+ const params: Record<string, unknown> = {}
354
+
355
+ for (const field of fields) {
356
+ const value = values[field.name]
357
+
358
+ if (field.kind === 'customValue') {
359
+ // Null clears the field on every record. `''` is "not chosen yet".
360
+ if (value === undefined || value === '') return undefined
361
+ params[field.name] = customFieldValuesBody({ [field.name]: value })[field.name]
362
+ continue
363
+ }
364
+
365
+ if (value === null && 'nullable' in field && field.nullable) {
366
+ params[field.name] = null
367
+ continue
368
+ }
369
+
370
+ const empty =
371
+ value === undefined || (typeof value === 'string' && value.trim().length === 0) || (Array.isArray(value) && value.length === 0)
372
+
373
+ if (empty && field.optional === true) {
374
+ continue
375
+ }
376
+
377
+ if (field.kind === 'boolean') {
378
+ if (typeof value !== 'boolean') return undefined
379
+ params[field.name] = value
380
+ continue
381
+ }
382
+
383
+ if (field.kind === 'tags') {
384
+ if (!Array.isArray(value) || value.length === 0) return undefined
385
+ params[field.name] = value
386
+ continue
387
+ }
388
+
389
+ if (typeof value !== 'string' || value.trim().length === 0) {
390
+ return undefined
391
+ }
392
+
393
+ if (field.kind === 'number') {
394
+ const number = Number(value)
395
+
396
+ if (!Number.isFinite(number) || (field.integer && !Number.isInteger(number))) return undefined
397
+ params[field.name] = number
398
+ continue
399
+ }
400
+
401
+ params[field.name] = field.kind === 'text' ? value.trim() : value
402
+ }
403
+
404
+ return params
405
+ }
@@ -0,0 +1,104 @@
1
+ import type { ParamField } from './bulkActionParams.ts'
2
+
3
+ /**
4
+ * The sentence the confirm step shows: what will happen, to how many
5
+ * records, with the values chosen. "Add tags bulk-test to 68 people."
6
+ * "Move 1 deal to Negotiation."
7
+ *
8
+ * Core's actions get a sentence of their own. Any other action names its
9
+ * label, the count and each param, so a module's action reads plainly too.
10
+ * Values come from what the reader saw: a select's option text, never an id.
11
+ */
12
+
13
+ export interface RunSummaryInput {
14
+ readonly actionKey: string
15
+ readonly actionLabel: string
16
+ readonly fields: readonly ParamField[]
17
+ readonly params: Readonly<Record<string, unknown>>
18
+ /** The option text each select showed when it was picked, by param name. */
19
+ readonly choices: Readonly<Record<string, string>>
20
+ /** "68 people", "1 deal". */
21
+ readonly records: string
22
+ }
23
+
24
+ function displayOf(field: ParamField, raw: unknown, choices: Readonly<Record<string, string>>): string {
25
+ if (raw === null) {
26
+ return field.kind === 'member' ? 'no owner' : 'nothing (cleared)'
27
+ }
28
+
29
+ if (Array.isArray(raw)) {
30
+ return raw.map(String).join(', ')
31
+ }
32
+
33
+ if (typeof raw === 'boolean') {
34
+ return raw ? 'yes' : 'no'
35
+ }
36
+
37
+ return choices[field.name] ?? String(raw)
38
+ }
39
+
40
+ function valueOf(input: RunSummaryInput, name: string): string {
41
+ const field = input.fields.find((candidate) => candidate.name === name)
42
+
43
+ return field === undefined ? '' : displayOf(field, input.params[name], input.choices)
44
+ }
45
+
46
+ export function runSummary(input: RunSummaryInput): string {
47
+ const { actionKey, records } = input
48
+
49
+ switch (actionKey) {
50
+ case 'core.add_tags':
51
+ return `Add tags ${valueOf(input, 'tags')} to ${records}.`
52
+ case 'core.remove_tags':
53
+ return `Remove tags ${valueOf(input, 'tags')} from ${records}.`
54
+ case 'core.add_to_list':
55
+ return `Add ${records} to ${valueOf(input, 'list_id')}.`
56
+ case 'core.remove_from_list':
57
+ return `Remove ${records} from ${valueOf(input, 'list_id')}.`
58
+ case 'core.set_owner':
59
+ return `Change the owner of ${records} to ${valueOf(input, 'owner_id')}.`
60
+ case 'core.delete':
61
+ return `Delete ${records}.`
62
+ case 'core.set_custom_field':
63
+ return `Set ${valueOf(input, 'field_id')} to ${valueOf(input, 'value')} for ${records}.`
64
+ case 'core.export':
65
+ return `Export ${records} to a CSV file.`
66
+ case 'events.invite':
67
+ return `Invite ${records} to ${valueOf(input, 'event_id')}.`
68
+ case 'hiring.add_candidate':
69
+ return `Add ${records} as candidates for ${valueOf(input, 'role_id')}.`
70
+ case 'positions.add_to_company':
71
+ return `Add ${records} to ${valueOf(input, 'company_id')} as ${valueOf(input, 'title')}.`
72
+ case 'plans.add_item':
73
+ return 'owner_id' in input.params
74
+ ? `Add the plan item "${valueOf(input, 'title')}", due ${valueOf(input, 'date')} and owned by ${valueOf(input, 'owner_id')}, to ${records}.`
75
+ : `Add the plan item "${valueOf(input, 'title')}", due ${valueOf(input, 'date')}, to ${records}.`
76
+ case 'enquiries.convert_to_deal':
77
+ return `Convert ${records} to deals.`
78
+ default:
79
+ break
80
+ }
81
+
82
+ if (actionKey.endsWith('.move_stage') && 'stage_id' in input.params) {
83
+ return `Move ${records} to ${valueOf(input, 'stage_id')}.`
84
+ }
85
+
86
+ const given = input.fields.filter((field) => field.name in input.params)
87
+
88
+ if (given.length === 0) {
89
+ return `${input.actionLabel}: ${records}.`
90
+ }
91
+
92
+ // "Set relationship warmth to warm for 2 people."
93
+ const only = given.length === 1 ? given[0] : undefined
94
+
95
+ if (only !== undefined && input.actionLabel.startsWith('Set ')) {
96
+ return `${input.actionLabel} to ${displayOf(only, input.params[only.name], input.choices)} for ${records}.`
97
+ }
98
+
99
+ const values = given
100
+ .map((field) => `${field.label} ${displayOf(field, input.params[field.name], input.choices)}`)
101
+ .join(', ')
102
+
103
+ return `${input.actionLabel} for ${records}: ${values}.`
104
+ }
@@ -0,0 +1,11 @@
1
+ import type { BulkJobStatus } from '@kelpie/schemas'
2
+
3
+ /** A job's status in words, as the progress panel and the Bulk jobs page show it. */
4
+ export const STATUS_TEXT: Readonly<Record<BulkJobStatus, string>> = {
5
+ queued: 'Waiting to start',
6
+ running: 'Running',
7
+ completed: 'Done',
8
+ completed_with_errors: 'Done, with some failures',
9
+ failed: 'Stopped before it finished',
10
+ cancelled: 'Cancelled',
11
+ }
package/src/index.ts CHANGED
@@ -225,6 +225,8 @@ export type {
225
225
  RecordSidebarCard,
226
226
  RecordTab,
227
227
  RouteContribution,
228
+ UserMenuItem,
229
+ UserMenuItemContext,
228
230
  } from './registry/contributions.ts'
229
231
 
230
232
  export { defineOverridable } from './registry/overridable.ts'
@@ -245,6 +247,7 @@ export {
245
247
  useRecordSidebarCards,
246
248
  useRecordTabs,
247
249
  useUiExtensions,
250
+ useUserMenuItems,
248
251
  } from './registry/context.ts'
249
252
 
250
253
  export { UiExtensionProvider } from './registry/UiExtensionProvider.tsx'
@@ -0,0 +1,59 @@
1
+ import type { Activity, Note } from '@kelpie/schemas'
2
+
3
+ /**
4
+ * Who a timeline row or a note is attributed to, when no member can be named.
5
+ *
6
+ * A member who leaves a workspace, or deletes their account, takes their
7
+ * member row with them. What they wrote stays, and its member reference is
8
+ * cleared, so the row names nobody. The other fields still say a member did
9
+ * it: a note keeps `origin: 'member'`, and an activity has no label, which
10
+ * only a member's activity lacks.
11
+ */
12
+ export const FORMER_MEMBER_LABEL = 'Former member'
13
+
14
+ /**
15
+ * The name to show beside a note, or undefined for none.
16
+ *
17
+ * A note an agent or the hosted AI wrote with no member behind it shows no
18
+ * name: the origin label beside the date says what wrote it. One from before
19
+ * origin was recorded has no such label, so a null author there still reads
20
+ * as the workspace key it almost always was. A null author on a member's note
21
+ * is a member who has since gone.
22
+ */
23
+ export function noteAuthorName(
24
+ note: Pick<Note, 'authorId' | 'origin'>,
25
+ nameById: ReadonlyMap<string, string>,
26
+ ): string | undefined {
27
+ if (note.authorId !== null) {
28
+ return nameById.get(note.authorId) ?? 'Unknown'
29
+ }
30
+
31
+ switch (note.origin) {
32
+ case 'member':
33
+ return FORMER_MEMBER_LABEL
34
+ case 'unknown':
35
+ return 'API key'
36
+ case 'agent':
37
+ case 'ai':
38
+ return undefined
39
+ }
40
+ }
41
+
42
+ /**
43
+ * The name to show beside an activity.
44
+ *
45
+ * Exactly one of the two actor columns is set when the row is written.
46
+ * `actorLabel` carries the display name when nothing on the team did it:
47
+ * "Form", "Gmail", "API key". Both are null only once the member behind it
48
+ * has gone.
49
+ */
50
+ export function activityActorName(
51
+ activity: Pick<Activity, 'actorMemberId' | 'actorLabel'>,
52
+ nameById: ReadonlyMap<string, string>,
53
+ ): string {
54
+ if (activity.actorMemberId === null) {
55
+ return activity.actorLabel ?? FORMER_MEMBER_LABEL
56
+ }
57
+
58
+ return nameById.get(activity.actorMemberId) ?? 'Unknown'
59
+ }