mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 13:39:24 +08:00
* fix: bug * test: kanban test * test: gantt block test * test: gantt test * test: gantt test * test: gantt test * refactor: convert parameters to destructured object * test: add tests choices * test: add tests media * test: add tests for datetime in creating form * feat(plugin-mock-collection): generate faker time * test: add tests for datetime in editing form * test: add tests for datetime in details form * test: gantt block test * test: gantt test * test: gantt test * test: gantt test * fix: bug * feat: improve code * test: add tests for relation fields * refactor: style improve * fix: rename SchemaSettings * fix: type bug * refactor: useDesinger() * fix: bug * fix: bug * fix: build tip * refactor: kanban setting * refactor: gantt setting * refactor: bulk update setting * refactor: bulk update setting * refactor: bulk edit settings * refactor: duplicate settings * refactor: print action setting * refactor: duplicate settings * refactor: bulk update refactor * refactor: bulk update refactor * fix: designableState * fix: bug * fix: designable * refactor: bulk update * fix: designable * test: add tests for relation fields * test: add tests for relation fields * test: add tests for relation fields * feat: client api doc * test: add tests for relation fields * test: avoid errors * test: make tests passing * fix: bug * test: gantt test * test: make tests passing * test: add tests for advanced fields * test: increase e2e timeout-minutes to 60 * fix: bug * fix: improve code * feat: add schema initailizer component demos * test: make tests passing * fix: schema settings demos * feat: shallowMerge & deepMerge * test: reduce number of tests * test: make tests passing * feat: updates * fix: add Initializer Internal * demos: useSchemaSettingsRender * test: make tests passing * test: make tests passing * test: bulk update test * refactor: useSchemaToolbar * fix: improve docs * fix: bug * test: duplicate action test * test: duplicate action test * test: duplicate action test * test: duplicate action test * chore: upgrade dumi theme * test: make tests passing * test: add tests for linkage rules * test: add test for form data templates * test: add tests for default value * test: reduce number of tests * refactor: bulk edit setting * test: bulk edit action test * test: bulk edit action test * fix: dn.deepMerge * fix: bug * test: bulk edit action test * test: kanban test * refactor: bulk update version * refactor: print action version * fix: bug * fix: toolbar * fix: docs ssr * test: add tests for system fields * test: add tests for actions * fix: bug * test: add tests for lazy loading of variables * test: make testing more stable * test: bulk edit test * test: bulk update action test * fix: update docs * test: print test * test: kanban test * test: kanban test * refactor: duplicate version * fix: merge bug * refactor: bulk update * fix: merge bug * refactor: bulk edit * refactor: import * refactor: export action * refactor: code improve * refactor: kanban code improve * fix: merge bug * refactor: readPrettyFormActionInitializers * test: print action test * test: print action test * refactor: print action * test: action test * refactor: gantt date change * style: gantt style improve * test: gantt &bulkUpdate test * test: bulk update test * test: duplicate action test * test: print action test * test: bulk edit action test * test: gantt block test * test: kanban block test * test: test file name * test: test file name * test: bulk update action tst * refactor: rename test file name * refactor: bulk update action * refactor: gantt test * fix: block template * fix: block template * fix: useFieldModeOptions * refactor: code improve * fix: merge bug --------- Co-authored-by: dream2023 <1098626505@qq.com> Co-authored-by: Rain <958414905@qq.com> Co-authored-by: chenos <chenlinxh@gmail.com>
238 lines
7.0 KiB
TypeScript
238 lines
7.0 KiB
TypeScript
import React, { useCallback, useState, useEffect } from 'react';
|
|
import {
|
|
SchemaSettings,
|
|
ActionDesigner,
|
|
useSchemaToolbar,
|
|
useDesignable,
|
|
useCompile,
|
|
DefaultValueProvider,
|
|
SchemaSettingsItemGroup,
|
|
SchemaSettingsModalItem,
|
|
SchemaSettingsActionModalItem,
|
|
SchemaSettingsSelectItem,
|
|
FlagProvider,
|
|
} from '@nocobase/client';
|
|
import { isValid, uid } from '@formily/shared';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { useField, useFieldSchema, ISchema } from '@formily/react';
|
|
|
|
const MenuGroup = (props) => {
|
|
const fieldSchema = useFieldSchema();
|
|
const { t } = useTranslation();
|
|
const compile = useCompile();
|
|
const actionTitle = fieldSchema.title ? compile(fieldSchema.title) : '';
|
|
|
|
return (
|
|
<SchemaSettingsItemGroup title={`${t('Customize')} > ${actionTitle}`}>{props.children}</SchemaSettingsItemGroup>
|
|
);
|
|
};
|
|
|
|
function UpdateMode() {
|
|
const { dn } = useDesignable();
|
|
const { t } = useTranslation();
|
|
const fieldSchema = useFieldSchema();
|
|
|
|
return (
|
|
<SchemaSettingsSelectItem
|
|
title={t('Data will be updated')}
|
|
options={[
|
|
{ label: t('Selected'), value: 'selected' },
|
|
{ label: t('All'), value: 'all' },
|
|
]}
|
|
value={fieldSchema?.['x-action-settings']?.['updateMode']}
|
|
onChange={(value) => {
|
|
fieldSchema['x-action-settings']['updateMode'] = value;
|
|
dn.emit('patch', {
|
|
schema: {
|
|
'x-uid': fieldSchema['x-uid'],
|
|
'x-action-settings': fieldSchema['x-action-settings'],
|
|
},
|
|
});
|
|
dn.refresh();
|
|
}}
|
|
/>
|
|
);
|
|
}
|
|
|
|
function AfterSuccess() {
|
|
const { dn } = useDesignable();
|
|
const { t } = useTranslation();
|
|
const fieldSchema = useFieldSchema();
|
|
return (
|
|
<SchemaSettingsModalItem
|
|
title={t('After successful submission')}
|
|
initialValues={fieldSchema?.['x-action-settings']?.['onSuccess']}
|
|
schema={
|
|
{
|
|
type: 'object',
|
|
title: t('After successful submission'),
|
|
properties: {
|
|
successMessage: {
|
|
title: t('Popup message'),
|
|
'x-decorator': 'FormItem',
|
|
'x-component': 'Input.TextArea',
|
|
'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': {},
|
|
},
|
|
},
|
|
} 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'],
|
|
},
|
|
});
|
|
}}
|
|
/>
|
|
);
|
|
}
|
|
function AssignedFieldValues() {
|
|
const { dn } = useDesignable();
|
|
const { t } = useTranslation();
|
|
const fieldSchema = useFieldSchema();
|
|
const field = useField();
|
|
const [initialSchema, setInitialSchema] = useState<ISchema>();
|
|
useEffect(() => {
|
|
const schemaUid = uid();
|
|
const schema: ISchema = {
|
|
type: 'void',
|
|
'x-uid': schemaUid,
|
|
'x-component': 'Grid',
|
|
'x-initializer': 'CustomFormItemInitializers',
|
|
};
|
|
setInitialSchema(schema);
|
|
}, [field.address]);
|
|
|
|
const tips = {
|
|
'customize:update': t(
|
|
'After clicking the custom button, the following fields of the current record will be saved according to the following form.',
|
|
),
|
|
'customize:save': t(
|
|
'After clicking the custom button, the following fields of the current record will be saved according to the following form.',
|
|
),
|
|
};
|
|
const actionType = fieldSchema['x-action'] ?? '';
|
|
const onSubmit = useCallback(
|
|
(assignedValues) => {
|
|
fieldSchema['x-action-settings']['assignedValues'] = assignedValues;
|
|
dn.emit('patch', {
|
|
schema: {
|
|
['x-uid']: fieldSchema['x-uid'],
|
|
'x-action-settings': fieldSchema['x-action-settings'],
|
|
},
|
|
});
|
|
},
|
|
[dn, fieldSchema],
|
|
);
|
|
|
|
return (
|
|
<FlagProvider isInAssignFieldValues={true}>
|
|
<DefaultValueProvider isAllowToSetDefaultValue={() => false}>
|
|
<SchemaSettingsActionModalItem
|
|
title={t('Assign field values')}
|
|
maskClosable={false}
|
|
initialSchema={initialSchema}
|
|
initialValues={fieldSchema?.['x-action-settings']?.assignedValues}
|
|
modalTip={tips[actionType]}
|
|
uid={fieldSchema?.['x-action-settings']?.schemaUid}
|
|
onSubmit={onSubmit}
|
|
/>
|
|
</DefaultValueProvider>
|
|
</FlagProvider>
|
|
);
|
|
}
|
|
|
|
const bulkUpdateActionSettings = new SchemaSettings({
|
|
name: 'ActionSettings:customize:bulkUpdate',
|
|
items: [
|
|
{
|
|
name: 'Customize',
|
|
Component: MenuGroup,
|
|
children: [
|
|
{
|
|
name: 'editButton',
|
|
Component: ActionDesigner.ButtonEditor,
|
|
useComponentProps() {
|
|
const { buttonEditorProps } = useSchemaToolbar();
|
|
return buttonEditorProps;
|
|
},
|
|
},
|
|
{
|
|
name: 'updateMode',
|
|
Component: UpdateMode,
|
|
useVisible() {
|
|
const fieldSchema = useFieldSchema();
|
|
const isUpdateModePopupAction = ['customize:bulkUpdate', 'customize:bulkEdit'].includes(
|
|
fieldSchema['x-action'],
|
|
);
|
|
return isUpdateModePopupAction;
|
|
},
|
|
},
|
|
{
|
|
name: 'assignFieldValues',
|
|
Component: AssignedFieldValues,
|
|
useVisible() {
|
|
const fieldSchema = useFieldSchema();
|
|
return isValid(fieldSchema?.['x-action-settings']?.assignedValues);
|
|
},
|
|
},
|
|
{
|
|
name: 'afterSuccess',
|
|
Component: AfterSuccess,
|
|
useVisible() {
|
|
const fieldSchema = useFieldSchema();
|
|
return isValid(fieldSchema?.['x-action-settings']?.onSuccess);
|
|
},
|
|
},
|
|
{
|
|
name: 'remove',
|
|
sort: 100,
|
|
Component: ActionDesigner.RemoveButton as any,
|
|
useComponentProps() {
|
|
const { removeButtonProps } = useSchemaToolbar();
|
|
return removeButtonProps;
|
|
},
|
|
},
|
|
],
|
|
},
|
|
],
|
|
});
|
|
|
|
export { bulkUpdateActionSettings };
|