mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 08:47:20 +00:00
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 { NAMESPACE } from './locale';
|
||||
|
||||
export default class extends Plugin {
|
||||
export default class PluginWorkflowClient extends Plugin {
|
||||
triggers = new Registry<Trigger>();
|
||||
instructions = new Registry<Instruction>();
|
||||
getTriggersOptions = () => {
|
||||
|
@ -40,7 +40,7 @@ function useUpdateConfigAction() {
|
||||
return;
|
||||
}
|
||||
await form.submit();
|
||||
await api.resource('workflows').update?.({
|
||||
await api.resource('workflows').update({
|
||||
filterByTk: workflow.id,
|
||||
values: {
|
||||
config: form.values,
|
||||
@ -151,23 +151,22 @@ export const TriggerConfig = () => {
|
||||
const compile = useCompile();
|
||||
const trigger = useTrigger();
|
||||
|
||||
const { title, executed } = workflow;
|
||||
const typeTitle = compile(trigger.title);
|
||||
const { fieldset, scope, components } = trigger;
|
||||
const detailText = executed ? '{{t("View")}}' : '{{t("Configure")}}';
|
||||
const detailText = workflow.executed ? '{{t("View")}}' : '{{t("Configure")}}';
|
||||
const titleText = lang('Trigger');
|
||||
|
||||
useEffect(() => {
|
||||
if (workflow) {
|
||||
setEditingTitle(workflow.title ?? typeTitle);
|
||||
setEditingTitle(workflow.triggerTitle ?? workflow.title ?? typeTitle);
|
||||
}
|
||||
}, [workflow]);
|
||||
|
||||
const form = useMemo(() => {
|
||||
const values = cloneDeep(workflow?.config);
|
||||
const values = cloneDeep(workflow.config);
|
||||
return createForm({
|
||||
initialValues: values,
|
||||
disabled: workflow?.executed,
|
||||
disabled: workflow.executed,
|
||||
});
|
||||
}, [workflow]);
|
||||
|
||||
@ -185,13 +184,13 @@ export const TriggerConfig = () => {
|
||||
async function (next) {
|
||||
const t = next || typeTitle;
|
||||
setEditingTitle(t);
|
||||
if (t === title) {
|
||||
if (t === workflow.triggerTitle) {
|
||||
return;
|
||||
}
|
||||
await api.resource('workflows').update?.({
|
||||
await api.resource('workflows').update({
|
||||
filterByTk: workflow.id,
|
||||
values: {
|
||||
title: t,
|
||||
triggerTitle: t,
|
||||
},
|
||||
});
|
||||
refresh();
|
||||
@ -298,7 +297,7 @@ export const TriggerConfig = () => {
|
||||
properties: fieldset,
|
||||
},
|
||||
actions: {
|
||||
...(executed
|
||||
...(workflow.executed
|
||||
? {}
|
||||
: {
|
||||
type: 'void',
|
||||
|
@ -30,7 +30,7 @@ type Pending = [ExecutionModel, JobModel?];
|
||||
|
||||
type CachedEvent = [WorkflowModel, any, { context?: any }];
|
||||
|
||||
export default class WorkflowPlugin extends Plugin {
|
||||
export default class PluginWorkflowServer extends Plugin {
|
||||
instructions: Registry<InstructionInterface> = new Registry();
|
||||
triggers: Registry<Trigger> = 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 { filterByTk, values } = context.action.params;
|
||||
context.action.mergeParams({
|
||||
whitelist: ['title', 'description', 'enabled', 'config', 'options'],
|
||||
whitelist: ['title', 'description', 'enabled', 'triggerTitle', 'config', 'options'],
|
||||
});
|
||||
// only enable/disable
|
||||
if (Object.keys(values).includes('config')) {
|
||||
|
@ -30,7 +30,11 @@ export default function () {
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
type: 'json',
|
||||
type: 'string',
|
||||
name: 'triggerTitle',
|
||||
},
|
||||
{
|
||||
type: 'jsonb',
|
||||
name: 'config',
|
||||
required: true,
|
||||
defaultValue: {},
|
||||
|
Loading…
Reference in New Issue
Block a user