fix(plugin-workflow): fix update workflow current property (#521)
This commit is contained in:
parent
151c3a32b8
commit
2b3f3bd5c3
@ -49,7 +49,8 @@ export default {
|
|||||||
{ value: 2, label: '{{t("After record updated")}}' },
|
{ value: 2, label: '{{t("After record updated")}}' },
|
||||||
{ value: 3, label: '{{t("After record added or updated")}}' },
|
{ value: 3, label: '{{t("After record added or updated")}}' },
|
||||||
{ value: 4, label: '{{t("After record deleted")}}' }
|
{ value: 4, label: '{{t("After record deleted")}}' }
|
||||||
]
|
],
|
||||||
|
placeholder: '{{t("Trigger on")}}'
|
||||||
},
|
},
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
@ -62,6 +63,7 @@ export default {
|
|||||||
'x-component': 'FieldsSelect',
|
'x-component': 'FieldsSelect',
|
||||||
'x-component-props': {
|
'x-component-props': {
|
||||||
mode: 'multiple',
|
mode: 'multiple',
|
||||||
|
placeholder: '{{t("Select Field")}}'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'config.condition': {
|
'config.condition': {
|
||||||
|
@ -17,16 +17,13 @@ import { EXECUTION_STATUS } from './constants';
|
|||||||
async function setCurrent(instance: WorkflowModel, options) {
|
async function setCurrent(instance: WorkflowModel, options) {
|
||||||
const updates: { enabled?: boolean, current?: boolean } = {};
|
const updates: { enabled?: boolean, current?: boolean } = {};
|
||||||
|
|
||||||
if (!instance.changed('enabled')) {
|
if (!instance.changed('enabled') || !instance.enabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (instance.enabled) {
|
|
||||||
instance.set('current', true);
|
instance.set('current', true);
|
||||||
updates.enabled = false;
|
updates.enabled = false;
|
||||||
}
|
|
||||||
|
|
||||||
if (instance.current) {
|
|
||||||
// NOTE: set to `null` but not `false` will not violate the unique index
|
// NOTE: set to `null` but not `false` will not violate the unique index
|
||||||
updates.current = null;
|
updates.current = null;
|
||||||
const previous = await (<typeof WorkflowModel>instance.constructor).findOne({
|
const previous = await (<typeof WorkflowModel>instance.constructor).findOne({
|
||||||
@ -41,7 +38,6 @@ async function setCurrent(instance: WorkflowModel, options) {
|
|||||||
transaction: options.transaction
|
transaction: options.transaction
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class WorkflowPlugin extends Plugin {
|
export default class WorkflowPlugin extends Plugin {
|
||||||
|
@ -33,12 +33,31 @@ describe('workflow > workflow', () => {
|
|||||||
collection: 'posts'
|
collection: 'posts'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
expect(workflow.current).toBe(true);
|
||||||
|
const p1 = await PostRepo.create({ values: { title: 't1' } });
|
||||||
|
const executions1 = await workflow.getExecutions();
|
||||||
|
expect(executions1.length).toBe(1);
|
||||||
|
|
||||||
|
const w = await WorkflowModel.findOne({
|
||||||
|
where: {
|
||||||
|
current: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
expect(w).not.toBeNull();
|
||||||
|
expect(w.current).toBe(true);
|
||||||
|
|
||||||
await workflow.update({ enabled: false });
|
await workflow.update({ enabled: false });
|
||||||
const post = await PostRepo.create({ values: { title: 't1' } });
|
const p2 = await PostRepo.create({ values: { title: 't2' } });
|
||||||
|
|
||||||
const executions = await workflow.getExecutions();
|
const executions2 = await workflow.getExecutions();
|
||||||
expect(executions.length).toBe(0);
|
expect(executions2.length).toBe(1);
|
||||||
|
|
||||||
|
const workflows = await WorkflowModel.findAll({
|
||||||
|
where: {
|
||||||
|
current: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
expect(workflows.length).toBe(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user