@kelpie/ui 0.21.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/api/resources/forms.d.ts +21 -7
  2. package/dist/api/resources/forms.d.ts.map +1 -1
  3. package/dist/api/resources/forms.js +39 -1
  4. package/dist/api/resources/forms.js.map +1 -1
  5. package/dist/api/resources/tags.d.ts +20 -0
  6. package/dist/api/resources/tags.d.ts.map +1 -0
  7. package/dist/api/resources/tags.js +52 -0
  8. package/dist/api/resources/tags.js.map +1 -0
  9. package/dist/components/Chip.d.ts +5 -1
  10. package/dist/components/Chip.d.ts.map +1 -1
  11. package/dist/components/Chip.js +8 -2
  12. package/dist/components/Chip.js.map +1 -1
  13. package/dist/components/TagInput.d.ts +29 -0
  14. package/dist/components/TagInput.d.ts.map +1 -0
  15. package/dist/components/TagInput.js +139 -0
  16. package/dist/components/TagInput.js.map +1 -0
  17. package/dist/pages/CompanyDetail.d.ts.map +1 -1
  18. package/dist/pages/CompanyDetail.js +4 -3
  19. package/dist/pages/CompanyDetail.js.map +1 -1
  20. package/dist/pages/DealDetail.d.ts.map +1 -1
  21. package/dist/pages/DealDetail.js +4 -3
  22. package/dist/pages/DealDetail.js.map +1 -1
  23. package/dist/pages/EnquiryDetail.js +4 -4
  24. package/dist/pages/EnquiryDetail.js.map +1 -1
  25. package/dist/pages/EventDetail.js +4 -4
  26. package/dist/pages/EventDetail.js.map +1 -1
  27. package/dist/pages/OpportunityDetail.js +4 -4
  28. package/dist/pages/OpportunityDetail.js.map +1 -1
  29. package/dist/pages/PartnershipDetail.js +4 -4
  30. package/dist/pages/PartnershipDetail.js.map +1 -1
  31. package/dist/pages/PersonDetail.js +5 -5
  32. package/dist/pages/PersonDetail.js.map +1 -1
  33. package/dist/pages/RaiseDetail.js +4 -4
  34. package/dist/pages/RaiseDetail.js.map +1 -1
  35. package/dist/pages/forms/FieldsEditor.d.ts.map +1 -1
  36. package/dist/pages/forms/FieldsEditor.js +6 -7
  37. package/dist/pages/forms/FieldsEditor.js.map +1 -1
  38. package/dist/pages/forms/FormActions.d.ts.map +1 -1
  39. package/dist/pages/forms/FormActions.js +4 -11
  40. package/dist/pages/forms/FormActions.js.map +1 -1
  41. package/dist/pages/forms/SubmissionDetail.d.ts.map +1 -1
  42. package/dist/pages/forms/SubmissionDetail.js +11 -3
  43. package/dist/pages/forms/SubmissionDetail.js.map +1 -1
  44. package/dist/pages/forms/SubmissionsTable.d.ts.map +1 -1
  45. package/dist/pages/forms/SubmissionsTable.js +76 -4
  46. package/dist/pages/forms/SubmissionsTable.js.map +1 -1
  47. package/dist/pages/forms/fieldList.d.ts +13 -5
  48. package/dist/pages/forms/fieldList.d.ts.map +1 -1
  49. package/dist/pages/forms/fieldList.js +12 -4
  50. package/dist/pages/forms/fieldList.js.map +1 -1
  51. package/package.json +2 -2
  52. package/src/api/resources/forms.ts +68 -7
  53. package/src/api/resources/tags.ts +71 -0
  54. package/src/components/Chip.tsx +32 -1
  55. package/src/components/TagInput.tsx +285 -0
  56. package/src/pages/CompanyDetail.tsx +6 -17
  57. package/src/pages/DealDetail.tsx +6 -17
  58. package/src/pages/EnquiryDetail.tsx +6 -18
  59. package/src/pages/EventDetail.tsx +6 -18
  60. package/src/pages/OpportunityDetail.tsx +6 -18
  61. package/src/pages/PartnershipDetail.tsx +6 -18
  62. package/src/pages/PersonDetail.tsx +7 -19
  63. package/src/pages/RaiseDetail.tsx +6 -18
  64. package/src/pages/forms/FieldsEditor.tsx +6 -7
  65. package/src/pages/forms/FormActions.tsx +18 -20
  66. package/src/pages/forms/SubmissionDetail.tsx +24 -5
  67. package/src/pages/forms/SubmissionsTable.tsx +171 -4
  68. package/src/pages/forms/fieldList.ts +21 -7
@@ -0,0 +1,285 @@
1
+ import type { TagTargetType } from '@kelpie/schemas'
2
+ import { useEffect, useId, useRef, useState } from 'react'
3
+
4
+ import { useInvalidateTagSuggestions, useTagSuggestions } from '../api/resources/tags.ts'
5
+ import { Chip } from './Chip.tsx'
6
+
7
+ /**
8
+ * Edit a record's tags: search the tags already in use, or create one.
9
+ *
10
+ * The search box holds only what is being typed. The chosen tags sit below it as
11
+ * chips, each with an × to remove it, so the box can be empty while the record
12
+ * still has tags. Every add and remove calls `onChange` at once with the whole
13
+ * new list; the caller saves it.
14
+ *
15
+ * The list opens in the page flow, not over it, so it pushes the chips down
16
+ * rather than hiding them. Chosen tags also lead the list, ticked, and a click
17
+ * removes one.
18
+ *
19
+ * Suggestions come from `GET /v1/tags` for `targetType`, so a person's picker
20
+ * offers person tags and not deal tags. A typed tag that differs from an
21
+ * existing one only by case takes the existing spelling, so "Investor" does not
22
+ * appear beside "investor".
23
+ */
24
+
25
+ export interface TagInputProps {
26
+ readonly value: readonly string[]
27
+ readonly onChange: (next: readonly string[]) => void
28
+ readonly targetType: TagTargetType
29
+ readonly placeholder?: string | undefined
30
+ /** `sm` for a record sidebar, `md` for a full-width form. */
31
+ readonly size?: 'sm' | 'md' | undefined
32
+ readonly label?: string | undefined
33
+ }
34
+
35
+ interface Row {
36
+ readonly kind: 'chosen' | 'existing' | 'create'
37
+ readonly tag: string
38
+ readonly count: number | null
39
+ }
40
+
41
+ function sameTag(left: string, right: string): boolean {
42
+ return left.toLowerCase() === right.toLowerCase()
43
+ }
44
+
45
+ export function TagInput({
46
+ value,
47
+ onChange,
48
+ targetType,
49
+ placeholder = 'Search or create a tag…',
50
+ size = 'sm',
51
+ label = 'Tags',
52
+ }: TagInputProps): React.JSX.Element {
53
+ const listId = useId()
54
+ const rootRef = useRef<HTMLDivElement>(null)
55
+ const [query, setQuery] = useState('')
56
+ const [open, setOpen] = useState(false)
57
+ const [highlight, setHighlight] = useState(0)
58
+ const { suggestions, isLoading } = useTagSuggestions(targetType, query, open)
59
+ const invalidate = useInvalidateTagSuggestions()
60
+
61
+ const trimmed = query.trim()
62
+ // Chosen tags lead the list, ticked, so a reader can see what is already on
63
+ // the record without closing it. They come from `value`, not the server, so
64
+ // one outside the top suggestions still shows.
65
+ const chosen = value.filter((tag) => tag.toLowerCase().includes(trimmed.toLowerCase()))
66
+ const offered = suggestions.filter(
67
+ (suggestion) => !value.some((tag) => sameTag(tag, suggestion.tag)),
68
+ )
69
+ const alreadyChosen = trimmed.length > 0 && value.some((tag) => sameTag(tag, trimmed))
70
+ const exists = suggestions.some((suggestion) => sameTag(suggestion.tag, trimmed))
71
+ const rows: readonly Row[] = [
72
+ ...chosen.map((tag): Row => ({ kind: 'chosen', tag, count: null })),
73
+ ...offered.map((suggestion): Row => ({
74
+ kind: 'existing',
75
+ tag: suggestion.tag,
76
+ count: suggestion.count,
77
+ })),
78
+ ...(trimmed.length > 0 && !exists && !alreadyChosen
79
+ ? [{ kind: 'create' as const, tag: trimmed, count: null }]
80
+ : []),
81
+ ]
82
+
83
+ useEffect(() => {
84
+ if (!open) {
85
+ return
86
+ }
87
+
88
+ function onPointerDown(event: MouseEvent): void {
89
+ if (rootRef.current?.contains(event.target as Node) !== true) {
90
+ setOpen(false)
91
+ }
92
+ }
93
+
94
+ document.addEventListener('mousedown', onPointerDown)
95
+
96
+ return () => {
97
+ document.removeEventListener('mousedown', onPointerDown)
98
+ }
99
+ }, [open])
100
+
101
+ // Start on the first tag not yet chosen, so Enter adds rather than removes.
102
+ // With nothing to add, nothing is highlighted, and Enter does nothing.
103
+ const firstOffered = chosen.length < rows.length ? chosen.length : -1
104
+
105
+ useEffect(() => {
106
+ setHighlight(firstOffered)
107
+ }, [query, open, firstOffered])
108
+
109
+ /** Adds each tag not already chosen, in order, and clears the box. */
110
+ function add(...tags: readonly string[]): void {
111
+ const next = [...value]
112
+
113
+ for (const tag of tags) {
114
+ const clean = tag.trim()
115
+
116
+ if (clean.length === 0 || next.some((existing) => sameTag(existing, clean))) {
117
+ continue
118
+ }
119
+
120
+ // Take the spelling already in use, if there is one.
121
+ const known = suggestions.find((suggestion) => sameTag(suggestion.tag, clean))
122
+
123
+ next.push(known?.tag ?? clean)
124
+ }
125
+
126
+ setQuery('')
127
+
128
+ if (next.length !== value.length) {
129
+ onChange(next)
130
+ invalidate()
131
+ }
132
+ }
133
+
134
+ /**
135
+ * A comma ends a tag, as it did when this was a text box. Handled on change
136
+ * rather than on keydown, so a pasted "a, b, c" adds three tags too. What
137
+ * follows the last comma stays in the box.
138
+ */
139
+ function type(text: string): void {
140
+ const parts = text.split(',')
141
+ const rest = parts.pop() ?? ''
142
+
143
+ if (parts.length > 0) {
144
+ add(...parts)
145
+ }
146
+
147
+ setQuery(rest)
148
+ setOpen(true)
149
+ }
150
+
151
+ function remove(tag: string): void {
152
+ onChange(value.filter((existing) => existing !== tag))
153
+ invalidate()
154
+ }
155
+
156
+ const inputClass = size === 'sm' ? 'px-2 py-1.5 text-[12px]' : 'px-3 py-2 text-[13px]'
157
+
158
+ return (
159
+ <div ref={rootRef} className="space-y-1.5">
160
+ <div className="relative">
161
+ <input
162
+ value={query}
163
+ onChange={(event) => {
164
+ type(event.target.value)
165
+ }}
166
+ onFocus={() => {
167
+ setOpen(true)
168
+ }}
169
+ onKeyDown={(event) => {
170
+ if (event.key === 'ArrowDown') {
171
+ event.preventDefault()
172
+ setOpen(true)
173
+ setHighlight((current) => Math.min(current + 1, Math.max(rows.length - 1, 0)))
174
+ } else if (event.key === 'ArrowUp') {
175
+ event.preventDefault()
176
+ setHighlight((current) => Math.max(current - 1, 0))
177
+ } else if (event.key === 'Enter') {
178
+ event.preventDefault()
179
+ const row = open ? rows[highlight] : undefined
180
+
181
+ if (row?.kind === 'chosen') {
182
+ remove(row.tag)
183
+ } else {
184
+ add(row?.tag ?? trimmed)
185
+ }
186
+ } else if (event.key === 'Escape') {
187
+ setOpen(false)
188
+ setQuery('')
189
+ }
190
+ }}
191
+ placeholder={placeholder}
192
+ role="combobox"
193
+ aria-label={label}
194
+ aria-expanded={open}
195
+ aria-controls={listId}
196
+ aria-autocomplete="list"
197
+ className={`w-full rounded-md border border-border bg-surface-raised outline-none focus:border-accent focus:ring-2 focus:ring-accent/20 ${inputClass}`}
198
+ />
199
+
200
+ {open && (
201
+ <ul
202
+ id={listId}
203
+ role="listbox"
204
+ aria-label={`${label} suggestions`}
205
+ className="mt-1 max-h-56 w-full overflow-auto rounded-md border border-border bg-surface-raised py-1"
206
+ >
207
+ {rows.length === 0 ? (
208
+ <li className="px-3 py-2 text-[12px] text-ink-faint">
209
+ {isLoading ? 'Loading…' : 'Type to create a tag'}
210
+ </li>
211
+ ) : (
212
+ rows.map((row, index) => (
213
+ <li
214
+ key={`${row.kind}:${row.tag}`}
215
+ role="option"
216
+ aria-selected={index === highlight}
217
+ aria-checked={row.kind === 'chosen'}
218
+ // A rule between the groups: chosen, then in use, then create.
219
+ className={
220
+ index > 0 && rows[index - 1]?.kind !== row.kind ? 'border-t border-border' : ''
221
+ }
222
+ >
223
+ <button
224
+ type="button"
225
+ onMouseEnter={() => {
226
+ setHighlight(index)
227
+ }}
228
+ onClick={() => {
229
+ if (row.kind === 'chosen') {
230
+ remove(row.tag)
231
+ } else {
232
+ add(row.tag)
233
+ }
234
+ }}
235
+ className={[
236
+ 'flex w-full items-center justify-between gap-2 px-3 py-1.5 text-left text-[12px]',
237
+ row.kind === 'create' ? 'font-medium text-accent' : 'text-ink',
238
+ index === highlight ? 'bg-accent-soft' : 'hover:bg-surface',
239
+ ].join(' ')}
240
+ >
241
+ <span className="flex min-w-0 items-center gap-1.5">
242
+ {row.kind === 'chosen' && (
243
+ <span aria-hidden className="text-accent">
244
+ ✓
245
+ </span>
246
+ )}
247
+ <span className="truncate">
248
+ {row.kind === 'create' ? `Create “${row.tag}”` : row.tag}
249
+ </span>
250
+ </span>
251
+ {row.kind === 'chosen' && (
252
+ <span className="shrink-0 text-[10px] text-ink-faint">
253
+ Added · click to remove
254
+ </span>
255
+ )}
256
+ {row.count !== null && row.count > 0 && (
257
+ <span className="shrink-0 text-[10px] text-ink-faint">{row.count}</span>
258
+ )}
259
+ </button>
260
+ </li>
261
+ ))
262
+ )}
263
+ </ul>
264
+ )}
265
+ </div>
266
+
267
+ {value.length > 0 && (
268
+ <ul aria-label={label} className="flex flex-wrap gap-1">
269
+ {value.map((tag) => (
270
+ <li key={tag}>
271
+ <Chip
272
+ onRemove={() => {
273
+ remove(tag)
274
+ }}
275
+ removeLabel={`Remove tag ${tag}`}
276
+ >
277
+ {tag}
278
+ </Chip>
279
+ </li>
280
+ ))}
281
+ </ul>
282
+ )}
283
+ </div>
284
+ )
285
+ }
@@ -53,6 +53,7 @@ import { RecordTabs } from '../components/RecordTabs.tsx'
53
53
  import type { RecordTabDescriptor } from '../components/RecordTabs.tsx'
54
54
  import { SectionHeader } from '../components/SectionHeader.tsx'
55
55
  import { SidebarField } from '../components/SidebarField.tsx'
56
+ import { TagInput } from '../components/TagInput.tsx'
56
57
  import { SummaryBlock } from '../components/SummaryBlock.tsx'
57
58
  import { useRecordTabs } from '../registry/context.ts'
58
59
  import { inSlotOrder } from '../registry/registry.ts'
@@ -363,24 +364,12 @@ function CompanySidebar({
363
364
  />
364
365
  </SidebarField>
365
366
  <SidebarField label="Tags">
366
- <InlineEdit
367
- value={company.tags.join(', ')}
368
- onChange={(value) => {
369
- patch({ tags: toTags(value) })
367
+ <TagInput
368
+ value={company.tags}
369
+ targetType="company"
370
+ onChange={(tags) => {
371
+ patch({ tags })
370
372
  }}
371
- display={
372
- company.tags.length > 0 ? (
373
- <span className="flex flex-wrap gap-1">
374
- {company.tags.map((tag) => (
375
- <Chip key={tag}>
376
- <span className="text-[10px]">{tag}</span>
377
- </Chip>
378
- ))}
379
- </span>
380
- ) : undefined
381
- }
382
- emptyLabel="Add tags…"
383
- displayClassName="not-italic"
384
373
  />
385
374
  </SidebarField>
386
375
  </section>
@@ -39,6 +39,7 @@ import { RecordTabs } from '../components/RecordTabs.tsx'
39
39
  import type { RecordTabDescriptor } from '../components/RecordTabs.tsx'
40
40
  import { SectionHeader } from '../components/SectionHeader.tsx'
41
41
  import { SidebarField } from '../components/SidebarField.tsx'
42
+ import { TagInput } from '../components/TagInput.tsx'
42
43
  import { SummaryBlock } from '../components/SummaryBlock.tsx'
43
44
  import { formatDay } from '../lib/dates.ts'
44
45
  import { formatMoney } from '../lib/money.ts'
@@ -443,24 +444,12 @@ function DealSidebar({ deal }: { readonly deal: Deal }): React.JSX.Element {
443
444
  />
444
445
  </SidebarField>
445
446
  <SidebarField label="Tags">
446
- <InlineEdit
447
- value={deal.tags.join(', ')}
448
- onChange={(value) => {
449
- patch({ tags: toTags(value) })
447
+ <TagInput
448
+ value={deal.tags}
449
+ targetType="deal"
450
+ onChange={(tags) => {
451
+ patch({ tags })
450
452
  }}
451
- display={
452
- deal.tags.length > 0 ? (
453
- <span className="flex flex-wrap gap-1">
454
- {deal.tags.map((tag) => (
455
- <Chip key={tag}>
456
- <span className="text-[10px]">{tag}</span>
457
- </Chip>
458
- ))}
459
- </span>
460
- ) : undefined
461
- }
462
- emptyLabel="Add tags…"
463
- displayClassName="not-italic"
464
453
  />
465
454
  </SidebarField>
466
455
  </section>
@@ -43,11 +43,11 @@ import { RecordTabs } from '../components/RecordTabs.tsx'
43
43
  import type { RecordTabDescriptor } from '../components/RecordTabs.tsx'
44
44
  import { SectionHeader } from '../components/SectionHeader.tsx'
45
45
  import { SidebarField } from '../components/SidebarField.tsx'
46
+ import { TagInput } from '../components/TagInput.tsx'
46
47
  import { SummaryBlock } from '../components/SummaryBlock.tsx'
47
48
  import { useRecordTabs } from '../registry/context.ts'
48
49
  import { inSlotOrder } from '../registry/registry.ts'
49
50
  import { useRecordTab } from '../lib/fragmentTarget.ts'
50
- import { toTags } from './fields.ts'
51
51
 
52
52
  /**
53
53
  * One enquiry.
@@ -350,24 +350,12 @@ function EnquirySidebar({ enquiry }: { readonly enquiry: Enquiry }): React.JSX.E
350
350
  />
351
351
  </SidebarField>
352
352
  <SidebarField label="Tags">
353
- <InlineEdit
354
- value={enquiry.tags.join(', ')}
355
- onChange={(value) => {
356
- patch({ tags: toTags(value) })
353
+ <TagInput
354
+ value={enquiry.tags}
355
+ targetType="enquiry"
356
+ onChange={(tags) => {
357
+ patch({ tags })
357
358
  }}
358
- display={
359
- enquiry.tags.length > 0 ? (
360
- <span className="flex flex-wrap gap-1">
361
- {enquiry.tags.map((tag) => (
362
- <Chip key={tag}>
363
- <span className="text-[10px]">{tag}</span>
364
- </Chip>
365
- ))}
366
- </span>
367
- ) : undefined
368
- }
369
- emptyLabel="Add tags…"
370
- displayClassName="not-italic"
371
359
  />
372
360
  </SidebarField>
373
361
  </section>
@@ -61,13 +61,13 @@ import { RecordTabs } from '../components/RecordTabs.tsx'
61
61
  import type { RecordTabDescriptor } from '../components/RecordTabs.tsx'
62
62
  import { SectionHeader } from '../components/SectionHeader.tsx'
63
63
  import { SidebarField } from '../components/SidebarField.tsx'
64
+ import { TagInput } from '../components/TagInput.tsx'
64
65
  import { SummaryBlock } from '../components/SummaryBlock.tsx'
65
66
  import { TimezoneSearch } from '../components/TimezoneSearch.tsx'
66
67
  import { formatDateTime } from '../lib/dates.ts'
67
68
  import { useRecordTab } from '../lib/fragmentTarget.ts'
68
69
  import { useRecordTabs } from '../registry/context.ts'
69
70
  import { inSlotOrder } from '../registry/registry.ts'
70
- import { toTags } from './fields.ts'
71
71
 
72
72
  /**
73
73
  * One dated gathering. Not a pipeline: no stages, no convert, no kanban.
@@ -396,24 +396,12 @@ function EventSidebar({ event }: { readonly event: CrmEvent }): React.JSX.Elemen
396
396
  />
397
397
  </SidebarField>
398
398
  <SidebarField label="Tags">
399
- <InlineEdit
400
- value={event.tags.join(', ')}
401
- onChange={(value) => {
402
- patch({ tags: toTags(value) })
399
+ <TagInput
400
+ value={event.tags}
401
+ targetType="event"
402
+ onChange={(tags) => {
403
+ patch({ tags })
403
404
  }}
404
- display={
405
- event.tags.length > 0 ? (
406
- <span className="flex flex-wrap gap-1">
407
- {event.tags.map((tag) => (
408
- <Chip key={tag}>
409
- <span className="text-[10px]">{tag}</span>
410
- </Chip>
411
- ))}
412
- </span>
413
- ) : undefined
414
- }
415
- emptyLabel="Add tags…"
416
- displayClassName="not-italic"
417
405
  />
418
406
  </SidebarField>
419
407
  </section>
@@ -43,12 +43,12 @@ import { RecordTabs } from '../components/RecordTabs.tsx'
43
43
  import type { RecordTabDescriptor } from '../components/RecordTabs.tsx'
44
44
  import { SectionHeader } from '../components/SectionHeader.tsx'
45
45
  import { SidebarField } from '../components/SidebarField.tsx'
46
+ import { TagInput } from '../components/TagInput.tsx'
46
47
  import { SummaryBlock } from '../components/SummaryBlock.tsx'
47
48
  import { formatDay } from '../lib/dates.ts'
48
49
  import { useRecordTab } from '../lib/fragmentTarget.ts'
49
50
  import { useRecordTabs } from '../registry/context.ts'
50
51
  import { inSlotOrder } from '../registry/registry.ts'
51
- import { toTags } from './fields.ts'
52
52
 
53
53
  /**
54
54
  * One opportunity.
@@ -376,24 +376,12 @@ function OpportunitySidebar({
376
376
  />
377
377
  </SidebarField>
378
378
  <SidebarField label="Tags">
379
- <InlineEdit
380
- value={opportunity.tags.join(', ')}
381
- onChange={(value) => {
382
- patch({ tags: toTags(value) })
379
+ <TagInput
380
+ value={opportunity.tags}
381
+ targetType="opportunity"
382
+ onChange={(tags) => {
383
+ patch({ tags })
383
384
  }}
384
- display={
385
- opportunity.tags.length > 0 ? (
386
- <span className="flex flex-wrap gap-1">
387
- {opportunity.tags.map((tag) => (
388
- <Chip key={tag}>
389
- <span className="text-[10px]">{tag}</span>
390
- </Chip>
391
- ))}
392
- </span>
393
- ) : undefined
394
- }
395
- emptyLabel="Add tags…"
396
- displayClassName="not-italic"
397
385
  />
398
386
  </SidebarField>
399
387
  </section>
@@ -43,12 +43,12 @@ import { RecordTabs } from '../components/RecordTabs.tsx'
43
43
  import type { RecordTabDescriptor } from '../components/RecordTabs.tsx'
44
44
  import { SectionHeader } from '../components/SectionHeader.tsx'
45
45
  import { SidebarField } from '../components/SidebarField.tsx'
46
+ import { TagInput } from '../components/TagInput.tsx'
46
47
  import { SummaryBlock } from '../components/SummaryBlock.tsx'
47
48
  import { formatDay } from '../lib/dates.ts'
48
49
  import { useRecordTab } from '../lib/fragmentTarget.ts'
49
50
  import { useRecordTabs } from '../registry/context.ts'
50
51
  import { inSlotOrder } from '../registry/registry.ts'
51
- import { toTags } from './fields.ts'
52
52
 
53
53
  /**
54
54
  * One partnership.
@@ -398,24 +398,12 @@ function PartnershipSidebar({
398
398
  />
399
399
  </SidebarField>
400
400
  <SidebarField label="Tags">
401
- <InlineEdit
402
- value={partnership.tags.join(', ')}
403
- onChange={(value) => {
404
- patch({ tags: toTags(value) })
401
+ <TagInput
402
+ value={partnership.tags}
403
+ targetType="partnership"
404
+ onChange={(tags) => {
405
+ patch({ tags })
405
406
  }}
406
- display={
407
- partnership.tags.length > 0 ? (
408
- <span className="flex flex-wrap gap-1">
409
- {partnership.tags.map((tag) => (
410
- <Chip key={tag}>
411
- <span className="text-[10px]">{tag}</span>
412
- </Chip>
413
- ))}
414
- </span>
415
- ) : undefined
416
- }
417
- emptyLabel="Add tags…"
418
- displayClassName="not-italic"
419
407
  />
420
408
  </SidebarField>
421
409
  </section>
@@ -32,7 +32,6 @@ import {
32
32
  import { AddressSidebarLink, AddressesField } from '../components/AddressesField.tsx'
33
33
  import { ActivitiesPanel, LatestActivity } from '../components/ActivitiesPanel.tsx'
34
34
  import { AgentTasks } from '../components/AgentTasks.tsx'
35
- import { Chip } from '../components/Chip.tsx'
36
35
  import { DecisionsPanel } from '../components/DecisionsPanel.tsx'
37
36
  import { FormsPanel } from '../components/FormsPanel.tsx'
38
37
  import { DeleteRecord } from '../components/DeleteRecord.tsx'
@@ -49,6 +48,7 @@ import { RecordTabs } from '../components/RecordTabs.tsx'
49
48
  import type { RecordTabDescriptor } from '../components/RecordTabs.tsx'
50
49
  import { SectionHeader } from '../components/SectionHeader.tsx'
51
50
  import { SidebarField } from '../components/SidebarField.tsx'
51
+ import { TagInput } from '../components/TagInput.tsx'
52
52
  import { SocialProfileIcons, SocialProfilesField } from '../components/SocialProfilesField.tsx'
53
53
  import { TimezoneSearch } from '../components/TimezoneSearch.tsx'
54
54
  import { PhonesField } from '../components/PhonesField.tsx'
@@ -61,7 +61,7 @@ import {
61
61
  CandidateStageField,
62
62
  CandidateStatusField,
63
63
  } from './candidateFields.tsx'
64
- import { toOptions, toTags } from './fields.ts'
64
+ import { toOptions } from './fields.ts'
65
65
  import { usePersonNames, useRoleTitles } from './hiringDirectory.ts'
66
66
 
67
67
  /**
@@ -587,24 +587,12 @@ function PersonSidebar({
587
587
  />
588
588
  </SidebarField>
589
589
  <SidebarField label="Tags">
590
- <InlineEdit
591
- value={person.tags.join(', ')}
592
- onChange={(value) => {
593
- patch({ tags: toTags(value) })
590
+ <TagInput
591
+ value={person.tags}
592
+ targetType="person"
593
+ onChange={(tags) => {
594
+ patch({ tags })
594
595
  }}
595
- display={
596
- person.tags.length > 0 ? (
597
- <span className="flex flex-wrap gap-1">
598
- {person.tags.map((tag) => (
599
- <Chip key={tag}>
600
- <span className="text-[10px]">{tag}</span>
601
- </Chip>
602
- ))}
603
- </span>
604
- ) : undefined
605
- }
606
- emptyLabel="Add tags…"
607
- displayClassName="not-italic"
608
596
  />
609
597
  </SidebarField>
610
598
  </section>
@@ -37,13 +37,13 @@ import { RecordTabs } from '../components/RecordTabs.tsx'
37
37
  import type { RecordTabDescriptor } from '../components/RecordTabs.tsx'
38
38
  import { SectionHeader } from '../components/SectionHeader.tsx'
39
39
  import { SidebarField } from '../components/SidebarField.tsx'
40
+ import { TagInput } from '../components/TagInput.tsx'
40
41
  import { SummaryBlock } from '../components/SummaryBlock.tsx'
41
42
  import { formatDay } from '../lib/dates.ts'
42
43
  import { formatMoney } from '../lib/money.ts'
43
44
  import { useRecordTab } from '../lib/fragmentTarget.ts'
44
45
  import { useRecordTabs } from '../registry/context.ts'
45
46
  import { inSlotOrder } from '../registry/registry.ts'
46
- import { toTags } from './fields.ts'
47
47
 
48
48
  /**
49
49
  * One raise.
@@ -406,24 +406,12 @@ function RaiseSidebar({ raise }: { readonly raise: Raise }): React.JSX.Element {
406
406
  </SidebarField>
407
407
  )}
408
408
  <SidebarField label="Tags">
409
- <InlineEdit
410
- value={raise.tags.join(', ')}
411
- onChange={(value) => {
412
- patch({ tags: toTags(value) })
409
+ <TagInput
410
+ value={raise.tags}
411
+ targetType="raise"
412
+ onChange={(tags) => {
413
+ patch({ tags })
413
414
  }}
414
- display={
415
- raise.tags.length > 0 ? (
416
- <span className="flex flex-wrap gap-1">
417
- {raise.tags.map((tag) => (
418
- <Chip key={tag}>
419
- <span className="text-[10px]">{tag}</span>
420
- </Chip>
421
- ))}
422
- </span>
423
- ) : undefined
424
- }
425
- emptyLabel="Add tags…"
426
- displayClassName="not-italic"
427
415
  />
428
416
  </SidebarField>
429
417
  </section>
@@ -51,14 +51,13 @@ import type { EditableField } from './fieldList.ts'
51
51
  * drags it up and down; "Add field" offers ready-made fields to append.
52
52
  *
53
53
  * Explicitly saved rather than saved per keystroke, unlike the inline editing
54
- * everywhere else in the app. A write replaces the whole list, so an
55
- * auto-committing builder would send one full rewrite per character typed into a
56
- * label, and every one of them would reissue every field id. The draft lives
57
- * here until somebody presses Save.
54
+ * everywhere else in the app. A write carries the whole list, so an
55
+ * auto-committing builder would send one full list per character typed into a
56
+ * label. The draft lives here until somebody presses Save.
58
57
  *
59
58
  * A field id is a stored id for a saved field and a local one for a field just
60
- * added; neither is sent. The server assigns ids and positions from the array's
61
- * order on every write.
59
+ * added. A save sends the stored ids, so a saved field keeps its id through any
60
+ * edit; a local id is not sent, and the server gives that field its id.
62
61
  */
63
62
 
64
63
  let localFieldCount = 0
@@ -137,7 +136,7 @@ export function FieldsEditor({ form }: FieldsEditorProps): React.JSX.Element {
137
136
  }
138
137
 
139
138
  function save(): void {
140
- updateFields.run({ id: form.id, fields: toFieldInputs(fields) })
139
+ updateFields.run({ id: form.id, fields: toFieldInputs(form, fields) })
141
140
  }
142
141
 
143
142
  return (