Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ui/src/utils/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,11 @@ const sourceToken = {
},
cancel: () => {
if (!source) sourceToken.init()
source.cancel()
if (source) {
source.cancel()
} else {
console.log('Source token failed to be cancelled')
}
}
}

Expand Down
23 changes: 21 additions & 2 deletions ui/src/views/AutogenView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ import { ref, reactive, toRaw } from 'vue'
import { api } from '@/api'
import { mixinDevice } from '@/utils/mixin.js'
import { genericCompare } from '@/utils/sort.js'
import { sourceToken } from '@/utils/request'
import store from '@/store'
import eventBus from '@/config/eventBus'

Expand Down Expand Up @@ -621,6 +622,9 @@ export default {
next()
},
beforeRouteLeave (to, from, next) {
console.log('DEBUG - Due to route change, ignoring results for any on-going API request', this.apiName)
sourceToken.cancel()
sourceToken.init()
this.currentPath = this.$route.fullPath
next()
},
Expand Down Expand Up @@ -920,19 +924,30 @@ export default {
break
}
}
this.itemCount = 0
var apiItemCount = 0
for (const key in json[responseName]) {
if (key === 'count') {
this.itemCount = json[responseName].count
apiItemCount = json[responseName].count
continue
}
objectName = key
break
}

if ('id' in this.$route.params && this.$route.params.id !== params.id) {
console.log('DEBUG - Discarding API response as its `id` does not match the uuid on the browser path')
return
}
if (this.dataView && apiItemCount > 1) {
console.log('DEBUG - Discarding API response as got more than one item in data view', this.$route.params, this.items)
return
}

this.items = json[responseName][objectName]
if (!this.items || this.items.length === 0) {
this.items = []
}
this.itemCount = apiItemCount

if (['listTemplates', 'listIsos'].includes(this.apiName) && this.items.length > 1) {
this.items = [...new Map(this.items.map(x => [x.id, x])).values()]
Expand Down Expand Up @@ -982,6 +997,10 @@ export default {
}
}
}).catch(error => {
if (!error || !error.message) {
console.log('API request likely got cancelled due to route change:', this.apiName)
return
}
if ([401].includes(error.response.status)) {
return
}
Expand Down