Skip to content

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

Give licenses the full name and retire `LicenseIcons` (#422)

Krystle Salazar08020082928b
diff --git a/src/components/Filters/FilterChecklist.vue b/src/components/Filters/FilterChecklist.vue
index 8c11cd2e1..bca060783 100644
--- a/src/components/Filters/FilterChecklist.vue
+++ b/src/components/Filters/FilterChecklist.vue
@@ -57,7 +57,7 @@
<script>
import LicenseExplanationTooltip from '~/components/Filters/LicenseExplanationTooltip'
-import VLicense from '~/components/License/VLicense'
+import VLicense from '~/components/License/VLicense.vue'
export default {
name: 'FilterCheckList',
diff --git a/src/components/ImageGrid/ImageCell.vue b/src/components/ImageGrid/ImageCell.vue
index 635eda874..e499f53fc 100644
--- a/src/components/ImageGrid/ImageCell.vue
+++ b/src/components/ImageGrid/ImageCell.vue
@@ -27,7 +27,11 @@
/>
</NuxtLink>
<figcaption class="overlay overlay__top p-2">
- <LicenseIcons :license="image.license" />
+ <VLicense
+ :license="image.license"
+ :bg-filled="true"
+ :hide-name="true"
+ />
</figcaption>
<figcaption class="overlay overlay__bottom py-2 px-4">
<span class="caption font-semibold">{{ image.title }}</span>
@@ -38,6 +42,7 @@
<script>
import getProviderLogo from '~/utils/get-provider-logo'
+import VLicense from '~/components/License/VLicense.vue'
const errorImage = require('~/assets/image_not_available_placeholder.png')
@@ -55,6 +60,7 @@ const toAbsolutePath = (url, prefix = 'https://') => {
export default {
name: 'ImageCell',
+ components: { VLicense },
props: ['image', 'shouldContainImage'],
data() {
return {
diff --git a/src/components/License/VLicense.vue b/src/components/License/VLicense.vue
index 6670df49b..3cb895620 100644
--- a/src/components/License/VLicense.vue
+++ b/src/components/License/VLicense.vue
@@ -1,16 +1,27 @@
<template>
<div class="license flex flex-row items-center gap-2">
<div class="flex gap-1">
- <VIcon v-if="isCC" :size="4" view-box="0 0 30 30" :icon-path="ccLogo" />
+ <VIcon
+ v-if="isCC"
+ :class="['icon', bgFilled ? 'bg-filled text-black' : '']"
+ view-box="0 0 30 30"
+ :icon-path="ccLogo"
+ :size="4"
+ />
<VIcon
v-for="(name, index) in icons"
:key="index"
- :size="4"
+ :class="['icon', bgFilled ? 'bg-filled text-black' : '']"
view-box="0 0 30 30"
:icon-path="svgs[name]"
+ :size="4"
/>
</div>
- <span class="name">
+ <span
+ v-if="!hideName"
+ class="name"
+ :aria-label="$t(`license-readable-names.${license}`)"
+ >
{{ $t(`license-names.${license}`) }}
</span>
</div>
@@ -52,6 +63,20 @@ export default {
required: true,
validator: (val) => ALL_LICENSES.includes(val),
},
+ /**
+ * Whether to display icons filled with a white background or leave them transparent.
+ */
+ bgFilled: {
+ type: Boolean,
+ default: false,
+ },
+ /**
+ * Either to show the license name next to the icons or hide it.
+ */
+ hideName: {
+ type: Boolean,
+ default: false,
+ },
},
setup(props) {
const icons = computed(() =>
@@ -78,3 +103,14 @@ export default {
},
}
</script>
+
+<style scoped>
+.icon {
+ height: 1.1667em;
+ width: 1.1667em;
+}
+
+.bg-filled {
+ background-image: radial-gradient(circle, #ffffff 60%, transparent 60%);
+}
+</style>
diff --git a/src/components/License/meta/VLicense.stories.mdx b/src/components/License/meta/VLicense.stories.mdx
index 2304ac20d..6cbdd10d1 100644
--- a/src/components/License/meta/VLicense.stories.mdx
+++ b/src/components/License/meta/VLicense.stories.mdx
@@ -6,7 +6,7 @@ import {
Story,
} from '@storybook/addon-docs'
-import VLicense from '~/components/License/VLicense'
+import VLicense from '~/components/license/VLicense.vue'
<Meta title="Components/VLicense" component={VLicense} />
@@ -109,3 +109,17 @@ It can also display some public domain licenses.
{Template.bind({})}
</Story>
</Canvas>
+
+It can also show only the license icons.
+
+<Canvas>
+ <Story
+ name="Only icons"
+ args={{
+ license: 'by-nc-sa',
+ hideName: true,
+ }}
+ >
+ {Template.bind({})}
+ </Story>
+</Canvas>
diff --git a/src/components/LicenseIcons.vue b/src/components/LicenseIcons.vue
deleted file mode 100644
index 16410730a..000000000
--- a/src/components/LicenseIcons.vue
+++ /dev/null
@@ -1,65 +0,0 @@
-<template>
- <span class="photo-license-icons">
- <i
- class="icon cc-logo text-lgr text-black has-background-white filter-icon"
- title="CC"
- >
- <!-- Closing i and opening template tag must be adjacent to prevent whitespace --> </i
- ><template v-for="(l, i) in getLicenseIcon(license)">
- <i
- v-if="l"
- :key="i"
- :class="{
- icon: true,
- ['text-black']: true,
- ['has-background-white']: true,
- ['text-lgr']: true,
- [`cc-${l}`]: true,
- ['filter-icon']: true,
- }"
- :alt="`${l.toUpperCase()}`"
- />
- </template>
- </span>
-</template>
-
-<script>
-const APItoIconNameMap = {
- by: 'by',
- nc: 'nc',
- nd: 'nd',
- sa: 'sa',
- cc0: 'zero',
- pdm: 'pd',
-}
-
-const LicenseIcons = {
- name: 'license-icons',
- props: {
- license: '',
- },
- methods: {
- getLicenseIcon(license) {
- let licenses = []
- if (license) {
- licenses = license.split('-')
- }
- return licenses.map((l) => APItoIconNameMap[l])
- },
- },
-}
-
-export default LicenseIcons
-</script>
-
-<!-- Add "scoped" attribute to limit CSS to this component only -->
-<style lang="scss" scoped>
-.icon {
- vertical-align: middle;
- margin-right: 0.3rem;
-}
-.photo-license-icons {
- display: inline-block;
- margin-right: 0.188rem;
-}
-</style>
diff --git a/src/components/SearchGridCell.vue b/src/components/SearchGridCell.vue
index 7edb81bb5..05858ecd6 100644
--- a/src/components/SearchGridCell.vue
+++ b/src/components/SearchGridCell.vue
@@ -27,7 +27,11 @@
/>
</NuxtLink>
<figcaption class="overlay overlay__top p-2">
- <LicenseIcons :license="image.license" />
+ <VLicense
+ :license="image.license"
+ :bg-filled="true"
+ :hide-name="true"
+ />
</figcaption>
<figcaption class="overlay overlay__bottom py-2 px-4">
<span class="caption font-semibold">{{ image.title }}</span>
@@ -37,8 +41,8 @@
</template>
<script>
-import LicenseIcons from '~/components/LicenseIcons'
import getProviderLogo from '~/utils/get-provider-logo'
+import VLicense from '~/components/License/VLicense.vue'
const errorImage = require('~/assets/image_not_available_placeholder.png')
@@ -56,9 +60,7 @@ const toAbsolutePath = (url, prefix = 'https://') => {
export default {
name: 'SearchGridCell',
- components: {
- LicenseIcons,
- },
+ components: { VLicense },
props: ['image', 'shouldContainImage'],
data() {
return {
diff --git a/src/locales/en.json b/src/locales/en.json
index 1ecd9807f..abd897a5d 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -641,6 +641,16 @@
"by-nc-sa": "BY-NC-SA",
"by-nc-nd": "BY-NC-ND"
},
+ "license-readable-names": {
+ "cc0": "Zero",
+ "pdm": "Public Domain Mark",
+ "by": "Attribution",
+ "by-sa": "Attribution-Share-Alike",
+ "by-nc": "Attribution-NonCommercial",
+ "by-nd": "Attribution-NoDerivatives",
+ "by-nc-sa": "Attribution-NonCommercial-Share-Alike",
+ "by-nc-nd": "Attribution-NonCommercial-NoDerivatives"
+ },
"dropdown-button": {
"aria": {
"arrow-label": "Dropdown"
diff --git a/src/locales/po-files/openverse.pot b/src/locales/po-files/openverse.pot
index 5437a25e3..2fc5ec1b2 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: 2021-11-29T14:32:09+00:00\n"
+"POT-Creation-Date: 2021-11-30T16:26:14+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
@@ -49,6 +49,38 @@ msgctxt "dropdown-button.aria.arrow-label"
msgid "Dropdown"
msgstr ""
+msgctxt "license-readable-names.cc0"
+msgid "Zero"
+msgstr ""
+
+msgctxt "license-readable-names.pdm"
+msgid "Public Domain Mark"
+msgstr ""
+
+msgctxt "license-readable-names.by"
+msgid "Attribution"
+msgstr ""
+
+msgctxt "license-readable-names.by-sa"
+msgid "Attribution-Share-Alike"
+msgstr ""
+
+msgctxt "license-readable-names.by-nc"
+msgid "Attribution-NonCommercial"
+msgstr ""
+
+msgctxt "license-readable-names.by-nd"
+msgid "Attribution-NoDerivatives"
+msgstr ""
+
+msgctxt "license-readable-names.by-nc-sa"
+msgid "Attribution-NonCommercial-Share-Alike"
+msgstr ""
+
+msgctxt "license-readable-names.by-nc-nd"
+msgid "Attribution-NonCommercial-NoDerivatives"
+msgstr ""
+
msgctxt "license-names.cc0"
msgid "CC0"
msgstr ""
@@ -702,7 +734,7 @@ msgctxt "browse-page.aria.scroll"
msgid "scroll to top"
msgstr ""
-#: src/components/SearchGridForm.vue:26
+#: src/components/SearchGridForm.vue:25
msgctxt "browse-page.aria.search"
msgid "search"
msgstr ""
@@ -775,7 +807,7 @@ msgid "This work is marked as being in the public domain."
msgstr ""
#. Do not translate words between ### ###.
-#: src/components/SearchGridForm.vue:82
+#: src/components/SearchGridForm.vue:79
msgctxt "browse-page.search-form.placeholder"
msgid "Search all ###type###"
msgstr ""
@@ -802,7 +834,7 @@ msgctxt "browse-page.search-form.collection-placeholder"
msgid "Search this collection"
msgstr ""
-#: src/components/SearchGridForm.vue:54
+#: src/components/SearchGridForm.vue:52
msgctxt "browse-page.search-form.button"
msgid "Search"
msgstr ""
@@ -852,7 +884,7 @@ msgctxt "filter-list.category-aria"
msgid "filters list for ###categoryName### category"
msgstr ""
-#: src/components/SearchGridForm.vue:16
+#: src/components/SearchGridForm.vue:15
msgctxt "filters.title"
msgid "Filters"
msgstr ""
@@ -1105,13 +1137,13 @@ msgid "An error occurred"
msgstr ""
#. Do not translate words between ### ###.
-#: src/pages/photos/_id.vue:58
+#: src/pages/photos/_id.vue:54
msgctxt "error.image-not-found"
msgid "Couldn't find image with id ###id###"
msgstr ""
#. Do not translate words between ### ###.
-#: src/pages/audio/_id.vue:74
+#: src/pages/audio/_id.vue:70
msgctxt "error.media-not-found"
msgid "Couldn't find ###mediaType### with id ###id###"
msgstr ""
@@ -1145,7 +1177,7 @@ msgctxt "extension.title"
msgid "Web extension"
msgstr ""
-#: src/pages/extension.vue:65
+#: src/pages/extension.vue:61
msgctxt "extension.conclusion"
msgid "Have your favourite content while browsing the web"
msgstr ""
@@ -1936,17 +1968,17 @@ msgctxt "header.source-nav-item"
msgid "Sources"
msgstr ""
-#: src/components/NavSection.vue:100
+#: src/components/NavSection.vue:103
msgctxt "header.search-guide-nav-item"
msgid "Search Guide"
msgstr ""
-#: src/components/NavSection.vue:108
+#: src/components/NavSection.vue:111
msgctxt "header.meta-search-nav-item"
msgid "Meta Search"
msgstr ""
-#: src/components/NavSection.vue:116
+#: src/components/NavSection.vue:119
msgctxt "header.feedback-nav-item"
msgid "Feedback"
msgstr ""
@@ -1955,12 +1987,12 @@ msgctxt "header.support-nav-item"
msgid "Support Us"
msgstr ""
-#: src/components/NavSection.vue:131
+#: src/components/NavSection.vue:134
msgctxt "header.extension-nav-item"
msgid "Web extension"
msgstr ""
-#: src/components/NavSection.vue:169
+#: src/components/NavSection.vue:172
msgctxt "header.placeholder"
msgid "Search all content"
msgstr ""
@@ -1970,17 +2002,17 @@ msgctxt "header.licenses-nav-item"
msgid "The Licenses"
msgstr ""
-#: src/components/NavSection.vue:64
+#: src/components/NavSection.vue:63
msgctxt "header.about-tab"
msgid "About"
msgstr ""
-#: src/components/NavSection.vue:93
+#: src/components/NavSection.vue:95
msgctxt "header.resources-tab"
msgid "Resources"
msgstr ""
-#: src/components/NavSection.vue:125
+#: src/components/NavSection.vue:128
msgctxt "header.api-nav-item"
msgid "API"
msgstr ""
@@ -2002,17 +2034,17 @@ msgctxt "header.aria.primary"
msgid "primary"
msgstr ""
-#: src/components/NavSection.vue:26
+#: src/components/NavSection.vue:23
msgctxt "header.aria.menu"
msgid "menu"
msgstr ""
-#: src/components/NavSection.vue:46
+#: src/components/NavSection.vue:43
msgctxt "header.aria.search"
msgid "search"
msgstr ""
-#: src/components/NavSection.vue:53
+#: src/components/NavSection.vue:50
msgctxt "header.aria.sr-search"
msgid "sr search button"
msgstr ""
diff --git a/test/unit/specs/components/AudioTrack/audio-track.spec.js b/test/unit/specs/components/AudioTrack/audio-track.spec.js
index 494ed57b1..5014e104c 100644
--- a/test/unit/specs/components/AudioTrack/audio-track.spec.js
+++ b/test/unit/specs/components/AudioTrack/audio-track.spec.js
@@ -22,7 +22,7 @@ const stubs = {
DownloadButton: true,
PlayPause: true,
NuxtLink: true,
- VIcon: true,
+ VLicense: true,
Waveform: true,
}
diff --git a/test/unit/specs/components/image-grid.spec.js b/test/unit/specs/components/image-grid.spec.js
index 6e3ba6952..c4ee2a45b 100644
--- a/test/unit/specs/components/image-grid.spec.js
+++ b/test/unit/specs/components/image-grid.spec.js
@@ -11,7 +11,7 @@ const propsData = {
}
const options = {
props: propsData,
- stubs: ['NuxtLink', 'LicenseIcons'],
+ stubs: ['NuxtLink', 'VLicense'],
}
describe('ImageGrid', () => {
it('renders images without load more button if canLoadMore is false', () => {
diff --git a/test/unit/specs/components/license-icons.spec.js b/test/unit/specs/components/license-icons.spec.js
deleted file mode 100644
index 86f05c3ae..000000000
--- a/test/unit/specs/components/license-icons.spec.js
+++ /dev/null
@@ -1,60 +0,0 @@
-import LicenseIcons from '~/components/LicenseIcons'
-import render from '../../test-utils/render'
-
-describe('LicenseIcons', () => {
- let options = null
- let props = null
- let license = null
-
- beforeEach(() => {
- license = 'by'
- props = {
- license,
- }
-
- options = {
- propsData: props,
- }
- })
-
- it('should render correct contents', () => {
- const wrapper = render(LicenseIcons, options)
- expect(wrapper.find('.photo-license-icons').element).toBeDefined()
- })
-
- it('should generate CC BY icons', () => {
- const wrapper = render(LicenseIcons, options)
- expect(wrapper.find('.cc-logo').element).toBeDefined()
- expect(wrapper.find('.cc-by').element).toBeDefined()
- })
-
- it('should generate CC BY SA icons', () => {
- props.license = 'by-sa'
- const wrapper = render(LicenseIcons, options)
- expect(wrapper.find('.cc-logo').element).toBeDefined()
- expect(wrapper.find('.cc-by').element).toBeDefined()
- expect(wrapper.find('.cc-sa').element).toBeDefined()
- })
-
- it('should generate CC BY ND icons', () => {
- props.license = 'by-nd'
- const wrapper = render(LicenseIcons, options)
- expect(wrapper.find('.cc-logo').element).toBeDefined()
- expect(wrapper.find('.cc-by').element).toBeDefined()
- expect(wrapper.find('.cc-nd').element).toBeDefined()
- })
-
- it('should generate CC0 icons', () => {
- props.license = 'cc0'
- const wrapper = render(LicenseIcons, options)
- expect(wrapper.find('.cc-logo').element).toBeDefined()
- expect(wrapper.find('.cc-zero').element).toBeDefined()
- })
-
- it('should generate PDM icons', () => {
- props.license = 'pdm'
- const wrapper = render(LicenseIcons, options)
- expect(wrapper.find('.cc-logo').element).toBeDefined()
- expect(wrapper.find('.cc-pd').element).toBeDefined()
- })
-})
diff --git a/test/unit/specs/components/related-images.spec.js b/test/unit/specs/components/related-images.spec.js
index bde9d3ac5..8adf730db 100644
--- a/test/unit/specs/components/related-images.spec.js
+++ b/test/unit/specs/components/related-images.spec.js
@@ -37,7 +37,7 @@ describe('RelatedImage', () => {
options = {
localVue,
propsData: props,
- stubs: ['LicenseIcons', 'NuxtLink'],
+ stubs: ['VLicense', 'NuxtLink'],
}
})
it('should render an image grid', async () => {
diff --git a/test/unit/specs/components/search-grid-cell.spec.js b/test/unit/specs/components/search-grid-cell.spec.js
index eafeffe5f..30595a816 100644
--- a/test/unit/specs/components/search-grid-cell.spec.js
+++ b/test/unit/specs/components/search-grid-cell.spec.js
@@ -14,7 +14,7 @@ describe('SearchGridCell', () => {
}
const options = {
propsData: props,
- stubs: { RouterLink: true, NuxtLink: true },
+ stubs: ['NuxtLink', 'VLicense'],
}
it('should render correct contents', () => {
diff --git a/test/unit/specs/components/search-grid.spec.js b/test/unit/specs/components/search-grid.spec.js
index faf7d6d20..2b3d9a5ae 100644
--- a/test/unit/specs/components/search-grid.spec.js
+++ b/test/unit/specs/components/search-grid.spec.js
@@ -85,7 +85,7 @@ describe('SearchGrid', () => {
MetaSearchForm: true,
NuxtLink: true,
// SaferBrowsing: true,
- LicenseIcons: true,
+ VLicense: true,
},
store: storeMock,
localVue,
diff --git a/test/unit/specs/components/v-license.spec.js b/test/unit/specs/components/v-license.spec.js
new file mode 100644
index 000000000..7253d189e
--- /dev/null
+++ b/test/unit/specs/components/v-license.spec.js
@@ -0,0 +1,37 @@
+import VLicense from '~/components/License/VLicense'
+import { render, screen } from '@testing-library/vue'
+
+describe('VLicense', () => {
+ let options = {
+ props: {
+ license: 'by',
+ },
+ }
+
+ it('should render the license name and icons', () => {
+ const { container } = render(VLicense, options)
+ const licenseName = screen.getByLabelText('license-readable-names.by')
+ expect(licenseName).toBeInTheDocument()
+ const licenseIcons = container.querySelectorAll('svg')
+ expect(licenseIcons).toHaveLength(2) // 'CC' and 'BY' icons
+ })
+
+ it('should render only the license icons', () => {
+ options.props.hideName = true
+ const { container } = render(VLicense, options)
+ const licenseName = screen.queryByLabelText('license-readable-names.by')
+ expect(licenseName).not.toBeInTheDocument()
+ const licenseIcons = container.querySelectorAll('svg')
+ expect(licenseIcons).toHaveLength(2)
+ })
+
+ it('should have background filled with black text', () => {
+ options.props.bgFilled = true
+ const { container } = render(VLicense, options)
+ const licenseIcons = container.querySelectorAll('svg')
+ expect(licenseIcons).toHaveLength(2)
+ licenseIcons.forEach((icon) => {
+ expect(icon).toHaveClass('bg-filled', 'text-black')
+ })
+ })
+})