@startsimpli/integrations 0.2.201 → 0.2.202

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 (85) hide show
  1. package/package.json +5 -5
  2. package/src/__tests__/briefing-markdown.test.ts +64 -0
  3. package/src/__tests__/converse-cards.test.ts +53 -0
  4. package/src/__tests__/converse-page.test.tsx +148 -37
  5. package/src/__tests__/converse-roci.test.ts +22 -0
  6. package/src/__tests__/converse-structure.test.ts +27 -0
  7. package/src/__tests__/converse-view.test.ts +46 -0
  8. package/src/__tests__/corpus-tracker.test.tsx +32 -176
  9. package/src/__tests__/data-table-logic.test.ts +75 -0
  10. package/src/__tests__/data-table.test.tsx +133 -0
  11. package/src/__tests__/home-brief.test.tsx +25 -40
  12. package/src/__tests__/library-call-shape.test.tsx +164 -0
  13. package/src/__tests__/load-error.test.tsx +1 -1
  14. package/src/__tests__/mini-markdown.test.tsx +24 -0
  15. package/src/__tests__/overview-page.test.tsx +36 -6
  16. package/src/__tests__/plan-shell.test.tsx +6 -4
  17. package/src/__tests__/timeline-events.test.ts +65 -0
  18. package/src/__tests__/timeline-table.test.tsx +66 -0
  19. package/src/__tests__/todo-table-model.test.ts +75 -0
  20. package/src/__tests__/todo-table.test.tsx +202 -0
  21. package/src/__tests__/tracker-timeline-component.test.tsx +4 -4
  22. package/src/__tests__/tracker-timeline-reader.test.ts +1 -1
  23. package/src/comms/__tests__/app-sends-page.test.tsx +69 -0
  24. package/src/comms/api/comms.ts +23 -0
  25. package/src/comms/components/ResultsPanel.tsx +2 -2
  26. package/src/comms/components/SendLog.tsx +20 -8
  27. package/src/comms/components/index.ts +1 -0
  28. package/src/comms/components/pages/AppSendsPage.tsx +58 -0
  29. package/src/comms/hooks/index.ts +8 -3
  30. package/src/components/FolderTree.tsx +12 -3
  31. package/src/components/index.ts +2 -1
  32. package/src/components/pages/ConversePage.tsx +114 -105
  33. package/src/components/pages/LibraryPage.tsx +63 -24
  34. package/src/components/pages/TrackerPage.tsx +170 -474
  35. package/src/components/pages/converse/CardView.tsx +72 -0
  36. package/src/components/pages/converse/SettingsMenu.tsx +37 -0
  37. package/src/components/pages/converse/Thread.tsx +48 -33
  38. package/src/components/pages/converse/useNeedsYou.ts +60 -0
  39. package/src/components/pages/home/BriefCard.tsx +16 -7
  40. package/src/components/pages/home/HomeBriefPage.tsx +6 -91
  41. package/src/components/pages/home/MiniMarkdown.tsx +51 -0
  42. package/src/components/pages/home/{DueSoonLine.tsx → dueSoonText.ts} +2 -11
  43. package/src/components/pages/home/index.ts +1 -1
  44. package/src/components/pages/overview/OverviewPage.tsx +46 -83
  45. package/src/components/pages/plan/TalkPage.tsx +5 -14
  46. package/src/components/pages/plan/TimelinePage.tsx +4 -2
  47. package/src/components/pages/tracker/SweepPanel.tsx +108 -0
  48. package/src/components/pages/tracker/TimelineTable.tsx +70 -0
  49. package/src/components/pages/tracker/TrackerTimeline.tsx +32 -15
  50. package/src/components/table/DataTable.tsx +92 -0
  51. package/src/components/table/RowMenu.tsx +35 -0
  52. package/src/components/table/TablePagination.tsx +63 -0
  53. package/src/components/table/TableToolbar.tsx +56 -0
  54. package/src/components/table/TodoTable.tsx +142 -0
  55. package/src/components/table/index.ts +10 -0
  56. package/src/components/table/table-logic.ts +60 -0
  57. package/src/components/table/todo-model.ts +93 -0
  58. package/src/corpus/briefing/generate-weekly.ts +4 -0
  59. package/src/corpus/briefing/generate.ts +4 -0
  60. package/src/corpus/briefing/index.ts +1 -0
  61. package/src/corpus/briefing/markdown.ts +71 -0
  62. package/src/corpus/client.ts +38 -146
  63. package/src/corpus/converse/cards.ts +69 -0
  64. package/src/corpus/converse/index.ts +6 -0
  65. package/src/corpus/converse/roci.ts +13 -0
  66. package/src/corpus/converse/structure.ts +39 -0
  67. package/src/corpus/converse/view.ts +34 -0
  68. package/src/corpus/index.ts +2 -0
  69. package/src/corpus/participants.ts +220 -0
  70. package/src/corpus/timeline-events.ts +83 -0
  71. package/src/corpus/tracker-sort.ts +9 -3
  72. package/src/corpus/tracker-timeline-client.ts +2 -0
  73. package/src/corpus/tracker-timeline.ts +4 -0
  74. package/src/corpus/types.ts +32 -5
  75. package/src/native/app/__tests__/plan-talk-registry.test.tsx +2 -1
  76. package/src/native/converse/ConverseScreen.tsx +3 -5
  77. package/src/native/home/HomeScreen.tsx +1 -1
  78. package/src/native/home/tab.tsx +1 -2
  79. package/src/native/plan/PlanTab.tsx +1 -2
  80. package/src/native/plan/__tests__/plan-tab.test.tsx +5 -5
  81. package/src/native/talk/TalkTab.tsx +1 -1
  82. package/src/native/talk/__tests__/talk-tab.test.tsx +1 -1
  83. package/src/__tests__/home-needs-your-call.test.tsx +0 -65
  84. package/src/components/pages/tracker/TrackerBoard.tsx +0 -45
  85. package/src/components/pages/tracker/TrackerToolbar.tsx +0 -44
@@ -0,0 +1,202 @@
1
+ /**
2
+ * THE TO-DO TABLE as the tracker page draws it: one toolbar, one table, ONE status per row, server-side everything.
3
+ */
4
+ import * as React from 'react';
5
+ import { afterEach, describe, expect, it, vi } from 'vitest';
6
+ import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react';
7
+
8
+ import { TrackerPage } from '../components/pages/TrackerPage';
9
+ import type { Commitment, CommitmentQuery, CommitmentTrackerApi, CorpusPage } from '../corpus/types';
10
+
11
+ afterEach(cleanup);
12
+
13
+ const NOW = Date.parse('2026-08-10T12:00:00Z');
14
+ const SCOPE = { orgId: 'tandem' };
15
+ const DAY = 86_400_000;
16
+
17
+ const todo = (n: number, over: Partial<Commitment> = {}): Commitment => ({
18
+ id: `t${n}`, externalId: `commit:t${n}`, dedupeKey: `t${n}`, subtype: 'action', title: `TEST SAMPLE to-do ${n}`, detail: '', status: 'open',
19
+ subjectKey: '', actionKey: '', mentions: [], firstSeenAt: null, lastSeenAt: null, extractorVersion: 't', source: 'voice', sourceLabel: 'V', scope: SCOPE, ...over,
20
+ }) as Commitment;
21
+
22
+ function api(rows: Commitment[], onQuery: (q: CommitmentQuery) => void = () => undefined, total = rows.length) {
23
+ const update = vi.fn(async (item: Commitment, patch: Partial<Commitment>) => ({ ...item, ...patch }) as Commitment);
24
+ const create = vi.fn(async (d: { title: string }) => todo(99, { title: d.title }));
25
+ const impl: CommitmentTrackerApi = {
26
+ async listCommitments(q: CommitmentQuery = {}): Promise<CorpusPage<Commitment>> {
27
+ onQuery(q);
28
+ return { count: total, next: null, previous: null, results: rows, appliedFilters: ['status', 'subtype', 'search', 'focus'] };
29
+ },
30
+ updateCommitment: update, createCommitment: create,
31
+ } as unknown as CommitmentTrackerApi;
32
+ return { impl, update, create };
33
+ }
34
+
35
+ const mount = (a: CommitmentTrackerApi, props: Partial<React.ComponentProps<typeof TrackerPage>> = {}) =>
36
+ render(<TrackerPage api={a} scope={SCOPE} now={NOW} showTimeline={false} projectNames={{ 'focus:p1': 'Website', 'focus:p2': 'Taxes' }} {...props} />);
37
+
38
+ describe('the table', () => {
39
+ it('draws the columns Quinn asked for and nothing else', async () => {
40
+ mount(api([todo(1, { focusId: 'focus:p1', sync: { state: 'synced', key: 'ENG-125', url: 'https://l/ENG-125' } })]).impl);
41
+ await screen.findByText('TEST SAMPLE to-do 1');
42
+ expect(screen.getAllByRole('columnheader').map((h) => h.textContent?.replace(/[▲▼]/g, ''))).toEqual(['Mark done', 'To-do', 'Project', 'Key', 'Status', 'Due', 'Actions']);
43
+ expect(within(screen.getByTestId('table-todos')).getByText('Website')).toBeTruthy();
44
+ expect(screen.getByRole('link', { name: /ENG-125/ }).getAttribute('href')).toBe('https://l/ENG-125');
45
+ });
46
+
47
+ it('shows ONE status per row and no pills, chips, or sync badge', async () => {
48
+ mount(api([todo(1, { status: 'in_progress', sync: { state: 'synced', key: 'ENG-1', stateName: 'In Progress' } })]).impl);
49
+ await screen.findByText('TEST SAMPLE to-do 1');
50
+ expect(within(screen.getByTestId('table-todos')).getAllByText('In progress')).toHaveLength(1);
51
+ expect(screen.queryByText('Synced')).toBeNull();
52
+ expect(document.querySelector('.rounded-full:not([aria-hidden])')).toBeNull();
53
+ });
54
+
55
+ it('overdue is plain red text in the due column: "7 days late"', async () => {
56
+ mount(api([todo(1, { dueAt: new Date(NOW - 7 * DAY).toISOString() }), todo(2, { dueAt: new Date(NOW + 3 * DAY).toISOString() })]).impl);
57
+ const late = await screen.findByText('7 days late');
58
+ expect(late.getAttribute('data-due-tone')).toBe('overdue');
59
+ expect(late.className).toMatch(/text-red/);
60
+ expect(screen.getByText('In 3 days').getAttribute('data-due-tone')).toBe('plain');
61
+ });
62
+
63
+ it('has no subtitle, no board/list toggle, no sort select, no quick-filter pills', async () => {
64
+ mount(api([todo(1)]).impl);
65
+ await screen.findByText('TEST SAMPLE to-do 1');
66
+ expect(screen.queryByLabelText('Sort to-dos')).toBeNull();
67
+ expect(screen.queryByRole('group', { name: 'Quick filters' })).toBeNull();
68
+ expect(screen.queryByRole('button', { name: 'Board' })).toBeNull();
69
+ expect(screen.queryByTestId('tracker-summary')).toBeNull();
70
+ });
71
+ });
72
+
73
+ describe('everything is a server query', () => {
74
+ it('asks for tasks still owed, page 1 of 25, with project names', async () => {
75
+ const q: CommitmentQuery[] = [];
76
+ mount(api([todo(1)], (x) => q.push(x)).impl);
77
+ await screen.findByText('TEST SAMPLE to-do 1');
78
+ expect(q[0]).toMatchObject({ status: ['open', 'in_progress', 'blocked'], subtype: ['action', 'requirement'], withFocus: true, page: 1, pageSize: 25, sort: 'due' });
79
+ });
80
+
81
+ it('searches on the server, after a pause, from page one', async () => {
82
+ const q: CommitmentQuery[] = [];
83
+ mount(api([todo(1)], (x) => q.push(x), 60).impl);
84
+ await screen.findByText('TEST SAMPLE to-do 1');
85
+ fireEvent.click(screen.getByRole('button', { name: 'Next page' }));
86
+ await waitFor(() => expect(q.at(-1)).toMatchObject({ page: 2 }));
87
+ fireEvent.change(screen.getByRole('searchbox', { name: 'Search to-dos' }), { target: { value: 'tax' } });
88
+ await waitFor(() => expect(q.at(-1)).toMatchObject({ search: 'tax', page: 1 }));
89
+ });
90
+
91
+ it('the Status and Project dropdowns are server filters', async () => {
92
+ const q: CommitmentQuery[] = [];
93
+ mount(api([todo(1)], (x) => q.push(x)).impl);
94
+ await screen.findByText('TEST SAMPLE to-do 1');
95
+ fireEvent.change(screen.getByRole('combobox', { name: 'Status' }), { target: { value: 'blocked' } });
96
+ await waitFor(() => expect(q.at(-1)).toMatchObject({ status: ['blocked'] }));
97
+ fireEvent.change(screen.getByRole('combobox', { name: 'Project' }), { target: { value: 'focus:p2' } });
98
+ await waitFor(() => expect(q.at(-1)).toMatchObject({ focus: 'focus:p2' }));
99
+ });
100
+
101
+ it('a project view has no Project dropdown or column, and files adds under it', async () => {
102
+ const { impl, create } = api([todo(1)]);
103
+ mount(impl, { focusId: 'focus:p1' });
104
+ await screen.findByText('TEST SAMPLE to-do 1');
105
+ expect(screen.queryByRole('combobox', { name: 'Project' })).toBeNull();
106
+ expect(screen.queryByRole('columnheader', { name: 'Project' })).toBeNull();
107
+ fireEvent.click(screen.getByRole('button', { name: /Add to-do/ }));
108
+ fireEvent.change(screen.getByLabelText('New to-do title'), { target: { value: 'Ship it' } });
109
+ fireEvent.keyDown(screen.getByLabelText('New to-do title'), { key: 'Enter' });
110
+ await waitFor(() => expect(create).toHaveBeenCalledWith({ title: 'Ship it', focusId: 'focus:p1' }));
111
+ });
112
+
113
+ it('sorting a header asks the server for that order and flips on the second click', async () => {
114
+ const q: CommitmentQuery[] = [];
115
+ mount(api([todo(1)], (x) => q.push(x)).impl);
116
+ await screen.findByText('TEST SAMPLE to-do 1');
117
+ fireEvent.click(screen.getByRole('button', { name: /^To-do/ }));
118
+ await waitFor(() => expect(q.at(-1)).toMatchObject({ sort: 'title', sortDir: 'asc' }));
119
+ fireEvent.click(screen.getByRole('button', { name: /^To-do/ }));
120
+ await waitFor(() => expect(q.at(-1)).toMatchObject({ sort: 'title', sortDir: 'desc' }));
121
+ });
122
+
123
+ it('rows per page is a server page size, and the footer reads 1-25 of 41', async () => {
124
+ const q: CommitmentQuery[] = [];
125
+ mount(api([todo(1)], (x) => q.push(x), 41).impl);
126
+ await screen.findByText('TEST SAMPLE to-do 1');
127
+ expect(screen.getByText('1-25 of 41')).toBeTruthy();
128
+ fireEvent.change(screen.getByLabelText('Rows per page'), { target: { value: '50' } });
129
+ await waitFor(() => expect(q.at(-1)).toMatchObject({ pageSize: 50, page: 1 }));
130
+ });
131
+
132
+ it('does not loop: one read on mount', async () => {
133
+ const q: CommitmentQuery[] = [];
134
+ mount(api([todo(1)], (x) => q.push(x)).impl);
135
+ await screen.findByText('TEST SAMPLE to-do 1');
136
+ await new Promise((r) => setTimeout(r, 150));
137
+ expect(q.filter((x) => x.pageSize === 25)).toHaveLength(1);
138
+ });
139
+ });
140
+
141
+ describe('row actions', () => {
142
+ it('the checkbox marks done, and re-opens', async () => {
143
+ const { impl, update } = api([todo(1), todo(2, { status: 'done' })]);
144
+ mount(impl);
145
+ fireEvent.click(await screen.findByRole('checkbox', { name: /Mark done: TEST SAMPLE to-do 1/ }));
146
+ await waitFor(() => expect(update).toHaveBeenCalledWith(expect.objectContaining({ externalId: 'commit:t1' }), { status: 'done' }));
147
+ fireEvent.click(screen.getByRole('checkbox', { name: /Mark done: TEST SAMPLE to-do 2/ }));
148
+ await waitFor(() => expect(update).toHaveBeenCalledWith(expect.objectContaining({ externalId: 'commit:t2' }), { status: 'open' }));
149
+ });
150
+
151
+ it('the row menu snoozes a week and drops', async () => {
152
+ const { impl, update } = api([todo(1)]);
153
+ mount(impl);
154
+ await screen.findByText('TEST SAMPLE to-do 1');
155
+ fireEvent.click(screen.getByRole('button', { name: /Actions for TEST SAMPLE to-do 1/ }));
156
+ fireEvent.click(screen.getByRole('menuitem', { name: 'Snooze a week' }));
157
+ await waitFor(() => expect(update).toHaveBeenCalledWith(expect.objectContaining({ externalId: 'commit:t1' }), { dueAt: '2026-08-17' }));
158
+ fireEvent.click(screen.getByRole('button', { name: /Actions for TEST SAMPLE to-do 1/ }));
159
+ fireEvent.click(screen.getByRole('menuitem', { name: 'Drop' }));
160
+ await waitFor(() => expect(update).toHaveBeenCalledWith(expect.objectContaining({ externalId: 'commit:t1' }), { status: 'dropped', statusReason: 'Dropped from the list' }));
161
+ });
162
+
163
+ it('+ Add to-do is the one filled control; Enter adds a row at the top and re-reads', async () => {
164
+ const q: CommitmentQuery[] = [];
165
+ const { impl, create } = api([todo(1)], (x) => q.push(x));
166
+ mount(impl);
167
+ await screen.findByText('TEST SAMPLE to-do 1');
168
+ const add = screen.getByRole('button', { name: /Add to-do/ });
169
+ expect(add.className).toMatch(/bg-gray-900/);
170
+ fireEvent.click(add);
171
+ const box = screen.getByLabelText('New to-do title');
172
+ fireEvent.change(box, { target: { value: 'Pay the invoice' } });
173
+ fireEvent.keyDown(box, { key: 'Enter' });
174
+ await waitFor(() => expect(create).toHaveBeenCalledWith({ title: 'Pay the invoice' }));
175
+ await waitFor(() => expect(q.length).toBeGreaterThan(1));
176
+ expect(screen.queryByLabelText('New to-do title')).toBeNull();
177
+ });
178
+
179
+ it('offers no add and no checkbox writes on a read-only api', async () => {
180
+ const ro = { listCommitments: async () => ({ count: 1, next: null, previous: null, results: [todo(1)], appliedFilters: [] }) } as unknown as CommitmentTrackerApi;
181
+ mount(ro);
182
+ await screen.findByText('TEST SAMPLE to-do 1');
183
+ expect(screen.queryByRole('button', { name: /Add to-do/ })).toBeNull();
184
+ expect((screen.getByRole('checkbox') as HTMLInputElement).disabled).toBe(true);
185
+ });
186
+
187
+ it('says so when nothing matches', async () => {
188
+ mount(api([]).impl);
189
+ expect(await screen.findByText(/Nothing has been pulled out of your meetings yet/)).toBeTruthy();
190
+ fireEvent.change(screen.getByRole('combobox', { name: 'Status' }), { target: { value: 'blocked' } });
191
+ expect(await screen.findByText('No to-dos match.')).toBeTruthy();
192
+ });
193
+ });
194
+
195
+ describe('twelve-plus sample rows incl. an overdue one', () => {
196
+ it('draws 13 rows', async () => {
197
+ const rows = Array.from({ length: 13 }, (_, i) => todo(i + 1, i === 0 ? { dueAt: new Date(NOW - 7 * DAY).toISOString() } : {}));
198
+ mount(api(rows, () => undefined, 41).impl);
199
+ await screen.findByText('TEST SAMPLE to-do 13');
200
+ expect(within(screen.getByTestId('table-todos')).getAllByRole('row')).toHaveLength(14);
201
+ });
202
+ });
@@ -25,7 +25,7 @@ describe('TrackerTimeline', () => {
25
25
  it('reads once, not once per render', async () => {
26
26
  const timeline = vi.fn().mockResolvedValue(read());
27
27
  const { rerender } = render(<TrackerTimeline api={{ timeline }} orgId="o" now={NOW} filter={{}} />);
28
- await screen.findByText('No to-dos in this window.');
28
+ await screen.findByText('Nothing happened to a to-do in this window.');
29
29
  for (let i = 0; i < 5; i += 1) rerender(<TrackerTimeline api={{ timeline }} orgId="o" now={NOW} filter={{}} />);
30
30
  expect(timeline).toHaveBeenCalledTimes(1);
31
31
  });
@@ -52,8 +52,8 @@ describe('TrackerTimeline', () => {
52
52
  }));
53
53
  render(<TrackerTimeline api={{ timeline }} orgId="o" now={NOW} filter={{}} />);
54
54
  // created on the 1st and overdue since the 4th: two rows for one to-do
55
- expect(await screen.findAllByText('Send the proposal')).toHaveLength(2);
56
- expect(screen.getAllByText('Overdue').length).toBeGreaterThan(0);
55
+ expect((await screen.findAllByText('Send the proposal')).length).toBeGreaterThanOrEqual(2);
56
+ expect(screen.getAllByText('To-do went overdue').length).toBeGreaterThan(0);
57
57
  expect(screen.getByText('Book the venue')).toBeInTheDocument();
58
58
  expect(screen.getByTestId('timeline-estimated')).toHaveTextContent('1 done to-do has no completion date');
59
59
  });
@@ -68,7 +68,7 @@ describe('TrackerTimeline', () => {
68
68
  render(<TrackerTimeline api={{ timeline }} orgId="o" now={NOW} filter={{}} />);
69
69
  expect(await screen.findByText('New thing')).toBeInTheDocument();
70
70
  expect(screen.queryByText('Old thing')).not.toBeInTheDocument(); // default 30D
71
- await userEvent.click(screen.getByRole('tab', { name: '90 days' }));
71
+ await userEvent.selectOptions(screen.getByRole('combobox', { name: 'Range' }), '90d');
72
72
  await waitFor(() => expect(screen.getByText('Old thing')).toBeInTheDocument());
73
73
  expect(timeline).toHaveBeenCalledTimes(1); // the range is a view, not a read
74
74
  });
@@ -73,7 +73,7 @@ describe('createTimelineReader', () => {
73
73
  ]);
74
74
  const out = await read(http);
75
75
  expect(out.items).toEqual([
76
- { id: 'c1', title: 'Send proposal', status: 'done', dueAt: null, firstSeenAt: '2026-11-01', resolvedAt: null, updatedAt: '2026-11-06T09:00:00Z' },
76
+ { id: 'c1', externalId: null, origin: null, title: 'Send proposal', status: 'done', dueAt: null, firstSeenAt: '2026-11-01', resolvedAt: null, updatedAt: '2026-11-06T09:00:00Z' },
77
77
  ]);
78
78
  });
79
79
 
@@ -0,0 +1,69 @@
1
+ /** Platform-scope app send log (bd startsim-u5iwb.9), against a mocked Django (msw). */
2
+ import * as React from 'react';
3
+ import { afterAll, afterEach, beforeAll, describe, expect, it } from 'vitest';
4
+ import { render, screen, waitFor } from '@testing-library/react';
5
+ import userEvent from '@testing-library/user-event';
6
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
7
+ import { http, HttpResponse } from 'msw';
8
+ import { setupServer } from 'msw/node';
9
+
10
+ import { AppSendsPage } from '../components/pages/AppSendsPage';
11
+ import { setApiBase } from '../api/index';
12
+ import { BASE, metrics, sendRows } from './fixtures';
13
+
14
+ const A = `${BASE}/api/v1/foundry/comms/apps`;
15
+ let sendsHits: URL[] = [];
16
+ let forbid = false;
17
+
18
+ const server = setupServer(
19
+ http.get(`${A}/`, () =>
20
+ forbid
21
+ ? HttpResponse.json({ detail: 'no' }, { status: 403 })
22
+ : HttpResponse.json([{ app: 'raise', sent: 0 }, { app: 'crochet', sent: 7 }]),
23
+ ),
24
+ http.get(`${A}/:app/sends/`, ({ request }) => {
25
+ sendsHits.push(new URL(request.url));
26
+ return HttpResponse.json({ count: 1, next: null, previous: null, results: sendRows(1) });
27
+ }),
28
+ http.get(`${A}/:app/metrics/`, () => HttpResponse.json(metrics())),
29
+ );
30
+
31
+ beforeAll(() => { setApiBase(`${BASE}/api/v1`); server.listen({ onUnhandledRequest: 'error' }); });
32
+ afterEach(() => { server.resetHandlers(); sendsHits = []; forbid = false; });
33
+ afterAll(() => server.close());
34
+
35
+ const mount = () =>
36
+ render(
37
+ <QueryClientProvider client={new QueryClient({ defaultOptions: { queries: { retry: false } } })}>
38
+ <AppSendsPage />
39
+ </QueryClientProvider>,
40
+ );
41
+
42
+ describe('AppSendsPage', () => {
43
+ it('lists the app with sends first and pages its log from the server', async () => {
44
+ mount();
45
+ await screen.findByRole('heading', { name: 'App emails' });
46
+ const select = (await screen.findByLabelText('App')) as HTMLSelectElement;
47
+ expect(select.value).toBe('crochet');
48
+ await waitFor(() => expect(sendsHits.length).toBeGreaterThan(0));
49
+ expect(sendsHits[0].pathname).toMatch(/apps\/crochet\/sends\/$/);
50
+ expect(sendsHits[0].searchParams.get('page_size')).toBe('25');
51
+ await screen.findByText('1–1 of 1');
52
+ });
53
+
54
+ it('switching app and typing a program key refetches with that filter', async () => {
55
+ mount();
56
+ await userEvent.selectOptions(await screen.findByLabelText('App'), 'raise');
57
+ await waitFor(() => expect(sendsHits.some((u) => u.pathname.includes('apps/raise/sends'))).toBe(true));
58
+ await userEvent.type(screen.getByLabelText('Program'), 'welcome');
59
+ await waitFor(() => expect(sendsHits.at(-1)?.searchParams.get('program')).toBe('welcome'));
60
+ });
61
+
62
+ it('shows a plain notice and no log for a non-admin', async () => {
63
+ forbid = true;
64
+ mount();
65
+ await screen.findByText(/Only Platform admins/);
66
+ expect(screen.queryByLabelText('App')).toBeNull();
67
+ expect(sendsHits).toHaveLength(0);
68
+ });
69
+ });
@@ -162,3 +162,26 @@ export function createCommsApi(slug: string): CommsApi {
162
162
  getMetrics: (query = {}) => request(`${P}/metrics/`, { query: { ...query } }),
163
163
  };
164
164
  }
165
+
166
+ /** The slice of the comms client the send log and results panels need. */
167
+ export type SendReportApi = Pick<CommsApi, 'slug' | 'listSends' | 'getMetrics'>;
168
+
169
+ /** Platform-scope send log for ONE first-party app (crochet, raise...): GET /foundry/comms/apps/<app>/. */
170
+ export function createAppCommsApi(app: string): SendReportApi {
171
+ const P = `/foundry/comms/apps/${seg(app)}`;
172
+ return {
173
+ slug: `app:${app}`,
174
+ listSends: (query = {}) => request(`${P}/sends/`, { query: { ...query } }),
175
+ getMetrics: (query = {}) => request(`${P}/metrics/`, { query: { ...query } }),
176
+ };
177
+ }
178
+
179
+ export interface AppActivity {
180
+ app: string;
181
+ sent: number;
182
+ }
183
+
184
+ /** Every first-party app with its sends in the last `days` (default 30). Platform admins only. */
185
+ export function listCommsApps(days = 30): Promise<AppActivity[]> {
186
+ return request('/foundry/comms/apps/', { query: { days } });
187
+ }
@@ -8,13 +8,13 @@
8
8
  */
9
9
  import type { ReactElement } from 'react';
10
10
 
11
- import type { CommsApi } from '../api/comms';
11
+ import type { SendReportApi } from '../api/comms';
12
12
  import { useCommsMetrics } from '../hooks/index';
13
13
  import type { CommsMetrics } from '../types/index';
14
14
  import { ErrorNotice, Note } from './_shared';
15
15
 
16
16
  export interface ResultsPanelProps {
17
- api: CommsApi;
17
+ api: SendReportApi;
18
18
  programKey?: string;
19
19
  }
20
20
 
@@ -15,13 +15,15 @@ import {
15
15
  TableRow,
16
16
  } from '@startsimpli/ui';
17
17
 
18
- import type { CommsApi } from '../api/comms';
18
+ import type { SendReportApi } from '../api/comms';
19
19
  import { useSends } from '../hooks/index';
20
20
  import { COMEBACK_PROGRAM_KEY, PRODUCT_UPDATE_PROGRAM_KEY } from '../types/index';
21
21
  import { ErrorNotice, NativeSelect, formatDate, formatDateTime, formatLocalTime, useFieldId } from './_shared';
22
22
 
23
23
  export interface SendLogProps {
24
- api: CommsApi;
24
+ api: SendReportApi;
25
+ /** Program filter choices. 'text' = free-text key (apps whose programs are not a fixed list). */
26
+ programs?: { value: string; label: string }[] | 'text';
25
27
  /** Rows per server page. Default 25; the server caps at 100. */
26
28
  pageSize?: number;
27
29
  }
@@ -36,7 +38,7 @@ const STATUSES = ['', 'pending', 'sent', 'delivered', 'opened', 'clicked', 'boun
36
38
 
37
39
  const programLabel = (key: string) => PROGRAMS.find((p) => p.value === key)?.label ?? key;
38
40
 
39
- export function SendLog({ api, pageSize = 25 }: SendLogProps): ReactElement {
41
+ export function SendLog({ api, programs = PROGRAMS, pageSize = 25 }: SendLogProps): ReactElement {
40
42
  const [page, setPage] = useState(1);
41
43
  const [program, setProgram] = useState('');
42
44
  const [status, setStatus] = useState('');
@@ -54,11 +56,21 @@ export function SendLog({ api, pageSize = 25 }: SendLogProps): ReactElement {
54
56
  <div className="space-y-1">
55
57
  <Label htmlFor={programId}>Program</Label>
56
58
  <div>
57
- <NativeSelect id={programId} value={program} onChange={(e) => { setProgram(e.target.value); setPage(1); }}>
58
- {PROGRAMS.map((p) => (
59
- <option key={p.value} value={p.value}>{p.label}</option>
60
- ))}
61
- </NativeSelect>
59
+ {programs === 'text' ? (
60
+ <input
61
+ id={programId}
62
+ className="h-9 rounded-md border bg-background px-2 text-sm"
63
+ placeholder="All"
64
+ value={program}
65
+ onChange={(e) => { setProgram(e.target.value.trim()); setPage(1); }}
66
+ />
67
+ ) : (
68
+ <NativeSelect id={programId} value={program} onChange={(e) => { setProgram(e.target.value); setPage(1); }}>
69
+ {programs.map((p) => (
70
+ <option key={p.value} value={p.value}>{p.label}</option>
71
+ ))}
72
+ </NativeSelect>
73
+ )}
62
74
  </div>
63
75
  </div>
64
76
  <div className="space-y-1">
@@ -14,3 +14,4 @@ export * from './ScheduledSends';
14
14
  export * from './ResultsPanel';
15
15
  export * from './SendLog';
16
16
  export * from './AudiencePanel';
17
+ export * from './pages/AppSendsPage';
@@ -0,0 +1,58 @@
1
+ /**
2
+ * APP SENDS: the Platform-scope log of every email a first-party app (crochet,
3
+ * raise...) sends through Foundry comms (bd startsim-u5iwb.9). Superuser only;
4
+ * the routes answer 403 otherwise and this renders that as a plain notice.
5
+ *
6
+ * `<AppSendsPage />` is the whole integration; the mounting app wires the
7
+ * bearer with setAuthTokenProvider first. One title, an app switch, the
8
+ * results, then the paged send log.
9
+ */
10
+ import { useMemo, useState, type ReactElement } from 'react';
11
+
12
+ import { createAppCommsApi } from '../../api/comms';
13
+ import { useCommsApps } from '../../hooks/index';
14
+ import { CommsApiError } from '../../types/index';
15
+ import { ResultsPanel } from '../ResultsPanel';
16
+ import { SendLog } from '../SendLog';
17
+ import { ErrorNotice, NativeSelect, useFieldId } from '../_shared';
18
+
19
+ export function AppSendsPage(): ReactElement {
20
+ const apps = useCommsApps();
21
+ const [picked, setPicked] = useState<string | null>(null);
22
+ const appId = useFieldId('comms-app-sends-app');
23
+ const list = apps.data ?? [];
24
+ const app = picked ?? list.find((a) => a.sent > 0)?.app ?? list[0]?.app ?? null;
25
+ const api = useMemo(() => (app ? createAppCommsApi(app) : null), [app]);
26
+
27
+ const forbidden = apps.error instanceof CommsApiError && apps.error.status === 403;
28
+
29
+ return (
30
+ <div className="space-y-4">
31
+ <h1 className="text-xl font-semibold">App emails</h1>
32
+ {forbidden ? (
33
+ <p className="text-sm text-muted-foreground">Only Platform admins can see every app's email.</p>
34
+ ) : (
35
+ <ErrorNotice error={apps.error} />
36
+ )}
37
+ {apps.data && list.length === 0 ? (
38
+ <p className="text-sm text-muted-foreground">No apps have sent email yet.</p>
39
+ ) : null}
40
+ {list.length > 0 && app && api ? (
41
+ <>
42
+ <div className="space-y-1">
43
+ <label htmlFor={appId} className="text-sm font-medium">App</label>
44
+ <div>
45
+ <NativeSelect id={appId} value={app} onChange={(e) => setPicked(e.target.value)}>
46
+ {list.map((a) => (
47
+ <option key={a.app} value={a.app}>{`${a.app} (${a.sent} sent, 30 days)`}</option>
48
+ ))}
49
+ </NativeSelect>
50
+ </div>
51
+ </div>
52
+ <ResultsPanel key={`m-${app}`} api={api} />
53
+ <SendLog key={`l-${app}`} api={api} programs="text" />
54
+ </>
55
+ ) : null}
56
+ </div>
57
+ );
58
+ }
@@ -17,7 +17,7 @@ import {
17
17
  type UseQueryResult,
18
18
  } from '@tanstack/react-query';
19
19
 
20
- import type { CommsApi } from '../api/comms';
20
+ import { listCommsApps, type AppActivity, type CommsApi, type SendReportApi } from '../api/comms';
21
21
  import type {
22
22
  AssetsQuery,
23
23
  AudienceSegments,
@@ -371,7 +371,7 @@ export function useDeleteAsset(api: CommsApi): UseMutationResult<void, Error, st
371
371
  // results ------------------------------------------------------------------
372
372
 
373
373
  /** Server-side pagination: page/page_size go to the server, never sliced here. */
374
- export function useSends(api: CommsApi, q: SendsQuery): UseQueryResult<SendsPage> {
374
+ export function useSends(api: SendReportApi, q: SendsQuery): UseQueryResult<SendsPage> {
375
375
  return useQuery({
376
376
  queryKey: commsKeys.sends(api.slug, q),
377
377
  queryFn: () => api.listSends(q),
@@ -379,6 +379,11 @@ export function useSends(api: CommsApi, q: SendsQuery): UseQueryResult<SendsPage
379
379
  });
380
380
  }
381
381
 
382
- export function useCommsMetrics(api: CommsApi, q: MetricsQuery): UseQueryResult<CommsMetrics> {
382
+ export function useCommsMetrics(api: SendReportApi, q: MetricsQuery): UseQueryResult<CommsMetrics> {
383
383
  return useQuery({ queryKey: commsKeys.metrics(api.slug, q), queryFn: () => api.getMetrics(q) });
384
384
  }
385
+
386
+ /** First-party apps with their send counts (Platform-scope send log). */
387
+ export function useCommsApps(days = 30): UseQueryResult<AppActivity[]> {
388
+ return useQuery({ queryKey: ['startsimpli', 'comms', 'apps', days] as const, queryFn: () => listCommsApps(days) });
389
+ }
@@ -95,6 +95,14 @@ export interface FolderTreeProps {
95
95
  * flat list it rendered before. Never a half-drawn tree.
96
96
  */
97
97
  onUnavailable?: () => void;
98
+ /**
99
+ * Do not read the first level yet. The Library holds it until its own rows
100
+ * are on screen: the facet read is the slowest one on a cold tenant and a
101
+ * server that answers one request at a time would otherwise answer it BEFORE
102
+ * the records the reader came for. The tree still shows "Loading folders…"
103
+ * while it waits; nothing about what it draws changes.
104
+ */
105
+ hold?: boolean;
98
106
  classNames?: Partial<Record<FolderTreeSlot, string>>;
99
107
  }
100
108
 
@@ -139,6 +147,7 @@ export function FolderTree({
139
147
  rootLabel = 'All documents',
140
148
  pageSize = 100,
141
149
  onUnavailable,
150
+ hold = false,
142
151
  classNames = {},
143
152
  }: FolderTreeProps) {
144
153
  const cn = { ...DEFAULTS, ...classNames };
@@ -219,8 +228,8 @@ export function FolderTree({
219
228
  }, [load]);
220
229
 
221
230
  React.useEffect(() => {
222
- if (!unavailable) ensure(FOLDER_ROOT);
223
- }, [ensure, unavailable]);
231
+ if (!unavailable && !hold) ensure(FOLDER_ROOT);
232
+ }, [ensure, unavailable, hold]);
224
233
 
225
234
  React.useEffect(() => {
226
235
  if (unavailable && !told.current) {
@@ -254,7 +263,7 @@ export function FolderTree({
254
263
  </button>
255
264
  </div>
256
265
 
257
- {root.loading && root.rows.length === 0 ? (
266
+ {(root.loading || hold) && root.rows.length === 0 ? (
258
267
  <p className={cn.muted}>Loading folders…</p>
259
268
  ) : null}
260
269
  {root.error ? <p className={cn.error} role="alert">{root.error}</p> : null}
@@ -42,6 +42,7 @@ export { FolderTree, folderTrail } from './FolderTree';
42
42
  export type { FolderSource, FolderTreeProps, FolderTreeSlot } from './FolderTree';
43
43
  export * from './pages/AskPage';
44
44
  export * from './pages/TrackerPage';
45
+ export * from './table';
45
46
  export * from './pages/TaskDetailPage';
46
47
  // Task-tracker pieces (bd startsim-2nn3h): the sync settings and the link chip.
47
48
  export { TaskTrackerSettings } from './pages/task-tracker/TaskTrackerSettings';
@@ -71,7 +72,7 @@ export type { WorkItemSlot } from './pages/work-items';
71
72
  export * from './pages/VoiceNotesPage';
72
73
  export { VoiceRecordButton, VOICE_MIME_CANDIDATES } from './pages/VoiceRecordButton';
73
74
  export { ConversePage } from './pages/ConversePage';
74
- export type { ConversePageProps, ConverseClassNames } from './pages/ConversePage';
75
+ export type { ConversePageProps } from './pages/ConversePage';
75
76
  export { ConnectorPage } from './pages/ConnectorPage';
76
77
  export type { ConnectorPageProps, ConnectorClassNames } from './pages/ConnectorPage';
77
78
  export { DecisionsPage } from './pages/DecisionsPage';