@nocobase/client-v2 2.2.0-beta.13 → 2.2.0-beta.15
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/APIClient.d.ts +1 -3
- package/es/components/category-tabs/SortableCategoryTabs.d.ts +55 -0
- package/es/components/category-tabs/index.d.ts +9 -0
- package/es/components/form/ScanInput/useCodeScanner.d.ts +2 -1
- package/es/components/form/TypedVariableInput.d.ts +31 -5
- package/es/components/form/filter/CollectionFilter.d.ts +2 -0
- package/es/components/form/filter/CollectionFilterItem.d.ts +11 -1
- package/es/components/form/filter/CollectionFilterPanel.d.ts +2 -0
- package/es/components/form/filter/index.d.ts +2 -0
- package/es/components/form/filter/useFilterActionProps.d.ts +2 -0
- package/es/components/index.d.ts +1 -0
- package/es/flow/actions/index.d.ts +1 -1
- package/es/flow/actions/linkageRules.d.ts +2 -0
- package/es/flow/admin-shell/admin-layout/AdminLayoutMenuModels.d.ts +1 -0
- package/es/flow/components/FieldAssignExactDatePicker.d.ts +1 -0
- package/es/flow/components/FieldAssignValueInput.d.ts +9 -0
- package/es/flow/components/RunJSValueEditor.d.ts +1 -0
- package/es/flow/components/filter/FilterGroup.d.ts +1 -0
- package/es/flow/components/filter/VariableFilterItem.d.ts +6 -1
- package/es/flow/index.d.ts +1 -0
- package/es/flow/models/base/PageModel/PageModel.d.ts +12 -0
- package/es/flow/models/base/PageModel/PageModelTabBar.d.ts +22 -0
- package/es/flow/models/base/PageModel/PageTabModel.d.ts +12 -0
- package/es/flow-compat/fieldValidationConstants.d.ts +1 -1
- package/es/flow-compat/routeTypes.d.ts +1 -0
- package/es/index.d.ts +4 -0
- package/es/index.mjs +144 -109
- package/es/utils/getRouteRuntimeVersion.d.ts +23 -0
- package/es/utils/index.d.ts +1 -0
- package/lib/index.js +153 -118
- package/lib/locale/languageCodes.js +2 -1
- package/package.json +7 -7
- package/src/APIClient.ts +1 -10
- package/src/Application.tsx +4 -0
- package/src/BaseApplication.tsx +1 -1
- package/src/__tests__/app.test.tsx +18 -0
- package/src/__tests__/browserChecker.test.ts +61 -0
- package/src/__tests__/getRouteRuntimeVersion.test.ts +68 -0
- package/src/__tests__/nocobase-buildin-plugin-auth.test.tsx +28 -0
- package/src/collection-manager/field-validation.ts +1 -1
- package/src/components/README.md +7 -1
- package/src/components/README.zh-CN.md +6 -1
- package/src/components/category-tabs/SortableCategoryTabs.tsx +210 -0
- package/src/components/category-tabs/index.ts +10 -0
- package/src/components/form/JsonTextArea.tsx +4 -0
- package/src/components/form/ScanInput/CodeScanner.tsx +23 -6
- package/src/components/form/ScanInput/__tests__/useCodeScanner.test.tsx +35 -1
- package/src/components/form/ScanInput/useCodeScanner.ts +16 -3
- package/src/components/form/TypedVariableInput.tsx +452 -101
- package/src/components/form/__tests__/TypedVariableInput.test.tsx +364 -12
- package/src/components/form/filter/CollectionFilter.tsx +4 -0
- package/src/components/form/filter/CollectionFilterItem.tsx +32 -7
- package/src/components/form/filter/CollectionFilterPanel.tsx +4 -0
- package/src/components/form/filter/__tests__/CollectionFilterItem.test.tsx +38 -0
- package/src/components/form/filter/__tests__/useFilterActionProps.test.tsx +95 -0
- package/src/components/form/filter/index.ts +2 -0
- package/src/components/form/filter/useFilterActionProps.ts +37 -6
- package/src/components/index.ts +1 -0
- package/src/flow/actions/__tests__/linkageRules.tab.test.ts +171 -0
- package/src/flow/actions/index.ts +2 -0
- package/src/flow/actions/linkageRules.tsx +86 -11
- package/src/flow/admin-shell/admin-layout/AdminLayoutComponent.tsx +0 -1
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutComponent.test.tsx +253 -6
- package/src/flow/components/FieldAssignExactDatePicker.tsx +25 -11
- package/src/flow/components/FieldAssignValueInput.tsx +76 -9
- package/src/flow/components/RunJSValueEditor.tsx +9 -1
- package/src/flow/components/__tests__/FieldAssignValueInput.context.test.tsx +84 -2
- package/src/flow/components/filter/FilterGroup.tsx +33 -5
- package/src/flow/components/filter/VariableFilterItem.tsx +158 -10
- package/src/flow/components/filter/__tests__/FilterGroup.test.tsx +45 -0
- package/src/flow/components/filter/__tests__/VariableFilterItem.leftMetaTree.test.tsx +9 -0
- package/src/flow/components/filter/__tests__/VariableFilterItem.test.tsx +70 -1
- package/src/flow/index.ts +1 -0
- package/src/flow/models/base/PageModel/PageModel.tsx +387 -53
- package/src/flow/models/base/PageModel/PageModelTabBar.tsx +114 -0
- package/src/flow/models/base/PageModel/PageTabModel.tsx +184 -3
- package/src/flow/models/base/PageModel/__tests__/PageModel.test.ts +790 -10
- package/src/flow/models/base/PageModel/__tests__/PageModelTabBar.module-isolation.test.tsx +130 -0
- package/src/flow/models/base/PageModel/__tests__/PageModelTabBar.test.tsx +118 -0
- package/src/flow/models/base/PageModel/__tests__/PageTabModel.test.ts +572 -1
- package/src/flow/models/blocks/table/TableBlockModel.tsx +1 -1
- package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/PopupSubTableFieldModel.tsx +1 -1
- package/src/flow/models/fields/VariableFieldFormModel.tsx +3 -3
- package/src/flow/models/fields/__tests__/VariableFieldFormModel.test.tsx +51 -0
- package/src/flow-compat/fieldValidationConstants.ts +1 -1
- package/src/flow-compat/routeTypes.ts +1 -0
- package/src/index.ts +4 -0
- package/src/locale/languageCodes.ts +2 -1
- package/src/nocobase-buildin-plugin/index.tsx +12 -0
- package/src/utils/getRouteRuntimeVersion.ts +185 -0
- package/src/utils/index.tsx +1 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { FlowEngine, FlowEngineProvider, type Collection } from '@nocobase/flow-engine';
|
|
11
|
+
import { renderHook } from '@testing-library/react';
|
|
12
|
+
import React from 'react';
|
|
13
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
14
|
+
import { useFilterActionProps } from '../useFilterActionProps';
|
|
15
|
+
|
|
16
|
+
vi.mock('../../../flow/components/filter/useFilterOptions', () => ({
|
|
17
|
+
useFilterOptions: () => [],
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
vi.mock('../CollectionFilterItem', () => ({
|
|
21
|
+
createCollectionFilterItem: () => undefined,
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
function makeCollection(): Collection {
|
|
25
|
+
return {
|
|
26
|
+
getFields: () => [{ name: 'title' }, { name: 'type' }],
|
|
27
|
+
} as unknown as Collection;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function makeWrapper() {
|
|
31
|
+
const engine = new FlowEngine();
|
|
32
|
+
const Wrapper: React.FC = ({ children }) => <FlowEngineProvider engine={engine}>{children}</FlowEngineProvider>;
|
|
33
|
+
return Wrapper;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
describe('useFilterActionProps', () => {
|
|
37
|
+
it('seeds the editable group from defaultValue when initialValue is missing', () => {
|
|
38
|
+
const { result } = renderHook(
|
|
39
|
+
() =>
|
|
40
|
+
useFilterActionProps({
|
|
41
|
+
collection: makeCollection(),
|
|
42
|
+
defaultValue: { $and: [{ title: { $includes: '' } }, { type: { $eq: undefined } }] },
|
|
43
|
+
onApply: () => undefined,
|
|
44
|
+
}),
|
|
45
|
+
{ wrapper: makeWrapper() },
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
expect(result.current.value).toMatchObject({
|
|
49
|
+
logic: '$and',
|
|
50
|
+
items: [
|
|
51
|
+
{ path: 'title', operator: '$includes', value: '' },
|
|
52
|
+
{ path: 'type', operator: '$eq', value: undefined },
|
|
53
|
+
],
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('reset restores defaultValue and emits its compiled filter', () => {
|
|
58
|
+
const onApply = vi.fn();
|
|
59
|
+
const { result } = renderHook(
|
|
60
|
+
() =>
|
|
61
|
+
useFilterActionProps({
|
|
62
|
+
collection: makeCollection(),
|
|
63
|
+
defaultValue: { $and: [{ title: { $includes: '' } }, { type: { $eq: undefined } }] },
|
|
64
|
+
initialValue: { $and: [{ title: { $includes: 'abc' } }] },
|
|
65
|
+
onApply,
|
|
66
|
+
}),
|
|
67
|
+
{ wrapper: makeWrapper() },
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
result.current.onReset();
|
|
71
|
+
|
|
72
|
+
expect(result.current.value).toMatchObject({
|
|
73
|
+
logic: '$and',
|
|
74
|
+
items: [
|
|
75
|
+
{ path: 'title', operator: '$includes', value: '' },
|
|
76
|
+
{ path: 'type', operator: '$eq', value: undefined },
|
|
77
|
+
],
|
|
78
|
+
});
|
|
79
|
+
expect(onApply).toHaveBeenCalledWith(undefined, 'reset');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('counts only effective compiled conditions, so empty default rows do not highlight the button', () => {
|
|
83
|
+
const { result } = renderHook(
|
|
84
|
+
() =>
|
|
85
|
+
useFilterActionProps({
|
|
86
|
+
collection: makeCollection(),
|
|
87
|
+
defaultValue: { $and: [{ title: { $includes: '' } }, { type: { $eq: undefined } }] },
|
|
88
|
+
onApply: () => undefined,
|
|
89
|
+
}),
|
|
90
|
+
{ wrapper: makeWrapper() },
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
expect(result.current.conditionCount).toBe(0);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -11,5 +11,7 @@
|
|
|
11
11
|
export { CollectionFilter } from './CollectionFilter';
|
|
12
12
|
export type { CollectionFilterProps } from './CollectionFilter';
|
|
13
13
|
export { CollectionFilterPanel } from './CollectionFilterPanel';
|
|
14
|
+
export { CollectionFilterItem } from './CollectionFilterItem';
|
|
15
|
+
export type { CollectionFilterItemValue } from './CollectionFilterItem';
|
|
14
16
|
export type { CollectionFilterPanelProps, CollectionFilterPanelRef } from './CollectionFilterPanel';
|
|
15
17
|
export type { CompiledFilter } from './useFilterActionProps';
|
|
@@ -43,6 +43,14 @@ const isCondition = (item: FilterGroupItem): item is CollectionFilterItemValue =
|
|
|
43
43
|
typeof (item as CollectionFilterItemValue).path === 'string' &&
|
|
44
44
|
Object.prototype.hasOwnProperty.call(item, 'operator');
|
|
45
45
|
|
|
46
|
+
const cloneFilterGroupItem = (item: FilterGroupItem): FilterGroupItem =>
|
|
47
|
+
isGroup(item) ? { logic: item.logic, items: item.items.map((child) => cloneFilterGroupItem(child)) } : { ...item };
|
|
48
|
+
|
|
49
|
+
const cloneFilterGroup = (group: FilterGroupValue): FilterGroupValue => ({
|
|
50
|
+
logic: group.logic,
|
|
51
|
+
items: group.items.map((item) => cloneFilterGroupItem(item)),
|
|
52
|
+
});
|
|
53
|
+
|
|
46
54
|
/**
|
|
47
55
|
* `true` when the rhs of a condition is "no real value yet" — covers `undefined` / `null` / empty string / empty array / empty plain object. Mirrors v1's `removeNullCondition` `isEmpty` predicate so half-filled rows ("Locked time → is → (no date picked yet)") get dropped on Submit instead of being sent to the server as `{lockedTs:{}}` and triggering a 500.
|
|
48
56
|
*/
|
|
@@ -164,6 +172,8 @@ export interface UseFilterActionPropsArgs extends UseFilterOptionsArgs {
|
|
|
164
172
|
collection: Collection | undefined;
|
|
165
173
|
/** Previously compiled filter param used to seed the editable filter group. */
|
|
166
174
|
initialValue?: CompiledFilter;
|
|
175
|
+
/** Default compiled filter used both for initial empty state and Reset. */
|
|
176
|
+
defaultValue?: CompiledFilter;
|
|
167
177
|
/**
|
|
168
178
|
* Called when the user submits or resets the filter popover. Receives the compiled filter param (`undefined` when cleared) and which footer button triggered the call. Typical implementation: `(filter, action) => { listRequest.run(filter); if (action === 'submit') closePopover(); }`.
|
|
169
179
|
*/
|
|
@@ -216,12 +226,23 @@ export interface UseFilterActionPropsResult {
|
|
|
216
226
|
* ```
|
|
217
227
|
*/
|
|
218
228
|
export function useFilterActionProps(args: UseFilterActionPropsArgs): UseFilterActionPropsResult {
|
|
219
|
-
const {
|
|
229
|
+
const {
|
|
230
|
+
collection,
|
|
231
|
+
initialValue,
|
|
232
|
+
defaultValue,
|
|
233
|
+
onApply,
|
|
234
|
+
filterableFieldNames,
|
|
235
|
+
nonfilterableFieldNames,
|
|
236
|
+
noIgnore,
|
|
237
|
+
t,
|
|
238
|
+
} = args;
|
|
239
|
+
const seedValue = initialValue ?? defaultValue;
|
|
240
|
+
const defaultGroup = decompileFilterGroup(defaultValue) || createEmptyGroup();
|
|
220
241
|
|
|
221
242
|
// Held in a ref so the group object identity is stable for the lifetime of the host component — `<FilterContent>` mutates this object directly (push/splice on `items`, swap `logic`), and a fresh observable on every render would reset that internal state.
|
|
222
243
|
const valueRef = useRef<FilterGroupValue>();
|
|
223
244
|
if (!valueRef.current) {
|
|
224
|
-
valueRef.current = observable(decompileFilterGroup(
|
|
245
|
+
valueRef.current = observable(decompileFilterGroup(seedValue) || createEmptyGroup()) as FilterGroupValue;
|
|
225
246
|
}
|
|
226
247
|
const value = valueRef.current;
|
|
227
248
|
|
|
@@ -240,9 +261,10 @@ export function useFilterActionProps(args: UseFilterActionPropsArgs): UseFilterA
|
|
|
240
261
|
});
|
|
241
262
|
|
|
242
263
|
const onReset = useMemoizedFn(() => {
|
|
243
|
-
|
|
244
|
-
value.
|
|
245
|
-
|
|
264
|
+
const next = cloneFilterGroup(defaultGroup);
|
|
265
|
+
value.logic = next.logic;
|
|
266
|
+
value.items = next.items;
|
|
267
|
+
onApply(compileFilterGroup(value), 'reset');
|
|
246
268
|
});
|
|
247
269
|
|
|
248
270
|
const translate = useMemoizedFn((key: string) => (t ? t(key) : key));
|
|
@@ -261,7 +283,16 @@ export function useFilterActionProps(args: UseFilterActionPropsArgs): UseFilterA
|
|
|
261
283
|
);
|
|
262
284
|
|
|
263
285
|
// Re-read on each render so `observer`-wrapped hosts re-render when the reactive `items` array length changes. No useMemo needed — the `value` object's identity is stable (held in a ref), but its observable `items.length` is what we actually care about, and the eslint exhaustive-deps rule rightly complains about depending on a mutable property of a stable ref.
|
|
264
|
-
const conditionCount =
|
|
286
|
+
const conditionCount = (() => {
|
|
287
|
+
const compiled = compileFilterGroup(value);
|
|
288
|
+
if (compiled?.$and && Array.isArray(compiled.$and)) {
|
|
289
|
+
return compiled.$and.length;
|
|
290
|
+
}
|
|
291
|
+
if (compiled?.$or && Array.isArray(compiled.$or)) {
|
|
292
|
+
return compiled.$or.length;
|
|
293
|
+
}
|
|
294
|
+
return 0;
|
|
295
|
+
})();
|
|
265
296
|
|
|
266
297
|
return { value, options, FilterItem, ctx, onSubmit, onReset, conditionCount };
|
|
267
298
|
}
|
package/src/components/index.ts
CHANGED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { ActionScene } from '@nocobase/flow-engine';
|
|
11
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
12
|
+
|
|
13
|
+
import * as registeredActions from '../index';
|
|
14
|
+
import * as linkageActions from '../linkageRules';
|
|
15
|
+
|
|
16
|
+
const tabLinkageRules = (linkageActions as Record<string, unknown>).tabLinkageRules as
|
|
17
|
+
| typeof linkageActions.menuLinkageRules
|
|
18
|
+
| undefined;
|
|
19
|
+
const linkageSetTabProps = (linkageActions as Record<string, unknown>).linkageSetTabProps as
|
|
20
|
+
| typeof linkageActions.linkageSetMenuItemProps
|
|
21
|
+
| undefined;
|
|
22
|
+
|
|
23
|
+
function createRuntime() {
|
|
24
|
+
let matched = true;
|
|
25
|
+
const setProps = vi.fn(function (this: { props: Record<string, unknown> }, props: Record<string, unknown>) {
|
|
26
|
+
this.props = {
|
|
27
|
+
...this.props,
|
|
28
|
+
...props,
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
const setHidden = vi.fn(function (this: { hidden: boolean }, value: boolean) {
|
|
32
|
+
this.hidden = value;
|
|
33
|
+
});
|
|
34
|
+
const model = {
|
|
35
|
+
uid: 'tab-1',
|
|
36
|
+
props: {} as Record<string, unknown>,
|
|
37
|
+
hidden: false,
|
|
38
|
+
__allModels: [],
|
|
39
|
+
setProps,
|
|
40
|
+
setHidden,
|
|
41
|
+
};
|
|
42
|
+
const ctx = {
|
|
43
|
+
app: { jsonLogic: { apply: () => matched } },
|
|
44
|
+
model,
|
|
45
|
+
t: (text: string) => text,
|
|
46
|
+
getAction: (name: string) => (name === 'linkageSetTabProps' ? linkageSetTabProps : undefined),
|
|
47
|
+
resolveJsonTemplate: vi.fn(async (value: unknown) => value),
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
ctx,
|
|
52
|
+
model,
|
|
53
|
+
setMatched(value: boolean) {
|
|
54
|
+
matched = value;
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const hideRule = {
|
|
60
|
+
value: [
|
|
61
|
+
{
|
|
62
|
+
key: 'rule-1',
|
|
63
|
+
title: 'Hide tab',
|
|
64
|
+
enable: true,
|
|
65
|
+
condition: {
|
|
66
|
+
logic: '$and',
|
|
67
|
+
items: [{ path: 'status', operator: '$eq', value: 'visible' }],
|
|
68
|
+
},
|
|
69
|
+
actions: [
|
|
70
|
+
{
|
|
71
|
+
key: 'action-1',
|
|
72
|
+
name: 'linkageSetTabProps',
|
|
73
|
+
params: { value: 'hidden' },
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
describe('tab linkage rules', () => {
|
|
81
|
+
it('should append the tab linkage scene without changing existing scene values', () => {
|
|
82
|
+
const scenes = ActionScene as unknown as Record<string, number>;
|
|
83
|
+
|
|
84
|
+
expect(scenes.MENU_LINKAGE_RULES).toBe(7);
|
|
85
|
+
expect(scenes.TAB_LINKAGE_RULES).toBe(8);
|
|
86
|
+
expect(scenes.TAB_LINKAGE_RULES).toBe(Math.max(...Object.values(scenes).filter(Number.isInteger)));
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('should register tab linkage actions from the actions entry', () => {
|
|
90
|
+
expect((registeredActions as Record<string, unknown>).tabLinkageRules).toBe(tabLinkageRules);
|
|
91
|
+
expect((registeredActions as Record<string, unknown>).linkageSetTabProps).toBe(linkageSetTabProps);
|
|
92
|
+
expect(tabLinkageRules).toBeDefined();
|
|
93
|
+
expect(linkageSetTabProps).toBeDefined();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('should expose tab state and runjs actions in ui schema', () => {
|
|
97
|
+
expect(tabLinkageRules).toBeDefined();
|
|
98
|
+
expect(linkageSetTabProps).toBeDefined();
|
|
99
|
+
|
|
100
|
+
const schema = tabLinkageRules?.uiSchema?.({
|
|
101
|
+
getActions: () =>
|
|
102
|
+
new Map([
|
|
103
|
+
['linkageSetTabProps', linkageSetTabProps],
|
|
104
|
+
['linkageRunjs', linkageActions.linkageRunjs],
|
|
105
|
+
['linkageSetMenuItemProps', linkageActions.linkageSetMenuItemProps],
|
|
106
|
+
]),
|
|
107
|
+
} as never) as Record<string, Record<string, Record<string, unknown>>> | undefined;
|
|
108
|
+
|
|
109
|
+
expect(schema?.value?.['x-component-props']?.supportedActions).toEqual(['linkageSetTabProps', 'linkageRunjs']);
|
|
110
|
+
expect(linkageSetTabProps?.scene).toBe((ActionScene as unknown as Record<string, number>).TAB_LINKAGE_RULES);
|
|
111
|
+
expect(linkageActions.linkageRunjs.scene).toContain(
|
|
112
|
+
(ActionScene as unknown as Record<string, number>).TAB_LINKAGE_RULES,
|
|
113
|
+
);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('should hide the tab when the condition matches and restore it when the condition misses', async () => {
|
|
117
|
+
expect(tabLinkageRules).toBeDefined();
|
|
118
|
+
const runtime = createRuntime();
|
|
119
|
+
|
|
120
|
+
await tabLinkageRules?.handler(runtime.ctx as never, hideRule);
|
|
121
|
+
expect(runtime.model.hidden).toBe(true);
|
|
122
|
+
|
|
123
|
+
runtime.setMatched(false);
|
|
124
|
+
await tabLinkageRules?.handler(runtime.ctx as never, hideRule);
|
|
125
|
+
expect(runtime.model.hidden).toBe(false);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('should restore the tab when linkage rules are cleared', async () => {
|
|
129
|
+
expect(tabLinkageRules).toBeDefined();
|
|
130
|
+
const runtime = createRuntime();
|
|
131
|
+
|
|
132
|
+
await tabLinkageRules?.handler(runtime.ctx as never, hideRule);
|
|
133
|
+
expect(runtime.model.hidden).toBe(true);
|
|
134
|
+
|
|
135
|
+
await tabLinkageRules?.handler(runtime.ctx as never, { value: [] });
|
|
136
|
+
expect(runtime.model.hidden).toBe(false);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('should not restore stale tab props while applying or clearing visibility rules', async () => {
|
|
140
|
+
expect(tabLinkageRules).toBeDefined();
|
|
141
|
+
const runtime = createRuntime();
|
|
142
|
+
runtime.model.props = {
|
|
143
|
+
title: 'Original title',
|
|
144
|
+
icon: 'original-icon',
|
|
145
|
+
route: { options: { badge: 'original' } },
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
await tabLinkageRules?.handler(runtime.ctx as never, hideRule);
|
|
149
|
+
expect(runtime.model.hidden).toBe(true);
|
|
150
|
+
|
|
151
|
+
const updatedProps = {
|
|
152
|
+
title: 'Updated title',
|
|
153
|
+
icon: 'updated-icon',
|
|
154
|
+
route: { options: { badge: 'updated' } },
|
|
155
|
+
};
|
|
156
|
+
runtime.model.props = updatedProps;
|
|
157
|
+
|
|
158
|
+
await tabLinkageRules?.handler(runtime.ctx as never, hideRule);
|
|
159
|
+
expect(runtime.model.props).toMatchObject(updatedProps);
|
|
160
|
+
expect(runtime.model.hidden).toBe(true);
|
|
161
|
+
|
|
162
|
+
runtime.setMatched(false);
|
|
163
|
+
await tabLinkageRules?.handler(runtime.ctx as never, hideRule);
|
|
164
|
+
expect(runtime.model.props).toMatchObject(updatedProps);
|
|
165
|
+
expect(runtime.model.hidden).toBe(false);
|
|
166
|
+
|
|
167
|
+
await tabLinkageRules?.handler(runtime.ctx as never, { value: [] });
|
|
168
|
+
expect(runtime.model.props).toMatchObject(updatedProps);
|
|
169
|
+
expect(runtime.model.hidden).toBe(false);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
@@ -43,10 +43,12 @@ export {
|
|
|
43
43
|
linkageSetDetailsFieldProps,
|
|
44
44
|
actionLinkageRules,
|
|
45
45
|
menuLinkageRules,
|
|
46
|
+
tabLinkageRules,
|
|
46
47
|
blockLinkageRules,
|
|
47
48
|
linkageSetBlockProps,
|
|
48
49
|
linkageSetActionProps,
|
|
49
50
|
linkageSetMenuItemProps,
|
|
51
|
+
linkageSetTabProps,
|
|
50
52
|
linkageSetFieldProps,
|
|
51
53
|
subFormLinkageSetFieldProps,
|
|
52
54
|
linkageAssignField,
|
|
@@ -731,6 +731,41 @@ export const linkageSetMenuItemProps = defineAction({
|
|
|
731
731
|
},
|
|
732
732
|
});
|
|
733
733
|
|
|
734
|
+
export const linkageSetTabProps = defineAction({
|
|
735
|
+
name: 'linkageSetTabProps',
|
|
736
|
+
title: tExpr('Set tab state'),
|
|
737
|
+
scene: ActionScene.TAB_LINKAGE_RULES,
|
|
738
|
+
sort: 100,
|
|
739
|
+
uiSchema: {
|
|
740
|
+
value: {
|
|
741
|
+
type: 'string',
|
|
742
|
+
'x-component': (props) => {
|
|
743
|
+
const { value, onChange } = props;
|
|
744
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
745
|
+
const ctx = useFlowContext();
|
|
746
|
+
const t = ctx.model.translate.bind(ctx.model);
|
|
747
|
+
|
|
748
|
+
return (
|
|
749
|
+
<Select
|
|
750
|
+
value={value}
|
|
751
|
+
onChange={onChange}
|
|
752
|
+
placeholder={t('Please select state')}
|
|
753
|
+
style={{ width: '100%' }}
|
|
754
|
+
options={[
|
|
755
|
+
{ label: t('Visible'), value: 'visible' },
|
|
756
|
+
{ label: t('Hidden'), value: 'hidden' },
|
|
757
|
+
]}
|
|
758
|
+
allowClear
|
|
759
|
+
/>
|
|
760
|
+
);
|
|
761
|
+
},
|
|
762
|
+
},
|
|
763
|
+
},
|
|
764
|
+
handler(ctx, { value, setProps }) {
|
|
765
|
+
setProps(ctx.model, { hiddenModel: value === 'hidden' });
|
|
766
|
+
},
|
|
767
|
+
});
|
|
768
|
+
|
|
734
769
|
export const linkageSetFieldProps = defineAction({
|
|
735
770
|
name: 'linkageSetFieldProps',
|
|
736
771
|
title: tExpr('Set field state'),
|
|
@@ -1339,6 +1374,7 @@ export const linkageRunjs = defineAction({
|
|
|
1339
1374
|
ActionScene.FIELD_LINKAGE_RULES,
|
|
1340
1375
|
ActionScene.ACTION_LINKAGE_RULES,
|
|
1341
1376
|
ActionScene.MENU_LINKAGE_RULES,
|
|
1377
|
+
ActionScene.TAB_LINKAGE_RULES,
|
|
1342
1378
|
ActionScene.DETAILS_FIELD_LINKAGE_RULES,
|
|
1343
1379
|
ActionScene.SUB_FORM_FIELD_LINKAGE_RULES,
|
|
1344
1380
|
],
|
|
@@ -2169,17 +2205,30 @@ const commonLinkageRulesHandler = async (ctx: FlowContext, params: any) => {
|
|
|
2169
2205
|
}
|
|
2170
2206
|
: props;
|
|
2171
2207
|
|
|
2172
|
-
//
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2208
|
+
// 只记录联动实际控制的属性,避免之后恢复状态时把标题、路由等无关的新配置回滚到旧快照。
|
|
2209
|
+
const originalProps = model.__originalProps || (model.__originalProps = {});
|
|
2210
|
+
const rememberOriginalProp = (key: string, value: unknown) => {
|
|
2211
|
+
if (!Object.prototype.hasOwnProperty.call(originalProps, key)) {
|
|
2212
|
+
originalProps[key] = value;
|
|
2213
|
+
}
|
|
2214
|
+
};
|
|
2215
|
+
Object.keys(normalizedProps || {}).forEach((key) => {
|
|
2216
|
+
if (key === 'hiddenModel') {
|
|
2217
|
+
rememberOriginalProp(
|
|
2218
|
+
key,
|
|
2219
|
+
Object.prototype.hasOwnProperty.call(model.props || {}, key) ? model.props?.[key] : model.hidden,
|
|
2220
|
+
);
|
|
2221
|
+
return;
|
|
2222
|
+
}
|
|
2223
|
+
|
|
2224
|
+
rememberOriginalProp(key, model.props?.[key]);
|
|
2225
|
+
if (key === 'hiddenText') {
|
|
2226
|
+
rememberOriginalProp('title', model.props?.title);
|
|
2227
|
+
}
|
|
2228
|
+
if (key === 'required') {
|
|
2229
|
+
rememberOriginalProp('rules', model.props?.rules);
|
|
2230
|
+
}
|
|
2231
|
+
});
|
|
2183
2232
|
|
|
2184
2233
|
// 临时存起来,遍历完所有规则后,再统一处理
|
|
2185
2234
|
patchPropsByModel.set(model, {
|
|
@@ -2463,6 +2512,32 @@ export const menuLinkageRules = defineAction({
|
|
|
2463
2512
|
},
|
|
2464
2513
|
});
|
|
2465
2514
|
|
|
2515
|
+
export const tabLinkageRules = defineAction({
|
|
2516
|
+
name: 'tabLinkageRules',
|
|
2517
|
+
title: tExpr('Tab linkage rules'),
|
|
2518
|
+
uiMode: 'embed',
|
|
2519
|
+
uiSchema(ctx) {
|
|
2520
|
+
return {
|
|
2521
|
+
value: {
|
|
2522
|
+
type: 'array',
|
|
2523
|
+
'x-component': LinkageRulesUI,
|
|
2524
|
+
'x-component-props': {
|
|
2525
|
+
supportedActions: getSupportedActions(ctx, ActionScene.TAB_LINKAGE_RULES),
|
|
2526
|
+
title: tExpr('Tab linkage rules'),
|
|
2527
|
+
},
|
|
2528
|
+
},
|
|
2529
|
+
};
|
|
2530
|
+
},
|
|
2531
|
+
defaultParams: {
|
|
2532
|
+
value: [],
|
|
2533
|
+
},
|
|
2534
|
+
useRawParams: true,
|
|
2535
|
+
handler: async (ctx, params) => {
|
|
2536
|
+
const resolved = await resolveLinkageRulesParamsPreservingRunJsScripts(ctx, params);
|
|
2537
|
+
return commonLinkageRulesHandler(ctx, resolved);
|
|
2538
|
+
},
|
|
2539
|
+
});
|
|
2540
|
+
|
|
2466
2541
|
export const fieldLinkageRules = defineAction({
|
|
2467
2542
|
name: 'fieldLinkageRules',
|
|
2468
2543
|
title: tExpr('Field linkage rules'),
|
|
@@ -712,7 +712,6 @@ export const AdminLayoutComponent = observer((props: any) => {
|
|
|
712
712
|
<MobileMenuControlContext.Provider value={{ closeMobileMenu }}>
|
|
713
713
|
<DndProvider collisionDetection={menuCollisionDetection} onDragEnd={handleMenuDragEnd}>
|
|
714
714
|
<ProLayout
|
|
715
|
-
key={`admin-layout-menu-${menuRouteRefreshVersion}`}
|
|
716
715
|
{...props}
|
|
717
716
|
contentStyle={contentStyle}
|
|
718
717
|
siderWidth={customToken.siderWidth || 200}
|