feat(plugin-workflow): add association select in calculation (#584)
This commit is contained in:
parent
4846c43c28
commit
e4a0bb42f6
@ -0,0 +1,29 @@
|
||||
import React from "react";
|
||||
import { Cascader } from 'antd';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { useCollectionFilterOptions, useCompile } from "@nocobase/client";
|
||||
|
||||
|
||||
|
||||
export default function (props) {
|
||||
const { collection, value, onChange } = props;
|
||||
const { t } = useTranslation();
|
||||
const compile = useCompile();
|
||||
const fields = useCollectionFilterOptions(collection);
|
||||
|
||||
return (
|
||||
<Cascader
|
||||
fieldNames={{
|
||||
label: 'title',
|
||||
value: 'name',
|
||||
children: 'children',
|
||||
}}
|
||||
changeOnSelect={false}
|
||||
value={Array.isArray(value) ? value : value?.split('.')}
|
||||
options={compile(fields)}
|
||||
onChange={onChange}
|
||||
placeholder={t('Select Field')}
|
||||
/>
|
||||
);
|
||||
}
|
@ -5,6 +5,7 @@ import { useCollectionDataSource, useCollectionManager, useCompile } from '@noco
|
||||
import { BaseTypeSet, CollectionFieldset } from '../calculators';
|
||||
import { collection, values } from '../schemas/collection';
|
||||
import { useFlowContext } from '../WorkflowCanvas';
|
||||
import CollectionFieldSelect from '../components/CollectionFieldSelect';
|
||||
|
||||
|
||||
|
||||
@ -38,24 +39,20 @@ export default {
|
||||
components: {
|
||||
CollectionFieldset
|
||||
},
|
||||
getter({ type, options, onChange }) {
|
||||
const { t } = useTranslation();
|
||||
const compile = useCompile();
|
||||
const { collections = [] } = useCollectionManager();
|
||||
getter(props) {
|
||||
const { type, options, onChange } = props;
|
||||
const { nodes } = useFlowContext();
|
||||
const { config } = nodes.find(n => n.id == options.nodeId);
|
||||
const collection = collections.find(item => item.name === config.collection) ?? { fields: [] };
|
||||
const value = options?.path;
|
||||
|
||||
return (
|
||||
<Select value={options.path} placeholder={t('Fields')} onChange={path => {
|
||||
onChange({ type, options: { ...options, path } });
|
||||
}}>
|
||||
{collection.fields
|
||||
.filter(field => BaseTypeSet.has(field.uiSchema.type))
|
||||
.map(field => (
|
||||
<Select.Option key={field.name} value={field.name}>{compile(field.uiSchema.title)}</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
<CollectionFieldSelect
|
||||
collection={config.collection}
|
||||
value={value}
|
||||
onChange={(value) => {
|
||||
onChange({ type, options: { ...options, path: value?.join('.') } });
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
@ -1,12 +1,11 @@
|
||||
import React from 'react';
|
||||
import { Select } from 'antd';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { useCollectionDataSource, useCollectionManager, useCompile } from '@nocobase/client';
|
||||
|
||||
import { useFlowContext } from '../WorkflowCanvas';
|
||||
import { BaseTypeSet, VariableComponent } from '../calculators';
|
||||
import { VariableComponent } from '../calculators';
|
||||
import { collection, filter } from '../schemas/collection';
|
||||
import CollectionFieldSelect from '../components/CollectionFieldSelect';
|
||||
|
||||
|
||||
|
||||
@ -45,24 +44,20 @@ export default {
|
||||
components: {
|
||||
VariableComponent
|
||||
},
|
||||
getter({ type, options, onChange }) {
|
||||
const { t } = useTranslation();
|
||||
const compile = useCompile();
|
||||
const { collections = [] } = useCollectionManager();
|
||||
getter(props) {
|
||||
const { type, options, onChange } = props;
|
||||
const { nodes } = useFlowContext();
|
||||
const { config } = nodes.find(n => n.id == options.nodeId);
|
||||
const collection = collections.find(item => item.name === config.collection) ?? { fields: [] };
|
||||
const value = options?.path;
|
||||
|
||||
return (
|
||||
<Select value={options.path} placeholder={t('Fields')} onChange={path => {
|
||||
onChange({ type, options: { ...options, path } });
|
||||
}}>
|
||||
{collection.fields
|
||||
.filter(field => BaseTypeSet.has(field.uiSchema?.type))
|
||||
.map(field => (
|
||||
<Select.Option key={field.name} value={field.name}>{compile(field.uiSchema.title)}</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
<CollectionFieldSelect
|
||||
collection={config.collection}
|
||||
value={value}
|
||||
onChange={(value) => {
|
||||
onChange({ type, options: { ...options, path: value?.join('.') } });
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
@ -5,11 +5,10 @@ import { observer, useForm, useFormEffects } from '@formily/react';
|
||||
import { useCollectionDataSource, useCollectionManager, useCompile } from '@nocobase/client';
|
||||
|
||||
import { useFlowContext } from '../WorkflowCanvas';
|
||||
import { BaseTypeSet } from '../calculators';
|
||||
import { collection, filter } from '../schemas/collection';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { css } from '@emotion/css';
|
||||
import { onFieldValueChange } from '@formily/core';
|
||||
import CollectionFieldSelect from '../components/CollectionFieldSelect';
|
||||
|
||||
const FieldsSelect = observer((props) => {
|
||||
const compile = useCompile();
|
||||
@ -42,6 +41,8 @@ const FieldsSelect = observer((props) => {
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
|
||||
export default {
|
||||
title: '{{t("Collection event")}}',
|
||||
type: 'collection',
|
||||
@ -127,27 +128,19 @@ export default {
|
||||
components: {
|
||||
FieldsSelect
|
||||
},
|
||||
getter({ type, options, onChange }) {
|
||||
const { t } = useTranslation();
|
||||
const compile = useCompile();
|
||||
const { collections = [] } = useCollectionManager();
|
||||
getter(props) {
|
||||
const { type, options, onChange } = props;
|
||||
const { workflow } = useFlowContext();
|
||||
const collection = collections.find(item => item.name === workflow.config.collection) ?? { fields: [] };
|
||||
const value = options?.path?.replace(/^data\./, '');
|
||||
|
||||
return (
|
||||
<Select
|
||||
placeholder={t('Fields')}
|
||||
value={options?.path?.replace(/^data\./, '')}
|
||||
onChange={(path) => {
|
||||
onChange({ type, options: { ...options, path: `data.${path}` } });
|
||||
<CollectionFieldSelect
|
||||
collection={workflow.config.collection}
|
||||
value={value}
|
||||
onChange={(value) => {
|
||||
onChange({ type, options: { ...options, path: `data.${value.join('.')}` } });
|
||||
}}
|
||||
>
|
||||
{collection.fields
|
||||
.filter(field => BaseTypeSet.has(field?.uiSchema?.type))
|
||||
.map(field => (
|
||||
<Select.Option key={field.name} value={field.name}>{compile(field.uiSchema.title)}</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
/>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user