@startsimpli/integrations 0.2.102 → 0.2.104
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 +4 -4
- package/src/__tests__/focus-standings.test.tsx +119 -0
- package/src/components/pages/PlanningPage.tsx +16 -4
- package/src/corpus/client.ts +5 -0
- package/src/corpus/entity-query.ts +67 -4
- package/src/corpus/index.ts +4 -2
- package/src/corpus/standings.ts +75 -0
- package/src/corpus/types.ts +6 -0
- package/src/native/__tests__/design-screens.test.tsx +97 -0
- package/src/native/__tests__/ux-polish.test.tsx +4 -2
- package/src/native/app/FoundryApp.tsx +2 -2
- package/src/native/app/__tests__/launch.test.ts +4 -1
- package/src/native/app/entity/EntityTab.tsx +13 -18
- package/src/native/app/icon.tsx +6 -1
- package/src/native/app/launch.ts +4 -0
- package/src/native/app/screens/RecordScreen.tsx +37 -30
- package/src/native/app/screens/SignInScreen.tsx +4 -3
- package/src/native/components/FoundryTabsShell.tsx +8 -5
- package/src/native/components/MoreTabList.tsx +20 -25
- package/src/native/components/NoteDetailScreen.tsx +49 -57
- package/src/native/components/NotesListScreen.tsx +13 -19
- package/src/native/components/__tests__/notes-screens.test.tsx +7 -7
- package/src/native/corpus/__tests__/counts.test.ts +82 -0
- package/src/native/corpus/__tests__/display.test.ts +37 -0
- package/src/native/corpus/api.ts +35 -2
- package/src/native/corpus/counts.ts +16 -0
- package/src/native/corpus/display.ts +62 -0
- package/src/native/corpus/fake-counts.ts +59 -0
- package/src/native/corpus/fake-tenant.ts +31 -3
- package/src/native/home/HomeScreen.tsx +15 -12
- package/src/native/home/__tests__/controller.test.ts +24 -11
- package/src/native/home/controller.ts +23 -17
- package/src/native/index.ts +3 -1
- package/src/native/screens/ask/AskScreen.tsx +20 -22
- package/src/native/screens/connect-claude/ConnectClaudeScreen.tsx +68 -61
- package/src/native/screens/connections/ConnectionsScreens.tsx +46 -42
- package/src/native/screens/library/LibraryDetailScreen.tsx +35 -49
- package/src/native/screens/library/LibraryListScreen.tsx +13 -21
- package/src/native/screens/planning/PlanningScreens.tsx +49 -26
- package/src/native/screens/planning/__tests__/controller.test.ts +17 -23
- package/src/native/screens/planning/controller.ts +18 -26
- package/src/native/tracker/TodoGlyph.tsx +11 -0
- package/src/native/tracker/TrackerDetailScreen.tsx +34 -39
- package/src/native/tracker/TrackerListScreen.tsx +28 -19
- package/src/native/tracker/__tests__/detail.test.ts +17 -0
- package/src/native/tracker/__tests__/format.test.ts +3 -3
- package/src/native/tracker/detail.ts +32 -19
- package/src/native/tracker/format.ts +8 -7
- package/src/native/voice/format.ts +0 -3
- package/src/native/screens/shared/PressableCard.tsx +0 -14
package/src/native/corpus/api.ts
CHANGED
|
@@ -16,9 +16,13 @@ import { createPlanningApi, type CreateCorpusApiOptions } from '../../corpus/cli
|
|
|
16
16
|
import { isRecord, notFound } from '../../corpus/client';
|
|
17
17
|
import type { TenantEntity, TenantFacetRow, TenantRelationship } from '../../corpus/entities';
|
|
18
18
|
import {
|
|
19
|
-
entityParams, facetParams, relationshipParams, toEntityPage,
|
|
20
|
-
type EntityPage, type EntityQuery, type FacetQuery, type RelationshipListQuery,
|
|
19
|
+
MAX_PAGE_SIZE, countParams, entityParams, facetParams, relationshipParams, toCountRows, toEntityPage,
|
|
20
|
+
type CountQuery, type CountRow, type WireCountRow, type EntityPage, type EntityQuery, type FacetQuery, type RelationshipListQuery,
|
|
21
21
|
} from '../../corpus/entity-query';
|
|
22
|
+
import { DEFAULT_TYPE_KEYS } from '../../corpus/entities';
|
|
23
|
+
import type { FocusStanding } from '../../corpus/types';
|
|
24
|
+
import { readStandings } from '../../corpus/standings';
|
|
25
|
+
import { displaysFrom, type SchemaTypeRow, type TypeDisplayConfig } from './display';
|
|
22
26
|
import type {
|
|
23
27
|
Commitment, CommitmentQuery, CommitmentStatus, CorpusAskApi, CorpusPage, CorpusScope,
|
|
24
28
|
DocumentQuery, Focus, FocusQuery, SourceDocument,
|
|
@@ -52,7 +56,19 @@ export interface NativeCorpusApi {
|
|
|
52
56
|
list(query: EntityQuery): Promise<EntityPage<TenantEntity>>;
|
|
53
57
|
get(id: string): Promise<TenantEntity>;
|
|
54
58
|
facets(query: FacetQuery): Promise<EntityPage<TenantFacetRow>>;
|
|
59
|
+
/** Grouped counts (`entities/counts/`): one read for a row of tiles, badges or cards. */
|
|
60
|
+
counts(query: CountQuery): Promise<EntityPage<CountRow>>;
|
|
55
61
|
};
|
|
62
|
+
/** The tenant's own schema, for generic rendering. */
|
|
63
|
+
schema: {
|
|
64
|
+
/** `config.display` per type that declares one (see `resolveDisplay`). Read once, then cached. */
|
|
65
|
+
displays(): Promise<Record<string, TypeDisplayConfig>>;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Total / done / overdue to-dos for a PAGE of projects, in two reads however
|
|
69
|
+
* many projects there are. Every id is present in the result, zeros if empty.
|
|
70
|
+
*/
|
|
71
|
+
standings(focusIds: string[], now?: number): Promise<Record<string, FocusStanding>>;
|
|
56
72
|
relationships: { list(query: RelationshipListQuery): Promise<EntityPage<TenantRelationship>> };
|
|
57
73
|
/** The web composers' api objects, unchanged: Library (documents), Tracker (commitments), Planning (focuses). */
|
|
58
74
|
corpus: CorpusApi & PlanningApi;
|
|
@@ -102,6 +118,7 @@ export function createNativeCorpusApi(deps: NativeCorpusDeps): NativeCorpusApi {
|
|
|
102
118
|
const scope = deps.scope ?? ({} as CorpusScope);
|
|
103
119
|
const corpus = createPlanningApi({ http, scope, ...deps.corpus }) as unknown as CorpusApi & PlanningApi;
|
|
104
120
|
|
|
121
|
+
let displays: Promise<Record<string, TypeDisplayConfig>> | null = null;
|
|
105
122
|
const api: NativeCorpusApi = {
|
|
106
123
|
http,
|
|
107
124
|
scope,
|
|
@@ -119,7 +136,23 @@ export function createNativeCorpusApi(deps: NativeCorpusDeps): NativeCorpusApi {
|
|
|
119
136
|
const params = facetParams(query);
|
|
120
137
|
return toEntityPage(params, await http.get<{ results?: TenantFacetRow[] }>(`${ENTITIES}/facets`, { params }), (row: TenantFacetRow) => row);
|
|
121
138
|
},
|
|
139
|
+
async counts(query) {
|
|
140
|
+
const params = countParams(query);
|
|
141
|
+
const page = toEntityPage(params, await http.get<{ results?: WireCountRow[] }>(`${ENTITIES}/counts`, { params }), (row: WireCountRow) => row);
|
|
142
|
+
return { ...page, items: toCountRows(query.groupBy, page.items) };
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
schema: {
|
|
146
|
+
displays() {
|
|
147
|
+
displays ??= http.get<{ results?: SchemaTypeRow[] }>('api/v1/schema/types', { params: { page_size: MAX_PAGE_SIZE } })
|
|
148
|
+
.then((page) => displaysFrom(page.results ?? []))
|
|
149
|
+
.catch((e) => { displays = null; throw e; });
|
|
150
|
+
return displays;
|
|
151
|
+
},
|
|
122
152
|
},
|
|
153
|
+
standings: (focusIds, now = Date.now()) => readStandings(http, focusIds, now, {
|
|
154
|
+
commitmentType: { ...DEFAULT_TYPE_KEYS, ...deps.corpus?.typeKeys }.commitment,
|
|
155
|
+
}),
|
|
123
156
|
relationships: {
|
|
124
157
|
async list(query) {
|
|
125
158
|
const params = relationshipParams(query);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading grouped counts (`entities.counts`): the figures a tile, a badge or a
|
|
3
|
+
* project card shows, from ONE request instead of one per number.
|
|
4
|
+
*/
|
|
5
|
+
import type { CountRow } from '../../corpus/entity-query';
|
|
6
|
+
|
|
7
|
+
/** `{ [value]: count }` for one group key; a null group (unfiled, no status) is keyed `''`. */
|
|
8
|
+
export function countsBy(rows: CountRow[], token: string): Record<string, number> {
|
|
9
|
+
const out: Record<string, number> = {};
|
|
10
|
+
for (const row of rows) {
|
|
11
|
+
const key = row.group[token];
|
|
12
|
+
const name = key === null || key === undefined ? '' : String(key);
|
|
13
|
+
out[name] = (out[name] ?? 0) + row.count;
|
|
14
|
+
}
|
|
15
|
+
return out;
|
|
16
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a row of a type reads, from the tenant's own schema (`config.display` on
|
|
3
|
+
* `GET api/v1/schema/types/`, bd startsim-cmpai) - so ONE generic row and detail
|
|
4
|
+
* renderer serves a type the client has never heard of. A type that declares
|
|
5
|
+
* nothing reads as its name alone.
|
|
6
|
+
*
|
|
7
|
+
* Keys are one lowercase word because the apps' API client camelCases response
|
|
8
|
+
* keys; attribute names and status values travel as VALUES.
|
|
9
|
+
*/
|
|
10
|
+
import type { TenantEntity } from '../../corpus/entities';
|
|
11
|
+
|
|
12
|
+
export type DisplayTone = 'good' | 'warn' | 'bad' | 'info' | 'neutral';
|
|
13
|
+
|
|
14
|
+
/** The declaration as stored on `EntityTypeDef.config.display`. */
|
|
15
|
+
export interface TypeDisplayConfig {
|
|
16
|
+
title?: string;
|
|
17
|
+
subtitle?: string;
|
|
18
|
+
date?: string;
|
|
19
|
+
status?: string;
|
|
20
|
+
tones?: Record<string, DisplayTone>;
|
|
21
|
+
icon?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** One row, resolved: what a generic list row / detail header shows. */
|
|
25
|
+
export interface RowDisplay {
|
|
26
|
+
title: string;
|
|
27
|
+
subtitle: string | null;
|
|
28
|
+
date: string | null;
|
|
29
|
+
status: { value: string; tone: DisplayTone } | null;
|
|
30
|
+
icon: string | null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface SchemaTypeRow { key: string; label?: string; config?: { display?: TypeDisplayConfig } | null }
|
|
34
|
+
|
|
35
|
+
const dataOf = (e: TenantEntity): Record<string, unknown> => (e.data ?? {}) as Record<string, unknown>;
|
|
36
|
+
|
|
37
|
+
function text(entity: TenantEntity, attribute: string | undefined): string | null {
|
|
38
|
+
if (!attribute) return null;
|
|
39
|
+
const raw = attribute === 'name' ? entity.name : dataOf(entity)[attribute];
|
|
40
|
+
if (raw === undefined || raw === null || raw === '') return null;
|
|
41
|
+
return String(raw);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** `config.display` (may be absent) + a row -> what to show. */
|
|
45
|
+
export function resolveDisplay(config: TypeDisplayConfig | undefined | null, entity: TenantEntity): RowDisplay {
|
|
46
|
+
const title = text(entity, config?.title) ?? (entity.name || String(entity.external_id ?? entity.externalId ?? entity.id));
|
|
47
|
+
const status = text(entity, config?.status);
|
|
48
|
+
return {
|
|
49
|
+
title,
|
|
50
|
+
subtitle: text(entity, config?.subtitle),
|
|
51
|
+
date: text(entity, config?.date),
|
|
52
|
+
status: status ? { value: status, tone: config?.tones?.[status] ?? 'neutral' } : null,
|
|
53
|
+
icon: config?.icon ?? null,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** `schema/types` rows -> `{ [type key]: declaration }` for the types that declare one. */
|
|
58
|
+
export function displaysFrom(rows: SchemaTypeRow[]): Record<string, TypeDisplayConfig> {
|
|
59
|
+
const out: Record<string, TypeDisplayConfig> = {};
|
|
60
|
+
for (const row of rows) if (row.config?.display) out[row.key] = row.config.display;
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The fake tenant's `GET api/v1/entities/counts` - the same contract as
|
|
3
|
+
* `tenant-starter/apps/api/counts.py`: group the (already filtered) rows by up to
|
|
4
|
+
* two keys - `type`, `attr.<name>`, `edge:<rel>[:out|in]` - and count them.
|
|
5
|
+
* `edge_targets` narrows an edge key to those far-end ids. Rows are `{values, count}` by
|
|
6
|
+
* POSITION with `group_by` echoed, never keyed by token (the apps' client camelCases keys).
|
|
7
|
+
*/
|
|
8
|
+
import type { TenantEntity, TenantRelationship } from '../../corpus/entities';
|
|
9
|
+
|
|
10
|
+
type Params = Record<string, unknown>;
|
|
11
|
+
|
|
12
|
+
const dataOf = (e: TenantEntity): Record<string, unknown> => (e.data ?? {}) as Record<string, unknown>;
|
|
13
|
+
const typeOf = (e: TenantEntity) => String(e.entity_type ?? e.entityType ?? '');
|
|
14
|
+
const ids = (v: unknown) => String(v ?? '').split(',').map((s) => s.trim()).filter(Boolean);
|
|
15
|
+
|
|
16
|
+
function keysFor(token: string, entity: TenantEntity, edges: TenantRelationship[], targets: string[] | null): Array<string | number | boolean | null> {
|
|
17
|
+
if (token === 'type') return [typeOf(entity)];
|
|
18
|
+
if (token.startsWith('attr.')) {
|
|
19
|
+
const v = dataOf(entity)[token.slice(5)];
|
|
20
|
+
return [v === undefined || v === '' ? null : (v as string | number | boolean)];
|
|
21
|
+
}
|
|
22
|
+
const [, rel, direction = 'out'] = token.split(':');
|
|
23
|
+
const far = edges
|
|
24
|
+
.filter((r) => String(r.rel_type ?? r.relType) === rel && String(direction === 'out' ? r.source : r.target) === String(entity.id))
|
|
25
|
+
.map((r) => String(direction === 'out' ? r.target : r.source))
|
|
26
|
+
.filter((id) => !targets || targets.includes(id));
|
|
27
|
+
if (targets) return far;
|
|
28
|
+
return far.length ? far : [null];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** `rows` are the entities that passed the list's filters. */
|
|
32
|
+
export function groupCounts(rows: TenantEntity[], edges: TenantRelationship[], params: Params) {
|
|
33
|
+
const tokens = ids(params.group_by);
|
|
34
|
+
if (!tokens.length || tokens.length > 2) throw Object.assign(new Error('group_by: name one or two keys'), { status: 400 });
|
|
35
|
+
const known = (t: string) => t === 'type' || t.startsWith('attr.') || t.startsWith('edge:');
|
|
36
|
+
if (!tokens.every(known)) throw Object.assign(new Error(`group_by: unknown key in ${tokens.join(',')}`), { status: 400 });
|
|
37
|
+
const targets = params.edge_targets !== undefined ? ids(params.edge_targets) : null;
|
|
38
|
+
const hasEdge = tokens.some((t) => t.startsWith('edge:'));
|
|
39
|
+
const tally = new Map<string, { values: Array<string | number | boolean | null>; count: number }>();
|
|
40
|
+
for (const entity of rows) {
|
|
41
|
+
let combos: Array<Array<string | number | boolean | null>> = [[]];
|
|
42
|
+
for (const token of tokens) {
|
|
43
|
+
const keys = keysFor(token, entity, edges, token.startsWith('edge:') ? targets : null);
|
|
44
|
+
combos = combos.flatMap((c) => keys.map((k) => [...c, k]));
|
|
45
|
+
}
|
|
46
|
+
for (const combo of combos) {
|
|
47
|
+
const id = JSON.stringify(combo);
|
|
48
|
+
const hit = tally.get(id) ?? { values: combo, count: 0 };
|
|
49
|
+
hit.count += 1;
|
|
50
|
+
tally.set(id, hit);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const order = (a: unknown, b: unknown) => (a === null ? 1 : b === null ? -1 : String(a).localeCompare(String(b)));
|
|
54
|
+
const results = [...tally.values()].sort((a, b) => {
|
|
55
|
+
for (let i = 0; i < tokens.length; i += 1) { const c = order(a.values[i], b.values[i]); if (c) return c; }
|
|
56
|
+
return 0;
|
|
57
|
+
});
|
|
58
|
+
return { tokens, results, applied: ['group_by', ...(targets && hasEdge ? ['edge_targets'] : [])], ignored: targets && !hasEdge ? ['edge_targets'] : [] };
|
|
59
|
+
}
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import type { TenantEntity, TenantRelationship } from '../../corpus/entities';
|
|
12
12
|
import { MAX_PAGE_SIZE } from '../../corpus/entity-query';
|
|
13
|
+
import { groupCounts } from './fake-counts';
|
|
13
14
|
import { REFRESH_ROW_TITLE } from './fake-scenarios';
|
|
14
15
|
import type { AuthorizedHttp } from '../voice/http';
|
|
15
16
|
|
|
@@ -22,6 +23,8 @@ export interface FakeTenantOptions {
|
|
|
22
23
|
/** Filter names this "tenant" does not understand: reported ignored, never applied. */
|
|
23
24
|
unsupported?: string[];
|
|
24
25
|
onRequest?: (method: string, path: string, params: Params) => void;
|
|
26
|
+
/** Rows of `schema/types` (default: the sample commitment display). */
|
|
27
|
+
schemaTypes?: Array<{ key: string; label?: string; config?: Record<string, unknown> }>;
|
|
25
28
|
/** Each entity list read a second time (same query) also returns one new row, so a refresh is visible. */
|
|
26
29
|
newRowOnReread?: boolean;
|
|
27
30
|
}
|
|
@@ -84,6 +87,11 @@ function pageOf<T>(rows: T[], params: Params, fallback: number) {
|
|
|
84
87
|
};
|
|
85
88
|
}
|
|
86
89
|
|
|
90
|
+
const SAMPLE_SCHEMA_TYPES = [
|
|
91
|
+
{ key: 'commitment', label: 'To-do', config: { display: { title: 'title', subtitle: 'owner_name', date: 'due_at', status: 'status', tones: { done: 'good', blocked: 'bad', open: 'info' }, icon: 'check-circle' } } },
|
|
92
|
+
{ key: 'focus', label: 'Project', config: {} },
|
|
93
|
+
];
|
|
94
|
+
|
|
87
95
|
export interface FakeTenant {
|
|
88
96
|
http: AuthorizedHttp;
|
|
89
97
|
requests: Array<{ method: string; path: string; params: Params }>;
|
|
@@ -97,7 +105,7 @@ export function createFakeTenantHttp(options: FakeTenantOptions = {}): FakeTenan
|
|
|
97
105
|
const requests: Array<{ method: string; path: string; params: Params }> = [];
|
|
98
106
|
let seq = 0;
|
|
99
107
|
|
|
100
|
-
function list(params: Params) {
|
|
108
|
+
function list(params: Params, unpaged = false) {
|
|
101
109
|
const applied: string[] = [];
|
|
102
110
|
const ignored: string[] = [];
|
|
103
111
|
const ok = (key: string) => key in params && !unsupported.has(key);
|
|
@@ -105,6 +113,7 @@ export function createFakeTenantHttp(options: FakeTenantOptions = {}): FakeTenan
|
|
|
105
113
|
const narrow = (key: string, test: (e: TenantEntity) => boolean) => { rows = rows.filter(test); applied.push(key); };
|
|
106
114
|
|
|
107
115
|
if (ok('type')) narrow('type', (e) => typeOf(e) === String(params.type));
|
|
116
|
+
if (ok('type__in')) { const w = asList(params.type__in); narrow('type__in', (e) => w.includes(typeOf(e))); }
|
|
108
117
|
if (ok('id')) narrow('id', (e) => String(e.id) === String(params.id));
|
|
109
118
|
if (ok('id__in')) { const w = asList(params.id__in); narrow('id__in', (e) => w.includes(String(e.id))); }
|
|
110
119
|
if (ok('external_id')) narrow('external_id', (e) => String(e.external_id ?? e.externalId) === String(params.external_id));
|
|
@@ -116,6 +125,10 @@ export function createFakeTenantHttp(options: FakeTenantOptions = {}): FakeTenan
|
|
|
116
125
|
] as const) {
|
|
117
126
|
if (ok(key)) narrow(key, (e) => { const v = String(dataOf(e)[field] ?? ''); return v !== '' && (after ? v >= String(params[key]) : v <= String(params[key])); });
|
|
118
127
|
}
|
|
128
|
+
if (ok('updated_after')) {
|
|
129
|
+
const stamp = (e: TenantEntity) => String((e as { updated_at?: string }).updated_at ?? created(e));
|
|
130
|
+
narrow('updated_after', (e) => stamp(e) > String(params.updated_after));
|
|
131
|
+
}
|
|
119
132
|
for (const [key, after] of [['created_after', true], ['created_before', false]] as const) {
|
|
120
133
|
if (ok(key)) narrow(key, (e) => (after ? created(e) >= String(params[key]) : created(e) <= String(params[key])));
|
|
121
134
|
}
|
|
@@ -188,11 +201,12 @@ export function createFakeTenantHttp(options: FakeTenantOptions = {}): FakeTenan
|
|
|
188
201
|
if (NOT_FILTERS.has(key) || applied.includes(key) || ignored.includes(key)) continue;
|
|
189
202
|
ignored.push(key);
|
|
190
203
|
}
|
|
191
|
-
|
|
204
|
+
const everything = unpaged ? { count: rows.length, next: null, previous: null, results: rows } : pageOf(rows, params, pageSize);
|
|
205
|
+
return { ...everything, applied_filters: applied, ignored_filters: ignored };
|
|
192
206
|
}
|
|
193
207
|
|
|
194
208
|
function facets(params: Params) {
|
|
195
|
-
const base = list({ ...params, attr: undefined, under: undefined
|
|
209
|
+
const base = list({ ...params, attr: undefined, under: undefined } as Params, true);
|
|
196
210
|
// Re-run the row filter over every page: `list` is paged, so ask for it all in-process.
|
|
197
211
|
const rows = (base as { results: TenantEntity[] }).results;
|
|
198
212
|
const attr = String(params.attr ?? '');
|
|
@@ -218,6 +232,18 @@ export function createFakeTenantHttp(options: FakeTenantOptions = {}): FakeTenan
|
|
|
218
232
|
return { ...pageOf(results, params, pageSize), applied_filters: [...base.applied_filters.filter((k) => k !== 'order'), 'attr', 'under'], ignored_filters: [] as string[] };
|
|
219
233
|
}
|
|
220
234
|
|
|
235
|
+
function counts(params: Params) {
|
|
236
|
+
const { group_by: _g, edge_targets: _t, ...filters } = params;
|
|
237
|
+
const base = list(filters as Params, true);
|
|
238
|
+
const grouped = groupCounts((base as { results: TenantEntity[] }).results, relationships, params);
|
|
239
|
+
return {
|
|
240
|
+
...pageOf(grouped.results, params, pageSize),
|
|
241
|
+
group_by: grouped.tokens,
|
|
242
|
+
applied_filters: [...base.applied_filters.filter((k) => k !== 'order'), ...grouped.applied],
|
|
243
|
+
ignored_filters: [...base.ignored_filters, ...grouped.ignored],
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
221
247
|
function edges(params: Params) {
|
|
222
248
|
const applied: string[] = [];
|
|
223
249
|
const ignored: string[] = [];
|
|
@@ -262,6 +288,8 @@ export function createFakeTenantHttp(options: FakeTenantOptions = {}): FakeTenan
|
|
|
262
288
|
const p = path.replace(/^\/+|\/+$/g, '');
|
|
263
289
|
if (p === 'api/v1/relationships') return edges(params) as T;
|
|
264
290
|
if (p === 'api/v1/entities/facets') return facets(params) as T;
|
|
291
|
+
if (p === 'api/v1/entities/counts') return counts(params) as T;
|
|
292
|
+
if (p === 'api/v1/schema/types') return pageOf(options.schemaTypes ?? SAMPLE_SCHEMA_TYPES, params, pageSize) as T;
|
|
265
293
|
if (p === 'api/v1/entities') return reread(params, list(params)) as T;
|
|
266
294
|
const detail = /^api\/v1\/entities\/(.+)$/.exec(p);
|
|
267
295
|
if (detail) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
2
|
import { FlatList, Pressable, RefreshControl, View } from 'react-native';
|
|
3
|
-
import { Alert, Button, EmptyState, ListRow, Skeleton, StatTile,
|
|
3
|
+
import { Alert, Button, EmptyState, Header, IconTile, ListRow, SectionHeader, Skeleton, StatTile, useTheme, type IconName } from '@startsimpli/ui-native';
|
|
4
4
|
import { useControllerState } from '../components/useControllerState';
|
|
5
5
|
import { timeAgo, type HomeArrival, type HomeController } from './controller';
|
|
6
6
|
|
|
@@ -25,21 +25,19 @@ export function HomeScreen({ controller, brand, tagline, onRecord, onOpenType, o
|
|
|
25
25
|
const s = useControllerState(controller);
|
|
26
26
|
useEffect(() => { if (active) void controller.load(); }, [controller, active]);
|
|
27
27
|
return (
|
|
28
|
+
<View style={{ flex: 1 }}>
|
|
29
|
+
<Header large title={brand} subtitle={tagline} />
|
|
28
30
|
<FlatList
|
|
29
31
|
testID="home-list"
|
|
30
32
|
data={s.arrivals}
|
|
31
33
|
keyExtractor={(a) => `${a.type}-${a.id}`}
|
|
32
34
|
refreshControl={<RefreshControl refreshing={false} onRefresh={() => { void controller.refresh(); }} tintColor={theme.colors.mutedForeground} />}
|
|
33
|
-
contentContainerStyle={{
|
|
35
|
+
contentContainerStyle={{ paddingHorizontal: theme.layout.gutter, paddingBottom: theme.spacing.xl, flexGrow: 1 }}
|
|
34
36
|
ListHeaderComponent={
|
|
35
|
-
<View style={{ gap: theme.spacing.
|
|
36
|
-
<
|
|
37
|
-
<Text variant="heading">{brand}</Text>
|
|
38
|
-
{tagline ? <Text variant="muted">{tagline}</Text> : null}
|
|
39
|
-
</View>
|
|
40
|
-
{onRecord ? <Button testID="home-record" title="Record a note" onPress={onRecord} /> : null}
|
|
37
|
+
<View style={{ gap: theme.spacing.xs, paddingBottom: theme.spacing.xs }}>
|
|
38
|
+
{onRecord ? <Button testID="home-record" title="Record a note" size="lg" style={{ marginTop: theme.spacing.sm }} onPress={onRecord} /> : null}
|
|
41
39
|
{s.error ? <Alert variant="destructive">{s.error}</Alert> : null}
|
|
42
|
-
<
|
|
40
|
+
<SectionHeader title="What has come in" />
|
|
43
41
|
<View style={{ flexDirection: 'row', gap: theme.spacing.sm }}>
|
|
44
42
|
{s.metrics.map((m) => (
|
|
45
43
|
<View key={m.key} style={{ flex: 1, minWidth: 0 }} testID={`home-metric-${m.key}`}>
|
|
@@ -51,17 +49,22 @@ export function HomeScreen({ controller, brand, tagline, onRecord, onOpenType, o
|
|
|
51
49
|
</View>
|
|
52
50
|
))}
|
|
53
51
|
</View>
|
|
54
|
-
<
|
|
52
|
+
<SectionHeader title="Latest arrivals" />
|
|
55
53
|
</View>
|
|
56
54
|
}
|
|
57
|
-
ListEmptyComponent={s.loading ? null : <EmptyState title="No records yet" description="Record a note to get started." />}
|
|
55
|
+
ListEmptyComponent={s.loading ? null : <EmptyState icon="note" title="No records yet" description="Record a note to get started." />}
|
|
58
56
|
renderItem={({ item }) => (
|
|
59
57
|
<ListRow
|
|
58
|
+
leading={<IconTile icon={ARRIVAL_ICON[item.type] ?? 'dot'} tone={item.type === 'commitment' ? 'success' : item.type === 'focus' ? 'warning' : 'info'} />}
|
|
59
|
+
eyebrow={item.typeLabel || undefined}
|
|
60
60
|
title={item.title}
|
|
61
|
-
|
|
61
|
+
meta={timeAgo(item.createdAt, now())}
|
|
62
62
|
onPress={onOpenArrival ? () => onOpenArrival(item) : undefined}
|
|
63
63
|
/>
|
|
64
64
|
)}
|
|
65
65
|
/>
|
|
66
|
+
</View>
|
|
66
67
|
);
|
|
67
68
|
}
|
|
69
|
+
|
|
70
|
+
const ARRIVAL_ICON: Record<string, IconName> = { commitment: 'check', source_document: 'note', focus: 'planning' };
|
|
@@ -10,17 +10,16 @@ const types = [
|
|
|
10
10
|
];
|
|
11
11
|
|
|
12
12
|
describe('home controller: what has come in', () => {
|
|
13
|
-
it('
|
|
13
|
+
it('every type count comes from ONE grouped read', async () => {
|
|
14
14
|
const api = createFakeNativeCorpusApi();
|
|
15
15
|
const c = createHomeController({ api, types, now: () => NOW });
|
|
16
16
|
await c.load();
|
|
17
17
|
const s = c.getState();
|
|
18
18
|
expect(s.metrics.map((m) => [m.label, m.count])).toEqual([['To-dos', 6], ['Documents', 3], ['Projects', 3]]);
|
|
19
|
-
|
|
20
|
-
expect(counts).toHaveLength(3);
|
|
19
|
+
expect(api.tenant.requests.filter((r) => r.path.endsWith('entities/counts'))).toHaveLength(1);
|
|
21
20
|
});
|
|
22
21
|
|
|
23
|
-
it('latest arrivals: newest first across types
|
|
22
|
+
it('latest arrivals: newest first across types in ONE bounded read', async () => {
|
|
24
23
|
const api = createFakeNativeCorpusApi();
|
|
25
24
|
const c = createHomeController({ api, types, limit: 4, now: () => NOW });
|
|
26
25
|
await c.load();
|
|
@@ -30,21 +29,35 @@ describe('home controller: what has come in', () => {
|
|
|
30
29
|
const stamps = s.arrivals.map((a) => a.createdAt);
|
|
31
30
|
expect([...stamps].sort().reverse()).toEqual(stamps);
|
|
32
31
|
const pages = api.tenant.requests.filter((r) => r.params?.order === 'recent');
|
|
33
|
-
expect(pages
|
|
34
|
-
expect(pages.
|
|
35
|
-
expect(s.arrivals[0]).toMatchObject({ type:
|
|
32
|
+
expect(pages).toHaveLength(1);
|
|
33
|
+
expect(pages[0].params).toMatchObject({ type__in: 'commitment,source_document,focus', page_size: 4 });
|
|
34
|
+
expect(s.arrivals[0]).toMatchObject({ type: 'commitment', typeLabel: 'To-dos' });
|
|
36
35
|
});
|
|
37
36
|
|
|
38
|
-
it('
|
|
39
|
-
const api = createFakeNativeCorpusApi(
|
|
37
|
+
it('the whole Home is two requests however many types it summarises', async () => {
|
|
38
|
+
const api = createFakeNativeCorpusApi();
|
|
39
|
+
await createHomeController({ api, types, now: () => NOW }).load();
|
|
40
|
+
expect(api.tenant.requests).toHaveLength(2);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('a failed counts read shows no count instead of a false zero; arrivals still load', async () => {
|
|
44
|
+
const api = createFakeNativeCorpusApi({ onRequest: (_m, path) => { if (path.endsWith('counts')) throw new Error('boom'); } });
|
|
40
45
|
const c = createHomeController({ api, types, now: () => NOW });
|
|
41
46
|
await c.load();
|
|
42
47
|
const s = c.getState();
|
|
43
|
-
expect(s.metrics.
|
|
44
|
-
expect(s.
|
|
48
|
+
expect(s.metrics.every((m) => m.count === null)).toBe(true);
|
|
49
|
+
expect(s.arrivals.length).toBeGreaterThan(0);
|
|
50
|
+
expect(s.error).toBeNull();
|
|
45
51
|
expect(s.loading).toBe(false);
|
|
46
52
|
});
|
|
47
53
|
|
|
54
|
+
it('when both reads fail Home says so', async () => {
|
|
55
|
+
const api = createFakeNativeCorpusApi({ onRequest: () => { throw new Error('boom'); } });
|
|
56
|
+
const c = createHomeController({ api, types, now: () => NOW });
|
|
57
|
+
await c.load();
|
|
58
|
+
expect(c.getState().error).toBe('Could not load your workspace.');
|
|
59
|
+
});
|
|
60
|
+
|
|
48
61
|
it('refresh reloads', async () => {
|
|
49
62
|
const api = createFakeNativeCorpusApi();
|
|
50
63
|
const c = createHomeController({ api, types, now: () => NOW });
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The Home tab's data: what the web Home shows ("What has come in" metrics and
|
|
3
3
|
* "Latest arrivals"), as a framework-free controller. Counts are the server's
|
|
4
|
-
*
|
|
5
|
-
* (server `order=recent`)
|
|
4
|
+
* grouped `entities/counts` read (one request for every type); arrivals are the
|
|
5
|
+
* newest page across the types (`type__in`, server `order=recent`). Two requests
|
|
6
|
+
* for the screen, however many types. Nothing here loads a full list.
|
|
6
7
|
*/
|
|
7
8
|
import type { TenantEntity } from '../../corpus/entities';
|
|
8
9
|
import type { NativeCorpusApi } from '../corpus/api';
|
|
10
|
+
import { countsBy } from '../corpus/counts';
|
|
9
11
|
|
|
10
12
|
export interface HomeType { key: string; label: string }
|
|
11
13
|
|
|
@@ -65,24 +67,28 @@ export function createHomeController({ api, types, limit = 8 }: HomeControllerOp
|
|
|
65
67
|
const set = (patch: Partial<HomeState>) => { state = { ...state, ...patch }; listeners.forEach((l) => l()); };
|
|
66
68
|
|
|
67
69
|
async function load() {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
70
|
+
// TWO reads for the whole screen, however many types it summarises: the count
|
|
71
|
+
// per type (one grouped read) and the newest rows across those types.
|
|
72
|
+
const [counts, recent] = await Promise.all([
|
|
73
|
+
api.entities.counts({ groupBy: ['type'], filters: { typeIn: types.map((t) => t.key) } })
|
|
74
|
+
.then((p) => countsBy(p.items, 'type')).catch(() => null),
|
|
75
|
+
api.entities.list({ filters: { typeIn: types.map((t) => t.key) }, order: 'recent', pageSize: limit })
|
|
76
|
+
.then((p) => p.items).catch(() => null),
|
|
77
|
+
]);
|
|
78
|
+
const label = new Map(types.map((t) => [t.key, t.label]));
|
|
79
|
+
const arrivals = (recent ?? []).map((entity): HomeArrival => {
|
|
80
|
+
const type = String(entity.entity_type ?? entity.entityType ?? '');
|
|
81
|
+
return {
|
|
82
|
+
id: String(entity.id), type, typeLabel: label.get(type) ?? type,
|
|
83
|
+
title: entity.name || entity.external_id || `#${entity.id}`, createdAt: stamp(entity), entity,
|
|
84
|
+
};
|
|
85
|
+
});
|
|
81
86
|
set({
|
|
82
87
|
loading: false,
|
|
83
|
-
|
|
88
|
+
// A type with no rows is absent from the grouped answer: zero there, null only when the read failed.
|
|
89
|
+
metrics: types.map((t) => ({ key: t.key, label: t.label, count: counts ? (counts[t.key] ?? 0) : null })),
|
|
84
90
|
arrivals,
|
|
85
|
-
error:
|
|
91
|
+
error: counts === null && recent === null ? 'Could not load your workspace.' : null,
|
|
86
92
|
});
|
|
87
93
|
}
|
|
88
94
|
|
package/src/native/index.ts
CHANGED
|
@@ -19,6 +19,8 @@ export * from './app';
|
|
|
19
19
|
export * from './shell/navigator';
|
|
20
20
|
export * from './shell/overflow';
|
|
21
21
|
export * from './corpus/api';
|
|
22
|
+
export * from './corpus/counts';
|
|
23
|
+
export * from './corpus/display';
|
|
22
24
|
export * from './corpus/ask';
|
|
23
25
|
export * from './corpus/paged';
|
|
24
26
|
export * from './corpus/fake';
|
|
@@ -47,7 +49,7 @@ export { AskScreen, type AskScreenProps } from './screens/ask/AskScreen';
|
|
|
47
49
|
export * from './screens/tabs';
|
|
48
50
|
// Planning, Connections, Connect Claude (bd startsim-23np6.1.6)
|
|
49
51
|
export {
|
|
50
|
-
createFocusDetailController, createPlanningController,
|
|
52
|
+
createFocusDetailController, createPlanningController,
|
|
51
53
|
type FocusDetailController, type FocusDetailState, type PlanningController, type PlanningScreenApi, type PlanningState,
|
|
52
54
|
} from './screens/planning/controller';
|
|
53
55
|
export { createFakePlanningApi } from './screens/planning/fake';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { FlatList, Pressable, View } from 'react-native';
|
|
3
|
-
import { Alert,
|
|
3
|
+
import { Alert, Button, ChatComposer, EmptyState, Header, ListRow, MessageBubble, Section, Select, Text, useTheme } from '@startsimpli/ui-native';
|
|
4
4
|
import { useControllerState as useStore } from '../../components/useControllerState';
|
|
5
5
|
import type { AnswerView } from './answer-view';
|
|
6
6
|
import type { AskController, AskMessage } from './controller';
|
|
@@ -21,7 +21,7 @@ export function AskScreen({ controller, onOpenDocument }: AskScreenProps) {
|
|
|
21
21
|
|
|
22
22
|
return (
|
|
23
23
|
<View style={{ flex: 1 }}>
|
|
24
|
-
<Header testID="ask-header" title="Ask" subtitle={scope ? `Scoped to ${scope}` : 'All projects'} />
|
|
24
|
+
<Header large testID="ask-header" title="Ask" subtitle={scope ? `Scoped to ${scope}` : 'All projects'} />
|
|
25
25
|
{s.projects.length ? (
|
|
26
26
|
<View style={{ paddingHorizontal: theme.spacing.lg, paddingBottom: theme.spacing.sm, flexDirection: 'row' }}>
|
|
27
27
|
<Select
|
|
@@ -46,7 +46,7 @@ export function AskScreen({ controller, onOpenDocument }: AskScreenProps) {
|
|
|
46
46
|
onContentSizeChange={() => list.current?.scrollToEnd?.({ animated: true })}
|
|
47
47
|
contentContainerStyle={{ padding: theme.spacing.lg, gap: theme.spacing.md, flexGrow: 1 }}
|
|
48
48
|
ListEmptyComponent={
|
|
49
|
-
<EmptyState icon="
|
|
49
|
+
<EmptyState icon="ask" title="Ask your documents" description="Answers come from your notes, meetings and files, with the records they used." />
|
|
50
50
|
}
|
|
51
51
|
renderItem={({ item }) => <Message message={item} onRetry={() => { void controller.retry(item.id); }} onOpenDocument={onOpenDocument} />}
|
|
52
52
|
/>
|
|
@@ -81,25 +81,23 @@ function Sources({ view, onOpenDocument }: { view: AnswerView; onOpenDocument: (
|
|
|
81
81
|
const [showUncited, setShowUncited] = useState(false);
|
|
82
82
|
const n = view.citations.length;
|
|
83
83
|
return (
|
|
84
|
-
<View style={{ gap: theme.spacing.
|
|
85
|
-
{
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
</Pressable>
|
|
102
|
-
))}
|
|
84
|
+
<View style={{ gap: theme.spacing.xs }}>
|
|
85
|
+
{n > 0 ? (
|
|
86
|
+
<Section title={`${n} source${n === 1 ? '' : 's'}`}>
|
|
87
|
+
{view.citations.map((c) => (
|
|
88
|
+
<ListRow
|
|
89
|
+
key={c.documentId}
|
|
90
|
+
testID={`ask-citation-${c.documentId}`}
|
|
91
|
+
accessibilityLabel={`Open ${c.title}`}
|
|
92
|
+
eyebrow={c.sourceLabel}
|
|
93
|
+
title={c.title}
|
|
94
|
+
preview={c.quote ? `“${c.quote}”` : undefined}
|
|
95
|
+
meta={c.dateLabel || undefined}
|
|
96
|
+
onPress={() => onOpenDocument(c.documentId)}
|
|
97
|
+
/>
|
|
98
|
+
))}
|
|
99
|
+
</Section>
|
|
100
|
+
) : null}
|
|
103
101
|
{view.uncited.length ? (
|
|
104
102
|
<View style={{ gap: theme.spacing.xs }}>
|
|
105
103
|
<Pressable accessibilityRole="button" testID="ask-uncited-toggle" onPress={() => setShowUncited((v) => !v)}>
|