fix: saving method of association field creation button is not effect (#2706)
* fix: the saving method of the association field creation button is not effective * refactor: code improve
This commit is contained in:
parent
e522e1f742
commit
d83afc52ec
@ -215,6 +215,8 @@ export const useAssociationCreateActionProps = () => {
|
|||||||
const currentRecord = useRecord();
|
const currentRecord = useRecord();
|
||||||
const currentUserContext = useCurrentUserContext();
|
const currentUserContext = useCurrentUserContext();
|
||||||
const currentUser = currentUserContext?.data?.data;
|
const currentUser = currentUserContext?.data?.data;
|
||||||
|
const action = actionField.componentProps.saveMode || 'create';
|
||||||
|
const filterKeys = actionField.componentProps.filterKeys?.checked || [];
|
||||||
return {
|
return {
|
||||||
async onClick() {
|
async onClick() {
|
||||||
const fieldNames = fields.map((field) => field.name);
|
const fieldNames = fields.map((field) => field.name);
|
||||||
@ -223,6 +225,7 @@ export const useAssociationCreateActionProps = () => {
|
|||||||
onSuccess,
|
onSuccess,
|
||||||
overwriteValues,
|
overwriteValues,
|
||||||
skipValidator,
|
skipValidator,
|
||||||
|
triggerWorkflows,
|
||||||
} = actionSchema?.['x-action-settings'] ?? {};
|
} = actionSchema?.['x-action-settings'] ?? {};
|
||||||
const addChild = fieldSchema?.['x-component-props']?.addChild;
|
const addChild = fieldSchema?.['x-component-props']?.addChild;
|
||||||
const assignedValues = parse(originalAssignedValues)({ currentTime: new Date(), currentRecord, currentUser });
|
const assignedValues = parse(originalAssignedValues)({ currentTime: new Date(), currentRecord, currentUser });
|
||||||
@ -238,12 +241,17 @@ export const useAssociationCreateActionProps = () => {
|
|||||||
actionField.data = field.data || {};
|
actionField.data = field.data || {};
|
||||||
actionField.data.loading = true;
|
actionField.data.loading = true;
|
||||||
try {
|
try {
|
||||||
const data = await resource.create({
|
const data = await resource[action]({
|
||||||
values: {
|
values: {
|
||||||
...values,
|
...values,
|
||||||
...overwriteValues,
|
...overwriteValues,
|
||||||
...assignedValues,
|
...assignedValues,
|
||||||
},
|
},
|
||||||
|
filterKeys: filterKeys,
|
||||||
|
// TODO(refactor): should change to inject by plugin
|
||||||
|
triggerWorkflows: triggerWorkflows?.length
|
||||||
|
? triggerWorkflows.map((row) => [row.workflowKey, row.context].filter(Boolean).join('!')).join(',')
|
||||||
|
: undefined,
|
||||||
});
|
});
|
||||||
actionField.data.loading = false;
|
actionField.data.loading = false;
|
||||||
actionField.data.data = data;
|
actionField.data.data = data;
|
||||||
|
@ -12,6 +12,7 @@ import { InternalSubTable } from './InternalSubTable';
|
|||||||
import { InternaPopoverNester } from './InternalPopoverNester';
|
import { InternaPopoverNester } from './InternalPopoverNester';
|
||||||
import { CreateRecordAction } from './components/CreateRecordAction';
|
import { CreateRecordAction } from './components/CreateRecordAction';
|
||||||
import { useAssociationFieldContext } from './hooks';
|
import { useAssociationFieldContext } from './hooks';
|
||||||
|
import { useCollection } from '../../../collection-manager';
|
||||||
|
|
||||||
const EditableAssociationField = observer(
|
const EditableAssociationField = observer(
|
||||||
(props: any) => {
|
(props: any) => {
|
||||||
@ -23,6 +24,8 @@ const EditableAssociationField = observer(
|
|||||||
const useCreateActionProps = () => {
|
const useCreateActionProps = () => {
|
||||||
const { onClick } = useCAP();
|
const { onClick } = useCAP();
|
||||||
const actionField: any = useField();
|
const actionField: any = useField();
|
||||||
|
const { getPrimaryKey } = useCollection();
|
||||||
|
const primaryKey = getPrimaryKey();
|
||||||
return {
|
return {
|
||||||
async onClick() {
|
async onClick() {
|
||||||
await onClick();
|
await onClick();
|
||||||
@ -30,9 +33,11 @@ const EditableAssociationField = observer(
|
|||||||
if (data) {
|
if (data) {
|
||||||
if (['m2m', 'o2m'].includes(collectionField?.interface) && multiple !== false) {
|
if (['m2m', 'o2m'].includes(collectionField?.interface) && multiple !== false) {
|
||||||
const values = form.getValuesIn(field.path) || [];
|
const values = form.getValuesIn(field.path) || [];
|
||||||
|
if (!values.find((v) => v[primaryKey] === data[primaryKey])) {
|
||||||
values.push(data);
|
values.push(data);
|
||||||
form.setValuesIn(field.path, values);
|
form.setValuesIn(field.path, values);
|
||||||
field.onInput(values);
|
field.onInput(values);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
form.setValuesIn(field.path, data);
|
form.setValuesIn(field.path, data);
|
||||||
field.onInput(data);
|
field.onInput(data);
|
||||||
|
Loading…
Reference in New Issue
Block a user