refactor: remove after success
This commit is contained in:
parent
eddb3230c6
commit
e07ee53db7
@ -1,17 +1,10 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import {
|
import { Menu, Plugin, RemoteSchemaTemplateManagerProvider, EditTitleField, useCollection } from '@nocobase/client';
|
||||||
Menu,
|
|
||||||
Plugin,
|
|
||||||
RemoteSchemaTemplateManagerProvider,
|
|
||||||
EditTitleField,
|
|
||||||
SchemaSettingOptions,
|
|
||||||
useCollection,
|
|
||||||
} from '@nocobase/client';
|
|
||||||
import { remove } from 'lodash';
|
import { remove } from 'lodash';
|
||||||
import { useFieldSchema } from '@formily/react';
|
import { useFieldSchema } from '@formily/react';
|
||||||
import { isValid } from '@formily/shared';
|
import { isValid } from '@formily/shared';
|
||||||
import { autorun } from '@formily/reactive';
|
import { autorun } from '@formily/reactive';
|
||||||
import { Locale, lang, tval } from './locale';
|
import { Locale, tval } from './locale';
|
||||||
import {
|
import {
|
||||||
PageModeSetting,
|
PageModeSetting,
|
||||||
EditFormulaTitleField,
|
EditFormulaTitleField,
|
||||||
@ -21,7 +14,6 @@ import {
|
|||||||
EditTitle,
|
EditTitle,
|
||||||
SetFilterScope,
|
SetFilterScope,
|
||||||
useSetFilterScopeVisible,
|
useSetFilterScopeVisible,
|
||||||
AfterSuccess,
|
|
||||||
FilterVariableInput,
|
FilterVariableInput,
|
||||||
EditDefaultValue,
|
EditDefaultValue,
|
||||||
} from './schema-settings';
|
} from './schema-settings';
|
||||||
@ -131,21 +123,13 @@ export class PluginCoreClient extends Plugin {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
this.app.schemaSettingsManager.addItem('actionSettings:submit', '', {
|
this.app.schemaSettingsManager.addItem('actionSettings:submit', 'pageMode', {
|
||||||
Component: PageModeSetting,
|
Component: PageModeSetting,
|
||||||
useVisible() {
|
useVisible() {
|
||||||
const fieldSchema = useFieldSchema();
|
const fieldSchema = useFieldSchema();
|
||||||
return isValid(fieldSchema?.['x-action-settings']?.sessionSubmit);
|
return isValid(fieldSchema?.['x-action-settings']?.pageMode);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const SchemaSettingOptionItems = this.schemaSettingsManager
|
|
||||||
.get('ActionSettings')
|
|
||||||
.items.filter((item) => item.name === 'Customize')[0].children;
|
|
||||||
SchemaSettingOptionItems.forEach((item) => {
|
|
||||||
if (item.name === 'afterSuccess') {
|
|
||||||
(item as SchemaSettingOptions).Component = AfterSuccess;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 预览区块需要提前加进来,没法放在 afterload 中,这块后面需要重构
|
// 预览区块需要提前加进来,没法放在 afterload 中,这块后面需要重构
|
||||||
const previewBlockItem = {
|
const previewBlockItem = {
|
||||||
@ -169,9 +153,7 @@ export class PluginCoreClient extends Plugin {
|
|||||||
|
|
||||||
this.app.addComponents({
|
this.app.addComponents({
|
||||||
AdminLayout,
|
AdminLayout,
|
||||||
AfterSuccess,
|
|
||||||
AssociatedField,
|
AssociatedField,
|
||||||
RemoteSelect,
|
|
||||||
AutoComplete,
|
AutoComplete,
|
||||||
CalcResult,
|
CalcResult,
|
||||||
CreateSubmitActionInitializer,
|
CreateSubmitActionInitializer,
|
||||||
@ -202,13 +184,14 @@ export class PluginCoreClient extends Plugin {
|
|||||||
PDFViewerProvider,
|
PDFViewerProvider,
|
||||||
PDFViwer: InternalPDFViewer,
|
PDFViwer: InternalPDFViewer,
|
||||||
PageLayout,
|
PageLayout,
|
||||||
|
RemoteSelect,
|
||||||
Select,
|
Select,
|
||||||
SettingBlock: SettingBlockInitializer,
|
SettingBlock: SettingBlockInitializer,
|
||||||
SignatureInput,
|
|
||||||
SheetBlock,
|
SheetBlock,
|
||||||
SheetBlockInitializer,
|
SheetBlockInitializer,
|
||||||
SheetBlockProvider,
|
SheetBlockProvider,
|
||||||
SheetBlockToolbar,
|
SheetBlockToolbar,
|
||||||
|
SignatureInput,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,13 +283,13 @@ export class PluginCoreClient extends Plugin {
|
|||||||
|
|
||||||
async afterLoad() {
|
async afterLoad() {
|
||||||
// log for debug
|
// log for debug
|
||||||
|
await this.registerSchemaInitializer();
|
||||||
if (process.env.NODE_ENV !== 'production') {
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
console.info('current components', this.app.components);
|
console.info('current components', this.app.components);
|
||||||
console.info('current schemaSettings', this.app.schemaSettingsManager.getAll());
|
console.info('current schemaSettings', this.app.schemaSettingsManager.getAll());
|
||||||
console.info('current schemaInitializer', this.app.schemaInitializerManager.getAll());
|
console.info('current schemaInitializer', this.app.schemaInitializerManager.getAll());
|
||||||
console.info('current providers', this.app.providers);
|
console.info('current providers', this.app.providers);
|
||||||
}
|
}
|
||||||
await this.registerSchemaInitializer();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async load() {
|
async load() {
|
||||||
|
@ -15,7 +15,7 @@ export const CreateSubmitActionInitializer: React.FC = (props) => {
|
|||||||
'x-action-settings': {
|
'x-action-settings': {
|
||||||
assignedValues: {},
|
assignedValues: {},
|
||||||
triggerWorkflows: [],
|
triggerWorkflows: [],
|
||||||
sessionSubmit: false,
|
pageMode: false,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
return <ActionInitializer {...props} schema={schema} />;
|
return <ActionInitializer {...props} schema={schema} />;
|
||||||
|
@ -102,7 +102,7 @@ export const useCreateActionProps = () => {
|
|||||||
overwriteValues,
|
overwriteValues,
|
||||||
skipValidator,
|
skipValidator,
|
||||||
triggerWorkflows,
|
triggerWorkflows,
|
||||||
sessionSubmit,
|
pageMode,
|
||||||
} = actionSchema?.['x-action-settings'] ?? {};
|
} = actionSchema?.['x-action-settings'] ?? {};
|
||||||
const addChild = fieldSchema?.['x-component-props']?.addChild;
|
const addChild = fieldSchema?.['x-component-props']?.addChild;
|
||||||
const assignedValues = {};
|
const assignedValues = {};
|
||||||
@ -165,7 +165,7 @@ export const useCreateActionProps = () => {
|
|||||||
actionField.data.data = data;
|
actionField.data.data = data;
|
||||||
__parent?.service?.refresh?.();
|
__parent?.service?.refresh?.();
|
||||||
if (!onSuccess?.successMessage) {
|
if (!onSuccess?.successMessage) {
|
||||||
if (sessionSubmit) {
|
if (pageMode) {
|
||||||
message.success(t('Saved successfully'));
|
message.success(t('Saved successfully'));
|
||||||
if (dn.designable) {
|
if (dn.designable) {
|
||||||
insert(viewerSchema);
|
insert(viewerSchema);
|
||||||
|
@ -469,88 +469,6 @@ export const SetFilterScope = (props) => {
|
|||||||
return <SchemaSettingsModalItem title={t('Custom filter')} width={770} schema={schema} onSubmit={onSubmit} />;
|
return <SchemaSettingsModalItem title={t('Custom filter')} width={770} schema={schema} onSubmit={onSubmit} />;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function AfterSuccess() {
|
|
||||||
const { dn } = useDesignable();
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const fieldSchema = useFieldSchema();
|
|
||||||
const component = fieldSchema.parent.parent['x-component'];
|
|
||||||
const schema = {
|
|
||||||
type: 'object',
|
|
||||||
title: t('After successful submission'),
|
|
||||||
properties: {
|
|
||||||
successMessage: {
|
|
||||||
title: t('Popup message'),
|
|
||||||
'x-decorator': 'FormItem',
|
|
||||||
'x-component': 'Input.TextArea',
|
|
||||||
'x-component-props': {},
|
|
||||||
},
|
|
||||||
dataClear: {
|
|
||||||
title: t('Clear data method'),
|
|
||||||
enum: [
|
|
||||||
{ label: t('Automatic clear'), value: false },
|
|
||||||
{ label: t('Manually clear'), value: true },
|
|
||||||
],
|
|
||||||
'x-decorator': 'FormItem',
|
|
||||||
'x-component': 'Radio.Group',
|
|
||||||
'x-component-props': {},
|
|
||||||
},
|
|
||||||
manualClose: {
|
|
||||||
title: t('Popup close method'),
|
|
||||||
enum: [
|
|
||||||
{ label: t('Automatic close'), value: false },
|
|
||||||
{ label: t('Manually close'), value: true },
|
|
||||||
],
|
|
||||||
'x-decorator': 'FormItem',
|
|
||||||
'x-component': 'Radio.Group',
|
|
||||||
'x-component-props': {},
|
|
||||||
},
|
|
||||||
redirecting: {
|
|
||||||
title: t('Then'),
|
|
||||||
enum: [
|
|
||||||
{ label: t('Stay on current page'), value: false },
|
|
||||||
{ label: t('Redirect to'), value: true },
|
|
||||||
],
|
|
||||||
'x-decorator': 'FormItem',
|
|
||||||
'x-component': 'Radio.Group',
|
|
||||||
'x-component-props': {},
|
|
||||||
'x-reactions': {
|
|
||||||
target: 'redirectTo',
|
|
||||||
fulfill: {
|
|
||||||
state: {
|
|
||||||
visible: '{{!!$self.value}}',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
redirectTo: {
|
|
||||||
title: t('Link'),
|
|
||||||
'x-decorator': 'FormItem',
|
|
||||||
'x-component': 'Input',
|
|
||||||
'x-component-props': {},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
if (!(component as string).includes('Form')) {
|
|
||||||
delete schema.properties.dataClear;
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<SchemaSettingsModalItem
|
|
||||||
title={t('After successful submission')}
|
|
||||||
initialValues={fieldSchema?.['x-action-settings']?.['onSuccess']}
|
|
||||||
schema={{ ...schema } as ISchema}
|
|
||||||
onSubmit={(onSuccess) => {
|
|
||||||
fieldSchema['x-action-settings']['onSuccess'] = onSuccess;
|
|
||||||
dn.emit('patch', {
|
|
||||||
schema: {
|
|
||||||
['x-uid']: fieldSchema['x-uid'],
|
|
||||||
'x-action-settings': fieldSchema['x-action-settings'],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 添加跳转页面选项
|
// 添加跳转页面选项
|
||||||
export const PageModeSetting = () => {
|
export const PageModeSetting = () => {
|
||||||
const { dn } = useDesignable();
|
const { dn } = useDesignable();
|
||||||
@ -559,9 +477,9 @@ export const PageModeSetting = () => {
|
|||||||
return (
|
return (
|
||||||
<SchemaSettingsSwitchItem
|
<SchemaSettingsSwitchItem
|
||||||
title={t('Navigate to new page')}
|
title={t('Navigate to new page')}
|
||||||
checked={!!fieldSchema?.['x-action-settings']?.sessionSubmit}
|
checked={!!fieldSchema?.['x-action-settings']?.pageMode}
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
fieldSchema['x-action-settings'].sessionSubmit = value;
|
fieldSchema['x-action-settings'].pageMode = value;
|
||||||
dn.emit('patch', {
|
dn.emit('patch', {
|
||||||
schema: {
|
schema: {
|
||||||
['x-uid']: fieldSchema['x-uid'],
|
['x-uid']: fieldSchema['x-uid'],
|
||||||
|
Loading…
Reference in New Issue
Block a user