Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Use links instead of buttons for header search type switcher (#1131)
Olga Bulatf09e1d90842a
diff --git a/src/components/VContentSwitcher/VMobileMenuModal.vue b/src/components/VContentSwitcher/VMobileMenuModal.vueindex 467e2ecf3..a2bb37872 100644--- a/src/components/VContentSwitcher/VMobileMenuModal.vue+++ b/src/components/VContentSwitcher/VMobileMenuModal.vue@@ -24,6 +24,7 @@ref="searchTypesNode"size="small":active-item="content.activeType.value"+ :use-links="true"@select="selectItem"/><VPageList layout="columns" class="mt-10" />diff --git a/src/components/VContentSwitcher/VSearchTypeItem.vue b/src/components/VContentSwitcher/VSearchTypeItem.vueindex 9fe3335ca..9679e0bfb 100644--- a/src/components/VContentSwitcher/VSearchTypeItem.vue+++ b/src/components/VContentSwitcher/VSearchTypeItem.vue@@ -2,6 +2,7 @@<VItem:selected="selected":is-first="itemId === 0"+ v-bind="component"@click.native="$emit('click', item)"><div class="flex flex-row items-center text-base">@@ -15,10 +16,10 @@</template><script>-import { computed } from '@nuxtjs/composition-api'+import { computed, useContext, useRoute } from '@nuxtjs/composition-api'import { defineComponent } from '@vue/composition-api'-import { contentStatus } from '~/constants/media'+import { ALL_MEDIA, contentStatus } from '~/constants/media'import VIcon from '~/components/VIcon/VIcon.vue'import VItem from '~/components/VItemGroup/VItem.vue'@@ -30,16 +31,40 @@ const propTypes = {itemId: { type: Number, required: true },selected: { type: Boolean, default: false },icon: { type: String, required: true },+ useLinks: { type: Boolean, default: true },}export default defineComponent({name: 'VSearchTypeItem',components: { VIcon, VItem, VPill },props: propTypes,setup(props) {+ const { app } = useContext()+ const route = useRoute()+const status = computed(() => {return contentStatus[props.item]})++ /**+ * The query is temporarily set to the incorrect value here: it uses the existing query+ * that is set for selected search type. When the search store conversion PR is merged,+ * we will set the query specific for the search type using `computeQueryParams(props.item)` method.+ */+ const component = computed(() => {+ if (!props.useLinks) {+ return {}+ }+ return {+ as: 'VLink',+ href: app.localePath({+ path: `/search/${props.item === ALL_MEDIA ? '' : props.item}`,+ // query: searchStore.computeQueryParams(props.item),+ query: route.value.query,+ }),+ }+ })return {+ component,status,}},diff --git a/src/components/VContentSwitcher/VSearchTypePopover.vue b/src/components/VContentSwitcher/VSearchTypePopover.vueindex a6ef73681..5beeb3c86 100644--- a/src/components/VContentSwitcher/VSearchTypePopover.vue+++ b/src/components/VContentSwitcher/VSearchTypePopover.vue@@ -22,6 +22,7 @@id="content-switcher-popover"size="medium":active-item="activeItem"+ :use-links="placement === 'header'"@select="selectItem"/></VPopover>diff --git a/src/components/VContentSwitcher/VSearchTypes.vue b/src/components/VContentSwitcher/VSearchTypes.vueindex 5fd29c4d0..c225268ce 100644--- a/src/components/VContentSwitcher/VSearchTypes.vue+++ b/src/components/VContentSwitcher/VSearchTypes.vue@@ -14,6 +14,7 @@:item="item":item-id="idx":icon="content.icons[item]"+ :use-links="useLinks":selected="item === activeItem"@click="handleClick(item)"/>@@ -46,6 +47,10 @@ export default defineComponent({required: true,validator: (val) => supportedSearchTypes.includes(val),},+ useLinks: {+ type: Boolean,+ default: true,+ },},setup(props, { emit }) {const content = useSearchType()diff --git a/src/locales/po-files/openverse.pot b/src/locales/po-files/openverse.potindex 66414816e..ce0368e21 100644--- a/src/locales/po-files/openverse.pot+++ b/src/locales/po-files/openverse.pot@@ -49,7 +49,7 @@ msgctxt "search-type.heading"msgid "Content types"msgstr ""-#: src/components/VContentSwitcher/VSearchTypeItem.vue:11+#: src/components/VContentSwitcher/VSearchTypeItem.vue:12msgctxt "search-type.status-beta"msgid "Beta"msgstr ""diff --git a/test/e2e/filters.spec.js b/test/e2e/filters.spec.jsindex ede60affd..652ae74e7 100644--- a/test/e2e/filters.spec.js+++ b/test/e2e/filters.spec.js@@ -97,13 +97,12 @@ test('common filters are retained when media type changes from single type to alawait changeContentType(page, 'All content')- await expect(page).toHaveURL(- '/search/?q=cat&license_type=commercial&license=cc0&searchBy=creator'- )-for (let checkbox of ['cc0', 'commercial', 'creator']) {await assertCheckboxStatus(page, checkbox)}+ await expect(page).toHaveURL(+ '/search/?q=cat&license_type=commercial&license=cc0&searchBy=creator'+ )})test('selecting some filters can disable dependent filters', async ({@@ -138,12 +137,12 @@ test('filters are updated when media type changes', async ({ page }) => {await changeContentType(page, 'Audio')- await expect(page).toHaveURL('/search/audio?q=cat&license=cc0')-await expect(page.locator('label:has-text("Tall")')).toHaveCount(0, {timeout: 300,})await assertCheckboxStatus(page, 'cc0')++ await expect(page).toHaveURL('/search/audio?q=cat&license=cc0')})test('new media request is sent when a filter is selected', async ({diff --git a/test/e2e/search-types.spec.js b/test/e2e/search-types.spec.jsindex e64927b0a..fa4d6ffa7 100644--- a/test/e2e/search-types.spec.js+++ b/test/e2e/search-types.spec.js@@ -115,10 +115,12 @@ for (let searchTypeName of ['audio', 'image']) {}) => {await page.goto('/search/?q=birds')const contentLink = await page.locator(- `a[href*="/search/${searchTypeName}"][href$="q=birds"]`+ `a:not([role="radio"])[href*="/search/${searchTypeName}"][href$="q=birds"]`)await expect(contentLink).toContainText(searchType.results)- await page.click(`a[href*="/search/${searchTypeName}"][href$="q=birds"]`)+ await page.click(+ `a:not([role="radio"])[href*="/search/${searchTypeName}"][href$="q=birds"]`+ )await expect(page).toHaveURL(searchType.url)await checkSearchResult(page, searchType)diff --git a/test/e2e/utils.js b/test/e2e/utils.jsindex 7823b9278..523d79157 100644--- a/test/e2e/utils.js+++ b/test/e2e/utils.js@@ -34,7 +34,7 @@ const changeContentType = async (page, to) => {await page.click(`button[aria-controls="content-switcher-popover"], button[aria-controls="content-switcher-modal"]`)- await page.click(`button[role="radio"]:has-text("${to}")`)+ await page.click(`a:has-text("${to}")`)}/*** Finds a button with a popup to the left of the filters button which doesn't have a 'menu' label