Skip to content

Commit a089a52

Browse files
committed
fix: if user passes integer/float as string for integer/float fields to the save data api - before throwing error we are trying to parse it
1 parent 1f53d7e commit a089a52

2 files changed

Lines changed: 36 additions & 11 deletions

File tree

custom/VisionAction.vue

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -830,19 +830,18 @@ async function saveData() {
830830
const saveResults = await Promise.all(saveTasks);
831831
const failedResult = saveResults.find(res => res?.ok === false || res?.error);
832832
833-
if (!failedResult) {
834-
confirmDialog.value.close();
835-
props.updateList();
836-
props.clearCheckboxes?.();
837-
} else if (failedResult.ok === false) {
838-
adminforth.alert({
839-
message: failedResult.error,
840-
variant: 'danger',
841-
timeout: 'unlimited',
833+
if (failedResult && failedResult.ok === false) {
834+
saveResults.filter(res => res?.ok === false).forEach(res => {
835+
adminforth.alert({
836+
message: res.error || t(errorText),
837+
variant: 'danger',
838+
timeout: 'unlimited',
839+
});
840+
console.error('Error saving data:', res.error);
842841
});
843842
isError.value = true;
844843
errorMessage.value = t(errorText);
845-
} else {
844+
} else if ( failedResult ) {
846845
console.error('Error saving data:', failedResult);
847846
isError.value = true;
848847
errorMessage.value = t(errorText);
@@ -852,6 +851,9 @@ async function saveData() {
852851
isError.value = true;
853852
errorMessage.value = t(errorText);
854853
} finally {
854+
confirmDialog.value.close();
855+
props.updateList();
856+
props.clearCheckboxes?.();
855857
isLoading.value = false;
856858
isDataSaved.value = true;
857859
window.removeEventListener('beforeunload', beforeUnloadHandler);

index.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,11 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
825825
}
826826
}
827827
const primaryKeyColumn = this.resourceConfig.columns.find((col) => col.primaryKey);
828+
828829
const decimalFieldsArray = this.resourceConfig.columns.filter(c => c.type === 'decimal').map(c => c.name);
830+
const integerFieldsArray = this.resourceConfig.columns.filter(c => c.type === 'integer').map(c => c.name);
831+
const floatFieldsArray = this.resourceConfig.columns.filter(c => c.type === 'float').map(c => c.name);
832+
829833
const updates = selectedIds.map(async (ID, idx) => {
830834
const oldRecord = await this.adminforth.resource(this.resourceConfig.resourceId).get( [Filters.EQ(primaryKeyColumn.name, ID)] );
831835
for (const [key, value] of Object.entries(outputImageFields)) {
@@ -869,6 +873,21 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
869873
}
870874
}
871875
}
876+
if (integerFieldsArray.length > 0) {
877+
for (const fieldName of integerFieldsArray) {
878+
if (fieldsToUpdate[idx].hasOwnProperty(fieldName)) {
879+
fieldsToUpdate[idx][fieldName] = parseInt(fieldsToUpdate[idx][fieldName], 10);
880+
}
881+
}
882+
}
883+
if (floatFieldsArray.length > 0) {
884+
for (const fieldName of floatFieldsArray) {
885+
if (fieldsToUpdate[idx].hasOwnProperty(fieldName)) {
886+
fieldsToUpdate[idx][fieldName] = parseFloat(fieldsToUpdate[idx][fieldName]);
887+
}
888+
}
889+
}
890+
872891
const newRecord = {
873892
...oldRecord,
874893
...fieldsToUpdate[idx]
@@ -881,7 +900,11 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
881900
adminUser: adminUser,
882901
})
883902
});
884-
await Promise.all(updates);
903+
try {
904+
await Promise.all(updates);
905+
} catch (error) {
906+
return { ok: false, error: `Error updating records, because of unprocesseble data for record ID ${selectedIds}` };
907+
}
885908
return { ok: true };
886909
} else {
887910
return { ok: false, error: isAllowedToSave.error };

0 commit comments

Comments
 (0)