Enhance error handling in massSetDestinations: Add notifications for failures, logging support, and update modal behavior to prevent data clearing on errors.
This commit is contained in:
parent
81233db437
commit
8ef279e735
2 changed files with 43 additions and 23 deletions
|
|
@ -267,7 +267,7 @@ export default {
|
|||
return this.premiseEditStore.showProcessingModal || this.destinationEditStore.showProcessingModal;
|
||||
},
|
||||
shownProcessingMessage() {
|
||||
if(this.premiseEditStore.showProcessingModal)
|
||||
if (this.premiseEditStore.showProcessingModal)
|
||||
return "Please wait. Prepare calculation ..."
|
||||
|
||||
return this.processingMessage;
|
||||
|
|
@ -444,6 +444,7 @@ export default {
|
|||
async closeEditModalAction(action) {
|
||||
|
||||
let massUpdate = false;
|
||||
let success = true;
|
||||
|
||||
if (this.modalType === 'amount' || this.modalType === 'routes' || this.modalType === "destinations") {
|
||||
|
||||
|
|
@ -453,18 +454,21 @@ export default {
|
|||
const setMatrix = this.$refs.modalComponent?.destMatrix;
|
||||
|
||||
if (setMatrix) {
|
||||
await this.destinationEditStore.massSetDestinations(setMatrix);
|
||||
success = await this.destinationEditStore.massSetDestinations(setMatrix);
|
||||
}
|
||||
} else {
|
||||
massUpdate = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (success) {
|
||||
// Clear data
|
||||
this.fillData(this.modalType);
|
||||
this.modalType = null;
|
||||
} else return;
|
||||
|
||||
if(massUpdate) {
|
||||
if (massUpdate) {
|
||||
await this.destinationEditStore.massUpdateDestinations(this.editIds);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import {defineStore} from 'pinia'
|
||||
import performRequest from "@/backend.js";
|
||||
import {config} from '@/config'
|
||||
import logger from "@/logger.js";
|
||||
import {useNotificationStore} from "@/store/notification.js";
|
||||
|
||||
export const useDestinationEditStore = defineStore('destinationEdit', {
|
||||
state: () => ({
|
||||
|
|
@ -83,6 +85,8 @@ export const useDestinationEditStore = defineStore('destinationEdit', {
|
|||
async massSetDestinations(updateMatrix) {
|
||||
this.loading = true;
|
||||
|
||||
try {
|
||||
|
||||
const toBeAdded = {};
|
||||
const toBeDeletedMap = new Map();
|
||||
|
||||
|
|
@ -105,8 +109,20 @@ export const useDestinationEditStore = defineStore('destinationEdit', {
|
|||
this.destinations.set(premiseId, [...filtered, ...data[premiseId]]);
|
||||
});
|
||||
|
||||
|
||||
} catch (error) {
|
||||
logger.error('Error in massSetDestinations:', error);
|
||||
useNotificationStore().addNotification({
|
||||
title: 'Unable to set destinations',
|
||||
message: error.message ?? error.toString(),
|
||||
variant: 'exception',
|
||||
icon: 'bug',
|
||||
})
|
||||
return false;
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
async massUpdateDestinations(premiseIds) {
|
||||
this.loading = true;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue