Merge pull request 'feat: 更新提交数据,支持增量提交' (#622) from feat/submit-edit-field-only into dev
Reviewed-on: daoyoucloud/tachycode#622
This commit is contained in:
commit
cdb6247a99
@ -6,7 +6,7 @@ import { App, message } from 'antd';
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import get from 'lodash/get';
|
import get from 'lodash/get';
|
||||||
import omit from 'lodash/omit';
|
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 { useTranslation } from 'react-i18next';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { useReactToPrint } from 'react-to-print';
|
import { useReactToPrint } from 'react-to-print';
|
||||||
@ -826,6 +826,7 @@ export const useUpdateActionProps = () => {
|
|||||||
overwriteValues,
|
overwriteValues,
|
||||||
skipValidator,
|
skipValidator,
|
||||||
triggerWorkflows,
|
triggerWorkflows,
|
||||||
|
isDeltaChanged,
|
||||||
} = actionSchema?.['x-action-settings'] ?? {};
|
} = actionSchema?.['x-action-settings'] ?? {};
|
||||||
|
|
||||||
const assignedValues = {};
|
const assignedValues = {};
|
||||||
@ -854,6 +855,7 @@ export const useUpdateActionProps = () => {
|
|||||||
await form.submit();
|
await form.submit();
|
||||||
}
|
}
|
||||||
const fieldNames = fields.map((field) => field.name);
|
const fieldNames = fields.map((field) => field.name);
|
||||||
|
const actionFields = getActiveFieldsName?.('form') || [];
|
||||||
const values = getFormValues({
|
const values = getFormValues({
|
||||||
filterByTk,
|
filterByTk,
|
||||||
field,
|
field,
|
||||||
@ -861,18 +863,33 @@ export const useUpdateActionProps = () => {
|
|||||||
fieldNames,
|
fieldNames,
|
||||||
getField,
|
getField,
|
||||||
resource,
|
resource,
|
||||||
actionFields: getActiveFieldsName?.('form') || [],
|
actionFields,
|
||||||
});
|
});
|
||||||
actionField.data = field.data || {};
|
actionField.data = field.data || {};
|
||||||
actionField.data.loading = true;
|
actionField.data.loading = true;
|
||||||
try {
|
|
||||||
await resource.update({
|
const rawValues = {
|
||||||
filterByTk,
|
|
||||||
values: {
|
|
||||||
...values,
|
...values,
|
||||||
...overwriteValues,
|
...overwriteValues,
|
||||||
...assignedValues,
|
...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,
|
...data,
|
||||||
updateAssociationValues,
|
updateAssociationValues,
|
||||||
// TODO(refactor): should change to inject by plugin
|
// TODO(refactor): should change to inject by plugin
|
||||||
|
@ -22,6 +22,7 @@ export const UpdateSubmitActionInitializer = (props) => {
|
|||||||
redirecting: false,
|
redirecting: false,
|
||||||
successMessage: '{{t("Updated successfully")}}',
|
successMessage: '{{t("Updated successfully")}}',
|
||||||
},
|
},
|
||||||
|
isDeltaChanged: false,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
return <ActionInitializer {...props} schema={schema} />;
|
return <ActionInitializer {...props} schema={schema} />;
|
||||||
|
@ -71,6 +71,7 @@ import {
|
|||||||
useCustomPresets,
|
useCustomPresets,
|
||||||
useCustomPresets1,
|
useCustomPresets1,
|
||||||
} from './schema-settings/SchemaSettingsDatePresets';
|
} from './schema-settings/SchemaSettingsDatePresets';
|
||||||
|
import { SchemaSettingsSubmitDataType } from './schema-settings/SchemaSettingsSubmitDataType';
|
||||||
export { usePDFViewerRef } from './schema-initializer';
|
export { usePDFViewerRef } from './schema-initializer';
|
||||||
export * from './components/custom-components/custom-components';
|
export * from './components/custom-components/custom-components';
|
||||||
|
|
||||||
@ -102,6 +103,10 @@ export class PluginCoreClient extends Plugin {
|
|||||||
Component: SchemaSettingsDatePresets,
|
Component: SchemaSettingsDatePresets,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.schemaSettingsManager.addItem('actionSettings:updateSubmit', 'submitDataType', {
|
||||||
|
Component: SchemaSettingsSubmitDataType,
|
||||||
|
});
|
||||||
|
|
||||||
this.schemaSettingsManager.addItem('FormItemSettings', 'hera-divider', {
|
this.schemaSettingsManager.addItem('FormItemSettings', 'hera-divider', {
|
||||||
type: 'divider',
|
type: 'divider',
|
||||||
useVisible() {
|
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...",
|
"loading...": "loading...",
|
||||||
"preview block": "preview block",
|
"preview block": "preview block",
|
||||||
"tabs": "tabs",
|
"tabs": "tabs",
|
||||||
"year": "year"
|
"year": "year",
|
||||||
|
"Select submit data type": "Select submit data type"
|
||||||
}
|
}
|
||||||
|
@ -27,5 +27,6 @@
|
|||||||
"loading...": "加载中...",
|
"loading...": "加载中...",
|
||||||
"preview block": "预览区块",
|
"preview block": "预览区块",
|
||||||
"tabs": "多标签",
|
"tabs": "多标签",
|
||||||
"year": "年"
|
"year": "年",
|
||||||
|
"Select submit data type": "增量提交"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user