Skip to content

Commit 54e9503

Browse files
committed
fix: update prepareDataForSave and analyzeFields functions to use primaryKey instead of hardcoded id
1 parent a7cb55a commit 54e9503

File tree

2 files changed

+22
-32
lines changed

2 files changed

+22
-32
lines changed

custom/visionAction.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ const openDialog = async () => {
8484
analyzeFields();
8585
}
8686
87-
watch(selected, (val) => {
88-
console.log('Selected changed:', val);
89-
}, { deep: true });
87+
// watch(selected, (val) => {
88+
// console.log('Selected changed:', val);
89+
// }, { deep: true });
9090
9191
const closeDialog = () => {
9292
confirmDialog.value.close();
@@ -194,12 +194,12 @@ function prepareDataForSave() {
194194
const checkedItems = selected.value
195195
.filter(item => item.isChecked === true)
196196
.map(item => {
197-
const { isChecked, id, ...itemWithoutIsCheckedAndId } = item;
197+
const { isChecked, primaryKey, ...itemWithoutIsCheckedAndId } = item;
198198
return itemWithoutIsCheckedAndId;
199199
});
200200
const checkedItemsIDs = selected.value
201201
.filter(item => item.isChecked === true)
202-
.map(item => item.id);
202+
.map(item => item[primaryKey]);
203203
return [checkedItemsIDs, checkedItems];
204204
}
205205
@@ -222,7 +222,7 @@ async function analyzeFields() {
222222
...res.result.map((item, idx) => ({
223223
...item,
224224
isChecked: true,
225-
id: selected.value[idx]?.id,
225+
[primaryKey]: selected.value[idx]?.[primaryKey],
226226
}))
227227
)
228228
}

index.ts

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -50,32 +50,22 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
5050
}
5151

5252

53-
// if (this.options.generateImages) {
54-
// const resource = adminforth.config.resources.find(r => r.resourceId === this.options.generateImages!.attachmentResource);
55-
// if (!resource) {
56-
// throw new Error(`Resource '${this.options.generateImages!.attachmentResource}' not found`);
57-
// }
58-
// this.attachmentResource = resource;
59-
// const field = resource.columns.find(c => c.name === this.options.generateImages!.attachmentFieldName);
60-
// if (!field) {
61-
// throw new Error(`Field '${this.options.generateImages!.attachmentFieldName}' not found in resource '${this.options.generateImages!.attachmentResource}'`);
62-
// }
63-
// const plugin = adminforth.activatedPlugins.find(p =>
64-
// p.resourceConfig!.resourceId === this.options.attachments!.attachmentResource &&
65-
// p.pluginOptions.pathColumnName === this.options.attachments!.attachmentFieldName
66-
// );
67-
// if (!plugin) {
68-
// throw new Error(`Plugin for attachment field '${this.options.attachments!.attachmentFieldName}' not found in resource '${this.options.attachments!.attachmentResource}', please check if Upload Plugin is installed on the field ${this.options.attachments!.attachmentFieldName}`);
69-
// }
70-
71-
// if (!plugin.pluginOptions.storageAdapter.objectCanBeAccesedPublicly()) {
72-
// throw new Error(`Upload Plugin for attachment field '${this.options.attachments!.attachmentFieldName}' in resource '${this.options.attachments!.attachmentResource}'
73-
// uses adapter which is not configured to store objects in public way, so it will produce only signed private URLs which can not be used in HTML text of blog posts.
74-
// Please configure adapter in such way that it will store objects publicly (e.g. for S3 use 'public-read' ACL).
75-
// `);
76-
// }
77-
// this.uploadPlugin = plugin;
78-
// }
53+
if (this.options.generateImages) {
54+
console.log('Generate Images options:', this.options.generateImages);
55+
for (const [key, value] of Object.entries(this.options.generateImages)) {
56+
const column = columns.find(c => c.name.toLowerCase() === key.toLowerCase());
57+
if (!column) {
58+
throw new Error(`⚠️ No column found for key "${key}"`);
59+
}
60+
const plugin = adminforth.activatedPlugins.find(p =>
61+
p.resourceConfig!.resourceId === key &&
62+
p.pluginOptions.pathColumnName === this.resourceConfig.resourceId
63+
);
64+
// if (!plugin) {
65+
// throw new Error(`Plugin for attachment field '${key}' not found in resource '${this.options.attachments!.attachmentResource}', please check if Upload Plugin is installed on the field ${this.options.attachments!.attachmentFieldName}`);
66+
// }
67+
}
68+
}
7969

8070

8171
const primaryKeyColumn = this.resourceConfig.columns.find((col) => col.primaryKey);

0 commit comments

Comments
 (0)