fix(plugin-workflow): fix manual assignee select variable type filter (#2396)

* fix(plugin-workflow): fix manual assignee select variable type filter

* chore(plugin-workflow): fix lint issues
This commit is contained in:
Junyi 2023-08-04 16:56:12 +07:00 committed by GitHub
parent 5ef8fe7848
commit 53a6a6c621
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 9 deletions

View File

@ -2,8 +2,15 @@ import { RemoteSelect, Variable } from '@nocobase/client';
import React from 'react';
import { useWorkflowVariableOptions } from '../../variable';
function isUserKeyField(field) {
if (field.isForeignKey) {
return field.target === 'users';
}
return field.collectionName === 'users' && field.name === 'id';
}
export function AssigneesSelect({ multiple = false, value = [], onChange }) {
const scope = useWorkflowVariableOptions({ types: [{ type: 'reference', options: { collection: 'users' } }] });
const scope = useWorkflowVariableOptions({ types: [isUserKeyField] });
return (
<Variable.Input

View File

@ -15,12 +15,12 @@ export type VariableOption = {
export type VariableOptions = VariableOption[] | null;
export type VariableDataType =
string |
{
| string
| {
type: string;
options?: { entity?: boolean; collection?: string }
} |
((field: any, appends?: string[]) => boolean);
options?: { entity?: boolean; collection?: string };
}
| ((field: any, appends?: string[]) => boolean);
export type OptionsOfUseVariableOptions = {
types?: VariableDataType[];
@ -29,7 +29,7 @@ export type OptionsOfUseVariableOptions = {
value?: string;
children?: string;
};
}
};
export const defaultFieldNames = { label: 'label', value: 'value', children: 'children' } as const;
@ -283,7 +283,15 @@ async function loadChildren(option) {
}
export function getCollectionFieldOptions(options): VariableOption[] {
const { fields, collection, types, appends = [], compile, getCollectionFields, fieldNames = defaultFieldNames } = options;
const {
fields,
collection,
types,
appends = [],
compile,
getCollectionFields,
fieldNames = defaultFieldNames,
} = options;
const normalizedFields = getNormalizedFields(collection, { compile, getCollectionFields });
const computedFields = fields ?? normalizedFields;
const boundLoadChildren = loadChildren.bind({ compile, getCollectionFields, fieldNames });