@nocobase/flow-engine 2.2.0-beta.15 → 2.2.0-beta.17
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/lib/acl/Acl.d.ts +2 -1
- package/lib/acl/Acl.js +28 -0
- package/lib/components/FlowContextSelector.js +7 -1
- package/lib/components/MobilePopup.js +14 -3
- package/lib/components/subModel/LazyDropdown.js +41 -26
- package/lib/flowContext.d.ts +5 -1
- package/lib/flowContext.js +18 -6
- package/lib/locale/en-US.json +2 -0
- package/lib/locale/index.d.ts +4 -0
- package/lib/locale/zh-CN.json +2 -0
- package/lib/utils/associationObjectVariable.d.ts +10 -0
- package/lib/utils/associationObjectVariable.js +10 -7
- package/lib/utils/dateVariable.d.ts +22 -0
- package/lib/utils/dateVariable.js +123 -16
- package/lib/utils/index.d.ts +3 -3
- package/lib/utils/index.js +8 -0
- package/lib/utils/params-resolvers.d.ts +3 -0
- package/lib/utils/params-resolvers.js +10 -0
- package/lib/utils/variablesParams.js +5 -0
- package/lib/views/createViewMeta.d.ts +1 -0
- package/lib/views/createViewMeta.js +53 -22
- package/package.json +4 -4
- package/src/__tests__/createViewMeta.popup.test.ts +84 -1
- package/src/__tests__/flowContext.test.ts +8 -0
- package/src/__tests__/objectVariable.test.ts +6 -1
- package/src/acl/Acl.tsx +36 -1
- package/src/acl/__tests__/Acl.test.tsx +70 -0
- package/src/components/FlowContextSelector.tsx +7 -1
- package/src/components/MobilePopup.tsx +16 -4
- package/src/components/__tests__/MobilePopup.test.tsx +42 -1
- package/src/components/subModel/LazyDropdown.tsx +44 -26
- package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +85 -2
- package/src/components/variables/__tests__/FlowContextSelector.test.tsx +35 -0
- package/src/flowContext.ts +31 -5
- package/src/locale/__tests__/index.test.ts +21 -0
- package/src/locale/en-US.json +2 -0
- package/src/locale/zh-CN.json +2 -0
- package/src/utils/__tests__/dateVariable.test.ts +57 -4
- package/src/utils/__tests__/variablesParams.test.ts +28 -1
- package/src/utils/associationObjectVariable.ts +9 -6
- package/src/utils/dateVariable.ts +145 -18
- package/src/utils/index.ts +17 -2
- package/src/utils/params-resolvers.ts +12 -0
- package/src/utils/variablesParams.ts +10 -0
- package/src/views/createViewMeta.ts +52 -18
|
@@ -15,6 +15,13 @@ import type { FlowView } from './FlowView';
|
|
|
15
15
|
|
|
16
16
|
type PopupModelLike = { getStepParams?: (a: string, b: string) => any } | undefined;
|
|
17
17
|
|
|
18
|
+
function buildPopupSourceRecordRef(ref?: Pick<RecordRef, 'associationName' | 'dataSourceKey' | 'sourceId'>) {
|
|
19
|
+
if (ref?.sourceId == null || ref.sourceId === '' || typeof ref.associationName !== 'string') return undefined;
|
|
20
|
+
const collection = ref.associationName.split('.')[0];
|
|
21
|
+
if (!collection) return undefined;
|
|
22
|
+
return { collection, dataSourceKey: ref.dataSourceKey || 'main', filterByTk: ref.sourceId };
|
|
23
|
+
}
|
|
24
|
+
|
|
18
25
|
function isDefined(value: any) {
|
|
19
26
|
return value !== undefined && value !== null;
|
|
20
27
|
}
|
|
@@ -327,13 +334,15 @@ export function createPopupMeta(ctx: FlowContext, anchorView?: FlowView): Proper
|
|
|
327
334
|
const stack = getViewStack(view);
|
|
328
335
|
const currentIndex = getAnchoredViewStackIndex(view, stack);
|
|
329
336
|
if (currentIndex >= 2) {
|
|
330
|
-
let cur
|
|
337
|
+
let cur = params;
|
|
331
338
|
let level = 1;
|
|
332
339
|
let parentRef = await getParentRecordRef(level, c);
|
|
333
340
|
while (parentRef) {
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
341
|
+
const parent: PopupVariableParams = { record: parentRef };
|
|
342
|
+
const sourceRecord = buildPopupSourceRecordRef(parentRef);
|
|
343
|
+
if (sourceRecord) parent.sourceRecord = sourceRecord;
|
|
344
|
+
cur.parent = parent;
|
|
345
|
+
cur = parent;
|
|
337
346
|
level += 1;
|
|
338
347
|
parentRef = await getParentRecordRef(level, c);
|
|
339
348
|
}
|
|
@@ -343,20 +352,12 @@ export function createPopupMeta(ctx: FlowContext, anchorView?: FlowView): Proper
|
|
|
343
352
|
}
|
|
344
353
|
|
|
345
354
|
try {
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
if (parentCollectionName) {
|
|
353
|
-
params.sourceRecord = {
|
|
354
|
-
collection: parentCollectionName,
|
|
355
|
-
dataSourceKey: dsKey,
|
|
356
|
-
filterByTk: srcId,
|
|
357
|
-
};
|
|
358
|
-
}
|
|
359
|
-
}
|
|
355
|
+
const sourceRecord = buildPopupSourceRecordRef({
|
|
356
|
+
sourceId: inputArgs?.sourceId,
|
|
357
|
+
associationName: inputArgs?.associationName,
|
|
358
|
+
dataSourceKey: inputArgs?.dataSourceKey,
|
|
359
|
+
});
|
|
360
|
+
if (sourceRecord) params.sourceRecord = sourceRecord;
|
|
360
361
|
} catch (err) {
|
|
361
362
|
c.logger?.debug?.({ err }, '[FlowEngine] buildVariablesParams: infer sourceRecord failed');
|
|
362
363
|
}
|
|
@@ -474,12 +475,14 @@ interface PopupNodeResource {
|
|
|
474
475
|
interface PopupNode {
|
|
475
476
|
uid?: string;
|
|
476
477
|
resource: PopupNodeResource;
|
|
478
|
+
sourceRecord?: unknown;
|
|
477
479
|
parent?: PopupNode;
|
|
478
480
|
}
|
|
479
481
|
|
|
480
482
|
export async function buildPopupRuntime(ctx: FlowContext, view: FlowView): Promise<PopupNode | undefined> {
|
|
481
483
|
const stack = getViewStack(view);
|
|
482
484
|
const currentIndex = getAnchoredViewStackIndex(view, stack);
|
|
485
|
+
const sourceRecord = view?.inputArgs?.parentItem?.value;
|
|
483
486
|
|
|
484
487
|
const openerUids = view?.inputArgs?.openerUids;
|
|
485
488
|
const hasOpener = Array.isArray(openerUids) && openerUids.length > 0;
|
|
@@ -502,6 +505,7 @@ export async function buildPopupRuntime(ctx: FlowContext, view: FlowView): Promi
|
|
|
502
505
|
filterByTk: args.filterByTk,
|
|
503
506
|
sourceId: args.sourceId,
|
|
504
507
|
},
|
|
508
|
+
...(typeof sourceRecord !== 'undefined' ? { sourceRecord } : {}),
|
|
505
509
|
};
|
|
506
510
|
}
|
|
507
511
|
|
|
@@ -530,6 +534,9 @@ export async function buildPopupRuntime(ctx: FlowContext, view: FlowView): Promi
|
|
|
530
534
|
return node;
|
|
531
535
|
};
|
|
532
536
|
const currentNode = await buildNode(currentIndex);
|
|
537
|
+
if (currentNode && typeof sourceRecord !== 'undefined') {
|
|
538
|
+
currentNode.sourceRecord = sourceRecord;
|
|
539
|
+
}
|
|
533
540
|
return currentNode;
|
|
534
541
|
}
|
|
535
542
|
|
|
@@ -541,6 +548,30 @@ export function registerPopupVariable(ctx: FlowContext, view: FlowView) {
|
|
|
541
548
|
// - 任意层级 parent.parent... 下的 record / sourceRecord 及其子字段
|
|
542
549
|
const POPUP_SERVER_PATH_RE =
|
|
543
550
|
/^(?:record|sourceRecord)(?:\.|$)|^parent(?:\.parent)*(?:\.(?:record|sourceRecord))(?:\.|$)/;
|
|
551
|
+
const shouldResolveSourceRecordOnServer = (path: string): boolean => {
|
|
552
|
+
if (path !== 'sourceRecord' && !path.startsWith('sourceRecord.')) return false;
|
|
553
|
+
|
|
554
|
+
const parentItem = view?.inputArgs?.parentItem;
|
|
555
|
+
if (typeof parentItem?.value === 'undefined') return true;
|
|
556
|
+
|
|
557
|
+
const sourcePath = path === 'sourceRecord' ? '' : path.slice('sourceRecord.'.length);
|
|
558
|
+
if (!sourcePath) return false;
|
|
559
|
+
|
|
560
|
+
const parentItemResolver = view?.inputArgs?.parentItemResolver;
|
|
561
|
+
if (typeof parentItemResolver === 'function') {
|
|
562
|
+
return parentItemResolver(`value.${sourcePath}`);
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
const segments = sourcePath.split('.').filter(Boolean);
|
|
566
|
+
let current = parentItem.value;
|
|
567
|
+
for (const segment of segments) {
|
|
568
|
+
if (current === null || typeof current !== 'object' || !(segment in current)) {
|
|
569
|
+
return true;
|
|
570
|
+
}
|
|
571
|
+
current = current[segment];
|
|
572
|
+
}
|
|
573
|
+
return false;
|
|
574
|
+
};
|
|
544
575
|
// 始终注册 popup 变量:
|
|
545
576
|
// - 若当前视图无可推断记录,仅在元信息中不呈现 record 字段;
|
|
546
577
|
// - 但仍可依据 navigation 推断并展示上级弹窗信息。
|
|
@@ -549,6 +580,9 @@ export function registerPopupVariable(ctx: FlowContext, view: FlowView) {
|
|
|
549
580
|
meta: createPopupMeta(ctx, view),
|
|
550
581
|
resolveOnServer: (p: string) => {
|
|
551
582
|
try {
|
|
583
|
+
if (p === 'sourceRecord' || p.startsWith('sourceRecord.')) {
|
|
584
|
+
return shouldResolveSourceRecordOnServer(p);
|
|
585
|
+
}
|
|
552
586
|
return !!p && POPUP_SERVER_PATH_RE.test(p);
|
|
553
587
|
} catch (_) {
|
|
554
588
|
return false;
|