mirror of
https://gitee.com/nocobase/nocobase.git
synced 2024-12-02 12:18:15 +08:00
fix(plugin-workflow): fix assignees and aggregate variable (#2725)
This commit is contained in:
parent
49c2fbf45d
commit
6beae90806
@ -17,19 +17,20 @@ import { NAMESPACE, lang } from '../locale';
|
||||
import { collection, filter } from '../schemas/collection';
|
||||
import { BaseTypeSets, defaultFieldNames, nodesOptions, triggerOptions } from '../variable';
|
||||
|
||||
function matchToManyField(field, appends): boolean {
|
||||
const fieldPrefix = `${field.name}.`;
|
||||
return (
|
||||
(['hasOne', 'belongsTo'].includes(field.type) &&
|
||||
(appends ? appends.includes(field.name) || appends.some((item) => item.startsWith(fieldPrefix)) : true)) ||
|
||||
['hasMany', 'belongsToMany'].includes(field.type)
|
||||
);
|
||||
function matchToManyField(field): boolean {
|
||||
// const fieldPrefix = `${field.name}.`;
|
||||
return ['hasMany', 'belongsToMany'].includes(field.type);
|
||||
}
|
||||
|
||||
function useAssociatedFields() {
|
||||
const compile = useCompile();
|
||||
return [nodesOptions, triggerOptions].map((item) => {
|
||||
const children = item.useOptions({ types: [matchToManyField] })?.filter(Boolean);
|
||||
const children = item
|
||||
.useOptions({
|
||||
types: [matchToManyField],
|
||||
appends: null,
|
||||
})
|
||||
?.filter(Boolean);
|
||||
return {
|
||||
label: compile(item.label),
|
||||
value: item.value,
|
||||
@ -100,6 +101,9 @@ function AssociatedConfig({ value, onChange, ...props }): JSX.Element {
|
||||
|
||||
// const associationFieldName = path.pop();
|
||||
const { field } = option.pop();
|
||||
if (!field || !['hasMany', 'belongsToMany'].includes(field.type)) {
|
||||
return;
|
||||
}
|
||||
// need to get:
|
||||
// * source collection (from node.config)
|
||||
// * target collection (from field name)
|
||||
@ -242,6 +246,9 @@ export default {
|
||||
title: `{{t("Data of associated collection", { ns: "${NAMESPACE}" })}}`,
|
||||
'x-decorator': 'FormItem',
|
||||
'x-component': 'AssociatedConfig',
|
||||
'x-component-props': {
|
||||
changeOnSelect: true,
|
||||
},
|
||||
'x-reactions': [
|
||||
{
|
||||
dependencies: ['associated'],
|
||||
|
@ -53,6 +53,8 @@ export default {
|
||||
const name = `${id}`;
|
||||
const [result] = getCollectionFieldOptions({
|
||||
// collection: config.collection,
|
||||
// depth: options?.depth ?? depth,
|
||||
appends: [name, ...(config.params?.appends?.map((item) => `${name}.${item}`) || [])],
|
||||
...options,
|
||||
fields: [
|
||||
{
|
||||
@ -65,8 +67,6 @@ export default {
|
||||
},
|
||||
},
|
||||
],
|
||||
// depth: options?.depth ?? depth,
|
||||
appends: [name, ...(config.params?.appends?.map((item) => `${name}.${item}`) || [])],
|
||||
compile,
|
||||
getCollectionFields,
|
||||
});
|
||||
|
@ -98,6 +98,8 @@ export default {
|
||||
const name = `${id}`;
|
||||
const [result] = getCollectionFieldOptions({
|
||||
// collection: config.collection,
|
||||
// depth: options?.depth ?? depth,
|
||||
appends: [name, ...(config.params?.appends?.map((item) => `${name}.${item}`) || [])],
|
||||
...options,
|
||||
fields: [
|
||||
{
|
||||
@ -110,8 +112,6 @@ export default {
|
||||
},
|
||||
},
|
||||
],
|
||||
// depth: options?.depth ?? depth,
|
||||
appends: [name, ...(config.params?.appends?.map((item) => `${name}.${item}`) || [])],
|
||||
compile,
|
||||
getCollectionFields,
|
||||
});
|
||||
|
@ -170,9 +170,9 @@ export default {
|
||||
// : 1;
|
||||
const result = getCollectionFieldOptions({
|
||||
// depth,
|
||||
appends: ['data', ...(config.appends?.map((item) => `data.${item}`) || [])],
|
||||
...options,
|
||||
fields: rootFields,
|
||||
appends: ['data', ...(config.appends?.map((item) => `data.${item}`) || [])],
|
||||
compile,
|
||||
getCollectionFields,
|
||||
});
|
||||
|
@ -77,9 +77,9 @@ export default {
|
||||
];
|
||||
const result = getCollectionFieldOptions({
|
||||
// depth,
|
||||
appends: ['data', 'user', ...(config.appends?.map((item) => `data.${item}`) || [])],
|
||||
...options,
|
||||
fields: rootFields,
|
||||
appends: ['data', 'user', ...(config.appends?.map((item) => `data.${item}`) || [])],
|
||||
compile,
|
||||
getCollectionFields,
|
||||
});
|
||||
|
@ -43,6 +43,7 @@ export default {
|
||||
if (config.mode === SCHEDULE_MODE.COLLECTION_FIELD) {
|
||||
const [fieldOption] = getCollectionFieldOptions({
|
||||
// depth,
|
||||
appends: ['data', ...(config.appends?.map((item) => `data.${item}`) || [])],
|
||||
...opts,
|
||||
fields: [
|
||||
{
|
||||
@ -55,7 +56,6 @@ export default {
|
||||
},
|
||||
},
|
||||
],
|
||||
appends: ['data', ...(config.appends?.map((item) => `data.${item}`) || [])],
|
||||
compile,
|
||||
getCollectionFields,
|
||||
});
|
||||
|
@ -29,6 +29,7 @@ export type OptionsOfUseVariableOptions = {
|
||||
value?: string;
|
||||
children?: string;
|
||||
};
|
||||
appends?: string[] | null;
|
||||
};
|
||||
|
||||
export const defaultFieldNames = { label: 'label', value: 'value', children: 'children' } as const;
|
||||
@ -126,7 +127,7 @@ export const BaseTypeSets = {
|
||||
// { type: 'reference', options: { collection: 'attachments', multiple: false } }
|
||||
// { type: 'reference', options: { collection: 'myExpressions', entity: false } }
|
||||
|
||||
function matchFieldType(field, type, appends?: string[]): boolean {
|
||||
function matchFieldType(field, type): boolean {
|
||||
const inputType = typeof type;
|
||||
if (inputType === 'string') {
|
||||
return BaseTypeSets[type]?.has(field.interface);
|
||||
@ -148,7 +149,7 @@ function matchFieldType(field, type, appends?: string[]): boolean {
|
||||
}
|
||||
|
||||
if (inputType === 'function') {
|
||||
return type(field, appends);
|
||||
return type(field);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -158,32 +159,51 @@ function isAssociationField(field): boolean {
|
||||
return ['belongsTo', 'hasOne', 'hasMany', 'belongsToMany'].includes(field.type);
|
||||
}
|
||||
|
||||
function getNextAppends(field, appends: string[]) {
|
||||
function getNextAppends(field, appends: string[] | null): string[] | null {
|
||||
if (appends == null) {
|
||||
return null;
|
||||
}
|
||||
const fieldPrefix = `${field.name}.`;
|
||||
return appends.filter((item) => item.startsWith(fieldPrefix)).map((item) => item.replace(fieldPrefix, ''));
|
||||
}
|
||||
|
||||
function filterTypedFields({ fields, types, appends, compile, getCollectionFields }) {
|
||||
return fields.filter((field) => {
|
||||
if (types?.length) {
|
||||
return types.some((type) => matchFieldType(field, type, appends));
|
||||
}
|
||||
const match = types?.length ? types.some((type) => matchFieldType(field, type)) : true;
|
||||
if (isAssociationField(field)) {
|
||||
if (appends === null) {
|
||||
return (
|
||||
match ||
|
||||
filterTypedFields({
|
||||
fields: getNormalizedFields(field.target, { compile, getCollectionFields }),
|
||||
types,
|
||||
// depth: depth - 1,
|
||||
appends,
|
||||
compile,
|
||||
getCollectionFields,
|
||||
})
|
||||
);
|
||||
}
|
||||
const nextAppends = getNextAppends(field, appends);
|
||||
const included = appends.includes(field.name);
|
||||
return (
|
||||
(nextAppends.length || included) &&
|
||||
filterTypedFields({
|
||||
fields: getNormalizedFields(field.target, { compile, getCollectionFields }),
|
||||
types,
|
||||
// depth: depth - 1,
|
||||
appends: nextAppends,
|
||||
compile,
|
||||
getCollectionFields,
|
||||
}).length
|
||||
);
|
||||
if (match) {
|
||||
return included;
|
||||
} else {
|
||||
return (
|
||||
(nextAppends?.length || included) &&
|
||||
filterTypedFields({
|
||||
fields: getNormalizedFields(field.target, { compile, getCollectionFields }),
|
||||
types,
|
||||
// depth: depth - 1,
|
||||
appends: nextAppends,
|
||||
compile,
|
||||
getCollectionFields,
|
||||
}).length
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return match;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
@ -273,7 +293,7 @@ function loadChildren(option) {
|
||||
option.children = result;
|
||||
} else {
|
||||
option.isLeaf = true;
|
||||
const matchingType = option.types ? option.types.some((type) => matchFieldType(option.field, type, appends)) : true;
|
||||
const matchingType = option.types ? option.types.some((type) => matchFieldType(option.field, type)) : true;
|
||||
if (!matchingType) {
|
||||
option.disabled = true;
|
||||
}
|
||||
@ -303,10 +323,11 @@ export function getCollectionFieldOptions(options): VariableOption[] {
|
||||
getCollectionFields,
|
||||
}).map((field) => {
|
||||
const label = compile(field.uiSchema?.title || field.name);
|
||||
// console.log('===', label, field);
|
||||
const nextAppends = getNextAppends(field, appends);
|
||||
// TODO: no matching fields in next appends should consider isLeaf as true
|
||||
const isLeaf = !isAssociationField(field) || (!nextAppends.length && !appends.includes(field.name));
|
||||
const isLeaf =
|
||||
!isAssociationField(field) || (nextAppends && !nextAppends.length && !appends.includes(field.name)) || false;
|
||||
|
||||
return {
|
||||
[fieldNames.label]: label,
|
||||
key: field.name,
|
||||
|
Loading…
Reference in New Issue
Block a user