Skip to content

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

Create the updated 'No results' and 'Server timeout' sections (#603)

Dhruv Bhanushalied69f4305482
diff --git a/src/assets/error_images/depressed_musician.jpg b/src/assets/error_images/depressed_musician.jpg
new file mode 100644
index 000000000..6347bd815
Binary files /dev/null and b/src/assets/error_images/depressed_musician.jpg differ
diff --git a/src/assets/error_images/image_info.json b/src/assets/error_images/image_info.json
new file mode 100644
index 000000000..1056d8d13
--- /dev/null
+++ b/src/assets/error_images/image_info.json
@@ -0,0 +1,30 @@
+{
+ "errors": [
+ {
+ "error": "NO_RESULT",
+ "image": {
+ "id": "depressed-musician",
+ "file": "depressed_musician",
+ "title": "Depressed musician vintage drawing",
+ "foreign_landing_url": "https://www.rawpixel.com/image/573060/depressed-musician-vintage-drawing",
+ "creator": "The British Library",
+ "license": "cc0",
+ "license_version": "1.0",
+ "license_url": "https://creativecommons.org/publicdomain/zero/1.0/"
+ }
+ },
+ {
+ "error": "SERVER_TIMEOUT",
+ "image": {
+ "id": "waiting-for-a-bite",
+ "file": "waiting_for_a_bite",
+ "title": "Waiting for a Bite, from Harper's Weekly, August 22, 1874, p. 693",
+ "foreign_landing_url": "https://collection.cooperhewitt.org/view/objects/asitem/id/105053",
+ "creator": "Edward Lagarde, American, 19th century",
+ "license": "cc0",
+ "license_version": "1.0",
+ "license_url": "https://creativecommons.org/publicdomain/zero/1.0/"
+ }
+ }
+ ]
+}
diff --git a/src/assets/error_images/waiting_for_a_bite.jpg b/src/assets/error_images/waiting_for_a_bite.jpg
new file mode 100644
index 000000000..b8ada4c0a
Binary files /dev/null and b/src/assets/error_images/waiting_for_a_bite.jpg differ
diff --git a/src/components/VErrorSection/VErrorImage.vue b/src/components/VErrorSection/VErrorImage.vue
new file mode 100644
index 000000000..6d5db087f
--- /dev/null
+++ b/src/components/VErrorSection/VErrorImage.vue
@@ -0,0 +1,58 @@
+<template>
+ <figure class="error-image">
+ <img :src="image.src" :alt="$t(image.alt)" :title="$t(image.alt)" />
+ <figcaption class="attribution" v-html="image.attribution" />
+ </figure>
+</template>
+
+<script>
+import { computed } from '@nuxtjs/composition-api'
+
+import { errorCodes } from '~/constants/errors'
+import { getAttributionMarkup } from '~/utils/attribution-html'
+
+import imageInfo from '~/assets/error_images/image_info.json'
+
+/**
+ * Displays a sad image to convey the absence of results for a search term.
+ */
+export default {
+ name: 'VErrorImage',
+ props: {
+ errorCode: {
+ type: String,
+ required: true,
+ validator: (val) => errorCodes.includes(val),
+ },
+ },
+ setup(props) {
+ const images = Object.fromEntries(
+ imageInfo.errors.map((errorItem) => {
+ let image = errorItem.image
+ image = {
+ ...image,
+ src: require(`~/assets/error_images/${image.file}.jpg`),
+ alt: `error-images.${image.id}`,
+ attribution: getAttributionMarkup(image),
+ }
+ return [errorItem.error, image]
+ })
+ )
+ const image = computed(() => images[props.errorCode])
+
+ return {
+ image,
+ }
+ },
+}
+</script>
+
+<style scoped lang="scss">
+::v-deep .attribution {
+ @apply text-dark-charcoal-70;
+
+ a {
+ @apply text-current underline;
+ }
+}
+</style>
diff --git a/src/components/VErrorSection/VErrorSection.vue b/src/components/VErrorSection/VErrorSection.vue
new file mode 100644
index 000000000..650a44a94
--- /dev/null
+++ b/src/components/VErrorSection/VErrorSection.vue
@@ -0,0 +1,23 @@
+<template>
+ <div class="error-section flex flex-row items-center max-w-screen-xl mx-auto">
+ <div class="image-pane hidden md:block flex-grow max-w-[432px]">
+ <!-- @slot Error image goes here -->
+ <slot name="image" />
+ </div>
+ <div class="flex-grow p-4 md:p-20">
+ <!-- @slot Main content goes here -->
+ <slot />
+ </div>
+ </div>
+</template>
+
+<script>
+/**
+ * This component sets the layout for showing error messages.
+ */
+export default {
+ name: 'VErrorSection',
+}
+</script>
+
+<style scoped></style>
diff --git a/src/components/VErrorSection/VNoResults.vue b/src/components/VErrorSection/VNoResults.vue
new file mode 100644
index 000000000..0125b24fc
--- /dev/null
+++ b/src/components/VErrorSection/VNoResults.vue
@@ -0,0 +1,29 @@
+<template>
+ <div class="no-results text-center md:text-left">
+ <h5 class="text-5xl">{{ $t('no-results.heading', { query: query.q }) }}</h5>
+ <h6 class="text-3xl font-normal md:font-bold mt-10 md:mt-16">
+ {{ $t('no-results.alternatives') }}
+ </h6>
+ <VMetaSourceList class="mt-4 md:mt-6" :type="type" :query="query" />
+ </div>
+</template>
+
+<script>
+import { supportedSearchTypes } from '~/constants/media'
+
+import VMetaSourceList from '~/components/VMetaSearch/VMetaSourceList.vue'
+
+export default {
+ name: 'VNoResults',
+ components: { VMetaSourceList },
+ props: {
+ type: {
+ type: String,
+ validator: (val) => supportedSearchTypes.includes(val),
+ },
+ query: {
+ type: Object,
+ },
+ },
+}
+</script>
diff --git a/src/components/VErrorSection/VServerTimeout.vue b/src/components/VErrorSection/VServerTimeout.vue
new file mode 100644
index 000000000..d4d022f85
--- /dev/null
+++ b/src/components/VErrorSection/VServerTimeout.vue
@@ -0,0 +1,11 @@
+<template>
+ <div class="server-timeout">
+ <h4 class="text-5xl">{{ $t('server-timeout.heading') }}</h4>
+ </div>
+</template>
+
+<script>
+export default {
+ name: 'VServerTimeout',
+}
+</script>
diff --git a/src/components/VErrorSection/meta/VErrorSection.stories.mdx b/src/components/VErrorSection/meta/VErrorSection.stories.mdx
new file mode 100644
index 000000000..c0bf33efe
--- /dev/null
+++ b/src/components/VErrorSection/meta/VErrorSection.stories.mdx
@@ -0,0 +1,88 @@
+import {
+ ArgsTable,
+ Canvas,
+ Description,
+ Meta,
+ Story,
+} from '@storybook/addon-docs'
+
+import VErrorSection from '~/components/VErrorSection/VErrorSection.vue'
+import VErrorImage from '~/components/VErrorSection/VErrorImage.vue'
+import VNoResults from '~/components/VErrorSection/VNoResults.vue'
+import VServerTimeout from '~/components/VErrorSection/VServerTimeout.vue'
+
+import { NO_RESULT, SERVER_TIMEOUT } from '~/constants/errors'
+
+<Meta title="Components/VErrorSection" component={VErrorSection} />
+
+# VErrorSection
+
+<Description of={VErrorSection} />
+
+<ArgsTable of={VErrorSection} />
+
+## No results
+
+This section appears when a search returns no hits.
+
+export const NoResultsTemplate = (args, { argTypes }) => ({
+ template: `
+ <VErrorSection>
+ <template #image>
+ <VErrorImage :error-code="errorCode" />
+ </template>
+ <VNoResults :type="type" :query="query"/>
+ </VErrorSection>
+ `,
+ data: () => ({
+ NO_RESULT,
+ }),
+ components: { VErrorSection, VErrorImage, VNoResults },
+ props: Object.keys(argTypes),
+})
+
+<Canvas>
+ <Story
+ name="No result"
+ args={{
+ errorCode: NO_RESULT,
+ type: 'image',
+ query: {
+ license: '',
+ license_type: '',
+ mature: false,
+ q: 'sad person',
+ searchBy: '',
+ },
+ }}
+ >
+ {NoResultsTemplate.bind({})}
+ </Story>
+</Canvas>
+
+## Server timeout
+
+This result appears when an API request times out.
+
+export const ServerTimeoutTemplate = (args, { argTypes }) => ({
+ template: `
+ <VErrorSection>
+ <template #image>
+ <!-- On large screens, image is in the left pane. -->
+ <VErrorImage class="hidden md:block" :error-code="errorCode" />
+ </template>
+ <VServerTimeout/>
+ <!-- On small screens, image is below error message. -->
+ <VErrorImage class="md:hidden mt-10" :error-code="errorCode" />
+ </VErrorSection>
+ `,
+ data: () => ({ SERVER_TIMEOUT }),
+ components: { VErrorSection, VErrorImage, VServerTimeout },
+ props: Object.keys(argTypes),
+})
+
+<Canvas>
+ <Story name="Server timeout" args={{ errorCode: SERVER_TIMEOUT }}>
+ {ServerTimeoutTemplate.bind({})}
+ </Story>
+</Canvas>
diff --git a/src/components/VMetaSearch/VMetaSearchForm.vue b/src/components/VMetaSearch/VMetaSearchForm.vue
index d81ae8ab2..001b5b965 100644
--- a/src/components/VMetaSearch/VMetaSearchForm.vue
+++ b/src/components/VMetaSearch/VMetaSearchForm.vue
@@ -6,9 +6,9 @@
>
<header class="mb-10">
<i18n
- v-if="!noresult"
+ v-if="!hasNoResults"
:path="
- supported
+ isSupported
? 'meta-search.form.supported-title'
: 'meta-search.form.unsupported-title'
"
@@ -39,7 +39,11 @@
</i18n>
</header>
- <VMetaSourceList :type="type" :query="metaQuery" />
+ <VMetaSourceList
+ class="md:justify-center mt-6 mb-10"
+ :type="type"
+ :query="metaQuery"
+ />
<p class="caption font-semibold max-w-3xl my-0 mx-auto">
{{ $t('meta-search.caption', { openverse: 'Openverse' }) }}
@@ -60,8 +64,8 @@ export default {
props: {
query: { type: Object, required: true },
type: { type: String, required: true },
- supported: { type: Boolean, default: false },
- noresult: { type: Boolean, required: true },
+ isSupported: { type: Boolean, default: false },
+ hasNoResults: { type: Boolean, required: true },
},
computed: {
unsupportedByUsefilter() {
diff --git a/src/components/VMetaSearch/VMetaSourceList.vue b/src/components/VMetaSearch/VMetaSourceList.vue
index 1cd4c4dd8..d03771563 100644
--- a/src/components/VMetaSearch/VMetaSourceList.vue
+++ b/src/components/VMetaSearch/VMetaSourceList.vue
@@ -1,43 +1,53 @@
<template>
- <div class="mb-10">
- <ul class="buttons is-centered mt-6">
- <li v-for="source in sources" :key="source">
- <VLink :href="getSourceUrl(source)" class="button small me-2 is-opaque">
- {{ source }}
- <sup class="top-0">
- <i class="ms-2 icon external-link" />
- </sup>
- </VLink>
- </li>
- </ul>
- </div>
+ <ul
+ class="meta-sources flex flex-col md:flex-row flex-wrap items-stretch gap-4 w-full"
+ >
+ <li v-for="source in sources" :key="source.name">
+ <VButton
+ as="VLink"
+ variant="tertiary"
+ size="disabled"
+ :href="source.url"
+ class="w-full md:w-auto text-sr font-bold p-4 md:py-2 md:px-3"
+ >
+ {{ source.name }}
+ <sup class="top-0">
+ <i class="ms-2 icon external-link" />
+ </sup>
+ </VButton>
+ </li>
+ </ul>
</template>
<script>
+import { computed } from '@nuxtjs/composition-api'
+
import getLegacySourceUrl, {
legacySourceMap,
} from '~/utils/get-legacy-source-url'
-import VLink from '~/components/VLink.vue'
+import VButton from '~/components/VButton.vue'
export default {
name: 'MetaSourceList',
- components: { VLink },
+ components: { VButton },
props: {
type: { type: String },
query: { type: Object },
},
- data() {
+ setup(props) {
+ const sources = computed(() =>
+ Object.keys(legacySourceMap)
+ .filter((sourceName) => legacySourceMap[sourceName][props.type])
+ .map((source) => ({
+ name: source,
+ url: getLegacySourceUrl(props.type)(source, props.query),
+ }))
+ )
+
return {
- sources: Object.keys(legacySourceMap).filter(
- (sourceName) => legacySourceMap[sourceName][this.type]
- ),
+ sources,
}
},
- methods: {
- getSourceUrl(source) {
- return getLegacySourceUrl(this.type)(source, this.query)
- },
- },
}
</script>
diff --git a/src/components/VSearchGrid.vue b/src/components/VSearchGrid.vue
index 84f1f5c4b..411451e48 100644
--- a/src/components/VSearchGrid.vue
+++ b/src/components/VSearchGrid.vue
@@ -1,5 +1,5 @@
<template>
- <section class="">
+ <section v-if="resultsCount">
<header
v-if="query.q && isSupported"
class="mt-4"
@@ -18,11 +18,17 @@
<VMetaSearchForm
v-if="!fetchState.isFetching"
:type="metaSearchFormType"
- :noresult="noresult"
+ :has-no-result="hasNoResult"
:query="query"
- :supported="isSupported"
+ :is-supported="isSupported"
/>
</section>
+ <VErrorSection v-else-if="!fetchState.isFetching" class="w-full py-10">
+ <template #image>
+ <VErrorImage :error-code="NO_RESULT" />
+ </template>
+ <VNoResults :type="metaSearchFormType" :query="query" />
+ </VErrorSection>
</template>
<script>
@@ -30,11 +36,16 @@ import { computed } from '@nuxtjs/composition-api'
import { ALL_MEDIA, IMAGE, supportedSearchTypes } from '~/constants/media'
+import { NO_RESULT } from '~/constants/errors'
+
import VMetaSearchForm from '~/components/VMetaSearch/VMetaSearchForm.vue'
+import VErrorSection from '~/components/VErrorSection/VErrorSection.vue'
+import VErrorImage from '~/components/VErrorSection/VErrorImage.vue'
+import VNoResults from '~/components/VErrorSection/VNoResults.vue'
export default {
name: 'VSearchGrid',
- components: { VMetaSearchForm },
+ components: { VErrorSection, VMetaSearchForm, VErrorImage, VNoResults },
props: {
supported: {
type: Boolean,
@@ -59,8 +70,8 @@ export default {
},
},
setup(props) {
- const noresult = computed(() => {
- // noresult is hard-coded for search types that are not currently
+ const hasNoResult = computed(() => {
+ // noResult is hard-coded for search types that are not currently
// supported by Openverse built-in search
return props.supported
? props.query.q !== '' && props.resultsCount === 0
@@ -77,10 +88,11 @@ export default {
})
return {
- noresult,
+ hasNoResult,
isSupported,
metaSearchFormType,
isAllView,
+ NO_RESULT,
}
},
}
diff --git a/src/constants/errors.js b/src/constants/errors.js
new file mode 100644
index 000000000..597130533
--- /dev/null
+++ b/src/constants/errors.js
@@ -0,0 +1,9 @@
+/*
+ * Contains constants pertaining to errors that might arise in the application
+ * that lead to the contents being replaced with an error message.
+ */
+
+export const NO_RESULT = 'NO_RESULT'
+export const SERVER_TIMEOUT = 'SERVER_TIMEOUT'
+
+export const errorCodes = [NO_RESULT, SERVER_TIMEOUT]
diff --git a/src/locales/en.json b/src/locales/en.json
index 7857e5018..3b51563a8 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -619,6 +619,17 @@
"modal": {
"close": "Close"
},
+ "error-images": {
+ "depressed-musician": "A depressed pianist rests their head in their hands.",
+ "waiting-for-a-bite": "Three boys sit on a broken log while two of them fish."
+ },
+ "no-results": {
+ "heading": "We couldn't find anything for \"{query}\".",
+ "alternatives": "Try a different query or use one of the additional sources to expand your search."
+ },
+ "server-timeout": {
+ "heading": "Whoops, it looks like that request took too long to complete. Please try again."
+ },
"search-type": {
"image": "Images",
"audio": "Audio",
diff --git a/src/locales/po-files/openverse.pot b/src/locales/po-files/openverse.pot
index d2ae96679..e31560b0e 100644
--- a/src/locales/po-files/openverse.pot
+++ b/src/locales/po-files/openverse.pot
@@ -4,7 +4,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Openverse \n"
"Report-Msgid-Bugs-To: https://github.com/wordpress/openverse/issues \n"
-"POT-Creation-Date: 2022-03-03T03:31:00+00:00\n"
+"POT-Creation-Date: 2022-03-04T04:33:42+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
@@ -62,6 +62,30 @@ msgctxt "search-type.see-audio"
msgid "See all audio"
msgstr ""
+#: src/components/VErrorSection/VServerTimeout.vue:3
+msgctxt "server-timeout.heading"
+msgid "Whoops, it looks like that request took too long to complete. Please try again."
+msgstr ""
+
+#. Do not translate words between ### ###.
+#: src/components/VErrorSection/VNoResults.vue:3
+msgctxt "no-results.heading"
+msgid "We couldn't find anything for \"###query###\"."
+msgstr ""
+
+#: src/components/VErrorSection/VNoResults.vue:5
+msgctxt "no-results.alternatives"
+msgid "Try a different query or use one of the additional sources to expand your search."
+msgstr ""
+
+msgctxt "error-images.depressed-musician"
+msgid "A depressed pianist rests their head in their hands."
+msgstr ""
+
+msgctxt "error-images.waiting-for-a-bite"
+msgid "Three boys sit on a broken log while two of them fish."
+msgstr ""
+
#: src/components/VFilters/VFilterChecklist.vue:44
msgctxt "modal.close"
msgid "Close"
@@ -272,7 +296,7 @@ msgid "Edge"
msgstr ""
#. Do not translate words between ### ###.
-#: src/components/VMetaSearch/VMetaSearchForm.vue:45
+#: src/components/VMetaSearch/VMetaSearchForm.vue:49
msgctxt "meta-search.caption"
msgid "###openverse### does not currently index the sources listed above, but through this interface is offering convenient access to search services provided by other independent organizations. ###openverse### has no control over the results that are returned. Do not assume that the results displayed in this search portal are under a CC license. Always verify that the work is actually under a CC license by following the link. If you are in doubt, you should contact the copyright holder directly, or try to contact the site where you found the content."
msgstr ""
diff --git a/src/utils/attribution-html.js b/src/utils/attribution-html.js
index da2c93eab..0c9df52cd 100644
--- a/src/utils/attribution-html.js
+++ b/src/utils/attribution-html.js
@@ -32,4 +32,32 @@ function getAttributionHtml(media, licenseUrl, fullLicenseName) {
return `<p style="font-size: 0.9rem;font-style: italic;">${mediaTag}${imgLink}${creator}${licenseLink}${licenseImgLink}</p>`
}
+/**
+ * Get the HTML markup for attributing the given media item.
+ *
+ * @param mediaItem - the media item, image or audio from the API, to attribute
+ * @returns {string} the HTML markup of the attribution
+ */
+export const getAttributionMarkup = (mediaItem) => {
+ if (!mediaItem) return ''
+
+ const extLink = (href, text) =>
+ `<a rel="noopener noreferrer" target="_blank" href="${href}">${text}</a>`
+
+ let title = `"${mediaItem.title}"`
+ if (mediaItem.foreign_landing_url) {
+ title = extLink(mediaItem.foreign_landing_url, title)
+ }
+
+ let creator = mediaItem.creator
+ if (mediaItem.creator_url) {
+ creator = extLink(mediaItem.creator_url, creator)
+ }
+
+ let license = `${mediaItem.license} ${mediaItem.license_version}`
+ license = extLink(mediaItem.license_url, license.toUpperCase())
+
+ return `${title} by ${creator} is licensed under ${license}.`
+}
+
export default getAttributionHtml
diff --git a/tailwind.config.js b/tailwind.config.js
index 59994fa9a..2e064017f 100644
--- a/tailwind.config.js
+++ b/tailwind.config.js
@@ -92,6 +92,7 @@ module.exports = {
64: '16.00rem',
70: '17.50rem',
80: '20.00rem',
+ 120: '30.00rem',
},
ringWidth: {
DEFAULT: '1.5px',
diff --git a/test/e2e/search.spec.js b/test/e2e/search.spec.js
index ac0fb034a..c1ac308b1 100644
--- a/test/e2e/search.spec.js
+++ b/test/e2e/search.spec.js
@@ -39,6 +39,11 @@ test.skip('shows search result metadata', async ({ page }) => {
await expect(loadMoreButton).toHaveCount(0, { timeout: 300 })
})
+test('shows no results page when no results', async ({ page }) => {
+ await page.goto('/search/image?q=243f6a8885a308d3')
+ await expect(page.locator('.error-section')).toBeVisible()
+})
+
test('navigates to the image detail page correctly', async ({ page }) => {
await page.goto('/search/image?q=honey')
const figure = page.locator('figure').first()