Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the sources table crash #4725

Merged
merged 6 commits into from
Aug 7, 2024
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
31 changes: 18 additions & 13 deletions frontend/src/components/VSourcesTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</tr>
</thead>
<tbody>
<tr v-for="provider in sortedProviders" :key="provider.display_name">
<tr v-for="provider in providers" :key="provider.display_name">
<td>
<VLink :href="providerViewUrl(provider)">{{
provider.display_name
Expand All @@ -60,7 +60,7 @@

<section role="region" class="mobile-source-table md:hidden">
<article
v-for="provider in sortedProviders"
v-for="provider in providers"
:key="provider.display_name"
:title="provider.display_name"
>
Expand All @@ -87,7 +87,7 @@
</template>

<script lang="ts">
import { computed, defineComponent, type PropType, reactive } from "vue"
import { defineComponent, type PropType, reactive, ref } from "vue"

import { useProviderStore } from "~/stores/provider"
import { useGetLocaleFormattedNumber } from "~/composables/use-get-locale-formatted-number"
Expand All @@ -113,19 +113,32 @@ export default defineComponent({
},
},
setup(props) {
const providerStore = useProviderStore()
const searchStore = useSearchStore()

const sorting = reactive({
direction: "asc",
field: "display_name" as keyof Omit<MediaProvider, "logo_url">,
})

// The providers in store are sorted by `source_name`, here we sort them by `display_name`.
const providers = ref<MediaProvider[]>(
providerStore.providers[props.media].sort(compareProviders)
)

function sortTable(field: keyof Omit<MediaProvider, "logo_url">) {
let direction = "asc"
let direction = field === "media_count" ? "desc" : "asc"
if (field === sorting.field) {
direction = sorting.direction === "asc" ? "desc" : "asc"
}

sorting.direction = direction
sorting.field = field

const sortedProviders = providers.value.sort(compareProviders)

providers.value =
direction === "asc" ? sortedProviders : sortedProviders.reverse()
}

function cleanSourceUrlForPresentation(url: string) {
Expand All @@ -138,7 +151,6 @@ export default defineComponent({
}

const getLocaleFormattedNumber = useGetLocaleFormattedNumber()
const providerStore = useProviderStore()

function compareProviders(prov1: MediaProvider, prov2: MediaProvider) {
let field1 = prov1[sorting.field]
Expand All @@ -161,13 +173,6 @@ export default defineComponent({
return 0
}

const sortedProviders = computed<MediaProvider[]>(() => {
const providers = providerStore.providers[props.media]
providers.sort(compareProviders)
return sorting.direction === "asc" ? providers : providers.reverse()
})

const searchStore = useSearchStore()
const providerViewUrl = (provider: MediaProvider) => {
return searchStore.getCollectionPath({
type: props.media,
Expand All @@ -179,7 +184,7 @@ export default defineComponent({
}
return {
getLocaleFormattedNumber,
sortedProviders,
providers,
sorting,
sortTable,
cleanSourceUrlForPresentation,
Expand Down
1 change: 1 addition & 0 deletions frontend/src/pages/sources.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ useHead({ title: `${t("sources.title")} | Openverse` })
<VLink href="https://www.si.edu/">Smithsonian Institute</VLink>
</template>
</i18n-t>
{{ " " }}
<i18n-t
scope="global"
keypath="sources.ccContent.provider.b"
Expand Down
14 changes: 14 additions & 0 deletions frontend/test/playwright/e2e/sources.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,17 @@ test("sources table has links to source pages", async ({ page }) => {

await expect(getH1(page, "Flickr")).toBeVisible()
})

// Tests the fix for https://github.com/WordPress/openverse/issues/4724
test("sources table can be sorted multiple times", async ({ page }) => {
await preparePageForTests(page, "xl")
await page.goto("/sources")

const totalItems = page.getByRole("cell", { name: /total items/i }).first()
await totalItems.click()
await totalItems.click()
await totalItems.click()

const firstRow = page.getByRole("row", { name: "Flickr" })
await expect(firstRow).toBeVisible()
})
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ for (const contentPage of contentPages) {
{
fullPage: true,
},
{ maxDiffPixelRatio: 0.01 }
{ maxDiffPixelRatio: 0.005 }
)
})
})
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 9 additions & 9 deletions frontend/test/unit/specs/components/v-sources-table.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ describe("VSourcesTable", () => {
providerStore.$patch({
providers: {
image: [
{
source_name: "Provider_A",
display_name: "Provider A",
source_url: "https://zzz.com",
media_count: 3333,
},
{
source_name: "Provider_B",
display_name: "Provider B",
Expand All @@ -38,12 +44,6 @@ describe("VSourcesTable", () => {
source_url: "www.xxx.com",
media_count: 2222,
},
{
source_name: "Provider_A",
display_name: "Provider A",
source_url: "https://zzz.com",
media_count: 3333,
},
],
},
})
Expand All @@ -55,7 +55,7 @@ describe("VSourcesTable", () => {
}
})

it('should be sorted by display_name ("Source") by default', async () => {
it('should use the provider store default sorting by display_name ("Source") by default', async () => {
await render(VSourcesTable, options)

const table = getTableData(screen.getAllByRole("row"))
Expand Down Expand Up @@ -90,9 +90,9 @@ describe("VSourcesTable", () => {
await userEvent.click(domainCell)
const table = getTableData(screen.getAllByRole("row"))
const expectedTable = [
["Provider B", "yyy.com", "1,111"],
["Provider C", "xxx.com", "2,222"],
["Provider A", "zzz.com", "3,333"],
["Provider C", "xxx.com", "2,222"],
["Provider B", "yyy.com", "1,111"],
]
expect(table).toEqual(expectedTable)
})
Expand Down