@nocobase/app-skills 0.1.0-beta.63 → 0.1.0-beta.64

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 (54) hide show
  1. package/package.json +1 -1
  2. package/skills/nocobase-app-development/SKILL.md +5 -0
  3. package/skills/nocobase-app-development/assets/business-examples/onboarding/client/pages/onboarding/index.tsx +35 -11
  4. package/skills/nocobase-app-development/assets/business-examples/onboarding/client/pages/onboarding/wizard.tsx +7 -2
  5. package/skills/nocobase-app-development/assets/business-examples/onboarding/tests/client/onboarding.test.tsx +8 -0
  6. package/skills/nocobase-app-development/assets/business-examples/procurement/client/pages/procurement/detail.tsx +3 -2
  7. package/skills/nocobase-app-development/assets/business-examples/procurement/client/pages/procurement/index.tsx +32 -10
  8. package/skills/nocobase-app-development/assets/customer-contacts-example/client/pages/customer-contacts/batch.tsx +8 -4
  9. package/skills/nocobase-app-development/assets/customer-contacts-example/client/pages/customer-contacts/detail.tsx +102 -53
  10. package/skills/nocobase-app-development/assets/customer-contacts-example/client/pages/customer-contacts/edit.tsx +24 -15
  11. package/skills/nocobase-app-development/assets/customer-contacts-example/client/pages/customer-contacts/index.tsx +146 -96
  12. package/skills/nocobase-app-development/assets/customer-contacts-example/client/pages/customer-contacts/locales.ts +6 -0
  13. package/skills/nocobase-app-development/assets/customer-contacts-example/client/pages/customer-contacts/shared.tsx +1 -1
  14. package/skills/nocobase-app-development/assets/customer-contacts-example/tests/client/customer-contacts.test.tsx +139 -0
  15. package/skills/nocobase-app-development/assets/list-edit-example/client/pages/skill-projects/detail.tsx +13 -4
  16. package/skills/nocobase-app-development/assets/list-edit-example/client/pages/skill-projects/edit.tsx +20 -72
  17. package/skills/nocobase-app-development/assets/list-edit-example/client/pages/skill-projects/index.tsx +20 -1
  18. package/skills/nocobase-app-development/assets/list-edit-example/client/pages/skill-projects/locales.ts +0 -8
  19. package/skills/nocobase-app-development/assets/list-edit-example/tests/client/skill-projects-changes.test.tsx +6 -3
  20. package/skills/nocobase-app-development/assets/list-edit-example/tests/client/skill-projects.test.tsx +286 -7
  21. package/skills/nocobase-app-development/references/frontend/component-selection.md +1 -1
  22. package/skills/nocobase-app-development/references/frontend/frontend-dev.md +25 -23
  23. package/skills/nocobase-app-development/references/frontend/mobile.md +136 -0
  24. package/skills/nocobase-app-development/references/frontend/references/child-routes.md +9 -5
  25. package/skills/nocobase-app-development/references/frontend/references/example/create-dialog.md +2 -0
  26. package/skills/nocobase-app-development/references/frontend/references/example/create-page.md +8 -18
  27. package/skills/nocobase-app-development/references/frontend/references/example/detail-page-tabs.md +21 -3
  28. package/skills/nocobase-app-development/references/frontend/references/example/edit-dialog.md +2 -0
  29. package/skills/nocobase-app-development/references/frontend/references/example/list-page.md +223 -95
  30. package/skills/nocobase-app-development/references/frontend/references/example/project-dashboard.md +3 -3
  31. package/skills/nocobase-app-development/references/frontend/references/example/project-form.md +19 -7
  32. package/skills/nocobase-app-development/references/frontend/references/example/types.md +5 -0
  33. package/skills/nocobase-app-development/references/frontend/references/executable-list-edit.md +1 -1
  34. package/skills/nocobase-app-development/references/frontend/references/executable-relation-batch.md +1 -1
  35. package/skills/nocobase-app-development/references/frontend/references/form.md +1 -1
  36. package/skills/nocobase-app-development/references/frontend/references/navigation.md +12 -5
  37. package/skills/nocobase-app-development/references/frontend/references/overlay.md +23 -93
  38. package/skills/nocobase-app-development/references/frontend/references/page.md +11 -8
  39. package/skills/nocobase-app-development/references/frontend/references/styling.md +14 -9
  40. package/skills/nocobase-app-development/references/frontend/references/table.md +58 -13
  41. package/skills/nocobase-app-development/references/frontend/references/testing.md +8 -8
  42. package/skills/nocobase-app-development/references/frontend/references/ui-library.md +20 -17
  43. package/skills/nocobase-app-development/references/frontend/scripts/capture.md +22 -13
  44. package/skills/nocobase-app-development/references/frontend/scripts/capture.mjs +16 -1
  45. package/skills/nocobase-app-development/references/frontend/templates/design.md +10 -4
  46. package/skills/nocobase-app-development/references/frontend/templates/prompts.md +3 -2
  47. package/skills/nocobase-app-development/references/frontend/templates/run.md +2 -2
  48. package/skills/nocobase-app-development/references/frontend/ui-acceptance.md +14 -0
  49. package/skills/nocobase-app-development/references/frontend/ui-guidelines.md +19 -16
  50. package/skills/nocobase-app-development/references/frontend/ui-workflow.md +6 -5
  51. package/skills/nocobase-app-development/references/migrations.md +2 -1
  52. package/skills/nocobase-app-development/references/submission.md +2 -2
  53. package/skills/nocobase-app-development/scripts/check-ui-components.mjs +480 -7
  54. package/skills/nocobase-app-plugin-development/references/ui-design.md +1 -1
@@ -13,14 +13,17 @@ import { useTranslation } from '@nocobase/i18n/client';
13
13
  import { useEffect, useRef, useState } from 'react';
14
14
  import { Link, Outlet, useLocation } from 'react-router';
15
15
  import type { ColumnDef } from '@tanstack/react-table';
16
- import { DataTable } from '#components/data-table';
16
+ import {
17
+ DataTable,
18
+ DataTableFilter,
19
+ DataTableSearch,
20
+ } from '#components/data-table';
17
21
  import { PageContainer } from '#components/page-container';
18
22
  import { PageHeader } from '#components/page-header';
19
23
  import { RecordLink } from '#components/record-link';
20
24
  import { StatusBadge } from '#components/status-badge';
21
25
  import { Button } from '#components/ui/button';
22
26
  import { Checkbox } from '#components/ui/checkbox';
23
- import { Input } from '#components/ui/input';
24
27
  import {
25
28
  AlertDialog,
26
29
  AlertDialogContent,
@@ -98,6 +101,7 @@ function CustomerContactsContent() {
98
101
  });
99
102
  const selected = selection.key === selectionKey ? selection.ids : [];
100
103
  const [confirmReset, setConfirmReset] = useState(false);
104
+ const appliedFilters = (status !== 'all' ? 1 : 0) + (owner ? 1 : 0);
101
105
  const [resetError, setResetError] = useState<unknown>();
102
106
  const lock = useWriteLock();
103
107
  const headerRef = useRef<HTMLDivElement>(null);
@@ -133,16 +137,19 @@ function CustomerContactsContent() {
133
137
  ...(edit.can || assign.can
134
138
  ? [
135
139
  {
136
- id: 'selection',
140
+ // DataTable shows this header above the phone cards too, as "Select all on this page".
141
+ id: 'select',
137
142
  header: () => (
138
143
  <Checkbox
139
- aria-label={t('customerContacts.selected', {
140
- count: rows.length,
141
- })}
144
+ aria-label={t('customerContacts.selectAll')}
142
145
  checked={
143
146
  rows.length > 0 &&
144
147
  rows.every((row) => selected.includes(row.id))
145
148
  }
149
+ indeterminate={
150
+ selected.length > 0 &&
151
+ !rows.every((row) => selected.includes(row.id))
152
+ }
146
153
  disabled={request.loading || !active}
147
154
  onCheckedChange={(checked) =>
148
155
  setSelection({
@@ -254,57 +261,6 @@ function CustomerContactsContent() {
254
261
  />
255
262
  </div>
256
263
  {!confirmReset && <WriteFeedback error={resetError} />}
257
- <div className='flex flex-wrap items-center gap-2'>
258
- <CustomerSearch
259
- value={search}
260
- onSearch={(value) => updateQuery('search', value)}
261
- />
262
- <StatusChoice
263
- all
264
- value={status}
265
- onChange={(value) => updateQuery('status', value)}
266
- />
267
- <div className='w-full sm:w-48'>
268
- <RelationPicker
269
- kind='salesReps'
270
- value={owner}
271
- label={t('customerContacts.owner')}
272
- onChange={(value) => updateQuery('ownerId', value)}
273
- />
274
- </div>
275
- {(search || status !== 'all' || owner) && (
276
- <Button
277
- variant='ghost'
278
- onClick={() => {
279
- const next = new URLSearchParams(params);
280
- for (const key of ['search', 'status', 'ownerId', 'page'])
281
- next.delete(key);
282
- setSelection({ key: '', ids: [] });
283
- setParams(next, { replace: true });
284
- }}
285
- >
286
- {t('customerContacts.clear')}
287
- </Button>
288
- )}
289
- </div>
290
- {selected.length > 0 && (
291
- <div className='flex flex-wrap items-center gap-2'>
292
- <span className='text-sm'>
293
- {t('customerContacts.selected', { count: selected.length })}
294
- </span>
295
- {(edit.can || assign.can) && (
296
- <Button
297
- variant='outline'
298
- render={
299
- <Link to={{ pathname: 'batch', search: location.search }} />
300
- }
301
- nativeButton={false}
302
- >
303
- {t('customerContacts.batchTitle')}
304
- </Button>
305
- )}
306
- </div>
307
- )}
308
264
  <DataTable
309
265
  columns={columns}
310
266
  data={rows}
@@ -322,6 +278,82 @@ function CustomerContactsContent() {
322
278
  loading={active && request.loading}
323
279
  loadingIdentity={path}
324
280
  onRetry={reload}
281
+ // One row on every width (mobile.md M4.1): DataTable puts the search box first, then the filters inline from
282
+ // md up or, on a phone, an icon Filters button named and badged with the applied count that opens them in a
283
+ // bottom sheet; Clear filters joins while something is applied (M4.2).
284
+ search={
285
+ <DataTableSearch
286
+ value={search}
287
+ label={t('customerContacts.search')}
288
+ onSearch={(value) => updateQuery('search', value)}
289
+ />
290
+ }
291
+ filters={
292
+ <>
293
+ <DataTableFilter label={t('customerContacts.status')}>
294
+ <StatusChoice
295
+ all
296
+ value={status}
297
+ onChange={(value) => updateQuery('status', value)}
298
+ />
299
+ </DataTableFilter>
300
+ <DataTableFilter label={t('customerContacts.owner')}>
301
+ <div className='w-48'>
302
+ <RelationPicker
303
+ kind='salesReps'
304
+ value={owner}
305
+ label={t('customerContacts.owner')}
306
+ onChange={(value) => updateQuery('ownerId', value)}
307
+ />
308
+ </div>
309
+ </DataTableFilter>
310
+ </>
311
+ }
312
+ filterCount={appliedFilters}
313
+ filtered={Boolean(search || status !== 'all' || owner)}
314
+ onClearFilters={() => {
315
+ const next = new URLSearchParams(params);
316
+ for (const key of ['search', 'status', 'ownerId', 'page'])
317
+ next.delete(key);
318
+ setSelection({ key: '', ids: [] });
319
+ setParams(next, { replace: true });
320
+ }}
321
+ // Transient: the selection count and its batch action join the controls' row while rows are selected.
322
+ toolbar={() =>
323
+ selected.length > 0 ? (
324
+ <div className='flex flex-wrap items-center gap-2'>
325
+ <span className='text-sm'>
326
+ {t('customerContacts.selected', { count: selected.length })}
327
+ </span>
328
+ {(edit.can || assign.can) && (
329
+ <Button
330
+ variant='outline'
331
+ render={
332
+ <Link to={{ pathname: 'batch', search: location.search }} />
333
+ }
334
+ nativeButton={false}
335
+ >
336
+ {t('customerContacts.batchTitle')}
337
+ </Button>
338
+ )}
339
+ </div>
340
+ ) : null
341
+ }
342
+ renderCard={(row) => (
343
+ <CustomerCard
344
+ customer={row.original}
345
+ search={location.search}
346
+ selection={
347
+ edit.can || assign.can
348
+ ? {
349
+ checked: selected.includes(row.original.id),
350
+ disabled: request.loading || !active,
351
+ onChange: (checked) => toggle(row.original.id, checked),
352
+ }
353
+ : undefined
354
+ }
355
+ />
356
+ )}
325
357
  />
326
358
  <AlertDialog
327
359
  open={confirmReset}
@@ -381,6 +413,63 @@ function CustomerContactsContent() {
381
413
  </PageContainer>
382
414
  );
383
415
  }
416
+ /**
417
+ * One customer on a phone (mobile.md M3): the selection checkbox when batch actions exist, the name link and status
418
+ * first, then the owner. The table's columns stay for wider screens. Like the rows, the card has no action menu: this
419
+ * list changes customers through selection and the batch action, and a customer's own edit belongs with its contacts
420
+ * on the customer's page (case (c) of M3.1).
421
+ */
422
+ function CustomerCard({
423
+ customer,
424
+ search,
425
+ selection,
426
+ }: {
427
+ customer: Customer;
428
+ search: string;
429
+ selection?: {
430
+ checked: boolean;
431
+ disabled: boolean;
432
+ onChange: (checked: boolean) => void;
433
+ };
434
+ }) {
435
+ const { t } = useTranslation();
436
+ return (
437
+ <div className='flex items-start gap-3 rounded-lg border p-4'>
438
+ {selection ? (
439
+ <Checkbox
440
+ className='mt-0.5'
441
+ aria-label={t('customerContacts.selectRow', { name: customer.name })}
442
+ checked={selection.checked}
443
+ disabled={selection.disabled}
444
+ onCheckedChange={selection.onChange}
445
+ />
446
+ ) : null}
447
+ <div className='flex min-w-0 flex-1 flex-col gap-2'>
448
+ <div className='flex flex-wrap items-center gap-2'>
449
+ <RecordLink
450
+ to={{ pathname: customer.id, search }}
451
+ className='min-w-0 break-words'
452
+ >
453
+ {customer.name}
454
+ </RecordLink>
455
+ <StatusBadge
456
+ tone={customer.status === 'active' ? 'success' : 'neutral'}
457
+ >
458
+ {t(`customerContacts.${customer.status}`)}
459
+ </StatusBadge>
460
+ </div>
461
+ <dl className='grid grid-cols-[auto_minmax(0,1fr)] gap-x-2 text-sm'>
462
+ <dt className='text-muted-foreground'>
463
+ {t('customerContacts.owner')}
464
+ </dt>
465
+ <dd className='min-w-0'>
466
+ <OwnerName id={customer.ownerId} />
467
+ </dd>
468
+ </dl>
469
+ </div>
470
+ </div>
471
+ );
472
+ }
384
473
  export function OwnerName({ id }: { id: string }) {
385
474
  const { t } = useTranslation();
386
475
  const api = useApiClient();
@@ -413,42 +502,3 @@ export function OwnerName({ id }: { id: string }) {
413
502
  </span>
414
503
  );
415
504
  }
416
- function CustomerSearch({
417
- value,
418
- onSearch,
419
- }: {
420
- value: string;
421
- onSearch: (value: string) => void;
422
- }) {
423
- const { t } = useTranslation();
424
- const [text, setText] = useState(value);
425
- const [seen, setSeen] = useState(value);
426
- const [sent, setSent] = useState(value);
427
- const [composing, setComposing] = useState(false);
428
- if (value !== seen) {
429
- setSeen(value);
430
- if (value !== sent) setText(value);
431
- }
432
- useEffect(() => {
433
- if (composing || text.trim() === value) return;
434
- const timer = setTimeout(() => {
435
- setSent(text.trim());
436
- onSearch(text.trim());
437
- }, 300);
438
- return () => clearTimeout(timer);
439
- }, [text, composing, value, onSearch]);
440
- return (
441
- <Input
442
- aria-label={t('customerContacts.search')}
443
- placeholder={t('customerContacts.search')}
444
- value={text}
445
- onChange={(e) => setText(e.target.value)}
446
- onCompositionStart={() => setComposing(true)}
447
- onCompositionEnd={(e) => {
448
- setComposing(false);
449
- setText(e.currentTarget.value);
450
- }}
451
- className='w-full sm:max-w-xs'
452
- />
453
- );
454
- }
@@ -20,10 +20,13 @@ export const enUS = {
20
20
  paused: 'Paused',
21
21
  closed: 'Closed',
22
22
  clear: 'Clear filters',
23
+ filters: 'Filters',
24
+ filtersApplied: 'Filters · {{count}}',
23
25
  select: 'Select a record',
24
26
  unavailable: 'Record unavailable',
25
27
  selected: '{{count}} selected on this page',
26
28
  selectRow: 'Select {{name}}',
29
+ selectAll: 'Select all customers on this page',
27
30
  edit: 'Edit',
28
31
  editCustomer: 'Edit customer',
29
32
  newContact: 'New contact',
@@ -96,10 +99,13 @@ export const zhCN: Record<keyof typeof enUS, string> = {
96
99
  paused: '暂停',
97
100
  closed: '已关闭',
98
101
  clear: '清除筛选',
102
+ filters: '筛选',
103
+ filtersApplied: '筛选 · {{count}}',
99
104
  select: '选择记录',
100
105
  unavailable: '记录不可用',
101
106
  selected: '已选择当前页 {{count}} 条',
102
107
  selectRow: '选择 {{name}}',
108
+ selectAll: '选择本页全部客户',
103
109
  edit: '编辑',
104
110
  editCustomer: '编辑客户',
105
111
  newContact: '新建联系人',
@@ -114,7 +114,7 @@ export function Choice({
114
114
  items={options}
115
115
  disabled={disabled}
116
116
  >
117
- <SelectTrigger aria-label={label} className='w-full sm:w-40'>
117
+ <SelectTrigger aria-label={label} className='w-full md:w-40'>
118
118
  <SelectValue />
119
119
  </SelectTrigger>
120
120
  <SelectContent className='w-auto max-w-[min(var(--container-sm),var(--available-width))] min-w-(--anchor-width) [&_[data-slot=select-item]>:first-child]:whitespace-normal'>
@@ -678,3 +678,142 @@ it('restarts the picker wait for each search and announces a slow next page outs
678
678
  vi.useRealTimers();
679
679
  }
680
680
  });
681
+
682
+ it('shows cards and a filter sheet with the applied count on a phone', async () => {
683
+ vi.stubGlobal('matchMedia', (query: string) => ({
684
+ matches: true,
685
+ media: query,
686
+ addEventListener: () => {},
687
+ removeEventListener: () => {},
688
+ }));
689
+ const calls: ApiCall[] = [];
690
+ await mount((call) => {
691
+ if (call.path === 'customerContacts/customers') {
692
+ calls.push(call);
693
+ return list([customer]);
694
+ }
695
+ throw new Error(`Unexpected ${call.path}`);
696
+ }, '/customer-contacts?ownerId=crm-rep');
697
+
698
+ const card = within(await screen.findByRole('list'))
699
+ .getAllByRole('listitem')
700
+ .at(0)!;
701
+ expect(within(card).getByRole('link', { name: 'Acorn 01' })).toBeVisible();
702
+ expect(within(card).getByText('Active')).toBeVisible();
703
+ expect(await within(card).findByText('Alex Rivera')).toBeVisible();
704
+ expect(screen.queryByRole('table')).not.toBeInTheDocument();
705
+
706
+ await userEvent.click(screen.getByRole('button', { name: 'Filters · 1' }));
707
+ const sheet = await screen.findByRole('dialog', { name: 'Filters' });
708
+ await userEvent.click(
709
+ within(sheet).getByRole('combobox', { name: 'Status' }),
710
+ );
711
+ await userEvent.click(await screen.findByRole('option', { name: 'Paused' }));
712
+ await waitFor(() =>
713
+ expect(calls.at(-1)?.query).toMatchObject({
714
+ status: 'paused',
715
+ ownerId: 'crm-rep',
716
+ page: '1',
717
+ }),
718
+ );
719
+ // The sheet is a temporary panel: closing it keeps the filters, which live in the URL.
720
+ await userEvent.keyboard('{Escape}');
721
+ expect(
722
+ await screen.findByRole('button', { name: 'Filters · 2' }),
723
+ ).toBeVisible();
724
+ });
725
+
726
+ it('selects and clears the whole page from the phone cards and keeps the batch target across widths', async () => {
727
+ let phone = true;
728
+ const listeners = new Set<() => void>();
729
+ vi.stubGlobal('matchMedia', (query: string) => ({
730
+ get matches() {
731
+ return phone;
732
+ },
733
+ media: query,
734
+ addEventListener: (_: string, listener: () => void) =>
735
+ listeners.add(listener),
736
+ removeEventListener: (_: string, listener: () => void) =>
737
+ listeners.delete(listener),
738
+ }));
739
+ const setPhone = (next: boolean) => {
740
+ phone = next;
741
+ act(() => {
742
+ for (const listener of listeners) listener();
743
+ });
744
+ };
745
+ const birch = { ...customer, id: 'customer-02', name: 'Birch 02' };
746
+ const cedar = { ...customer, id: 'customer-11', name: 'Cedar 11' };
747
+ await mount(({ path, query }) => {
748
+ if (path === 'customerContacts/customers') {
749
+ if (query?.status === 'paused') return list([]);
750
+ return Number(query?.page) === 2
751
+ ? list([cedar], 2, 12)
752
+ : list([customer, birch], 1, 12);
753
+ }
754
+ throw new Error(`Unexpected ${path}`);
755
+ });
756
+ // The page re-renders its select-all checkbox, so query it each time.
757
+ // Its accessible name is the page's own label ("Select all customers on this page") or, where the checkbox takes
758
+ // its name from the wrapping label, the visible text; find it inside that label so both resolve the same control.
759
+ const selectAll = () =>
760
+ within(
761
+ screen.getByText('Select all on this page').closest('label')!,
762
+ ).getByRole('checkbox');
763
+ await screen.findByText('Select all on this page');
764
+ expect(screen.queryByRole('table')).not.toBeInTheDocument();
765
+
766
+ // One card selected: the page is partly selected.
767
+ await userEvent.click(
768
+ screen.getByRole('checkbox', { name: 'Select Acorn 01' }),
769
+ );
770
+ expect(selectAll()).toHaveAttribute('aria-checked', 'mixed');
771
+ // One tap on the label selects the rest of the page.
772
+ await userEvent.click(screen.getByText('Select all on this page'));
773
+ await screen.findByText('2 selected on this page');
774
+ expect(selectAll()).toHaveAttribute('aria-checked', 'true');
775
+
776
+ // The selection survives a switch to the desktop table and back.
777
+ setPhone(false);
778
+ expect(await screen.findByRole('table')).toBeVisible();
779
+ expect(screen.getByText('2 selected on this page')).toBeVisible();
780
+ setPhone(true);
781
+ await waitFor(() =>
782
+ expect(screen.queryByRole('table')).not.toBeInTheDocument(),
783
+ );
784
+ expect(screen.getByText('2 selected on this page')).toBeVisible();
785
+
786
+ // A second tap clears the page; a third selects it again, and the batch action targets exactly this page.
787
+ await userEvent.click(selectAll());
788
+ expect(screen.queryByText(/selected on this page/u)).not.toBeInTheDocument();
789
+ await userEvent.click(selectAll());
790
+ await screen.findByText('2 selected on this page');
791
+ await userEvent.click(
792
+ screen.getByRole('button', { name: 'Edit selected customers' }),
793
+ );
794
+ await screen.findByText('This assignment will change 2 selected customers.');
795
+ await userEvent.keyboard('{Escape}');
796
+ await waitFor(() =>
797
+ expect(
798
+ screen.queryByText('This assignment will change 2 selected customers.'),
799
+ ).not.toBeInTheDocument(),
800
+ );
801
+
802
+ // Selection is scoped to the page and the query: paging and filtering clear it.
803
+ // Closing the batch dialog without applying keeps the page's selection.
804
+ expect(screen.getByText('2 selected on this page')).toBeVisible();
805
+ await userEvent.click(screen.getByRole('button', { name: /next page/i }));
806
+ await screen.findByRole('checkbox', { name: 'Select Cedar 11' });
807
+ expect(screen.queryByText(/selected on this page/u)).not.toBeInTheDocument();
808
+ await userEvent.click(screen.getByText('Select all on this page'));
809
+ await screen.findByText('1 selected on this page');
810
+ await userEvent.click(screen.getByRole('button', { name: 'Filters' }));
811
+ const sheet = await screen.findByRole('dialog', { name: 'Filters' });
812
+ await userEvent.click(
813
+ within(sheet).getByRole('combobox', { name: 'Status' }),
814
+ );
815
+ await userEvent.click(await screen.findByRole('option', { name: 'Paused' }));
816
+ await userEvent.keyboard('{Escape}');
817
+ await screen.findByText('No results');
818
+ expect(screen.queryByText(/selected on this page/u)).not.toBeInTheDocument();
819
+ });
@@ -11,6 +11,7 @@ import { useState } from 'react';
11
11
  import {
12
12
  Link,
13
13
  Outlet,
14
+ useLocation,
14
15
  useNavigate,
15
16
  useParams,
16
17
  useResolvedPath,
@@ -33,7 +34,8 @@ import { Button } from '#components/ui/button';
33
34
  import { Skeleton } from '#components/ui/skeleton';
34
35
  import { announceDataChange } from '#hooks/use-data-changes';
35
36
  import { useListData } from '#hooks/use-list-data';
36
- import { useRouteSearches } from '../../routing/route-context.js';
37
+ import { TABLE_URL_KEYS } from '#hooks/use-table-url-state';
38
+ import { useAncestorSearch } from '../../routing/route-context.js';
37
39
  import type { SkillProject } from './index.js';
38
40
  import { projectScope } from './scopes.js';
39
41
 
@@ -41,8 +43,10 @@ import { projectScope } from './scopes.js';
41
43
  export default function SkillProjectDetailPage() {
42
44
  const { t } = useTranslation();
43
45
  const { projectId = '' } = useParams();
46
+ const location = useLocation();
44
47
  const owner = useResolvedPath('..').pathname;
45
- const searches = useRouteSearches();
48
+ // The list's own keys: after a reload of this page or its edit dialog, they come from the URL the list linked to.
49
+ const ownerSearch = useAncestorSearch(owner, TABLE_URL_KEYS);
46
50
  const scope = projectScope(projectId);
47
51
  // The project this page deleted stays on screen while it returns to the list.
48
52
  const [deleted, setDeleted] = useState<SkillProject>();
@@ -54,7 +58,7 @@ export default function SkillProjectDetailPage() {
54
58
  const status =
55
59
  request.error instanceof ApiClientError ? request.error.status : undefined;
56
60
  const project = deleted ?? (request.error ? undefined : request.data?.data);
57
- const source = { pathname: owner, search: searches.get(owner) ?? '' };
61
+ const source = { pathname: owner, search: ownerSearch };
58
62
  usePageBreadcrumb([
59
63
  { label: t('skillProjects.title'), to: source },
60
64
  { label: project?.name ?? t('skillProjects.detail') },
@@ -74,7 +78,12 @@ export default function SkillProjectDetailPage() {
74
78
  return source;
75
79
  }}
76
80
  />
77
- <Button render={<Link to='edit' />} nativeButton={false}>
81
+ <Button
82
+ render={
83
+ <Link to={{ pathname: 'edit', search: location.search }} />
84
+ }
85
+ nativeButton={false}
86
+ >
78
87
  {t('skillProjects.editAction')}
79
88
  </Button>
80
89
  </>
@@ -14,16 +14,6 @@ import { FeedbackForm } from '#components/feedback-form';
14
14
  import { RouteDialog } from '#components/route-dialog';
15
15
  import { useRouteOverlay } from '#components/use-route-overlay';
16
16
  import { Alert, AlertDescription } from '#components/ui/alert';
17
- import {
18
- AlertDialog,
19
- AlertDialogContent,
20
- AlertDialogHeader,
21
- AlertDialogTitle,
22
- AlertDialogDescription,
23
- AlertDialogFooter,
24
- AlertDialogCancel,
25
- AlertDialogAction,
26
- } from '#components/ui/alert-dialog';
27
17
  import { Button } from '#components/ui/button';
28
18
  import { Skeleton } from '#components/ui/skeleton';
29
19
  import { Input } from '#components/ui/input';
@@ -121,8 +111,12 @@ function ProjectEditor({
121
111
  const submission = useSubmission({
122
112
  scope: `${session?.user.id}:skillProjects:${project?.id ?? 'new'}`,
123
113
  });
114
+ // What is saved, as the form shows it: the record, or the blank values of a new project. A form that restores a
115
+ // draft starts from it (`defaultValues: draft ?? saved`) and keeps this as `savedValues`, so leaving with the draft
116
+ // still asks (mobile.md M7.4).
117
+ const [saved] = useState(() => ({ name: project?.name ?? '' }));
124
118
  const form = useForm({
125
- defaultValues: { name: project?.name ?? '' },
119
+ defaultValues: saved,
126
120
  shouldFocusError: false,
127
121
  });
128
122
  const navigate = useNavigate();
@@ -136,45 +130,21 @@ function ProjectEditor({
136
130
  const [confirmedMissing, setConfirmedMissing] = useState<
137
131
  'committed' | 'not-committed'
138
132
  >();
133
+ // Set once saved or once the record is gone, so the guard below lets the dialog close.
139
134
  const savedRef = useRef(false);
140
- const [confirmDiscard, setConfirmDiscard] = useState(false);
141
- const discardRef = useRef<{
142
- promise: Promise<boolean>;
143
- resolve: (value: boolean) => void;
144
- } | null>(null);
145
- const decideDiscard = (discard: boolean) => {
146
- discardRef.current?.resolve(discard);
147
- discardRef.current = null;
148
- setConfirmDiscard(false);
149
- };
150
- useEffect(
151
- () => () => {
152
- discardRef.current?.resolve(false);
153
- },
154
- [],
135
+ // No way out only while a save is in flight. An unknown outcome (`submission.pending`, after a lost response or a
136
+ // 5xx) is not a lock: the FeedbackForm's `values` still make every way out ask, and discarding leaves. The operation
137
+ // key stays in session storage, so reopening the form offers the same retry (`restoringInput`).
138
+ useNavigationGuard(
139
+ () => savedRef.current || !(busyRef.current || submission.submitting),
155
140
  );
156
- useNavigationGuard(() => {
157
- if (savedRef.current) return true;
158
- if (busyRef.current || submission.submitting || submission.pending)
159
- return false;
160
- if (!form.formState.isDirty) return true;
161
- if (discardRef.current) return discardRef.current.promise;
162
- let resolve!: (value: boolean) => void;
163
- const promise = new Promise<boolean>((done) => {
164
- resolve = done;
165
- });
166
- discardRef.current = { promise, resolve };
167
- setConfirmDiscard(true);
168
- return promise;
169
- });
170
141
  useEffect(() => {
171
142
  const warn = (event: BeforeUnloadEvent) => {
172
- if (busyRef.current || submission.pending || form.formState.isDirty)
173
- event.preventDefault();
143
+ if (busyRef.current || submission.pending) event.preventDefault();
174
144
  };
175
145
  window.addEventListener('beforeunload', warn);
176
146
  return () => window.removeEventListener('beforeunload', warn);
177
- }, [submission.pending, form.formState.isDirty]);
147
+ }, [submission.pending]);
178
148
  const submit = async () => {
179
149
  if (!session || busyRef.current) return;
180
150
  busyRef.current = true;
@@ -252,14 +222,13 @@ function ProjectEditor({
252
222
  <RouteDialog
253
223
  title={t(project ? 'skillProjects.edit' : 'skillProjects.create')}
254
224
  className='sm:max-w-md'
255
- beforeClose={() =>
256
- !busyRef.current && !submission.submitting && !submission.pending
257
- }
225
+ // Every way out asks "Discard changes?" while the form's values differ from the saved ones (the FeedbackForm's
226
+ // `values` and `savedValues` below): ×, Esc, the backdrop, Cancel and browser back. The save's own navigation,
227
+ // from the FeedbackForm's onSubmit, leaves without asking.
228
+ beforeClose={() => !busyRef.current && !submission.submitting}
258
229
  footer={
259
230
  <>
260
- <CancelButton
261
- disabled={submission.submitting || submission.pending}
262
- />
231
+ <CancelButton disabled={submission.submitting} />
263
232
  <Button
264
233
  type='submit'
265
234
  form={formId}
@@ -276,29 +245,6 @@ function ProjectEditor({
276
245
  </>
277
246
  }
278
247
  >
279
- <AlertDialog
280
- open={confirmDiscard}
281
- onOpenChange={(open) => {
282
- if (!open) decideDiscard(false);
283
- }}
284
- >
285
- <AlertDialogContent className='sm:max-w-md'>
286
- <AlertDialogHeader>
287
- <AlertDialogTitle>{t('skillProjects.discard')}</AlertDialogTitle>
288
- <AlertDialogDescription>
289
- {t('skillProjects.discardHint')}
290
- </AlertDialogDescription>
291
- </AlertDialogHeader>
292
- <AlertDialogFooter>
293
- <AlertDialogCancel>
294
- {t('skillProjects.keepEditing')}
295
- </AlertDialogCancel>
296
- <AlertDialogAction onClick={() => decideDiscard(true)}>
297
- {t('skillProjects.discardAction')}
298
- </AlertDialogAction>
299
- </AlertDialogFooter>
300
- </AlertDialogContent>
301
- </AlertDialog>
302
248
  {restoringInput && !error ? (
303
249
  <Alert>
304
250
  <AlertDescription>{t('skillProjects.restoreInput')}</AlertDescription>
@@ -306,6 +252,8 @@ function ProjectEditor({
306
252
  ) : null}
307
253
  <FeedbackForm
308
254
  id={formId}
255
+ values={form.getValues}
256
+ savedValues={saved}
309
257
  error={error}
310
258
  errorContent={
311
259
  confirmedMissing