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

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 (26) hide show
  1. package/package.json +1 -1
  2. package/skills/nocobase-app-development/assets/list-edit-example/client/pages/skill-projects/detail.tsx +165 -36
  3. package/skills/nocobase-app-development/assets/list-edit-example/client/pages/skill-projects/edit.tsx +19 -16
  4. package/skills/nocobase-app-development/assets/list-edit-example/client/pages/skill-projects/index.tsx +141 -31
  5. package/skills/nocobase-app-development/assets/list-edit-example/client/pages/skill-projects/locales.ts +28 -0
  6. package/skills/nocobase-app-development/assets/list-edit-example/client/pages/skill-projects/scopes.ts +3 -0
  7. package/skills/nocobase-app-development/assets/list-edit-example/server/providers/skill-projects.ts +42 -4
  8. package/skills/nocobase-app-development/assets/list-edit-example/server/routes/skill-projects.ts +59 -2
  9. package/skills/nocobase-app-development/assets/list-edit-example/tests/client/skill-projects-changes.test.tsx +360 -0
  10. package/skills/nocobase-app-development/assets/list-edit-example/tests/client/skill-projects.test.tsx +2 -0
  11. package/skills/nocobase-app-development/assets/list-edit-example/tests/server/skill-projects.test.ts +73 -0
  12. package/skills/nocobase-app-development/references/frontend/frontend-dev.md +1 -1
  13. package/skills/nocobase-app-development/references/frontend/references/api.md +1 -1
  14. package/skills/nocobase-app-development/references/frontend/references/data-changes.md +70 -0
  15. package/skills/nocobase-app-development/references/frontend/references/executable-list-edit.md +4 -4
  16. package/skills/nocobase-app-development/references/frontend/references/overlay.md +1 -1
  17. package/skills/nocobase-app-development/references/frontend/references/page-freshness.md +1 -1
  18. package/skills/nocobase-app-development/references/frontend/references/table.md +2 -2
  19. package/skills/nocobase-app-development/references/frontend/references/testing.md +2 -0
  20. package/skills/nocobase-app-development/references/frontend/references/ui-library.md +1 -1
  21. package/skills/nocobase-app-development/references/frontend/ui-guidelines.md +1 -1
  22. package/skills/nocobase-app-development/references/settings-navigation.md +1 -1
  23. package/skills/nocobase-app-plugin-development/references/testing.md +1 -1
  24. package/skills/nocobase-app-upgrade/SKILL.md +2 -0
  25. package/skills/nocobase-app-upgrade/references/data-change-upgrade.md +20 -0
  26. package/skills/nocobase-app-upgrade/references/notification-template-upgrade.md +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/app-skills",
3
- "version": "0.1.0-beta.62",
3
+ "version": "0.1.0-beta.63",
4
4
  "description": "Agent Skills for developing applications and plugins, upgrading and deploying NocoBase applications.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -1,58 +1,62 @@
1
- import { ApiClientError, usePageBreadcrumb } from '@nocobase/app-client';
1
+ import {
2
+ ApiClientError,
3
+ useApiClient,
4
+ usePageBreadcrumb,
5
+ useSubmission,
6
+ useToaster,
7
+ } from '@nocobase/app-client';
8
+ import { useAuthentication } from '@nocobase/app-plugin-authentication/client';
2
9
  import { useTranslation } from '@nocobase/i18n/client';
3
- import { useMemo } from 'react';
10
+ import { useState } from 'react';
4
11
  import {
5
12
  Link,
6
13
  Outlet,
14
+ useNavigate,
7
15
  useParams,
8
16
  useResolvedPath,
9
- useOutletContext,
10
17
  } from 'react-router';
11
18
  import { PageContainer } from '#components/page-container';
12
19
  import { PageHeader } from '#components/page-header';
13
20
  import { RouteChildPage } from '#components/route-child-page';
14
21
  import { Alert, AlertDescription } from '#components/ui/alert';
22
+ import {
23
+ AlertDialog,
24
+ AlertDialogAction,
25
+ AlertDialogCancel,
26
+ AlertDialogContent,
27
+ AlertDialogDescription,
28
+ AlertDialogFooter,
29
+ AlertDialogHeader,
30
+ AlertDialogTitle,
31
+ } from '#components/ui/alert-dialog';
15
32
  import { Button } from '#components/ui/button';
16
33
  import { Skeleton } from '#components/ui/skeleton';
34
+ import { announceDataChange } from '#hooks/use-data-changes';
17
35
  import { useListData } from '#hooks/use-list-data';
18
36
  import { useRouteSearches } from '../../routing/route-context.js';
19
37
  import type { SkillProject } from './index.js';
38
+ import { projectScope } from './scopes.js';
20
39
 
21
40
  /** A record always names its list, including on a direct open or an unsuccessful load. */
22
41
  export default function SkillProjectDetailPage() {
23
42
  const { t } = useTranslation();
24
- const { projectId } = useParams();
43
+ const { projectId = '' } = useParams();
25
44
  const owner = useResolvedPath('..').pathname;
26
45
  const searches = useRouteSearches();
27
- const ownerContext = useOutletContext<{
28
- reload: () => void;
29
- onSaved: (project: SkillProject) => void;
30
- }>();
46
+ const scope = projectScope(projectId);
47
+ // The project this page deleted stays on screen while it returns to the list.
48
+ const [deleted, setDeleted] = useState<SkillProject>();
49
+ // Its edit dialog announces the saved project, which replaces this read.
31
50
  const request = useListData<{ data: SkillProject }>(
32
- `skillProjects/${encodeURIComponent(projectId ?? '')}`,
33
- );
34
- const { reload, replaceData } = request;
35
- const context = useMemo(
36
- () => ({
37
- reload: () => {
38
- reload();
39
- ownerContext.reload();
40
- },
41
- onSaved: (project: SkillProject) => {
42
- replaceData({ data: project });
43
- ownerContext.onSaved(project);
44
- },
45
- }),
46
- [reload, replaceData, ownerContext],
51
+ `skillProjects/${encodeURIComponent(projectId)}`,
52
+ { scopes: [scope], active: !deleted },
47
53
  );
48
54
  const status =
49
55
  request.error instanceof ApiClientError ? request.error.status : undefined;
50
- const project = request.error ? undefined : request.data?.data;
56
+ const project = deleted ?? (request.error ? undefined : request.data?.data);
57
+ const source = { pathname: owner, search: searches.get(owner) ?? '' };
51
58
  usePageBreadcrumb([
52
- {
53
- label: t('skillProjects.title'),
54
- to: { pathname: owner, search: searches.get(owner) ?? '' },
55
- },
59
+ { label: t('skillProjects.title'), to: source },
56
60
  { label: project?.name ?? t('skillProjects.detail') },
57
61
  ]);
58
62
  return (
@@ -61,14 +65,23 @@ export default function SkillProjectDetailPage() {
61
65
  <PageHeader
62
66
  title={project?.name ?? t('skillProjects.detail')}
63
67
  actions={
64
- project ? (
65
- <Button render={<Link to='edit' />}>
66
- {t('skillProjects.editAction')}
67
- </Button>
68
+ project && !deleted ? (
69
+ <>
70
+ <DeleteProject
71
+ project={project}
72
+ onDeleted={() => {
73
+ setDeleted(project);
74
+ return source;
75
+ }}
76
+ />
77
+ <Button render={<Link to='edit' />} nativeButton={false}>
78
+ {t('skillProjects.editAction')}
79
+ </Button>
80
+ </>
68
81
  ) : undefined
69
82
  }
70
83
  />
71
- {request.error ? (
84
+ {request.error && !deleted ? (
72
85
  <Alert variant='destructive'>
73
86
  <AlertDescription>
74
87
  {t(
@@ -87,17 +100,133 @@ export default function SkillProjectDetailPage() {
87
100
  ) : null}
88
101
  </AlertDescription>
89
102
  </Alert>
90
- ) : request.loading ? (
103
+ ) : !project ? (
91
104
  <Skeleton
92
105
  className='h-16 w-full'
93
106
  aria-label={t('skillProjects.loading')}
94
107
  />
95
108
  ) : (
96
- <p>{project?.name}</p>
109
+ <p>{project.name}</p>
97
110
  )}
98
111
  {/* Editing is a dialog: its Cancel closes the dialog rather than leaving the detail. */}
99
- <Outlet context={context} />
112
+ <Outlet />
100
113
  </PageContainer>
101
114
  </RouteChildPage>
102
115
  );
103
116
  }
117
+
118
+ /**
119
+ * Deletes with an operation key. Success or an already-missing record returns
120
+ * to the source list; an unknown outcome keeps the dialog for a same-key retry
121
+ * and asks every affected view to read the server again.
122
+ */
123
+ function DeleteProject({
124
+ project,
125
+ onDeleted,
126
+ }: {
127
+ readonly project: SkillProject;
128
+ readonly onDeleted: () => { pathname: string; search: string };
129
+ }) {
130
+ const { t } = useTranslation();
131
+ const api = useApiClient();
132
+ const toaster = useToaster();
133
+ const navigate = useNavigate();
134
+ const { session } = useAuthentication();
135
+ const submission = useSubmission({
136
+ scope: `${session?.user.id}:skillProjects:${project.id}:delete`,
137
+ });
138
+ const [open, setOpen] = useState(false);
139
+ const [error, setError] = useState<'denied' | 'failed' | 'uncertain'>();
140
+ const scope = projectScope(project.id);
141
+ const finish = async (message: string) => {
142
+ const source = onDeleted();
143
+ announceDataChange({ scopes: [scope], results: { [scope]: null } });
144
+ toaster.show({ type: 'success', title: message });
145
+ setOpen(false);
146
+ await navigate(source);
147
+ };
148
+ const confirm = async () => {
149
+ const recovering = submission.pending;
150
+ setError(undefined);
151
+ try {
152
+ const done = await submission.run({ id: project.id }, (key, signal) =>
153
+ api.request<{ data: { id: string } }>({
154
+ path: `skillProjects/${encodeURIComponent(project.id)}`,
155
+ method: 'DELETE',
156
+ headers: { 'Idempotency-Key': key },
157
+ signal,
158
+ }),
159
+ );
160
+ if (done)
161
+ await finish(t('skillProjects.deleted', { name: project.name }));
162
+ } catch (failure) {
163
+ const code = failure instanceof ApiClientError ? failure.status : 0;
164
+ if (code === 404) {
165
+ // The record is gone, whoever removed it: what the user wanted has happened.
166
+ await finish(t('skillProjects.alreadyDeleted', { name: project.name }));
167
+ return;
168
+ }
169
+ if (recovering || code === 0 || code >= 500) {
170
+ // Never resubmit on its own: affected views read the server instead.
171
+ announceDataChange({ scopes: [scope] });
172
+ setError('uncertain');
173
+ } else setError(code === 403 ? 'denied' : 'failed');
174
+ }
175
+ };
176
+ return (
177
+ <AlertDialog
178
+ open={open}
179
+ onOpenChange={(next) => {
180
+ if (submission.submitting) return;
181
+ if (!next) setError(undefined);
182
+ setOpen(next);
183
+ }}
184
+ >
185
+ <Button variant='outline' onClick={() => setOpen(true)}>
186
+ {t('skillProjects.deleteAction')}
187
+ </Button>
188
+ <AlertDialogContent>
189
+ <AlertDialogHeader>
190
+ <AlertDialogTitle>
191
+ {t('skillProjects.deleteTitle', { name: project.name })}
192
+ </AlertDialogTitle>
193
+ <AlertDialogDescription>
194
+ {t('skillProjects.deleteHint')}
195
+ </AlertDialogDescription>
196
+ </AlertDialogHeader>
197
+ {error ? (
198
+ <Alert variant='destructive'>
199
+ <AlertDescription>
200
+ {t(
201
+ error === 'uncertain'
202
+ ? 'skillProjects.deleteUncertain'
203
+ : error === 'denied'
204
+ ? 'skillProjects.denied'
205
+ : 'skillProjects.deleteFailed',
206
+ )}
207
+ </AlertDescription>
208
+ </Alert>
209
+ ) : null}
210
+ <AlertDialogFooter>
211
+ <AlertDialogCancel disabled={submission.submitting}>
212
+ {t('skillProjects.cancel')}
213
+ </AlertDialogCancel>
214
+ <AlertDialogAction
215
+ variant='destructive'
216
+ disabled={submission.submitting || error === 'denied'}
217
+ onClick={(event) => {
218
+ event.preventDefault();
219
+ void confirm();
220
+ }}
221
+ >
222
+ {t(
223
+ submission.submitting
224
+ ? 'skillProjects.deleting'
225
+ : 'skillProjects.deleteAction',
226
+ )}
227
+ </AlertDialogAction>
228
+ </AlertDialogFooter>
229
+ </AlertDialogContent>
230
+ </AlertDialog>
231
+ );
232
+ }
@@ -8,13 +8,7 @@ import {
8
8
  import { useAuthentication } from '@nocobase/app-plugin-authentication/client';
9
9
  import { useTranslation } from '@nocobase/i18n/client';
10
10
  import { useEffect, useId, useRef, useState, type ReactElement } from 'react';
11
- import {
12
- Link,
13
- useNavigate,
14
- useOutletContext,
15
- useParams,
16
- useLocation,
17
- } from 'react-router';
11
+ import { Link, useNavigate, useParams, useLocation } from 'react-router';
18
12
  import { useForm } from 'react-hook-form';
19
13
  import { FeedbackForm } from '#components/feedback-form';
20
14
  import { RouteDialog } from '#components/route-dialog';
@@ -34,13 +28,14 @@ import { Button } from '#components/ui/button';
34
28
  import { Skeleton } from '#components/ui/skeleton';
35
29
  import { Input } from '#components/ui/input';
36
30
  import { Label } from '#components/ui/label';
31
+ import { announceDataChange } from '#hooks/use-data-changes';
37
32
  import { useListData } from '#hooks/use-list-data';
38
33
  import type { SkillProject } from './index.js';
34
+ import { projectScope, projectsScope } from './scopes.js';
39
35
 
40
36
  export default function SkillProjectEditPage(): ReactElement {
41
37
  const { projectId } = useParams();
42
38
  const { t } = useTranslation();
43
- const { reload } = useOutletContext<{ reload: () => void }>();
44
39
  const request = useListData<{ data: SkillProject }>(
45
40
  `skillProjects/${encodeURIComponent(projectId ?? '')}`,
46
41
  { active: Boolean(projectId) },
@@ -48,8 +43,10 @@ export default function SkillProjectEditPage(): ReactElement {
48
43
  const status =
49
44
  request.error instanceof ApiClientError ? request.error.status : undefined;
50
45
  useEffect(() => {
51
- if (status === 404) reload();
52
- }, [status, reload]);
46
+ // Views still showing the missing record read again.
47
+ if (status === 404 && projectId)
48
+ announceDataChange({ scopes: [projectScope(projectId)] });
49
+ }, [status, projectId]);
53
50
  if (!projectId) return <ProjectEditor key='new' />;
54
51
  if (request.error || !request.data)
55
52
  return (
@@ -130,10 +127,6 @@ function ProjectEditor({
130
127
  });
131
128
  const navigate = useNavigate();
132
129
  const location = useLocation();
133
- const { reload, onSaved } = useOutletContext<{
134
- reload: () => void;
135
- onSaved: (project: SkillProject) => void;
136
- }>();
137
130
  const toaster = useToaster();
138
131
  const [error, setError] = useState<unknown>();
139
132
  const [gone, setGone] = useState(false);
@@ -188,6 +181,7 @@ function ProjectEditor({
188
181
  const recovering = submission.pending;
189
182
  const snapshot = { name: form.getValues('name'), id: project?.id };
190
183
  let saved: { data: SkillProject } | undefined;
184
+ const changedScope = project ? projectScope(project.id) : projectsScope;
191
185
  try {
192
186
  saved = await submission.run(snapshot, async (key, signal, input) => {
193
187
  setError(undefined);
@@ -227,7 +221,15 @@ function ProjectEditor({
227
221
  savedRef.current = true;
228
222
  form.reset(form.getValues());
229
223
  }
230
- reload();
224
+ announceDataChange({ scopes: [changedScope] });
225
+ } else if (
226
+ recovering ||
227
+ !(failure instanceof ApiClientError) ||
228
+ failure.status >= 500
229
+ ) {
230
+ // The outcome is unknown: affected views read the server to show what
231
+ // actually happened, while this form keeps the original operation.
232
+ announceDataChange({ scopes: [changedScope] });
231
233
  }
232
234
  } finally {
233
235
  busyRef.current = false;
@@ -235,7 +237,8 @@ function ProjectEditor({
235
237
  if (saved) {
236
238
  busyRef.current = false;
237
239
  savedRef.current = true;
238
- onSaved(saved.data);
240
+ const scope = projectScope(saved.data.id);
241
+ announceDataChange({ scopes: [scope], results: { [scope]: saved } });
239
242
  toaster.show({
240
243
  type: 'success',
241
244
  title: t(project ? 'skillProjects.saved' : 'skillProjects.created', {
@@ -4,7 +4,12 @@ import { useEffect, useMemo, useRef, useState, type ReactElement } from 'react';
4
4
  import { Link, Outlet, useLocation } from 'react-router';
5
5
  import { FolderIcon } from 'lucide-react';
6
6
  import type { ColumnDef } from '@tanstack/react-table';
7
- import { DataTable } from '#components/data-table';
7
+ import { DataTable, DataTableColumnHeader } from '#components/data-table';
8
+ import { Card, CardDescription, CardHeader } from '#components/ui/card';
9
+ import { Input } from '#components/ui/input';
10
+ import { type DataChange } from '#hooks/use-data-changes';
11
+ import { useUrlSearch } from '#hooks/use-url-search';
12
+ import { projectsScope } from './scopes.js';
8
13
  import { PageContainer } from '#components/page-container';
9
14
  import { PageHeader } from '#components/page-header';
10
15
  import { RecordLink } from '#components/record-link';
@@ -37,21 +42,47 @@ export interface SkillProject {
37
42
  name: string;
38
43
  }
39
44
 
45
+ export interface SkillProjectList {
46
+ data: SkillProject[];
47
+ meta: { total: number };
48
+ }
49
+
40
50
  export default function SkillProjectsPage(): ReactElement {
41
51
  const { t } = useTranslation();
42
- const { active } = useListLocation();
52
+ const { active, params } = useListLocation();
43
53
  const location = useLocation();
44
- const request = useListData<{
45
- data: SkillProject[];
46
- meta: { total: number };
47
- }>('skillProjects', { active, keepPreviousData: true });
48
- const { data, reload, replaceData } = request;
54
+ const searchBox = useUrlSearch({ resetParams: ['page'] });
55
+ const q = params.get('q')?.trim() ?? '';
56
+ const sortingQuery = new URLSearchParams();
57
+ if (q) sortingQuery.set('q', q);
58
+ if (params.get('sort') === 'name') {
59
+ sortingQuery.set('sort', 'name');
60
+ sortingQuery.set('order', params.get('order') === 'desc' ? 'desc' : 'asc');
61
+ }
62
+ const requestPath = sortingQuery.size
63
+ ? `${projectsScope}?${sortingQuery}`
64
+ : projectsScope;
65
+ const defaultOrder = !sortingQuery.has('sort') && !q;
66
+ const request = useListData<SkillProjectList>(requestPath, {
67
+ active,
68
+ keepPreviousData: true,
69
+ scopes: [projectsScope],
70
+ // Show a confirmed write at once; the verification read follows.
71
+ merge: (current, change) => mergeProjects(current, change, defaultOrder),
72
+ });
73
+ const summary = useListData<{ data: { total: number } }>(
74
+ `${projectsScope}/summary`,
75
+ { active, keepPreviousData: true, scopes: [projectsScope] },
76
+ );
77
+ const { data } = request;
49
78
  const tableState = useTableUrlState({
50
79
  active,
51
80
  revision: request.revision,
52
- sortColumns: [],
81
+ sortColumns: ['name'],
53
82
  rowCount:
54
- !request.loading && !request.error ? data?.data.length : undefined,
83
+ !request.loading && !request.error && request.path === requestPath
84
+ ? data?.data.length
85
+ : undefined,
55
86
  });
56
87
  const returnTargetRef = useRef<HTMLDivElement>(null);
57
88
  const returningRef = useRef(false);
@@ -70,30 +101,16 @@ export default function SkillProjectsPage(): ReactElement {
70
101
  });
71
102
  return () => cancelAnimationFrame(frame);
72
103
  }, [active, request.loading, data]);
73
- const context = useMemo(
74
- () => ({
75
- reload: reload,
76
- onSaved: (project: SkillProject) => {
77
- if (!data) return;
78
- const existed = data.data.some((row) => row.id === project.id);
79
- const rows = [
80
- ...data.data.filter((row) => row.id !== project.id),
81
- project,
82
- ];
83
- rows.sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
84
- replaceData({
85
- data: rows.slice(0, 100),
86
- meta: { total: data.meta.total + (existed ? 0 : 1) },
87
- });
88
- },
89
- }),
90
- [reload, replaceData, data],
91
- );
92
104
  const columns = useMemo<ColumnDef<SkillProject>[]>(
93
105
  () => [
94
106
  {
95
107
  accessorKey: 'name',
96
- header: t('skillProjects.name'),
108
+ header: ({ column }) => (
109
+ <DataTableColumnHeader
110
+ column={column}
111
+ title={t('skillProjects.name')}
112
+ />
113
+ ),
97
114
  cell: ({ row }) => (
98
115
  <RecordLink
99
116
  to={`${row.original.id}/details`}
@@ -129,6 +146,8 @@ export default function SkillProjectsPage(): ReactElement {
129
146
  );
130
147
  const status =
131
148
  request.error instanceof ApiClientError ? request.error.status : undefined;
149
+ // Whether the shown rows answer a search, from the response rather than the URL.
150
+ const shownQuery = new URLSearchParams(request.path.split('?')[1]).get('q');
132
151
  const createAction = (
133
152
  <Button
134
153
  render={<Link to={{ pathname: 'new', search: location.search }} />}
@@ -149,12 +168,23 @@ export default function SkillProjectsPage(): ReactElement {
149
168
  title={t('skillProjects.title')}
150
169
  description={t('skillProjects.description')}
151
170
  actions={
152
- request.data?.data.length && !request.error
171
+ (request.data?.data.length || shownQuery) && !request.error
153
172
  ? createAction
154
173
  : undefined
155
174
  }
156
175
  />
157
176
  </div>
177
+ <ProjectsMetric
178
+ total={summary.error ? undefined : summary.data?.data.total}
179
+ failed={Boolean(summary.error)}
180
+ />
181
+ <Input
182
+ type='search'
183
+ className='w-full sm:max-w-xs'
184
+ aria-label={t('skillProjects.search')}
185
+ placeholder={t('skillProjects.search')}
186
+ {...searchBox.inputProps}
187
+ />
158
188
  <div
159
189
  className='flex h-8 items-center justify-end'
160
190
  data-testid='refresh-slot'
@@ -208,6 +238,17 @@ export default function SkillProjectsPage(): ReactElement {
208
238
  </TableBody>
209
239
  </Table>
210
240
  </div>
241
+ ) : request.data?.data.length === 0 && !request.error && shownQuery ? (
242
+ <Empty className='min-h-48 border'>
243
+ <EmptyHeader>
244
+ <EmptyTitle>{t('skillProjects.noResults')}</EmptyTitle>
245
+ </EmptyHeader>
246
+ <EmptyContent>
247
+ <Button variant='outline' onClick={() => searchBox.clear()}>
248
+ {t('skillProjects.clearSearch')}
249
+ </Button>
250
+ </EmptyContent>
251
+ </Empty>
211
252
  ) : request.data?.data.length === 0 && !request.error ? (
212
253
  <Empty className='min-h-48 border'>
213
254
  <EmptyHeader>
@@ -228,6 +269,9 @@ export default function SkillProjectsPage(): ReactElement {
228
269
  paginationState={tableState.paginationState}
229
270
  onPaginationChange={tableState.onPaginationChange}
230
271
  pageSizeOptions={tableState.pageSizeOptions}
272
+ manualSorting
273
+ sortingState={tableState.sortingState}
274
+ onSortingChange={tableState.onSortingChange}
231
275
  columns={columns}
232
276
  data={request.data.data}
233
277
  getRowId={(row) => row.id}
@@ -236,11 +280,77 @@ export default function SkillProjectsPage(): ReactElement {
236
280
  />
237
281
  </>
238
282
  ) : null}
239
- <Outlet context={context} />
283
+ <Outlet />
240
284
  </PageContainer>
241
285
  );
242
286
  }
243
287
 
288
+ /** Applies confirmed results to the shown rows, in the endpoint's order. */
289
+ function mergeProjects(
290
+ current: SkillProjectList,
291
+ change: DataChange,
292
+ defaultOrder: boolean,
293
+ ): SkillProjectList | undefined {
294
+ let rows = current.data;
295
+ let total = current.meta.total;
296
+ let changed = false;
297
+ for (const [scope, value] of Object.entries(change.results ?? {})) {
298
+ const [resource, id, ...rest] = scope.split('/');
299
+ if (resource !== projectsScope || !id || rest.length) continue;
300
+ const existed = rows.some((row) => row.id === id);
301
+ if (value === null) {
302
+ if (!existed) continue;
303
+ rows = rows.filter((row) => row.id !== id);
304
+ total -= 1;
305
+ } else {
306
+ const project = (value as { data: SkillProject }).data;
307
+ if (existed) rows = rows.map((row) => (row.id === id ? project : row));
308
+ else if (defaultOrder) {
309
+ // Searched or re-sorted rows wait for the read to place a new record.
310
+ rows = [...rows, project]
311
+ .sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0))
312
+ .slice(0, 100);
313
+ total += 1;
314
+ } else continue;
315
+ }
316
+ changed = true;
317
+ }
318
+ return changed ? { data: rows, meta: { total } } : undefined;
319
+ }
320
+
321
+ function ProjectsMetric({
322
+ total,
323
+ failed,
324
+ }: {
325
+ readonly total: number | undefined;
326
+ readonly failed: boolean;
327
+ }): ReactElement {
328
+ const { t } = useTranslation();
329
+ return (
330
+ <Card size='sm' className='w-full sm:max-w-56'>
331
+ <CardHeader>
332
+ <CardDescription>{t('skillProjects.totalMetric')}</CardDescription>
333
+ {/* The card's own title size is fixed for small cards; a metric needs a larger figure. */}
334
+ <p
335
+ className='font-heading text-2xl font-semibold tabular-nums'
336
+ data-testid='projects-total'
337
+ >
338
+ {failed ? (
339
+ t('skillProjects.metricUnavailable')
340
+ ) : total === undefined ? (
341
+ <Skeleton
342
+ className='h-8 w-12'
343
+ aria-label={t('skillProjects.loading')}
344
+ />
345
+ ) : (
346
+ total
347
+ )}
348
+ </p>
349
+ </CardHeader>
350
+ </Card>
351
+ );
352
+ }
353
+
244
354
  function RefreshIndicator(): ReactElement | null {
245
355
  const { t } = useTranslation();
246
356
  const [visible, setVisible] = useState(false);
@@ -1,4 +1,18 @@
1
1
  export const enUS = {
2
+ search: 'Search projects',
3
+ noResults: 'No projects match this search.',
4
+ clearSearch: 'Clear search',
5
+ totalMetric: 'Total projects',
6
+ metricUnavailable: 'Unavailable',
7
+ deleteAction: 'Delete',
8
+ deleting: 'Deleting…',
9
+ deleteTitle: 'Delete “{{name}}”?',
10
+ deleteHint: 'This project will be removed for everyone.',
11
+ deleted: 'Deleted “{{name}}”.',
12
+ alreadyDeleted: '“{{name}}” was already deleted.',
13
+ deleteFailed: 'Unable to delete this project. Try again.',
14
+ deleteUncertain:
15
+ 'The delete result is unknown. The page is checking the project again; retry to confirm with the same request.',
2
16
  emptyTitle: 'No projects',
3
17
  saved: 'Saved “{{name}}”.',
4
18
  created: 'Created “{{name}}”.',
@@ -44,6 +58,20 @@ export const enUS = {
44
58
  };
45
59
 
46
60
  export const zhCN = {
61
+ search: '搜索项目',
62
+ noResults: '没有符合搜索条件的项目。',
63
+ clearSearch: '清除搜索',
64
+ totalMetric: '项目总数',
65
+ metricUnavailable: '暂不可用',
66
+ deleteAction: '删除',
67
+ deleting: '正在删除…',
68
+ deleteTitle: '删除“{{name}}”?',
69
+ deleteHint: '删除后所有人都将看不到此项目。',
70
+ deleted: '已删除“{{name}}”。',
71
+ alreadyDeleted: '“{{name}}”已被删除。',
72
+ deleteFailed: '无法删除此项目,请重试。',
73
+ deleteUncertain:
74
+ '删除结果尚未确定,页面正在重新读取此项目;重试将使用同一请求确认结果。',
47
75
  emptyTitle: '暂无项目',
48
76
  saved: '已保存“{{name}}”。',
49
77
  created: '已创建“{{name}}”。',
@@ -0,0 +1,3 @@
1
+ /** Everything about projects; a write to one project names `skillProjects/<id>`. */
2
+ export const projectsScope = 'skillProjects';
3
+ export const projectScope = (id: string) => `${projectsScope}/${id}`;