@startsimpli/integrations 0.2.130 → 0.2.132

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 (40) hide show
  1. package/package.json +4 -4
  2. package/src/__tests__/connectable-entries.test.tsx +45 -0
  3. package/src/__tests__/connections.test.tsx +5 -1
  4. package/src/__tests__/task-tracker-connection.test.tsx +155 -0
  5. package/src/__tests__/task-tracker-shared.test.ts +108 -0
  6. package/src/__tests__/tracker-linear-chip.test.tsx +87 -0
  7. package/src/api/connections.ts +14 -0
  8. package/src/components/index.ts +4 -0
  9. package/src/components/pages/ConnectionsPage.tsx +28 -3
  10. package/src/components/pages/TrackerPage.tsx +18 -0
  11. package/src/components/pages/connectable-entries.ts +19 -0
  12. package/src/components/pages/task-tracker/ExternalLinkChip.tsx +53 -0
  13. package/src/components/pages/task-tracker/TaskTrackerSettings.tsx +112 -0
  14. package/src/components/pages/types.ts +4 -0
  15. package/src/components/pages/work-items.tsx +8 -1
  16. package/src/corpus/entities.ts +15 -0
  17. package/src/corpus/types.ts +3 -0
  18. package/src/index.ts +2 -0
  19. package/src/native/__tests__/task-tracker.test.tsx +206 -0
  20. package/src/native/app/FoundryApp.tsx +1 -1
  21. package/src/native/app/data.ts +5 -1
  22. package/src/native/app/registry.tsx +4 -2
  23. package/src/native/corpus/fake-data.ts +3 -3
  24. package/src/native/corpus/fake-tenant.ts +3 -0
  25. package/src/native/screens/connections/ConnectionsScreens.tsx +52 -12
  26. package/src/native/screens/connections/controller.ts +71 -1
  27. package/src/native/screens/connections/fake.ts +38 -7
  28. package/src/native/screens/connections/tab.tsx +25 -7
  29. package/src/native/task-tracker/SyncChips.tsx +35 -0
  30. package/src/native/task-tracker/TrackerSettingsScreen.tsx +85 -0
  31. package/src/native/task-tracker/index.ts +2 -0
  32. package/src/native/tracker/TrackerDetailScreen.tsx +14 -1
  33. package/src/native/tracker/TrackerListScreen.tsx +7 -1
  34. package/src/native/tracker/tab.tsx +16 -7
  35. package/src/task-tracker/index.ts +5 -0
  36. package/src/task-tracker/item-sync.ts +87 -0
  37. package/src/task-tracker/links.ts +34 -0
  38. package/src/task-tracker/settings-controller.ts +138 -0
  39. package/src/task-tracker/sync-config.ts +95 -0
  40. package/src/task-tracker/useTrackerName.ts +29 -0
@@ -1,11 +1,12 @@
1
- import { useMemo, useState } from 'react';
2
- import { View } from 'react-native';
1
+ import { useEffect, useMemo, useState } from 'react';
2
+ import { AppState, View } from 'react-native';
3
3
  import { Alert, Button, DataList, DetailScreen, Header, IconTile, ListRow, Sheet, StatusChip, Text, useTheme, type ToneKey } from '@startsimpli/ui-native';
4
4
  import { connectionStatusLabel } from '../../../components/pages/connection-format';
5
5
  import type { Connection, ConnectionStatus, MemberConnectionsApi } from '../../../components/pages/types';
6
6
  import { connectionHealthLine } from './format';
7
7
  import { useControllerState } from '../../components/useControllerState';
8
- import { createConnectionsController, type ConnectionsController } from './controller';
8
+ import { createConnectionsController, type ConnectionsController, type OpenUrl } from './controller';
9
+ import { isTaskTracker } from '../../../task-tracker/sync-config';
9
10
 
10
11
  /** The StatusChip status word that gives a connection status its colour. */
11
12
  const chipStatus = (s: ConnectionStatus): string =>
@@ -21,6 +22,11 @@ export interface ConnectionsListScreenProps { controller: ConnectionsController;
21
22
  export function ConnectionsListScreen({ controller, onOpen }: ConnectionsListScreenProps) {
22
23
  const s = useControllerState(controller);
23
24
  const theme = useTheme();
25
+ // OAuth connectors the foundry opened to me that I have not connected yet: one tap, no form.
26
+ const held = new Set(s.rows.filter((r) => r.status !== 'disabled').map((r) => r.connector_key));
27
+ const connectable = !s.canConnect ? [] : s.catalog.filter((c) => c.auth_mode === 'oauth' && c.availability?.available !== false && !held.has(c.key));
28
+ // What the phone cannot connect itself (a key to paste, or no opener) stays a pointer to the web.
29
+ const others = s.catalog.filter((c) => !connectable.includes(c) && !(s.canConnect && c.auth_mode === 'oauth' && held.has(c.key)));
24
30
  return (
25
31
  <View style={{ flex: 1 }}>
26
32
  <Header large title="Connections" subtitle={s.loading ? undefined : `${s.rows.length} connected account${s.rows.length === 1 ? '' : 's'}`} />
@@ -35,11 +41,28 @@ export function ConnectionsListScreen({ controller, onOpen }: ConnectionsListScr
35
41
  onRetry={() => { void controller.refresh(); }}
36
42
  emptyTitle="Nothing connected"
37
43
  emptyDescription="Connect an account (calendar, files, meeting notes) on the web and it shows up here."
38
- ListHeaderComponent={s.catalog.length ? (
39
- <Text variant="footnote" style={{ paddingBottom: theme.spacing.sm }}>
40
- {`Open to connect: ${s.catalog.map((c) => c.name).join(', ')}. Add new accounts on the web.`}
41
- </Text>
42
- ) : undefined}
44
+ ListHeaderComponent={(
45
+ <View>
46
+ {s.actionError ? <Alert variant="destructive">{s.actionError}</Alert> : null}
47
+ {s.awaitingConsent ? <Text variant="footnote" testID="connect-awaiting" style={{ paddingBottom: theme.spacing.sm }}>Finish signing in in your browser, then come back here.</Text> : null}
48
+ {connectable.map((c) => (
49
+ <ListRow
50
+ key={c.key}
51
+ testID={`connect-${c.key}`}
52
+ leading={<IconTile icon="link" tone="info" />}
53
+ title={`Connect ${c.name}`}
54
+ subtitle={c.description || undefined}
55
+ meta={s.connecting === c.key ? 'Opening...' : undefined}
56
+ onPress={() => { void controller.connect(c); }}
57
+ />
58
+ ))}
59
+ {others.length ? (
60
+ <Text variant="footnote" style={{ paddingBottom: theme.spacing.sm }}>
61
+ {`Open to connect: ${others.map((c) => c.name).join(', ')}. Add new accounts on the web.`}
62
+ </Text>
63
+ ) : null}
64
+ </View>
65
+ )}
43
66
  renderItem={({ item }: { item: Connection }) => (
44
67
  <ListRow
45
68
  testID={`connection-${item.id}`}
@@ -56,7 +79,7 @@ export function ConnectionsListScreen({ controller, onOpen }: ConnectionsListScr
56
79
  );
57
80
  }
58
81
 
59
- export function ConnectionDetailScreen({ controller, id, onBack }: { controller: ConnectionsController; id: string; onBack: () => void }) {
82
+ export function ConnectionDetailScreen({ controller, id, onBack, onOpenSettings }: { controller: ConnectionsController; id: string; onBack: () => void; onOpenSettings?: (c: Connection) => void }) {
60
83
  const s = useControllerState(controller);
61
84
  const theme = useTheme();
62
85
  const [confirming, setConfirming] = useState(false);
@@ -67,6 +90,8 @@ export function ConnectionDetailScreen({ controller, id, onBack }: { controller:
67
90
  return <DetailScreen title="Connection" onBack={onBack} testID="connection-detail" loading={s.loading} unavailable={s.loading ? undefined : { title: 'This connection is no longer available' }} />;
68
91
  }
69
92
  const live = row.status !== 'disabled';
93
+ // The catalog says which connectors are task trackers; nothing here names one.
94
+ const tracker = isTaskTracker(s.catalog.find((c) => c.key === row.connector_key));
70
95
  return (
71
96
  <>
72
97
  <DetailScreen
@@ -88,16 +113,24 @@ export function ConnectionDetailScreen({ controller, id, onBack }: { controller:
88
113
  {row.check_error ? <Alert variant="destructive">{row.check_error}</Alert> : null}
89
114
  {row.status === 'needs_reauth' ? <Text variant="muted">The vendor stopped accepting this grant. Reconnect it on the web.</Text> : null}
90
115
  {s.actionError ? <Alert variant="destructive">{s.actionError}</Alert> : null}
116
+ {s.syncNote ? <Text variant="muted" testID="connection-sync-note">{s.syncNote}</Text> : null}
91
117
  {check ? <Alert variant={check.ok ? 'default' : 'destructive'}>{check.detail || (check.ok ? 'Connection is healthy.' : 'The check failed.')}</Alert> : null}
92
118
  {live ? null : <Text variant="muted">Disconnected. Its key was deleted and its scheduled fetches stopped. Reconnect it on the web.</Text>}
93
119
  </>
94
120
  )}
95
- actions={live ? <Button testID="connection-check" title={s.checking === id ? 'Testing...' : 'Test now'} disabled={s.checking !== null} onPress={() => { void controller.check(id); }} /> : undefined}
121
+ actions={live ? (
122
+ <View style={{ gap: theme.spacing.sm }}>
123
+ <Button testID="connection-check" title={s.checking === id ? 'Testing...' : 'Test now'} disabled={s.checking !== null} onPress={() => { void controller.check(id); }} />
124
+ {tracker && onOpenSettings ? <Button testID="connection-sync-settings" title="Sync settings" variant="outline" onPress={() => onOpenSettings(row)} /> : null}
125
+ {tracker ? <Button testID="connection-sync-now" title={s.syncing === id ? 'Syncing...' : 'Sync now'} variant="outline" disabled={s.syncing !== null} onPress={() => { void controller.syncNow(id); }} /> : null}
126
+ </View>
127
+ ) : undefined}
96
128
  footer={live ? <Button testID="connection-disconnect" title="Disconnect" variant="destructive" onPress={() => setConfirming(true)} /> : undefined}
97
129
  />
98
130
  <Sheet visible={confirming} onClose={() => setConfirming(false)} title={`Disconnect ${row.connector_name}?`} testID="connection-confirm">
99
131
  <View style={{ gap: theme.spacing.md, padding: theme.spacing.lg }}>
100
132
  <Text variant="muted">Its stored key is deleted and its scheduled fetches stop. This cannot be undone: you would connect again from the vendor.</Text>
133
+ {tracker ? <Text variant="muted" testID="connection-confirm-tracker">{`Your to-dos stay in Tandem. Nothing is deleted in ${row.connector_name}; they simply stop syncing.`}</Text> : null}
101
134
  <Button testID="connection-confirm-yes" title={s.disconnecting === id ? 'Disconnecting...' : 'Yes, disconnect'} variant="destructive" disabled={s.disconnecting !== null}
102
135
  onPress={() => { void controller.disconnect(id).then(() => setConfirming(false)); }} />
103
136
  <Button title="Cancel" variant="ghost" onPress={() => setConfirming(false)} />
@@ -107,7 +140,14 @@ export function ConnectionDetailScreen({ controller, id, onBack }: { controller:
107
140
  );
108
141
  }
109
142
 
110
- export function useConnectionsController(api: MemberConnectionsApi): ConnectionsController {
143
+ export function useConnectionsController(api: MemberConnectionsApi, options: { openUrl?: OpenUrl; returnTo?: string } = {}): ConnectionsController {
111
144
  // The controller reads once when it is built; Connections re-reads on pull-to-refresh and after a change.
112
- return useMemo(() => createConnectionsController({ api }), [api]);
145
+ const { openUrl, returnTo } = options;
146
+ const controller = useMemo(() => createConnectionsController({ api, openUrl, returnTo }), [api, openUrl, returnTo]);
147
+ // Coming back from a vendor's sign-in page: read the connections again.
148
+ useEffect(() => {
149
+ const sub = AppState.addEventListener('change', (state) => { if (state === 'active') void controller.returned(); });
150
+ return () => sub.remove();
151
+ }, [controller]);
152
+ return controller;
113
153
  }
@@ -14,6 +14,9 @@ import { createStore, errorMessage } from '../store';
14
14
 
15
15
  export interface ConnectionCheck { ok: boolean; detail: string }
16
16
 
17
+ /** Opens a URL outside the app (`Linking.openURL`): the consent page of a vendor. */
18
+ export type OpenUrl = (url: string) => Promise<unknown>;
19
+
17
20
  export interface ConnectionsState {
18
21
  loading: boolean;
19
22
  refreshing: boolean;
@@ -28,6 +31,16 @@ export interface ConnectionsState {
28
31
  checking: string | null;
29
32
  disconnecting: string | null;
30
33
  actionError: string | null;
34
+ /** Catalog key of the connector whose consent page is open; its card appears on return. */
35
+ connecting: string | null;
36
+ /** Whether this app can start a vendor sign-in (an opener was provided and the api has the verb). */
37
+ canConnect: boolean;
38
+ /** The consent page was opened and the app has not come back to read the result yet. */
39
+ awaitingConsent: boolean;
40
+ /** Connection id whose "Sync now" is running. */
41
+ syncing: string | null;
42
+ /** "Syncing with Linear now..." after a sync-now. */
43
+ syncNote: string | null;
31
44
  }
32
45
 
33
46
  export interface ConnectionsController {
@@ -36,12 +49,25 @@ export interface ConnectionsController {
36
49
  refresh(): Promise<void>;
37
50
  check(id: string): Promise<void>;
38
51
  disconnect(id: string): Promise<void>;
52
+ /**
53
+ * Connect an OAuth connector from the phone: ask the server for the consent URL
54
+ * and hand it, untouched, to the injected opener. The result is read when the
55
+ * app comes back (`returned`).
56
+ */
57
+ connect(entry: ConnectorCatalogEntry): Promise<void>;
58
+ /** The app came back to the foreground or arrived on a return link: read the connections again. */
59
+ returned(): Promise<void>;
60
+ /** Push what is pending and pull what changed, for a task-tracker connection. */
61
+ syncNow(id: string): Promise<void>;
39
62
  }
40
63
 
41
- export function createConnectionsController({ api }: { api: MemberConnectionsApi }): ConnectionsController {
64
+ export function createConnectionsController(
65
+ { api, openUrl, returnTo }: { api: MemberConnectionsApi; openUrl?: OpenUrl; returnTo?: string },
66
+ ): ConnectionsController {
42
67
  const store = createStore<ConnectionsState>({
43
68
  loading: true, refreshing: false, rows: [], permissions: null, catalog: [], error: null,
44
69
  checks: {}, checking: null, disconnecting: null, actionError: null,
70
+ connecting: null, canConnect: Boolean(openUrl && api.startOAuth), awaitingConsent: false, syncing: null, syncNote: null,
45
71
  });
46
72
 
47
73
  async function read(initial: boolean) {
@@ -61,6 +87,12 @@ export function createConnectionsController({ api }: { api: MemberConnectionsApi
61
87
  }
62
88
  void read(true);
63
89
 
90
+ async function returned() {
91
+ if (!store.getState().awaitingConsent) return;
92
+ await read(false);
93
+ store.set({ awaitingConsent: false });
94
+ }
95
+
64
96
  return {
65
97
  getState: store.getState,
66
98
  subscribe: store.subscribe,
@@ -77,6 +109,44 @@ export function createConnectionsController({ api }: { api: MemberConnectionsApi
77
109
  store.set({ checking: null });
78
110
  }
79
111
  },
112
+ async connect(entry) {
113
+ if (store.getState().connecting) return;
114
+ if (!api.startOAuth || !openUrl) {
115
+ store.set({ actionError: `${entry.name} cannot be connected from this app version. Connect it on the web.` });
116
+ return;
117
+ }
118
+ store.set({ connecting: entry.key, actionError: null });
119
+ try {
120
+ const start = await api.startOAuth({
121
+ connector_key: entry.key, name: entry.name,
122
+ capabilities_enabled: entry.capabilities,
123
+ ...(returnTo ? { return_to: returnTo } : {}),
124
+ });
125
+ // The URL is complete as the server wrote it: nothing is added to it here.
126
+ const opened = await openUrl(start.authorization_url);
127
+ store.set({ awaitingConsent: true });
128
+ // A sign-in that finished inside the app (no browser hop) is read at once.
129
+ if ((opened as { completed?: boolean } | undefined)?.completed) await returned();
130
+ } catch (e) {
131
+ store.set({ actionError: errorMessage(e, `Could not start connecting ${entry.name}.`) });
132
+ } finally {
133
+ store.set({ connecting: null });
134
+ }
135
+ },
136
+ returned,
137
+ async syncNow(id) {
138
+ if (store.getState().syncing || !api.syncConnectionNow) return;
139
+ const name = store.getState().rows.find((r) => r.id === id)?.connector_name || 'the tracker';
140
+ store.set({ syncing: id, actionError: null, syncNote: null });
141
+ try {
142
+ await api.syncConnectionNow(id);
143
+ store.set({ syncNote: `Syncing with ${name} now. Pull to refresh in a moment.` });
144
+ } catch (e) {
145
+ store.set({ actionError: errorMessage(e, 'Could not start a sync.') });
146
+ } finally {
147
+ store.set({ syncing: null });
148
+ }
149
+ },
80
150
  async disconnect(id) {
81
151
  if (store.getState().disconnecting) return;
82
152
  store.set({ disconnecting: id, actionError: null });
@@ -9,7 +9,9 @@ export interface FakeConnectionsOptions {
9
9
  }
10
10
 
11
11
  export type FakeConnectionsApi = MemberConnectionsApi & {
12
- calls: { connections: number; check: string[]; disconnect: string[] };
12
+ calls: { connections: number; check: string[]; disconnect: string[]; sync: string[]; started: string[]; saved: Array<Record<string, unknown>> };
13
+ /** The consent page "finished" (a simulator has no browser to sign in with): the started connector now holds a card. */
14
+ completeConsent(): void;
13
15
  };
14
16
 
15
17
  const conn = (id: string, key: string, name: string, over: Partial<Connection>): Connection => ({
@@ -26,21 +28,28 @@ export function sampleConnections(): Connection[] {
26
28
  ];
27
29
  }
28
30
 
29
- const catalog = (key: string, name: string, description: string): ConnectorCatalogEntry => ({
30
- key, name, description, logo_url: '', docs_url: '', capabilities: ['read'], auth_mode: 'oauth',
31
+ const catalog = (key: string, name: string, description: string, kind = ''): ConnectorCatalogEntry => ({
32
+ key, name, description, logo_url: '', docs_url: '', capabilities: ['read'], auth_mode: 'oauth', kind,
31
33
  credential_schema: {} as never, config_schema: {} as never, record_types: [], supports_webhooks: false,
32
34
  availability: { available: true, reason: '' },
33
35
  });
34
36
 
35
37
  export function createFakeConnectionsApi(options: FakeConnectionsOptions = {}): FakeConnectionsApi {
36
38
  let rows = options.connections ?? sampleConnections();
37
- const calls: FakeConnectionsApi['calls'] = { connections: 0, check: [], disconnect: [] };
39
+ const calls: FakeConnectionsApi['calls'] = { connections: 0, check: [], disconnect: [], sync: [], started: [], saved: [] };
40
+ let started: string | null = null;
41
+ const CHOICES: Record<string, Array<{ id: string; label: string; detail?: Record<string, unknown> }>> = {
42
+ team: [{ id: 'team-eng', label: 'Engineering (ENG)' }, { id: 'team-per', label: 'Personal (PER)' }],
43
+ project: [{ id: 'proj-tandem', label: 'Tandem' }, { id: 'proj-287a', label: '287A' }],
44
+ state: [{ id: 'st-todo', label: 'Todo', detail: { state_type: 'unstarted' } }, { id: 'st-prog', label: 'In Progress', detail: { state_type: 'started' } }, { id: 'st-done', label: 'Done', detail: { state_type: 'completed' } }],
45
+ user: [{ id: 'u-quinn', label: 'Quinn' }],
46
+ };
38
47
  const unsupported = () => { throw new Error('Not available in the fake connections api.'); };
39
48
  return {
40
49
  calls,
41
50
  async connectorCatalog() {
42
51
  if (options.readError) throw options.readError;
43
- return { results: [catalog('google_calendar', 'Google Calendar', 'Events and availability.'), catalog('dropbox', 'Dropbox', 'Files from a folder.'), catalog('granola', 'Granola', 'Meeting notes.'), catalog('gmail', 'Gmail', 'Threads and attachments.')] };
52
+ return { results: [catalog('google_calendar', 'Google Calendar', 'Events and availability.'), catalog('dropbox', 'Dropbox', 'Files from a folder.'), catalog('granola', 'Granola', 'Meeting notes.'), catalog('gmail', 'Gmail', 'Threads and attachments.'), catalog('linear', 'Linear', 'Issues and projects, kept in step with your to-dos.', 'task_tracker')] };
44
53
  },
45
54
  async connections() {
46
55
  calls.connections += 1;
@@ -61,8 +70,30 @@ export function createFakeConnectionsApi(options: FakeConnectionsOptions = {}):
61
70
  connect: unsupported as never,
62
71
  rotateCredential: unsupported as never,
63
72
  connectionRuns: async () => ({ results: [] }),
64
- updateConnectionConfig: unsupported as never,
65
- startOAuth: unsupported as never,
73
+ async updateConnectionConfig(id, config) {
74
+ calls.saved.push(config);
75
+ const row = rows.find((r) => r.id === id);
76
+ if (!row) throw new Error('Not found.');
77
+ const next = { ...row, config: { ...row.config, ...config } };
78
+ rows = rows.map((r) => (r.id === id ? next : r));
79
+ return next;
80
+ },
81
+ async syncConnectionNow(id) { calls.sync.push(id); return { queued: true }; },
82
+ async connectionChoices(_id, params) {
83
+ const kind = params?.kind ?? 'team';
84
+ return { results: (CHOICES[kind] ?? []).map((c) => ({ id: c.id, label: c.label, kind, selectable: true, reason: '', remediation: '', hidden_by_default: false, detail: c.detail ?? {} })), kind, cursor: null, has_more: false };
85
+ },
86
+ async startOAuth(input) {
87
+ calls.started.push(input.connector_key);
88
+ started = input.connector_key;
89
+ return { authorization_url: `https://consent.example/${input.connector_key}/authorize?state=fake`, state: 'fake', redirect_uri: 'https://api.example/cb/' };
90
+ },
91
+ completeConsent() {
92
+ if (!started) return;
93
+ const name = started === 'linear' ? 'Linear' : started;
94
+ rows = [...rows, conn(`cn-${started}`, started, name, { account_label: 'Acme workspace', capabilities_enabled: ['poll', 'push'] })];
95
+ started = null;
96
+ },
66
97
  oauthInitiate: unsupported as never,
67
98
  connectionInstructions: unsupported as never,
68
99
  } as FakeConnectionsApi;
@@ -1,15 +1,33 @@
1
+ import { useState } from 'react';
1
2
  import type { FoundryTab } from '../../components/FoundryTabsShell';
2
- import type { MemberConnectionsApi } from '../../../components/pages/types';
3
+ import type { Connection, MemberConnectionsApi } from '../../../components/pages/types';
4
+ import { TrackerSettingsScreen, useSettingsController } from '../../task-tracker/TrackerSettingsScreen';
3
5
  import { ConnectionDetailScreen, ConnectionsListScreen, useConnectionsController } from './ConnectionsScreens';
6
+ import type { OpenUrl } from './controller';
4
7
 
5
- function Connections({ api, route, push, back }: { api: MemberConnectionsApi; route: { id: string } | null; push: (id: string) => void; back: () => void }) {
6
- const controller = useConnectionsController(api);
8
+ interface ConnectionsOptions { api: MemberConnectionsApi; openUrl?: OpenUrl; returnTo?: string }
9
+
10
+ function Settings({ api, connection, onBack }: { api: MemberConnectionsApi; connection: Connection; onBack: () => void }) {
11
+ const controller = useSettingsController(api as never, connection);
12
+ return <TrackerSettingsScreen controller={controller} connection={connection} onBack={onBack} />;
13
+ }
14
+
15
+ function Connections({ api, openUrl, returnTo, route, push, back }: ConnectionsOptions & { route: { id: string } | null; push: (id: string) => void; back: () => void }) {
16
+ const controller = useConnectionsController(api, { openUrl, returnTo });
17
+ const [settingsFor, setSettingsFor] = useState<Connection | null>(null);
18
+ if (route && settingsFor && settingsFor.id === route.id) {
19
+ return <Settings api={api} connection={settingsFor} onBack={() => setSettingsFor(null)} />;
20
+ }
7
21
  return route
8
- ? <ConnectionDetailScreen controller={controller} id={route.id} onBack={back} />
22
+ ? <ConnectionDetailScreen controller={controller} id={route.id} onBack={back} onOpenSettings={setSettingsFor} />
9
23
  : <ConnectionsListScreen controller={controller} onOpen={(c) => push(c.id)} />;
10
24
  }
11
25
 
12
- /** The Connections tab: my connected accounts, their health, test and disconnect. */
13
- export function createConnectionsTab({ api, key = 'connections', label = 'Connections' }: { api: MemberConnectionsApi; key?: string; label?: string }): FoundryTab {
14
- return { key, label, render: ({ route, push, back }) => <Connections api={api} route={route} push={push} back={back} /> };
26
+ /**
27
+ * The Connections tab: my connected accounts, their health, test and disconnect; an OAuth connector can be
28
+ * connected from here when the app gives it an opener (`openUrl`, e.g. `Linking.openURL`); a connected task tracker
29
+ * also gets its sync settings and Sync now.
30
+ */
31
+ export function createConnectionsTab({ api, key = 'connections', label = 'Connections', openUrl, returnTo }: { api: MemberConnectionsApi; key?: string; label?: string; openUrl?: OpenUrl; returnTo?: string }): FoundryTab {
32
+ return { key, label, render: ({ route, push, back }) => <Connections api={api} openUrl={openUrl} returnTo={returnTo} route={route} push={push} back={back} /> };
15
33
  }
@@ -0,0 +1,35 @@
1
+ import { Pressable, View } from 'react-native';
2
+ import { Tag, useTheme, type ToneKey } from '@startsimpli/ui-native';
3
+ import { syncChip, type BadgeTone, type ItemSync } from '../../task-tracker/item-sync';
4
+
5
+ const TONE: Record<BadgeTone, ToneKey> = { ok: 'success', pending: 'info', warn: 'warning', error: 'danger', muted: 'neutral' };
6
+
7
+ /**
8
+ * A to-do's tracker truth on the phone: the identifier (tap to open it in the
9
+ * tracker's app, https fallback), the tracker's own state and the sync badge with
10
+ * a spoken label for each state. Renders nothing for an item with no sync facts.
11
+ * The tracker's name comes from data; `onOpen` is injected (the app's opener).
12
+ */
13
+ export function SyncChips({ sync, trackerName, onOpen, testID = 'sync-chips' }: {
14
+ sync: ItemSync | undefined;
15
+ trackerName?: string;
16
+ onOpen?: (url: string) => void;
17
+ testID?: string;
18
+ }) {
19
+ const theme = useTheme();
20
+ if (!sync) return null;
21
+ const chip = syncChip(sync, trackerName);
22
+ return (
23
+ <View testID={testID} style={{ flexDirection: 'row', flexWrap: 'wrap', alignItems: 'center', gap: theme.spacing.xs }}>
24
+ {chip.identifier ? (
25
+ chip.url && onOpen ? (
26
+ <Pressable testID={`${testID}-open`} accessibilityRole="link" accessibilityLabel={`${chip.openLabel}: ${chip.identifier}`} hitSlop={8} onPress={() => onOpen(chip.url as string)}>
27
+ <Tag label={chip.identifier} tone="info" outline />
28
+ </Pressable>
29
+ ) : <Tag label={chip.identifier} outline />
30
+ ) : null}
31
+ {chip.stateLabel ? <Tag testID={`${testID}-state`} label={chip.stateLabel} outline /> : null}
32
+ <Tag testID={`${testID}-badge`} label={chip.badge.text} tone={TONE[chip.badge.tone]} accessibilityLabel={chip.badge.a11y} />
33
+ </View>
34
+ );
35
+ }
@@ -0,0 +1,85 @@
1
+ import { useEffect } from 'react';
2
+ import { View } from 'react-native';
3
+ import { Alert, Button, DetailScreen, Section, Select, Text, useTheme } from '@startsimpli/ui-native';
4
+ import type { Connection } from '../../components/pages/types';
5
+ import { STATUS_OPTIONS, type TaskSyncConfig, type TrackerStatus } from '../../task-tracker/sync-config';
6
+ import { createSettingsController, type SettingsApi, type SettingsController } from '../../task-tracker/settings-controller';
7
+ import { useControllerState } from '../components/useControllerState';
8
+ import { useMemo } from 'react';
9
+
10
+ export function useSettingsController(api: SettingsApi, connection: Connection, onSaved?: (c: Connection) => void): SettingsController {
11
+ // One controller per connection: edits survive a re-render.
12
+ // eslint-disable-next-line react-hooks/exhaustive-deps
13
+ return useMemo(() => createSettingsController({ api, connection, onSaved }), [api, connection.id]);
14
+ }
15
+
16
+ type PickKey = 'default_container_id' | 'default_project_id' | 'personal_container_id' | 'assignee_id';
17
+
18
+ /** Sync settings of a connected task tracker: team, project, personal destination, assignee, state mapping. */
19
+ export function TrackerSettingsScreen({ controller, connection, onBack }: { controller: SettingsController; connection: Connection; onBack: () => void }) {
20
+ const theme = useTheme();
21
+ const s = useControllerState(controller);
22
+ useEffect(() => { void controller.load(); }, [controller]);
23
+ const tracker = connection.connector_name || 'the tracker';
24
+
25
+ const pick = (label: string, key: PickKey, kind: 'team' | 'project' | 'user', clearLabel: string) => (
26
+ <Select
27
+ testID={`settings-${key}`}
28
+ label={label}
29
+ searchable
30
+ options={(s.choices[kind] ?? []).map((c) => ({ value: c.id, label: c.label }))}
31
+ value={(s.value[key] as string | undefined) || null}
32
+ clearLabel={clearLabel}
33
+ placeholder={clearLabel}
34
+ disabled={s.loading}
35
+ onChange={(v) => controller.set({ [key]: v ?? '' } as Partial<TaskSyncConfig>)}
36
+ />
37
+ );
38
+
39
+ return (
40
+ <DetailScreen
41
+ title="Sync settings"
42
+ onBack={onBack}
43
+ testID="tracker-settings"
44
+ hero={{ eyebrow: tracker, title: 'Sync settings', subtitle: connection.account_label || undefined }}
45
+ banner={(
46
+ <>
47
+ {s.error ? <Alert variant="destructive">{s.error}</Alert> : null}
48
+ {s.note ? <Alert variant="default">{s.note}</Alert> : null}
49
+ </>
50
+ )}
51
+ actions={(
52
+ <View style={{ gap: theme.spacing.sm }}>
53
+ <Button testID="settings-save" title={s.saving ? 'Saving...' : 'Save sync settings'} disabled={s.saving || !s.changed} onPress={() => { void controller.save(); }} />
54
+ {s.canSync ? (
55
+ <Button testID="settings-sync-now" title={s.syncing ? 'Syncing...' : 'Sync now'} variant="outline" disabled={s.syncing || s.saving} onPress={() => { void controller.syncNow(); }} />
56
+ ) : null}
57
+ </View>
58
+ )}
59
+ >
60
+ <Section title="Where new to-dos go">
61
+ <View style={{ gap: theme.spacing.md, paddingVertical: theme.spacing.md }}>
62
+ {pick('Team', 'default_container_id', 'team', 'Not set (stay in Tandem)')}
63
+ {pick('Default project', 'default_project_id', 'project', 'No project')}
64
+ {pick('Personal to-dos', 'personal_container_id', 'team', 'Keep in Tandem only')}
65
+ {pick(`Also bring in ${tracker} issues assigned to`, 'assignee_id', 'user', 'Nobody in particular')}
66
+ </View>
67
+ </Section>
68
+ <Section title={`${tracker} states and Tandem status`}>
69
+ <View style={{ gap: theme.spacing.md, paddingVertical: theme.spacing.md }}>
70
+ {s.rows.length === 0 && !s.loading ? <Text variant="muted">No states found.</Text> : null}
71
+ {s.rows.map((row) => (
72
+ <Select
73
+ key={row.id}
74
+ testID={`settings-state-${row.id}`}
75
+ label={row.name}
76
+ options={STATUS_OPTIONS.map((o) => ({ value: o.value, label: o.value === row.defaultStatus ? `${o.label} (default)` : o.label }))}
77
+ value={row.status}
78
+ onChange={(v) => { if (v) controller.setStatus(row.id, v as TrackerStatus); }}
79
+ />
80
+ ))}
81
+ </View>
82
+ </Section>
83
+ </DetailScreen>
84
+ );
85
+ }
@@ -0,0 +1,2 @@
1
+ export { SyncChips } from './SyncChips';
2
+ export { TrackerSettingsScreen, useSettingsController } from './TrackerSettingsScreen';
@@ -5,6 +5,8 @@ import type { NativeCorpusApi } from '../corpus/api';
5
5
  import { usePullRefresh } from '../components/usePullRefresh';
6
6
  import { useControllerState } from '../components/useControllerState';
7
7
  import { createTrackerDetailController } from './detail';
8
+ import { SyncChips } from '../task-tracker/SyncChips';
9
+ import { syncChip } from '../../task-tracker/item-sync';
8
10
  import { formatDue, isOverdueAt, priorityText } from './format';
9
11
 
10
12
  export interface TrackerDetailScreenProps {
@@ -16,10 +18,12 @@ export interface TrackerDetailScreenProps {
16
18
  /** Called after a status write succeeds (the list refreshes). */
17
19
  onChanged?: () => void;
18
20
  now?: () => number;
21
+ trackerName?: string;
22
+ onOpenLink?: (url: string) => void;
19
23
  }
20
24
 
21
25
  /** One to-do: status, due, owner, project, the verbatim source quote(s) and mark done / reopen. */
22
- export function TrackerDetailScreen({ api, id, onBack, onOpenNote, onChanged, now = Date.now }: TrackerDetailScreenProps) {
26
+ export function TrackerDetailScreen({ api, id, onBack, onOpenNote, onChanged, now = Date.now, trackerName, onOpenLink }: TrackerDetailScreenProps) {
23
27
  const theme = useTheme();
24
28
  const controller = useMemo(() => createTrackerDetailController({ api, id, onChanged }), [api, id, onChanged]);
25
29
  useEffect(() => { void controller.load(); }, [controller]);
@@ -60,6 +64,15 @@ export function TrackerDetailScreen({ api, id, onBack, onOpenNote, onChanged, no
60
64
  />
61
65
  )}
62
66
  >
67
+ {item.sync ? (
68
+ <Section title={trackerName ? `In ${trackerName}` : 'In your tracker'}>
69
+ <View style={{ paddingVertical: theme.spacing.md, gap: theme.spacing.sm }}>
70
+ <SyncChips testID="todo-sync" sync={item.sync} trackerName={trackerName} onOpen={onOpenLink} />
71
+ {item.sync.error ? <Text variant="footnote" testID="todo-sync-error">{item.sync.error}</Text> : null}
72
+ {item.sync.url && onOpenLink ? <Button testID="todo-open-tracker" title={syncChip(item.sync, trackerName).openLabel} variant="outline" size="sm" style={{ alignSelf: 'flex-start' }} onPress={() => onOpenLink(item.sync!.url as string)} /> : null}
73
+ </View>
74
+ </Section>
75
+ ) : null}
63
76
  {item.detail ? <Section title="Details"><View style={{ paddingVertical: theme.spacing.md }}><Text variant="body">{item.detail}</Text></View></Section> : null}
64
77
  {s.sources.length ? (
65
78
  <Section title="Where it came from">
@@ -7,6 +7,7 @@ import { useControllerState } from '../components/useControllerState';
7
7
  import { rowDisplay, useTypeDisplay, type DisplaysSource } from '../screens/shared/useTypeDisplay';
8
8
  import type { TrackerController, TrackerRow } from './controller';
9
9
  import { TodoGlyph } from './TodoGlyph';
10
+ import { SyncChips } from '../task-tracker/SyncChips';
10
11
  import { TRACKER_VIEWS, rowParts, type TrackerView } from './format';
11
12
 
12
13
  export interface TrackerListScreenProps {
@@ -16,6 +17,10 @@ export interface TrackerListScreenProps {
16
17
  onOpen: (item: Commitment) => void;
17
18
  /** Injectable clock for the "Overdue" label. */
18
19
  now?: () => number;
20
+ /** The connected tracker's display name, for "Open in <tracker>". */
21
+ trackerName?: string;
22
+ /** Open a tracker item's url (the app's opener: tracker app first, https fallback). */
23
+ onOpenLink?: (url: string) => void;
19
24
  }
20
25
 
21
26
  /** What an empty list says per view. Reached only when no project or search narrows it (those read "No to-dos match"). */
@@ -31,7 +36,7 @@ const EMPTY: Record<TrackerView, { title: string; description: string }> = {
31
36
  * Closed), project and search are all query parameters; swipe a row to mark it
32
37
  * done (or reopen it from Closed); pull to refresh; the list pages on scroll.
33
38
  */
34
- export function TrackerListScreen({ controller, onOpen, displays, now = Date.now }: TrackerListScreenProps) {
39
+ export function TrackerListScreen({ controller, onOpen, displays, now = Date.now, trackerName, onOpenLink }: TrackerListScreenProps) {
35
40
  const state = useControllerState(controller);
36
41
  const display = useTypeDisplay(displays, 'commitment');
37
42
  const theme = useTheme();
@@ -64,6 +69,7 @@ export function TrackerListScreen({ controller, onOpen, displays, now = Date.now
64
69
  meta={parts.due ?? undefined}
65
70
  metaTone={parts.overdue ? 'danger' : undefined}
66
71
  // Open is the default and needs no badge; in progress, blocked and dropped do.
72
+ footer={row.item.sync ? <SyncChips testID={`todo-sync-${row.item.id}`} sync={row.item.sync} trackerName={trackerName} onOpen={onOpenLink} /> : undefined}
67
73
  trailing={status === 'blocked' || status === 'dropped' || status === 'in_progress' ? <StatusChip status={status} /> : undefined}
68
74
  onPress={() => onOpen(row.item)}
69
75
  />
@@ -1,5 +1,8 @@
1
1
  import type { FoundryTab } from '../components/FoundryTabsShell';
2
+ import type { MemberConnectionsApi } from '../../components/pages/types';
2
3
  import type { NativeCorpusApi } from '../corpus/api';
4
+ import { useTrackerName } from '../../task-tracker/useTrackerName';
5
+ import { openTrackerLink } from '../../task-tracker/links';
3
6
  import { createTrackerController, type TrackerController } from './controller';
4
7
  import { TrackerDetailScreen } from './TrackerDetailScreen';
5
8
  import { TrackerListScreen } from './TrackerListScreen';
@@ -11,14 +14,20 @@ export interface TrackerTabOptions {
11
14
  /** The Notes tab's key; a to-do from a voice note offers "Open note" into it. Omit for no link. */
12
15
  notesKey?: string;
13
16
  controller?: TrackerController;
17
+ /** With this, a to-do linked to a task tracker names the connected tracker ("Open in Linear"). */
18
+ memberConnections?: Pick<MemberConnectionsApi, 'connections' | 'connectorCatalog'>;
19
+ /** Opens a URL outside the app (`Linking.openURL`). A tracker link tries the tracker's app, then https. */
20
+ openUrl?: (url: string) => Promise<unknown>;
14
21
  }
15
22
 
16
23
  /** The to-do tab as one `FoundryTabsShell` entry: list -> detail (with the source note link). */
17
- export function trackerTab({ api, key = 'tracker', label = 'To-dos', notesKey = 'notes', controller = createTrackerController({ api }) }: TrackerTabOptions): FoundryTab {
18
- return {
19
- key, label, resetOnLeave: true,
20
- render: ({ route, push, back, openTab }) => route
21
- ? <TrackerDetailScreen api={api} id={route.id} onBack={back} onChanged={() => { void controller.refresh(); }} onOpenNote={notesKey ? (docId) => openTab(notesKey, docId) : undefined} />
22
- : <TrackerListScreen controller={controller} displays={api.schema?.displays} onOpen={(c) => push(c.id)} />,
23
- };
24
+ export function trackerTab({ api, key = 'tracker', label = 'To-dos', notesKey = 'notes', controller = createTrackerController({ api }), memberConnections, openUrl }: TrackerTabOptions): FoundryTab {
25
+ const onOpenLink = openUrl ? (url: string) => { void openTrackerLink(url, openUrl).catch(() => undefined); } : undefined;
26
+ function Screen({ route, push, back, openTab }: { route: { id: string } | null; push: (id: string) => void; back: () => void; openTab: (tab: string, id?: string) => void }) {
27
+ const trackerName = useTrackerName(memberConnections);
28
+ return route
29
+ ? <TrackerDetailScreen api={api} id={route.id} onBack={back} onChanged={() => { void controller.refresh(); }} onOpenNote={notesKey ? (docId) => openTab(notesKey, docId) : undefined} trackerName={trackerName} onOpenLink={onOpenLink} />
30
+ : <TrackerListScreen controller={controller} displays={api.schema?.displays} onOpen={(c) => push(c.id)} trackerName={trackerName} onOpenLink={onOpenLink} />;
31
+ }
32
+ return { key, label, resetOnLeave: true, render: (props) => <Screen {...props} /> };
24
33
  }
@@ -0,0 +1,5 @@
1
+ export * from './item-sync';
2
+ export * from './links';
3
+ export * from './sync-config';
4
+ export * from './useTrackerName';
5
+ export * from './settings-controller';