From 0c280dc85cbc755511dfda2c91fcf82c92413c4c Mon Sep 17 00:00:00 2001 From: Zack Krida Date: Fri, 17 Sep 2021 14:21:40 -0400 Subject: [PATCH] Add process.env.allMediaFeature flag --- nuxt.config.js | 2 ++ src/components/HeroSection.vue | 2 +- src/components/SearchTypeTabs.vue | 6 +++++- src/pages/search/audio.vue | 15 +++++++++++++-- src/store-modules/filter-store.js | 26 +++++++++++++++----------- 5 files changed, 36 insertions(+), 15 deletions(-) diff --git a/nuxt.config.js b/nuxt.config.js index 2365eb1b0d..99dee68145 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -12,6 +12,8 @@ export const env = { filterStorageKey: 'openverse-filter-visibility', notificationStorageKey: 'openverse-show-notification', enableInternalAnalytics: process.env.ENABLE_INTERNAL_ANALYTICS || false, + /** Feature flag to enable non-image media */ + allMediaFeature: process.env.ALL_MEDIA_FEATURE || true, } /** diff --git a/src/components/HeroSection.vue b/src/components/HeroSection.vue index d40a2242b2..a5da190233 100644 --- a/src/components/HeroSection.vue +++ b/src/components/HeroSection.vue @@ -79,7 +79,7 @@ export default { onSubmit() { this.$store.commit(SET_QUERY, { query: { q: this.form.searchTerm } }) const newPath = this.localePath({ - path: '/search', + path: process.env.allMediaFeature ? '/search' : '/search/image', query: { q: this.form.searchTerm, ...filtersToQueryData(this.$store.state.filters, ALL_MEDIA), diff --git a/src/components/SearchTypeTabs.vue b/src/components/SearchTypeTabs.vue index f639f4288a..e7b9203599 100644 --- a/src/components/SearchTypeTabs.vue +++ b/src/components/SearchTypeTabs.vue @@ -26,8 +26,12 @@ import { queryStringToSearchType } from '~/utils/search-query-transform' export default { name: 'SearchTypeTabs', data() { + let contentTypes = [IMAGE, AUDIO, VIDEO] + if (process.env.allMediaFeature) { + contentTypes.unshift(ALL_MEDIA) + } return { - contentTypes: [ALL_MEDIA, IMAGE, AUDIO, VIDEO], + contentTypes, } }, computed: { diff --git a/src/pages/search/audio.vue b/src/pages/search/audio.vue index 2754dbc8f5..00eeafc0dc 100644 --- a/src/pages/search/audio.vue +++ b/src/pages/search/audio.vue @@ -1,7 +1,11 @@ @@ -11,6 +15,12 @@ import { AUDIO } from '~/constants/media' export default { name: 'AudioSearch', + data() { + return { + // Only show audio results if non-image results are supported + supported: process.env.allMediaFeature, + } + }, computed: { query() { return this.$store.state.query @@ -21,6 +31,7 @@ export default { }, methods: { onLoadMoreAudios(searchParams) { + if (!this.supported) return this.$emit('onLoadMoreItems', searchParams) }, }, diff --git a/src/store-modules/filter-store.js b/src/store-modules/filter-store.js index c71046c551..97b2351368 100644 --- a/src/store-modules/filter-store.js +++ b/src/store-modules/filter-store.js @@ -36,16 +36,18 @@ export const mediaFilterKeys = { 'searchBy', 'mature', ], - audio: [ - 'licenses', - 'licenseTypes', - 'audioCategories', - 'audioExtensions', - 'durations', - 'audioProviders', - 'searchBy', - 'mature', - ], + audio: process.env.allMediaFeature + ? [ + 'licenses', + 'licenseTypes', + 'audioCategories', + 'audioExtensions', + 'durations', + 'audioProviders', + 'searchBy', + 'mature', + ] + : [], video: [], all: ['licenses', 'licenseTypes', 'searchBy', 'mature'], } @@ -58,7 +60,9 @@ export const mediaSpecificFilters = { 'sizes', 'imageProviders', ], - audio: ['audioCategories', 'audioExtensions', 'durations', 'audioProviders'], + audio: process.env.allMediaFeature + ? ['audioCategories', 'audioExtensions', 'durations', 'audioProviders'] + : [], video: [], }