Merge pull request 'feat: 更新提交数据,支持增量提交' (#622) from feat/submit-edit-field-only into dev

Reviewed-on: daoyoucloud/tachycode#622
This commit is contained in:
sealday 2024-04-08 12:14:59 +08:00
commit cdb6247a99
6 changed files with 64 additions and 9 deletions

View File

@ -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;
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: {
...values,
...overwriteValues,
...assignedValues,
},
values: isDeltaChanged ? filterValues(rawValues) : rawValues,
...data,
updateAssociationValues,
// TODO(refactor): should change to inject by plugin

View File

@ -22,6 +22,7 @@ export const UpdateSubmitActionInitializer = (props) => {
redirecting: false,
successMessage: '{{t("Updated successfully")}}',
},
isDeltaChanged: false,
},
};
return <ActionInitializer {...props} schema={schema} />;

View File

@ -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() {

View File

@ -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';

View File

@ -27,5 +27,6 @@
"loading...": "loading...",
"preview block": "preview block",
"tabs": "tabs",
"year": "year"
"year": "year",
"Select submit data type": "Select submit data type"
}

View File

@ -27,5 +27,6 @@
"loading...": "加载中...",
"preview block": "预览区块",
"tabs": "多标签",
"year": "年"
"year": "年",
"Select submit data type": "增量提交"
}