Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Make additional search types flag clearer and add external sources for additional types (#2141)

Olga Bulat83b470ddab13
diff --git a/frontend/feat/feature-flags.json b/frontend/feat/feature-flags.json
index d83ee32d3..01ee54bda 100644
--- a/frontend/feat/feature-flags.json
+++ b/frontend/feat/feature-flags.json
@@ -9,12 +9,12 @@
"defaultState": "off",
"storage": "cookie"
},
- "external_sources": {
+ "additional_search_types": {
"status": {
"staging": "switchable",
"production": "disabled"
},
- "description": "Toggle the external sources in the header's search type switcher.",
+ "description": "Toggle additional search types in the content switcher.",
"defaultState": "off",
"storage": "cookie"
},
diff --git a/frontend/src/components/VContentSwitcher/meta/VSearchTypeButton.stories.mdx b/frontend/src/components/VContentSwitcher/meta/VSearchTypeButton.stories.mdx
index 3d1de65f9..098b5b9b8 100644
--- a/frontend/src/components/VContentSwitcher/meta/VSearchTypeButton.stories.mdx
+++ b/frontend/src/components/VContentSwitcher/meta/VSearchTypeButton.stories.mdx
@@ -41,7 +41,7 @@ export const Template = (args) => ({
components: { VSearchTypeButton },
setup() {
const featureFlagStore = useFeatureFlagStore()
- featureFlagStore.toggleFeature("external_sources", "on")
+ featureFlagStore.toggleFeature("additional_search_types", "on")
const st = useSearchType()
st.setActiveType(args.searchType)
args["aria-haspopup"] = "dialog"
diff --git a/frontend/src/components/VContentSwitcher/meta/VSearchTypePopover.stories.mdx b/frontend/src/components/VContentSwitcher/meta/VSearchTypePopover.stories.mdx
index 0ab0a9965..bcf96c872 100644
--- a/frontend/src/components/VContentSwitcher/meta/VSearchTypePopover.stories.mdx
+++ b/frontend/src/components/VContentSwitcher/meta/VSearchTypePopover.stories.mdx
@@ -31,7 +31,7 @@ export const Template = (args) => ({
setup() {
const featureFlagStore = useFeatureFlagStore()
featureFlagStore.toggleFeature(
- "external_sources",
+ "additional_search_types",
args.additionalTypes ? "on" : "off"
)
return { args }
diff --git a/frontend/src/components/VContentSwitcher/meta/VSearchTypes.stories.mdx b/frontend/src/components/VContentSwitcher/meta/VSearchTypes.stories.mdx
index 4750ceefd..080bb6a2e 100644
--- a/frontend/src/components/VContentSwitcher/meta/VSearchTypes.stories.mdx
+++ b/frontend/src/components/VContentSwitcher/meta/VSearchTypes.stories.mdx
@@ -37,7 +37,7 @@ export const Template = (args) => ({
setup() {
const featureFlagStore = useFeatureFlagStore()
featureFlagStore.toggleFeature(
- "external_sources",
+ "additional_search_types",
args.additionalTypes ? "on" : "off"
)
return { args }
diff --git a/frontend/src/components/VSearchGrid.vue b/frontend/src/components/VSearchGrid.vue
index c3f6eb943..53d5e06d2 100644
--- a/frontend/src/components/VSearchGrid.vue
+++ b/frontend/src/components/VSearchGrid.vue
@@ -42,12 +42,14 @@ import {
IMAGE,
SearchType,
isSupportedMediaType,
+ isAdditionalSearchType,
} from "~/constants/media"
import { NO_RESULT } from "~/constants/errors"
import { defineEvent } from "~/types/emits"
import type { FetchState } from "~/types/fetch-state"
import type { ApiQueryParams } from "~/utils/search-query-transform"
import { getAdditionalSources } from "~/utils/get-additional-sources"
+import { useFeatureFlagStore } from "~/stores/feature-flag"
import VExternalSearchForm from "~/components/VExternalSearch/VExternalSearchForm.vue"
import VErrorSection from "~/components/VErrorSection/VErrorSection.vue"
@@ -106,9 +108,16 @@ export default defineComponent({
* External sources search form shows the external sources for current search type, or for images if the search type is 'All Content'.
*/
const externalSourcesType = computed(() => {
+ const featureFlagStore = useFeatureFlagStore()
if (isSupportedMediaType(props.searchType)) {
return props.searchType
}
+ if (
+ featureFlagStore.isOn("additional_search_types") &&
+ isAdditionalSearchType(props.searchType)
+ ) {
+ return props.searchType
+ }
return IMAGE
})
diff --git a/frontend/src/composables/use-search-type.ts b/frontend/src/composables/use-search-type.ts
index a91881d12..ff787601a 100644
--- a/frontend/src/composables/use-search-type.ts
+++ b/frontend/src/composables/use-search-type.ts
@@ -48,7 +48,9 @@ export default function useSearchType() {
const featureFlagStore = useFeatureFlagStore()
const additionalTypes = computed(() =>
- featureFlagStore.isOn("external_sources") ? additionalSearchTypes : []
+ featureFlagStore.isOn("additional_search_types")
+ ? additionalSearchTypes
+ : []
)
const searchTypes = [...supportedSearchTypes]
diff --git a/frontend/src/stores/search.ts b/frontend/src/stores/search.ts
index c812309ce..130c3cc60 100644
--- a/frontend/src/stores/search.ts
+++ b/frontend/src/stores/search.ts
@@ -208,11 +208,11 @@ export const useSearchStore = defineStore("search", {
setSearchType(type: SearchType) {
const featureFlagStore = useFeatureFlagStore()
if (
- !featureFlagStore.isOn("external_sources") &&
+ !featureFlagStore.isOn("additional_search_types") &&
isAdditionalSearchType(type)
) {
throw new Error(
- `Please enable the 'external_sources' flag to use the ${type}`
+ `Please enable the 'additional_search_types' flag to use the ${type}`
)
}
diff --git a/frontend/test/playwright/visual-regression/pages/homepage.spec.ts b/frontend/test/playwright/visual-regression/pages/homepage.spec.ts
index 2e9f0179d..d14949fd0 100644
--- a/frontend/test/playwright/visual-regression/pages/homepage.spec.ts
+++ b/frontend/test/playwright/visual-regression/pages/homepage.spec.ts
@@ -66,7 +66,7 @@ for (const dir of languageDirections) {
test("content switcher with external sources open", async ({
page,
}) => {
- await page.goto(pathWithDir("/?ff_external_sources=on", dir))
+ await page.goto(pathWithDir("/?ff_additional_search_types=on", dir))
await cleanImageCarousel(page)
await page.locator("#search-type-button").click()
diff --git a/frontend/test/unit/specs/stores/search-store.spec.js b/frontend/test/unit/specs/stores/search-store.spec.js
index f69c6f2ac..1eb4daf77 100644
--- a/frontend/test/unit/specs/stores/search-store.spec.js
+++ b/frontend/test/unit/specs/stores/search-store.spec.js
@@ -107,7 +107,7 @@ describe("Search Store", () => {
"mediaFiltersForDisplay returns $filterTypeCount filters for $searchType",
({ searchType, filterTypeCount }) => {
const featureFlagStore = useFeatureFlagStore()
- featureFlagStore.toggleFeature("external_sources", "on")
+ featureFlagStore.toggleFeature("additional_search_types", "on")
const searchStore = useSearchStore()
searchStore.setSearchType(searchType)
@@ -425,7 +425,7 @@ describe("Search Store", () => {
searchStore.setSearchType(searchType)
const featureFlagStore = useFeatureFlagStore()
- featureFlagStore.toggleFeature("external_sources", "on")
+ featureFlagStore.toggleFeature("additional_search_types", "on")
// Set all filters to checked
for (let ft in searchStore.filters) {
@@ -448,7 +448,7 @@ describe("Search Store", () => {
it("Does not set filter or count filter as applied, and does not raise error for unsupported search types", () => {
const searchStore = useSearchStore()
const featureFlagStore = useFeatureFlagStore()
- featureFlagStore.toggleFeature("external_sources", "on")
+ featureFlagStore.toggleFeature("additional_search_types", "on")
searchStore.toggleFilter({
filterType: "licenseTypes",
code: "commercial",