@kelpie/ui 0.18.0 → 0.19.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/components/AiDrawer.d.ts +13 -0
- package/dist/components/AiDrawer.d.ts.map +1 -0
- package/dist/components/AiDrawer.js +165 -0
- package/dist/components/AiDrawer.js.map +1 -0
- package/dist/components/ApiKeysPanel.js +1 -1
- package/dist/components/DataTable.js +1 -1
- package/dist/components/KanbanBoard.d.ts +5 -1
- package/dist/components/KanbanBoard.d.ts.map +1 -1
- package/dist/components/KanbanBoard.js +37 -2
- package/dist/components/KanbanBoard.js.map +1 -1
- package/dist/components/NotesPanel.js +2 -2
- package/dist/components/NotesPanel.js.map +1 -1
- package/dist/components/PageHeader.js +1 -1
- package/dist/components/PageHeader.js.map +1 -1
- package/dist/components/PersonIntakePanel.d.ts +21 -0
- package/dist/components/PersonIntakePanel.d.ts.map +1 -0
- package/dist/components/PersonIntakePanel.js +76 -0
- package/dist/components/PersonIntakePanel.js.map +1 -0
- package/dist/components/SegmentedControl.js +2 -2
- package/dist/components/SegmentedControl.js.map +1 -1
- package/dist/components/Shell.d.ts.map +1 -1
- package/dist/components/Shell.js +39 -3
- package/dist/components/Shell.js.map +1 -1
- package/dist/components/WorkspaceSwitcher.d.ts.map +1 -1
- package/dist/components/WorkspaceSwitcher.js +10 -2
- package/dist/components/WorkspaceSwitcher.js.map +1 -1
- package/dist/components/aiDrawerState.d.ts +45 -0
- package/dist/components/aiDrawerState.d.ts.map +1 -0
- package/dist/components/aiDrawerState.js +14 -0
- package/dist/components/aiDrawerState.js.map +1 -0
- package/dist/components/personIntakeTask.d.ts +5 -0
- package/dist/components/personIntakeTask.d.ts.map +1 -0
- package/dist/components/personIntakeTask.js +13 -0
- package/dist/components/personIntakeTask.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/mediaQuery.d.ts +9 -0
- package/dist/lib/mediaQuery.d.ts.map +1 -0
- package/dist/lib/mediaQuery.js +24 -0
- package/dist/lib/mediaQuery.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 +9 -5
- package/dist/modules/PersonIntakeWizard.js.map +1 -1
- package/dist/pages/FormDetail.d.ts.map +1 -1
- package/dist/pages/FormDetail.js +7 -7
- package/dist/pages/FormDetail.js.map +1 -1
- package/dist/pages/ListDetail.d.ts.map +1 -1
- package/dist/pages/ListDetail.js +2 -2
- package/dist/pages/ListDetail.js.map +1 -1
- package/dist/pages/PeoplePage.d.ts.map +1 -1
- package/dist/pages/PeoplePage.js +8 -6
- package/dist/pages/PeoplePage.js.map +1 -1
- package/dist/pages/RoleDetail.d.ts.map +1 -1
- package/dist/pages/RoleDetail.js +3 -3
- package/dist/pages/RoleDetail.js.map +1 -1
- package/dist/pages/account/ConnectedAppsPage.js +1 -1
- package/dist/pages/admin/DataPage.js +2 -2
- package/dist/pages/forms/AddFieldMenu.js +2 -2
- package/dist/pages/forms/AddFieldMenu.js.map +1 -1
- package/dist/pages/handbook/HandbookPage.js +4 -4
- package/dist/pages/handbook/HandbookPage.js.map +1 -1
- package/dist/registry/contributions.d.ts +8 -3
- package/dist/registry/contributions.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/components/AiDrawer.tsx +272 -0
- package/src/components/ApiKeysPanel.tsx +1 -1
- package/src/components/DataTable.tsx +1 -1
- package/src/components/KanbanBoard.tsx +119 -2
- package/src/components/NotesPanel.tsx +7 -4
- package/src/components/PageHeader.tsx +1 -1
- package/src/components/{PersonIntakeDialog.tsx → PersonIntakePanel.tsx} +17 -50
- package/src/components/SegmentedControl.tsx +2 -2
- package/src/components/Shell.tsx +98 -12
- package/src/components/WorkspaceSwitcher.tsx +13 -2
- package/src/components/aiDrawerState.ts +61 -0
- package/src/components/personIntakeTask.tsx +14 -0
- package/src/index.ts +5 -0
- package/src/lib/mediaQuery.ts +32 -0
- package/src/modules/PersonIntakeWizard.tsx +10 -5
- package/src/pages/FormDetail.tsx +18 -14
- package/src/pages/ListDetail.tsx +5 -3
- package/src/pages/PeoplePage.tsx +7 -10
- package/src/pages/RoleDetail.tsx +10 -5
- package/src/pages/account/ConnectedAppsPage.tsx +1 -1
- package/src/pages/admin/DataPage.tsx +2 -2
- package/src/pages/forms/AddFieldMenu.tsx +2 -2
- package/src/pages/handbook/HandbookPage.tsx +5 -5
- package/src/registry/contributions.ts +8 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PERSON_INTAKE_MAX_TEXT } from '@kelpie/schemas'
|
|
2
|
-
import {
|
|
2
|
+
import { useState } from 'react'
|
|
3
3
|
import type { ReactNode } from 'react'
|
|
4
4
|
|
|
5
5
|
import { useResolveAgentTask } from '../api/resources/agentTasks.ts'
|
|
@@ -12,9 +12,10 @@ import { ErrorPanel, LoadingPanel } from './QueryState.tsx'
|
|
|
12
12
|
* People's **Add from notes**: a second way to add a person, from what the
|
|
13
13
|
* user already knows.
|
|
14
14
|
*
|
|
15
|
-
* Core owns the button and this
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* Core owns the button and this panel, which runs in the AI drawer so the page
|
|
16
|
+
* stays usable while the model works. When a module provides a wizard and it
|
|
17
|
+
* is ready (Kelpie AI enabled, with a key), the panel renders it. Without one,
|
|
18
|
+
* the panel still works: it builds the `workspace.add_person` prompt
|
|
18
19
|
* with the user's notes appended, for the user to paste into their own agent.
|
|
19
20
|
* That is the same pattern as the Log transcript task.
|
|
20
21
|
*/
|
|
@@ -37,55 +38,19 @@ export function AddFromNotesButton({ onClick }: { readonly onClick: () => void }
|
|
|
37
38
|
)
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
export interface
|
|
41
|
+
export interface PersonIntakePanelProps {
|
|
42
|
+
/** Ends the intake. */
|
|
41
43
|
readonly onClose: () => void
|
|
44
|
+
readonly onPendingChange: (pending: boolean) => void
|
|
42
45
|
}
|
|
43
46
|
|
|
44
|
-
export function
|
|
47
|
+
export function PersonIntakePanel({ onClose, onPendingChange }: PersonIntakePanelProps): React.JSX.Element {
|
|
45
48
|
const provider = usePersonIntakeProvider()
|
|
46
49
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
window.addEventListener('keydown', onKey)
|
|
52
|
-
return () => {
|
|
53
|
-
window.removeEventListener('keydown', onKey)
|
|
54
|
-
}
|
|
55
|
-
}, [onClose])
|
|
56
|
-
|
|
57
|
-
return (
|
|
58
|
-
<div
|
|
59
|
-
className="fixed inset-0 z-40 flex items-end justify-center bg-ink/30 p-4 sm:items-center"
|
|
60
|
-
role="dialog"
|
|
61
|
-
aria-modal="true"
|
|
62
|
-
aria-label="Add a person from notes"
|
|
63
|
-
onClick={onClose}
|
|
64
|
-
>
|
|
65
|
-
<div
|
|
66
|
-
className="flex max-h-[90vh] w-full max-w-2xl flex-col overflow-hidden rounded-lg border border-border bg-surface"
|
|
67
|
-
onClick={(event) => {
|
|
68
|
-
event.stopPropagation()
|
|
69
|
-
}}
|
|
70
|
-
>
|
|
71
|
-
<div className="flex items-start justify-between gap-3 border-b border-border px-4 py-3">
|
|
72
|
-
<div>
|
|
73
|
-
<div className="text-[14px] font-semibold text-ink">Add a person from notes</div>
|
|
74
|
-
<div className="mt-0.5 text-[12px] text-ink-muted">
|
|
75
|
-
Paste what you know. Kelpie builds the record from it.
|
|
76
|
-
</div>
|
|
77
|
-
</div>
|
|
78
|
-
<button type="button" className="text-[12px] font-medium text-ink-muted hover:text-ink" onClick={onClose}>
|
|
79
|
-
Close
|
|
80
|
-
</button>
|
|
81
|
-
</div>
|
|
82
|
-
{provider === undefined ? (
|
|
83
|
-
<CopyPromptIntake reason="The AI module is not part of this install." />
|
|
84
|
-
) : (
|
|
85
|
-
<ProvidedIntake provider={provider} onClose={onClose} />
|
|
86
|
-
)}
|
|
87
|
-
</div>
|
|
88
|
-
</div>
|
|
50
|
+
return provider === undefined ? (
|
|
51
|
+
<CopyPromptIntake reason="The AI module is not part of this install." />
|
|
52
|
+
) : (
|
|
53
|
+
<ProvidedIntake provider={provider} onClose={onClose} onPendingChange={onPendingChange} />
|
|
89
54
|
)
|
|
90
55
|
}
|
|
91
56
|
|
|
@@ -93,9 +58,11 @@ export function PersonIntakeDialog({ onClose }: PersonIntakeDialogProps): React.
|
|
|
93
58
|
function ProvidedIntake({
|
|
94
59
|
provider,
|
|
95
60
|
onClose,
|
|
61
|
+
onPendingChange,
|
|
96
62
|
}: {
|
|
97
63
|
readonly provider: PersonIntakeProvider
|
|
98
64
|
readonly onClose: () => void
|
|
65
|
+
readonly onPendingChange: (pending: boolean) => void
|
|
99
66
|
}): React.JSX.Element {
|
|
100
67
|
const availability: AgentRunnerAvailability = provider.useAvailability({ enabled: true })
|
|
101
68
|
|
|
@@ -109,10 +76,10 @@ function ProvidedIntake({
|
|
|
109
76
|
|
|
110
77
|
const Wizard = provider.Wizard
|
|
111
78
|
|
|
112
|
-
return <Wizard onClose={onClose} />
|
|
79
|
+
return <Wizard onClose={onClose} onPendingChange={onPendingChange} />
|
|
113
80
|
}
|
|
114
81
|
|
|
115
|
-
/** The
|
|
82
|
+
/** The panel body and footer, the same frame the wizard's steps use. */
|
|
116
83
|
export function IntakeFrame({
|
|
117
84
|
children,
|
|
118
85
|
footer,
|
|
@@ -21,7 +21,7 @@ export function SegmentedControl<T extends string>({
|
|
|
21
21
|
<div
|
|
22
22
|
role="group"
|
|
23
23
|
aria-label={ariaLabel}
|
|
24
|
-
className="inline-flex rounded-md border border-border bg-surface-raised p-0.5"
|
|
24
|
+
className="inline-flex max-w-full overflow-x-auto rounded-md border border-border bg-surface-raised p-0.5"
|
|
25
25
|
>
|
|
26
26
|
{options.map((option) => {
|
|
27
27
|
const selected = value === option.id
|
|
@@ -35,7 +35,7 @@ export function SegmentedControl<T extends string>({
|
|
|
35
35
|
onChange(option.id)
|
|
36
36
|
}}
|
|
37
37
|
className={[
|
|
38
|
-
'rounded px-2.5 py-1 text-[12px] font-medium transition-colors',
|
|
38
|
+
'shrink-0 whitespace-nowrap rounded px-2.5 py-1 text-[12px] font-medium transition-colors',
|
|
39
39
|
selected ? 'bg-accent-soft text-accent-hover' : 'text-ink-muted hover:text-ink',
|
|
40
40
|
].join(' ')}
|
|
41
41
|
>
|
package/src/components/Shell.tsx
CHANGED
|
@@ -9,6 +9,7 @@ import { ONBOARDING_RERUN_ENTRY } from '../pages/onboarding/onboardingRerun.ts'
|
|
|
9
9
|
import { useNavItems } from '../registry/context.ts'
|
|
10
10
|
import type { NavItem } from '../registry/contributions.ts'
|
|
11
11
|
import { useVisibleNavItems } from '../registry/visibleNav.ts'
|
|
12
|
+
import { AiDrawerLauncher, AiDrawerPanel, AiDrawerProvider } from './AiDrawer.tsx'
|
|
12
13
|
import { ErrorBoundary } from './ErrorBoundary.tsx'
|
|
13
14
|
import { WorkspaceSwitcher } from './WorkspaceSwitcher.tsx'
|
|
14
15
|
|
|
@@ -90,6 +91,16 @@ const THEME_LABELS: Readonly<Record<ThemePreference, string>> = {
|
|
|
90
91
|
}
|
|
91
92
|
|
|
92
93
|
export function Shell(): React.JSX.Element {
|
|
94
|
+
// The drawer's state sits here, above the routed outlet, so an AI task
|
|
95
|
+
// survives a route change.
|
|
96
|
+
return (
|
|
97
|
+
<AiDrawerProvider>
|
|
98
|
+
<ShellLayout />
|
|
99
|
+
</AiDrawerProvider>
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function ShellLayout(): React.JSX.Element {
|
|
93
104
|
const navigate = useNavigate()
|
|
94
105
|
const location = useLocation()
|
|
95
106
|
const { account } = useAccount()
|
|
@@ -97,6 +108,9 @@ export function Shell(): React.JSX.Element {
|
|
|
97
108
|
const moduleNav = useNavItems('primary')
|
|
98
109
|
const moduleAdminNav = useNavItems('admin')
|
|
99
110
|
const [menuOpen, setMenuOpen] = useState(false)
|
|
111
|
+
// Below `md` the sidebar is an off-canvas drawer; from `md` up it is always
|
|
112
|
+
// shown and this flag has no effect.
|
|
113
|
+
const [navOpen, setNavOpen] = useState(false)
|
|
100
114
|
// The same preference the account page writes, so this button and that page
|
|
101
115
|
// cannot disagree about which theme the account is on.
|
|
102
116
|
const { theme, setTheme } = useTheme()
|
|
@@ -129,6 +143,24 @@ export function Shell(): React.JSX.Element {
|
|
|
129
143
|
}
|
|
130
144
|
}, [menuOpen])
|
|
131
145
|
|
|
146
|
+
useEffect(() => {
|
|
147
|
+
if (!navOpen) {
|
|
148
|
+
return
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function onKeyDown(event: KeyboardEvent): void {
|
|
152
|
+
if (event.key === 'Escape') {
|
|
153
|
+
setNavOpen(false)
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
document.addEventListener('keydown', onKeyDown)
|
|
158
|
+
|
|
159
|
+
return () => {
|
|
160
|
+
document.removeEventListener('keydown', onKeyDown)
|
|
161
|
+
}
|
|
162
|
+
}, [navOpen])
|
|
163
|
+
|
|
132
164
|
const navItems = useVisibleNavItems(CORE_NAV, moduleNav)
|
|
133
165
|
const topLevelItems = navItems.filter((item) => TOP_LEVEL_NAV_IDS.has(item.id))
|
|
134
166
|
const nonTopLevelItems = navItems.filter((item) => !TOP_LEVEL_NAV_IDS.has(item.id))
|
|
@@ -142,16 +174,50 @@ export function Shell(): React.JSX.Element {
|
|
|
142
174
|
|
|
143
175
|
return (
|
|
144
176
|
<div className="flex min-h-screen bg-surface">
|
|
145
|
-
|
|
146
|
-
<div
|
|
177
|
+
{navOpen && (
|
|
178
|
+
<div
|
|
179
|
+
aria-hidden
|
|
180
|
+
className="fixed inset-0 z-40 bg-black/40 md:hidden"
|
|
181
|
+
onClick={() => {
|
|
182
|
+
setNavOpen(false)
|
|
183
|
+
}}
|
|
184
|
+
/>
|
|
185
|
+
)}
|
|
186
|
+
<aside
|
|
187
|
+
id="shell-nav"
|
|
188
|
+
className={[
|
|
189
|
+
'fixed inset-y-0 left-0 z-40 flex w-[240px] shrink-0 flex-col border-r border-sidebar-border bg-sidebar transition-transform duration-150 md:static md:w-[200px] md:translate-x-0',
|
|
190
|
+
navOpen ? 'translate-x-0' : '-translate-x-full',
|
|
191
|
+
].join(' ')}
|
|
192
|
+
>
|
|
193
|
+
<div className="flex items-center justify-between px-3 py-4">
|
|
147
194
|
<NavLink to="/dashboard" className="group block px-2">
|
|
148
195
|
<div className="text-[15px] font-semibold tracking-tight text-sidebar-ink transition-opacity group-hover:opacity-80">
|
|
149
196
|
Kelpie
|
|
150
197
|
</div>
|
|
151
198
|
</NavLink>
|
|
199
|
+
<button
|
|
200
|
+
type="button"
|
|
201
|
+
aria-label="Close navigation"
|
|
202
|
+
onClick={() => {
|
|
203
|
+
setNavOpen(false)
|
|
204
|
+
}}
|
|
205
|
+
className="rounded-md px-2 py-1 text-[12px] text-sidebar-muted transition hover:bg-sidebar-hover hover:text-sidebar-ink md:hidden"
|
|
206
|
+
>
|
|
207
|
+
Close
|
|
208
|
+
</button>
|
|
152
209
|
</div>
|
|
153
210
|
|
|
154
|
-
|
|
211
|
+
{/* A tap on any link closes the drawer, including a tap on the link
|
|
212
|
+
for the page already open, which does not change the route. */}
|
|
213
|
+
<nav
|
|
214
|
+
className="flex flex-1 flex-col gap-5 overflow-y-auto px-2 pb-4"
|
|
215
|
+
onClick={(event) => {
|
|
216
|
+
if (event.target instanceof Element && event.target.closest('a') !== null) {
|
|
217
|
+
setNavOpen(false)
|
|
218
|
+
}
|
|
219
|
+
}}
|
|
220
|
+
>
|
|
155
221
|
{inAdminNav ? (
|
|
156
222
|
<>
|
|
157
223
|
<Link
|
|
@@ -229,9 +295,23 @@ export function Shell(): React.JSX.Element {
|
|
|
229
295
|
</aside>
|
|
230
296
|
|
|
231
297
|
<div className="flex min-w-0 flex-1 flex-col">
|
|
232
|
-
<header className="flex h-11 items-center gap-
|
|
298
|
+
<header className="flex h-11 items-center gap-2 border-b border-border px-3 sm:gap-3 md:px-5">
|
|
299
|
+
<button
|
|
300
|
+
type="button"
|
|
301
|
+
aria-label="Open navigation"
|
|
302
|
+
aria-controls="shell-nav"
|
|
303
|
+
aria-expanded={navOpen}
|
|
304
|
+
onClick={() => {
|
|
305
|
+
setNavOpen(true)
|
|
306
|
+
}}
|
|
307
|
+
className="flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-ink-muted transition hover:bg-surface-sunken hover:text-ink md:hidden"
|
|
308
|
+
>
|
|
309
|
+
<svg viewBox="0 0 16 16" aria-hidden className="h-4 w-4">
|
|
310
|
+
<path d="M2 4h12M2 8h12M2 12h12" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
|
|
311
|
+
</svg>
|
|
312
|
+
</button>
|
|
233
313
|
<form
|
|
234
|
-
className="flex-1"
|
|
314
|
+
className="min-w-0 flex-1"
|
|
235
315
|
onSubmit={(event) => {
|
|
236
316
|
event.preventDefault()
|
|
237
317
|
const term = query.trim()
|
|
@@ -253,6 +333,7 @@ export function Shell(): React.JSX.Element {
|
|
|
253
333
|
className="w-full max-w-sm rounded-md border border-transparent bg-surface-sunken px-2.5 py-1 text-[13px] text-ink outline-none transition placeholder:text-ink-faint focus:border-border focus:bg-surface-raised"
|
|
254
334
|
/>
|
|
255
335
|
</form>
|
|
336
|
+
<AiDrawerLauncher />
|
|
256
337
|
<button
|
|
257
338
|
type="button"
|
|
258
339
|
onClick={() => {
|
|
@@ -343,13 +424,18 @@ export function Shell(): React.JSX.Element {
|
|
|
343
424
|
</div>
|
|
344
425
|
</header>
|
|
345
426
|
|
|
346
|
-
<
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
<
|
|
351
|
-
|
|
352
|
-
|
|
427
|
+
<div className="flex min-h-0 flex-1">
|
|
428
|
+
<main className="min-w-0 flex-1 overflow-auto px-4 py-5 md:px-5">
|
|
429
|
+
{/* Keyed on the path so navigating away from a crashed page remounts
|
|
430
|
+
the boundary instead of leaving it stuck showing the old error. */}
|
|
431
|
+
<ErrorBoundary key={location.pathname}>
|
|
432
|
+
<Outlet />
|
|
433
|
+
</ErrorBoundary>
|
|
434
|
+
</main>
|
|
435
|
+
{/* Outside the route boundary, so a page that throws does not take a
|
|
436
|
+
running AI task with it. */}
|
|
437
|
+
<AiDrawerPanel />
|
|
438
|
+
</div>
|
|
353
439
|
</div>
|
|
354
440
|
</div>
|
|
355
441
|
)
|
|
@@ -3,6 +3,7 @@ import { useNavigate } from 'react-router'
|
|
|
3
3
|
|
|
4
4
|
import { useAccountWorkspaces, useSession, useSwitchWorkspace } from '../api/resources/session.ts'
|
|
5
5
|
import { ONBOARDING_NEW_WORKSPACE_ENTRY } from '../pages/onboarding/onboardingRerun.ts'
|
|
6
|
+
import { useAiDrawer } from './aiDrawerState.ts'
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Header control: the workspace this session is in, and a menu to move it.
|
|
@@ -17,6 +18,7 @@ export function WorkspaceSwitcher(): React.JSX.Element | null {
|
|
|
17
18
|
const { session } = useSession()
|
|
18
19
|
const { workspaces, isLoading } = useAccountWorkspaces()
|
|
19
20
|
const switchWorkspace = useSwitchWorkspace()
|
|
21
|
+
const aiDrawer = useAiDrawer()
|
|
20
22
|
const [open, setOpen] = useState(false)
|
|
21
23
|
const menuRef = useRef<HTMLDivElement>(null)
|
|
22
24
|
const currentId = session?.workspaceId ?? null
|
|
@@ -50,7 +52,7 @@ export function WorkspaceSwitcher(): React.JSX.Element | null {
|
|
|
50
52
|
|
|
51
53
|
if (isLoading && workspaces.length === 0) {
|
|
52
54
|
return (
|
|
53
|
-
<span className="max-w-[
|
|
55
|
+
<span className="max-w-[8rem] truncate px-2 py-1 sm:max-w-[10rem] text-[12px] text-ink-faint" aria-hidden>
|
|
54
56
|
Workspace
|
|
55
57
|
</span>
|
|
56
58
|
)
|
|
@@ -73,7 +75,7 @@ export function WorkspaceSwitcher(): React.JSX.Element | null {
|
|
|
73
75
|
aria-haspopup="menu"
|
|
74
76
|
aria-label="Switch workspace"
|
|
75
77
|
title={label}
|
|
76
|
-
className="inline-flex max-w-[
|
|
78
|
+
className="inline-flex max-w-[8rem] items-center gap-1 rounded-md sm:max-w-[12rem] px-2 py-1 text-[12px] text-ink-muted transition hover:bg-surface-sunken hover:text-ink"
|
|
77
79
|
>
|
|
78
80
|
<span className="truncate">{label}</span>
|
|
79
81
|
<svg viewBox="0 0 12 12" aria-hidden className="h-2.5 w-2.5 shrink-0">
|
|
@@ -108,10 +110,19 @@ export function WorkspaceSwitcher(): React.JSX.Element | null {
|
|
|
108
110
|
return
|
|
109
111
|
}
|
|
110
112
|
|
|
113
|
+
// An AI task belongs to one workspace, so the switch discards it.
|
|
114
|
+
if (
|
|
115
|
+
aiDrawer.isPending &&
|
|
116
|
+
!window.confirm('AI is still working on a task. Switching workspace discards it. Switch anyway?')
|
|
117
|
+
) {
|
|
118
|
+
return
|
|
119
|
+
}
|
|
120
|
+
|
|
111
121
|
switchWorkspace
|
|
112
122
|
.runAsync({ workspaceId: workspace.id })
|
|
113
123
|
.then(() => {
|
|
114
124
|
setOpen(false)
|
|
125
|
+
aiDrawer.finish()
|
|
115
126
|
void navigate('/dashboard', { replace: true })
|
|
116
127
|
})
|
|
117
128
|
.catch(() => undefined)
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react'
|
|
2
|
+
import type { ReactNode } from 'react'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The AI drawer's contract and hook, apart from its components so the
|
|
6
|
+
* component file keeps fast refresh (the same split as `registry/context.ts`).
|
|
7
|
+
* The drawer itself is `AiDrawer.tsx`.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** What a task may do to the drawer it sits in. */
|
|
11
|
+
export interface AiDrawerControls {
|
|
12
|
+
/** Hides the drawer. The task stays mounted. */
|
|
13
|
+
readonly close: () => void
|
|
14
|
+
/** Ends the task and unmounts it. */
|
|
15
|
+
readonly finish: () => void
|
|
16
|
+
/** Tells the header button to show the pending spinner. */
|
|
17
|
+
readonly setPending: (pending: boolean) => void
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** The content of the drawer. One is active at a time. */
|
|
21
|
+
export interface AiDrawerTask {
|
|
22
|
+
readonly id: string
|
|
23
|
+
readonly title: string
|
|
24
|
+
/** A line under the title. */
|
|
25
|
+
readonly description?: string
|
|
26
|
+
readonly render: (controls: AiDrawerControls) => ReactNode
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface AiDrawerState {
|
|
30
|
+
readonly activeTask: AiDrawerTask | undefined
|
|
31
|
+
readonly isOpen: boolean
|
|
32
|
+
readonly isPending: boolean
|
|
33
|
+
/**
|
|
34
|
+
* Opens the drawer on `task`. When another task is active, opens on that
|
|
35
|
+
* one instead, says so, and returns `false`. Nothing is replaced silently.
|
|
36
|
+
*/
|
|
37
|
+
readonly open: (task: AiDrawerTask) => boolean
|
|
38
|
+
/** Shows the active task again. */
|
|
39
|
+
readonly reopen: () => void
|
|
40
|
+
readonly close: () => void
|
|
41
|
+
/** Ends the active task. */
|
|
42
|
+
readonly finish: () => void
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const AiDrawerContext = createContext<AiDrawerState | undefined>(undefined)
|
|
46
|
+
|
|
47
|
+
export function useAiDrawer(): AiDrawerState {
|
|
48
|
+
const state = useContext(AiDrawerContext)
|
|
49
|
+
|
|
50
|
+
if (state === undefined) {
|
|
51
|
+
throw new Error('useAiDrawer needs an AiDrawerProvider above it. Shell provides one.')
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return state
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Whether the drawer says that a new task has to wait for the active one. */
|
|
58
|
+
export const AiDrawerBusyNoticeContext = createContext(false)
|
|
59
|
+
|
|
60
|
+
/** The active task's pending setter, handed to it through its controls. */
|
|
61
|
+
export const AiDrawerPendingContext = createContext<(pending: boolean) => void>(() => undefined)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AiDrawerTask } from './aiDrawerState.ts'
|
|
2
|
+
import { PersonIntakePanel } from './PersonIntakePanel.tsx'
|
|
3
|
+
|
|
4
|
+
export const PERSON_INTAKE_TASK_ID = 'person-intake'
|
|
5
|
+
|
|
6
|
+
/** The AI drawer task People's **Add from notes** opens. */
|
|
7
|
+
export function personIntakeTask(): AiDrawerTask {
|
|
8
|
+
return {
|
|
9
|
+
id: PERSON_INTAKE_TASK_ID,
|
|
10
|
+
title: 'Add a person from notes',
|
|
11
|
+
description: 'Paste what you know. Kelpie builds the record from it.',
|
|
12
|
+
render: (controls) => <PersonIntakePanel onClose={controls.finish} onPendingChange={controls.setPending} />,
|
|
13
|
+
}
|
|
14
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -248,6 +248,11 @@ export {
|
|
|
248
248
|
} from './registry/context.ts'
|
|
249
249
|
|
|
250
250
|
export { UiExtensionProvider } from './registry/UiExtensionProvider.tsx'
|
|
251
|
+
|
|
252
|
+
// The side drawer AI work runs in. Shell provides it; a module or page opens a
|
|
253
|
+
// task in it with `useAiDrawer().open(task)`.
|
|
254
|
+
export { useAiDrawer } from './components/aiDrawerState.ts'
|
|
255
|
+
export type { AiDrawerControls, AiDrawerState, AiDrawerTask } from './components/aiDrawerState.ts'
|
|
251
256
|
export type { UiExtensionProviderProps } from './registry/UiExtensionProvider.tsx'
|
|
252
257
|
|
|
253
258
|
// The optional `ai` module's UI. An assembly that lists `createAiModule()` on
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useSyncExternalStore } from 'react'
|
|
2
|
+
|
|
3
|
+
/** Tailwind's `md` breakpoint, as a query that matches below it. */
|
|
4
|
+
export const BELOW_MD_QUERY = '(max-width: 767.98px)'
|
|
5
|
+
|
|
6
|
+
function hasMatchMedia(): boolean {
|
|
7
|
+
return typeof window !== 'undefined' && typeof window.matchMedia === 'function'
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Whether `query` matches now, updated when it starts or stops matching. For
|
|
12
|
+
* a layout that cannot be done with CSS alone, such as rendering a different
|
|
13
|
+
* component tree. Without `matchMedia` (jsdom, server rendering) it is false.
|
|
14
|
+
*/
|
|
15
|
+
export function useMediaQuery(query: string): boolean {
|
|
16
|
+
return useSyncExternalStore(
|
|
17
|
+
(onChange: () => void): (() => void) => {
|
|
18
|
+
if (!hasMatchMedia()) {
|
|
19
|
+
return () => undefined
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const list = window.matchMedia(query)
|
|
23
|
+
list.addEventListener('change', onChange)
|
|
24
|
+
|
|
25
|
+
return () => {
|
|
26
|
+
list.removeEventListener('change', onChange)
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
(): boolean => hasMatchMedia() && window.matchMedia(query).matches,
|
|
30
|
+
(): boolean => false,
|
|
31
|
+
)
|
|
32
|
+
}
|
|
@@ -14,14 +14,14 @@ import type {
|
|
|
14
14
|
PersonIntakeResultStatus,
|
|
15
15
|
PersonIntakeSource,
|
|
16
16
|
} from '@kelpie/schemas'
|
|
17
|
-
import { useState } from 'react'
|
|
17
|
+
import { useEffect, useState } from 'react'
|
|
18
18
|
import { Link } from 'react-router'
|
|
19
19
|
|
|
20
20
|
import { useAiServiceLabel } from '../api/resources/ai.ts'
|
|
21
21
|
import { useApplyPersonIntake, useIdentifyPerson, useResearchPerson } from '../api/resources/personIntake.ts'
|
|
22
22
|
import { Chip } from '../components/Chip.tsx'
|
|
23
23
|
import type { ChipTone } from '../components/Chip.tsx'
|
|
24
|
-
import { IntakeFrame, NotesField } from '../components/
|
|
24
|
+
import { IntakeFrame, NotesField } from '../components/PersonIntakePanel.tsx'
|
|
25
25
|
import { ErrorPanel } from '../components/QueryState.tsx'
|
|
26
26
|
import type { PersonIntakeWizardProps } from '../registry/contributions.ts'
|
|
27
27
|
import { effectiveSelection } from './personIntakeSelection.ts'
|
|
@@ -53,12 +53,17 @@ const primaryButton =
|
|
|
53
53
|
const secondaryButton =
|
|
54
54
|
'rounded-md px-2.5 py-1.5 text-[12px] font-medium text-ink-muted hover:text-ink disabled:opacity-50'
|
|
55
55
|
|
|
56
|
-
export function PersonIntakeWizard({ onClose }: PersonIntakeWizardProps): React.JSX.Element {
|
|
56
|
+
export function PersonIntakeWizard({ onClose, onPendingChange }: PersonIntakeWizardProps): React.JSX.Element {
|
|
57
57
|
const [step, setStep] = useState<Step>({ kind: 'notes' })
|
|
58
58
|
const [text, setText] = useState('')
|
|
59
59
|
const identify = useIdentifyPerson()
|
|
60
60
|
const research = useResearchPerson()
|
|
61
61
|
const apply = useApplyPersonIntake()
|
|
62
|
+
const pending = identify.isPending || research.isPending || apply.isPending
|
|
63
|
+
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
onPendingChange?.(pending)
|
|
66
|
+
}, [pending, onPendingChange])
|
|
62
67
|
|
|
63
68
|
async function runIdentify(): Promise<void> {
|
|
64
69
|
const identified = await identify.runAsync(text.trim())
|
|
@@ -161,7 +166,7 @@ function NotesStep({
|
|
|
161
166
|
<NotesField value={text} onChange={onChange} disabled={pending} />
|
|
162
167
|
{pending && (
|
|
163
168
|
<p className="mt-2 text-[12px] text-ink-muted">
|
|
164
|
-
{serviceLabel} is looking this person up. With web search on, this can take a minute.
|
|
169
|
+
{serviceLabel} is looking this person up. With web search on, this can take a minute. You can keep working: this task stays open in the drawer.
|
|
165
170
|
</p>
|
|
166
171
|
)}
|
|
167
172
|
{error !== null && (
|
|
@@ -323,7 +328,7 @@ function ConfirmStep({
|
|
|
323
328
|
</fieldset>
|
|
324
329
|
{pending && (
|
|
325
330
|
<p className="mt-3 text-[12px] text-ink-muted">
|
|
326
|
-
{serviceLabel} is researching this person. With web search on, this can take a minute.
|
|
331
|
+
{serviceLabel} is researching this person. With web search on, this can take a minute. You can keep working: this task stays open in the drawer.
|
|
327
332
|
</p>
|
|
328
333
|
)}
|
|
329
334
|
<Sources sources={identified.sources} />
|
package/src/pages/FormDetail.tsx
CHANGED
|
@@ -53,20 +53,24 @@ export function FormDetail(): React.JSX.Element {
|
|
|
53
53
|
← Forms
|
|
54
54
|
</Link>
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
{/* On a phone the controls go under the heading, so a long title keeps
|
|
57
|
+
the full width and does not break over several lines. */}
|
|
58
|
+
<div className="mb-6 flex flex-col gap-3 sm:flex-row sm:flex-wrap sm:items-start sm:justify-between">
|
|
57
59
|
<FormHeading form={record} />
|
|
58
|
-
<
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
60
|
+
<div className="flex flex-wrap items-center gap-3">
|
|
61
|
+
<DeleteRecord
|
|
62
|
+
recordLabel="Form"
|
|
63
|
+
recordName={record.name}
|
|
64
|
+
isPending={deleteForm.isPending}
|
|
65
|
+
error={deleteForm.error}
|
|
66
|
+
onConfirm={() => {
|
|
67
|
+
deleteForm
|
|
68
|
+
.runAsync(record.id)
|
|
69
|
+
.then(() => navigate('/forms'))
|
|
70
|
+
.catch(() => undefined)
|
|
71
|
+
}}
|
|
72
|
+
/>
|
|
73
|
+
</div>
|
|
70
74
|
</div>
|
|
71
75
|
|
|
72
76
|
<RecordTabs
|
|
@@ -118,7 +122,7 @@ function FormHeading({ form }: { readonly form: Form }): React.JSX.Element {
|
|
|
118
122
|
}
|
|
119
123
|
|
|
120
124
|
return (
|
|
121
|
-
<div className="min-w-
|
|
125
|
+
<div className="min-w-[12rem] flex-1">
|
|
122
126
|
<div className="flex flex-wrap items-center gap-2">
|
|
123
127
|
<div className="min-w-0 flex-1">
|
|
124
128
|
<InlineEdit
|
package/src/pages/ListDetail.tsx
CHANGED
|
@@ -65,9 +65,11 @@ export function ListDetail(): React.JSX.Element {
|
|
|
65
65
|
← Lists
|
|
66
66
|
</Link>
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
{/* On a phone the controls go under the heading, so a long title keeps
|
|
69
|
+
the full width and does not break over several lines. */}
|
|
70
|
+
<div className="mb-6 flex flex-col gap-3 sm:flex-row sm:flex-wrap sm:items-start sm:justify-between">
|
|
69
71
|
<ListHeading list={record} />
|
|
70
|
-
<div className="flex
|
|
72
|
+
<div className="flex flex-wrap items-center gap-3">
|
|
71
73
|
<Chip>{RECORD_TARGET_TYPE_LABELS[record.targetType]}</Chip>
|
|
72
74
|
<DeleteRecord
|
|
73
75
|
recordLabel="List"
|
|
@@ -99,7 +101,7 @@ function ListHeading({ list }: { readonly list: List }): React.JSX.Element {
|
|
|
99
101
|
const { patch, error } = useListPatch(list)
|
|
100
102
|
|
|
101
103
|
return (
|
|
102
|
-
<div className="min-w-
|
|
104
|
+
<div className="min-w-[12rem] flex-1">
|
|
103
105
|
{error !== null && (
|
|
104
106
|
<div className="mb-2">
|
|
105
107
|
<ErrorPanel error={error} />
|
package/src/pages/PeoplePage.tsx
CHANGED
|
@@ -5,11 +5,13 @@ import { useNavigate } from 'react-router'
|
|
|
5
5
|
|
|
6
6
|
import { useTimezone } from '../api/resources/account.ts'
|
|
7
7
|
import { useCreatePerson, usePeople } from '../api/resources/people.ts'
|
|
8
|
+
import { useAiDrawer } from '../components/aiDrawerState.ts'
|
|
8
9
|
import { Chip } from '../components/Chip.tsx'
|
|
9
10
|
import { SocialNetworkIcon } from '../components/SocialNetworkIcon.tsx'
|
|
10
11
|
import { ColumnPicker } from '../components/ColumnPicker.tsx'
|
|
11
12
|
import { DataTable } from '../components/DataTable.tsx'
|
|
12
|
-
import { AddFromNotesButton
|
|
13
|
+
import { AddFromNotesButton } from '../components/PersonIntakePanel.tsx'
|
|
14
|
+
import { personIntakeTask } from '../components/personIntakeTask.tsx'
|
|
13
15
|
import type { Column } from '../components/DataTable.tsx'
|
|
14
16
|
import { FilterBar, PageHeader } from '../components/PageHeader.tsx'
|
|
15
17
|
import { Paginator } from '../components/Paginator.tsx'
|
|
@@ -60,7 +62,7 @@ export function PeoplePage(): React.JSX.Element {
|
|
|
60
62
|
})
|
|
61
63
|
const directory = usePeopleDirectory(people.records.map((person) => person.id))
|
|
62
64
|
const createPerson = useCreatePerson()
|
|
63
|
-
const
|
|
65
|
+
const aiDrawer = useAiDrawer()
|
|
64
66
|
|
|
65
67
|
async function addPerson(): Promise<void> {
|
|
66
68
|
// The same defaults the API applies, so a person created here and one
|
|
@@ -196,6 +198,8 @@ export function PeoplePage(): React.JSX.Element {
|
|
|
196
198
|
{
|
|
197
199
|
key: 'tags',
|
|
198
200
|
header: 'Tags',
|
|
201
|
+
// On a phone the tag chips wrap one per line and make every row tall.
|
|
202
|
+
className: 'hidden md:table-cell',
|
|
199
203
|
getSortValue: (person) => person.tags.join(', ') || null,
|
|
200
204
|
render: (person) =>
|
|
201
205
|
person.tags.length > 0 ? (
|
|
@@ -252,19 +256,12 @@ export function PeoplePage(): React.JSX.Element {
|
|
|
252
256
|
/>
|
|
253
257
|
<AddFromNotesButton
|
|
254
258
|
onClick={() => {
|
|
255
|
-
|
|
259
|
+
aiDrawer.open(personIntakeTask())
|
|
256
260
|
}}
|
|
257
261
|
/>
|
|
258
262
|
</>
|
|
259
263
|
}
|
|
260
264
|
/>
|
|
261
|
-
{intakeOpen && (
|
|
262
|
-
<PersonIntakeDialog
|
|
263
|
-
onClose={() => {
|
|
264
|
-
setIntakeOpen(false)
|
|
265
|
-
}}
|
|
266
|
-
/>
|
|
267
|
-
)}
|
|
268
265
|
<FilterBar
|
|
269
266
|
value={term}
|
|
270
267
|
onChange={setTerm}
|