Merge branch 'next' into develop

This commit is contained in:
nocobase[bot] 2025-06-19 02:12:02 +00:00
commit 5e83e2b82b
6 changed files with 50 additions and 36 deletions

View File

@ -23,7 +23,7 @@ import {
useWorkflowAnyExecuted,
CheckboxGroupWithTooltip,
RadioWithTooltip,
useGetCollectionFields,
useGetDataSourceCollectionManager,
TriggerCollectionRecordSelect,
WorkflowVariableWrapper,
} from '@nocobase/plugin-workflow/client';
@ -40,8 +40,8 @@ const COLLECTION_TRIGGER_ACTION = {
function useVariables(config, options) {
const [dataSourceName, collection] = parseCollectionName(config.collection);
const compile = useCompile();
const getCollectionFields = useGetCollectionFields(dataSourceName);
const getMainCollectionFields = useGetCollectionFields();
const collectionManager = useGetDataSourceCollectionManager(dataSourceName);
const mainCollectionManager = useGetDataSourceCollectionManager();
const langTriggerData = useLang('Trigger data');
const langUserSubmittedForm = useLang('User acted');
@ -63,7 +63,7 @@ function useVariables(config, options) {
},
],
compile,
getCollectionFields,
collectionManager,
}),
...getCollectionFieldOptions({
// depth,
@ -87,7 +87,7 @@ function useVariables(config, options) {
},
],
compile,
getCollectionFields: getMainCollectionFields,
collectionManager: mainCollectionManager,
}),
];
return result;

View File

@ -17,13 +17,13 @@ import CollectionFieldset from '../components/CollectionFieldset';
import { AssignedFieldsFormSchemaConfig } from '../components/AssignedFieldsFormSchemaConfig';
import { NAMESPACE } from '../locale';
import { appends, collection, values } from '../schemas/collection';
import { getCollectionFieldOptions, useGetCollectionFields } from '../variable';
import { getCollectionFieldOptions, useGetDataSourceCollectionManager } from '../variable';
import { Instruction, useNodeSavedConfig } from '.';
function useVariables({ key: name, title, config }, options) {
const [dataSourceName, collection] = parseCollectionName(config.collection);
const compile = useCompile();
const getCollectionFields = useGetCollectionFields(dataSourceName);
const collectionManager = useGetDataSourceCollectionManager(dataSourceName);
// const depth = config?.params?.appends?.length
// ? config?.params?.appends.reduce((max, item) => Math.max(max, item.split('.').length), 1)
// : 0;
@ -44,7 +44,7 @@ function useVariables({ key: name, title, config }, options) {
},
],
compile,
getCollectionFields,
collectionManager,
});
return result;

View File

@ -25,14 +25,14 @@ import { CollectionBlockInitializer } from '../components/CollectionBlockInitial
import { FilterDynamicComponent } from '../components/FilterDynamicComponent';
import { NAMESPACE } from '../locale';
import { appends, collection, filter, pagination, sort } from '../schemas/collection';
import { WorkflowVariableInput, getCollectionFieldOptions, useGetCollectionFields } from '../variable';
import { WorkflowVariableInput, getCollectionFieldOptions, useGetDataSourceCollectionManager } from '../variable';
import { Instruction, useNodeSavedConfig } from '.';
import { RadioWithTooltip } from '../components';
function useVariables({ key: name, title, config }, options) {
const [dataSourceName, collection] = parseCollectionName(config.collection);
const compile = useCompile();
const getCollectionFields = useGetCollectionFields(dataSourceName);
const collectionManager = useGetDataSourceCollectionManager(dataSourceName);
// const depth = config?.params?.appends?.length
// ? config?.params?.appends.reduce((max, item) => Math.max(max, item.split('.').length), 1)
// : 0;
@ -53,7 +53,7 @@ function useVariables({ key: name, title, config }, options) {
},
],
compile,
getCollectionFields,
collectionManager,
});
return result;

View File

@ -12,7 +12,7 @@ import { CollectionBlockInitializer } from '../components/CollectionBlockInitial
import { FieldsSelect } from '../components/FieldsSelect';
import { NAMESPACE, lang } from '../locale';
import { appends, collection, filter } from '../schemas/collection';
import { getCollectionFieldOptions, useGetCollectionFields } from '../variable';
import { getCollectionFieldOptions, useGetDataSourceCollectionManager } from '../variable';
import { useWorkflowAnyExecuted } from '../hooks';
import { Trigger } from '.';
import { TriggerCollectionRecordSelect } from '../components/TriggerCollectionRecordSelect';
@ -34,7 +34,7 @@ const collectionModeOptions = [
function useVariables(config, options) {
const [dataSourceName, collection] = parseCollectionName(config.collection);
const compile = useCompile();
const getCollectionFields = useGetCollectionFields(dataSourceName);
const collectionManager = useGetDataSourceCollectionManager(dataSourceName);
const rootFields = [
{
@ -56,7 +56,7 @@ function useVariables(config, options) {
...options,
fields: rootFields,
compile,
getCollectionFields,
collectionManager,
});
return result;
}

View File

@ -11,7 +11,7 @@ import { SchemaInitializerItemType, parseCollectionName, useCollectionDataSource
import { CollectionBlockInitializer } from '../../components/CollectionBlockInitializer';
import { NAMESPACE, lang } from '../../locale';
import { getCollectionFieldOptions, useGetCollectionFields } from '../../variable';
import { getCollectionFieldOptions, useGetDataSourceCollectionManager } from '../../variable';
import { Trigger } from '..';
import { ScheduleConfig } from './ScheduleConfig';
import { SCHEDULE_MODE } from './constants';
@ -23,7 +23,7 @@ import { TriggerCollectionRecordSelect } from '../../components/TriggerCollectio
function useVariables(config, opts) {
const [dataSourceName, collection] = parseCollectionName(config.collection);
const compile = useCompile();
const getCollectionFields = useGetCollectionFields(dataSourceName);
const collectionManager = useGetDataSourceCollectionManager(dataSourceName);
const options: any[] = [];
if (!opts?.types || opts.types.includes('date')) {
options.push({ key: 'date', value: 'date', label: lang('Trigger time') });
@ -50,7 +50,7 @@ function useVariables(config, opts) {
},
],
compile,
getCollectionFields,
collectionManager,
});
if (fieldOption) {
options.push(fieldOption);

View File

@ -10,7 +10,15 @@
import { uniqBy } from 'lodash';
import React, { createContext, useCallback, useContext } from 'react';
import { Variable, parseCollectionName, useApp, useCompile, useGlobalVariable, usePlugin } from '@nocobase/client';
import {
CollectionManager,
Variable,
parseCollectionName,
useApp,
useCompile,
useGlobalVariable,
usePlugin,
} from '@nocobase/client';
import WorkflowPlugin from '.';
import { useFlowContext } from './FlowContext';
@ -38,7 +46,7 @@ export type VariableDataType =
entity?: boolean;
};
}
| ((field: any) => boolean);
| ((field: any, options: { collectionManager?: CollectionManager }) => boolean);
export type UseVariableOptions = {
types?: VariableDataType[];
@ -133,7 +141,11 @@ export const BaseTypeSets = {
// { type: 'reference', options: { collection: 'attachments', multiple: false } }
// { type: 'reference', options: { collection: 'myExpressions', entity: false } }
function matchFieldType(field, type: VariableDataType): boolean {
function matchFieldType(
field,
type: VariableDataType,
{ collectionManager }: { collectionManager?: CollectionManager },
): boolean {
if (typeof type === 'string') {
return BaseTypeSets[type]?.has(field.interface);
}
@ -154,7 +166,7 @@ function matchFieldType(field, type: VariableDataType): boolean {
}
if (typeof type === 'function') {
return type(field);
return type(field, { collectionManager });
}
return false;
@ -172,9 +184,9 @@ function getNextAppends(field, appends: string[] | null): string[] | null {
return appends.filter((item) => item.startsWith(fieldPrefix)).map((item) => item.replace(fieldPrefix, ''));
}
function filterTypedFields({ fields, types, appends, depth = 1, compile, getCollectionFields }) {
function filterTypedFields({ fields, types, appends, depth = 1, compile, collectionManager }) {
return fields.filter((field) => {
const match = types?.length ? types.some((type) => matchFieldType(field, type)) : true;
const match = types?.length ? types.some((type) => matchFieldType(field, type, { collectionManager })) : true;
if (isAssociationField(field)) {
if (appends === null) {
if (!depth) {
@ -183,12 +195,12 @@ function filterTypedFields({ fields, types, appends, depth = 1, compile, getColl
return (
match ||
filterTypedFields({
fields: getNormalizedFields(field.target, { compile, getCollectionFields }),
fields: getNormalizedFields(field.target, { compile, collectionManager }),
types,
depth: depth - 1,
appends,
compile,
getCollectionFields,
collectionManager,
})
);
}
@ -200,12 +212,12 @@ function filterTypedFields({ fields, types, appends, depth = 1, compile, getColl
return (
(nextAppends?.length || included) &&
filterTypedFields({
fields: getNormalizedFields(field.target, { compile, getCollectionFields }),
fields: getNormalizedFields(field.target, { compile, collectionManager }),
types,
// depth: depth - 1,
appends: nextAppends,
compile,
getCollectionFields,
collectionManager,
}).length
);
}
@ -242,11 +254,11 @@ export function useWorkflowVariableOptions(options: UseVariableOptions = {}) {
return result;
}
function getNormalizedFields(collectionName, { compile, getCollectionFields }) {
function getNormalizedFields(collectionName, { compile, collectionManager }) {
// NOTE: for compatibility with legacy version
const [dataSourceName, collection] = parseCollectionName(collectionName);
// NOTE: `dataSourceName` will be ignored in new version
const fields = getCollectionFields(collection, dataSourceName);
const fields = collectionManager.getCollectionAllFields(collection);
const fkFields: any[] = [];
const result: any[] = [];
fields.forEach((field) => {
@ -315,7 +327,9 @@ function loadChildren(option) {
option.children = result;
} else {
option.isLeaf = true;
const matchingType = option.types ? option.types.some((type) => matchFieldType(option.field, type)) : true;
const matchingType = option.types
? option.types.some((type) => matchFieldType(option.field, type, { collectionManager: this.collectionManager }))
: true;
if (!matchingType) {
option.disabled = true;
}
@ -330,11 +344,11 @@ export function getCollectionFieldOptions(options): VariableOption[] {
appends = [],
depth = 1,
compile,
getCollectionFields,
collectionManager,
fieldNames = defaultFieldNames,
} = options;
const computedFields = fields ?? getNormalizedFields(collection, { compile, getCollectionFields });
const boundLoadChildren = loadChildren.bind({ compile, getCollectionFields, fieldNames });
const computedFields = fields ?? getNormalizedFields(collection, { compile, collectionManager });
const boundLoadChildren = loadChildren.bind({ compile, collectionManager, fieldNames });
const result: VariableOption[] = filterTypedFields({
fields: computedFields,
@ -342,7 +356,7 @@ export function getCollectionFieldOptions(options): VariableOption[] {
depth,
appends,
compile,
getCollectionFields,
collectionManager,
}).map((field) => {
const label = compile(field.uiSchema?.title || field.name);
const nextAppends = getNextAppends(field, appends);
@ -366,11 +380,11 @@ export function getCollectionFieldOptions(options): VariableOption[] {
return result;
}
export function useGetCollectionFields(dataSourceName?) {
export function useGetDataSourceCollectionManager(dataSourceName?) {
const app = useApp();
const { collectionManager } = app.dataSourceManager.getDataSource(dataSourceName);
return useCallback((collectionName) => collectionManager.getCollectionAllFields(collectionName), [collectionManager]);
return collectionManager;
}
export function WorkflowVariableInput({ variableOptions, ...props }): JSX.Element {