@sixb/app 0.2.6 → 0.2.7

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 (57) hide show
  1. package/dist/agent/components/sandbox-recovery.d.ts +8 -2
  2. package/dist/agent/components/sandbox-recovery.d.ts.map +1 -1
  3. package/dist/agent/delegation/use-children.d.ts +5 -5
  4. package/dist/agent/delegation/use-children.d.ts.map +1 -1
  5. package/dist/agent/hooks/thread-queries.d.ts +8 -8
  6. package/dist/agent/hooks/thread-queries.d.ts.map +1 -1
  7. package/dist/agent/hooks/use-agent-conversation.d.ts.map +1 -1
  8. package/dist/agent/hooks/use-thread-lists.d.ts.map +1 -1
  9. package/dist/agent/i18n/en.d.ts +5 -0
  10. package/dist/agent/i18n/en.d.ts.map +1 -1
  11. package/dist/agent/i18n/fr.d.ts.map +1 -1
  12. package/dist/agent/i18n/index.d.ts +10 -0
  13. package/dist/agent/i18n/index.d.ts.map +1 -1
  14. package/dist/artifacts/queries.d.ts.map +1 -1
  15. package/dist/artifacts/renderers/live-frame.d.ts.map +1 -1
  16. package/dist/{chunk-ezntd3yy.js → chunk-1f4h75n3.js} +1 -1
  17. package/dist/{chunk-qjw5r2vk.js → chunk-7v9622qb.js} +25 -11
  18. package/dist/{chunk-qjw5r2vk.js.map → chunk-7v9622qb.js.map} +6 -6
  19. package/dist/{chunk-096d52h2.js → chunk-dntecmwb.js} +1 -1
  20. package/dist/{chunk-94d7enwc.js → chunk-qmka6aea.js} +1 -1
  21. package/dist/index.js +1 -1
  22. package/dist/pages/console/data/accounts.d.ts.map +1 -1
  23. package/dist/pages/console/data/connectors.d.ts.map +1 -1
  24. package/dist/pages/console/data/datasets.d.ts.map +1 -1
  25. package/dist/pages/console/data/pipelines.d.ts.map +1 -1
  26. package/dist/pages/console/data/projections.d.ts.map +1 -1
  27. package/dist/pages/console/data/syncs.d.ts.map +1 -1
  28. package/dist/pages/console/ontology/actions.d.ts.map +1 -1
  29. package/dist/pages/console/ontology/object-type.d.ts.map +1 -1
  30. package/dist/pages/console/ontology/object-types.d.ts.map +1 -1
  31. package/dist/pages/console/ontology/rules.d.ts.map +1 -1
  32. package/dist/pages/console/ontology/workflow.d.ts.map +1 -1
  33. package/dist/pages/console/ontology/workflows.d.ts.map +1 -1
  34. package/dist/pages/folders.d.ts +106 -0
  35. package/dist/pages/folders.d.ts.map +1 -0
  36. package/dist/pages.js +5234 -4904
  37. package/dist/pages.js.map +15 -14
  38. package/package.json +3 -3
  39. package/src/agent/components/sandbox-recovery.tsx +24 -6
  40. package/src/agent/hooks/use-agent-conversation.ts +7 -0
  41. package/src/agent/i18n/en.ts +6 -0
  42. package/src/agent/i18n/fr.ts +6 -0
  43. package/src/pages/console/data/connectors.tsx +60 -49
  44. package/src/pages/console/data/datasets.tsx +79 -68
  45. package/src/pages/console/data/pipelines.tsx +80 -69
  46. package/src/pages/console/data/projections.tsx +111 -82
  47. package/src/pages/console/data/syncs.tsx +62 -52
  48. package/src/pages/console/ontology/actions.tsx +51 -24
  49. package/src/pages/console/ontology/object-type.tsx +5 -1
  50. package/src/pages/console/ontology/object-types.tsx +41 -32
  51. package/src/pages/console/ontology/rules.tsx +48 -38
  52. package/src/pages/console/ontology/workflow.tsx +9 -3
  53. package/src/pages/console/ontology/workflows.tsx +55 -67
  54. package/src/pages/folders.tsx +335 -0
  55. /package/dist/{chunk-ezntd3yy.js.map → chunk-1f4h75n3.js.map} +0 -0
  56. /package/dist/{chunk-096d52h2.js.map → chunk-dntecmwb.js.map} +0 -0
  57. /package/dist/{chunk-94d7enwc.js.map → chunk-qmka6aea.js.map} +0 -0
@@ -0,0 +1,335 @@
1
+ /**
2
+ * Browsing a list of definitions by the folders they sit in: `datasets/raw/erp/orders.ts` puts
3
+ * `orders` in the folder `raw/erp`. A list page shows its top level with a tile for each folder,
4
+ * and opening one becomes the page itself, titled by the folder with a way back up, the way a
5
+ * detail page is. Searching looks through every folder at once and groups what it finds by
6
+ * folder. A project without folders sees its lists exactly as before.
7
+ *
8
+ * The open folder lives in the URL (`?folder=raw/erp`), so the browser's back button, reloads and
9
+ * shared links all keep it.
10
+ */
11
+ import { defineMessages, type MessageTree, plural, type Translation } from "@sixb/ui/lib/i18n"
12
+ import { cn } from "@sixb/ui/lib/utils"
13
+ import { type ReactNode, useMemo } from "react"
14
+ import { Link, useLocation, useSearchParams } from "react-router-dom"
15
+
16
+ export const en = {
17
+ items: (count: number) => plural("en", count, { one: "1 item", other: `${count} items` }),
18
+ } satisfies MessageTree
19
+
20
+ export const fr: Translation<typeof en> = {
21
+ items: (count: number) => plural("fr", count, { one: "1 élément", other: `${count} éléments` }),
22
+ }
23
+
24
+ const useFolderMessages = defineMessages<typeof en>({ en, fr }).useMessages
25
+
26
+ const FOLDER_PARAM = "folder"
27
+
28
+ /** A definition as the API lists it: in a folder below its directory, or at its top. */
29
+ export interface Foldered {
30
+ readonly folder?: string
31
+ }
32
+
33
+ /** One empty list for every page to start from while its query loads, so memos hold. */
34
+ export const noItems: readonly never[] = []
35
+
36
+ export interface FolderTile {
37
+ /** The folder's own name, such as `erp`. */
38
+ readonly name: string
39
+ /** Its full path, such as `raw/erp`. */
40
+ readonly path: string
41
+ /** Everything inside it, in subfolders too. */
42
+ readonly count: number
43
+ readonly href: string
44
+ }
45
+
46
+ export interface FolderGroup<TItem> {
47
+ /** Undefined for the items at the top. */
48
+ readonly folder: string | undefined
49
+ readonly items: readonly TItem[]
50
+ }
51
+
52
+ export interface FolderBrowser<TItem> {
53
+ /** The open folder's subfolders, by name. */
54
+ readonly folders: readonly FolderTile[]
55
+ /** The items directly in the open folder. */
56
+ readonly items: readonly TItem[]
57
+ /** While the list is narrowed, every match grouped by folder, the top first. */
58
+ readonly groups: readonly FolderGroup<TItem>[] | undefined
59
+ /** What the page's header shows: the list's own at the top, the folder's inside one. */
60
+ readonly frame: {
61
+ readonly title: string
62
+ readonly description?: string
63
+ readonly back?: { readonly href: string; readonly label: string }
64
+ readonly meta?: ReactNode
65
+ }
66
+ }
67
+
68
+ /**
69
+ * Arrange `items` by folder for the page at the current URL. Pass every item while nothing narrows
70
+ * the list, and only the matches with `narrowed` while a search or filter does: folders then give
71
+ * way to the matches from all of them, grouped by folder.
72
+ */
73
+ export function useFolderBrowser<TItem extends Foldered>({
74
+ items,
75
+ title,
76
+ description,
77
+ meta,
78
+ narrowed = false,
79
+ }: {
80
+ readonly items: readonly TItem[]
81
+ /** The list's own title and description, shown at the top. */
82
+ readonly title: string
83
+ readonly description?: string
84
+ readonly meta?: ReactNode
85
+ readonly narrowed?: boolean
86
+ }): FolderBrowser<TItem> {
87
+ const messages = useFolderMessages()
88
+ const { pathname } = useLocation()
89
+ const [searchParams] = useSearchParams()
90
+ const arranged = useMemo(
91
+ () => arrangeByFolder(items, searchParams.get(FOLDER_PARAM) ?? undefined, narrowed),
92
+ [items, narrowed, searchParams]
93
+ )
94
+
95
+ const hrefFor = (folder: string | undefined) => {
96
+ const params = new URLSearchParams(searchParams)
97
+ if (folder) params.set(FOLDER_PARAM, folder)
98
+ else params.delete(FOLDER_PARAM)
99
+ // A folder's slashes read better left as they are, and a query allows them.
100
+ const query = params.toString().replaceAll("%2F", "/")
101
+ return query ? `${pathname}?${query}` : pathname
102
+ }
103
+
104
+ const { folder } = arranged
105
+ const parent = folder ? parentOf(folder) : undefined
106
+ return {
107
+ items: arranged.items,
108
+ groups: arranged.groups,
109
+ folders: arranged.folders.map((tile) => ({ ...tile, href: hrefFor(tile.path) })),
110
+ frame: folder
111
+ ? {
112
+ title: nameOf(folder),
113
+ back: { href: hrefFor(parent), label: parent ? nameOf(parent) : title },
114
+ meta: <span className="tabular-nums">{messages.items(arranged.total)}</span>,
115
+ }
116
+ : { title, description, meta },
117
+ }
118
+ }
119
+
120
+ /** What a list holds at one folder, before it becomes links and a page header. */
121
+ export interface FolderArrangement<TItem> {
122
+ /** The open folder, or `undefined` at the top. */
123
+ readonly folder: string | undefined
124
+ readonly folders: readonly Omit<FolderTile, "href">[]
125
+ readonly items: readonly TItem[]
126
+ readonly groups: readonly FolderGroup<TItem>[] | undefined
127
+ /** Everything in the open folder, in its subfolders too. */
128
+ readonly total: number
129
+ }
130
+
131
+ /**
132
+ * The open folder's subfolders, each with how much it holds, and the items directly in it; or
133
+ * while `narrowed`, every item grouped by its folder. A folder nothing is in any more, say after
134
+ * its files moved, opens the top instead.
135
+ */
136
+ export function arrangeByFolder<TItem extends Foldered>(
137
+ items: readonly TItem[],
138
+ requested: string | undefined,
139
+ narrowed: boolean
140
+ ): FolderArrangement<TItem> {
141
+ if (narrowed) {
142
+ const byFolder = new Map<string | undefined, TItem[]>()
143
+ for (const item of items) {
144
+ const group = byFolder.get(item.folder)
145
+ if (group) group.push(item)
146
+ else byFolder.set(item.folder, [item])
147
+ }
148
+ const groups = [...byFolder.entries()]
149
+ .sort(([left], [right]) => compareFolders(left, right))
150
+ .map(([folder, grouped]) => ({ folder, items: grouped }))
151
+ return { folder: undefined, folders: [], items, groups, total: items.length }
152
+ }
153
+
154
+ const within = requested ? items.filter((item) => isWithin(item.folder, requested)) : items
155
+ const folder = requested && within.length > 0 ? requested : undefined
156
+ const inFolder = folder ? within : items
157
+
158
+ const counts = new Map<string, number>()
159
+ const direct: TItem[] = []
160
+ for (const item of inFolder) {
161
+ if (item.folder === folder) {
162
+ direct.push(item)
163
+ continue
164
+ }
165
+ // Inside `folder`, so `item.folder` is longer than it and its next segment is the subfolder.
166
+ const rest = folder ? item.folder?.slice(folder.length + 1) : item.folder
167
+ const name = rest?.split("/")[0]
168
+ if (!name) continue
169
+ const child = folder ? `${folder}/${name}` : name
170
+ counts.set(child, (counts.get(child) ?? 0) + 1)
171
+ }
172
+ const folders = [...counts.entries()]
173
+ .map(([path, count]) => ({ name: nameOf(path), path, count }))
174
+ .sort((left, right) => compareNames(left.name, right.name))
175
+
176
+ return { folder, folders, items: direct, groups: undefined, total: inFolder.length }
177
+ }
178
+
179
+ /**
180
+ * A folder browser's body: the open folder's subfolders as tiles, then its items through
181
+ * `children`, or while narrowed each folder's matches under its name. `children` only runs for a
182
+ * non-empty list, so a folder holding only folders shows no empty list.
183
+ */
184
+ export function FolderContents<TItem>({
185
+ browser,
186
+ rootLabel,
187
+ children,
188
+ }: {
189
+ readonly browser: FolderBrowser<TItem>
190
+ /** Names the matches at the top while narrowed, such as "Datasets". */
191
+ readonly rootLabel: string
192
+ readonly children: (items: readonly TItem[]) => ReactNode
193
+ }) {
194
+ if (browser.groups) {
195
+ // With every match in one place, as in a project without folders, a heading would only repeat
196
+ // the page.
197
+ if (browser.groups.length < 2) return <>{children(browser.items)}</>
198
+ return (
199
+ <div className="flex flex-col gap-6">
200
+ {browser.groups.map((group) => (
201
+ <section key={group.folder ?? ""} className="flex flex-col gap-2.5">
202
+ <FolderHeading folder={group.folder} rootLabel={rootLabel} />
203
+ {children(group.items)}
204
+ </section>
205
+ ))}
206
+ </div>
207
+ )
208
+ }
209
+
210
+ return (
211
+ <div className="flex flex-col gap-4">
212
+ {browser.folders.length > 0 ? <FolderTiles folders={browser.folders} /> : null}
213
+ {browser.items.length > 0 ? children(browser.items) : null}
214
+ </div>
215
+ )
216
+ }
217
+
218
+ function FolderTiles({ folders }: { readonly folders: readonly FolderTile[] }) {
219
+ const messages = useFolderMessages()
220
+ return (
221
+ // As many columns as fit tiles wide enough for a usual name, so names are read, not cut: one
222
+ // on a phone.
223
+ <ul className="grid grid-cols-[repeat(auto-fill,minmax(min(100%,12.5rem),1fr))] gap-2.5">
224
+ {folders.map((folder) => (
225
+ <li key={folder.path} className="min-w-0">
226
+ <Link
227
+ to={folder.href}
228
+ title={folder.name}
229
+ className={cn(
230
+ "group flex h-full min-w-0 items-center gap-3 rounded-xl border border-border bg-card px-3.5 py-2.5",
231
+ "shadow-[0_1px_2px_0_rgb(0_0_0/0.04)] outline-none transition-[background-color,border-color,transform] duration-150",
232
+ "hover:border-foreground/15 hover:bg-muted/40 focus-visible:ring-2 focus-visible:ring-ring",
233
+ "motion-safe:active:scale-[0.985]"
234
+ )}
235
+ >
236
+ <FolderGlyph className="h-7 w-8 shrink-0" />
237
+ <span className="min-w-0 flex-1">
238
+ {/* A name too long for its tile wraps, at its hyphens first, rather than lose its end. */}
239
+ <span className="line-clamp-2 text-sm leading-5 font-medium break-words">
240
+ {folder.name}
241
+ </span>
242
+ <span className="block text-xs leading-4 tabular-nums text-muted-foreground">
243
+ {messages.items(folder.count)}
244
+ </span>
245
+ </span>
246
+ </Link>
247
+ </li>
248
+ ))}
249
+ </ul>
250
+ )
251
+ }
252
+
253
+ /** A folder's full path over its matches, with a glyph that says what it is. */
254
+ function FolderHeading({
255
+ folder,
256
+ rootLabel,
257
+ }: {
258
+ readonly folder: string | undefined
259
+ readonly rootLabel: string
260
+ }) {
261
+ return (
262
+ <h3 className="flex min-w-0 items-center gap-2 px-0.5 text-[0.8125rem] leading-5 font-medium text-muted-foreground">
263
+ {/* The top is the list itself, not a folder. */}
264
+ {folder ? <FolderGlyph className="h-3.5 w-4 shrink-0" /> : null}
265
+ <span className="truncate">{folder ? folder.replaceAll("/", " / ") : rootLabel}</span>
266
+ </h3>
267
+ )
268
+ }
269
+
270
+ /** A folder, drawn as one: its tab behind, its front over it, in a quiet system blue. */
271
+ function FolderGlyph({ className }: { readonly className?: string }) {
272
+ return (
273
+ <svg aria-hidden viewBox="0 0 32 26" className={className}>
274
+ <path
275
+ d="M1.5 5A3.5 3.5 0 0 1 5 1.5h6.2a3 3 0 0 1 2.1.88L15.4 4.5H27A3.5 3.5 0 0 1 30.5 8v2h-29z"
276
+ className="fill-[#6aa6e6] dark:fill-[#3f6fa3]"
277
+ />
278
+ <rect
279
+ x="1.5"
280
+ y="7"
281
+ width="29"
282
+ height="17.5"
283
+ rx="3.25"
284
+ className="fill-[#8cc0f2] dark:fill-[#5288c2]"
285
+ />
286
+ <path d="M2.75 9.25h26.5" className="stroke-white/40 dark:stroke-white/15" strokeWidth="1" />
287
+ </svg>
288
+ )
289
+ }
290
+
291
+ /**
292
+ * Where a detail page's back link goes: its folder when it has one, so leaving a definition
293
+ * returns to where it was found, or the list itself.
294
+ */
295
+ export function folderBack(
296
+ list: { readonly href: string; readonly label: string },
297
+ folder: string | undefined
298
+ ): { readonly href: string; readonly label: string } {
299
+ if (!folder) return list
300
+ return { href: `${list.href}?${FOLDER_PARAM}=${encodeFolder(folder)}`, label: nameOf(folder) }
301
+ }
302
+
303
+ function encodeFolder(folder: string): string {
304
+ return folder.split("/").map(encodeURIComponent).join("/")
305
+ }
306
+
307
+ /** Whether `folder` is `ancestor` or inside it. Everything is within the top. */
308
+ function isWithin(folder: string | undefined, ancestor: string | undefined): boolean {
309
+ if (ancestor === undefined) return true
310
+ if (folder === undefined) return false
311
+ return folder === ancestor || folder.startsWith(`${ancestor}/`)
312
+ }
313
+
314
+ function nameOf(folder: string): string {
315
+ return folder.slice(folder.lastIndexOf("/") + 1)
316
+ }
317
+
318
+ function parentOf(folder: string): string | undefined {
319
+ const slash = folder.lastIndexOf("/")
320
+ return slash === -1 ? undefined : folder.slice(0, slash)
321
+ }
322
+
323
+ const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" })
324
+
325
+ function compareNames(left: string, right: string): number {
326
+ return collator.compare(left, right)
327
+ }
328
+
329
+ /** The top first, then folders by path. */
330
+ function compareFolders(left: string | undefined, right: string | undefined): number {
331
+ if (left === right) return 0
332
+ if (left === undefined) return -1
333
+ if (right === undefined) return 1
334
+ return compareNames(left, right)
335
+ }