@nocobase/app-template-default 1.0.0-beta.67 → 1.0.0-beta.69
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/.agents/rules/components.md +2 -2
- package/.agents/rules/shell.md +5 -1
- package/AGENTS.md +5 -3
- package/Dockerfile.dockerignore +0 -1
- package/README.MD +3 -1
- package/client/app.ts +15 -0
- package/client/components/data-table/column-header.tsx +91 -0
- package/client/components/data-table/data-table.tsx +216 -0
- package/client/components/data-table/index.ts +13 -0
- package/client/components/data-table/pagination.tsx +165 -0
- package/client/components/data-table/view-options.tsx +77 -0
- package/client/components/page-header.tsx +1 -1
- package/client/components/permission-editor.tsx +589 -0
- package/client/components/permission-filter.tsx +455 -0
- package/client/components/route-overlay.tsx +26 -13
- package/client/components/status-badge.tsx +7 -1
- package/client/components/ui/checkbox.tsx +25 -0
- package/client/components/ui/sidebar.tsx +1 -4
- package/client/components/ui/switch.tsx +30 -0
- package/client/components/ui/table.tsx +113 -0
- package/client/extensions/nocobase-inbox/inbox-item.tsx +44 -58
- package/client/extensions/nocobase-inbox/inbox-list.tsx +73 -75
- package/client/index.tsx +4 -0
- package/client/layouts/components/app-sidebar.tsx +6 -6
- package/client/layouts/components/layout-header.tsx +1 -1
- package/client/layouts/components/navigation-menu.tsx +223 -12
- package/client/layouts/components/sidebar-footer.tsx +1 -1
- package/client/layouts/components/user-menu.tsx +1 -1
- package/client/layouts/use-sidebar-preference.ts +62 -42
- package/client/lib/navigation-transform.ts +8 -0
- package/client/lib/scrollbar.ts +88 -0
- package/client/locales/system/en-US.ts +11 -0
- package/client/locales/system/settings-en-US.ts +141 -0
- package/client/locales/system/settings-zh-CN.ts +135 -0
- package/client/locales/system/zh-CN.ts +22 -12
- package/client/pages/auth/auth-page.css +52 -0
- package/client/pages/auth/login.tsx +1 -1
- package/client/pages/auth/reset-password.tsx +57 -14
- package/client/pages/auth/shared.tsx +26 -24
- package/client/pages/home/index.tsx +2 -2
- package/client/pages/settings/hooks.tsx +137 -0
- package/client/pages/settings/permission-filters.tsx +119 -0
- package/client/pages/settings/permissions-model.ts +260 -0
- package/client/pages/settings/role-form.tsx +426 -0
- package/client/pages/settings/roles.tsx +163 -0
- package/client/pages/settings/routes.ts +79 -0
- package/client/pages/settings/shared.tsx +119 -0
- package/client/pages/settings/user-detail.tsx +268 -0
- package/client/pages/settings/user-form.tsx +427 -0
- package/client/pages/settings/users.tsx +451 -0
- package/client/routing/app-router.tsx +4 -1
- package/client/routing/route-navigation.ts +10 -1
- package/client/routing/session-preparation.tsx +65 -0
- package/client/styles.css +257 -24
- package/client/theme/theme-settings.tsx +12 -7
- package/client/theme/themes/compact.css +9 -14
- package/client/theme/themes/default.css +7 -12
- package/package.json +26 -25
- package/server/app.ts +2 -0
- package/server/config/notification.ts +4 -7
- package/tests/components/app-layout-routes.test.tsx +14 -7
- package/tests/components/auth-i18n.test.tsx +57 -5
- package/tests/components/data-table.test.tsx +127 -0
- package/tests/components/layout-i18n.test.tsx +10 -3
- package/tests/components/navigation-menu.test.tsx +155 -16
- package/tests/components/permission-editor.test.tsx +477 -0
- package/tests/components/permission-filter-binding.test.tsx +150 -0
- package/tests/components/permission-filter.test.tsx +202 -0
- package/tests/components/settings.test.tsx +294 -0
- package/tests/components/sidebar-permissions.test.tsx +17 -19
- package/tests/components/sidebar-preference.test.tsx +209 -14
- package/tests/components/status-badge.test.tsx +22 -0
- package/tests/components/user-permissions.test.tsx +142 -0
- package/tests/fixtures/theme-tokens.tsx +9 -1
- package/tests/logic/asset-url-build.test.ts +0 -1
- package/tests/logic/client-routes.test.ts +40 -0
- package/tests/logic/client-shell.test.tsx +10 -2
- package/tests/logic/config-example.test.ts +30 -0
- package/tests/logic/dev-client-watch.test.ts +8 -1
- package/tests/logic/route-overlay.test.tsx +42 -0
- package/tests/logic/scrollbar.test.ts +88 -0
- package/tests/logic/session-preparation.test.tsx +223 -0
- package/tests/logic/settings-permissions.test.ts +168 -0
- package/tests/logic/theme-tokens.test.ts +1 -0
- package/vite.config.ts +0 -22
- package/vitest.config.ts +1 -0
- package/client/agent-annotations-host.ts +0 -25
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
import { DataTable, DataTableColumnHeader } from '#components/data-table';
|
|
2
|
+
import type { ColumnDef } from '@tanstack/react-table';
|
|
3
|
+
import { useSettingsData, useUserPermission } from './hooks.js';
|
|
4
|
+
import { useApiClient, useToaster } from '@nocobase/app-client';
|
|
5
|
+
import { useTranslation } from '@nocobase/i18n/client';
|
|
6
|
+
import {
|
|
7
|
+
UsersClient,
|
|
8
|
+
type ManagedUser,
|
|
9
|
+
} from '@nocobase/app-plugin-users/client/user-client';
|
|
10
|
+
import {
|
|
11
|
+
useCallback,
|
|
12
|
+
useMemo,
|
|
13
|
+
useState,
|
|
14
|
+
useEffect,
|
|
15
|
+
type ReactElement,
|
|
16
|
+
} from 'react';
|
|
17
|
+
import { Link, Outlet, useLocation, useSearchParams } from 'react-router';
|
|
18
|
+
import { MoreHorizontalIcon, PlusIcon, UsersIcon } from 'lucide-react';
|
|
19
|
+
import { PageContainer } from '#components/page-container';
|
|
20
|
+
import { PageHeader } from '#components/page-header';
|
|
21
|
+
import { Button } from '#components/ui/button';
|
|
22
|
+
import { Input } from '#components/ui/input';
|
|
23
|
+
import { Badge } from '#components/ui/badge';
|
|
24
|
+
import {
|
|
25
|
+
Select,
|
|
26
|
+
SelectTrigger,
|
|
27
|
+
SelectValue,
|
|
28
|
+
SelectContent,
|
|
29
|
+
SelectItem,
|
|
30
|
+
} from '#components/ui/select';
|
|
31
|
+
import {
|
|
32
|
+
DropdownMenu,
|
|
33
|
+
DropdownMenuTrigger,
|
|
34
|
+
DropdownMenuContent,
|
|
35
|
+
DropdownMenuItem,
|
|
36
|
+
DropdownMenuSeparator,
|
|
37
|
+
} from '#components/ui/dropdown-menu';
|
|
38
|
+
import {
|
|
39
|
+
Empty,
|
|
40
|
+
EmptyMedia,
|
|
41
|
+
EmptyTitle,
|
|
42
|
+
EmptyDescription,
|
|
43
|
+
EmptyContent,
|
|
44
|
+
} from '#components/ui/empty';
|
|
45
|
+
import { ConfirmAction, SettingsError, SettingsLoading } from './shared.js';
|
|
46
|
+
|
|
47
|
+
function UserActions({
|
|
48
|
+
user,
|
|
49
|
+
reload,
|
|
50
|
+
}: {
|
|
51
|
+
readonly user: ManagedUser;
|
|
52
|
+
readonly reload: (updated?: ManagedUser) => void;
|
|
53
|
+
}): ReactElement {
|
|
54
|
+
const { t } = useTranslation();
|
|
55
|
+
const api = useApiClient();
|
|
56
|
+
const toaster = useToaster();
|
|
57
|
+
const client = useMemo(() => new UsersClient(api), [api]);
|
|
58
|
+
const canUpdate = useUserPermission('update', user.id);
|
|
59
|
+
const canDisable = useUserPermission('disable', user.id);
|
|
60
|
+
const canEnable = useUserPermission('enable', user.id);
|
|
61
|
+
const canRevoke = useUserPermission('revoke-sessions', user.id);
|
|
62
|
+
const location = useLocation();
|
|
63
|
+
const [action, setAction] = useState<
|
|
64
|
+
'disable' | 'enable' | 'revokeSessions'
|
|
65
|
+
>();
|
|
66
|
+
const [busy, setBusy] = useState(false);
|
|
67
|
+
const [error, setError] = useState<unknown>();
|
|
68
|
+
const run = async () => {
|
|
69
|
+
if (!action) return;
|
|
70
|
+
setBusy(true);
|
|
71
|
+
setError(undefined);
|
|
72
|
+
try {
|
|
73
|
+
const updated = await client[action](user.id);
|
|
74
|
+
toaster.show({
|
|
75
|
+
type: 'success',
|
|
76
|
+
title: t('settings.actionSaved', { name: user.name }),
|
|
77
|
+
});
|
|
78
|
+
setAction(undefined);
|
|
79
|
+
reload(updated ?? undefined);
|
|
80
|
+
} catch (next) {
|
|
81
|
+
setError(next);
|
|
82
|
+
} finally {
|
|
83
|
+
setBusy(false);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
return (
|
|
87
|
+
<>
|
|
88
|
+
<DropdownMenu>
|
|
89
|
+
<DropdownMenuTrigger
|
|
90
|
+
render={
|
|
91
|
+
<Button
|
|
92
|
+
size='icon-sm'
|
|
93
|
+
variant='ghost'
|
|
94
|
+
aria-label={t('settings.actionsFor', { name: user.name })}
|
|
95
|
+
>
|
|
96
|
+
<MoreHorizontalIcon />
|
|
97
|
+
</Button>
|
|
98
|
+
}
|
|
99
|
+
/>
|
|
100
|
+
<DropdownMenuContent align='end' className='w-auto min-w-40'>
|
|
101
|
+
{canUpdate && (
|
|
102
|
+
<DropdownMenuItem
|
|
103
|
+
render={
|
|
104
|
+
<Link
|
|
105
|
+
to={{ pathname: `${user.id}/edit`, search: location.search }}
|
|
106
|
+
/>
|
|
107
|
+
}
|
|
108
|
+
>
|
|
109
|
+
{t('settings.edit')}
|
|
110
|
+
</DropdownMenuItem>
|
|
111
|
+
)}
|
|
112
|
+
{(canDisable || canEnable || canRevoke) && <DropdownMenuSeparator />}
|
|
113
|
+
{!user.disabledAt && canDisable && (
|
|
114
|
+
<DropdownMenuItem
|
|
115
|
+
variant='destructive'
|
|
116
|
+
onClick={() => setAction('disable')}
|
|
117
|
+
>
|
|
118
|
+
{t('settings.disable')}
|
|
119
|
+
</DropdownMenuItem>
|
|
120
|
+
)}
|
|
121
|
+
{user.disabledAt && canEnable && (
|
|
122
|
+
<DropdownMenuItem onClick={() => setAction('enable')}>
|
|
123
|
+
{t('settings.enable')}
|
|
124
|
+
</DropdownMenuItem>
|
|
125
|
+
)}
|
|
126
|
+
{canRevoke && (
|
|
127
|
+
<DropdownMenuItem
|
|
128
|
+
variant='destructive'
|
|
129
|
+
onClick={() => setAction('revokeSessions')}
|
|
130
|
+
>
|
|
131
|
+
{t('settings.revokeSessions')}
|
|
132
|
+
</DropdownMenuItem>
|
|
133
|
+
)}
|
|
134
|
+
</DropdownMenuContent>
|
|
135
|
+
</DropdownMenu>
|
|
136
|
+
<ConfirmAction
|
|
137
|
+
open={Boolean(action)}
|
|
138
|
+
title={t(
|
|
139
|
+
`settings.${action === 'disable' ? 'disableTitle' : action === 'enable' ? 'enableTitle' : 'revokeTitle'}`,
|
|
140
|
+
{ name: user.name },
|
|
141
|
+
)}
|
|
142
|
+
description={
|
|
143
|
+
<>
|
|
144
|
+
<p>
|
|
145
|
+
{t(
|
|
146
|
+
action === 'disable'
|
|
147
|
+
? 'settings.disableHint'
|
|
148
|
+
: action === 'enable'
|
|
149
|
+
? 'settings.enableHint'
|
|
150
|
+
: 'settings.revokeHint',
|
|
151
|
+
)}
|
|
152
|
+
</p>
|
|
153
|
+
<SettingsError error={error} />
|
|
154
|
+
</>
|
|
155
|
+
}
|
|
156
|
+
confirmLabel={t(`settings.${action ?? 'confirm'}`)}
|
|
157
|
+
busy={busy}
|
|
158
|
+
onCancel={() => setAction(undefined)}
|
|
159
|
+
onConfirm={() => void run()}
|
|
160
|
+
/>
|
|
161
|
+
</>
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export default function UsersPage(): ReactElement {
|
|
166
|
+
const { t } = useTranslation();
|
|
167
|
+
const [params, setParams] = useSearchParams();
|
|
168
|
+
const location = useLocation();
|
|
169
|
+
const [queryDraft, setQueryDraft] = useState<{
|
|
170
|
+
key: string;
|
|
171
|
+
value: string;
|
|
172
|
+
}>();
|
|
173
|
+
const query =
|
|
174
|
+
queryDraft?.key === location.key
|
|
175
|
+
? queryDraft.value
|
|
176
|
+
: (params.get('q') ?? '');
|
|
177
|
+
const setQuery = (value: string) =>
|
|
178
|
+
setQueryDraft({ key: location.key, value });
|
|
179
|
+
const [composing, setComposing] = useState(false);
|
|
180
|
+
const page = Math.max(1, Number(params.get('page')) || 1);
|
|
181
|
+
const status = params.get('status') ?? 'all';
|
|
182
|
+
const pageSize = [20, 50, 100].includes(Number(params.get('pageSize')))
|
|
183
|
+
? Number(params.get('pageSize'))
|
|
184
|
+
: 20;
|
|
185
|
+
const update = (key: string, value: string) => {
|
|
186
|
+
setParams(
|
|
187
|
+
(old) => {
|
|
188
|
+
const next = new URLSearchParams(old);
|
|
189
|
+
if (value && value !== 'all') next.set(key, value);
|
|
190
|
+
else next.delete(key);
|
|
191
|
+
next.delete('page');
|
|
192
|
+
return next;
|
|
193
|
+
},
|
|
194
|
+
{ replace: true },
|
|
195
|
+
);
|
|
196
|
+
};
|
|
197
|
+
useEffect(() => {
|
|
198
|
+
if (composing || query === (params.get('q') ?? '')) return;
|
|
199
|
+
const timer = setTimeout(() => {
|
|
200
|
+
setParams(
|
|
201
|
+
(old) => {
|
|
202
|
+
const next = new URLSearchParams(old);
|
|
203
|
+
if (query) next.set('q', query);
|
|
204
|
+
else next.delete('q');
|
|
205
|
+
next.delete('page');
|
|
206
|
+
return next;
|
|
207
|
+
},
|
|
208
|
+
{ replace: true },
|
|
209
|
+
);
|
|
210
|
+
}, 300);
|
|
211
|
+
return () => clearTimeout(timer);
|
|
212
|
+
}, [query, composing, params, setParams]);
|
|
213
|
+
const remote = new URLSearchParams({
|
|
214
|
+
page: String(page),
|
|
215
|
+
pageSize: String(pageSize),
|
|
216
|
+
...(params.get('q') ? { q: params.get('q')! } : {}),
|
|
217
|
+
...(status !== 'all' ? { status } : {}),
|
|
218
|
+
...(params.get('order')
|
|
219
|
+
? { sort: 'name', order: params.get('order')! }
|
|
220
|
+
: {}),
|
|
221
|
+
});
|
|
222
|
+
const request = useSettingsData<{
|
|
223
|
+
data: readonly ManagedUser[];
|
|
224
|
+
meta: { total: number };
|
|
225
|
+
}>(`users?${remote}`, true);
|
|
226
|
+
const { data: pageData, replaceData, reload: refreshUsers } = request;
|
|
227
|
+
const reload = useCallback(
|
|
228
|
+
(updated?: ManagedUser) => {
|
|
229
|
+
if (updated && pageData)
|
|
230
|
+
replaceData({
|
|
231
|
+
...pageData,
|
|
232
|
+
data: pageData.data.map((row) =>
|
|
233
|
+
row.id === updated.id ? updated : row,
|
|
234
|
+
),
|
|
235
|
+
});
|
|
236
|
+
refreshUsers();
|
|
237
|
+
},
|
|
238
|
+
[pageData, replaceData, refreshUsers],
|
|
239
|
+
);
|
|
240
|
+
const canCreate = useUserPermission('create');
|
|
241
|
+
const canAssign = useUserPermission('assign-role');
|
|
242
|
+
const rows = request.data?.data ?? [];
|
|
243
|
+
const columns = useMemo<ColumnDef<ManagedUser>[]>(
|
|
244
|
+
() => [
|
|
245
|
+
{
|
|
246
|
+
accessorKey: 'name',
|
|
247
|
+
header: ({ column }) => (
|
|
248
|
+
<DataTableColumnHeader column={column} title={t('settings.name')} />
|
|
249
|
+
),
|
|
250
|
+
enableHiding: false,
|
|
251
|
+
cell: ({ row }) => (
|
|
252
|
+
<Link
|
|
253
|
+
className='font-medium text-primary hover:underline'
|
|
254
|
+
to={{
|
|
255
|
+
pathname: row.original.id,
|
|
256
|
+
search: location.search,
|
|
257
|
+
}}
|
|
258
|
+
>
|
|
259
|
+
{row.original.name}
|
|
260
|
+
</Link>
|
|
261
|
+
),
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
accessorKey: 'email',
|
|
265
|
+
header: t('settings.email'),
|
|
266
|
+
enableSorting: false,
|
|
267
|
+
cell: ({ row }) => (
|
|
268
|
+
<span className='block max-w-64 truncate' title={row.original.email}>
|
|
269
|
+
{row.original.email}
|
|
270
|
+
</span>
|
|
271
|
+
),
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
id: 'status',
|
|
275
|
+
header: t('settings.status'),
|
|
276
|
+
enableSorting: false,
|
|
277
|
+
cell: ({ row }) => (
|
|
278
|
+
<Badge variant='secondary'>
|
|
279
|
+
{t(
|
|
280
|
+
row.original.disabledAt
|
|
281
|
+
? 'settings.disabled'
|
|
282
|
+
: 'settings.enabled',
|
|
283
|
+
)}
|
|
284
|
+
</Badge>
|
|
285
|
+
),
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
id: 'roles',
|
|
289
|
+
header: t('settings.assignedRoles'),
|
|
290
|
+
enableSorting: false,
|
|
291
|
+
cell: ({ row }) =>
|
|
292
|
+
Object.values(row.original.roleScopes).flat().join(', ') || '—',
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
id: 'actions',
|
|
296
|
+
header: () => <span className='sr-only'>{t('settings.actions')}</span>,
|
|
297
|
+
enableSorting: false,
|
|
298
|
+
cell: ({ row }) => <UserActions user={row.original} reload={reload} />,
|
|
299
|
+
},
|
|
300
|
+
],
|
|
301
|
+
[t, location.search, reload],
|
|
302
|
+
);
|
|
303
|
+
const create =
|
|
304
|
+
canCreate && canAssign ? (
|
|
305
|
+
<Button
|
|
306
|
+
nativeButton={false}
|
|
307
|
+
render={<Link to={{ pathname: 'create', search: location.search }} />}
|
|
308
|
+
>
|
|
309
|
+
<PlusIcon />
|
|
310
|
+
{t('settings.newUser')}
|
|
311
|
+
</Button>
|
|
312
|
+
) : null;
|
|
313
|
+
const filtered = Boolean(params.get('q')) || status !== 'all';
|
|
314
|
+
return (
|
|
315
|
+
<>
|
|
316
|
+
<PageContainer>
|
|
317
|
+
<PageHeader
|
|
318
|
+
title={t('settings.users')}
|
|
319
|
+
description={t('settings.usersDescription')}
|
|
320
|
+
actions={rows.length || filtered ? create : undefined}
|
|
321
|
+
/>
|
|
322
|
+
<div className='flex flex-wrap items-center gap-3'>
|
|
323
|
+
<Input
|
|
324
|
+
className='w-full sm:max-w-xs'
|
|
325
|
+
value={query}
|
|
326
|
+
aria-label={t('settings.userSearch')}
|
|
327
|
+
placeholder={t('settings.userSearch')}
|
|
328
|
+
onCompositionStart={() => setComposing(true)}
|
|
329
|
+
onCompositionEnd={() => setComposing(false)}
|
|
330
|
+
onChange={(event) => setQuery(event.target.value)}
|
|
331
|
+
/>
|
|
332
|
+
<Select
|
|
333
|
+
items={['all', 'enabled', 'disabled'].map((value) => ({
|
|
334
|
+
value,
|
|
335
|
+
label: t(`settings.${value}`),
|
|
336
|
+
}))}
|
|
337
|
+
value={status}
|
|
338
|
+
onValueChange={(value) => update('status', String(value))}
|
|
339
|
+
>
|
|
340
|
+
<SelectTrigger aria-label={t('settings.status')}>
|
|
341
|
+
<SelectValue />
|
|
342
|
+
</SelectTrigger>
|
|
343
|
+
<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'>
|
|
344
|
+
{['all', 'enabled', 'disabled'].map((item) => (
|
|
345
|
+
<SelectItem key={item} value={item}>
|
|
346
|
+
{t(`settings.${item}`)}
|
|
347
|
+
</SelectItem>
|
|
348
|
+
))}
|
|
349
|
+
</SelectContent>
|
|
350
|
+
</Select>
|
|
351
|
+
{filtered && (
|
|
352
|
+
<Button
|
|
353
|
+
variant='ghost'
|
|
354
|
+
onClick={() => {
|
|
355
|
+
setQuery('');
|
|
356
|
+
setParams({});
|
|
357
|
+
}}
|
|
358
|
+
>
|
|
359
|
+
{t('settings.clear')}
|
|
360
|
+
</Button>
|
|
361
|
+
)}
|
|
362
|
+
</div>
|
|
363
|
+
{request.data && request.loading && (
|
|
364
|
+
<span role='status' className='text-sm text-muted-foreground'>
|
|
365
|
+
{t('settings.loading')}
|
|
366
|
+
</span>
|
|
367
|
+
)}
|
|
368
|
+
<SettingsError error={request.error} retry={request.reload} />
|
|
369
|
+
{request.loading && !request.data ? (
|
|
370
|
+
<SettingsLoading />
|
|
371
|
+
) : (
|
|
372
|
+
!request.error &&
|
|
373
|
+
(rows.length ? (
|
|
374
|
+
<DataTable<ManagedUser>
|
|
375
|
+
columns={columns}
|
|
376
|
+
data={rows}
|
|
377
|
+
getRowId={(row) => row.id}
|
|
378
|
+
manualPagination
|
|
379
|
+
rowCount={request.data?.meta.total ?? 0}
|
|
380
|
+
paginationState={{ pageIndex: page - 1, pageSize }}
|
|
381
|
+
onPaginationChange={(updater) => {
|
|
382
|
+
const next =
|
|
383
|
+
typeof updater === 'function'
|
|
384
|
+
? updater({ pageIndex: page - 1, pageSize })
|
|
385
|
+
: updater;
|
|
386
|
+
setParams((old) => {
|
|
387
|
+
const result = new URLSearchParams(old);
|
|
388
|
+
result.set('page', String(next.pageIndex + 1));
|
|
389
|
+
result.set('pageSize', String(next.pageSize));
|
|
390
|
+
return result;
|
|
391
|
+
});
|
|
392
|
+
}}
|
|
393
|
+
manualSorting
|
|
394
|
+
sortingState={
|
|
395
|
+
params.get('order')
|
|
396
|
+
? [{ id: 'name', desc: params.get('order') === 'desc' }]
|
|
397
|
+
: []
|
|
398
|
+
}
|
|
399
|
+
onSortingChange={(updater) => {
|
|
400
|
+
const previous = params.get('order')
|
|
401
|
+
? [{ id: 'name', desc: params.get('order') === 'desc' }]
|
|
402
|
+
: [];
|
|
403
|
+
const next =
|
|
404
|
+
typeof updater === 'function' ? updater(previous) : updater;
|
|
405
|
+
update('order', next[0] ? (next[0].desc ? 'desc' : 'asc') : '');
|
|
406
|
+
}}
|
|
407
|
+
pageSizeOptions={[20, 50, 100]}
|
|
408
|
+
showSelectedCount={false}
|
|
409
|
+
loading={request.loading}
|
|
410
|
+
/>
|
|
411
|
+
) : (
|
|
412
|
+
<Empty className='min-h-48 border border-dashed'>
|
|
413
|
+
<EmptyMedia variant='icon'>
|
|
414
|
+
<UsersIcon />
|
|
415
|
+
</EmptyMedia>
|
|
416
|
+
<EmptyTitle>
|
|
417
|
+
{t(filtered ? 'settings.noResults' : 'settings.noUsers')}
|
|
418
|
+
</EmptyTitle>
|
|
419
|
+
<EmptyDescription>
|
|
420
|
+
{t(
|
|
421
|
+
filtered ? 'settings.clearHint' : 'settings.usersDescription',
|
|
422
|
+
)}
|
|
423
|
+
</EmptyDescription>
|
|
424
|
+
<EmptyContent>
|
|
425
|
+
{filtered ? (
|
|
426
|
+
<Button
|
|
427
|
+
variant='outline'
|
|
428
|
+
onClick={() => {
|
|
429
|
+
setQuery('');
|
|
430
|
+
setParams({});
|
|
431
|
+
}}
|
|
432
|
+
>
|
|
433
|
+
{t('settings.clear')}
|
|
434
|
+
</Button>
|
|
435
|
+
) : (
|
|
436
|
+
create
|
|
437
|
+
)}
|
|
438
|
+
</EmptyContent>
|
|
439
|
+
</Empty>
|
|
440
|
+
))
|
|
441
|
+
)}
|
|
442
|
+
{request.data && (
|
|
443
|
+
<p className='text-sm text-muted-foreground'>
|
|
444
|
+
{t('settings.total', { count: request.data.meta.total })}
|
|
445
|
+
</p>
|
|
446
|
+
)}
|
|
447
|
+
</PageContainer>
|
|
448
|
+
<Outlet context={{ reload }} />
|
|
449
|
+
</>
|
|
450
|
+
);
|
|
451
|
+
}
|
|
@@ -11,6 +11,7 @@ import { EMPTY_ARRAY } from '#lib/constants';
|
|
|
11
11
|
import { AppLayout } from '../layouts/app-layout.js';
|
|
12
12
|
import { renderRouteTree } from './route-tree.js';
|
|
13
13
|
import { StandalonePageLayout } from './standalone-page-layout.js';
|
|
14
|
+
import { SessionPreparation } from './session-preparation.js';
|
|
14
15
|
|
|
15
16
|
export interface AppRouterProps {
|
|
16
17
|
readonly clientRoutes: readonly AppClientRegisteredRoute[];
|
|
@@ -34,7 +35,9 @@ export function AppRouter({ clientRoutes }: AppRouterProps): ReactElement {
|
|
|
34
35
|
<Route
|
|
35
36
|
element={
|
|
36
37
|
<RequiredAuthentication>
|
|
37
|
-
<
|
|
38
|
+
<SessionPreparation>
|
|
39
|
+
<Outlet />
|
|
40
|
+
</SessionPreparation>
|
|
38
41
|
</RequiredAuthentication>
|
|
39
42
|
}
|
|
40
43
|
>
|
|
@@ -8,8 +8,10 @@ import { useEffect, useMemo, useState } from 'react';
|
|
|
8
8
|
import { matchPath, matchRoutes, type RouteObject } from 'react-router';
|
|
9
9
|
|
|
10
10
|
import { EMPTY_ARRAY } from '#lib/constants';
|
|
11
|
+
import { transformNavigation } from '#lib/navigation-transform';
|
|
11
12
|
|
|
12
13
|
export interface RouteNavigationItem {
|
|
14
|
+
readonly section?: boolean;
|
|
13
15
|
readonly route: AppClientRegisteredRoute;
|
|
14
16
|
readonly children: readonly RouteNavigationItem[];
|
|
15
17
|
}
|
|
@@ -17,10 +19,17 @@ export interface RouteNavigationItem {
|
|
|
17
19
|
export function buildRouteNavigation(
|
|
18
20
|
routes: readonly AppClientRegisteredRoute[],
|
|
19
21
|
denied: ReadonlySet<string>,
|
|
22
|
+
): RouteNavigationItem[] {
|
|
23
|
+
return transformNavigation(visibleRouteNavigation(routes, denied));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function visibleRouteNavigation(
|
|
27
|
+
routes: readonly AppClientRegisteredRoute[],
|
|
28
|
+
denied: ReadonlySet<string>,
|
|
20
29
|
): RouteNavigationItem[] {
|
|
21
30
|
return routes.flatMap((route) => {
|
|
22
31
|
if (denied.has(routeKey(route))) return [];
|
|
23
|
-
const children =
|
|
32
|
+
const children = visibleRouteNavigation(
|
|
24
33
|
route.children ?? EMPTY_ARRAY,
|
|
25
34
|
denied,
|
|
26
35
|
);
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { useAuthentication } from '@nocobase/app-plugin-authentication/client';
|
|
2
|
+
import { useTranslation } from '@nocobase/i18n/client';
|
|
3
|
+
import { useState, type PropsWithChildren, type ReactElement } from 'react';
|
|
4
|
+
|
|
5
|
+
import { Loading } from '#components/loading';
|
|
6
|
+
import { Button } from '#components/ui/button';
|
|
7
|
+
|
|
8
|
+
/** The first identity handshake must invalidate permissions before pages mount. */
|
|
9
|
+
export function SessionPreparation({
|
|
10
|
+
children,
|
|
11
|
+
}: PropsWithChildren): ReactElement {
|
|
12
|
+
const { preparation, retryPreparation, client, refresh } =
|
|
13
|
+
useAuthentication();
|
|
14
|
+
const { t } = useTranslation();
|
|
15
|
+
const [signingOut, setSigningOut] = useState(false);
|
|
16
|
+
const [signOutFailed, setSignOutFailed] = useState(false);
|
|
17
|
+
|
|
18
|
+
if (preparation === 'ready') return <>{children}</>;
|
|
19
|
+
if (preparation === 'preparing') {
|
|
20
|
+
return <Loading className='min-h-svh' label={t('auth.preparingSession')} />;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<section className='grid min-h-svh place-items-center px-6'>
|
|
25
|
+
<div className='w-full max-w-lg space-y-4 text-center'>
|
|
26
|
+
<h1 className='text-xl font-semibold'>{t('auth.connectionFailed')}</h1>
|
|
27
|
+
<p className='text-sm text-muted-foreground'>
|
|
28
|
+
{t('auth.connectionFailedDescription')}
|
|
29
|
+
</p>
|
|
30
|
+
{signOutFailed ? (
|
|
31
|
+
<p role='alert'>{t('account.signOutFailed')}</p>
|
|
32
|
+
) : null}
|
|
33
|
+
<div className='flex justify-center gap-3'>
|
|
34
|
+
<Button disabled={signingOut} onClick={retryPreparation}>
|
|
35
|
+
{t('auth.retry')}
|
|
36
|
+
</Button>
|
|
37
|
+
<Button
|
|
38
|
+
variant='outline'
|
|
39
|
+
disabled={signingOut}
|
|
40
|
+
onClick={() => {
|
|
41
|
+
void (async () => {
|
|
42
|
+
setSigningOut(true);
|
|
43
|
+
setSignOutFailed(false);
|
|
44
|
+
try {
|
|
45
|
+
const result = await client.signOut();
|
|
46
|
+
if (result.error) {
|
|
47
|
+
setSignOutFailed(true);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
await refresh();
|
|
51
|
+
} catch {
|
|
52
|
+
setSignOutFailed(true);
|
|
53
|
+
} finally {
|
|
54
|
+
setSigningOut(false);
|
|
55
|
+
}
|
|
56
|
+
})();
|
|
57
|
+
}}
|
|
58
|
+
>
|
|
59
|
+
{t(signingOut ? 'account.signingOut' : 'account.signOut')}
|
|
60
|
+
</Button>
|
|
61
|
+
</div>
|
|
62
|
+
</div>
|
|
63
|
+
</section>
|
|
64
|
+
);
|
|
65
|
+
}
|