@nocobase/client-v2 2.2.0-alpha.3 → 2.2.0-alpha.5
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/BaseApplication.d.ts +2 -0
- package/es/RouteRepository.d.ts +8 -0
- package/es/RouterManager.d.ts +15 -0
- package/es/authRedirect.d.ts +1 -0
- package/es/components/form/TypedVariableInput.d.ts +9 -1
- package/es/components/form/filter/CollectionFilter.d.ts +2 -0
- package/es/components/form/filter/CollectionFilterPanel.d.ts +2 -0
- package/es/components/form/filter/useFilterActionProps.d.ts +2 -0
- package/es/entry-actions/EntryActionManager.d.ts +24 -0
- package/es/entry-actions/index.d.ts +9 -0
- package/es/flow/admin-shell/BaseLayoutModel.d.ts +6 -0
- package/es/flow/admin-shell/BaseLayoutRouteCoordinator.d.ts +7 -0
- package/es/flow/admin-shell/admin-layout/AppListRender.d.ts +2 -1
- package/es/flow/admin-shell/admin-layout/AppSwitcherActionPanelModel.d.ts +24 -0
- package/es/flow/admin-shell/admin-layout/index.d.ts +1 -0
- package/es/flow/admin-shell/admin-layout/useApplications.d.ts +7 -2
- package/es/flow/models/base/ActionModelCore.d.ts +2 -0
- package/es/flow/routeTransientInputArgs.d.ts +14 -0
- package/es/index.d.ts +6 -0
- package/es/index.mjs +229 -143
- package/es/utils/getRouteRuntimeVersion.d.ts +23 -0
- package/es/utils/index.d.ts +1 -0
- package/es/utils/markdownSanitize.d.ts +11 -0
- package/lib/index.js +219 -133
- package/package.json +7 -7
- package/src/BaseApplication.tsx +2 -0
- package/src/RouteRepository.ts +25 -0
- package/src/RouterManager.tsx +142 -1
- package/src/__tests__/RouteRepository.test.ts +23 -0
- package/src/__tests__/RouterManager.test.ts +125 -0
- package/src/__tests__/authRedirect.test.ts +17 -0
- package/src/__tests__/getRouteRuntimeVersion.test.ts +68 -0
- package/src/authRedirect.ts +38 -0
- package/src/components/form/JsonTextArea.tsx +4 -0
- package/src/components/form/TypedVariableInput.tsx +58 -34
- package/src/components/form/__tests__/TypedVariableInput.test.tsx +52 -0
- package/src/components/form/filter/CollectionFilter.tsx +4 -0
- package/src/components/form/filter/CollectionFilterPanel.tsx +4 -0
- package/src/components/form/filter/__tests__/useFilterActionProps.test.tsx +95 -0
- package/src/components/form/filter/useFilterActionProps.ts +37 -6
- package/src/entry-actions/EntryActionManager.ts +76 -0
- package/src/entry-actions/index.ts +10 -0
- package/src/flow/FlowPage.tsx +29 -2
- package/src/flow/__tests__/FlowPage.test.tsx +152 -25
- package/src/flow/__tests__/FlowRoute.test.tsx +547 -2
- package/src/flow/actions/__tests__/dataScopeFilter.test.ts +62 -0
- package/src/flow/actions/__tests__/openView.defineProps.route.test.tsx +80 -20
- package/src/flow/actions/dataScopeFilter.ts +10 -1
- package/src/flow/actions/dateTimeFormat.tsx +2 -2
- package/src/flow/actions/openView.tsx +21 -1
- package/src/flow/admin-shell/BaseLayoutModel.tsx +124 -0
- package/src/flow/admin-shell/BaseLayoutRouteCoordinator.ts +184 -42
- package/src/flow/admin-shell/__tests__/AdminLayoutRouteCoordinator.test.ts +1016 -119
- package/src/flow/admin-shell/admin-layout/AdminLayoutComponent.tsx +41 -4
- package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.test.tsx +177 -1
- package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.tsx +20 -0
- package/src/flow/admin-shell/admin-layout/AppListRender.tsx +13 -2
- package/src/flow/admin-shell/admin-layout/AppSwitcherActionPanelModel.tsx +289 -0
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutModel.test.tsx +436 -2
- package/src/flow/admin-shell/admin-layout/__tests__/TopbarActionsBar.test.tsx +48 -0
- package/src/flow/admin-shell/admin-layout/index.ts +1 -0
- package/src/flow/admin-shell/admin-layout/useApplications.tsx +81 -12
- package/src/flow/common/Markdown/Display.tsx +14 -3
- package/src/flow/common/Markdown/Edit.tsx +19 -7
- package/src/flow/components/FlowRoute.tsx +128 -16
- package/src/flow/internal/components/Markdown/util.ts +2 -1
- package/src/flow/models/base/ActionModel.tsx +10 -8
- package/src/flow/models/base/ActionModelCore.tsx +5 -0
- package/src/flow/models/blocks/table/TableColumnModel.tsx +6 -2
- package/src/flow/models/blocks/table/__tests__/TableColumnModel.test.tsx +51 -0
- package/src/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.tsx +45 -13
- package/src/flow/models/fields/TextareaFieldModel.tsx +42 -19
- package/src/flow/models/fields/__tests__/TextareaFieldModel.test.tsx +32 -1
- package/src/flow/models/topbar/TopbarActionModel.tsx +78 -3
- package/src/flow/routeTransientInputArgs.ts +27 -0
- package/src/flow/utils/__tests__/dateTimeFormat.test.ts +42 -0
- package/src/index.ts +6 -0
- package/src/nocobase-buildin-plugin/index.tsx +7 -1
- package/src/utils/getRouteRuntimeVersion.ts +185 -0
- package/src/utils/index.tsx +1 -0
- package/src/utils/markdownSanitize.ts +88 -0
|
@@ -7,44 +7,105 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { render } from '@testing-library/react';
|
|
10
|
+
import { render, waitFor } from '@testing-library/react';
|
|
11
11
|
import React from 'react';
|
|
12
12
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
13
13
|
import { FlowPage } from '../FlowPage';
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
type TestContextProperty = {
|
|
16
|
+
value?: unknown;
|
|
17
|
+
get?: () => unknown;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type TestModelContext = {
|
|
21
|
+
isMobileLayout: boolean;
|
|
22
|
+
themeToken: {
|
|
23
|
+
marginBlock: number;
|
|
24
|
+
};
|
|
25
|
+
addDelegate: ReturnType<typeof vi.fn>;
|
|
26
|
+
defineProperty: ReturnType<typeof vi.fn>;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
type TestPageModel = {
|
|
30
|
+
uid: string;
|
|
31
|
+
props: {
|
|
32
|
+
showFlowSettings: boolean;
|
|
33
|
+
};
|
|
34
|
+
context: TestModelContext;
|
|
35
|
+
removeParentDelegate: ReturnType<typeof vi.fn>;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
type RendererProps = {
|
|
39
|
+
model?: TestPageModel;
|
|
40
|
+
showFlowSettings?: boolean;
|
|
41
|
+
} & Record<string, unknown>;
|
|
42
|
+
|
|
43
|
+
const defineContextProperty = (context: TestModelContext, key: string, property: TestContextProperty) => {
|
|
44
|
+
Object.defineProperty(context, key, {
|
|
45
|
+
configurable: true,
|
|
46
|
+
enumerable: true,
|
|
47
|
+
get: property.get || (() => property.value),
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const createPageModel = (): TestPageModel => {
|
|
52
|
+
const context = {
|
|
53
|
+
isMobileLayout: false,
|
|
54
|
+
themeToken: {
|
|
55
|
+
marginBlock: 16,
|
|
56
|
+
},
|
|
57
|
+
addDelegate: vi.fn(),
|
|
58
|
+
defineProperty: vi.fn((key: string, property: TestContextProperty) => {
|
|
59
|
+
defineContextProperty(context, key, property);
|
|
60
|
+
}),
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
return {
|
|
18
64
|
uid: 'public-form-page',
|
|
19
65
|
props: {
|
|
20
66
|
showFlowSettings: false,
|
|
21
67
|
},
|
|
22
|
-
context
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
68
|
+
context,
|
|
69
|
+
removeParentDelegate: vi.fn(),
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const mocks = vi.hoisted(() => ({
|
|
74
|
+
rendererMobileStates: [] as boolean[],
|
|
75
|
+
rendererProps: undefined as RendererProps | undefined,
|
|
76
|
+
model: undefined as TestPageModel | undefined,
|
|
77
|
+
viewInputMobileLayout: true as boolean | undefined,
|
|
78
|
+
contextMobileLayout: undefined as boolean | undefined,
|
|
29
79
|
}));
|
|
30
80
|
|
|
31
81
|
vi.mock('@nocobase/flow-engine', async () => {
|
|
32
|
-
const actual = await vi.importActual<
|
|
82
|
+
const actual = await vi.importActual<typeof import('@nocobase/flow-engine')>('@nocobase/flow-engine');
|
|
33
83
|
const ReactModule = await import('react');
|
|
84
|
+
class TestPageModelClass {}
|
|
34
85
|
|
|
35
86
|
return {
|
|
36
87
|
...actual,
|
|
37
|
-
FlowModelRenderer: vi.fn((props:
|
|
88
|
+
FlowModelRenderer: vi.fn((props: RendererProps) => {
|
|
38
89
|
mocks.rendererProps = props;
|
|
90
|
+
if (typeof props.model?.context.isMobileLayout === 'boolean') {
|
|
91
|
+
mocks.rendererMobileStates.push(props.model.context.isMobileLayout);
|
|
92
|
+
}
|
|
39
93
|
return ReactModule.createElement('div', { 'data-testid': 'flow-model-renderer' });
|
|
40
94
|
}),
|
|
41
95
|
useFlowEngine: vi.fn(() => ({
|
|
42
|
-
getModelClassAsync: vi.fn(),
|
|
43
|
-
loadOrCreateModel: vi.fn(),
|
|
96
|
+
getModelClassAsync: vi.fn(async () => TestPageModelClass),
|
|
97
|
+
loadOrCreateModel: vi.fn(async () => mocks.model),
|
|
44
98
|
context: {},
|
|
99
|
+
translate: vi.fn((value: string) => value),
|
|
45
100
|
})),
|
|
46
101
|
useFlowModelById: vi.fn(() => mocks.model),
|
|
47
102
|
useFlowViewContext: vi.fn(() => ({
|
|
103
|
+
view: {
|
|
104
|
+
inputArgs: {
|
|
105
|
+
...(typeof mocks.viewInputMobileLayout === 'boolean' ? { isMobileLayout: mocks.viewInputMobileLayout } : {}),
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
...(typeof mocks.contextMobileLayout === 'boolean' ? { isMobileLayout: mocks.contextMobileLayout } : {}),
|
|
48
109
|
themeToken: {
|
|
49
110
|
marginBlock: 16,
|
|
50
111
|
},
|
|
@@ -53,27 +114,93 @@ vi.mock('@nocobase/flow-engine', async () => {
|
|
|
53
114
|
});
|
|
54
115
|
|
|
55
116
|
vi.mock('ahooks', async () => {
|
|
56
|
-
const actual = await vi.importActual<
|
|
117
|
+
const actual = await vi.importActual<typeof import('ahooks')>('ahooks');
|
|
118
|
+
const ReactModule = await import('react');
|
|
57
119
|
return {
|
|
58
120
|
...actual,
|
|
59
|
-
useRequest: vi.fn(() =>
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
121
|
+
useRequest: vi.fn((service: () => Promise<unknown>) => {
|
|
122
|
+
const serviceRef = ReactModule.useRef(service);
|
|
123
|
+
const [state, setState] = ReactModule.useState<{
|
|
124
|
+
loading: boolean;
|
|
125
|
+
data?: unknown;
|
|
126
|
+
error?: unknown;
|
|
127
|
+
}>({
|
|
128
|
+
loading: true,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
ReactModule.useEffect(() => {
|
|
132
|
+
let active = true;
|
|
133
|
+
serviceRef
|
|
134
|
+
.current()
|
|
135
|
+
.then((data) => {
|
|
136
|
+
if (active) {
|
|
137
|
+
setState({ loading: false, data, error: null });
|
|
138
|
+
}
|
|
139
|
+
})
|
|
140
|
+
.catch((error) => {
|
|
141
|
+
if (active) {
|
|
142
|
+
setState({ loading: false, data: undefined, error });
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
return () => {
|
|
147
|
+
active = false;
|
|
148
|
+
};
|
|
149
|
+
}, []);
|
|
150
|
+
|
|
151
|
+
return state;
|
|
152
|
+
}),
|
|
66
153
|
};
|
|
67
154
|
});
|
|
68
155
|
|
|
69
156
|
describe('FlowPage', () => {
|
|
70
157
|
afterEach(() => {
|
|
158
|
+
mocks.rendererMobileStates = [];
|
|
71
159
|
mocks.rendererProps = undefined;
|
|
160
|
+
mocks.model = undefined;
|
|
161
|
+
mocks.viewInputMobileLayout = true;
|
|
162
|
+
mocks.contextMobileLayout = undefined;
|
|
72
163
|
});
|
|
73
164
|
|
|
74
|
-
it('uses showFlowSettings from page model props', () => {
|
|
165
|
+
it('uses showFlowSettings from page model props', async () => {
|
|
166
|
+
mocks.model = createPageModel();
|
|
75
167
|
render(<FlowPage />);
|
|
76
168
|
|
|
77
|
-
|
|
169
|
+
await waitFor(() => {
|
|
170
|
+
expect((mocks.rendererProps as { showFlowSettings?: boolean } | undefined)?.showFlowSettings).toBe(false);
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('exposes mobile layout state from route-managed view inputArgs before first render', async () => {
|
|
175
|
+
mocks.model = createPageModel();
|
|
176
|
+
render(<FlowPage onModelLoaded={vi.fn()} />);
|
|
177
|
+
|
|
178
|
+
await waitFor(() => {
|
|
179
|
+
expect(mocks.rendererMobileStates.length).toBeGreaterThan(0);
|
|
180
|
+
});
|
|
181
|
+
expect(mocks.rendererMobileStates[0]).toBe(true);
|
|
78
182
|
});
|
|
183
|
+
|
|
184
|
+
it.each([
|
|
185
|
+
{ viewInputMobileLayout: true, contextMobileLayout: false, expected: false },
|
|
186
|
+
{ viewInputMobileLayout: false, contextMobileLayout: true, expected: true },
|
|
187
|
+
{ viewInputMobileLayout: undefined, contextMobileLayout: true, expected: true },
|
|
188
|
+
{ viewInputMobileLayout: undefined, contextMobileLayout: false, expected: false },
|
|
189
|
+
{ viewInputMobileLayout: true, contextMobileLayout: undefined, expected: true },
|
|
190
|
+
{ viewInputMobileLayout: false, contextMobileLayout: undefined, expected: false },
|
|
191
|
+
])(
|
|
192
|
+
'resolves mobile layout state from view input args and layout context %#',
|
|
193
|
+
async ({ viewInputMobileLayout, contextMobileLayout, expected }) => {
|
|
194
|
+
mocks.viewInputMobileLayout = viewInputMobileLayout;
|
|
195
|
+
mocks.contextMobileLayout = contextMobileLayout;
|
|
196
|
+
mocks.model = createPageModel();
|
|
197
|
+
|
|
198
|
+
render(<FlowPage onModelLoaded={vi.fn()} />);
|
|
199
|
+
|
|
200
|
+
await waitFor(() => {
|
|
201
|
+
expect(mocks.rendererMobileStates.length).toBeGreaterThan(0);
|
|
202
|
+
});
|
|
203
|
+
expect(mocks.rendererMobileStates[0]).toBe(expected);
|
|
204
|
+
},
|
|
205
|
+
);
|
|
79
206
|
});
|