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;
|
return this.premiseEditStore.showProcessingModal || this.destinationEditStore.showProcessingModal;
|
||||||
},
|
},
|
||||||
shownProcessingMessage() {
|
shownProcessingMessage() {
|
||||||
if(this.premiseEditStore.showProcessingModal)
|
if (this.premiseEditStore.showProcessingModal)
|
||||||
return "Please wait. Prepare calculation ..."
|
return "Please wait. Prepare calculation ..."
|
||||||
|
|
||||||
return this.processingMessage;
|
return this.processingMessage;
|
||||||
|
|
@ -444,6 +444,7 @@ export default {
|
||||||
async closeEditModalAction(action) {
|
async closeEditModalAction(action) {
|
||||||
|
|
||||||
let massUpdate = false;
|
let massUpdate = false;
|
||||||
|
let success = true;
|
||||||
|
|
||||||
if (this.modalType === 'amount' || this.modalType === 'routes' || this.modalType === "destinations") {
|
if (this.modalType === 'amount' || this.modalType === 'routes' || this.modalType === "destinations") {
|
||||||
|
|
||||||
|
|
@ -453,18 +454,21 @@ export default {
|
||||||
const setMatrix = this.$refs.modalComponent?.destMatrix;
|
const setMatrix = this.$refs.modalComponent?.destMatrix;
|
||||||
|
|
||||||
if (setMatrix) {
|
if (setMatrix) {
|
||||||
await this.destinationEditStore.massSetDestinations(setMatrix);
|
success = await this.destinationEditStore.massSetDestinations(setMatrix);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
massUpdate = true
|
massUpdate = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (success) {
|
||||||
// Clear data
|
// Clear data
|
||||||
this.fillData(this.modalType);
|
this.fillData(this.modalType);
|
||||||
this.modalType = null;
|
this.modalType = null;
|
||||||
|
} else return;
|
||||||
|
|
||||||
if(massUpdate) {
|
if (massUpdate) {
|
||||||
await this.destinationEditStore.massUpdateDestinations(this.editIds);
|
await this.destinationEditStore.massUpdateDestinations(this.editIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
import {defineStore} from 'pinia'
|
import {defineStore} from 'pinia'
|
||||||
import performRequest from "@/backend.js";
|
import performRequest from "@/backend.js";
|
||||||
import {config} from '@/config'
|
import {config} from '@/config'
|
||||||
|
import logger from "@/logger.js";
|
||||||
|
import {useNotificationStore} from "@/store/notification.js";
|
||||||
|
|
||||||
export const useDestinationEditStore = defineStore('destinationEdit', {
|
export const useDestinationEditStore = defineStore('destinationEdit', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
|
|
@ -83,6 +85,8 @@ export const useDestinationEditStore = defineStore('destinationEdit', {
|
||||||
async massSetDestinations(updateMatrix) {
|
async massSetDestinations(updateMatrix) {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
const toBeAdded = {};
|
const toBeAdded = {};
|
||||||
const toBeDeletedMap = new Map();
|
const toBeDeletedMap = new Map();
|
||||||
|
|
||||||
|
|
@ -105,8 +109,20 @@ export const useDestinationEditStore = defineStore('destinationEdit', {
|
||||||
this.destinations.set(premiseId, [...filtered, ...data[premiseId]]);
|
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;
|
this.loading = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
},
|
},
|
||||||
async massUpdateDestinations(premiseIds) {
|
async massUpdateDestinations(premiseIds) {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue