@startsimpli/integrations 0.2.204 → 0.2.205
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/package.json +3 -3
- package/src/__tests__/corpus-folders.test.tsx +20 -121
- package/src/__tests__/corpus-freshness.test.tsx +0 -21
- package/src/__tests__/corpus-pages.test.tsx +20 -21
- package/src/__tests__/corpus-source-strip.test.tsx +0 -63
- package/src/__tests__/library-failure-reason.test.tsx +0 -18
- package/src/__tests__/library-model.test.ts +56 -0
- package/src/__tests__/library-table.test.tsx +193 -0
- package/src/components/FolderTree.tsx +32 -16
- package/src/components/pages/LibraryPage.tsx +196 -655
- package/src/components/pages/library/LibraryTable.tsx +40 -0
- package/src/components/pages/library/LibraryTree.tsx +89 -0
- package/src/components/pages/library/library-model.ts +86 -0
- package/src/components/table/DataTable.tsx +4 -1
- package/src/corpus/client.ts +1 -0
- package/src/corpus/fixtures.ts +4 -2
- package/src/corpus/types.ts +2 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** The Library list: the shared DataTable with the Library's columns. Click a row to open the record. */
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
|
|
4
|
+
import { formatDate } from '../../documentText';
|
|
5
|
+
import { DataTable } from '../../table';
|
|
6
|
+
import type { DataTableProps } from '../../table';
|
|
7
|
+
import type { SourceDocument } from '../../../corpus/types';
|
|
8
|
+
import { folderCell, typeLabel, whoText } from './library-model';
|
|
9
|
+
|
|
10
|
+
type Shared = Pick<DataTableProps<SourceDocument>, 'sort' | 'onSort' | 'page' | 'pageSize' | 'total' | 'onPage' | 'onPageSize' | 'loading' | 'emptyMessage'>;
|
|
11
|
+
|
|
12
|
+
export function LibraryTable({ rows, onOpen, hidden, ...shared }: { rows: SourceDocument[]; onOpen: (id: string) => void; hidden?: Set<string> } & Shared) {
|
|
13
|
+
return (
|
|
14
|
+
<DataTable<SourceDocument>
|
|
15
|
+
tableId="library"
|
|
16
|
+
rows={rows}
|
|
17
|
+
rowKey={(d) => String(d.id)}
|
|
18
|
+
onRowClick={(d) => onOpen(String(d.id))}
|
|
19
|
+
columns={[
|
|
20
|
+
{
|
|
21
|
+
key: 'title', header: 'Title', className: 'w-full min-w-[8rem] max-w-0',
|
|
22
|
+
render: (d) => (
|
|
23
|
+
<button type="button" onClick={() => onOpen(String(d.id))} className="block w-full truncate text-left font-medium text-gray-900 hover:underline dark:text-gray-100" title={d.title}>
|
|
24
|
+
{d.title}
|
|
25
|
+
</button>
|
|
26
|
+
),
|
|
27
|
+
},
|
|
28
|
+
{ key: 'source', header: 'Source', hideOnPhone: true, className: 'whitespace-nowrap text-gray-700 dark:text-gray-300', render: (d) => d.sourceLabel || d.source },
|
|
29
|
+
{
|
|
30
|
+
key: 'folder', hidden: hidden?.has('folder'), header: 'Folder', hideOnPhone: true, className: 'whitespace-nowrap text-gray-600 dark:text-gray-400',
|
|
31
|
+
render: (d) => { const f = folderCell(d); return <span title={f.full || undefined}>{f.label}</span>; },
|
|
32
|
+
},
|
|
33
|
+
{ key: 'type', hidden: hidden?.has('type'), header: 'Type', hideOnPhone: true, className: 'whitespace-nowrap text-gray-600 dark:text-gray-400', render: (d) => typeLabel(d.subtype) },
|
|
34
|
+
{ key: 'date', header: 'Date', sortable: true, className: 'whitespace-nowrap text-gray-600 dark:text-gray-400', render: (d) => formatDate(d.occurredAt ?? d.ingestedAt) },
|
|
35
|
+
{ key: 'who', hidden: hidden?.has('who'), header: 'Who', hideOnPhone: true, className: 'max-w-[9rem] truncate text-gray-600 dark:text-gray-400', render: (d) => whoText(d.participants) },
|
|
36
|
+
]}
|
|
37
|
+
{...shared}
|
|
38
|
+
/>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Library's left tree: "All documents", then one node per connected source with its count.
|
|
3
|
+
* A source shows folders ONLY if it has some: each source's top-level folders are read once
|
|
4
|
+
* (`attr.source`), one source at a time and after the rows, and a source that returns none draws
|
|
5
|
+
* no arrow and no children. Selecting a folder means the folder and everything under it.
|
|
6
|
+
*/
|
|
7
|
+
import * as React from 'react';
|
|
8
|
+
|
|
9
|
+
import { FolderTree } from '../../FolderTree';
|
|
10
|
+
import type { FolderSource } from '../../FolderTree';
|
|
11
|
+
import type { SourceFreshness } from '../../../corpus/types';
|
|
12
|
+
|
|
13
|
+
export interface LibrarySelection { source: string | null; folder: string | null }
|
|
14
|
+
|
|
15
|
+
export function LibraryTree({ api, sources, sourcesLoaded, selection, onSelect, hold, onUnavailable }: {
|
|
16
|
+
api: FolderSource;
|
|
17
|
+
sources: SourceFreshness[];
|
|
18
|
+
/** The source list has been read (an empty list before that does not mean there are none). */
|
|
19
|
+
sourcesLoaded: boolean;
|
|
20
|
+
selection: LibrarySelection;
|
|
21
|
+
onSelect: (next: LibrarySelection) => void;
|
|
22
|
+
/** Do not read any folders yet (the rows come first). */
|
|
23
|
+
hold: boolean;
|
|
24
|
+
/** The corpus cannot enumerate folders: the sources stay, the folder rows never appear. */
|
|
25
|
+
onUnavailable?: () => void;
|
|
26
|
+
}) {
|
|
27
|
+
// source key -> how many top-level folders it has, once known. A source is probed only after the one before it.
|
|
28
|
+
const [folders, setFolders] = React.useState<Record<string, number>>({});
|
|
29
|
+
const [open, setOpen] = React.useState<Record<string, boolean>>({});
|
|
30
|
+
const firstUnknown = sources.findIndex((s) => folders[s.source] === undefined);
|
|
31
|
+
const node = 'flex min-w-0 flex-1 items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left text-sm';
|
|
32
|
+
const on = 'bg-gray-100 font-medium text-gray-900 dark:bg-gray-800 dark:text-gray-100';
|
|
33
|
+
const off = 'text-gray-700 hover:bg-gray-50 dark:text-gray-300 dark:hover:bg-gray-800/60';
|
|
34
|
+
const allSelected = !selection.source && !selection.folder;
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<nav aria-label="Sources and folders" className="space-y-0.5">
|
|
38
|
+
<button type="button" aria-current={allSelected ? 'true' : undefined} className={`${node} ${allSelected ? on : off}`} onClick={() => onSelect({ source: null, folder: null })}>
|
|
39
|
+
<span className="truncate">All documents</span>
|
|
40
|
+
</button>
|
|
41
|
+
{/* No connected source to hang folders on: the corpus's own top-level folders, so nothing is unreachable. */}
|
|
42
|
+
{sourcesLoaded && sources.length === 0 ? (
|
|
43
|
+
<FolderTree
|
|
44
|
+
api={api}
|
|
45
|
+
showRoot={false}
|
|
46
|
+
selected={selection.folder}
|
|
47
|
+
hold={hold}
|
|
48
|
+
onSelect={(folder) => onSelect({ source: null, folder })}
|
|
49
|
+
onUnavailable={onUnavailable}
|
|
50
|
+
/>
|
|
51
|
+
) : null}
|
|
52
|
+
{sources.map((source, index) => {
|
|
53
|
+
const has = (folders[source.source] ?? 0) > 0;
|
|
54
|
+
const active = selection.source === source.source;
|
|
55
|
+
const expanded = has && (open[source.source] ?? active);
|
|
56
|
+
return (
|
|
57
|
+
<div key={source.source}>
|
|
58
|
+
<div className="flex items-center">
|
|
59
|
+
{has ? (
|
|
60
|
+
<button type="button" aria-expanded={expanded} aria-label={`${expanded ? 'Collapse' : 'Expand'} ${source.label}`} className="w-4 shrink-0 text-xs text-gray-400 hover:text-gray-700"
|
|
61
|
+
onClick={() => setOpen((prev) => ({ ...prev, [source.source]: !expanded }))}>
|
|
62
|
+
{expanded ? '▾' : '▸'}
|
|
63
|
+
</button>
|
|
64
|
+
) : <span aria-hidden className="w-4 shrink-0" />}
|
|
65
|
+
<button type="button" aria-current={active && !selection.folder ? 'true' : undefined} className={`${node} ${active && !selection.folder ? on : off}`}
|
|
66
|
+
onClick={() => { onSelect({ source: source.source, folder: null }); if (has) setOpen((prev) => ({ ...prev, [source.source]: true })); }}>
|
|
67
|
+
<span className="min-w-0 truncate">{source.label}</span>
|
|
68
|
+
{typeof source.documentCount === 'number' ? <span className="shrink-0 text-xs text-gray-400">{source.documentCount}</span> : null}
|
|
69
|
+
</button>
|
|
70
|
+
</div>
|
|
71
|
+
{/* Always mounted so the one probe happens, hidden until the source is open. */}
|
|
72
|
+
<div hidden={!expanded} className="ml-4">
|
|
73
|
+
<FolderTree
|
|
74
|
+
api={api}
|
|
75
|
+
source={source.source}
|
|
76
|
+
showRoot={false}
|
|
77
|
+
selected={active ? selection.folder : null}
|
|
78
|
+
hold={hold || (firstUnknown !== -1 && index > firstUnknown)}
|
|
79
|
+
onRootLoaded={(count) => setFolders((prev) => (prev[source.source] === count ? prev : { ...prev, [source.source]: count }))}
|
|
80
|
+
onSelect={(folder) => onSelect({ source: source.source, folder })}
|
|
81
|
+
onUnavailable={onUnavailable}
|
|
82
|
+
/>
|
|
83
|
+
</div>
|
|
84
|
+
</div>
|
|
85
|
+
);
|
|
86
|
+
})}
|
|
87
|
+
</nav>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/** Pure rules for the Library table: what each column says, and the Type and Date filters. */
|
|
2
|
+
import type { DocumentQuery, PartyRef, SourceDocument } from '../../../corpus/types';
|
|
3
|
+
import type { FilterOption } from '../../table';
|
|
4
|
+
import type { TableSort } from '../../table';
|
|
5
|
+
|
|
6
|
+
const TYPE_WORDS: Record<string, string> = {
|
|
7
|
+
document: 'Document', file: 'File', meeting: 'Meeting', voice_note: 'Voice note', email: 'Email',
|
|
8
|
+
issue: 'Issue', message: 'Message', note: 'Note', call: 'Call', transcript: 'Transcript',
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/** A friendly word for a subtype the source gave, or the subtype tidied up; a dash when it gave none. */
|
|
12
|
+
export function typeLabel(subtype: string | undefined | null): string {
|
|
13
|
+
if (!subtype) return '—';
|
|
14
|
+
const known = TYPE_WORDS[subtype];
|
|
15
|
+
if (known) return known;
|
|
16
|
+
const words = subtype.replace(/[_-]+/g, ' ').trim();
|
|
17
|
+
return words ? words.charAt(0).toUpperCase() + words.slice(1) : '—';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Type filter options: "All types" plus the subtypes seen on screen so far (data, not a vendor list). */
|
|
21
|
+
export function typeOptions(seen: string[], active: string | undefined): FilterOption[] {
|
|
22
|
+
const values = Array.from(new Set([...seen, ...(active ? [active] : [])])).filter(Boolean).sort();
|
|
23
|
+
return [{ value: '', label: 'All types' }, ...values.map((value) => ({ value, label: typeLabel(value) }))];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const DATE_FILTERS: FilterOption[] = [
|
|
27
|
+
{ value: '', label: 'Any date' },
|
|
28
|
+
{ value: '7', label: 'Past 7 days' },
|
|
29
|
+
{ value: '30', label: 'Past 30 days' },
|
|
30
|
+
{ value: '90', label: 'Past 90 days' },
|
|
31
|
+
{ value: 'year', label: 'This year' },
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
/** The `occurredAfter` instant for a Date option, from an explicit clock. */
|
|
35
|
+
export function dateAfter(key: string, now: number): string | undefined {
|
|
36
|
+
if (!key) return undefined;
|
|
37
|
+
const at = new Date(now);
|
|
38
|
+
if (key === 'year') return `${at.getUTCFullYear()}-01-01T00:00:00Z`;
|
|
39
|
+
const days = Number(key);
|
|
40
|
+
if (!Number.isFinite(days) || days <= 0) return undefined;
|
|
41
|
+
return new Date(now - days * 86_400_000).toISOString();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Which Date option an `occurredAfter` came from, so the dropdown shows the choice. */
|
|
45
|
+
export function dateKeyOf(after: string | undefined, now: number): string {
|
|
46
|
+
if (!after) return '';
|
|
47
|
+
for (const option of DATE_FILTERS) {
|
|
48
|
+
if (option.value && dateAfter(option.value, now) === after) return option.value;
|
|
49
|
+
}
|
|
50
|
+
return '';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The Date header sorts by when it happened: newest first or oldest first, always server-side. */
|
|
54
|
+
export function orderOf(sort: TableSort | null): DocumentQuery['order'] {
|
|
55
|
+
if (!sort || sort.key !== 'date') return undefined;
|
|
56
|
+
return sort.dir === 'asc' ? 'oldest' : 'recent';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** "Ada, Grace +2": the people on a record, short. A dash when the source has none. */
|
|
60
|
+
export function whoText(people: PartyRef[]): string {
|
|
61
|
+
const names = people.map((p) => p.name).filter(Boolean);
|
|
62
|
+
if (names.length === 0) return '—';
|
|
63
|
+
if (names.length <= 2) return names.join(', ');
|
|
64
|
+
return `${names.slice(0, 2).join(', ')} +${names.length - 2}`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The container shown in the Folder column: its last segment, a dash when the source has no folders. */
|
|
68
|
+
export function folderCell(document: SourceDocument): { label: string; full: string } {
|
|
69
|
+
const full = document.folder ?? '';
|
|
70
|
+
if (!full) return { label: '—', full: '' };
|
|
71
|
+
const segments = full.split('/').filter(Boolean);
|
|
72
|
+
return { label: segments[segments.length - 1] ?? full, full };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Columns with nothing in them on the loaded page: hidden, never shown as a column of dashes. `Who` waits for the
|
|
77
|
+
* people read (they arrive after the rows) so it does not blink out before they land.
|
|
78
|
+
*/
|
|
79
|
+
export function emptyColumns(rows: SourceDocument[], peopleSettled: boolean): Set<string> {
|
|
80
|
+
const out = new Set<string>();
|
|
81
|
+
if (rows.length === 0) return out;
|
|
82
|
+
if (!rows.some((d) => d.subtype)) out.add('type');
|
|
83
|
+
if (!rows.some((d) => d.folder)) out.add('folder');
|
|
84
|
+
if (peopleSettled && !rows.some((d) => d.participants.length > 0)) out.add('who');
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
@@ -20,6 +20,8 @@ export interface DataTableColumn<Row> {
|
|
|
20
20
|
className?: string;
|
|
21
21
|
/** Hide this column under the `md` breakpoint (phones). */
|
|
22
22
|
hideOnPhone?: boolean;
|
|
23
|
+
/** Drop this column entirely (no header, no cells): a column nothing on the loaded page has a value for is dead weight. */
|
|
24
|
+
hidden?: boolean;
|
|
23
25
|
/** Visually hide the header text (checkbox and menu columns) while keeping it for screen readers. */
|
|
24
26
|
srOnlyHeader?: boolean;
|
|
25
27
|
render: (row: Row) => React.ReactNode;
|
|
@@ -52,9 +54,10 @@ export interface DataTableProps<Row> {
|
|
|
52
54
|
const hide = (c: { hideOnPhone?: boolean }) => (c.hideOnPhone ? 'hidden md:table-cell' : '');
|
|
53
55
|
|
|
54
56
|
export function DataTable<Row>({
|
|
55
|
-
tableId, columns, rows, rowKey, sort, onSort, page = 1, pageSize = 25, total = rows.length, onPage, onPageSize,
|
|
57
|
+
tableId, columns: allColumns, rows, rowKey, sort, onSort, page = 1, pageSize = 25, total = rows.length, onPage, onPageSize,
|
|
56
58
|
loading, emptyMessage = 'Nothing to show.', rowClassName, topRow, onRowClick,
|
|
57
59
|
}: DataTableProps<Row>) {
|
|
60
|
+
const columns = allColumns.filter((c) => !c.hidden);
|
|
58
61
|
return (
|
|
59
62
|
<div className="w-full min-w-0 max-w-full overflow-hidden rounded-lg border border-gray-200 bg-white dark:border-gray-700 dark:bg-gray-900" data-testid={`table-${tableId}`}>
|
|
60
63
|
<div className="overflow-x-auto">
|
package/src/corpus/client.ts
CHANGED
package/src/corpus/fixtures.ts
CHANGED
|
@@ -1077,7 +1077,9 @@ function facetRead(rows: TenantEntity[], params: Record<string, unknown>) {
|
|
|
1077
1077
|
);
|
|
1078
1078
|
}
|
|
1079
1079
|
const type = params.type ? String(params.type) : '';
|
|
1080
|
+
const bySource = params['attr.source'] ? String(params['attr.source']) : '';
|
|
1080
1081
|
const scoped = (type ? rows.filter((entity) => entity.entity_type === type) : rows)
|
|
1082
|
+
.filter((entity) => !bySource || (entity.data as Record<string, unknown> | undefined)?.source === bySource)
|
|
1081
1083
|
.filter((entity) => {
|
|
1082
1084
|
const value = (entity.data as Record<string, unknown> | undefined)?.[attribute];
|
|
1083
1085
|
return typeof value === 'string' && value !== '';
|
|
@@ -1092,7 +1094,7 @@ function facetRead(rows: TenantEntity[], params: Record<string, unknown>) {
|
|
|
1092
1094
|
const results = [...flat]
|
|
1093
1095
|
.map(([value, count]) => ({ value, count }))
|
|
1094
1096
|
.sort((a, b) => a.value.localeCompare(b.value));
|
|
1095
|
-
return { ...slicePage(results, params), applied_filters: ['attr'] };
|
|
1097
|
+
return { ...slicePage(results, params), applied_filters: bySource ? ['attr', 'attr.source'] : ['attr'] };
|
|
1096
1098
|
}
|
|
1097
1099
|
|
|
1098
1100
|
const [self, descendants] = subtreeBound(params.under);
|
|
@@ -1115,7 +1117,7 @@ function facetRead(rows: TenantEntity[], params: Record<string, unknown>) {
|
|
|
1115
1117
|
const results = [...groups]
|
|
1116
1118
|
.map(([value, at]) => ({ value, count: at.count, has_children: at.deeper }))
|
|
1117
1119
|
.sort((a, b) => a.value.localeCompare(b.value));
|
|
1118
|
-
return { ...slicePage(results, params), applied_filters: ['attr', 'under'] };
|
|
1120
|
+
return { ...slicePage(results, params), applied_filters: bySource ? ['attr', 'attr.source', 'under'] : ['attr', 'under'] };
|
|
1119
1121
|
}
|
|
1120
1122
|
|
|
1121
1123
|
/** The same DRF envelope `slice()` builds, outside the closure that owns it. */
|
package/src/corpus/types.ts
CHANGED
|
@@ -404,6 +404,8 @@ export interface CorpusFolder {
|
|
|
404
404
|
*/
|
|
405
405
|
export interface FolderQuery {
|
|
406
406
|
under: string;
|
|
407
|
+
/** Only the folders of ONE source (goes out as `attr.source`); the facet read honours it. */
|
|
408
|
+
source?: string;
|
|
407
409
|
page?: number;
|
|
408
410
|
pageSize?: number;
|
|
409
411
|
}
|