@startsimpli/integrations 0.2.105 → 0.2.107
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/native/app/FoundryApp.tsx +38 -14
- package/src/native/app/__tests__/haptics.test.tsx +48 -0
- package/src/native/app/__tests__/hapticsExpo.test.ts +27 -0
- package/src/native/app/__tests__/registry.test.tsx +14 -1
- package/src/native/app/__tests__/schemaLoad.test.ts +28 -0
- package/src/native/app/config/__tests__/schema.test.ts +96 -0
- package/src/native/app/config/__tests__/validate.test.ts +12 -2
- package/src/native/app/config/defaults.ts +11 -11
- package/src/native/app/config/index.ts +1 -0
- package/src/native/app/config/schema.ts +62 -0
- package/src/native/app/config/types.ts +2 -0
- package/src/native/app/config/validate.ts +7 -1
- package/src/native/app/device.ts +5 -0
- package/src/native/app/entity/EntityTab.tsx +50 -19
- package/src/native/app/entity/__tests__/EntityTab.test.tsx +61 -0
- package/src/native/app/entity/__tests__/format.test.ts +42 -0
- package/src/native/app/entity/format.ts +38 -12
- package/src/native/app/haptics.ts +30 -0
- package/src/native/app/index.ts +1 -0
- package/src/native/app/registry.tsx +5 -2
- package/src/native/app/schemaLoad.ts +37 -0
- package/src/native/app/screens/ShellBanners.tsx +11 -6
- package/src/native/app/screens/SignInScreen.tsx +2 -2
- package/src/native/components/NoteDetailScreen.tsx +3 -2
- package/src/native/components/usePullRefresh.tsx +4 -2
- package/src/native/corpus/__tests__/display.test.ts +36 -1
- package/src/native/corpus/api.ts +12 -8
- package/src/native/corpus/display.ts +37 -1
- package/src/native/corpus/fake-tenant.ts +2 -1
- package/src/native/home/HomeScreen.tsx +6 -5
- package/src/native/home/__tests__/controller.test.ts +32 -0
- package/src/native/home/controller.ts +11 -6
- package/src/native/home/tab.tsx +2 -2
- package/src/native/screens/__tests__/displayView.test.ts +21 -0
- package/src/native/screens/shared/displayView.ts +23 -0
|
@@ -1,20 +1,35 @@
|
|
|
1
1
|
import { useEffect, useMemo, useState } from 'react';
|
|
2
|
-
import { View } from 'react-native';
|
|
3
|
-
import {
|
|
2
|
+
import { Text as RNText, View } from 'react-native';
|
|
3
|
+
import { DataList, DetailScreen, Header, IconTile, ListRow, Section, StatusChip, useTheme } from '@startsimpli/ui-native';
|
|
4
4
|
import type { TenantEntity } from '../../../corpus/entities';
|
|
5
5
|
import type { FoundryTab, TabContext } from '../../components/FoundryTabsShell';
|
|
6
6
|
import { useControllerState } from '../../components/useControllerState';
|
|
7
|
+
import { usePullRefresh } from '../../components/usePullRefresh';
|
|
7
8
|
import type { NativeCorpusApi } from '../../corpus/api';
|
|
9
|
+
import { layerDisplays, type TypeDisplayConfig } from '../../corpus/display';
|
|
10
|
+
import { iconName, toneKey, whenText } from '../../screens/shared/displayView';
|
|
8
11
|
import type { FoundryEntityType } from '../config/types';
|
|
9
12
|
import { entityFields, entityRow, type EntityRowView } from './format';
|
|
10
13
|
|
|
11
|
-
type Api = Pick<NativeCorpusApi, 'entities' | 'lists'
|
|
14
|
+
type Api = Pick<NativeCorpusApi, 'entities' | 'lists'> & Partial<Pick<NativeCorpusApi, 'schema'>>;
|
|
15
|
+
|
|
16
|
+
/** The type's declared display (tenant schema over the built-in defaults); the default alone until the schema answers or when it cannot. */
|
|
17
|
+
function useTypeDisplay(api: Api, type: string): TypeDisplayConfig | undefined {
|
|
18
|
+
const [declared, setDeclared] = useState<Record<string, TypeDisplayConfig> | null>(null);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
let live = true;
|
|
21
|
+
api.schema?.displays().then((d) => { if (live) setDeclared(d); }, () => undefined);
|
|
22
|
+
return () => { live = false; };
|
|
23
|
+
}, [api]);
|
|
24
|
+
return useMemo(() => layerDisplays(declared)[type], [declared, type]);
|
|
25
|
+
}
|
|
12
26
|
|
|
13
27
|
function EntityList({ api, type, spec, onOpen }: { api: Api; type: string; spec: FoundryEntityType; onOpen: (id: string) => void }) {
|
|
14
28
|
const list = useMemo(() => api.lists.entities({ type }), [api, type]);
|
|
15
29
|
const state = useControllerState(list);
|
|
30
|
+
const display = useTypeDisplay(api, type);
|
|
16
31
|
useEffect(() => { void list.refresh(); }, [list]);
|
|
17
|
-
const rows = useMemo(() => state.items.map((e) => entityRow(e, spec)), [state.items, spec]);
|
|
32
|
+
const rows = useMemo(() => state.items.map((e) => entityRow(e, spec, display)), [state.items, spec, display]);
|
|
18
33
|
const plural = spec.plural ?? `${spec.label}s`;
|
|
19
34
|
return (
|
|
20
35
|
<View style={{ flex: 1 }} testID={`entity-${type}-screen`}>
|
|
@@ -26,10 +41,11 @@ function EntityList({ api, type, spec, onOpen }: { api: Api; type: string; spec:
|
|
|
26
41
|
renderItem={({ item }) => (
|
|
27
42
|
<View testID={`entity-${item.id}`}>
|
|
28
43
|
<ListRow
|
|
29
|
-
leading={<IconTile icon=
|
|
44
|
+
leading={<IconTile icon={iconName(item.icon, 'note')} tone={item.status ? toneKey(item.tone) : 'info'} />}
|
|
30
45
|
title={item.title}
|
|
31
46
|
subtitle={item.subtitle}
|
|
32
|
-
|
|
47
|
+
meta={whenText(item.date)}
|
|
48
|
+
trailing={item.status ? <StatusChip status={item.status} tone={toneKey(item.tone)} /> : undefined}
|
|
33
49
|
onPress={() => onOpen(item.id)}
|
|
34
50
|
/>
|
|
35
51
|
</View>
|
|
@@ -48,38 +64,53 @@ function EntityList({ api, type, spec, onOpen }: { api: Api; type: string; spec:
|
|
|
48
64
|
);
|
|
49
65
|
}
|
|
50
66
|
|
|
51
|
-
function EntityDetail({ api, spec, id, onBack }: { api: Api; spec: FoundryEntityType; id: string; onBack: () => void }) {
|
|
67
|
+
function EntityDetail({ api, type, spec, id, onBack }: { api: Api; type: string; spec: FoundryEntityType; id: string; onBack: () => void }) {
|
|
68
|
+
const theme = useTheme();
|
|
69
|
+
const display = useTypeDisplay(api, type);
|
|
52
70
|
const [entity, setEntity] = useState<TenantEntity | null>(null);
|
|
53
71
|
const [error, setError] = useState<string | null>(null);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
setEntity(null);
|
|
57
|
-
setError(null);
|
|
58
|
-
api.entities.get(id).then((e) => { if (live) setEntity(e); }, (e: unknown) => { if (live) setError(e instanceof Error ? e.message : 'Could not load this record.'); });
|
|
59
|
-
return () => { live = false; };
|
|
72
|
+
const load = useMemo(() => async () => {
|
|
73
|
+
try { setEntity(await api.entities.get(id)); setError(null); } catch (e: unknown) { setError(e instanceof Error ? e.message : 'Could not load this record.'); }
|
|
60
74
|
}, [api, id]);
|
|
61
|
-
|
|
75
|
+
useEffect(() => { setEntity(null); setError(null); void load(); }, [load]);
|
|
76
|
+
const refreshControl = usePullRefresh(load);
|
|
77
|
+
const row = entity ? entityRow(entity, spec, display) : null;
|
|
78
|
+
const fields = entity ? entityFields(entity, display) : [];
|
|
79
|
+
const facts = fields.filter((f) => !f.long);
|
|
80
|
+
const prose = fields.filter((f) => f.long);
|
|
62
81
|
return (
|
|
63
82
|
<DetailScreen
|
|
64
83
|
title={spec.label}
|
|
65
84
|
onBack={onBack}
|
|
66
85
|
headerTestID="entity-detail"
|
|
86
|
+
refreshControl={refreshControl}
|
|
67
87
|
loading={!entity && !error}
|
|
68
88
|
unavailable={!entity && error ? { title: 'Could not load this record', description: error } : undefined}
|
|
69
|
-
hero={row ? {
|
|
70
|
-
|
|
71
|
-
|
|
89
|
+
hero={row ? {
|
|
90
|
+
eyebrow: spec.label,
|
|
91
|
+
title: row.title,
|
|
92
|
+
subtitle: row.subtitle,
|
|
93
|
+
tags: row.status ? <StatusChip status={row.status} tone={toneKey(row.tone)} /> : undefined,
|
|
94
|
+
} : undefined}
|
|
95
|
+
meta={facts.length ? facts.map((f) => ({ label: f.label, value: f.value, wide: f.value.length > 24 })) : undefined}
|
|
96
|
+
>
|
|
97
|
+
{prose.map((f) => (
|
|
98
|
+
<Section key={f.key} title={f.label}>
|
|
99
|
+
<RNText selectable style={{ color: theme.colors.foreground, paddingVertical: theme.spacing.md, fontSize: 15, lineHeight: 22 }}>{f.value}</RNText>
|
|
100
|
+
</Section>
|
|
101
|
+
))}
|
|
102
|
+
</DetailScreen>
|
|
72
103
|
);
|
|
73
104
|
}
|
|
74
105
|
|
|
75
|
-
/** A tab over any tenant entity type
|
|
106
|
+
/** A tab over any tenant entity type: rows and details read from the type's declared display, with `entityTypes[type]` overriding. */
|
|
76
107
|
export function entityTab({ api, tab, type, spec }: { api: Api; tab: { key: string; label: string }; type: string; spec: FoundryEntityType }): FoundryTab {
|
|
77
108
|
return {
|
|
78
109
|
key: tab.key,
|
|
79
110
|
label: tab.label,
|
|
80
111
|
resetOnLeave: true,
|
|
81
112
|
render: (ctx: TabContext) => (ctx.route
|
|
82
|
-
? <EntityDetail api={api} spec={spec} id={ctx.route.id} onBack={ctx.back} />
|
|
113
|
+
? <EntityDetail api={api} type={type} spec={spec} id={ctx.route.id} onBack={ctx.back} />
|
|
83
114
|
: <EntityList api={api} type={type} spec={spec} onOpen={(id) => ctx.push(id)} />),
|
|
84
115
|
};
|
|
85
116
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { act, allText, render } from '../../../../../../ui-native/test/render';
|
|
3
|
+
import { createFakeNativeCorpusApi } from '../../../corpus/fake';
|
|
4
|
+
import type { TabContext } from '../../../components/FoundryTabsShell';
|
|
5
|
+
import { entityTab } from '../EntityTab';
|
|
6
|
+
|
|
7
|
+
const tick = () => act(async () => { await new Promise((res) => setTimeout(res, 30)); });
|
|
8
|
+
const ctx = (over: Partial<TabContext> = {}): TabContext => ({ tab: 't', active: true, route: null, push: vi.fn(), back: vi.fn(), openTab: vi.fn(), ...over });
|
|
9
|
+
|
|
10
|
+
const invoice = (id: string, extra: Record<string, unknown>) => ({
|
|
11
|
+
id, entity_type: 'invoice', name: `INV-${id}`, created_at: '2026-11-03T10:00:00Z',
|
|
12
|
+
data: { number: `INV-${id}`, client: 'Acme', state: 'overdue', due: '2026-11-05', notes: 'n'.repeat(120), ...extra },
|
|
13
|
+
});
|
|
14
|
+
const api = () => createFakeNativeCorpusApi({
|
|
15
|
+
entities: [invoice('1', {}), invoice('2', { state: 'paid' })],
|
|
16
|
+
schemaTypes: [{ key: 'invoice', label: 'Invoice', config: { display: { title: 'number', subtitle: 'client', date: 'due', status: 'state', tones: { overdue: 'bad', paid: 'good' }, icon: 'note' } } }],
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe('entity tab over a type the client has never heard of', () => {
|
|
20
|
+
it('rows read from the tenant-declared display: title, subtitle, date and status chip', async () => {
|
|
21
|
+
const tab = entityTab({ api: api(), tab: { key: 'invoices', label: 'Invoices' }, type: 'invoice', spec: { label: 'Invoice', plural: 'Invoices' } });
|
|
22
|
+
const r = render(<>{tab.render(ctx())}</>);
|
|
23
|
+
await tick();
|
|
24
|
+
const text = allText(r);
|
|
25
|
+
expect(text).toContain('Invoices');
|
|
26
|
+
expect(text).toContain('INV-1');
|
|
27
|
+
expect(text).toContain('Acme');
|
|
28
|
+
expect(text).toContain('Nov 5');
|
|
29
|
+
expect(text).toMatch(/Overdue/i);
|
|
30
|
+
expect(text).toMatch(/Paid/i);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('the config fields win over the declared display', async () => {
|
|
34
|
+
const tab = entityTab({ api: api(), tab: { key: 'invoices', label: 'Invoices' }, type: 'invoice', spec: { label: 'Invoice', titleField: 'client' } });
|
|
35
|
+
const r = render(<>{tab.render(ctx())}</>);
|
|
36
|
+
await tick();
|
|
37
|
+
expect(allText(r)).toContain('Acme');
|
|
38
|
+
expect(allText(r)).not.toContain('INV-1');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('the detail header shows the title, status and subtitle; short facts in the grid, long text in its own section; header attributes are not repeated', async () => {
|
|
42
|
+
const tab = entityTab({ api: api(), tab: { key: 'invoices', label: 'Invoices' }, type: 'invoice', spec: { label: 'Invoice' } });
|
|
43
|
+
const r = render(<>{tab.render(ctx({ route: { id: '1' } as TabContext['route'] }))}</>);
|
|
44
|
+
await tick();
|
|
45
|
+
const text = allText(r);
|
|
46
|
+
expect(text).toContain('INV-1');
|
|
47
|
+
expect(text).toMatch(/Overdue/i);
|
|
48
|
+
expect(text).toContain('Acme');
|
|
49
|
+
expect(text).toContain('Notes');
|
|
50
|
+
expect(text).toContain('n'.repeat(120));
|
|
51
|
+
expect(text).not.toContain('State');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('with no schema read it still lists rows by name (the type is just undeclared)', async () => {
|
|
55
|
+
const bare = createFakeNativeCorpusApi({ entities: [invoice('1', {})], schemaTypes: [] });
|
|
56
|
+
const tab = entityTab({ api: bare, tab: { key: 'invoices', label: 'Invoices' }, type: 'invoice', spec: { label: 'Invoice' } });
|
|
57
|
+
const r = render(<>{tab.render(ctx())}</>);
|
|
58
|
+
await tick();
|
|
59
|
+
expect(allText(r)).toContain('INV-1');
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { entityFields, entityRow } from '../format';
|
|
3
|
+
|
|
4
|
+
const spec = { label: 'To-do' };
|
|
5
|
+
const todo = { id: 't1', entity_type: 'commitment', name: 'Call Megan', data: { title: 'Call Megan about the deck', owner_name: 'Quinn', due_at: '2026-11-05', status: 'blocked', detail: 'x'.repeat(200) } };
|
|
6
|
+
const display = { title: 'title', subtitle: 'owner_name', date: 'due_at', status: 'status', tones: { blocked: 'bad' as const }, icon: 'check' };
|
|
7
|
+
|
|
8
|
+
describe('entityRow', () => {
|
|
9
|
+
it('reads title, subtitle, date, status tone and icon from the type display', () => {
|
|
10
|
+
expect(entityRow(todo, spec, display)).toEqual({
|
|
11
|
+
id: 't1', title: 'Call Megan about the deck', subtitle: 'Quinn', date: '2026-11-05', status: 'blocked', tone: 'bad', icon: 'check',
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
it('explicit config fields win over the display, per aspect', () => {
|
|
15
|
+
const row = entityRow(todo, { label: 'To-do', titleField: 'owner_name', subtitleFields: ['status', 'owner_name'] }, display);
|
|
16
|
+
expect(row.title).toBe('Quinn');
|
|
17
|
+
expect(row.subtitle).toBe('blocked · Quinn');
|
|
18
|
+
expect(row.status).toBe('blocked');
|
|
19
|
+
expect(row.tone).toBe('bad');
|
|
20
|
+
});
|
|
21
|
+
it('with no display and no config it reads as the name', () => {
|
|
22
|
+
expect(entityRow(todo, spec)).toEqual({ id: 't1', title: 'Call Megan' });
|
|
23
|
+
});
|
|
24
|
+
it('a nameless row is labelled with its type and id, never blank', () => {
|
|
25
|
+
expect(entityRow({ id: '9' }, spec).title).toBe('To-do 9');
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('entityFields', () => {
|
|
30
|
+
it('leaves out the attributes the header already shows', () => {
|
|
31
|
+
const keys = entityFields(todo, display).map((f) => f.key);
|
|
32
|
+
expect(keys).not.toContain('title');
|
|
33
|
+
expect(keys).not.toContain('status');
|
|
34
|
+
expect(keys).toContain('detail');
|
|
35
|
+
});
|
|
36
|
+
it('lists the date first and splits long text from short facts', () => {
|
|
37
|
+
const f = entityFields(todo, display);
|
|
38
|
+
expect(f.map((x) => x.key)).toEqual(['due_at', 'detail']);
|
|
39
|
+
expect(f.find((x) => x.key === 'detail')?.long).toBe(true);
|
|
40
|
+
expect(f.find((x) => x.key === 'due_at')?.long).toBe(false);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { TenantEntity } from '../../../corpus/entities';
|
|
2
|
+
import { resolveDisplay, type DisplayTone, type TypeDisplayConfig } from '../../corpus/display';
|
|
2
3
|
import type { FoundryEntityType } from '../config/types';
|
|
3
4
|
|
|
4
5
|
const text = (v: unknown): string => {
|
|
@@ -11,25 +12,50 @@ const text = (v: unknown): string => {
|
|
|
11
12
|
|
|
12
13
|
const attr = (e: TenantEntity, field: string): string => (field === 'name' ? e.name ?? '' : '') || text((e.data ?? {})[field]);
|
|
13
14
|
|
|
14
|
-
export interface EntityRowView { id: string; title: string; subtitle?: string; status?: string }
|
|
15
|
+
export interface EntityRowView { id: string; title: string; subtitle?: string; status?: string; tone?: DisplayTone; date?: string; icon?: string }
|
|
15
16
|
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
/**
|
|
18
|
+
* One list row for an entity. How it reads comes from the type's declared display (the tenant's schema over the
|
|
19
|
+
* built-in defaults); the app config's `titleField` / `subtitleFields` / `statusField` win, aspect by aspect.
|
|
20
|
+
*/
|
|
21
|
+
export function entityRow(entity: TenantEntity, spec: FoundryEntityType, display?: TypeDisplayConfig): EntityRowView {
|
|
22
|
+
const merged: TypeDisplayConfig = {
|
|
23
|
+
...display,
|
|
24
|
+
...(spec.titleField ? { title: spec.titleField } : {}),
|
|
25
|
+
...(spec.statusField ? { status: spec.statusField } : {}),
|
|
26
|
+
};
|
|
27
|
+
const shown = resolveDisplay(merged, entity);
|
|
28
|
+
const joined = (spec.subtitleFields ?? []).map((f) => attr(entity, f)).filter(Boolean).join(' · ');
|
|
29
|
+
const subtitle = joined || shown.subtitle || '';
|
|
30
|
+
const named = shown.title && shown.title !== String(entity.id) ? shown.title : '';
|
|
20
31
|
return {
|
|
21
32
|
id: String(entity.id),
|
|
22
|
-
title:
|
|
33
|
+
title: named || `${spec.label} ${entity.id}`,
|
|
23
34
|
...(subtitle ? { subtitle } : {}),
|
|
24
|
-
...(status ? { status } : {}),
|
|
35
|
+
...(shown.status ? { status: shown.status.value, tone: shown.status.tone } : {}),
|
|
36
|
+
...(shown.date ? { date: shown.date } : {}),
|
|
37
|
+
...(shown.icon ? { icon: shown.icon } : {}),
|
|
25
38
|
};
|
|
26
39
|
}
|
|
27
40
|
|
|
28
41
|
const label = (key: string) => key.replace(/[_-]+/g, ' ').replace(/^./, (c) => c.toUpperCase());
|
|
29
42
|
|
|
30
|
-
/**
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
43
|
+
/** Text longer than this is body copy, not a fact for the grid. */
|
|
44
|
+
const LONG = 80;
|
|
45
|
+
|
|
46
|
+
export interface EntityField { key: string; label: string; value: string; long: boolean }
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The readable attributes of an entity for a detail screen: scalars and lists; nested objects are left out. The
|
|
50
|
+
* attributes the header already shows (title, subtitle, status) are skipped; the date leads.
|
|
51
|
+
*/
|
|
52
|
+
export function entityFields(entity: TenantEntity, display?: TypeDisplayConfig): EntityField[] {
|
|
53
|
+
const shown = new Set([display?.title, display?.subtitle, display?.status].filter((k): k is string => Boolean(k)));
|
|
54
|
+
const fields = Object.entries(entity.data ?? {})
|
|
55
|
+
.filter(([key]) => !shown.has(key))
|
|
56
|
+
.map(([key, value]) => ({ key, label: label(key), value: text(value), long: false }))
|
|
57
|
+
.filter((f) => f.value !== '')
|
|
58
|
+
.map((f) => ({ ...f, long: f.value.length > LONG }));
|
|
59
|
+
const lead = display?.date;
|
|
60
|
+
return lead ? [...fields.filter((f) => f.key === lead), ...fields.filter((f) => f.key !== lead)] : fields;
|
|
35
61
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { FoundryDevice } from './device';
|
|
2
|
+
|
|
3
|
+
/** The slice of `expo-haptics` the shell uses, so the mapping is testable without the native module. */
|
|
4
|
+
export interface ExpoHapticsLike {
|
|
5
|
+
selectionAsync(): Promise<void>;
|
|
6
|
+
impactAsync(style: never): Promise<void>;
|
|
7
|
+
notificationAsync(type: never): Promise<void>;
|
|
8
|
+
ImpactFeedbackStyle: { Light: unknown; Medium: unknown };
|
|
9
|
+
NotificationFeedbackType: { Success: unknown; Warning: unknown; Error: unknown };
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* `device.haptics` from `expo-haptics`: `haptics: hapticsFromExpo(await import('expo-haptics'))` in the app's
|
|
14
|
+
* `src/device.ts`. Fire-and-forget: a rejected call (no taptic engine, simulator) is swallowed.
|
|
15
|
+
*/
|
|
16
|
+
export function hapticsFromExpo(expo: ExpoHapticsLike): NonNullable<FoundryDevice['haptics']> {
|
|
17
|
+
const impact = (style: unknown) => expo.impactAsync(style as never);
|
|
18
|
+
const notify = (type: unknown) => expo.notificationAsync(type as never);
|
|
19
|
+
return (kind) => {
|
|
20
|
+
const run = {
|
|
21
|
+
selection: () => expo.selectionAsync(),
|
|
22
|
+
light: () => impact(expo.ImpactFeedbackStyle.Light),
|
|
23
|
+
medium: () => impact(expo.ImpactFeedbackStyle.Medium),
|
|
24
|
+
success: () => notify(expo.NotificationFeedbackType.Success),
|
|
25
|
+
warning: () => notify(expo.NotificationFeedbackType.Warning),
|
|
26
|
+
error: () => notify(expo.NotificationFeedbackType.Error),
|
|
27
|
+
}[kind];
|
|
28
|
+
void run().catch(() => undefined);
|
|
29
|
+
};
|
|
30
|
+
}
|
package/src/native/app/index.ts
CHANGED
|
@@ -67,7 +67,9 @@ export const BUILTIN_FACTORIES: Record<string, ScreenFactory> = {
|
|
|
67
67
|
'connect-claude': ({ member }, tab) => createConnectClaudeTab({ api: member.mcpTokens, key: tab.key, label: tab.label ?? `Claude` }),
|
|
68
68
|
entity: ({ config, corpus }, tab) => {
|
|
69
69
|
const type = String(tab.options?.entityType);
|
|
70
|
-
|
|
70
|
+
// A type the config does not describe is labelled from its key until the tenant schema fills it in.
|
|
71
|
+
const spec = config.entityTypes[type] ?? { label: type.replace(/[_-]+/g, ' ').replace(/^./, (c) => c.toUpperCase()) };
|
|
72
|
+
return entityTab({ api: corpus, tab: { key: tab.key, label: tab.label ?? spec.plural ?? tabLabel(tab) }, type, spec });
|
|
71
73
|
},
|
|
72
74
|
};
|
|
73
75
|
|
|
@@ -99,6 +101,7 @@ export function createScreenRegistry(extra: Record<string, ScreenFactory> = {}):
|
|
|
99
101
|
export function buildFoundryTabs(deps: ScreenDeps, registry: ScreenRegistry = createScreenRegistry()): FoundryTab[] {
|
|
100
102
|
return deps.config.tabs.map((t) => {
|
|
101
103
|
const tab = registry.create(deps, t);
|
|
102
|
-
|
|
104
|
+
const icon = t.icon ?? SCREEN_DEFAULTS[t.screen]?.icon;
|
|
105
|
+
return icon ? { ...tab, icon: glyphIcon(icon) } : tab;
|
|
103
106
|
});
|
|
104
107
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { SchemaTypeInfo } from '../corpus/display';
|
|
2
|
+
|
|
3
|
+
export interface SchemaLoadDeps {
|
|
4
|
+
/** The live read (`api.schema.types`). */
|
|
5
|
+
read(): Promise<SchemaTypeInfo[]>;
|
|
6
|
+
/** The last answer saved on the device, as the JSON `save` wrote. */
|
|
7
|
+
loadCache(): Promise<string | null>;
|
|
8
|
+
saveCache(value: string): Promise<void>;
|
|
9
|
+
/** How long the live read may take before the saved answer is used. Default 4000. */
|
|
10
|
+
timeoutMs?: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const isTypes = (v: unknown): v is SchemaTypeInfo[] => Array.isArray(v) && v.every((t) => typeof t === 'object' && t !== null && typeof (t as { key?: unknown }).key === 'string');
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The tenant's declared types for the app shell: the live read, saved for next time; offline or slow, the saved copy;
|
|
17
|
+
* with neither, null (the shell then runs on its config alone). Never throws: the app must open without the schema.
|
|
18
|
+
*/
|
|
19
|
+
export async function loadSchemaTypes(deps: SchemaLoadDeps): Promise<SchemaTypeInfo[] | null> {
|
|
20
|
+
const timeout = deps.timeoutMs ?? 4000;
|
|
21
|
+
try {
|
|
22
|
+
const live = await Promise.race([
|
|
23
|
+
deps.read(),
|
|
24
|
+
new Promise<never>((_, reject) => { setTimeout(() => reject(new Error('schema read timed out')), timeout); }),
|
|
25
|
+
]);
|
|
26
|
+
void deps.saveCache(JSON.stringify(live)).catch(() => undefined);
|
|
27
|
+
return live;
|
|
28
|
+
} catch {
|
|
29
|
+
try {
|
|
30
|
+
const raw = await deps.loadCache();
|
|
31
|
+
const saved: unknown = raw ? JSON.parse(raw) : null;
|
|
32
|
+
return isTypes(saved) && saved.length ? saved : null;
|
|
33
|
+
} catch {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Alert, Button } from '@startsimpli/ui-native';
|
|
1
|
+
import { Banner } from '@startsimpli/ui-native';
|
|
3
2
|
import { useControllerState } from '../../components/useControllerState';
|
|
4
3
|
import { bannerText, type Banners } from '../banners';
|
|
5
4
|
import type { FoundryStrings } from '../strings';
|
|
@@ -9,10 +8,16 @@ export function ShellBanners({ banners, strings }: { banners: Banners; strings:
|
|
|
9
8
|
const state = useControllerState(banners);
|
|
10
9
|
const banner = bannerText(state, strings);
|
|
11
10
|
if (!banner) return null;
|
|
11
|
+
const failed = banner.tone === 'error';
|
|
12
12
|
return (
|
|
13
|
-
<
|
|
14
|
-
|
|
15
|
-
{
|
|
16
|
-
|
|
13
|
+
<Banner
|
|
14
|
+
testID="shell-banner"
|
|
15
|
+
tone={failed ? 'danger' : 'warning'}
|
|
16
|
+
icon={failed ? 'alert' : state.offline ? 'alert' : 'dot'}
|
|
17
|
+
message={banner.text}
|
|
18
|
+
actionLabel={failed ? strings.dismiss : undefined}
|
|
19
|
+
onAction={failed ? () => banners.setError(null) : undefined}
|
|
20
|
+
actionTestID="shell-banner-dismiss"
|
|
21
|
+
/>
|
|
17
22
|
);
|
|
18
23
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
2
|
import { View } from 'react-native';
|
|
3
|
-
import { Alert, Button, Input, Screen, Text, useTheme } from '@startsimpli/ui-native';
|
|
3
|
+
import { Alert, Banner, Button, Input, Screen, Text, useTheme } from '@startsimpli/ui-native';
|
|
4
4
|
import type { FoundryStrings } from '../strings';
|
|
5
5
|
|
|
6
6
|
export function SignInScreen({ strings, notice, onSignIn }: { strings: FoundryStrings; /** Why the person is here again (session expired). */ notice?: string | null; onSignIn: (email: string, password: string) => Promise<void> }) {
|
|
@@ -25,7 +25,7 @@ export function SignInScreen({ strings, notice, onSignIn }: { strings: FoundrySt
|
|
|
25
25
|
return (
|
|
26
26
|
<Screen style={{ justifyContent: 'center', gap: theme.spacing.md }}>
|
|
27
27
|
<Text variant="largeTitle" style={{ marginBottom: theme.spacing.sm }}>{strings.signInTitle}</Text>
|
|
28
|
-
{notice ? <View testID="session-expired"><
|
|
28
|
+
{notice ? <View testID="session-expired"><Banner tone="info" icon="alert" message={notice} style={{ borderRadius: 12 }} /></View> : null}
|
|
29
29
|
<Input value={email} onChangeText={setEmail} placeholder={strings.email} autoCapitalize="none" keyboardType="email-address" autoCorrect={false} testID="email" />
|
|
30
30
|
<Input value={password} onChangeText={setPassword} placeholder={strings.password} secureTextEntry testID="password" />
|
|
31
31
|
{failed ? <Alert variant="destructive">{strings.signInFailed}</Alert> : null}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
2
|
import { Alert as RNAlert, View } from 'react-native';
|
|
3
|
-
import { Alert, Button, Chip, DetailScreen, Icon, ListRow, Section, StatusChip, Tag, Text, useTheme } from '@startsimpli/ui-native';
|
|
3
|
+
import { Alert, Button, Chip, DetailScreen, Icon, ListRow, Section, StatusChip, Tag, Text, useHaptics, useTheme } from '@startsimpli/ui-native';
|
|
4
4
|
import type { VoiceFocus, VoiceNote } from '../../corpus/voice';
|
|
5
5
|
import type { VoiceNotesController } from '../voice/controller';
|
|
6
6
|
import { DELETE_NOTE_TITLE, deleteNoteMessage, formatDuration, formatNoteDate, statusLabel } from '../voice/format';
|
|
@@ -28,6 +28,7 @@ function ProjectPicker({ focuses, value, onPick }: { focuses: VoiceFocus[]; valu
|
|
|
28
28
|
export function NoteDetailScreen({ controller, noteId, onBack }: NoteDetailScreenProps) {
|
|
29
29
|
const state = useVoiceNotes(controller);
|
|
30
30
|
const theme = useTheme();
|
|
31
|
+
const haptic = useHaptics();
|
|
31
32
|
const [showTranscript, setShowTranscript] = useState(false);
|
|
32
33
|
const [picking, setPicking] = useState(false);
|
|
33
34
|
// A deep link, or a note moved out of the active filter, is not on a loaded page: the controller fetches it by id.
|
|
@@ -46,7 +47,7 @@ export function NoteDetailScreen({ controller, noteId, onBack }: NoteDetailScree
|
|
|
46
47
|
const confirmDelete = () =>
|
|
47
48
|
RNAlert.alert(DELETE_NOTE_TITLE, deleteNoteMessage(note.status), [
|
|
48
49
|
{ text: 'Cancel', style: 'cancel' },
|
|
49
|
-
{ text: 'Delete', style: 'destructive', onPress: () => { void controller.remove(note.id).then(onBack); } },
|
|
50
|
+
{ text: 'Delete', style: 'destructive', onPress: () => { haptic('warning'); void controller.remove(note.id).then(onBack); } },
|
|
50
51
|
]);
|
|
51
52
|
const meta = [formatNoteDate(note.occurredAt), formatDuration(note.durationMs)].filter(Boolean).join(' · ');
|
|
52
53
|
const lead = noteLead(note);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useCallback, useRef, useState, type ReactElement } from 'react';
|
|
2
2
|
import { RefreshControl, type RefreshControlProps } from 'react-native';
|
|
3
|
-
import { useTheme } from '@startsimpli/ui-native';
|
|
3
|
+
import { useHaptics, useTheme } from '@startsimpli/ui-native';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Pull-to-refresh for a plain ScrollView (detail screens): the spinner stays up while `reload` runs
|
|
@@ -8,12 +8,14 @@ import { useTheme } from '@startsimpli/ui-native';
|
|
|
8
8
|
*/
|
|
9
9
|
export function usePullRefresh(reload: () => Promise<unknown> | void): ReactElement<RefreshControlProps> {
|
|
10
10
|
const theme = useTheme();
|
|
11
|
+
const haptic = useHaptics();
|
|
11
12
|
const [refreshing, setRefreshing] = useState(false);
|
|
12
13
|
const latest = useRef(reload);
|
|
13
14
|
latest.current = reload;
|
|
14
15
|
const onRefresh = useCallback(async () => {
|
|
16
|
+
haptic('light');
|
|
15
17
|
setRefreshing(true);
|
|
16
18
|
try { await latest.current(); } catch { /* the controller shows its own error */ } finally { setRefreshing(false); }
|
|
17
|
-
}, []);
|
|
19
|
+
}, [haptic]);
|
|
18
20
|
return <RefreshControl refreshing={refreshing} onRefresh={onRefresh} tintColor={theme.colors.mutedForeground} />;
|
|
19
21
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { displaysFrom, resolveDisplay } from '../display';
|
|
2
|
+
import { DEFAULT_DISPLAYS, displaysFrom, layerDisplays, resolveDisplay, typesFrom } from '../display';
|
|
3
|
+
import { createNativeCorpusApi } from '../api';
|
|
3
4
|
import { createFakeNativeCorpusApi } from '../fake';
|
|
4
5
|
|
|
5
6
|
const todo = { id: 't1', entity_type: 'todo', name: 'Call Megan', data: { owner: 'Quinn', due_at: '2026-11-05', status: 'blocked' } };
|
|
@@ -35,3 +36,37 @@ describe('displaysFrom / api.schema.displays', () => {
|
|
|
35
36
|
expect(api.tenant.requests.filter((r) => r.path.includes('schema/types'))).toHaveLength(1);
|
|
36
37
|
});
|
|
37
38
|
});
|
|
39
|
+
|
|
40
|
+
describe('typesFrom / api.schema.types', () => {
|
|
41
|
+
it('lists every declared type with its label and display, dropping the org-wide "*" row', () => {
|
|
42
|
+
expect(typesFrom([{ key: '*' }, { key: 'a', label: 'Alpha', config: { display: { title: 'name' } } }, { key: 'b' }]))
|
|
43
|
+
.toEqual([{ key: 'a', label: 'Alpha', display: { title: 'name' } }, { key: 'b' }]);
|
|
44
|
+
});
|
|
45
|
+
it('shares one schema read with displays()', async () => {
|
|
46
|
+
const api = createFakeNativeCorpusApi();
|
|
47
|
+
const types = await api.schema.types();
|
|
48
|
+
expect(types.map((t) => t.key)).toEqual(['commitment', 'focus', 'source_document']);
|
|
49
|
+
expect((await api.schema.displays()).focus).toMatchObject({ status: 'status' });
|
|
50
|
+
expect(api.tenant.requests.filter((r) => r.path.includes('schema/types'))).toHaveLength(1);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe('layered displays', () => {
|
|
55
|
+
it('a tenant declaration replaces the built-in default for its type, other types keep theirs', () => {
|
|
56
|
+
const layered = layerDisplays({ commitment: { title: 'name' } });
|
|
57
|
+
expect(layered.commitment).toEqual({ title: 'name' });
|
|
58
|
+
expect(layered.focus).toEqual(DEFAULT_DISPLAYS.focus);
|
|
59
|
+
expect(layerDisplays(null)).toEqual(DEFAULT_DISPLAYS);
|
|
60
|
+
});
|
|
61
|
+
it('a status with underscores keeps its tone through the real http path and when the client camelCases tone keys', async () => {
|
|
62
|
+
const body = { results: [{ key: 'focus', label: 'Focus', config: { display: { status: 'status', tones: { on_track: 'good' } } } }] };
|
|
63
|
+
const api = createNativeCorpusApi({
|
|
64
|
+
baseUrl: 'https://t.example',
|
|
65
|
+
authorizedFetch: async () => new Response(JSON.stringify(body), { status: 200, headers: { 'content-type': 'application/json' } }),
|
|
66
|
+
});
|
|
67
|
+
const display = (await api.schema.displays()).focus;
|
|
68
|
+
expect(resolveDisplay(display, { id: '1', name: 'Q4', data: { status: 'on_track' } }).status).toEqual({ value: 'on_track', tone: 'good' });
|
|
69
|
+
const camelled = { status: 'status', tones: { onTrack: 'good' } } as const;
|
|
70
|
+
expect(resolveDisplay(camelled, { id: '1', name: 'Q4', data: { status: 'on_track' } }).status?.tone).toBe('good');
|
|
71
|
+
});
|
|
72
|
+
});
|
package/src/native/corpus/api.ts
CHANGED
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
import { DEFAULT_TYPE_KEYS } from '../../corpus/entities';
|
|
23
23
|
import type { FocusStanding } from '../../corpus/types';
|
|
24
24
|
import { readStandings } from '../../corpus/standings';
|
|
25
|
-
import { displaysFrom, type SchemaTypeRow, type TypeDisplayConfig } from './display';
|
|
25
|
+
import { displaysFrom, typesFrom, type SchemaTypeInfo, type SchemaTypeRow, type TypeDisplayConfig } from './display';
|
|
26
26
|
import type {
|
|
27
27
|
Commitment, CommitmentQuery, CommitmentStatus, CorpusAskApi, CorpusPage, CorpusScope,
|
|
28
28
|
DocumentQuery, Focus, FocusQuery, SourceDocument,
|
|
@@ -63,6 +63,8 @@ export interface NativeCorpusApi {
|
|
|
63
63
|
schema: {
|
|
64
64
|
/** `config.display` per type that declares one (see `resolveDisplay`). Read once, then cached. */
|
|
65
65
|
displays(): Promise<Record<string, TypeDisplayConfig>>;
|
|
66
|
+
/** Every declared type (key, label, display). Same single read as `displays()`. */
|
|
67
|
+
types(): Promise<SchemaTypeInfo[]>;
|
|
66
68
|
};
|
|
67
69
|
/**
|
|
68
70
|
* Total / done / overdue to-dos for a PAGE of projects, in two reads however
|
|
@@ -118,7 +120,13 @@ export function createNativeCorpusApi(deps: NativeCorpusDeps): NativeCorpusApi {
|
|
|
118
120
|
const scope = deps.scope ?? ({} as CorpusScope);
|
|
119
121
|
const corpus = createPlanningApi({ http, scope, ...deps.corpus }) as unknown as CorpusApi & PlanningApi;
|
|
120
122
|
|
|
121
|
-
let
|
|
123
|
+
let schemaRows: Promise<SchemaTypeRow[]> | null = null;
|
|
124
|
+
const rows = () => {
|
|
125
|
+
schemaRows ??= http.get<{ results?: SchemaTypeRow[] }>('api/v1/schema/types', { params: { page_size: MAX_PAGE_SIZE } })
|
|
126
|
+
.then((page) => page.results ?? [])
|
|
127
|
+
.catch((e) => { schemaRows = null; throw e; });
|
|
128
|
+
return schemaRows;
|
|
129
|
+
};
|
|
122
130
|
const api: NativeCorpusApi = {
|
|
123
131
|
http,
|
|
124
132
|
scope,
|
|
@@ -143,12 +151,8 @@ export function createNativeCorpusApi(deps: NativeCorpusDeps): NativeCorpusApi {
|
|
|
143
151
|
},
|
|
144
152
|
},
|
|
145
153
|
schema: {
|
|
146
|
-
displays()
|
|
147
|
-
|
|
148
|
-
.then((page) => displaysFrom(page.results ?? []))
|
|
149
|
-
.catch((e) => { displays = null; throw e; });
|
|
150
|
-
return displays;
|
|
151
|
-
},
|
|
154
|
+
displays: async () => displaysFrom(await rows()),
|
|
155
|
+
types: async () => typesFrom(await rows()),
|
|
152
156
|
},
|
|
153
157
|
standings: (focusIds, now = Date.now()) => readStandings(http, focusIds, now, {
|
|
154
158
|
commitmentType: { ...DEFAULT_TYPE_KEYS, ...deps.corpus?.typeKeys }.commitment,
|