Skip to content

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

Add `VCollectionHeader` component (#2734)

Olga Bulat1c1d9f58b7fa
diff --git a/frontend/src/assets/svg/raw/institution.svg b/frontend/src/assets/svg/raw/institution.svg
new file mode 100644
index 000000000..9ecbcee19
--- /dev/null
+++ b/frontend/src/assets/svg/raw/institution.svg
@@ -0,0 +1,3 @@
+<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M18.646 9H20V8L19 7.5L12 4L5 7.5L4 8V9H18.646ZM15.646 7.5L12 5.677L8.354 7.5H15.646ZM7.749 16.94V10.44H6.249V16.94H7.749ZM12.749 10.44V16.94H11.249V10.44H12.749ZM17.749 10.44V16.94H16.249V10.44H17.749ZM20.001 19.25C20.001 19.664 19.667 20 19.253 20H4.752C4.55309 20 4.36232 19.921 4.22167 19.7803C4.08102 19.6397 4.002 19.4489 4.002 19.25C4.002 19.0511 4.08102 18.8603 4.22167 18.7197C4.36232 18.579 4.55309 18.5 4.752 18.5H19.252C19.4507 18.5003 19.6412 18.5794 19.7817 18.72C19.9221 18.8606 20.001 19.0513 20.001 19.25Z" fill="currentColor"/>
+</svg>
diff --git a/frontend/src/assets/svg/raw/person.svg b/frontend/src/assets/svg/raw/person.svg
new file mode 100644
index 000000000..3d38ca456
--- /dev/null
+++ b/frontend/src/assets/svg/raw/person.svg
@@ -0,0 +1,4 @@
+<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M16 9C16 11.2091 14.2091 13 12 13C9.79086 13 8 11.2091 8 9C8 6.79086 9.79086 5 12 5C14.2091 5 16 6.79086 16 9ZM14.5 9C14.5 10.3807 13.3807 11.5 12 11.5C10.6193 11.5 9.5 10.3807 9.5 9C9.5 7.61929 10.6193 6.5 12 6.5C13.3807 6.5 14.5 7.61929 14.5 9Z" fill="currentColor"/>
+ <path d="M18.75 20V18C18.75 16.4812 17.5188 15.25 16 15.25L8 15.25C6.48122 15.25 5.25 16.4812 5.25 18V20H6.75L6.75 18C6.75 17.3096 7.30964 16.75 8 16.75L16 16.75C16.6904 16.75 17.25 17.3096 17.25 18V20H18.75Z" fill="currentColor"/>
+</svg>
diff --git a/frontend/src/assets/svg/raw/tag.svg b/frontend/src/assets/svg/raw/tag.svg
new file mode 100644
index 000000000..d7c544e66
--- /dev/null
+++ b/frontend/src/assets/svg/raw/tag.svg
@@ -0,0 +1,3 @@
+<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M5 4.25C4.58579 4.25 4.25 4.58579 4.25 5V12.8261C4.25 13.0252 4.32911 13.216 4.46991 13.3567L11.1908 20.0715C11.4056 20.2865 11.6607 20.4571 11.9415 20.5735C12.2225 20.69 12.5238 20.75 12.828 20.75C13.1322 20.75 13.4335 20.69 13.7145 20.5735C13.9954 20.457 14.2509 20.286 14.4658 20.0709L20.0754 14.4599L19.545 13.9296L20.0769 14.4583C20.5081 14.0245 20.75 13.4377 20.75 12.8261C20.75 12.2145 20.5081 11.6278 20.0769 11.194L13.3545 4.46974C13.2138 4.32904 13.023 4.25 12.8241 4.25H5ZM19.25 12.8261C19.25 13.0413 19.165 13.2476 19.0136 13.4003L13.4044 19.011C13.3287 19.0868 13.2389 19.1469 13.14 19.1879C13.0411 19.2289 12.935 19.25 12.828 19.25C12.7209 19.25 12.6149 19.2289 12.516 19.1879C12.4171 19.1469 12.3267 19.0862 12.251 19.0104L5.75 12.5153V5.75H12.5134L19.0137 12.252C19.165 12.4047 19.25 12.611 19.25 12.8261ZM9 10C9.55228 10 10 9.55228 10 9C10 8.44772 9.55228 8 9 8C8.44772 8 8 8.44772 8 9C8 9.55228 8.44772 10 9 10Z" fill="currentColor"/>
+</svg>
diff --git a/frontend/src/components/VCollectionHeader/VCollectionHeader.vue b/frontend/src/components/VCollectionHeader/VCollectionHeader.vue
new file mode 100644
index 000000000..0d8c44ebe
--- /dev/null
+++ b/frontend/src/components/VCollectionHeader/VCollectionHeader.vue
@@ -0,0 +1,144 @@
+<template>
+ <div
+ class="collection-header grid grid-cols-[1.5rem,1fr] gap-x-2 gap-y-4 md:grid-rows-[auto,auto] md:gap-y-8"
+ :class="
+ collection === 'tag'
+ ? 'tags grid-rows-[auto,auto] md:grid-cols-[2.5rem,1fr]'
+ : 'grid-rows-[auto,auto,auto] md:grid-cols-[2.5rem,1fr,auto]'
+ "
+ >
+ <VIcon :name="iconName" :size="isMd ? 10 : 6" class="icon" />
+ <h1 class="title text-3xl font-semibold leading-snug md:text-6xl">
+ {{ title }}
+ </h1>
+ <VButton
+ v-if="collection !== 'tag' && url"
+ as="VLink"
+ variant="filled-dark"
+ size="medium"
+ class="button label-bold !flex-none md:ms-4 md:mt-1"
+ has-icon-end
+ show-external-icon
+ :external-icon-size="6"
+ :href="url"
+ @click="sendAnalyticsEvent"
+ >{{ $t(`collection.link.${collection}`) }}</VButton
+ >
+ <p
+ class="results caption-regular md:label-regular mt-2 text-dark-charcoal-70 md:mt-0"
+ >
+ {{ resultsLabel }}
+ </p>
+ </div>
+</template>
+
+<script lang="ts">
+import { computed, defineComponent, PropType } from "vue"
+
+import { useUiStore } from "~/stores/ui"
+import type { Collection } from "~/types/search"
+import { useAnalytics } from "~/composables/use-analytics"
+
+import VButton from "~/components/VButton.vue"
+import VIcon from "~/components/VIcon/VIcon.vue"
+
+const icons = {
+ tag: "tag",
+ source: "institution",
+ creator: "person",
+}
+
+/**
+ * Renders the header of a tag/creator/source collection page.
+ */
+export default defineComponent({
+ name: "VCollectionHeader",
+ components: { VIcon, VButton },
+ props: {
+ collection: {
+ type: String as PropType<Collection>,
+ required: true,
+ },
+ /**
+ * The name of the tag/creator/source. The source name should be the display
+ * name, not the code.
+ */
+ title: {
+ type: String,
+ required: true,
+ },
+ slug: {
+ type: String,
+ },
+ url: {
+ type: String,
+ },
+ /**
+ * The label showing the result count, to display below the title.
+ * Should be built by the parent component.
+ */
+ resultsLabel: {
+ type: String,
+ required: true,
+ },
+ },
+ setup(props) {
+ const uiStore = useUiStore()
+
+ const iconName = computed(() => icons[props.collection])
+
+ const isMd = computed(() => uiStore.isBreakpoint("md"))
+
+ const { sendCustomEvent } = useAnalytics()
+
+ const sendAnalyticsEvent = () => {
+ if (!props.url || !props.slug) return
+ const eventName =
+ props.collection === "creator"
+ ? "VISIT_CREATOR_LINK"
+ : "VISIT_SOURCE_LINK"
+ sendCustomEvent(eventName, {
+ url: props.url,
+ source: props.slug,
+ })
+ }
+
+ return {
+ iconName,
+ isMd,
+ sendAnalyticsEvent,
+ }
+ },
+})
+</script>
+
+<style scoped>
+.collection-header {
+ grid-template-areas: "icon title" "button button" "results results";
+}
+@screen md {
+ .collection-header {
+ grid-template-areas: "icon title button" "results results results";
+ }
+}
+.collection-header.tags {
+ grid-template-areas: "icon title" "results results";
+}
+@screen md {
+ .collection-header.tags {
+ grid-template-areas: "icon title" "results results";
+ }
+}
+.icon {
+ grid-area: icon;
+}
+.title {
+ grid-area: title;
+}
+.button {
+ grid-area: button;
+}
+.results {
+ grid-area: results;
+}
+</style>
diff --git a/frontend/src/components/VCollectionHeader/meta/VCollectionHeader.stories.mdx b/frontend/src/components/VCollectionHeader/meta/VCollectionHeader.stories.mdx
new file mode 100644
index 000000000..79596c0cc
--- /dev/null
+++ b/frontend/src/components/VCollectionHeader/meta/VCollectionHeader.stories.mdx
@@ -0,0 +1,65 @@
+import {
+ ArgsTable,
+ Canvas,
+ Description,
+ Meta,
+ Story,
+} from "@storybook/addon-docs"
+
+import VCollectionHeader from "~/components/VCollectionHeader/VCollectionHeader.vue"
+
+<Meta title="Components/VCollectionHeader" component={VCollectionHeader} />
+
+export const AllCollectionsTemplate = (args) => ({
+ template: `
+<div class="wrapper w-full p-2 flex flex-col gap-2 bg-dark-charcoal-06">
+ <VCollectionHeader v-for="collection in args.collections" :key="collection.collectionName" v-bind="collection" class="bg-white"/>
+</div>`,
+ components: { VCollectionHeader },
+ setup() {
+ return { args }
+ },
+})
+
+export const collections = [
+ {
+ collectionName: "tag",
+ collection: "tag",
+ title: "cat",
+ resultsLabel: "10000 audio files with the selected tag",
+ },
+ {
+ collectionName: "source",
+ collection: "source",
+ title: "Metropolitan Museum of Art",
+ url: "https://www.metmuseum.org/",
+ resultsLabel: "10000 images provided by this source",
+ },
+ {
+ collectionName: "creator",
+ collection: "creator",
+ title: "iocyoungreporters",
+ url: "https://www.flickr.com/photos/126018610@N05",
+ resultsLabel: "10000 images. iocyoungreporters, Flickr",
+ },
+ {
+ collectionName: "source-with-long-name",
+ collection: "source",
+ title:
+ "Smithsonian Institution: National Museum of African American History and Culture",
+ url: "https://nmaahc.si.edu",
+ resultsLabel: "10000 images provided by this source",
+ },
+]
+
+# VCollectionHeader
+
+<Description of={VCollectionHeader} />
+
+<ArgsTable of={VCollectionHeader} />
+
+<Canvas>
+ <Story name="All collections" args={{ collections }}>
+ {AllCollectionsTemplate.bind({})}
+ </Story>
+</Canvas>
diff --git a/frontend/src/components/VIcon/VIcon.vue b/frontend/src/components/VIcon/VIcon.vue
index fa526251f..092a06c0d 100644
--- a/frontend/src/components/VIcon/VIcon.vue
+++ b/frontend/src/components/VIcon/VIcon.vue
@@ -53,14 +53,14 @@ export default defineComponent({
},
/**
* The size of the icon based on tailwind values. Possible values:
- * 4 - 1rem, 5 - 1.25rem, 6 - 1.5rem, 8 - 2rem, 12 - 3rem.
+ * 4 - 1rem, 5 - 1.25rem, 6 - 1.5rem, 8 - 2rem, 10 - 2.5rem, 12 - 3rem.
*
* @default 6
*/
size: {
type: Number,
default: 6,
- validator: (val: number) => [4, 5, 6, 8, 12].includes(val),
+ validator: (val: number) => [4, 5, 6, 8, 10, 12].includes(val),
},
/**
* whether to flip the icon for RTL languages; This generally makes sense
diff --git a/frontend/src/locales/scripts/en.json5 b/frontend/src/locales/scripts/en.json5
index ae63af068..747229b33 100644
--- a/frontend/src/locales/scripts/en.json5
+++ b/frontend/src/locales/scripts/en.json5
@@ -772,4 +772,10 @@
userReportedSensitive: "{openverse} users have reported this work as sensitive.",
},
},
+ collection: {
+ link: {
+ source: "Open source site",
+ creator: "Open creator page",
+ },
+ },
}
diff --git a/frontend/src/pages/image/_id/index.vue b/frontend/src/pages/image/_id/index.vue
index d933a2537..238a02dd4 100644
--- a/frontend/src/pages/image/_id/index.vue
+++ b/frontend/src/pages/image/_id/index.vue
@@ -253,6 +253,7 @@ export default defineComponent({
}
sendCustomEvent("VISIT_CREATOR_LINK", {
id: image.value.id,
+ source: image.value.source ?? image.value.provider,
url: image.value.creator_url ?? "",
})
}
diff --git a/frontend/src/types/analytics.ts b/frontend/src/types/analytics.ts
index 495f89f09..2fa65ed56 100644
--- a/frontend/src/types/analytics.ts
+++ b/frontend/src/types/analytics.ts
@@ -206,15 +206,32 @@ export type Events = {
}
/**
* Description: The user visits a creator's link in the single result UI
+ * or the creator's collection page.
* Questions:
* - Are creator links clicked much? Does Openverse increase visibility
* of included creator's profiles?
*/
VISIT_CREATOR_LINK: {
- /** The unique ID of the media */
- id: string
+ /** The unique ID of the media, if the creator link is on the single result page */
+ id?: string
/** The permalink to the creator's profile */
url: string
+ /** The slug for the source where the creator's media is from */
+ source: string
+ }
+ /**
+ * Description: The user visits a source's link in the single result UI
+ * or the source's collection page.
+ * Questions:
+ * - Are source links clicked much? Does Openverse increase visibility
+ * of included sources?
+ */
+ VISIT_SOURCE_LINK: {
+ /** The unique ID of the media, if the source link is on the single
+ * result page */
+ id?: string
+ /** The source's slug that identifies it */
+ source: string
}
/**
* Description: The user visits a CC license description page on CC.org
diff --git a/frontend/src/types/search.ts b/frontend/src/types/search.ts
new file mode 100644
index 000000000..3a6a096e4
--- /dev/null
+++ b/frontend/src/types/search.ts
@@ -0,0 +1 @@
+export type Collection = "tag" | "creator" | "source"
diff --git a/frontend/test/playwright/visual-regression/pages/pages-single-result.spec.ts b/frontend/test/playwright/visual-regression/pages/pages-single-result.spec.ts
index e23b51433..9022a459e 100644
--- a/frontend/test/playwright/visual-regression/pages/pages-single-result.spec.ts
+++ b/frontend/test/playwright/visual-regression/pages/pages-single-result.spec.ts
@@ -34,9 +34,16 @@ for (const mediaType of supportedMediaTypes) {
await openFirstResult(page, mediaType)
await cleanRelatedImages(page)
- await expectSnapshot(`${mediaType}-${dir}-from-search-results`, page, {
- fullPage: true,
- })
+ await expectSnapshot(
+ `${mediaType}-${dir}-from-search-results`,
+ page,
+ {
+ fullPage: true,
+ },
+ {
+ maxDiffPixelRatio: 0.1,
+ }
+ )
})
})
}
diff --git a/frontend/test/storybook/visual-regression/v-collection-header.spec.ts b/frontend/test/storybook/visual-regression/v-collection-header.spec.ts
new file mode 100644
index 000000000..4a24400d8
--- /dev/null
+++ b/frontend/test/storybook/visual-regression/v-collection-header.spec.ts
@@ -0,0 +1,19 @@
+import { test } from "@playwright/test"
+
+import breakpoints from "~~/test/playwright/utils/breakpoints"
+
+test.describe("VCollectionHeader", () => {
+ breakpoints.describeEvery(({ expectSnapshot }) => {
+ for (const languageDirection of ["ltr", "rtl"]) {
+ test(`All headers ${languageDirection}`, async ({ page }) => {
+ await page.goto(
+ `/iframe.html?id=components-vcollectionheader--all-collections`
+ )
+ await expectSnapshot(
+ `VCollectionHeaders-${languageDirection}`,
+ page.locator(".wrapper")
+ )
+ })
+ }
+ })
+})
diff --git a/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-ltr-2xl-linux.png b/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-ltr-2xl-linux.png
new file mode 100644
index 000000000..75c3cf27d
Binary files /dev/null and b/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-ltr-2xl-linux.png differ
diff --git a/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-ltr-lg-linux.png b/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-ltr-lg-linux.png
new file mode 100644
index 000000000..6eeacf52e
Binary files /dev/null and b/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-ltr-lg-linux.png differ
diff --git a/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-ltr-md-linux.png b/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-ltr-md-linux.png
new file mode 100644
index 000000000..9420d6ad1
Binary files /dev/null and b/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-ltr-md-linux.png differ
diff --git a/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-ltr-sm-linux.png b/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-ltr-sm-linux.png
new file mode 100644
index 000000000..63a416d2b
Binary files /dev/null and b/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-ltr-sm-linux.png differ
diff --git a/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-ltr-xl-linux.png b/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-ltr-xl-linux.png
new file mode 100644
index 000000000..8903d78aa
Binary files /dev/null and b/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-ltr-xl-linux.png differ
diff --git a/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-ltr-xs-linux.png b/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-ltr-xs-linux.png
new file mode 100644
index 000000000..683ddafe7
Binary files /dev/null and b/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-ltr-xs-linux.png differ
diff --git a/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-rtl-2xl-linux.png b/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-rtl-2xl-linux.png
new file mode 100644
index 000000000..75c3cf27d
Binary files /dev/null and b/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-rtl-2xl-linux.png differ
diff --git a/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-rtl-lg-linux.png b/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-rtl-lg-linux.png
new file mode 100644
index 000000000..6eeacf52e
Binary files /dev/null and b/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-rtl-lg-linux.png differ
diff --git a/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-rtl-md-linux.png b/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-rtl-md-linux.png
new file mode 100644
index 000000000..9420d6ad1
Binary files /dev/null and b/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-rtl-md-linux.png differ
diff --git a/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-rtl-sm-linux.png b/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-rtl-sm-linux.png
new file mode 100644
index 000000000..63a416d2b
Binary files /dev/null and b/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-rtl-sm-linux.png differ
diff --git a/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-rtl-xl-linux.png b/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-rtl-xl-linux.png
new file mode 100644
index 000000000..8903d78aa
Binary files /dev/null and b/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-rtl-xl-linux.png differ
diff --git a/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-rtl-xs-linux.png b/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-rtl-xs-linux.png
new file mode 100644
index 000000000..683ddafe7
Binary files /dev/null and b/frontend/test/storybook/visual-regression/v-collection-header.spec.ts-snapshots/VCollectionHeaders-rtl-xs-linux.png differ