feat: 更新提交数据,支持增量提交
This commit is contained in:
parent
c9bbe51500
commit
64387242a6
@ -6,7 +6,7 @@ import { App, message } from 'antd';
|
||||
import _ from 'lodash';
|
||||
import get from 'lodash/get';
|
||||
import omit from 'lodash/omit';
|
||||
import { ChangeEvent, useCallback, useContext, useEffect } from 'react';
|
||||
import { ChangeEvent, useCallback, useContext, useEffect, useMemo } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useReactToPrint } from 'react-to-print';
|
||||
@ -826,6 +826,7 @@ export const useUpdateActionProps = () => {
|
||||
overwriteValues,
|
||||
skipValidator,
|
||||
triggerWorkflows,
|
||||
isDeltaChanged,
|
||||
} = actionSchema?.['x-action-settings'] ?? {};
|
||||
|
||||
const assignedValues = {};
|
||||
@ -854,6 +855,7 @@ export const useUpdateActionProps = () => {
|
||||
await form.submit();
|
||||
}
|
||||
const fieldNames = fields.map((field) => field.name);
|
||||
const actionFields = getActiveFieldsName?.('form') || [];
|
||||
const values = getFormValues({
|
||||
filterByTk,
|
||||
field,
|
||||
@ -861,18 +863,33 @@ export const useUpdateActionProps = () => {
|
||||
fieldNames,
|
||||
getField,
|
||||
resource,
|
||||
actionFields: getActiveFieldsName?.('form') || [],
|
||||
actionFields,
|
||||
});
|
||||
actionField.data = field.data || {};
|
||||
actionField.data.loading = true;
|
||||
try {
|
||||
await resource.update({
|
||||
filterByTk,
|
||||
values: {
|
||||
|
||||
const rawValues = {
|
||||
...values,
|
||||
...overwriteValues,
|
||||
...assignedValues,
|
||||
},
|
||||
};
|
||||
|
||||
const filterValues = (srcValues) =>
|
||||
Object.entries(srcValues).reduce((obj, keyValuePair) => {
|
||||
const [key, value] = keyValuePair;
|
||||
if (actionFields.includes(key)) {
|
||||
obj = {
|
||||
...obj,
|
||||
[key]: value,
|
||||
};
|
||||
}
|
||||
return obj;
|
||||
}, {});
|
||||
|
||||
try {
|
||||
await resource.update({
|
||||
filterByTk,
|
||||
values: isDeltaChanged ? filterValues(rawValues) : rawValues,
|
||||
...data,
|
||||
updateAssociationValues,
|
||||
// TODO(refactor): should change to inject by plugin
|
||||
|
@ -22,6 +22,7 @@ export const UpdateSubmitActionInitializer = (props) => {
|
||||
redirecting: false,
|
||||
successMessage: '{{t("Updated successfully")}}',
|
||||
},
|
||||
isDeltaChanged: false,
|
||||
},
|
||||
};
|
||||
return <ActionInitializer {...props} schema={schema} />;
|
||||
|
@ -71,6 +71,7 @@ import {
|
||||
useCustomPresets,
|
||||
useCustomPresets1,
|
||||
} from './schema-settings/SchemaSettingsDatePresets';
|
||||
import { SchemaSettingsSubmitDataType } from './schema-settings/SchemaSettingsSubmitDataType';
|
||||
export { usePDFViewerRef } from './schema-initializer';
|
||||
export * from './components/custom-components/custom-components';
|
||||
|
||||
@ -102,6 +103,10 @@ export class PluginCoreClient extends Plugin {
|
||||
Component: SchemaSettingsDatePresets,
|
||||
});
|
||||
|
||||
this.schemaSettingsManager.addItem('actionSettings:updateSubmit', 'submitDataType', {
|
||||
Component: SchemaSettingsSubmitDataType,
|
||||
});
|
||||
|
||||
this.schemaSettingsManager.addItem('FormItemSettings', 'hera-divider', {
|
||||
type: 'divider',
|
||||
useVisible() {
|
||||
|
@ -0,0 +1,30 @@
|
||||
import React from 'react';
|
||||
import { useFieldSchema } from '@nocobase/schema';
|
||||
import { SchemaSettingsSwitchItem, useDesignable } from '@nocobase/client';
|
||||
import { useTranslation } from '../locale';
|
||||
|
||||
// 选择提交数据方式,是否增量提交,默认全量提交
|
||||
export const SchemaSettingsSubmitDataType = () => {
|
||||
const { dn } = useDesignable();
|
||||
const { t } = useTranslation();
|
||||
const fieldSchema = useFieldSchema();
|
||||
return (
|
||||
<SchemaSettingsSwitchItem
|
||||
title={t('Select submit data type')}
|
||||
checked={!!fieldSchema?.['x-action-settings']?.isDeltaChanged}
|
||||
onChange={(value) => {
|
||||
fieldSchema['x-action-settings'].isDeltaChanged = value;
|
||||
dn.emit('patch', {
|
||||
schema: {
|
||||
['x-uid']: fieldSchema['x-uid'],
|
||||
'x-action-settings': {
|
||||
...fieldSchema['x-action-settings'],
|
||||
},
|
||||
},
|
||||
});
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
SchemaSettingsSubmitDataType.displayName = 'SchemaSettingsSubmitDataType';
|
@ -27,5 +27,6 @@
|
||||
"loading...": "loading...",
|
||||
"preview block": "preview block",
|
||||
"tabs": "tabs",
|
||||
"year": "year"
|
||||
"year": "year",
|
||||
"Select submit data type": "Select submit data type"
|
||||
}
|
||||
|
@ -27,5 +27,6 @@
|
||||
"loading...": "加载中...",
|
||||
"preview block": "预览区块",
|
||||
"tabs": "多标签",
|
||||
"year": "年"
|
||||
"year": "年",
|
||||
"Select submit data type": "增量提交"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user