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 { BaseTypeSet, CollectionFieldset } from '../calculators';
|
||||||
import { collection, values } from '../schemas/collection';
|
import { collection, values } from '../schemas/collection';
|
||||||
import { useFlowContext } from '../WorkflowCanvas';
|
import { useFlowContext } from '../WorkflowCanvas';
|
||||||
|
import CollectionFieldSelect from '../components/CollectionFieldSelect';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -38,24 +39,20 @@ export default {
|
|||||||
components: {
|
components: {
|
||||||
CollectionFieldset
|
CollectionFieldset
|
||||||
},
|
},
|
||||||
getter({ type, options, onChange }) {
|
getter(props) {
|
||||||
const { t } = useTranslation();
|
const { type, options, onChange } = props;
|
||||||
const compile = useCompile();
|
|
||||||
const { collections = [] } = useCollectionManager();
|
|
||||||
const { nodes } = useFlowContext();
|
const { nodes } = useFlowContext();
|
||||||
const { config } = nodes.find(n => n.id == options.nodeId);
|
const { config } = nodes.find(n => n.id == options.nodeId);
|
||||||
const collection = collections.find(item => item.name === config.collection) ?? { fields: [] };
|
const value = options?.path;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Select value={options.path} placeholder={t('Fields')} onChange={path => {
|
<CollectionFieldSelect
|
||||||
onChange({ type, options: { ...options, path } });
|
collection={config.collection}
|
||||||
}}>
|
value={value}
|
||||||
{collection.fields
|
onChange={(value) => {
|
||||||
.filter(field => BaseTypeSet.has(field.uiSchema.type))
|
onChange({ type, options: { ...options, path: value?.join('.') } });
|
||||||
.map(field => (
|
}}
|
||||||
<Select.Option key={field.name} value={field.name}>{compile(field.uiSchema.title)}</Select.Option>
|
/>
|
||||||
))}
|
|
||||||
</Select>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Select } from 'antd';
|
|
||||||
import { useTranslation } from 'react-i18next';
|
|
||||||
|
|
||||||
import { useCollectionDataSource, useCollectionManager, useCompile } from '@nocobase/client';
|
import { useCollectionDataSource, useCollectionManager, useCompile } from '@nocobase/client';
|
||||||
|
|
||||||
import { useFlowContext } from '../WorkflowCanvas';
|
import { useFlowContext } from '../WorkflowCanvas';
|
||||||
import { BaseTypeSet, VariableComponent } from '../calculators';
|
import { VariableComponent } from '../calculators';
|
||||||
import { collection, filter } from '../schemas/collection';
|
import { collection, filter } from '../schemas/collection';
|
||||||
|
import CollectionFieldSelect from '../components/CollectionFieldSelect';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -45,24 +44,20 @@ export default {
|
|||||||
components: {
|
components: {
|
||||||
VariableComponent
|
VariableComponent
|
||||||
},
|
},
|
||||||
getter({ type, options, onChange }) {
|
getter(props) {
|
||||||
const { t } = useTranslation();
|
const { type, options, onChange } = props;
|
||||||
const compile = useCompile();
|
|
||||||
const { collections = [] } = useCollectionManager();
|
|
||||||
const { nodes } = useFlowContext();
|
const { nodes } = useFlowContext();
|
||||||
const { config } = nodes.find(n => n.id == options.nodeId);
|
const { config } = nodes.find(n => n.id == options.nodeId);
|
||||||
const collection = collections.find(item => item.name === config.collection) ?? { fields: [] };
|
const value = options?.path;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Select value={options.path} placeholder={t('Fields')} onChange={path => {
|
<CollectionFieldSelect
|
||||||
onChange({ type, options: { ...options, path } });
|
collection={config.collection}
|
||||||
}}>
|
value={value}
|
||||||
{collection.fields
|
onChange={(value) => {
|
||||||
.filter(field => BaseTypeSet.has(field.uiSchema?.type))
|
onChange({ type, options: { ...options, path: value?.join('.') } });
|
||||||
.map(field => (
|
}}
|
||||||
<Select.Option key={field.name} value={field.name}>{compile(field.uiSchema.title)}</Select.Option>
|
/>
|
||||||
))}
|
|
||||||
</Select>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -5,11 +5,10 @@ import { observer, useForm, useFormEffects } from '@formily/react';
|
|||||||
import { useCollectionDataSource, useCollectionManager, useCompile } from '@nocobase/client';
|
import { useCollectionDataSource, useCollectionManager, useCompile } from '@nocobase/client';
|
||||||
|
|
||||||
import { useFlowContext } from '../WorkflowCanvas';
|
import { useFlowContext } from '../WorkflowCanvas';
|
||||||
import { BaseTypeSet } from '../calculators';
|
|
||||||
import { collection, filter } from '../schemas/collection';
|
import { collection, filter } from '../schemas/collection';
|
||||||
import { useTranslation } from 'react-i18next';
|
|
||||||
import { css } from '@emotion/css';
|
import { css } from '@emotion/css';
|
||||||
import { onFieldValueChange } from '@formily/core';
|
import { onFieldValueChange } from '@formily/core';
|
||||||
|
import CollectionFieldSelect from '../components/CollectionFieldSelect';
|
||||||
|
|
||||||
const FieldsSelect = observer((props) => {
|
const FieldsSelect = observer((props) => {
|
||||||
const compile = useCompile();
|
const compile = useCompile();
|
||||||
@ -42,6 +41,8 @@ const FieldsSelect = observer((props) => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
title: '{{t("Collection event")}}',
|
title: '{{t("Collection event")}}',
|
||||||
type: 'collection',
|
type: 'collection',
|
||||||
@ -127,27 +128,19 @@ export default {
|
|||||||
components: {
|
components: {
|
||||||
FieldsSelect
|
FieldsSelect
|
||||||
},
|
},
|
||||||
getter({ type, options, onChange }) {
|
getter(props) {
|
||||||
const { t } = useTranslation();
|
const { type, options, onChange } = props;
|
||||||
const compile = useCompile();
|
|
||||||
const { collections = [] } = useCollectionManager();
|
|
||||||
const { workflow } = useFlowContext();
|
const { workflow } = useFlowContext();
|
||||||
const collection = collections.find(item => item.name === workflow.config.collection) ?? { fields: [] };
|
const value = options?.path?.replace(/^data\./, '');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Select
|
<CollectionFieldSelect
|
||||||
placeholder={t('Fields')}
|
collection={workflow.config.collection}
|
||||||
value={options?.path?.replace(/^data\./, '')}
|
value={value}
|
||||||
onChange={(path) => {
|
onChange={(value) => {
|
||||||
onChange({ type, options: { ...options, path: `data.${path}` } });
|
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