From 3c982cc09cd3fb91e5e3a03aa213f26c68a7eabf Mon Sep 17 00:00:00 2001 From: Daniel Townsend Date: Mon, 17 Apr 2023 22:46:21 +0100 Subject: [PATCH] stop duplicate API calls --- admin_ui/src/views/RowListing.vue | 33 ++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/admin_ui/src/views/RowListing.vue b/admin_ui/src/views/RowListing.vue index 9946e8b9..bdc1bb83 100644 --- a/admin_ui/src/views/RowListing.vue +++ b/admin_ui/src/views/RowListing.vue @@ -474,6 +474,9 @@ export default Vue.extend({ return Object.fromEntries(orderBy.map((i) => [i.column, i])) }, + filterParams(): { [key: string]: any } { + return this.$store.state.filterParams + }, rowCount() { return this.$store.state.rowCount }, @@ -650,11 +653,31 @@ export default Vue.extend({ await this.fetchRows() }, "$route.query": async function () { - this.$store.commit( - "updateFilterParams", - this.$router.currentRoute.query - ) - await this.fetchRows() + const queryParams = this.$router.currentRoute.query + const orderBy = queryParams.__order + + if (orderBy) { + delete queryParams.__order + } + + const paramsChanged = + JSON.stringify(this.filterParams) != + JSON.stringify(this.filterParams) + + if (paramsChanged) { + this.$store.commit("updateFilterParams", queryParams) + } + + if (orderBy) { + this.$store.commit( + "updateOrderBy", + deserialiseOrderByString(orderBy) + ) + } + + if (paramsChanged || orderBy) { + await this.fetchRows() + } }, rows() { this.resetRowCheckbox()