Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Update the external search modal and items (#2860)
Olga Bulat836fd9bda6d2
diff --git a/frontend/src/components/VExternalSearch/VExternalSearchForm.vue b/frontend/src/components/VExternalSearch/VExternalSearchForm.vueindex 922c56790..e9a8755fc 100644--- a/frontend/src/components/VExternalSearch/VExternalSearchForm.vue+++ b/frontend/src/components/VExternalSearch/VExternalSearchForm.vue@@ -36,72 +36,73 @@<template #query>{{ searchTerm }}</template></i18n>- <VButton- id="external-sources-button"- ref="triggerRef"- :pressed="triggerA11yProps['aria-expanded']"- aria-haspopup="dialog"- :aria-controls="- isMd ? 'external-sources-popover' : 'external-sources-modal'- "- variant="dropdown-label"- size="disabled"- class="caption-regular ms-2 min-w-max gap-1 px-3 py-1 pe-1 text-dark-charcoal focus-visible:border-tx"- @click="onTriggerClick"- >{{ $t("externalSources.button").toString()- }}<VIcon- class="text-dark-charcoal-40"- :class="{ 'text-white': triggerA11yProps['aria-expanded'] }"- name="caret-down"- />- </VButton>- <template v-if="triggerElement">- <Component- :is="isMd ? 'VPopoverContent' : 'VModalContent'"- :id="isMd ? 'external-sources-popover' : 'external-sources-modal'"- :aria-labelledby="'external-sources-button'"- :hide="closeDialog"- :trigger-element="triggerElement"- :visible="isVisible"- :z-index="isMd ? 'popover' : 'modal'"- :variant="isMd ? undefined : 'centered'"- >- <VExternalSourceList- class="flex flex-col"- :search-term="searchTerm"- @close="closeDialog"- />- </Component>- </template>+ <VModal+ variant="centered"+ :hide-on-click-outside="true"+ labelled-by="external-sources-button"+ @open="handleModalOpen"+ >+ <template #trigger="triggerA11yProps">+ <VButton+ id="external-sources-button"+ v-bind="triggerA11yProps"+ aria-controls="external-sources-modal"+ variant="dropdown-label"+ size="disabled"+ class="caption-regular ms-2 min-w-max gap-1 px-3 py-1 pe-1 text-dark-charcoal focus-visible:border-tx"+ >{{ `${$t("externalSources.button")}`+ }}<VIcon+ class="text-dark-charcoal-40"+ :class="{ 'text-white': triggerA11yProps['aria-expanded'] }"+ name="caret-down"+ />+ </VButton>+ </template>+ <template #top-bar="{ close }">+ <header+ class="flex items-center justify-between pe-5 ps-7 pt-5 sm:pe-7 sm:ps-9 sm:pt-7"+ >+ <h2 class="heading-6" tabindex="-1">+ {{ $t("externalSources.title") }}+ </h2>+ <VIconButton+ size="small"+ :icon-props="{ name: 'close' }"+ variant="transparent-gray"+ :label="$t('modal.close')"+ @click="close"+ />+ </header>+ </template>+ <VExternalSourceList class="flex flex-col" :search-term="searchTerm" />+ </VModal></section></template><script lang="ts">-import { computed, defineComponent, ref, SetupContext } from "vue"+import { defineComponent, ref } from "vue"import { storeToRefs } from "pinia"import { defineEvent } from "~/types/emits"-import { useUiStore } from "~/stores/ui"import { useSearchStore } from "~/stores/search"import { useMediaStore } from "~/stores/media"-import { useDialogControl } from "~/composables/use-dialog-control"import { useAnalytics } from "~/composables/use-analytics"import { useExternalSources } from "~/composables/use-external-sources"import VExternalSourceList from "~/components/VExternalSearch/VExternalSourceList.vue"import VButton from "~/components/VButton.vue"import VIcon from "~/components/VIcon/VIcon.vue"-import VPopoverContent from "~/components/VPopover/VPopoverContent.vue"-import VModalContent from "~/components/VModal/VModalContent.vue"+import VModal from "~/components/VModal/VModal.vue"+import VIconButton from "~/components/VIconButton/VIconButton.vue"export default defineComponent({name: "VExternalSearchForm",components: {- VModalContent,- VPopoverContent,+ VModal,+ VIconButton,VIcon,VButton,VExternalSourceList,@@ -123,45 +124,20 @@ export default defineComponent({emits: {tab: defineEvent<[KeyboardEvent]>(),},- setup(_, { emit }) {+ setup() {const sectionRef = ref<HTMLElement | null>(null)- const triggerRef = ref<{ $el: HTMLElement } | null>(null)- const uiStore = useUiStore()const searchStore = useSearchStore()const { sendCustomEvent } = useAnalytics()- const isMd = computed(() => uiStore.isBreakpoint("md"))-- const triggerElement = computed(() => triggerRef.value?.$el)-- const lockBodyScroll = computed(() => !isMd.value)-- const isVisible = ref(false)-const mediaStore = useMediaStore()const { currentPage } = storeToRefs(mediaStore)- const {- close: closeDialog,- open: openDialog,- onTriggerClick,- triggerA11yProps,- } = useDialogControl({- visibleRef: isVisible,- nodeRef: sectionRef,- lockBodyScroll,- emit: emit as SetupContext["emit"],- })-- const eventedOnTriggerClick = () => {- if (!isVisible.value) {- sendCustomEvent("VIEW_EXTERNAL_SOURCES", {- searchType: searchStore.searchType,- query: searchStore.searchTerm,- resultPage: currentPage.value || 1,- })- }- onTriggerClick()+ const handleModalOpen = () => {+ sendCustomEvent("VIEW_EXTERNAL_SOURCES", {+ searchType: searchStore.searchType,+ query: searchStore.searchTerm,+ resultPage: currentPage.value || 1,+ })}const { externalSourcesType } = useExternalSources()@@ -169,16 +145,8 @@ export default defineComponent({return {externalSourcesType,sectionRef,- triggerRef,- triggerElement,- isMd,-- closeDialog,- openDialog,- onTriggerClick: eventedOnTriggerClick,- triggerA11yProps,- isVisible,+ handleModalOpen,}},})diff --git a/frontend/src/components/VExternalSearch/VExternalSourceList.vue b/frontend/src/components/VExternalSearch/VExternalSourceList.vueindex 1b3001034..72de77057 100644--- a/frontend/src/components/VExternalSearch/VExternalSourceList.vue+++ b/frontend/src/components/VExternalSearch/VExternalSourceList.vue@@ -1,26 +1,23 @@<template>- <div class="relative max-w-[280px]" data-testid="source-list-popover">- <h2 class="description-bold mb-2 px-4 pt-5 text-start">- {{ $t("externalSources.title") }}- </h2>- <VCloseButton- :label="$t('modal.close')"- class="!absolute end-0 top-0"- @close="$emit('close')"- />- <p class="caption-regular mb-4 px-4 text-start">+ <div+ class="p-4 pt-0 sm:max-w-[25rem] sm:p-6 sm:pt-0"+ data-testid="source-list-popover"+ >+ <p class="label-regular px-3 py-4 text-start !leading-normal">{{ $t("externalSources.caption", { openverse: "Openverse" }) }}</p><VButtonv-for="source in externalSources":key="source.name"as="VLink"- variant="transparent-tx"- size="disabled"- class="caption-bold !w-full justify-between px-4 py-3 text-dark-charcoal hover:bg-dark-charcoal-10"+ variant="transparent-gray"+ size="medium"+ class="label-regular !w-full justify-between"show-external-icon- :external-icon-size="4"+ has-icon-end+ :external-icon-size="6":href="source.url"+ :send-external-link-click-event="false"@mousedown="handleClick(source.name)">{{ source.name }}@@ -36,7 +33,6 @@ import { useAnalytics } from "~/composables/use-analytics"import { useExternalSources } from "~/composables/use-external-sources"import VButton from "~/components/VButton.vue"-import VCloseButton from "~/components/VCloseButton.vue"/*** This component renders a list of pre-populated links to additional sources@@ -44,7 +40,7 @@ import VCloseButton from "~/components/VCloseButton.vue"*/export default defineComponent({name: "VExternalSourceList",- components: { VCloseButton, VButton },+ components: { VButton },props: {/*** The search term for which the external sources links are generated.diff --git a/frontend/src/components/VIcon/VIcon.vue b/frontend/src/components/VIcon/VIcon.vueindex 092a06c0d..0be048a14 100644--- a/frontend/src/components/VIcon/VIcon.vue+++ b/frontend/src/components/VIcon/VIcon.vue@@ -1,6 +1,6 @@<template><SvgIcon- class="v-icon flex-shrink-0 flex-grow-0"+ class="v-icon flex-none":class="[`w-${size}`, `h-${size}`, { 'rtl-flip': rtlFlip }]":name="name"aria-hidden="true"diff --git a/frontend/src/components/VIconButton/VOldIconButton.vue b/frontend/src/components/VIconButton/VOldIconButton.vueindex 83d864cb6..f58711f70 100644--- a/frontend/src/components/VIconButton/VOldIconButton.vue+++ b/frontend/src/components/VIconButton/VOldIconButton.vue@@ -3,7 +3,7 @@v-bind="buttonProps":aria-label="label"size="disabled"- class="icon-button flex flex-shrink-0 flex-grow-0 items-center justify-center"+ class="icon-button flex flex-none items-center justify-center":class="[buttonSizeClasses, { 'border-1.5': !borderless }]":type="type"v-on="$listeners"diff --git a/frontend/src/components/VModal/VModal.vue b/frontend/src/components/VModal/VModal.vueindex 5e3dad804..b76171931 100644--- a/frontend/src/components/VModal/VModal.vue+++ b/frontend/src/components/VModal/VModal.vue@@ -30,8 +30,8 @@:mode="mode":content-classes="modalContentClasses">- <template #top-bar>- <slot name="top-bar" />+ <template #top-bar="{ close: hide }">+ <slot name="top-bar" :close="hide" /></template><slot name="default" /></VModalContent>@@ -39,14 +39,7 @@</template><script lang="ts">-import {- defineComponent,- ref,- computed,- toRef,- PropType,- SetupContext,-} from "vue"+import { defineComponent, ref, computed, PropType, SetupContext } from "vue"import type { ModalColorMode, ModalVariant } from "~/types/modal"@@ -138,16 +131,6 @@ export default defineComponent({type: String as PropType<ModalColorMode>,default: "light",},- /**- * This props allows for the modal to be opened or closed programmatically.- * The modal handles the visibility internally if this prop is not provided.- *- * @default undefined- */- visible: {- type: Boolean,- default: undefined,- },modalContentClasses: {type: String,default: "",@@ -163,12 +146,12 @@ export default defineComponent({*/"close",],- setup(props, { emit }) {- const visiblePropRef =- typeof props.visible === "undefined" ? undefined : toRef(props, "visible")-+ setup(_, { emit }) {const nodeRef = ref<null | HTMLElement>(null)- const modalContentRef = ref<InstanceType<typeof VModalContent> | null>(null)+ const modalContentRef = ref<{+ $el: HTMLElement+ deactivateFocusTrap?: () => void+ } | null>(null)const triggerContainerRef = ref<HTMLElement | null>(null)const triggerRef = computed(@@ -186,7 +169,6 @@ export default defineComponent({triggerA11yProps,visible: visibleRef,} = useDialogControl({- visibleRef: visiblePropRef,lockBodyScroll: true,nodeRef,emit: emit as SetupContext["emit"],diff --git a/frontend/src/components/VModal/VModalContent.vue b/frontend/src/components/VModal/VModalContent.vueindex 1e98d0d7e..15fadb53f 100644--- a/frontend/src/components/VModal/VModalContent.vue+++ b/frontend/src/components/VModal/VModalContent.vue@@ -129,7 +129,7 @@ export default defineComponent({},setup(props, { emit, attrs }) {const propsRefs = toRefs(props)- const closeButton = ref<InstanceType<typeof VCloseButton> | null>(null)+ const closeButton = ref<{ $el: HTMLElement } | null>(null)const initialFocusElement = computed(() => props.initialFocusElement || closeButton.value?.$el)@@ -194,6 +194,9 @@ export default defineComponent({.modal-two-thirds {@apply mt-auto h-2/3 w-full rounded-se-lg rounded-ss-lg bg-white;}+.modal-centered {+ @apply m-6 rounded sm:m-0;+}.modal-dark {@apply bg-black text-white;@@ -203,10 +206,10 @@ export default defineComponent({}.modal-content-default {- @apply text-left align-bottom md:rounded-se-md md:rounded-ss-md;+ @apply text-left align-bottom md:rounded-se-lg md:rounded-ss-lg;}.modal-content-centered {- @apply w-auto;+ @apply w-auto rounded;}.modal-fit-content {@apply mt-auto w-full rounded-se-lg rounded-ss-lg bg-white;@@ -215,10 +218,10 @@ export default defineComponent({@apply flex w-full flex-col justify-between px-6 pb-10;}.modal-content-two-thirds {- @apply overflow-y-hidden rounded-se-md rounded-ss-md;+ @apply overflow-y-hidden rounded-se-lg rounded-ss-lg;}.modal-content-fit-content {- @apply rounded-se-md rounded-ss-md;+ @apply rounded-se-lg rounded-ss-lg;}.modal-content-dark {@apply bg-black text-white;diff --git a/frontend/src/composables/use-dialog-control.ts b/frontend/src/composables/use-dialog-control.tsindex 08371c820..ec74ffd8a 100644--- a/frontend/src/composables/use-dialog-control.ts+++ b/frontend/src/composables/use-dialog-control.ts@@ -40,7 +40,7 @@ export function useDialogControl({if (shouldLockBodyScroll.value) {visible ? lock() : unlock()}- if (!internallyControlled) emit(visible ? "open" : "close")+ emit(visible ? "open" : "close")onCleanup(() => {if (shouldLockBodyScroll.value) {unlock()diff --git a/frontend/tailwind.config.ts b/frontend/tailwind.config.tsindex ac8737402..227f34cfb 100644--- a/frontend/tailwind.config.ts+++ b/frontend/tailwind.config.ts@@ -226,7 +226,6 @@ export default {},borderRadius: {inherit: "inherit",- md: "0.5rem",},outlineWidth: {1.5: "1.5px",diff --git a/frontend/test/playwright/e2e/external-sources.spec.ts b/frontend/test/playwright/e2e/external-sources.spec.tsindex 34cffac18..077383fa6 100644--- a/frontend/test/playwright/e2e/external-sources.spec.ts+++ b/frontend/test/playwright/e2e/external-sources.spec.ts@@ -1,35 +1,52 @@import { test } from "@playwright/test"-import { goToSearchTerm } from "~~/test/playwright/utils/navigation"+import { goToSearchTerm, t } from "~~/test/playwright/utils/navigation"import {collectAnalyticsEvents,expectEventPayloadToMatch,} from "~~/test/playwright/utils/analytics"-test("sends correct analytics events", async ({ page, context }) => {+test("sends VIEW_EXTERNAL_SOURCES analytics events", async ({+ page,+ context,+}) => {+ const events = collectAnalyticsEvents(context)++ await goToSearchTerm(page, "cat", { searchType: "image", mode: "SSR" })++ await page.getByRole("button", { name: t("externalSources.button") }).click()+ await page.getByRole("button", { name: /close/i }).click()++ const viewEvent = events.find((event) => event.n === "VIEW_EXTERNAL_SOURCES")++ expectEventPayloadToMatch(viewEvent, {+ searchType: "image",+ query: "cat",+ resultPage: 1,+ })+})++test("sends SELECT_EXTERNAL_SOURCE analytics events", async ({+ page,+ context,+}) => {const pagePromise = page.context().waitForEvent("page")const events = collectAnalyticsEvents(context)await goToSearchTerm(page, "cat", { searchType: "image", mode: "SSR" })- await page.getByRole("button", { name: "Source list" }).click()+ await page.getByRole("button", { name: t("externalSources.button") }).click()await page.getByRole("link", { name: "Centre for Ageing Better" }).click()const newPage = await pagePromiseawait newPage.close()- const viewEvent = events.find((event) => event.n === "VIEW_EXTERNAL_SOURCES")const selectEvent = events.find((event) => event.n === "SELECT_EXTERNAL_SOURCE")- expectEventPayloadToMatch(viewEvent, {- searchType: "image",- query: "cat",- resultPage: 1,- })expectEventPayloadToMatch(selectEvent, {name: "Centre For Ageing Better",mediaType: "image",diff --git a/frontend/test/playwright/visual-regression/components/external-sources-section.spec.ts-snapshots/external-audio-sources-popover-ltr-sm-linux.png b/frontend/test/playwright/visual-regression/components/external-sources-section.spec.ts-snapshots/external-audio-sources-popover-ltr-sm-linux.pngindex ce4c210eb..8df852c51 100644Binary files a/frontend/test/playwright/visual-regression/components/external-sources-section.spec.ts-snapshots/external-audio-sources-popover-ltr-sm-linux.png and b/frontend/test/playwright/visual-regression/components/external-sources-section.spec.ts-snapshots/external-audio-sources-popover-ltr-sm-linux.png differdiff --git a/frontend/test/playwright/visual-regression/components/external-sources-section.spec.ts-snapshots/external-audio-sources-popover-ltr-xl-linux.png b/frontend/test/playwright/visual-regression/components/external-sources-section.spec.ts-snapshots/external-audio-sources-popover-ltr-xl-linux.pngindex 674ba04a8..38181e5c4 100644Binary files a/frontend/test/playwright/visual-regression/components/external-sources-section.spec.ts-snapshots/external-audio-sources-popover-ltr-xl-linux.png and b/frontend/test/playwright/visual-regression/components/external-sources-section.spec.ts-snapshots/external-audio-sources-popover-ltr-xl-linux.png differdiff --git a/frontend/test/playwright/visual-regression/components/external-sources-section.spec.ts-snapshots/external-audio-sources-popover-rtl-sm-linux.png b/frontend/test/playwright/visual-regression/components/external-sources-section.spec.ts-snapshots/external-audio-sources-popover-rtl-sm-linux.pngindex 24c2866c7..8c1462133 100644Binary files a/frontend/test/playwright/visual-regression/components/external-sources-section.spec.ts-snapshots/external-audio-sources-popover-rtl-sm-linux.png and b/frontend/test/playwright/visual-regression/components/external-sources-section.spec.ts-snapshots/external-audio-sources-popover-rtl-sm-linux.png differdiff --git a/frontend/test/playwright/visual-regression/components/external-sources-section.spec.ts-snapshots/external-audio-sources-popover-rtl-xl-linux.png b/frontend/test/playwright/visual-regression/components/external-sources-section.spec.ts-snapshots/external-audio-sources-popover-rtl-xl-linux.pngindex 5a98a0572..1c283efd4 100644Binary files a/frontend/test/playwright/visual-regression/components/external-sources-section.spec.ts-snapshots/external-audio-sources-popover-rtl-xl-linux.png and b/frontend/test/playwright/visual-regression/components/external-sources-section.spec.ts-snapshots/external-audio-sources-popover-rtl-xl-linux.png differdiff --git a/frontend/test/playwright/visual-regression/components/external-sources-section.spec.ts-snapshots/external-image-sources-popover-ltr-sm-linux.png b/frontend/test/playwright/visual-regression/components/external-sources-section.spec.ts-snapshots/external-image-sources-popover-ltr-sm-linux.pngindex e3245878b..2da8adcde 100644Binary files a/frontend/test/playwright/visual-regression/components/external-sources-section.spec.ts-snapshots/external-image-sources-popover-ltr-sm-linux.png and b/frontend/test/playwright/visual-regression/components/external-sources-section.spec.ts-snapshots/external-image-sources-popover-ltr-sm-linux.png differdiff --git a/frontend/test/playwright/visual-regression/components/external-sources-section.spec.ts-snapshots/external-image-sources-popover-ltr-xl-linux.png b/frontend/test/playwright/visual-regression/components/external-sources-section.spec.ts-snapshots/external-image-sources-popover-ltr-xl-linux.pngindex 5aa3a2d8f..1aa4d089d 100644Binary files a/frontend/test/playwright/visual-regression/components/external-sources-section.spec.ts-snapshots/external-image-sources-popover-ltr-xl-linux.png and b/frontend/test/playwright/visual-regression/components/external-sources-section.spec.ts-snapshots/external-image-sources-popover-ltr-xl-linux.png differdiff --git a/frontend/test/playwright/visual-regression/components/external-sources-section.spec.ts-snapshots/external-image-sources-popover-rtl-sm-linux.png b/frontend/test/playwright/visual-regression/components/external-sources-section.spec.ts-snapshots/external-image-sources-popover-rtl-sm-linux.pngindex 2fbfbb5a5..65c21d943 100644Binary files a/frontend/test/playwright/visual-regression/components/external-sources-section.spec.ts-snapshots/external-image-sources-popover-rtl-sm-linux.png and b/frontend/test/playwright/visual-regression/components/external-sources-section.spec.ts-snapshots/external-image-sources-popover-rtl-sm-linux.png differdiff --git a/frontend/test/playwright/visual-regression/components/external-sources-section.spec.ts-snapshots/external-image-sources-popover-rtl-xl-linux.png b/frontend/test/playwright/visual-regression/components/external-sources-section.spec.ts-snapshots/external-image-sources-popover-rtl-xl-linux.pngindex dfdc29de1..ae204e6ee 100644Binary files a/frontend/test/playwright/visual-regression/components/external-sources-section.spec.ts-snapshots/external-image-sources-popover-rtl-xl-linux.png and b/frontend/test/playwright/visual-regression/components/external-sources-section.spec.ts-snapshots/external-image-sources-popover-rtl-xl-linux.png differ