From 04f0ae04cf65cfe0eb4476483f0af49154fbb0d0 Mon Sep 17 00:00:00 2001 From: Dallas Richmond Date: Thu, 18 Jul 2024 14:32:59 -0700 Subject: [PATCH] Added the ability to store user column preferences in localstoragre --- .../src/wells/components/SearchColumnSelect.vue | 16 ++++++++++------ .../src/wells/components/SearchResults.vue | 4 ++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/frontend/src/wells/components/SearchColumnSelect.vue b/app/frontend/src/wells/components/SearchColumnSelect.vue index a7af84e8b..9a1131a5a 100644 --- a/app/frontend/src/wells/components/SearchColumnSelect.vue +++ b/app/frontend/src/wells/components/SearchColumnSelect.vue @@ -272,9 +272,10 @@ export default { const columnIds = [...this.localSelectedColumnIds] columnIds.sort((columnA, columnB) => { return this.columnOrders[columnA] - this.columnOrders[columnB] - }) - this.$store.commit(SET_SEARCH_RESULT_COLUMNS, columnIds) - this.hideModal() + }); + localStorage.setItem('userColumnPreferences', JSON.stringify(columnIds)); + this.$store.commit(SET_SEARCH_RESULT_COLUMNS, columnIds); + this.hideModal(); }, cancelChanges () { this.localSelectedColumnIds = [...this.selectedColumnIds] @@ -283,9 +284,12 @@ export default { } }, created () { - this.localSelectedColumnIds = [...this.selectedColumnIds] - this.initColumnOrders() - + if (localStorage && localStorage.getItem('userColumnPreferences')) { + this.localSelectedColumnIds = JSON.parse(localStorage.getItem('userColumnPreferences')); + } else { + this.localSelectedColumnIds = [...this.selectedColumnIds]; + } + this.initColumnOrders(); // listen for reset wells search so we can adjust our selected search columns this.$store.subscribeAction((action, state) => { if (action.type === RESET_WELLS_SEARCH) { diff --git a/app/frontend/src/wells/components/SearchResults.vue b/app/frontend/src/wells/components/SearchResults.vue index 459e3a05d..14bd35c26 100644 --- a/app/frontend/src/wells/components/SearchResults.vue +++ b/app/frontend/src/wells/components/SearchResults.vue @@ -147,6 +147,7 @@ import SearchResultExports from '@/wells/components/SearchResultExports.vue' import SearchResultFilter from '@/wells/components/SearchResultFilter.vue' import SearchColumnSelect from '@/wells/components/SearchColumnSelect.vue' import filterMixin from '@/wells/components/mixins/filters.js' +import { SET_SEARCH_RESULT_COLUMNS } from '../store/mutations.types' export default { mixins: [filterMixin], @@ -328,6 +329,9 @@ export default { } }, created () { + if(localStorage && localStorage.getItem('userColumnPreferences')) { + this.$store.commit(SET_SEARCH_RESULT_COLUMNS, JSON.parse(localStorage.getItem('userColumnPreferences'))); + } this.initFilterParams() } }