Fix(plugin workflow): fix cannot get job result properties (#382)

* fix(plugin-workflow): card drawer title

* fix(plugin-workflow): fix job result to use raw object than proxied model (#380)
This commit is contained in:
Junyi 2022-05-13 13:26:49 +08:00 committed by GitHub
parent 9e3995ab4a
commit 2df0e46318
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 54 additions and 15 deletions

View File

@ -165,13 +165,14 @@ export function NodeDefaultView(props) {
const { data, children } = props; const { data, children } = props;
const instruction = instructions.get(data.type); const instruction = instructions.get(data.type);
const detailText = workflow.executed ? '{{t("View")}}' : '{{t("Configure")}}'; const detailText = workflow.executed ? '{{t("View")}}' : '{{t("Configure")}}';
const typeText = compile(instruction.title);
return ( return (
<div className={cx(nodeClass, `workflow-node-type-${data.type}`)}> <div className={cx(nodeClass, `workflow-node-type-${data.type}`)}>
<div className={cx(nodeCardClass)}> <div className={cx(nodeCardClass)}>
<div className={cx(nodeHeaderClass)}> <div className={cx(nodeHeaderClass)}>
<div className={cx(nodeMetaClass)}> <div className={cx(nodeMetaClass)}>
<Tag>{compile(instruction.title)}</Tag> <Tag>{typeText}</Tag>
</div> </div>
<h4 className={cx(nodeTitleClass)}> <h4 className={cx(nodeTitleClass)}>
<strong>{data.title}</strong> <strong>{data.title}</strong>
@ -196,7 +197,7 @@ export function NodeDefaultView(props) {
properties: { properties: {
drawer: { drawer: {
type: 'void', type: 'void',
title: detailText, title: typeText,
'x-component': 'Action.Drawer', 'x-component': 'Action.Drawer',
'x-decorator': 'Form', 'x-decorator': 'Form',
'x-decorator-props': { 'x-decorator-props': {

View File

@ -61,6 +61,7 @@ export const TriggerConfig = () => {
const { type, config, executed } = data.data; const { type, config, executed } = data.data;
const { title, fieldset, scope, components } = triggers.get(type); const { title, fieldset, scope, components } = triggers.get(type);
const detailText = executed ? '{{t("View")}}' : '{{t("Configure")}}'; const detailText = executed ? '{{t("View")}}' : '{{t("Configure")}}';
const titleText = `${t('Trigger')}: ${compile(title)}`;
return ( return (
<div className={cx(nodeCardClass)}> <div className={cx(nodeCardClass)}>
@ -77,7 +78,7 @@ export const TriggerConfig = () => {
properties: { properties: {
drawer: { drawer: {
type: 'void', type: 'void',
title: detailText, title: titleText,
'x-component': 'Action.Drawer', 'x-component': 'Action.Drawer',
'x-decorator': 'Form', 'x-decorator': 'Form',
'x-decorator-props': { 'x-decorator-props': {

View File

@ -33,7 +33,7 @@ describe('workflow > instructions > update', () => {
describe('update one', () => { describe('update one', () => {
it('params: from context', async () => { it('params: from context', async () => {
const n2 = await workflow.createNode({ const n1 = await workflow.createNode({
type: 'update', type: 'update',
config: { config: {
collection: 'posts', collection: 'posts',
@ -59,4 +59,42 @@ describe('workflow > instructions > update', () => {
expect(updatedPost.published).toBe(true); expect(updatedPost.published).toBe(true);
}); });
}); });
it('params: from job of node', async () => {
const n1 = await workflow.createNode({
type: 'query',
config: {
collection: 'posts',
params: {
filter: {
title: 'test'
}
}
}
});
const n2 = await workflow.createNode({
type: 'update',
config: {
collection: 'posts',
params: {
filter: {
id: `{{$jobsMapByNodeId.${n1.id}.id}}`
},
values: {
title: 'changed'
}
}
},
upstreamId: n1.id
});
await n1.setDownstream(n2);
// NOTE: the result of post immediately created will not be changed by workflow
const { id } = await PostModel.create({ title: 'test' });
// should get from db
const post = await PostModel.findByPk(id);
expect(post.title).toBe('changed');
});
}); });

View File

@ -40,7 +40,7 @@ export default {
type: 'integer', type: 'integer',
title: 'branch index' title: 'branch index'
}, },
// for reasons: // Note: for reasons:
// 1. redirect type node to solve cycle flow. // 1. redirect type node to solve cycle flow.
// 2. recognize as real next node after branches. // 2. recognize as real next node after branches.
{ {
@ -53,14 +53,7 @@ export default {
interface: 'select', interface: 'select',
type: 'string', type: 'string',
name: 'type', name: 'type',
title: '类型', title: '类型'
// TODO: data for test only now
dataSource: [
{ label: '数据处理', value: 'data' },
{ label: '数据查询', value: 'query' },
{ label: '等待人工输入', value: 'prompt' },
{ label: '条件判断', value: 'condition' },
]
}, },
{ {
interface: 'json', interface: 'json',

View File

@ -16,7 +16,8 @@ export default {
}); });
return { return {
result, // NOTE: get() for non-proxied instance (#380)
result: result.get(),
status: JOB_STATUS.RESOLVED status: JOB_STATUS.RESOLVED
}; };
} }

View File

@ -13,6 +13,10 @@ export default {
const options = execution.getParsedValue(params); const options = execution.getParsedValue(params);
const result = await (multiple ? repo.find : repo.findOne).call(repo, { const result = await (multiple ? repo.find : repo.findOne).call(repo, {
...options, ...options,
// NOTE: `raw` to avoid getting undefined value from Proxied model instance (#380)
// e.g. Object.prototype.hasOwnProperty.call(result, 'id') // false
// so the properties can not be get by json-templates(object-path)
raw: true,
transaction: execution.tx transaction: execution.tx
}); });

View File

@ -1,8 +1,9 @@
import { JOB_STATUS } from "../constants"; import { JOB_STATUS } from "../constants";
import ExecutionModel from "../models/Execution";
import FlowNodeModel from "../models/FlowNode"; import FlowNodeModel from "../models/FlowNode";
export default { export default {
async run(this: FlowNodeModel, input, execution) { async run(this: FlowNodeModel, input, execution: ExecutionModel) {
const { const {
collection, collection,
multiple = false, multiple = false,