fix: update useCreateActionProps & useUpdateActionProps

This commit is contained in:
chenos 2022-04-19 09:27:52 +08:00
parent 10dcc7fea0
commit fca0943e8d
2 changed files with 76 additions and 51 deletions

View File

@ -44,7 +44,10 @@ export const useCreateActionProps = () => {
if (!skipValidator) { if (!skipValidator) {
await form.submit(); await form.submit();
} }
const values = {}; let values = {};
if (resource instanceof TableFieldResource) {
values = form.values;
} else {
for (const key in form.values) { for (const key in form.values) {
if (fieldNames.includes(key)) { if (fieldNames.includes(key)) {
const items = form.values[key]; const items = form.values[key];
@ -56,7 +59,7 @@ export const useCreateActionProps = () => {
} else if (items && typeof items === 'object') { } else if (items && typeof items === 'object') {
values[key] = items[targetKey]; values[key] = items[targetKey];
} else { } else {
values[key] = items[targetKey]; values[key] = items;
} }
} else { } else {
values[key] = form.values[key]; values[key] = form.values[key];
@ -65,6 +68,7 @@ export const useCreateActionProps = () => {
values[key] = form.values[key]; values[key] = form.values[key];
} }
} }
}
await resource.create({ await resource.create({
values: { values: {
...values, ...values,
@ -110,14 +114,21 @@ export const useUpdateActionProps = () => {
await form.submit(); await form.submit();
} }
const fieldNames = fields.map((field) => field.name); const fieldNames = fields.map((field) => field.name);
const values = {}; let values = {};
if (resource instanceof TableFieldResource) {
values = form.values;
} else {
for (const key in form.values) { for (const key in form.values) {
if (fieldNames.includes(key)) { if (fieldNames.includes(key)) {
const collectionField = getField(key);
if (collectionField.interface === 'subTable') {
values[key] = form.values[key];
continue;
}
if (!field.added.has(key)) { if (!field.added.has(key)) {
continue; continue;
} }
const items = form.values[key]; const items = form.values[key];
const collectionField = getField(key);
if (collectionField.interface === 'linkTo') { if (collectionField.interface === 'linkTo') {
const targetKey = collectionField.targetKey || 'id'; const targetKey = collectionField.targetKey || 'id';
if (Array.isArray(items)) { if (Array.isArray(items)) {
@ -125,7 +136,7 @@ export const useUpdateActionProps = () => {
} else if (items && typeof items === 'object') { } else if (items && typeof items === 'object') {
values[key] = items[targetKey]; values[key] = items[targetKey];
} else { } else {
values[key] = items[targetKey]; values[key] = items;
} }
} else { } else {
values[key] = form.values[key]; values[key] = form.values[key];
@ -134,6 +145,7 @@ export const useUpdateActionProps = () => {
values[key] = form.values[key]; values[key] = form.values[key];
} }
} }
}
await resource.update({ await resource.update({
filterByTk, filterByTk,
values: { values: {

View File

@ -97,19 +97,25 @@ export class CollectionManagerPlugin extends Plugin {
foreignKey: model.get('foreignKey'), foreignKey: model.get('foreignKey'),
interface: 'linkTo', interface: 'linkTo',
reverseField: { reverseField: {
interface: 'linkTo', interface: 'subTable',
uiSchema: { uiSchema: {
type: 'void',
title: through.get('title'), title: through.get('title'),
'x-component': 'RecordPicker', 'x-component': 'TableField',
'x-component-props': { 'x-component-props': {},
// mode: 'tags',
multiple: true,
fieldNames: {
label: 'id',
value: 'id',
},
},
}, },
// uiSchema: {
// title: through.get('title'),
// 'x-component': 'RecordPicker',
// 'x-component-props': {
// // mode: 'tags',
// multiple: true,
// fieldNames: {
// label: 'id',
// value: 'id',
// },
// },
// },
}, },
uiSchema: { uiSchema: {
title: db.getCollection(sourceName)?.options?.title || sourceName, title: db.getCollection(sourceName)?.options?.title || sourceName,
@ -135,19 +141,26 @@ export class CollectionManagerPlugin extends Plugin {
foreignKey: model.get('otherKey'), foreignKey: model.get('otherKey'),
interface: 'linkTo', interface: 'linkTo',
reverseField: { reverseField: {
interface: 'linkTo', interface: 'subTable',
uiSchema: { uiSchema: {
type: 'void',
title: through.get('title'), title: through.get('title'),
'x-component': 'RecordPicker', 'x-component': 'TableField',
'x-component-props': { 'x-component-props': {},
// mode: 'tags',
multiple: true,
fieldNames: {
label: 'id',
value: 'id',
},
},
}, },
// interface: 'linkTo',
// uiSchema: {
// title: through.get('title'),
// 'x-component': 'RecordPicker',
// 'x-component-props': {
// // mode: 'tags',
// multiple: true,
// fieldNames: {
// label: 'id',
// value: 'id',
// },
// },
// },
}, },
uiSchema: { uiSchema: {
title: db.getCollection(targetName)?.options?.title || targetName, title: db.getCollection(targetName)?.options?.title || targetName,