@kelpie/ui 0.21.0 → 0.23.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.
- package/dist/api/resource.d.ts +12 -0
- package/dist/api/resource.d.ts.map +1 -1
- package/dist/api/resource.js +11 -0
- package/dist/api/resource.js.map +1 -1
- package/dist/api/resources/decisions.d.ts +31 -0
- package/dist/api/resources/decisions.d.ts.map +1 -1
- package/dist/api/resources/decisions.js +51 -1
- package/dist/api/resources/decisions.js.map +1 -1
- package/dist/api/resources/forms.d.ts +21 -7
- package/dist/api/resources/forms.d.ts.map +1 -1
- package/dist/api/resources/forms.js +39 -1
- package/dist/api/resources/forms.js.map +1 -1
- package/dist/api/resources/oauth.d.ts +2 -0
- package/dist/api/resources/oauth.d.ts.map +1 -1
- package/dist/api/resources/oauth.js +13 -1
- package/dist/api/resources/oauth.js.map +1 -1
- package/dist/api/resources/personIntake.d.ts +15 -3
- package/dist/api/resources/personIntake.d.ts.map +1 -1
- package/dist/api/resources/personIntake.js +38 -9
- package/dist/api/resources/personIntake.js.map +1 -1
- package/dist/api/resources/session.d.ts.map +1 -1
- package/dist/api/resources/session.js +4 -0
- package/dist/api/resources/session.js.map +1 -1
- package/dist/api/resources/tags.d.ts +20 -0
- package/dist/api/resources/tags.d.ts.map +1 -0
- package/dist/api/resources/tags.js +52 -0
- package/dist/api/resources/tags.js.map +1 -0
- package/dist/app/KelpieApp.d.ts.map +1 -1
- package/dist/app/KelpieApp.js +2 -1
- package/dist/app/KelpieApp.js.map +1 -1
- package/dist/components/AddRecordPanel.d.ts +35 -0
- package/dist/components/AddRecordPanel.d.ts.map +1 -0
- package/dist/components/AddRecordPanel.js +35 -0
- package/dist/components/AddRecordPanel.js.map +1 -0
- package/dist/components/AiDrawer.d.ts.map +1 -1
- package/dist/components/AiDrawer.js +29 -6
- package/dist/components/AiDrawer.js.map +1 -1
- package/dist/components/ApiKeysPanel.d.ts.map +1 -1
- package/dist/components/ApiKeysPanel.js +101 -44
- package/dist/components/ApiKeysPanel.js.map +1 -1
- package/dist/components/Chip.d.ts +5 -1
- package/dist/components/Chip.d.ts.map +1 -1
- package/dist/components/Chip.js +8 -2
- package/dist/components/Chip.js.map +1 -1
- package/dist/components/CustomFieldsPanel.d.ts.map +1 -1
- package/dist/components/CustomFieldsPanel.js +5 -2
- package/dist/components/CustomFieldsPanel.js.map +1 -1
- package/dist/components/DecisionProvenance.d.ts +27 -0
- package/dist/components/DecisionProvenance.d.ts.map +1 -0
- package/dist/components/DecisionProvenance.js +53 -0
- package/dist/components/DecisionProvenance.js.map +1 -0
- package/dist/components/DecisionsPanel.d.ts +3 -0
- package/dist/components/DecisionsPanel.d.ts.map +1 -1
- package/dist/components/DecisionsPanel.js +9 -5
- package/dist/components/DecisionsPanel.js.map +1 -1
- package/dist/components/MarkdownView.d.ts.map +1 -1
- package/dist/components/MarkdownView.js +18 -2
- package/dist/components/MarkdownView.js.map +1 -1
- package/dist/components/NotesPanel.d.ts.map +1 -1
- package/dist/components/NotesPanel.js +7 -3
- package/dist/components/NotesPanel.js.map +1 -1
- package/dist/components/OriginLabel.d.ts +5 -0
- package/dist/components/OriginLabel.d.ts.map +1 -0
- package/dist/components/OriginLabel.js +22 -0
- package/dist/components/OriginLabel.js.map +1 -0
- package/dist/components/Shell.d.ts.map +1 -1
- package/dist/components/Shell.js +17 -5
- package/dist/components/Shell.js.map +1 -1
- package/dist/components/TagInput.d.ts +29 -0
- package/dist/components/TagInput.d.ts.map +1 -0
- package/dist/components/TagInput.js +139 -0
- package/dist/components/TagInput.js.map +1 -0
- package/dist/components/aiDrawerState.d.ts +12 -0
- package/dist/components/aiDrawerState.d.ts.map +1 -1
- package/dist/components/aiDrawerState.js.map +1 -1
- package/dist/components/personIntakeTask.d.ts +15 -0
- package/dist/components/personIntakeTask.d.ts.map +1 -1
- package/dist/components/personIntakeTask.js +42 -0
- package/dist/components/personIntakeTask.js.map +1 -1
- package/dist/lib/personIntakeRunStorage.d.ts +15 -0
- package/dist/lib/personIntakeRunStorage.d.ts.map +1 -0
- package/dist/lib/personIntakeRunStorage.js +88 -0
- package/dist/lib/personIntakeRunStorage.js.map +1 -0
- package/dist/modules/PersonIntakeWizard.d.ts +1 -1
- package/dist/modules/PersonIntakeWizard.d.ts.map +1 -1
- package/dist/modules/PersonIntakeWizard.js +243 -29
- package/dist/modules/PersonIntakeWizard.js.map +1 -1
- package/dist/modules/ai.d.ts +1 -1
- package/dist/modules/ai.js +1 -1
- package/dist/pages/CompaniesPage.d.ts.map +1 -1
- package/dist/pages/CompaniesPage.js +13 -6
- package/dist/pages/CompaniesPage.js.map +1 -1
- package/dist/pages/CompanyDetail.d.ts.map +1 -1
- package/dist/pages/CompanyDetail.js +4 -3
- package/dist/pages/CompanyDetail.js.map +1 -1
- package/dist/pages/DealDetail.d.ts.map +1 -1
- package/dist/pages/DealDetail.js +4 -3
- package/dist/pages/DealDetail.js.map +1 -1
- package/dist/pages/DealsPage.d.ts.map +1 -1
- package/dist/pages/DealsPage.js +16 -8
- package/dist/pages/DealsPage.js.map +1 -1
- package/dist/pages/DecisionsPage.d.ts.map +1 -1
- package/dist/pages/DecisionsPage.js +7 -3
- package/dist/pages/DecisionsPage.js.map +1 -1
- package/dist/pages/EnquiriesPage.d.ts.map +1 -1
- package/dist/pages/EnquiriesPage.js +14 -6
- package/dist/pages/EnquiriesPage.js.map +1 -1
- package/dist/pages/EnquiryDetail.js +4 -4
- package/dist/pages/EnquiryDetail.js.map +1 -1
- package/dist/pages/EventDetail.js +4 -4
- package/dist/pages/EventDetail.js.map +1 -1
- package/dist/pages/FundraisingPage.d.ts.map +1 -1
- package/dist/pages/FundraisingPage.js +16 -11
- package/dist/pages/FundraisingPage.js.map +1 -1
- package/dist/pages/OpportunitiesPage.d.ts.map +1 -1
- package/dist/pages/OpportunitiesPage.js +14 -6
- package/dist/pages/OpportunitiesPage.js.map +1 -1
- package/dist/pages/OpportunityDetail.js +4 -4
- package/dist/pages/OpportunityDetail.js.map +1 -1
- package/dist/pages/PartnershipDetail.js +4 -4
- package/dist/pages/PartnershipDetail.js.map +1 -1
- package/dist/pages/PartnershipsPage.d.ts.map +1 -1
- package/dist/pages/PartnershipsPage.js +16 -11
- package/dist/pages/PartnershipsPage.js.map +1 -1
- package/dist/pages/PeoplePage.d.ts.map +1 -1
- package/dist/pages/PeoplePage.js +13 -8
- package/dist/pages/PeoplePage.js.map +1 -1
- package/dist/pages/PersonDetail.js +7 -7
- package/dist/pages/PersonDetail.js.map +1 -1
- package/dist/pages/RaiseDetail.js +4 -4
- package/dist/pages/RaiseDetail.js.map +1 -1
- package/dist/pages/SearchPage.d.ts.map +1 -1
- package/dist/pages/SearchPage.js +2 -1
- package/dist/pages/SearchPage.js.map +1 -1
- package/dist/pages/account/ConnectedAppsPage.d.ts +0 -5
- package/dist/pages/account/ConnectedAppsPage.d.ts.map +1 -1
- package/dist/pages/account/ConnectedAppsPage.js +38 -6
- package/dist/pages/account/ConnectedAppsPage.js.map +1 -1
- package/dist/pages/admin/AgentsPanel.d.ts +10 -0
- package/dist/pages/admin/AgentsPanel.d.ts.map +1 -0
- package/dist/pages/admin/AgentsPanel.js +81 -0
- package/dist/pages/admin/AgentsPanel.js.map +1 -0
- package/dist/pages/admin/AiAdminPage.d.ts.map +1 -1
- package/dist/pages/admin/AiAdminPage.js +9 -6
- package/dist/pages/admin/AiAdminPage.js.map +1 -1
- package/dist/pages/admin/AiPage.js +1 -1
- package/dist/pages/admin/TeamPage.d.ts.map +1 -1
- package/dist/pages/admin/TeamPage.js +16 -3
- package/dist/pages/admin/TeamPage.js.map +1 -1
- package/dist/pages/ai/AiAccessPage.d.ts +11 -0
- package/dist/pages/ai/AiAccessPage.d.ts.map +1 -0
- package/dist/pages/ai/AiAccessPage.js +16 -0
- package/dist/pages/ai/AiAccessPage.js.map +1 -0
- package/dist/pages/ai/McpPanel.d.ts +7 -0
- package/dist/pages/ai/McpPanel.d.ts.map +1 -0
- package/dist/pages/ai/McpPanel.js +86 -0
- package/dist/pages/ai/McpPanel.js.map +1 -0
- package/dist/pages/auth/nextPath.d.ts +6 -0
- package/dist/pages/auth/nextPath.d.ts.map +1 -1
- package/dist/pages/auth/nextPath.js +16 -1
- package/dist/pages/auth/nextPath.js.map +1 -1
- package/dist/pages/dashboard/sections.d.ts.map +1 -1
- package/dist/pages/dashboard/sections.js +4 -2
- package/dist/pages/dashboard/sections.js.map +1 -1
- package/dist/pages/forms/EmbedPanel.js +1 -1
- package/dist/pages/forms/EmbedPanel.js.map +1 -1
- package/dist/pages/forms/FieldsEditor.d.ts.map +1 -1
- package/dist/pages/forms/FieldsEditor.js +6 -7
- package/dist/pages/forms/FieldsEditor.js.map +1 -1
- package/dist/pages/forms/FormActions.d.ts.map +1 -1
- package/dist/pages/forms/FormActions.js +4 -11
- package/dist/pages/forms/FormActions.js.map +1 -1
- package/dist/pages/forms/FormEmails.d.ts.map +1 -1
- package/dist/pages/forms/FormEmails.js +6 -1
- package/dist/pages/forms/FormEmails.js.map +1 -1
- package/dist/pages/forms/FormSettings.d.ts.map +1 -1
- package/dist/pages/forms/FormSettings.js +6 -2
- package/dist/pages/forms/FormSettings.js.map +1 -1
- package/dist/pages/forms/SubmissionDetail.d.ts.map +1 -1
- package/dist/pages/forms/SubmissionDetail.js +26 -6
- package/dist/pages/forms/SubmissionDetail.js.map +1 -1
- package/dist/pages/forms/SubmissionsTable.d.ts.map +1 -1
- package/dist/pages/forms/SubmissionsTable.js +81 -6
- package/dist/pages/forms/SubmissionsTable.js.map +1 -1
- package/dist/pages/forms/fieldList.d.ts +13 -5
- package/dist/pages/forms/fieldList.d.ts.map +1 -1
- package/dist/pages/forms/fieldList.js +12 -4
- package/dist/pages/forms/fieldList.js.map +1 -1
- package/dist/pages/oauth/ConsentPage.d.ts.map +1 -1
- package/dist/pages/oauth/ConsentPage.js +132 -15
- package/dist/pages/oauth/ConsentPage.js.map +1 -1
- package/dist/registry/contributions.d.ts +1 -1
- package/package.json +3 -3
- package/src/api/resource.ts +16 -0
- package/src/api/resources/decisions.ts +81 -1
- package/src/api/resources/forms.ts +68 -7
- package/src/api/resources/oauth.ts +15 -1
- package/src/api/resources/personIntake.ts +54 -13
- package/src/api/resources/session.ts +4 -0
- package/src/api/resources/tags.ts +71 -0
- package/src/app/KelpieApp.tsx +4 -2
- package/src/components/AddRecordPanel.tsx +143 -0
- package/src/components/AiDrawer.tsx +34 -7
- package/src/components/ApiKeysPanel.tsx +193 -75
- package/src/components/Chip.tsx +32 -1
- package/src/components/CustomFieldsPanel.tsx +15 -5
- package/src/components/DecisionProvenance.tsx +95 -0
- package/src/components/DecisionsPanel.tsx +30 -2
- package/src/components/MarkdownView.tsx +45 -11
- package/src/components/NotesPanel.tsx +15 -6
- package/src/components/OriginLabel.tsx +26 -0
- package/src/components/Shell.tsx +30 -6
- package/src/components/TagInput.tsx +285 -0
- package/src/components/aiDrawerState.ts +12 -0
- package/src/components/personIntakeTask.tsx +48 -0
- package/src/lib/personIntakeRunStorage.ts +97 -0
- package/src/modules/PersonIntakeWizard.tsx +391 -30
- package/src/modules/ai.tsx +1 -1
- package/src/pages/CompaniesPage.tsx +22 -5
- package/src/pages/CompanyDetail.tsx +6 -17
- package/src/pages/DealDetail.tsx +6 -17
- package/src/pages/DealsPage.tsx +25 -8
- package/src/pages/DecisionsPage.tsx +28 -1
- package/src/pages/EnquiriesPage.tsx +23 -5
- package/src/pages/EnquiryDetail.tsx +6 -18
- package/src/pages/EventDetail.tsx +6 -18
- package/src/pages/FundraisingPage.tsx +25 -11
- package/src/pages/OpportunitiesPage.tsx +23 -5
- package/src/pages/OpportunityDetail.tsx +6 -18
- package/src/pages/PartnershipDetail.tsx +6 -18
- package/src/pages/PartnershipsPage.tsx +25 -11
- package/src/pages/PeoplePage.tsx +22 -7
- package/src/pages/PersonDetail.tsx +11 -21
- package/src/pages/RaiseDetail.tsx +6 -18
- package/src/pages/SearchPage.tsx +3 -0
- package/src/pages/account/ConnectedAppsPage.tsx +97 -14
- package/src/pages/admin/{McpPanel.tsx → AgentsPanel.tsx} +11 -168
- package/src/pages/admin/AiAdminPage.tsx +16 -11
- package/src/pages/admin/AiPage.tsx +1 -1
- package/src/pages/admin/TeamPage.tsx +33 -0
- package/src/pages/ai/AiAccessPage.tsx +23 -0
- package/src/pages/ai/McpPanel.tsx +261 -0
- package/src/pages/auth/nextPath.ts +18 -1
- package/src/pages/dashboard/sections.tsx +4 -0
- package/src/pages/forms/EmbedPanel.tsx +3 -2
- package/src/pages/forms/FieldsEditor.tsx +6 -7
- package/src/pages/forms/FormActions.tsx +18 -20
- package/src/pages/forms/FormEmails.tsx +11 -2
- package/src/pages/forms/FormSettings.tsx +5 -0
- package/src/pages/forms/SubmissionDetail.tsx +47 -9
- package/src/pages/forms/SubmissionsTable.tsx +180 -5
- package/src/pages/forms/fieldList.ts +21 -7
- package/src/pages/oauth/ConsentPage.tsx +271 -33
- package/src/registry/contributions.ts +1 -1
|
@@ -2,27 +2,38 @@ import {
|
|
|
2
2
|
PERSON_INTAKE_KIND_LABELS,
|
|
3
3
|
PERSON_INTAKE_KINDS,
|
|
4
4
|
PERSON_INTAKE_PERSON_KEY,
|
|
5
|
+
personIntakeCandidateBody,
|
|
5
6
|
personIntakeDependencies,
|
|
7
|
+
personIntakeCandidateSchema,
|
|
6
8
|
} from '@kelpie/schemas'
|
|
7
9
|
import type {
|
|
8
10
|
PersonIntakeCandidate,
|
|
11
|
+
PersonIntakeCandidateWire,
|
|
9
12
|
PersonIntakeIdentifyResult,
|
|
10
13
|
PersonIntakeItem,
|
|
11
14
|
PersonIntakeKind,
|
|
12
15
|
PersonIntakeResearchResult,
|
|
13
16
|
PersonIntakeResult,
|
|
14
17
|
PersonIntakeResultStatus,
|
|
18
|
+
PersonIntakeSavedRun,
|
|
15
19
|
PersonIntakeSource,
|
|
16
20
|
} from '@kelpie/schemas'
|
|
17
21
|
import { useEffect, useState } from 'react'
|
|
18
22
|
import { Link } from 'react-router'
|
|
19
23
|
|
|
20
24
|
import { useAiServiceLabel } from '../api/resources/ai.ts'
|
|
21
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
useApplyPersonIntake,
|
|
27
|
+
usePersonIntakeRun,
|
|
28
|
+
useStartIdentify,
|
|
29
|
+
useStartResearch,
|
|
30
|
+
} from '../api/resources/personIntake.ts'
|
|
31
|
+
import { useSession } from '../api/resources/session.ts'
|
|
22
32
|
import { Chip } from '../components/Chip.tsx'
|
|
23
33
|
import type { ChipTone } from '../components/Chip.tsx'
|
|
24
34
|
import { IntakeFrame, NotesField } from '../components/PersonIntakePanel.tsx'
|
|
25
|
-
import { ErrorPanel } from '../components/QueryState.tsx'
|
|
35
|
+
import { ErrorPanel, LoadingPanel } from '../components/QueryState.tsx'
|
|
36
|
+
import { clearSavedIntakeRuns, readSavedIntakeRun, saveIntakeRun } from '../lib/personIntakeRunStorage.ts'
|
|
26
37
|
import type { PersonIntakeWizardProps } from '../registry/contributions.ts'
|
|
27
38
|
import { effectiveSelection } from './personIntakeSelection.ts'
|
|
28
39
|
|
|
@@ -31,19 +42,65 @@ import { effectiveSelection } from './personIntakeSelection.ts'
|
|
|
31
42
|
* person, choose what to create, done. Spec: person intake, in the `ai`
|
|
32
43
|
* module's docs (`docs/agents/kelpie-ai.md`).
|
|
33
44
|
*
|
|
34
|
-
* The wizard holds no records of its own.
|
|
35
|
-
*
|
|
45
|
+
* The wizard holds no records of its own. `identify` and `research` each start
|
|
46
|
+
* an AI run on the server, and the wizard reads the run every 2 seconds until
|
|
47
|
+
* it settles. The run and the step are kept in `sessionStorage`, so a reload
|
|
48
|
+
* picks the task up again; the server keeps a run's result for an hour. The
|
|
49
|
+
* last step writes only the ticked items.
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* What the Confirm step shows. It names no run: when the step is rebuilt from
|
|
54
|
+
* a saved candidate after a reload, the identify run that found the person
|
|
55
|
+
* may be gone, and there is no id to give it. The run, when it is still known,
|
|
56
|
+
* is the step's `identifyRunId`.
|
|
36
57
|
*/
|
|
58
|
+
type Identified = Omit<PersonIntakeIdentifyResult, 'runId'>
|
|
37
59
|
|
|
38
60
|
type Step =
|
|
61
|
+
| { readonly kind: 'restoring'; readonly saved: PersonIntakeSavedRun['step'] }
|
|
39
62
|
| { readonly kind: 'notes' }
|
|
40
|
-
| {
|
|
63
|
+
| {
|
|
64
|
+
readonly kind: 'confirm'
|
|
65
|
+
readonly identified: Identified
|
|
66
|
+
/** The identify run behind this step, when its result is still on the server. */
|
|
67
|
+
readonly identifyRunId: string | null
|
|
68
|
+
readonly target?: string | null
|
|
69
|
+
}
|
|
41
70
|
| { readonly kind: 'choose'; readonly research: PersonIntakeResearchResult }
|
|
42
71
|
| { readonly kind: 'done'; readonly results: readonly PersonIntakeResult[] }
|
|
43
72
|
|
|
73
|
+
/** A run the wizard is waiting on, and what it was started with. */
|
|
74
|
+
interface WatchedRun {
|
|
75
|
+
readonly runId: string
|
|
76
|
+
readonly text: string
|
|
77
|
+
/** The identify run a research run was started from. */
|
|
78
|
+
readonly identifyRunId: string | null
|
|
79
|
+
/** The confirmed person, for a research run. */
|
|
80
|
+
readonly candidate: PersonIntakeCandidateWire | null
|
|
81
|
+
readonly existingPersonId: string | null
|
|
82
|
+
/**
|
|
83
|
+
* After a reload of a failed research run, the person it was started with.
|
|
84
|
+
* The wizard reads the identify run again for the full Confirm step; when
|
|
85
|
+
* that run or its result has gone, it rebuilds Confirm from this instead.
|
|
86
|
+
*/
|
|
87
|
+
readonly fallback: { readonly candidate: PersonIntakeCandidateWire; readonly existingPersonId: string | null } | null
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** What the wizard keeps for a reload, less the user it belongs to. */
|
|
91
|
+
type SavedState = Omit<PersonIntakeSavedRun, 'user_id'>
|
|
92
|
+
|
|
44
93
|
const STEP_LABELS = ['Notes', 'Confirm', 'Choose', 'Done'] as const
|
|
45
94
|
|
|
46
|
-
const STEP_INDEX: Readonly<Record<Step['kind'], number>> = {
|
|
95
|
+
const STEP_INDEX: Readonly<Record<Exclude<Step['kind'], 'restoring'>, number>> = {
|
|
96
|
+
notes: 0,
|
|
97
|
+
confirm: 1,
|
|
98
|
+
choose: 2,
|
|
99
|
+
done: 3,
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Shown, with the notes still filled in, when a run's result has gone. */
|
|
103
|
+
const RESULT_GONE_MESSAGE = 'This result is no longer available. Start again.'
|
|
47
104
|
|
|
48
105
|
/** Pipeline records start unticked: the model suggests them, the user decides. */
|
|
49
106
|
const OFF_BY_DEFAULT: ReadonlySet<PersonIntakeKind> = new Set(['partnership', 'deal', 'enquiry'])
|
|
@@ -53,42 +110,306 @@ const primaryButton =
|
|
|
53
110
|
const secondaryButton =
|
|
54
111
|
'rounded-md px-2.5 py-1.5 text-[12px] font-medium text-ink-muted hover:text-ink disabled:opacity-50'
|
|
55
112
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
113
|
+
/** The Confirm step for a research run, rebuilt from the person it was started with. */
|
|
114
|
+
function confirmFrom(
|
|
115
|
+
candidate: PersonIntakeCandidateWire | null,
|
|
116
|
+
identifyRunId: string | null,
|
|
117
|
+
existingPersonId: string | null,
|
|
118
|
+
): Step {
|
|
119
|
+
if (candidate === null) return { kind: 'notes' }
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
kind: 'confirm',
|
|
123
|
+
identified: { candidates: [personIntakeCandidateSchema.parse(candidate)], question: null, sources: [] },
|
|
124
|
+
identifyRunId,
|
|
125
|
+
target: existingPersonId,
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function confirmFor(watched: WatchedRun): Step {
|
|
130
|
+
return confirmFrom(watched.candidate, watched.identifyRunId, watched.existingPersonId)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function stepIndex(step: Step): number {
|
|
134
|
+
return step.kind === 'restoring' ? STEP_INDEX[step.saved] : STEP_INDEX[step.kind]
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Where a reload starts: the run to read, or, for a run that failed, the step
|
|
139
|
+
* and the notes alone. A failed research run reads its identify run again,
|
|
140
|
+
* while that result is kept, to rebuild the Confirm step.
|
|
141
|
+
*/
|
|
142
|
+
function restoredState(saved: PersonIntakeSavedRun | undefined): { step: Step; watched: WatchedRun | undefined } {
|
|
143
|
+
if (saved === undefined) return { step: { kind: 'notes' }, watched: undefined }
|
|
144
|
+
|
|
145
|
+
const runId = saved.run_id ?? (saved.step === 'confirm' ? saved.identify_run_id : null)
|
|
146
|
+
|
|
147
|
+
if (runId !== null) {
|
|
148
|
+
return {
|
|
149
|
+
step: { kind: 'restoring', saved: saved.step },
|
|
150
|
+
watched: {
|
|
151
|
+
runId,
|
|
152
|
+
text: saved.text,
|
|
153
|
+
identifyRunId: saved.run_id === null ? null : saved.identify_run_id,
|
|
154
|
+
candidate: saved.run_id === null ? null : saved.candidate,
|
|
155
|
+
existingPersonId: saved.run_id === null ? null : saved.existing_person_id,
|
|
156
|
+
fallback:
|
|
157
|
+
saved.run_id === null && saved.candidate !== null
|
|
158
|
+
? { candidate: saved.candidate, existingPersonId: saved.existing_person_id }
|
|
159
|
+
: null,
|
|
160
|
+
},
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return {
|
|
165
|
+
step: saved.step === 'confirm' ? confirmFrom(saved.candidate, null, saved.existing_person_id) : { kind: 'notes' },
|
|
166
|
+
watched: undefined,
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function PersonIntakeWizard(props: PersonIntakeWizardProps): React.JSX.Element {
|
|
171
|
+
const { session } = useSession()
|
|
172
|
+
|
|
173
|
+
// The saved run is per workspace and user, so the wizard waits until it knows both.
|
|
174
|
+
if (session === undefined) return <LoadingPanel label="Loading…" />
|
|
175
|
+
|
|
176
|
+
return (
|
|
177
|
+
<IntakeWizard
|
|
178
|
+
key={`${session.workspaceId ?? ''}:${session.userId}`}
|
|
179
|
+
{...props}
|
|
180
|
+
workspaceId={session.workspaceId}
|
|
181
|
+
userId={session.userId}
|
|
182
|
+
/>
|
|
183
|
+
)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function IntakeWizard({
|
|
187
|
+
onClose,
|
|
188
|
+
onPendingChange,
|
|
189
|
+
workspaceId,
|
|
190
|
+
userId,
|
|
191
|
+
}: PersonIntakeWizardProps & { readonly workspaceId: string | null; readonly userId: string }): React.JSX.Element {
|
|
192
|
+
const [restored] = useState(() => {
|
|
193
|
+
const saved = workspaceId === null ? undefined : readSavedIntakeRun(workspaceId, userId)
|
|
194
|
+
|
|
195
|
+
return { ...restoredState(saved), text: saved?.text ?? '' }
|
|
196
|
+
})
|
|
197
|
+
const [step, setStep] = useState<Step>(restored.step)
|
|
198
|
+
const [text, setText] = useState(restored.text)
|
|
199
|
+
const [watched, setWatched] = useState<WatchedRun | undefined>(restored.watched)
|
|
200
|
+
/** Why the last run failed, from the server. Shown as written: it is the run log's reason. */
|
|
201
|
+
const [runFailure, setRunFailure] = useState<string | null>(null)
|
|
202
|
+
const [resultGone, setResultGone] = useState(false)
|
|
203
|
+
const identify = useStartIdentify()
|
|
204
|
+
const research = useStartResearch()
|
|
61
205
|
const apply = useApplyPersonIntake()
|
|
62
|
-
const
|
|
206
|
+
const polled = usePersonIntakeRun(watched?.runId)
|
|
207
|
+
// While a run is watched, even one the wizard cannot read just now, nothing
|
|
208
|
+
// new starts: the server run goes on, and a second would spend another.
|
|
209
|
+
const pending = identify.isPending || research.isPending || apply.isPending || watched !== undefined
|
|
210
|
+
const readError = watched !== undefined && !polled.isNotFound ? polled.error : null
|
|
63
211
|
|
|
64
212
|
useEffect(() => {
|
|
65
213
|
onPendingChange?.(pending)
|
|
66
214
|
}, [pending, onPendingChange])
|
|
67
215
|
|
|
216
|
+
// Moves the wizard on when the run it waits on changes, once per settled run.
|
|
217
|
+
useEffect(() => {
|
|
218
|
+
if (watched === undefined) return
|
|
219
|
+
|
|
220
|
+
function keep(state: SavedState): void {
|
|
221
|
+
if (workspaceId !== null) saveIntakeRun(workspaceId, { user_id: userId, ...state })
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function forget(): void {
|
|
225
|
+
if (workspaceId !== null) clearSavedIntakeRuns(workspaceId)
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** The run's result has gone: Confirm from the saved person when there is one, else the notes. */
|
|
229
|
+
function resultGoneFor(current: WatchedRun): void {
|
|
230
|
+
setWatched(undefined)
|
|
231
|
+
|
|
232
|
+
if (current.fallback !== null) {
|
|
233
|
+
setStep(confirmFrom(current.fallback.candidate, null, current.fallback.existingPersonId))
|
|
234
|
+
keep({
|
|
235
|
+
run_id: null,
|
|
236
|
+
identify_run_id: null,
|
|
237
|
+
step: 'confirm',
|
|
238
|
+
text: current.text,
|
|
239
|
+
candidate: current.fallback.candidate,
|
|
240
|
+
existing_person_id: current.fallback.existingPersonId,
|
|
241
|
+
})
|
|
242
|
+
return
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
setResultGone(true)
|
|
246
|
+
setStep({ kind: 'notes' })
|
|
247
|
+
forget()
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (polled.isNotFound) {
|
|
251
|
+
resultGoneFor(watched)
|
|
252
|
+
return
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (polled.error !== null) {
|
|
256
|
+
// The run may still finish. Keep watching it, and show the error with
|
|
257
|
+
// a way to read it again; the step leaves the loading state.
|
|
258
|
+
setStep((current) => (current.kind === 'restoring' ? confirmOrNotes(watched) : current))
|
|
259
|
+
return
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const run = polled.run
|
|
263
|
+
if (run === undefined) return
|
|
264
|
+
|
|
265
|
+
if (run.status === 'queued' || run.status === 'running') {
|
|
266
|
+
setStep((current) =>
|
|
267
|
+
current.kind !== 'restoring' ? current : run.kind === 'identify' ? { kind: 'notes' } : confirmFor(watched),
|
|
268
|
+
)
|
|
269
|
+
return
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
setWatched(undefined)
|
|
273
|
+
|
|
274
|
+
if (run.status === 'failed') {
|
|
275
|
+
setRunFailure(run.failureReason ?? 'The AI run failed.')
|
|
276
|
+
setStep((current) =>
|
|
277
|
+
current.kind === 'confirm' ? current : run.kind === 'identify' ? { kind: 'notes' } : confirmFor(watched),
|
|
278
|
+
)
|
|
279
|
+
// The step and the notes stay saved, with no run to wait on.
|
|
280
|
+
keep({
|
|
281
|
+
run_id: null,
|
|
282
|
+
identify_run_id: run.kind === 'research' ? watched.identifyRunId : null,
|
|
283
|
+
step: run.kind === 'identify' ? 'notes' : 'confirm',
|
|
284
|
+
text: watched.text,
|
|
285
|
+
candidate: run.kind === 'research' ? watched.candidate : null,
|
|
286
|
+
existing_person_id: run.kind === 'research' ? watched.existingPersonId : null,
|
|
287
|
+
})
|
|
288
|
+
return
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (run.kind === 'identify' && run.result !== null) {
|
|
292
|
+
setStep({ kind: 'confirm', identified: run.result, identifyRunId: run.runId })
|
|
293
|
+
keep({
|
|
294
|
+
run_id: run.runId,
|
|
295
|
+
identify_run_id: null,
|
|
296
|
+
step: 'confirm',
|
|
297
|
+
text: watched.text,
|
|
298
|
+
candidate: null,
|
|
299
|
+
existing_person_id: null,
|
|
300
|
+
})
|
|
301
|
+
return
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
if (run.kind === 'research' && run.result !== null) {
|
|
305
|
+
setStep({ kind: 'choose', research: run.result })
|
|
306
|
+
keep({
|
|
307
|
+
run_id: run.runId,
|
|
308
|
+
identify_run_id: watched.identifyRunId,
|
|
309
|
+
step: 'choose',
|
|
310
|
+
text: watched.text,
|
|
311
|
+
candidate: watched.candidate,
|
|
312
|
+
existing_person_id: watched.existingPersonId,
|
|
313
|
+
})
|
|
314
|
+
return
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// Succeeded, and the hour has passed: the result is gone.
|
|
318
|
+
resultGoneFor(watched)
|
|
319
|
+
}, [watched, polled.run, polled.error, polled.isNotFound, workspaceId, userId])
|
|
320
|
+
|
|
321
|
+
function remember(run: WatchedRun, savedStep: PersonIntakeSavedRun['step']): void {
|
|
322
|
+
setWatched(run)
|
|
323
|
+
if (workspaceId === null) return
|
|
324
|
+
|
|
325
|
+
saveIntakeRun(workspaceId, {
|
|
326
|
+
user_id: userId,
|
|
327
|
+
run_id: run.runId,
|
|
328
|
+
identify_run_id: run.identifyRunId,
|
|
329
|
+
step: savedStep,
|
|
330
|
+
text: run.text,
|
|
331
|
+
candidate: run.candidate,
|
|
332
|
+
existing_person_id: run.existingPersonId,
|
|
333
|
+
})
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function forgetSaved(): void {
|
|
337
|
+
if (workspaceId !== null) clearSavedIntakeRuns(workspaceId)
|
|
338
|
+
}
|
|
339
|
+
|
|
68
340
|
async function runIdentify(): Promise<void> {
|
|
69
|
-
|
|
70
|
-
|
|
341
|
+
setRunFailure(null)
|
|
342
|
+
setResultGone(false)
|
|
343
|
+
const notes = text.trim()
|
|
344
|
+
const started = await identify.runAsync(notes)
|
|
345
|
+
remember(
|
|
346
|
+
{ runId: started.runId, text: notes, identifyRunId: null, candidate: null, existingPersonId: null, fallback: null },
|
|
347
|
+
'notes',
|
|
348
|
+
)
|
|
71
349
|
}
|
|
72
350
|
|
|
73
|
-
async function runResearch(
|
|
74
|
-
|
|
75
|
-
|
|
351
|
+
async function runResearch(
|
|
352
|
+
candidate: PersonIntakeCandidate,
|
|
353
|
+
existingPersonId: string | null,
|
|
354
|
+
identifyRunId: string | null,
|
|
355
|
+
): Promise<void> {
|
|
356
|
+
setRunFailure(null)
|
|
357
|
+
const notes = text.trim()
|
|
358
|
+
const started = await research.runAsync({ text: notes, candidate, existingPersonId })
|
|
359
|
+
remember(
|
|
360
|
+
{
|
|
361
|
+
runId: started.runId,
|
|
362
|
+
text: notes,
|
|
363
|
+
identifyRunId,
|
|
364
|
+
candidate: personIntakeCandidateBody(candidate),
|
|
365
|
+
existingPersonId,
|
|
366
|
+
fallback: null,
|
|
367
|
+
},
|
|
368
|
+
'confirm',
|
|
369
|
+
)
|
|
76
370
|
}
|
|
77
371
|
|
|
78
372
|
async function runApply(items: readonly PersonIntakeItem[]): Promise<void> {
|
|
79
373
|
const applied = await apply.runAsync(items)
|
|
80
374
|
setStep({ kind: 'done', results: applied.results })
|
|
375
|
+
forgetSaved()
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function startAgain(): void {
|
|
379
|
+
setRunFailure(null)
|
|
380
|
+
setStep({ kind: 'notes' })
|
|
381
|
+
forgetSaved()
|
|
81
382
|
}
|
|
82
383
|
|
|
83
384
|
return (
|
|
84
385
|
<>
|
|
85
|
-
<StepBar current={
|
|
386
|
+
<StepBar current={stepIndex(step)} />
|
|
387
|
+
{readError !== null && (
|
|
388
|
+
<div role="alert" className="border-b border-border px-4 py-3">
|
|
389
|
+
<ErrorPanel error={readError} />
|
|
390
|
+
<p className="mt-2 text-[12px] text-ink-muted">
|
|
391
|
+
The run may still be working. Kelpie will not start another until this one is read.
|
|
392
|
+
</p>
|
|
393
|
+
<button
|
|
394
|
+
type="button"
|
|
395
|
+
className={`${secondaryButton} mt-1`}
|
|
396
|
+
onClick={() => {
|
|
397
|
+
polled.refetch()
|
|
398
|
+
}}
|
|
399
|
+
>
|
|
400
|
+
Check again
|
|
401
|
+
</button>
|
|
402
|
+
</div>
|
|
403
|
+
)}
|
|
404
|
+
{step.kind === 'restoring' && <LoadingPanel label="Picking up where you left off…" />}
|
|
86
405
|
{step.kind === 'notes' && (
|
|
87
406
|
<NotesStep
|
|
88
407
|
text={text}
|
|
89
408
|
onChange={setText}
|
|
90
|
-
pending={
|
|
409
|
+
pending={pending}
|
|
91
410
|
error={identify.error}
|
|
411
|
+
failure={runFailure}
|
|
412
|
+
notice={resultGone ? RESULT_GONE_MESSAGE : null}
|
|
92
413
|
onNext={() => {
|
|
93
414
|
void runIdentify().catch(() => undefined)
|
|
94
415
|
}}
|
|
@@ -97,13 +418,13 @@ export function PersonIntakeWizard({ onClose, onPendingChange }: PersonIntakeWiz
|
|
|
97
418
|
{step.kind === 'confirm' && (
|
|
98
419
|
<ConfirmStep
|
|
99
420
|
identified={step.identified}
|
|
100
|
-
|
|
421
|
+
initialTarget={step.target}
|
|
422
|
+
pending={pending}
|
|
101
423
|
error={research.error}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}}
|
|
424
|
+
failure={runFailure}
|
|
425
|
+
onBack={startAgain}
|
|
105
426
|
onNext={(candidate, existingPersonId) => {
|
|
106
|
-
void runResearch(candidate, existingPersonId).catch(() => undefined)
|
|
427
|
+
void runResearch(candidate, existingPersonId, step.identifyRunId).catch(() => undefined)
|
|
107
428
|
}}
|
|
108
429
|
/>
|
|
109
430
|
)}
|
|
@@ -112,9 +433,7 @@ export function PersonIntakeWizard({ onClose, onPendingChange }: PersonIntakeWiz
|
|
|
112
433
|
research={step.research}
|
|
113
434
|
pending={apply.isPending}
|
|
114
435
|
error={apply.error}
|
|
115
|
-
onBack={
|
|
116
|
-
setStep({ kind: 'notes' })
|
|
117
|
-
}}
|
|
436
|
+
onBack={startAgain}
|
|
118
437
|
onNext={(items) => {
|
|
119
438
|
void runApply(items).catch(() => undefined)
|
|
120
439
|
}}
|
|
@@ -125,6 +444,27 @@ export function PersonIntakeWizard({ onClose, onPendingChange }: PersonIntakeWiz
|
|
|
125
444
|
)
|
|
126
445
|
}
|
|
127
446
|
|
|
447
|
+
/**
|
|
448
|
+
* Where a run the wizard could not read leaves it: the Confirm step for
|
|
449
|
+
* research, or for a reload of a failed research run the saved person's
|
|
450
|
+
* Confirm step, else the notes.
|
|
451
|
+
*/
|
|
452
|
+
function confirmOrNotes(watched: WatchedRun): Step {
|
|
453
|
+
if (watched.candidate !== null) return confirmFor(watched)
|
|
454
|
+
if (watched.fallback !== null) return confirmFrom(watched.fallback.candidate, null, watched.fallback.existingPersonId)
|
|
455
|
+
|
|
456
|
+
return { kind: 'notes' }
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/** A failed run's reason. The server wrote it for the user, so it is shown as it is. */
|
|
460
|
+
function RunFailure({ reason }: { readonly reason: string }): React.JSX.Element {
|
|
461
|
+
return (
|
|
462
|
+
<div role="alert" className="mt-3 rounded-md border border-danger/40 bg-danger-soft px-4 py-3">
|
|
463
|
+
<p className="text-[13px] font-medium text-danger">{reason}</p>
|
|
464
|
+
</div>
|
|
465
|
+
)
|
|
466
|
+
}
|
|
467
|
+
|
|
128
468
|
function StepBar({ current }: { readonly current: number }): React.JSX.Element {
|
|
129
469
|
return (
|
|
130
470
|
<ol className="flex gap-4 border-b border-border px-4 py-2 text-[11px]">
|
|
@@ -146,12 +486,18 @@ function NotesStep({
|
|
|
146
486
|
onChange,
|
|
147
487
|
pending,
|
|
148
488
|
error,
|
|
489
|
+
notice,
|
|
490
|
+
failure,
|
|
149
491
|
onNext,
|
|
150
492
|
}: {
|
|
151
493
|
readonly text: string
|
|
152
494
|
readonly onChange: (value: string) => void
|
|
153
495
|
readonly pending: boolean
|
|
154
496
|
readonly error: Error | null
|
|
497
|
+
/** Why the run failed, as the server put it. */
|
|
498
|
+
readonly failure: string | null
|
|
499
|
+
/** A line above the notes, such as the result having gone. */
|
|
500
|
+
readonly notice: string | null
|
|
155
501
|
readonly onNext: () => void
|
|
156
502
|
}): React.JSX.Element {
|
|
157
503
|
const serviceLabel = useAiServiceLabel()
|
|
@@ -163,6 +509,11 @@ function NotesStep({
|
|
|
163
509
|
</button>
|
|
164
510
|
}
|
|
165
511
|
>
|
|
512
|
+
{notice !== null && (
|
|
513
|
+
<p role="status" className="mb-2 rounded-md border border-warning/40 bg-warning-soft px-3 py-2 text-[12px] text-ink">
|
|
514
|
+
{notice}
|
|
515
|
+
</p>
|
|
516
|
+
)}
|
|
166
517
|
<NotesField value={text} onChange={onChange} disabled={pending} />
|
|
167
518
|
{pending && (
|
|
168
519
|
<p className="mt-2 text-[12px] text-ink-muted">
|
|
@@ -174,6 +525,7 @@ function NotesStep({
|
|
|
174
525
|
<ErrorPanel error={error} />
|
|
175
526
|
</div>
|
|
176
527
|
)}
|
|
528
|
+
{failure !== null && <RunFailure reason={failure} />}
|
|
177
529
|
</IntakeFrame>
|
|
178
530
|
)
|
|
179
531
|
}
|
|
@@ -189,21 +541,29 @@ type Target = string
|
|
|
189
541
|
|
|
190
542
|
function ConfirmStep({
|
|
191
543
|
identified,
|
|
544
|
+
initialTarget,
|
|
192
545
|
pending,
|
|
193
546
|
error,
|
|
547
|
+
failure,
|
|
194
548
|
onBack,
|
|
195
549
|
onNext,
|
|
196
550
|
}: {
|
|
197
|
-
readonly identified:
|
|
551
|
+
readonly identified: Identified
|
|
552
|
+
/** The target a research run was started with, when the step is rebuilt after a reload. */
|
|
553
|
+
readonly initialTarget?: string | null | undefined
|
|
198
554
|
readonly pending: boolean
|
|
199
555
|
readonly error: Error | null
|
|
556
|
+
/** Why the research run failed, as the server put it. */
|
|
557
|
+
readonly failure: string | null
|
|
200
558
|
readonly onBack: () => void
|
|
201
559
|
readonly onNext: (candidate: PersonIntakeCandidate, existingPersonId: string | null) => void
|
|
202
560
|
}): React.JSX.Element {
|
|
203
561
|
const serviceLabel = useAiServiceLabel()
|
|
204
562
|
const first = identified.candidates[0]
|
|
205
563
|
const [candidateKey, setCandidateKey] = useState(first?.key ?? '')
|
|
206
|
-
const [target, setTarget] = useState<Target>(
|
|
564
|
+
const [target, setTarget] = useState<Target>(
|
|
565
|
+
initialTarget === undefined ? (first?.existingPeople[0]?.id ?? 'new') : (initialTarget ?? 'new'),
|
|
566
|
+
)
|
|
207
567
|
const candidate = identified.candidates.find((entry) => entry.key === candidateKey)
|
|
208
568
|
|
|
209
569
|
if (identified.candidates.length === 0) {
|
|
@@ -337,6 +697,7 @@ function ConfirmStep({
|
|
|
337
697
|
<ErrorPanel error={error} />
|
|
338
698
|
</div>
|
|
339
699
|
)}
|
|
700
|
+
{failure !== null && <RunFailure reason={failure} />}
|
|
340
701
|
</IntakeFrame>
|
|
341
702
|
)
|
|
342
703
|
}
|
|
@@ -469,7 +830,7 @@ function itemTitle(item: PersonIntakeItem, companyNames: ReadonlyMap<string, str
|
|
|
469
830
|
return item.title === '' ? `At ${company}` : `${item.title} at ${company}`
|
|
470
831
|
}
|
|
471
832
|
case 'note':
|
|
472
|
-
return '
|
|
833
|
+
return 'Research note'
|
|
473
834
|
}
|
|
474
835
|
}
|
|
475
836
|
|
package/src/modules/ai.tsx
CHANGED
|
@@ -9,7 +9,7 @@ import { PersonIntakeWizard } from './PersonIntakeWizard.tsx'
|
|
|
9
9
|
* Not registered by default. An assembly that lists `createAiModule()` on the
|
|
10
10
|
* server lists `aiUi` in `kelpie.ui.config.ts`, the same pairing any module
|
|
11
11
|
* uses. Two tabs on core's Admin → AI page, Settings and Run log, before
|
|
12
|
-
* core's
|
|
12
|
+
* core's Agents tab. On record pages it is the Agent menu's runner: Run dispatches straight to the "Kelpie AI" agent row, and
|
|
13
13
|
* stays disabled until AI is enabled and has a key. Preview's Run… still lists
|
|
14
14
|
* every registered agent, Kelpie AI included. On People it is the wizard behind
|
|
15
15
|
* Add from notes.
|
|
@@ -5,6 +5,8 @@ import { useNavigate } from 'react-router'
|
|
|
5
5
|
|
|
6
6
|
import { useTimezone } from '../api/resources/account.ts'
|
|
7
7
|
import { useCompanies, useCreateCompany } from '../api/resources/companies.ts'
|
|
8
|
+
import { AddRecordPanel } from '../components/AddRecordPanel.tsx'
|
|
9
|
+
import type { AddRecordValues } from '../components/AddRecordPanel.tsx'
|
|
8
10
|
import { Chip } from '../components/Chip.tsx'
|
|
9
11
|
import type { ChipTone } from '../components/Chip.tsx'
|
|
10
12
|
import { ColumnPicker } from '../components/ColumnPicker.tsx'
|
|
@@ -50,10 +52,14 @@ export function CompaniesPage(): React.JSX.Element {
|
|
|
50
52
|
const headcounts = useCompanyHeadcounts(companies.records.map((company) => company.id))
|
|
51
53
|
const createCompany = useCreateCompany()
|
|
52
54
|
|
|
53
|
-
|
|
54
|
-
const company = await createCompany.runAsync({ name: 'New company' })
|
|
55
|
+
const [adding, setAdding] = useState(false)
|
|
55
56
|
|
|
56
|
-
|
|
57
|
+
function addCompany(values: AddRecordValues): void {
|
|
58
|
+
createCompany
|
|
59
|
+
.runAsync({ name: values.name })
|
|
60
|
+
.then((record) => navigate(`/companies/${record.id}`))
|
|
61
|
+
// The failure is shown from `createCompany.error` below.
|
|
62
|
+
.catch(() => undefined)
|
|
57
63
|
}
|
|
58
64
|
|
|
59
65
|
const columns: readonly Column<Company>[] = [
|
|
@@ -195,7 +201,7 @@ export function CompaniesPage(): React.JSX.Element {
|
|
|
195
201
|
<PageHeader
|
|
196
202
|
title="Companies"
|
|
197
203
|
onAdd={() => {
|
|
198
|
-
|
|
204
|
+
setAdding(true)
|
|
199
205
|
}}
|
|
200
206
|
addLabel="Add company"
|
|
201
207
|
actions={
|
|
@@ -208,6 +214,17 @@ export function CompaniesPage(): React.JSX.Element {
|
|
|
208
214
|
/>
|
|
209
215
|
<FilterBar value={term} onChange={setTerm} placeholder="Filter by name, type, tags…" />
|
|
210
216
|
|
|
217
|
+
{adding && (
|
|
218
|
+
<AddRecordPanel
|
|
219
|
+
title="Add company"
|
|
220
|
+
isPending={createCompany.isPending}
|
|
221
|
+
onCancel={() => {
|
|
222
|
+
setAdding(false)
|
|
223
|
+
}}
|
|
224
|
+
onCreate={addCompany}
|
|
225
|
+
/>
|
|
226
|
+
)}
|
|
227
|
+
|
|
211
228
|
{createCompany.error !== null && (
|
|
212
229
|
<div className="mb-3">
|
|
213
230
|
<ErrorPanel error={createCompany.error} />
|
|
@@ -236,7 +253,7 @@ export function CompaniesPage(): React.JSX.Element {
|
|
|
236
253
|
: {
|
|
237
254
|
label: 'Add company',
|
|
238
255
|
onClick: () => {
|
|
239
|
-
|
|
256
|
+
setAdding(true)
|
|
240
257
|
},
|
|
241
258
|
}
|
|
242
259
|
}
|
|
@@ -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
|
-
<
|
|
367
|
-
value={company.tags
|
|
368
|
-
|
|
369
|
-
|
|
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>
|