mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 08:47:20 +00:00
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 currentUserContext = useCurrentUserContext();
|
||||
const currentUser = currentUserContext?.data?.data;
|
||||
const action = actionField.componentProps.saveMode || 'create';
|
||||
const filterKeys = actionField.componentProps.filterKeys?.checked || [];
|
||||
return {
|
||||
async onClick() {
|
||||
const fieldNames = fields.map((field) => field.name);
|
||||
@ -223,6 +225,7 @@ export const useAssociationCreateActionProps = () => {
|
||||
onSuccess,
|
||||
overwriteValues,
|
||||
skipValidator,
|
||||
triggerWorkflows,
|
||||
} = actionSchema?.['x-action-settings'] ?? {};
|
||||
const addChild = fieldSchema?.['x-component-props']?.addChild;
|
||||
const assignedValues = parse(originalAssignedValues)({ currentTime: new Date(), currentRecord, currentUser });
|
||||
@ -238,12 +241,17 @@ export const useAssociationCreateActionProps = () => {
|
||||
actionField.data = field.data || {};
|
||||
actionField.data.loading = true;
|
||||
try {
|
||||
const data = await resource.create({
|
||||
const data = await resource[action]({
|
||||
values: {
|
||||
...values,
|
||||
...overwriteValues,
|
||||
...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.data = data;
|
||||
|
@ -12,6 +12,7 @@ import { InternalSubTable } from './InternalSubTable';
|
||||
import { InternaPopoverNester } from './InternalPopoverNester';
|
||||
import { CreateRecordAction } from './components/CreateRecordAction';
|
||||
import { useAssociationFieldContext } from './hooks';
|
||||
import { useCollection } from '../../../collection-manager';
|
||||
|
||||
const EditableAssociationField = observer(
|
||||
(props: any) => {
|
||||
@ -23,6 +24,8 @@ const EditableAssociationField = observer(
|
||||
const useCreateActionProps = () => {
|
||||
const { onClick } = useCAP();
|
||||
const actionField: any = useField();
|
||||
const { getPrimaryKey } = useCollection();
|
||||
const primaryKey = getPrimaryKey();
|
||||
return {
|
||||
async onClick() {
|
||||
await onClick();
|
||||
@ -30,9 +33,11 @@ const EditableAssociationField = observer(
|
||||
if (data) {
|
||||
if (['m2m', 'o2m'].includes(collectionField?.interface) && multiple !== false) {
|
||||
const values = form.getValuesIn(field.path) || [];
|
||||
values.push(data);
|
||||
form.setValuesIn(field.path, values);
|
||||
field.onInput(values);
|
||||
if (!values.find((v) => v[primaryKey] === data[primaryKey])) {
|
||||
values.push(data);
|
||||
form.setValuesIn(field.path, values);
|
||||
field.onInput(values);
|
||||
}
|
||||
} else {
|
||||
form.setValuesIn(field.path, data);
|
||||
field.onInput(data);
|
||||
|
Loading…
Reference in New Issue
Block a user