refactor(plugin-workflow): add trigger title for workflow which is different with title (#3333)
This commit is contained in:
parent
5ff7f686b1
commit
05078faf1a
@ -0,0 +1,47 @@
|
|||||||
|
import React, { useCallback, useMemo, useState } from 'react';
|
||||||
|
import { cloneDeep } from 'lodash';
|
||||||
|
import { createForm } from '@formily/core';
|
||||||
|
import { useForm } from '@formily/react';
|
||||||
|
|
||||||
|
import { ActionContextProvider, FormProvider } from '@nocobase/client';
|
||||||
|
|
||||||
|
export function useFormProviderProps() {
|
||||||
|
return { form: useForm() };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function DrawerFormProvider(props) {
|
||||||
|
const { values, disabled, visible, setVisible } = props;
|
||||||
|
const [formValueChanged, setFormValueChanged] = useState(false);
|
||||||
|
|
||||||
|
const form = useMemo(() => {
|
||||||
|
const v = cloneDeep(values);
|
||||||
|
return createForm({
|
||||||
|
values: v,
|
||||||
|
initialValues: v,
|
||||||
|
disabled: disabled,
|
||||||
|
});
|
||||||
|
}, [disabled, values]);
|
||||||
|
|
||||||
|
const resetForm = useCallback(
|
||||||
|
(editing) => {
|
||||||
|
setVisible(editing);
|
||||||
|
if (!editing) {
|
||||||
|
form.reset();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[form],
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ActionContextProvider
|
||||||
|
value={{
|
||||||
|
visible,
|
||||||
|
setVisible: resetForm,
|
||||||
|
formValueChanged,
|
||||||
|
setFormValueChanged,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<FormProvider form={form}>{props.children}</FormProvider>
|
||||||
|
</ActionContextProvider>
|
||||||
|
);
|
||||||
|
}
|
@ -33,7 +33,7 @@ import { useTriggerWorkflowsActionProps } from './hooks/useTriggerWorkflowAction
|
|||||||
import { getWorkflowDetailPath, getWorkflowExecutionsPath } from './constant';
|
import { getWorkflowDetailPath, getWorkflowExecutionsPath } from './constant';
|
||||||
import { NAMESPACE } from './locale';
|
import { NAMESPACE } from './locale';
|
||||||
|
|
||||||
export default class extends Plugin {
|
export default class PluginWorkflowClient extends Plugin {
|
||||||
triggers = new Registry<Trigger>();
|
triggers = new Registry<Trigger>();
|
||||||
instructions = new Registry<Instruction>();
|
instructions = new Registry<Instruction>();
|
||||||
getTriggersOptions = () => {
|
getTriggersOptions = () => {
|
||||||
|
@ -40,7 +40,7 @@ function useUpdateConfigAction() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await form.submit();
|
await form.submit();
|
||||||
await api.resource('workflows').update?.({
|
await api.resource('workflows').update({
|
||||||
filterByTk: workflow.id,
|
filterByTk: workflow.id,
|
||||||
values: {
|
values: {
|
||||||
config: form.values,
|
config: form.values,
|
||||||
@ -151,23 +151,22 @@ export const TriggerConfig = () => {
|
|||||||
const compile = useCompile();
|
const compile = useCompile();
|
||||||
const trigger = useTrigger();
|
const trigger = useTrigger();
|
||||||
|
|
||||||
const { title, executed } = workflow;
|
|
||||||
const typeTitle = compile(trigger.title);
|
const typeTitle = compile(trigger.title);
|
||||||
const { fieldset, scope, components } = trigger;
|
const { fieldset, scope, components } = trigger;
|
||||||
const detailText = executed ? '{{t("View")}}' : '{{t("Configure")}}';
|
const detailText = workflow.executed ? '{{t("View")}}' : '{{t("Configure")}}';
|
||||||
const titleText = lang('Trigger');
|
const titleText = lang('Trigger');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (workflow) {
|
if (workflow) {
|
||||||
setEditingTitle(workflow.title ?? typeTitle);
|
setEditingTitle(workflow.triggerTitle ?? workflow.title ?? typeTitle);
|
||||||
}
|
}
|
||||||
}, [workflow]);
|
}, [workflow]);
|
||||||
|
|
||||||
const form = useMemo(() => {
|
const form = useMemo(() => {
|
||||||
const values = cloneDeep(workflow?.config);
|
const values = cloneDeep(workflow.config);
|
||||||
return createForm({
|
return createForm({
|
||||||
initialValues: values,
|
initialValues: values,
|
||||||
disabled: workflow?.executed,
|
disabled: workflow.executed,
|
||||||
});
|
});
|
||||||
}, [workflow]);
|
}, [workflow]);
|
||||||
|
|
||||||
@ -185,13 +184,13 @@ export const TriggerConfig = () => {
|
|||||||
async function (next) {
|
async function (next) {
|
||||||
const t = next || typeTitle;
|
const t = next || typeTitle;
|
||||||
setEditingTitle(t);
|
setEditingTitle(t);
|
||||||
if (t === title) {
|
if (t === workflow.triggerTitle) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await api.resource('workflows').update?.({
|
await api.resource('workflows').update({
|
||||||
filterByTk: workflow.id,
|
filterByTk: workflow.id,
|
||||||
values: {
|
values: {
|
||||||
title: t,
|
triggerTitle: t,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
refresh();
|
refresh();
|
||||||
@ -298,7 +297,7 @@ export const TriggerConfig = () => {
|
|||||||
properties: fieldset,
|
properties: fieldset,
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
...(executed
|
...(workflow.executed
|
||||||
? {}
|
? {}
|
||||||
: {
|
: {
|
||||||
type: 'void',
|
type: 'void',
|
||||||
|
@ -30,7 +30,7 @@ type Pending = [ExecutionModel, JobModel?];
|
|||||||
|
|
||||||
type CachedEvent = [WorkflowModel, any, { context?: any }];
|
type CachedEvent = [WorkflowModel, any, { context?: any }];
|
||||||
|
|
||||||
export default class WorkflowPlugin extends Plugin {
|
export default class PluginWorkflowServer extends Plugin {
|
||||||
instructions: Registry<InstructionInterface> = new Registry();
|
instructions: Registry<InstructionInterface> = new Registry();
|
||||||
triggers: Registry<Trigger> = new Registry();
|
triggers: Registry<Trigger> = new Registry();
|
||||||
functions: Registry<CustomFunction> = new Registry();
|
functions: Registry<CustomFunction> = new Registry();
|
||||||
|
@ -7,7 +7,7 @@ export async function update(context: Context, next) {
|
|||||||
const repository = utils.getRepositoryFromParams(context) as Repository;
|
const repository = utils.getRepositoryFromParams(context) as Repository;
|
||||||
const { filterByTk, values } = context.action.params;
|
const { filterByTk, values } = context.action.params;
|
||||||
context.action.mergeParams({
|
context.action.mergeParams({
|
||||||
whitelist: ['title', 'description', 'enabled', 'config', 'options'],
|
whitelist: ['title', 'description', 'enabled', 'triggerTitle', 'config', 'options'],
|
||||||
});
|
});
|
||||||
// only enable/disable
|
// only enable/disable
|
||||||
if (Object.keys(values).includes('config')) {
|
if (Object.keys(values).includes('config')) {
|
||||||
|
@ -30,7 +30,11 @@ export default function () {
|
|||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'json',
|
type: 'string',
|
||||||
|
name: 'triggerTitle',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'jsonb',
|
||||||
name: 'config',
|
name: 'config',
|
||||||
required: true,
|
required: true,
|
||||||
defaultValue: {},
|
defaultValue: {},
|
||||||
|
Loading…
Reference in New Issue
Block a user