@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.
- package/package.json +4 -4
- package/src/__tests__/connectable-entries.test.tsx +45 -0
- package/src/__tests__/connections.test.tsx +5 -1
- package/src/__tests__/task-tracker-connection.test.tsx +155 -0
- package/src/__tests__/task-tracker-shared.test.ts +108 -0
- package/src/__tests__/tracker-linear-chip.test.tsx +87 -0
- package/src/api/connections.ts +14 -0
- package/src/components/index.ts +4 -0
- package/src/components/pages/ConnectionsPage.tsx +28 -3
- package/src/components/pages/TrackerPage.tsx +18 -0
- package/src/components/pages/connectable-entries.ts +19 -0
- package/src/components/pages/task-tracker/ExternalLinkChip.tsx +53 -0
- package/src/components/pages/task-tracker/TaskTrackerSettings.tsx +112 -0
- package/src/components/pages/types.ts +4 -0
- package/src/components/pages/work-items.tsx +8 -1
- package/src/corpus/entities.ts +15 -0
- package/src/corpus/types.ts +3 -0
- package/src/index.ts +2 -0
- package/src/native/__tests__/task-tracker.test.tsx +206 -0
- package/src/native/app/FoundryApp.tsx +1 -1
- package/src/native/app/data.ts +5 -1
- package/src/native/app/registry.tsx +4 -2
- package/src/native/corpus/fake-data.ts +3 -3
- package/src/native/corpus/fake-tenant.ts +3 -0
- package/src/native/screens/connections/ConnectionsScreens.tsx +52 -12
- package/src/native/screens/connections/controller.ts +71 -1
- package/src/native/screens/connections/fake.ts +38 -7
- package/src/native/screens/connections/tab.tsx +25 -7
- package/src/native/task-tracker/SyncChips.tsx +35 -0
- package/src/native/task-tracker/TrackerSettingsScreen.tsx +85 -0
- package/src/native/task-tracker/index.ts +2 -0
- package/src/native/tracker/TrackerDetailScreen.tsx +14 -1
- package/src/native/tracker/TrackerListScreen.tsx +7 -1
- package/src/native/tracker/tab.tsx +16 -7
- package/src/task-tracker/index.ts +5 -0
- package/src/task-tracker/item-sync.ts +87 -0
- package/src/task-tracker/links.ts +34 -0
- package/src/task-tracker/settings-controller.ts +138 -0
- package/src/task-tracker/sync-config.ts +95 -0
- package/src/task-tracker/useTrackerName.ts +29 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a to-do says about its link to a task tracker (bd startsim-2nn3h/04dfc).
|
|
3
|
+
*
|
|
4
|
+
* The sync engine writes these keys onto the item's entity data
|
|
5
|
+
* (`task_sync/mapping.py:facts_from_remote` and the `sync_*` bookkeeping). This
|
|
6
|
+
* module only READS them, in one place, so the web row and the phone row can
|
|
7
|
+
* never disagree about what "Out of sync" means. It names no vendor: the label
|
|
8
|
+
* of the tracker is passed in from the connection's `connector_name`.
|
|
9
|
+
*/
|
|
10
|
+
export type SyncState = 'synced' | 'pending' | 'error' | 'conflict' | 'unsynced' | 'remote_deleted';
|
|
11
|
+
|
|
12
|
+
export interface ItemSync {
|
|
13
|
+
state: SyncState;
|
|
14
|
+
/** The tracker's identifier for the item, e.g. `ENG-7`. */
|
|
15
|
+
key?: string;
|
|
16
|
+
url?: string;
|
|
17
|
+
/** The tracker's own workflow state name, e.g. `In Progress`. */
|
|
18
|
+
stateName?: string;
|
|
19
|
+
/** The last sync error, when there is one. */
|
|
20
|
+
error?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const STATES: readonly SyncState[] = ['synced', 'pending', 'error', 'conflict', 'unsynced', 'remote_deleted'];
|
|
24
|
+
const text = (v: unknown): string => (typeof v === 'string' ? v.trim() : '');
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The sync facts of an item, or `undefined` when it has none. `unsynced` is
|
|
28
|
+
* returned ONLY when the engine wrote it: an absent field means "this workspace
|
|
29
|
+
* has no tracker", not "this item missed its sync", so a row in a workspace
|
|
30
|
+
* without a tracker renders exactly as it did before.
|
|
31
|
+
*/
|
|
32
|
+
export function readItemSync(data: Record<string, unknown> | null | undefined): ItemSync | undefined {
|
|
33
|
+
if (!data) return undefined;
|
|
34
|
+
const raw = text(data.sync_state);
|
|
35
|
+
const state = (STATES as readonly string[]).includes(raw) ? (raw as SyncState) : undefined;
|
|
36
|
+
const key = text(data.external_key);
|
|
37
|
+
const url = text(data.external_url);
|
|
38
|
+
const linked = Boolean(text(data.external_id) || key || url);
|
|
39
|
+
if (!state && !linked) return undefined;
|
|
40
|
+
const resolved: SyncState = state ?? 'synced';
|
|
41
|
+
const stateName = text(data.state_name);
|
|
42
|
+
const error = text(data.sync_error);
|
|
43
|
+
return {
|
|
44
|
+
state: resolved,
|
|
45
|
+
...(key ? { key } : {}),
|
|
46
|
+
...(url ? { url } : {}),
|
|
47
|
+
...(stateName ? { stateName } : {}),
|
|
48
|
+
...(error ? { error } : {}),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type BadgeTone = 'ok' | 'pending' | 'warn' | 'error' | 'muted';
|
|
53
|
+
|
|
54
|
+
export interface SyncChip {
|
|
55
|
+
identifier?: string;
|
|
56
|
+
stateLabel?: string;
|
|
57
|
+
url?: string;
|
|
58
|
+
/** `Open in <tracker>` - the tracker is named from data. */
|
|
59
|
+
openLabel: string;
|
|
60
|
+
badge: { text: string; tone: BadgeTone; /** The last error, shown as the tooltip. */ detail?: string; /** Screen-reader sentence. */ a11y: string };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The chip model for a row: identifier, state and the sync badge. */
|
|
64
|
+
export function syncChip(sync: ItemSync, trackerName?: string): SyncChip {
|
|
65
|
+
const tracker = trackerName?.trim() || 'tracker';
|
|
66
|
+
const withDetail = (lead: string) => (sync.error ? `${lead}: ${sync.error}` : lead);
|
|
67
|
+
let badge: SyncChip['badge'];
|
|
68
|
+
switch (sync.state) {
|
|
69
|
+
case 'synced': badge = { text: 'Synced', tone: 'ok', a11y: `Synced with ${tracker}` }; break;
|
|
70
|
+
case 'pending': badge = { text: 'Syncing', tone: 'pending', a11y: `Waiting to sync with ${tracker}` }; break;
|
|
71
|
+
case 'error':
|
|
72
|
+
badge = { text: 'Out of sync', tone: 'error', ...(sync.error ? { detail: sync.error } : {}), a11y: withDetail(`Out of sync with ${tracker}`) };
|
|
73
|
+
break;
|
|
74
|
+
case 'conflict':
|
|
75
|
+
badge = { text: 'Out of sync', tone: 'warn', ...(sync.error ? { detail: sync.error } : {}), a11y: withDetail(`Sync conflict with ${tracker}`) };
|
|
76
|
+
break;
|
|
77
|
+
case 'remote_deleted': badge = { text: `Removed in ${tracker}`, tone: 'warn', a11y: `Removed in ${tracker}; kept in Tandem` }; break;
|
|
78
|
+
default: badge = { text: 'Tandem only', tone: 'muted', a11y: `Only in Tandem, not sent to ${tracker}` };
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
...(sync.key ? { identifier: sync.key } : {}),
|
|
82
|
+
...(sync.stateName ? { stateLabel: sync.stateName } : {}),
|
|
83
|
+
...(sync.url ? { url: sync.url } : {}),
|
|
84
|
+
openLabel: `Open in ${tracker}`,
|
|
85
|
+
badge,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opening a tracker item. A tracker's native app has its own URL scheme; the https
|
|
3
|
+
* link always works. The mapping is DATA (one table), so adding a tracker is a row,
|
|
4
|
+
* not a branch. `openURL` is injected (`Linking.openURL` on a phone): a rejected
|
|
5
|
+
* app link falls back to https, and `canOpenURL` is never needed (it would need an
|
|
6
|
+
* Info.plist whitelist).
|
|
7
|
+
*/
|
|
8
|
+
export const TRACKER_APP_SCHEMES: Array<{ host: string; scheme: string }> = [
|
|
9
|
+
{ host: 'linear.app', scheme: 'linear' },
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
/** The app-scheme form of a tracker https url, or null when the host has no app. */
|
|
13
|
+
export function appLinkFor(url: string): string | null {
|
|
14
|
+
const m = /^https:\/\/([^/?#]+)(\/[^?#]*)?/i.exec(url.trim());
|
|
15
|
+
if (!m) return null;
|
|
16
|
+
const host = m[1].toLowerCase();
|
|
17
|
+
const row = TRACKER_APP_SCHEMES.find((r) => r.host === host);
|
|
18
|
+
return row ? `${row.scheme}:/${m[2] ?? '/'}` : null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type OpenUrl = (url: string) => Promise<unknown>;
|
|
22
|
+
|
|
23
|
+
export async function openTrackerLink(url: string, openURL: OpenUrl): Promise<void> {
|
|
24
|
+
const app = appLinkFor(url);
|
|
25
|
+
if (app) {
|
|
26
|
+
try {
|
|
27
|
+
await openURL(app);
|
|
28
|
+
return;
|
|
29
|
+
} catch {
|
|
30
|
+
// No app installed (or it refused): the web link is the fallback.
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
await openURL(url);
|
|
34
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sync settings of a connected task tracker as a framework-free controller
|
|
3
|
+
* (bd startsim-2nn3h / 04dfc). The web `TaskTrackerSettings` and the phone's
|
|
4
|
+
* settings screen both render this one state, so they cannot disagree about what a
|
|
5
|
+
* save sends: the stored `task_sync` block with the edit laid over it (the server
|
|
6
|
+
* replaces the block whole).
|
|
7
|
+
*/
|
|
8
|
+
import type { Connection, ConnectionChoicePage } from '../components/pages/types';
|
|
9
|
+
import {
|
|
10
|
+
readTaskSync, stateOf, stateRows, withTaskSync,
|
|
11
|
+
type StateRow, type TaskSyncConfig, type TrackerChoice, type TrackerStatus,
|
|
12
|
+
} from './sync-config';
|
|
13
|
+
|
|
14
|
+
export interface SettingsApi {
|
|
15
|
+
connectionChoices(id: string, params?: { kind?: string; cursor?: string }): Promise<ConnectionChoicePage>;
|
|
16
|
+
updateConnectionConfig(id: string, config: Record<string, unknown>): Promise<Connection>;
|
|
17
|
+
syncConnectionNow?(id: string): Promise<{ queued: boolean }>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const CHOICE_KINDS = ['team', 'project', 'state', 'user'] as const;
|
|
21
|
+
export type ChoiceKind = (typeof CHOICE_KINDS)[number];
|
|
22
|
+
|
|
23
|
+
export interface SettingsState {
|
|
24
|
+
loading: boolean;
|
|
25
|
+
choices: Partial<Record<ChoiceKind, TrackerChoice[]>>;
|
|
26
|
+
/** Stored block + unsaved edits. */
|
|
27
|
+
value: TaskSyncConfig;
|
|
28
|
+
rows: StateRow[];
|
|
29
|
+
changed: boolean;
|
|
30
|
+
/** Whether the api can sync now (older clients cannot). */
|
|
31
|
+
canSync: boolean;
|
|
32
|
+
saving: boolean;
|
|
33
|
+
syncing: boolean;
|
|
34
|
+
error: string;
|
|
35
|
+
note: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface SettingsController {
|
|
39
|
+
getState(): SettingsState;
|
|
40
|
+
subscribe(listener: () => void): () => void;
|
|
41
|
+
load(): Promise<void>;
|
|
42
|
+
set(patch: Partial<TaskSyncConfig>): void;
|
|
43
|
+
setStatus(stateId: string, status: TrackerStatus): void;
|
|
44
|
+
save(): Promise<void>;
|
|
45
|
+
syncNow(): Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const say = (e: unknown, fallback: string) => (e instanceof Error && e.message ? e.message : fallback);
|
|
49
|
+
|
|
50
|
+
async function readAll(api: SettingsApi, id: string, kind: ChoiceKind): Promise<TrackerChoice[]> {
|
|
51
|
+
const out: TrackerChoice[] = [];
|
|
52
|
+
let cursor: string | undefined;
|
|
53
|
+
for (let page = 0; page < 20; page += 1) {
|
|
54
|
+
const res = await api.connectionChoices(id, { kind, ...(cursor ? { cursor } : {}) });
|
|
55
|
+
out.push(...res.results.map((r) => ({ id: r.id, label: r.label, kind: r.kind, detail: r.detail })));
|
|
56
|
+
if (!res.has_more || !res.cursor) break;
|
|
57
|
+
cursor = res.cursor;
|
|
58
|
+
}
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function createSettingsController(
|
|
63
|
+
{ api, connection, onSaved }: { api: SettingsApi; connection: Connection; onSaved?: (saved: Connection) => void },
|
|
64
|
+
): SettingsController {
|
|
65
|
+
let base = connection;
|
|
66
|
+
let edits: Partial<TaskSyncConfig> = {};
|
|
67
|
+
let choices: SettingsState['choices'] = {};
|
|
68
|
+
let flags = { loading: true, saving: false, syncing: false, error: '', note: '' };
|
|
69
|
+
const listeners = new Set<() => void>();
|
|
70
|
+
let snapshot: SettingsState | null = null;
|
|
71
|
+
const tracker = connection.connector_name || 'the tracker';
|
|
72
|
+
|
|
73
|
+
const build = (): SettingsState => {
|
|
74
|
+
const value = { ...readTaskSync(base), ...edits };
|
|
75
|
+
return {
|
|
76
|
+
...flags, choices, value,
|
|
77
|
+
rows: stateRows((choices.state ?? []).map(stateOf), value.state_overrides),
|
|
78
|
+
changed: Object.keys(edits).length > 0,
|
|
79
|
+
canSync: typeof api.syncConnectionNow === 'function',
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
const emit = () => { snapshot = build(); listeners.forEach((l) => l()); };
|
|
83
|
+
snapshot = build();
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
getState: () => snapshot as SettingsState,
|
|
87
|
+
subscribe(l) { listeners.add(l); return () => { listeners.delete(l); }; },
|
|
88
|
+
async load() {
|
|
89
|
+
flags = { ...flags, loading: true, error: '' };
|
|
90
|
+
emit();
|
|
91
|
+
try {
|
|
92
|
+
const pairs = await Promise.all(CHOICE_KINDS.map((k) => readAll(api, base.id, k).then((rows) => [k, rows] as const)));
|
|
93
|
+
choices = Object.fromEntries(pairs);
|
|
94
|
+
} catch (e) {
|
|
95
|
+
flags = { ...flags, error: say(e, `Could not read ${tracker}.`) };
|
|
96
|
+
}
|
|
97
|
+
flags = { ...flags, loading: false };
|
|
98
|
+
emit();
|
|
99
|
+
},
|
|
100
|
+
set(patch) { edits = { ...edits, ...patch }; emit(); },
|
|
101
|
+
setStatus(stateId, status) {
|
|
102
|
+
const row = build().rows.find((r) => r.id === stateId);
|
|
103
|
+
const next = { ...(build().value.state_overrides ?? {}) };
|
|
104
|
+
if (!row || status === row.defaultStatus) delete next[stateId];
|
|
105
|
+
else next[stateId] = status;
|
|
106
|
+
edits = { ...edits, state_overrides: next };
|
|
107
|
+
emit();
|
|
108
|
+
},
|
|
109
|
+
async save() {
|
|
110
|
+
flags = { ...flags, saving: true, error: '', note: '' };
|
|
111
|
+
emit();
|
|
112
|
+
try {
|
|
113
|
+
const block = withTaskSync(base, edits);
|
|
114
|
+
const saved = await api.updateConnectionConfig(base.id, { task_sync: Object.keys(block).length ? block : null });
|
|
115
|
+
base = saved && saved.config !== undefined ? saved : { ...base, config: { ...(base.config ?? {}), task_sync: Object.keys(block).length ? block : undefined } };
|
|
116
|
+
edits = {};
|
|
117
|
+
flags = { ...flags, saving: false, note: 'Sync settings saved.' };
|
|
118
|
+
emit();
|
|
119
|
+
onSaved?.(base);
|
|
120
|
+
} catch (e) {
|
|
121
|
+
flags = { ...flags, saving: false, error: say(e, 'Those settings were not saved.') };
|
|
122
|
+
emit();
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
async syncNow() {
|
|
126
|
+
if (!api.syncConnectionNow) return;
|
|
127
|
+
flags = { ...flags, syncing: true, error: '', note: '' };
|
|
128
|
+
emit();
|
|
129
|
+
try {
|
|
130
|
+
await api.syncConnectionNow(base.id);
|
|
131
|
+
flags = { ...flags, syncing: false, note: `Syncing with ${tracker} now. Changes show up in a moment.` };
|
|
132
|
+
} catch (e) {
|
|
133
|
+
flags = { ...flags, syncing: false, error: say(e, 'Could not start a sync.') };
|
|
134
|
+
}
|
|
135
|
+
emit();
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `connection.config['task_sync']` as the settings screens edit it (bd
|
|
3
|
+
* startsim-2nn3h/04dfc). Defined once for web and phone.
|
|
4
|
+
*
|
|
5
|
+
* THE SERVER REPLACES THE BLOCK WHOLE on a config PATCH, so every save sends the
|
|
6
|
+
* stored block with the edit laid over it (`withTaskSync`); sending only the
|
|
7
|
+
* changed field would wipe the rest.
|
|
8
|
+
*/
|
|
9
|
+
import type { Connection } from '../components/pages/types';
|
|
10
|
+
|
|
11
|
+
export type TrackerStatus = 'open' | 'in_progress' | 'blocked' | 'done' | 'dropped';
|
|
12
|
+
|
|
13
|
+
export interface TaskSyncConfig {
|
|
14
|
+
/** The team a new to-do is created in. */
|
|
15
|
+
default_container_id?: string;
|
|
16
|
+
/** The project a new to-do is created in. */
|
|
17
|
+
default_project_id?: string;
|
|
18
|
+
/** Where personal-destination to-dos go. */
|
|
19
|
+
personal_container_id?: string;
|
|
20
|
+
/** tracker project id -> Tandem project (focus) id. */
|
|
21
|
+
project_focus?: Record<string, string>;
|
|
22
|
+
/** tracker workflow state id -> Tandem status. */
|
|
23
|
+
state_overrides?: Record<string, TrackerStatus>;
|
|
24
|
+
assignee_id?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const TASK_SYNC_KEY = 'task_sync';
|
|
28
|
+
const STRINGS = ['default_container_id', 'default_project_id', 'personal_container_id', 'assignee_id'] as const;
|
|
29
|
+
const MAPS = ['project_focus', 'state_overrides'] as const;
|
|
30
|
+
|
|
31
|
+
export const STATUS_OPTIONS: Array<{ value: TrackerStatus; label: string }> = [
|
|
32
|
+
{ value: 'open', label: 'Open' },
|
|
33
|
+
{ value: 'in_progress', label: 'In progress' },
|
|
34
|
+
{ value: 'blocked', label: 'Blocked' },
|
|
35
|
+
{ value: 'done', label: 'Done' },
|
|
36
|
+
{ value: 'dropped', label: 'Dropped' },
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
/** What the engine does with a tracker state of each type when there is no override (mapping.py). */
|
|
40
|
+
export const STATE_TYPE_STATUS: Record<string, TrackerStatus> = {
|
|
41
|
+
backlog: 'open', unstarted: 'open', started: 'in_progress', completed: 'done', canceled: 'dropped',
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const isTaskTracker = (entry: { kind?: string } | undefined | null): boolean => entry?.kind === 'task_tracker';
|
|
45
|
+
|
|
46
|
+
/** The saved block, cleaned to the shape the server accepts. */
|
|
47
|
+
export function readTaskSync(connection: Pick<Connection, 'config'>): TaskSyncConfig {
|
|
48
|
+
const raw = (connection.config ?? {})[TASK_SYNC_KEY];
|
|
49
|
+
if (!raw || typeof raw !== 'object') return {};
|
|
50
|
+
const src = raw as Record<string, unknown>;
|
|
51
|
+
const out: Record<string, unknown> = {};
|
|
52
|
+
for (const k of STRINGS) if (typeof src[k] === 'string' && src[k]) out[k] = src[k];
|
|
53
|
+
for (const k of MAPS) {
|
|
54
|
+
const m = src[k];
|
|
55
|
+
if (m && typeof m === 'object' && Object.keys(m).length) out[k] = { ...(m as object) };
|
|
56
|
+
}
|
|
57
|
+
return out as TaskSyncConfig;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** The whole block to save: stored + `edit`, with blanks and empty maps dropped. */
|
|
61
|
+
export function withTaskSync(connection: Pick<Connection, 'config'>, edit: Partial<TaskSyncConfig>): TaskSyncConfig {
|
|
62
|
+
const merged: Record<string, unknown> = { ...readTaskSync(connection), ...edit };
|
|
63
|
+
for (const k of STRINGS) if (!merged[k]) delete merged[k];
|
|
64
|
+
for (const k of MAPS) {
|
|
65
|
+
const m = merged[k] as Record<string, unknown> | undefined;
|
|
66
|
+
if (!m || !Object.keys(m).length) delete merged[k];
|
|
67
|
+
}
|
|
68
|
+
return merged as TaskSyncConfig;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface TrackerChoice { id: string; label: string; kind?: string; detail?: Record<string, unknown> }
|
|
72
|
+
|
|
73
|
+
export interface StateRow {
|
|
74
|
+
id: string; name: string; type: string; defaultStatus: TrackerStatus; status: TrackerStatus; overridden: boolean;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** The mapping table: every tracker state, what it means by default, and what it means now. */
|
|
78
|
+
export function stateRows(
|
|
79
|
+
states: Array<{ id: string; name: string; type: string }>,
|
|
80
|
+
overrides: Record<string, TrackerStatus> | undefined,
|
|
81
|
+
): StateRow[] {
|
|
82
|
+
return states.map((s) => {
|
|
83
|
+
const defaultStatus = STATE_TYPE_STATUS[s.type] ?? 'open';
|
|
84
|
+
const override = overrides?.[s.id];
|
|
85
|
+
return { id: s.id, name: s.name, type: s.type, defaultStatus, status: override ?? defaultStatus, overridden: Boolean(override) && override !== defaultStatus };
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** A picker row for a state, from the choices api (`detail.state_type`). */
|
|
90
|
+
export const stateOf = (c: TrackerChoice): { id: string; name: string; type: string } => ({
|
|
91
|
+
id: c.id, name: c.label, type: String((c.detail as { state_type?: string } | undefined)?.state_type ?? ''),
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
export const DISCONNECT_TRACKER_NOTE =
|
|
95
|
+
'Your to-dos stay in Tandem. Nothing is deleted in the tracker; they simply stop syncing.';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
import type { MemberConnectionsApi } from '../components/pages/types';
|
|
4
|
+
import { isTaskTracker } from './sync-config';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The display name of the task tracker this member has connected (the first
|
|
8
|
+
* connected connection whose catalog row says `kind: task_tracker`), or
|
|
9
|
+
* `undefined` when there is none or the read fails. Lets a screen name the tracker
|
|
10
|
+
* in "Open in <tracker>" without any app-local lookup.
|
|
11
|
+
*/
|
|
12
|
+
export function useTrackerName(
|
|
13
|
+
api: Pick<MemberConnectionsApi, 'connections' | 'connectorCatalog'> | undefined,
|
|
14
|
+
): string | undefined {
|
|
15
|
+
const [name, setName] = React.useState<string | undefined>();
|
|
16
|
+
React.useEffect(() => {
|
|
17
|
+
if (!api) return undefined;
|
|
18
|
+
let live = true;
|
|
19
|
+
Promise.all([api.connections(), api.connectorCatalog()])
|
|
20
|
+
.then(([mine, catalog]) => {
|
|
21
|
+
const kinds = new Map(catalog.results.map((e) => [e.key, e]));
|
|
22
|
+
const hit = mine.results.find((c) => c.status === 'connected' && isTaskTracker(kinds.get(c.connector_key)));
|
|
23
|
+
if (live) setName(hit?.connector_name || undefined);
|
|
24
|
+
})
|
|
25
|
+
.catch(() => { if (live) setName(undefined); });
|
|
26
|
+
return () => { live = false; };
|
|
27
|
+
}, [api]);
|
|
28
|
+
return name;
|
|
29
|
+
}
|