mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-01 18:52:20 +08:00
refactor(plugin-workflow): refactor validate context api (#6082)
This commit is contained in:
parent
18fec90aa8
commit
85b36da746
@ -233,16 +233,16 @@ export default class extends Trigger {
|
||||
);
|
||||
}
|
||||
|
||||
validateConfig(values) {
|
||||
validateContext(values) {
|
||||
if (!values.data) {
|
||||
return {
|
||||
data: 'Data property is required',
|
||||
data: 'Data is required',
|
||||
};
|
||||
}
|
||||
|
||||
if (!values.userId) {
|
||||
return {
|
||||
userId: 'UserId property is required',
|
||||
userId: 'UserId is required',
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -96,9 +96,9 @@ function useExecuteConfirmAction() {
|
||||
const ctx = useActionContext();
|
||||
const navigate = useNavigateNoUpdate();
|
||||
const { message: messageApi } = App.useApp();
|
||||
const { autoRevision, ...values } = form.values;
|
||||
return {
|
||||
async run() {
|
||||
const { autoRevision, ...values } = form.values;
|
||||
// Not executed, could choose to create new version (by default)
|
||||
// Executed, stay in current version, and refresh
|
||||
await form.submit();
|
||||
|
@ -83,7 +83,14 @@ export const ScheduleModes = {
|
||||
nullable: false,
|
||||
changeOnSelect: true,
|
||||
render(props) {
|
||||
return <DatePicker showTime placeholder={lang('Current time')} {...props} value={dayjs(props.value)} />;
|
||||
return (
|
||||
<DatePicker
|
||||
showTime
|
||||
placeholder={lang('Current time')}
|
||||
{...props}
|
||||
value={dayjs(props.value || new Date())}
|
||||
/>
|
||||
);
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -236,10 +236,10 @@ export default class CollectionTrigger extends Trigger {
|
||||
});
|
||||
}
|
||||
|
||||
validateConfig(values) {
|
||||
validateContext(values) {
|
||||
if (!values.data) {
|
||||
return {
|
||||
data: 'Data property is required',
|
||||
data: 'Data is required',
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -437,4 +437,13 @@ export default class DateFieldScheduleTrigger {
|
||||
|
||||
return this.workflow.trigger(workflow, { ...values, data, date: values?.date ?? new Date() }, options);
|
||||
}
|
||||
|
||||
validateContext(values) {
|
||||
if (!values?.data) {
|
||||
return {
|
||||
data: 'Data is required',
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -7,8 +7,6 @@
|
||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||
*/
|
||||
|
||||
import { Context } from '@nocobase/actions';
|
||||
import { parseCollectionName } from '@nocobase/data-source-manager';
|
||||
import Trigger from '..';
|
||||
import type Plugin from '../../Plugin';
|
||||
import DateFieldScheduleTrigger from './DateFieldScheduleTrigger';
|
||||
@ -69,25 +67,19 @@ export default class ScheduleTrigger extends Trigger {
|
||||
// return !existed.length;
|
||||
// }
|
||||
|
||||
validateConfig(values) {
|
||||
if (!values.mode) {
|
||||
validateContext(values) {
|
||||
if (!values?.mode) {
|
||||
return {
|
||||
mode: 'Mode property is required',
|
||||
mode: 'Mode is required',
|
||||
};
|
||||
}
|
||||
const trigger = this.getTrigger(values.mode);
|
||||
if (!trigger) {
|
||||
return {
|
||||
mode: 'Mode in invalid',
|
||||
};
|
||||
}
|
||||
|
||||
if (!values.startsOn) {
|
||||
return {
|
||||
startsOn: 'StartsOn property is required',
|
||||
};
|
||||
}
|
||||
|
||||
if (values.mode === SCHEDULE_MODE.DATE_FIELD && !values.collection) {
|
||||
return {
|
||||
collection: 'Collection property is required',
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
return trigger.validateContext?.(values);
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ export abstract class Trigger {
|
||||
return true;
|
||||
}
|
||||
duplicateConfig?(workflow: WorkflowModel, options: Transactionable): object | Promise<object>;
|
||||
validateConfig?(values: any): null | void | { [key: string]: string };
|
||||
validateContext?(values: any): null | void | { [key: string]: string };
|
||||
sync?: boolean;
|
||||
execute?(
|
||||
workflow: WorkflowModel,
|
||||
|
Loading…
x
Reference in New Issue
Block a user