Fix(plugin-workflow) (#353)

* fix(plugin-workflow): fix component reaction

* test(plugin-workflow): try to fix ci random failing
This commit is contained in:
Junyi 2022-05-02 10:10:22 +08:00 committed by GitHub
parent 53ef901156
commit 7ef1ebb600
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 77 additions and 75 deletions

View File

@ -2,7 +2,7 @@ import React, { useContext } from 'react';
import { Dropdown, Menu, Button } from 'antd'; import { Dropdown, Menu, Button } from 'antd';
import { PlusOutlined } from '@ant-design/icons'; import { PlusOutlined } from '@ant-design/icons';
import { cx } from '@emotion/css'; import { cx } from '@emotion/css';
import { addButtonClass, branchBlockClass, branchClass, nodeBlockClass, nodeCardClass, nodeHeaderClass, nodeTitleClass } from './style'; import { useTranslation } from 'react-i18next';
import { import {
useCollection, useCollection,
@ -10,8 +10,7 @@ import {
useResourceActionContext useResourceActionContext
} from '..'; } from '..';
import { Instruction, instructions, Node } from './nodes'; import { Instruction, instructions, Node } from './nodes';
import { t } from 'i18next'; import { addButtonClass, branchBlockClass, branchClass, nodeBlockClass, nodeCardClass, nodeHeaderClass, nodeTitleClass } from './style';
import { useTranslation } from 'react-i18next';

View File

@ -1,6 +1,5 @@
import { css } from "@emotion/css"; import { css } from "@emotion/css";
import { useForm } from "@formily/react"; import { useForm } from "@formily/react";
import { useCollectionManager } from "../../collection-manager";
import { useCollectionFilterOptions } from "../../collection-manager/action-hooks"; import { useCollectionFilterOptions } from "../../collection-manager/action-hooks";
export const collection = { export const collection = {

View File

@ -1,7 +1,6 @@
import React from 'react'; import React from 'react';
import { Select } from 'antd'; import { Select } from 'antd';
import { action } from '@formily/reactive'; import { observer, useForm } from '@formily/react';
import { useForm } from '@formily/react';
import { useCollectionDataSource, useCollectionManager } from '../../collection-manager'; import { useCollectionDataSource, useCollectionManager } from '../../collection-manager';
import { useCompile } from '../../schema-component'; import { useCompile } from '../../schema-component';
@ -11,26 +10,27 @@ import { BaseTypeSet } from '../calculators';
import { collection, filter } from '../schemas/collection'; import { collection, filter } from '../schemas/collection';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
function useCollectionFieldsDataSource() { const FieldsSelect = observer((props) => {
const compile = useCompile(); const compile = useCompile();
const { getCollectionFields } = useCollectionManager(); const { getCollectionFields } = useCollectionManager();
const { values } = useForm(); const { values } = useForm();
const fields = getCollectionFields(values?.config?.collection); const fields = getCollectionFields(values?.config?.collection);
return (field: any) => { return (
action.bound((data: any) => { <Select
field.dataSource = data {...props}
>
{fields
.filter(field => ( .filter(field => (
!field.hidden !field.hidden
&& (field.uiSchema ? !field.uiSchema['x-read-pretty'] : true) && (field.uiSchema ? !field.uiSchema['x-read-pretty'] : true)
)) ))
.map(field => ({ .map(field => (
label: compile(field.uiSchema?.title), <Select.Option value={field.name}>{compile(field.uiSchema?.title)}</Select.Option>
value: field.name ))}
})); </Select>
})(fields); );
}; });
}
export default { export default {
title: '{{t("Collection event")}}', title: '{{t("Collection event")}}',
@ -59,13 +59,10 @@ export default {
title: '{{t("Changed fields")}}', title: '{{t("Changed fields")}}',
description: '{{t("Triggered only if one of the selected fields changes. If unselected, it means that it will be triggered when any field changes. When record is added or deleted, any field is considered to have been changed.")}}', description: '{{t("Triggered only if one of the selected fields changes. If unselected, it means that it will be triggered when any field changes. When record is added or deleted, any field is considered to have been changed.")}}',
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-component': 'Select', 'x-component': 'FieldsSelect',
'x-component-props': { 'x-component-props': {
mode: 'multiple', mode: 'multiple',
}, }
'x-reactions': [
'{{useCollectionFieldsDataSource()}}'
]
}, },
'config.condition': { 'config.condition': {
...filter, ...filter,
@ -74,8 +71,10 @@ export default {
} }
}, },
scope: { scope: {
useCollectionDataSource, useCollectionDataSource
useCollectionFieldsDataSource },
components: {
FieldsSelect
}, },
getter({ type, options, onChange }) { getter({ type, options, onChange }) {
const { t } = useTranslation(); const { t } = useTranslation();

View File

@ -54,7 +54,7 @@ export const TriggerConfig = () => {
return null; return null;
} }
const { type, config } = data.data; const { type, config } = data.data;
const { title, fieldset, scope } = triggers.get(type); const { title, fieldset, scope, components } = triggers.get(type);
return ( return (
<div className={cx(nodeCardClass)}> <div className={cx(nodeCardClass)}>
<div className={cx(nodeMetaClass)}> <div className={cx(nodeMetaClass)}>
@ -110,6 +110,7 @@ export const TriggerConfig = () => {
} }
}} }}
scope={scope} scope={scope}
components={components}
/> />
</div> </div>
); );

View File

@ -148,6 +148,7 @@ describe('workflow > instructions > condition', () => {
}); });
it('and false', async () => { it('and false', async () => {
await db.sequelize.transaction(async transaction => {
const n1 = workflow.createNode({ const n1 = workflow.createNode({
type: 'condition', type: 'condition',
config: { config: {
@ -167,14 +168,15 @@ describe('workflow > instructions > condition', () => {
} }
} }
} }
}); }, { transaction });
const post = await PostModel.create({ title: 't1' }); const post = await PostModel.create({ title: 't1' }, { transaction });
const [execution] = await workflow.getExecutions(); const [execution] = await workflow.getExecutions({ transaction });
const [job] = await execution.getJobs(); const [job] = await execution.getJobs({ transaction });
expect(job.result).toBe(false); expect(job.result).toBe(false);
}); });
});
it('or true', async () => { it('or true', async () => {
const n1 = workflow.createNode({ const n1 = workflow.createNode({
@ -235,6 +237,7 @@ describe('workflow > instructions > condition', () => {
}); });
it('nested', async () => { it('nested', async () => {
await db.sequelize.transaction(async transaction => {
const n1 = workflow.createNode({ const n1 = workflow.createNode({
type: 'condition', type: 'condition',
config: { config: {
@ -259,13 +262,14 @@ describe('workflow > instructions > condition', () => {
} }
} }
} }
}); }, { transaction });
const post = await PostModel.create({ title: 't1' }); const post = await PostModel.create({ title: 't1' }, { transaction });
const [execution] = await workflow.getExecutions(); const [execution] = await workflow.getExecutions({ transaction });
const [job] = await execution.getJobs(); const [job] = await execution.getJobs({ transaction });
expect(job.result).toBe(false); expect(job.result).toBe(false);
}); });
}); });
});
}); });