Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Create VSourcesTable component #1317

Merged
merged 4 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
"@testing-library/vue": "^5.8.2",
"@types/express-useragent": "^1.0.2",
"@types/jest": "^26.0.22",
"@types/lodash.sortby": "^4.7.7",
"@types/module-alias": "^2.0.1",
"@types/uuid": "^8.3.4",
"@typescript-eslint/eslint-plugin": "^5.17.0",
Expand Down
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 6 additions & 10 deletions src/components/TableSortIcon.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="flex flex-col" :class="[active ? activeClass : inactiveClass]">
<div class="flex flex-col" :class="[active ? 'text-dark-blue' : 'text-gray']">
<svg
width="12"
height="6"
Expand All @@ -24,20 +24,16 @@
</div>
</template>

<script>
export default {
<script lang="ts">
import { defineComponent } from '@nuxtjs/composition-api'

export default defineComponent({
name: 'TableSortIcon',
props: {
active: {
type: Boolean,
required: true,
},
},
data() {
return {
activeClass: 'text-dark-blue',
inactiveClass: 'text-gray',
}
},
}
})
</script>
173 changes: 173 additions & 0 deletions src/components/VSourcesTable.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
<template>
<table
:aria-label="$t('sources.aria.table').toString()"
role="region"
class="table table-fixed w-full mt-4 mb-10 not-prose text-base"
>
<thead>
<tr>
<th
tabindex="0"
@click="sortTable('display_name')"
@keypress.enter="sortTable('display_name')"
>
<span class="w-full flex flex-row items-center justify-between">
{{ $t('sources.providers.source') }}
<TableSortIcon :active="sorting.field === 'display_name'" />
</span>
</th>
<th
tabindex="0"
@click="sortTable('source_url')"
@keypress.enter="sortTable('source_url')"
>
<span class="w-full flex flex-row items-center justify-between">
{{ $t('sources.providers.domain') }}
<TableSortIcon :active="sorting.field === 'source_url'" />
</span>
</th>
<th
tabindex="0"
@click="sortTable('media_count')"
@keypress.enter="sortTable('media_count')"
>
<span class="w-full flex flex-row items-center justify-between">
{{ $t('sources.providers.item') }}
<TableSortIcon :active="sorting.field === 'media_count'" />
</span>
</th>
</tr>
</thead>
<tbody>
<tr v-for="(provider, index) in sortedProviders" :key="index">
<td>
{{ provider.display_name }}
</td>
<td class="font-semibold truncate">
<VLink :href="provider.source_url">
{{ cleanSourceUrlForPresentation(provider.source_url) }}
</VLink>
</td>
<td class="text-right">
{{ getLocaleFormattedNumber(provider.media_count || 0) }}
</td>
</tr>
</tbody>
</table>
</template>

<script lang="ts">
import sortBy from 'lodash.sortby'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL lodash.sortby is over 2300 LOC 😱 Good thing we have #1108 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤯

import {
computed,
defineComponent,
PropType,
reactive,
} from '@nuxtjs/composition-api'

import { useProviderStore } from '~/stores/provider'
import { useGetLocaleFormattedNumber } from '~/composables/use-get-locale-formatted-number'

import type { SupportedMediaType } from '~/constants/media'

import TableSortIcon from '~/components/TableSortIcon.vue'
import VLink from '~/components/VLink.vue'

import externalLinkIcon from '~/assets/icons/external-link.svg'

export default defineComponent({
name: 'VSourcesTable',
components: {
TableSortIcon,
VLink,
},
props: {
media: {
type: String as PropType<SupportedMediaType>,
required: true,
},
},
setup(props) {
const sorting = reactive({
direction: 'asc',
field: 'display_name',
})

function sortTable(field: string) {
let direction = 'asc'
if (field === sorting.field) {
direction = sorting.direction === 'asc' ? 'desc' : 'asc'
}

sorting.direction = direction
sorting.field = field
}
function cleanSourceUrlForPresentation(url: string) {
const stripProtocol = (s: string) => s.replace(/https?:\/\//, '')
const stripLeadingWww = (s: string) =>
s.startsWith('www.') ? s.replace('www.', '') : s
const removeAfterSlash = (s: string) => s.split('/')[0]

return removeAfterSlash(stripLeadingWww(stripProtocol(url)))
}
const getLocaleFormattedNumber = useGetLocaleFormattedNumber()
const providerStore = useProviderStore()

const sortedProviders = computed(() => {
const sorted = sortBy(providerStore.providers[props.media], [
sorting.field,
])
return sorting.direction === 'asc' ? sorted : sorted.reverse()
})
return {
getLocaleFormattedNumber,
externalLinkIcon,
sortedProviders,
sorting,
sortTable,
cleanSourceUrlForPresentation,
}
},
})
</script>

<style scoped>
@tailwind base;
@tailwind components;
@tailwind utilities;

@layer components {
.table {
@apply border-0 rounded-sm border-separate border-dark-charcoal-20;
}
.table th,
.table td {
@apply border-dark-charcoal-20;
}
.table a {
@apply text-pink hover:underline;
}
.table th {
@apply bg-dark-charcoal-10 border-t cursor-pointer;
}
.table th,
.table td {
@apply p-4 border-r first:border-l;
}
.table td {
@apply break-normal border-y-0;
}

.table tr {
@apply even:bg-dark-charcoal-06;
}

.table th {
@apply first:rounded-tl-sm last:rounded-tr-sm;
}

.table tr:last-child td {
@apply first:rounded-bl-sm last:rounded-br-sm border-b;
}
}
</style>
10 changes: 7 additions & 3 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@
"cc-content": {
"where": "Where does the content on {openverse} come from?",
"content": "There is openly licensed content hosted on millions of domains across the breadth of the internet. Our team systematically identifies providers hosting CC-licensed content. If it’s a good fit, we index that content and make it discoverable through {openverse}.",
"provider": "Some providers have multiple different groupings of content within them. {flickr} has sources ranging from NASA to personal photography. The {smithsonian} comprises a dozen, diverse collections. Wikimedia Commons runs the gamut in terms of content, and is used by several Galleries, Libraries, Archives, and Museums highlighting some or all of their digitized collections.",
"europeana": "{openverse} is especially grateful for the work of {link}, an organization that works to digitize and make discoverable cultural heritage works across Europe. {openverse} is able to index hundreds of valuable sources, through a single integration with the {link-api}.",
"provider": "Some providers have multiple different groupings of content within them. {flickr} has sources ranging from NASA to personal photography. The {smithsonian} comprises a dozen diverse collections. Wikimedia Commons runs the gamut in terms of content, and is used by several Galleries, Libraries, Archives, and Museums highlighting some or all of their digitized collections.",
"europeana": "{openverse} is especially grateful for the work of {link}, an organization that works to digitize and make discoverable cultural heritage works across Europe. {openverse} is able to index hundreds of valuable sources through a single integration with the {link-api}.",
"europeana-api": "Europeana API",
"smithsonian": "Smithsonian Institute"
},
Expand All @@ -108,7 +108,11 @@
},
"suggestions": "We appreciate suggestions for new sources from our community of users.",
"issue-button": "Suggest a new source",
"aria": { "table": "sources table" }
"aria": { "table": "sources table" },
"heading": {
"image": "Image Sources",
"audio": "Audio Sources"
}
},
"meta-search-page": {
"title": "Meta Search",
Expand Down
20 changes: 15 additions & 5 deletions src/locales/po-files/openverse.pot
Original file line number Diff line number Diff line change
Expand Up @@ -1606,7 +1606,17 @@ msgctxt "sources.issue-button"
msgid "Suggest a new source"
msgstr ""

#: src/pages/sources.vue:77
msgctxt "sources.heading.image"
msgid "Image Sources"
msgstr ""

#: src/pages/sources.vue:79
msgctxt "sources.heading.audio"
msgid "Audio Sources"
msgstr ""

#: src/components/VSourcesTable.vue:3
msgctxt "sources.aria.table"
msgid "sources table"
msgstr ""
Expand Down Expand Up @@ -1651,13 +1661,13 @@ msgstr ""
#. Do not translate words between ### ###.
#: src/pages/sources.vue:13
msgctxt "sources.cc-content.provider"
msgid "Some providers have multiple different groupings of content within them. ###flickr### has sources ranging from NASA to personal photography. The ###smithsonian### comprises a dozen, diverse collections. Wikimedia Commons runs the gamut in terms of content, and is used by several Galleries, Libraries, Archives, and Museums highlighting some or all of their digitized collections."
msgid "Some providers have multiple different groupings of content within them. ###flickr### has sources ranging from NASA to personal photography. The ###smithsonian### comprises a dozen diverse collections. Wikimedia Commons runs the gamut in terms of content, and is used by several Galleries, Libraries, Archives, and Museums highlighting some or all of their digitized collections."
msgstr ""

#. Do not translate words between ### ###.
#: src/pages/sources.vue:23
msgctxt "sources.cc-content.europeana"
msgid "###openverse### is especially grateful for the work of ###link###, an organization that works to digitize and make discoverable cultural heritage works across Europe. ###openverse### is able to index hundreds of valuable sources, through a single integration with the ###link-api###."
msgid "###openverse### is especially grateful for the work of ###link###, an organization that works to digitize and make discoverable cultural heritage works across Europe. ###openverse### is able to index hundreds of valuable sources through a single integration with the ###link-api###."
msgstr ""

#: src/pages/sources.vue:30
Expand All @@ -1670,17 +1680,17 @@ msgctxt "sources.cc-content.smithsonian"
msgid "Smithsonian Institute"
msgstr ""

#: src/pages/sources.vue:91
#: src/components/VSourcesTable.vue:15
msgctxt "sources.providers.source"
msgid "Source"
msgstr ""

#: src/pages/sources.vue:101
#: src/components/VSourcesTable.vue:25
msgctxt "sources.providers.domain"
msgid "Domain"
msgstr ""

#: src/pages/sources.vue:111
#: src/components/VSourcesTable.vue:35
msgctxt "sources.providers.item"
msgid "Total items"
msgstr ""
Expand Down
Loading