From 0e12e3a79c7dab529a541ff417c5e4da28397af6 Mon Sep 17 00:00:00 2001 From: Olga Bulat Date: Thu, 28 Oct 2021 19:42:10 +0300 Subject: [PATCH] Make search and filter stores namespaced (#316) * Make search and filter store namespaced When merging a query, it is impossible to unset a parameter value, so query replacement was added Use map helpers and address code review changes Apply suggestions from code review Co-authored-by: Krystle Salazar --- src/components/AudioDetails/Table.vue | 13 +- src/components/AudioDetails/Tags.vue | 7 +- src/components/AudioResultsList.vue | 50 +- .../ContentReport/ContentReportForm.vue | 20 +- src/components/ContentReport/ReportError.vue | 3 +- src/components/EmbeddedNavSection.vue | 10 +- src/components/Filters/FilterChecklist.vue | 2 +- src/components/Filters/FilterDisplay.vue | 5 +- src/components/Filters/FiltersList.vue | 8 +- src/components/Filters/SearchGridFilter.vue | 20 +- src/components/HeroSection.vue | 22 +- src/components/HomeLicenseFilter.vue | 7 +- src/components/ImageDetails/ImageInfo.vue | 17 +- src/components/MetaSearch/MetaSearchForm.vue | 6 +- src/components/NavSection.vue | 11 +- src/components/NotificationBanner.vue | 2 +- src/components/PhotoTags.vue | 7 +- src/components/SaferBrowsing.vue | 5 +- src/components/SearchGrid.vue | 7 +- src/components/SearchGridForm.vue | 16 +- src/components/SearchGridManualLoad.vue | 74 ++- src/constants/action-types.js | 6 +- src/constants/mutation-types.js | 8 +- src/constants/store-modules.js | 3 + src/layouts/embedded-with-nav-search.vue | 3 +- src/layouts/embedded.vue | 3 +- src/pages/about.vue | 3 +- src/pages/audio/_id.vue | 8 +- src/pages/extension.vue | 3 +- src/pages/feedback.vue | 5 +- src/pages/index.vue | 3 +- src/pages/meta-search.vue | 3 +- src/pages/photos/_id.vue | 11 +- src/pages/search-help.vue | 3 +- src/pages/search.vue | 32 +- src/pages/sources.vue | 5 +- .../filter-store.js => store/filter.js} | 150 +++--- src/store/index.js | 40 +- src/store/provider.js | 3 +- .../search-store.js => store/search.js} | 136 +++-- src/utils/search-query-transform.js | 2 +- src/utils/sixpack.js | 2 +- .../components/AudioTrack/audio-track.spec.js | 1 + .../ContentReport/content-report-form.spec.js | 58 ++- .../ImageDetails/image-info.spec.js | 25 +- .../specs/components/filter-display.spec.js | 25 +- .../specs/components/hero-section.spec.js | 71 ++- .../components/home-license-filter.spec.js | 51 +- .../unit/specs/components/nav-section.spec.js | 33 +- test/unit/specs/components/photo-tags.spec.js | 27 +- .../components/search-grid-filter.spec.js | 157 +++--- .../specs/components/search-grid-form.spec.js | 27 +- .../components/search-grid-wrapper.spec.js | 27 +- .../unit/specs/components/search-grid.spec.js | 90 ++-- test/unit/specs/pages/browse-page.spec.js | 64 ++- test/unit/specs/store/filter-store.spec.js | 475 +++++++++++++++--- test/unit/specs/store/search-store.spec.js | 240 +++++---- .../utils/search-query-transform.spec.js | 2 +- test/unit/test-utils/sample-store.js | 2 +- 59 files changed, 1379 insertions(+), 740 deletions(-) rename src/{store-modules/filter-store.js => store/filter.js} (79%) rename src/{store-modules/search-store.js => store/search.js} (67%) diff --git a/src/components/AudioDetails/Table.vue b/src/components/AudioDetails/Table.vue index 15521ea1ac6..2c795ef66cc 100644 --- a/src/components/AudioDetails/Table.vue +++ b/src/components/AudioDetails/Table.vue @@ -72,22 +72,19 @@ diff --git a/src/layouts/embedded.vue b/src/layouts/embedded.vue index db77a725e1b..1075e257c86 100644 --- a/src/layouts/embedded.vue +++ b/src/layouts/embedded.vue @@ -11,6 +11,7 @@ import { mapState } from 'vuex' import iframeHeight from '~/mixins/iframe-height' import i18nSync from '~/mixins/i18n-sync' +import { NAV } from '~/constants/store-modules' const embeddedPage = { name: 'embedded', @@ -19,7 +20,7 @@ const embeddedPage = { head() { return this.$nuxtI18nHead({ addSeoAttributes: true, addDirAttribute: true }) }, - computed: { ...mapState('nav', ['isReferredFromCc']) }, + computed: { ...mapState(NAV, ['isReferredFromCc']) }, } export default embeddedPage diff --git a/src/pages/about.vue b/src/pages/about.vue index e3be535e5a5..ed45ccd97c7 100644 --- a/src/pages/about.vue +++ b/src/pages/about.vue @@ -97,6 +97,7 @@ diff --git a/src/pages/photos/_id.vue b/src/pages/photos/_id.vue index 18501d19219..bf33273d870 100644 --- a/src/pages/photos/_id.vue +++ b/src/pages/photos/_id.vue @@ -18,6 +18,7 @@ import axios from 'axios' import { mapActions, mapState } from 'vuex' import { FETCH_IMAGE } from '~/constants/action-types' +import { SEARCH } from '~/constants/store-modules' const PhotoDetailPage = { name: 'PhotoDetailPage', @@ -39,7 +40,13 @@ const PhotoDetailPage = { } }, computed: { - ...mapState(['image']), + ...mapState(SEARCH, ['image']), + }, + async asyncData({ env, route }) { + return { + thumbnailURL: `${env.apiUrl}thumbs/${route.params.id}`, + imageId: route.params.id, + } }, async fetch() { this.imageId = this.$route.params.id @@ -66,7 +73,7 @@ const PhotoDetailPage = { }) }, methods: { - ...mapActions({ fetchImage: FETCH_IMAGE }), + ...mapActions(SEARCH, { fetchImage: FETCH_IMAGE }), onImageLoaded(event) { this.imageWidth = event.target.naturalWidth this.imageHeight = event.target.naturalHeight diff --git a/src/pages/search-help.vue b/src/pages/search-help.vue index 71026131d78..6b2c6fb4056 100644 --- a/src/pages/search-help.vue +++ b/src/pages/search-help.vue @@ -256,6 +256,7 @@ /* eslint-disable vue/html-quotes */ import { mapState } from 'vuex' +import { NAV } from '~/constants/store-modules' const SearchHelpPage = { name: 'search-help-page', @@ -265,7 +266,7 @@ const SearchHelpPage = { : 'with-nav-search' }, computed: { - ...mapState('nav', ['isEmbedded']), + ...mapState(NAV, ['isEmbedded']), }, methods: { providerSearchLink(providerCode) { diff --git a/src/pages/search.vue b/src/pages/search.vue index bbc24517ce4..19d461dc6f3 100644 --- a/src/pages/search.vue +++ b/src/pages/search.vue @@ -28,14 +28,11 @@