@startsimpli/integrations 0.2.143 → 0.2.144

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startsimpli/integrations",
3
- "version": "0.2.143",
3
+ "version": "0.2.144",
4
4
  "description": "Provider-agnostic types, API clients, hooks, and UI primitives for email + calendar integrations across StartSimpli apps, plus foundry customer email (subpath ./comms).",
5
5
  "license": "MIT",
6
6
  "homepage": "https://startsimpli.com",
@@ -679,3 +679,28 @@ describe('TrackerPage — filtering', () => {
679
679
  expect(screen.queryByText(/nothing is owed/i)).toBeNull();
680
680
  });
681
681
  });
682
+
683
+ describe('TrackerPage — paging a large list', () => {
684
+ it('loads the next server page on request and appends it', async () => {
685
+ const pages: Record<number, Commitment[]> = {
686
+ 1: [commitment({ externalId: 'commit:p1', title: 'First page item' })],
687
+ 2: [commitment({ externalId: 'commit:p2', title: 'Second page item' })],
688
+ };
689
+ const seen: number[] = [];
690
+ const api: CommitmentTrackerApi = {
691
+ async listCommitments(query: CommitmentQuery = {}) {
692
+ const page = query.page ?? 1;
693
+ if (query.status) seen.push(page);
694
+ return { count: 2, next: page === 1 ? 'more' : null, previous: null, results: pages[page] ?? [], appliedFilters: [] };
695
+ },
696
+ };
697
+ render(<TrackerPage api={api} scope={SCOPE} now={NOW} />);
698
+ await screen.findByText('First page item');
699
+ expect(screen.queryByText('Second page item')).toBeNull();
700
+ await userEvent.click(screen.getByRole('button', { name: /load more/i }));
701
+ expect(await screen.findByText('Second page item')).toBeInTheDocument();
702
+ expect(screen.getByText('First page item')).toBeInTheDocument();
703
+ expect(seen).toEqual([1, 2]);
704
+ expect(screen.queryByRole('button', { name: /load more/i })).toBeNull();
705
+ });
706
+ });
@@ -155,6 +155,8 @@ export function TrackerPage({
155
155
 
156
156
  const [rows, setRows] = React.useState<Commitment[]>([]);
157
157
  const [total, setTotal] = React.useState(0);
158
+ const [pageNo, setPageNo] = React.useState(1);
159
+ const [loadingMore, setLoadingMore] = React.useState(false);
158
160
  const [applied, setApplied] = React.useState<string[]>([]);
159
161
  const [loading, setLoading] = React.useState(true);
160
162
  const [error, setError] = React.useState('');
@@ -190,6 +192,7 @@ export function TrackerPage({
190
192
  try {
191
193
  const page = await apiRef.current.listCommitments(query);
192
194
  setRows(page.results);
195
+ setPageNo(1);
193
196
  setTotal(page.count);
194
197
  setApplied(page.appliedFilters ?? []);
195
198
  if (page.results.length > 0) {
@@ -209,6 +212,25 @@ export function TrackerPage({
209
212
  }
210
213
  }, [query]);
211
214
 
215
+ /** The next SERVER page of what is owed, appended; the list never loads in one piece. */
216
+ const loadMore = React.useCallback(async () => {
217
+ setLoadingMore(true);
218
+ try {
219
+ const next = pageNo + 1;
220
+ const page = await apiRef.current.listCommitments({ ...query, page: next });
221
+ setRows((prev) => {
222
+ const seen = new Set(prev.map((r) => r.externalId));
223
+ return [...prev, ...page.results.filter((r) => !seen.has(r.externalId))];
224
+ });
225
+ setPageNo(next);
226
+ setTotal(page.count);
227
+ } catch (err) {
228
+ setError(failureMessage(err));
229
+ } finally {
230
+ setLoadingMore(false);
231
+ }
232
+ }, [pageNo, query]);
233
+
212
234
  const loadDone = React.useCallback(async () => {
213
235
  try {
214
236
  const page = await apiRef.current.listCommitments({ status: ['done', 'dropped'], withFocus: true, pageSize: 50 });
@@ -507,7 +529,12 @@ export function TrackerPage({
507
529
  ) : null))}
508
530
 
509
531
  {total > rows.length ? (
510
- <p className={cn.muted}>Showing the first {rows.length} of {total} open items.</p>
532
+ <p className={cn.muted}>
533
+ Showing {rows.length} of {total} open items.{' '}
534
+ <button type="button" className="text-blue-700 underline disabled:opacity-50" disabled={loadingMore} onClick={() => void loadMore()}>
535
+ {loadingMore ? 'Loading…' : 'Load more'}
536
+ </button>
537
+ </p>
511
538
  ) : null}
512
539
 
513
540
  {c.stale ? (