@nocobase/client-v2 2.2.45 → 2.2.47
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/es/flow/models/actions/getHasManyDeleteFilterByTk.d.ts +12 -0
- package/es/flow/models/base/PageModel/closeGuard.d.ts +8 -1
- package/es/flow/models/blocks/form/EditFormModel.d.ts +2 -0
- package/es/flow/models/topbar/UserCenterTopbarActionModel.d.ts +2 -0
- package/es/index.mjs +86 -86
- package/lib/index.js +89 -89
- package/package.json +7 -7
- package/src/flow/admin-shell/admin-layout/__tests__/TopbarActionsBar.mobile.test.tsx +55 -1
- package/src/flow/models/actions/BulkDeleteActionModel.tsx +13 -2
- package/src/flow/models/actions/DeleteActionModel.tsx +16 -2
- package/src/flow/models/actions/__tests__/DeleteActionModel.test.ts +256 -0
- package/src/flow/models/actions/getHasManyDeleteFilterByTk.ts +40 -0
- package/src/flow/models/base/PageModel/closeGuard.ts +9 -8
- package/src/flow/models/blocks/form/EditFormModel.tsx +23 -1
- package/src/flow/models/blocks/form/__tests__/EditFormModel.pagination.test.tsx +77 -0
- package/src/flow/models/topbar/UserCenterTopbarActionModel.tsx +58 -28
|
@@ -11,7 +11,7 @@ import { UserOutlined } from '@ant-design/icons';
|
|
|
11
11
|
import { css, cx } from '@emotion/css';
|
|
12
12
|
import { FlowModel, FlowModelRenderer, observer } from '@nocobase/flow-engine';
|
|
13
13
|
import { Divider, Dropdown, Empty, Select, Spin, theme } from 'antd';
|
|
14
|
-
import React, { useCallback, useContext, useEffect, useState } from 'react';
|
|
14
|
+
import React, { useCallback, useContext, useEffect, useLayoutEffect, useState } from 'react';
|
|
15
15
|
import { ErrorBoundary } from 'react-error-boundary';
|
|
16
16
|
import { createAclSnippetAllow } from '../../../acl/createAclSnippetAllow';
|
|
17
17
|
import { MobileTopbarActionsContext } from '../../admin-shell/admin-layout/MobileTopbarActionsContext';
|
|
@@ -240,6 +240,9 @@ export class UserCenterItemModel extends FlowModel {
|
|
|
240
240
|
|
|
241
241
|
async prepare() {}
|
|
242
242
|
|
|
243
|
+
/** Recheck this item on each opening without delaying other menu items. */
|
|
244
|
+
checkAvailability?(): Promise<boolean>;
|
|
245
|
+
|
|
243
246
|
render() {
|
|
244
247
|
return <UserCenterTextItemView model={this as UserCenterTextItemModel} />;
|
|
245
248
|
}
|
|
@@ -373,6 +376,9 @@ const UserCenterSelectItemView = observer(
|
|
|
373
376
|
{ displayName: 'UserCenterSelectItemView' },
|
|
374
377
|
);
|
|
375
378
|
|
|
379
|
+
// Ant Design caches the hidden dropdown. Context lets availability checks observe every opening.
|
|
380
|
+
const UserCenterOpenContext = React.createContext(false);
|
|
381
|
+
|
|
376
382
|
const UserCenterDropdownPanel = (props: {
|
|
377
383
|
model: UserCenterTopbarActionModel;
|
|
378
384
|
open: boolean;
|
|
@@ -381,7 +387,9 @@ const UserCenterDropdownPanel = (props: {
|
|
|
381
387
|
const { model, open, closeDropdown } = props;
|
|
382
388
|
const { token } = theme.useToken();
|
|
383
389
|
const [loading, setLoading] = useState(false);
|
|
384
|
-
const [
|
|
390
|
+
const [preparedItems, setPreparedItems] = useState<UserCenterItemModel[]>([]);
|
|
391
|
+
const menuOpen = useContext(UserCenterOpenContext);
|
|
392
|
+
const [availability, setAvailability] = useState(new Map<UserCenterItemModel, boolean>());
|
|
385
393
|
|
|
386
394
|
useEffect(() => {
|
|
387
395
|
if (!open) {
|
|
@@ -390,37 +398,57 @@ const UserCenterDropdownPanel = (props: {
|
|
|
390
398
|
|
|
391
399
|
let cancelled = false;
|
|
392
400
|
setLoading(true);
|
|
393
|
-
|
|
401
|
+
setPreparedItems([]);
|
|
394
402
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
if (!cancelled)
|
|
399
|
-
|
|
400
|
-
}
|
|
401
|
-
})
|
|
402
|
-
.catch((error) => {
|
|
403
|
+
async function prepareItems() {
|
|
404
|
+
try {
|
|
405
|
+
const items = await model.getPreparedItems(closeDropdown);
|
|
406
|
+
if (!cancelled) setPreparedItems(items);
|
|
407
|
+
} catch (error) {
|
|
403
408
|
console.error('[NocoBase] User center prepare failed.', error);
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
});
|
|
409
|
+
} finally {
|
|
410
|
+
if (!cancelled) setLoading(false);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
prepareItems();
|
|
410
414
|
|
|
411
415
|
return () => {
|
|
412
416
|
cancelled = true;
|
|
413
417
|
};
|
|
414
418
|
}, [closeDropdown, model, open]);
|
|
415
419
|
|
|
420
|
+
useLayoutEffect(() => {
|
|
421
|
+
// Keep the overlay stable during its exit animation. Clear old availability before the next opening paints.
|
|
422
|
+
if (!menuOpen) return;
|
|
423
|
+
let cancelled = false;
|
|
424
|
+
setAvailability(new Map());
|
|
425
|
+
async function checkItem(item: UserCenterItemModel) {
|
|
426
|
+
if (!item.checkAvailability) return;
|
|
427
|
+
let available = false;
|
|
428
|
+
try {
|
|
429
|
+
available = await item.checkAvailability();
|
|
430
|
+
} catch (error) {
|
|
431
|
+
console.error(`[NocoBase] User center item '${item.getItemId()}' availability check failed.`, error);
|
|
432
|
+
}
|
|
433
|
+
if (!cancelled) setAvailability((previous) => new Map(previous).set(item, available));
|
|
434
|
+
}
|
|
435
|
+
preparedItems.forEach(checkItem);
|
|
436
|
+
return () => {
|
|
437
|
+
cancelled = true;
|
|
438
|
+
};
|
|
439
|
+
}, [menuOpen, preparedItems]);
|
|
440
|
+
|
|
441
|
+
const items = preparedItems.filter((item) => !item.checkAvailability || availability.get(item));
|
|
442
|
+
const waiting = loading || (!items.length && preparedItems.some((item) => !availability.has(item)));
|
|
443
|
+
|
|
416
444
|
return (
|
|
417
445
|
<div className={userCenterDropdownClassName} style={getUserCenterDropdownVars(token)}>
|
|
418
|
-
{
|
|
446
|
+
{waiting ? (
|
|
419
447
|
<div className="nb-user-center-loading">
|
|
420
448
|
<Spin size="small" />
|
|
421
449
|
</div>
|
|
422
450
|
) : null}
|
|
423
|
-
{!
|
|
451
|
+
{!waiting && !items.length ? (
|
|
424
452
|
<div className="nb-user-center-empty">
|
|
425
453
|
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description={model.context.t('No data')} />
|
|
426
454
|
</div>
|
|
@@ -460,15 +488,17 @@ const UserCenterTopbarActionView = observer(
|
|
|
460
488
|
}, [closeMobileTopbar]);
|
|
461
489
|
|
|
462
490
|
return model.renderWrapper(
|
|
463
|
-
<
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
491
|
+
<UserCenterOpenContext.Provider value={open}>
|
|
492
|
+
<Dropdown
|
|
493
|
+
trigger={['hover']}
|
|
494
|
+
placement="bottomRight"
|
|
495
|
+
open={open}
|
|
496
|
+
onOpenChange={setOpen}
|
|
497
|
+
dropdownRender={() => <UserCenterDropdownPanel model={model} open={open} closeDropdown={closeDropdown} />}
|
|
498
|
+
>
|
|
499
|
+
<span className={userCenterTriggerClassName}>{model.renderButton()}</span>
|
|
500
|
+
</Dropdown>
|
|
501
|
+
</UserCenterOpenContext.Provider>,
|
|
472
502
|
);
|
|
473
503
|
},
|
|
474
504
|
{ displayName: 'UserCenterTopbarActionView' },
|