@museumwnf/viewer-core 2.25.0 → 2.25.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { computed, toValue } from 'vue'
|
|
1
|
+
import { computed, toValue, watchEffect } from 'vue'
|
|
2
2
|
import { useDataPackage } from '../composables/useDataPackage.js'
|
|
3
3
|
import { entityRef } from '../composables/useEntities.js'
|
|
4
4
|
import { useI18n } from '../i18n/index.js'
|
|
@@ -42,6 +42,19 @@ export function useCatalogueResults(spec, { entity: routeEntity = '' } = {}) {
|
|
|
42
42
|
]
|
|
43
43
|
const { filters, page, active, apply, reset, goToPage } = useListQuery({ keys })
|
|
44
44
|
|
|
45
|
+
// A URL value in an older spelling (a legacy country code) is turned into
|
|
46
|
+
// the facet's own as soon as the facet can read it, so the controls bound
|
|
47
|
+
// to `filters`, the options they match and the summary all see the value
|
|
48
|
+
// the records carry. Re-runs when the route writes the old spelling back.
|
|
49
|
+
watchEffect(() => {
|
|
50
|
+
for (const [key, facet] of Object.entries(current.value.facets ?? {})) {
|
|
51
|
+
const value = filters[key]
|
|
52
|
+
if (!facet.canonical || !value) continue
|
|
53
|
+
const wanted = facet.canonical(value)
|
|
54
|
+
if (wanted != null && String(wanted) !== value) filters[key] = String(wanted)
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
|
|
45
58
|
const helpers = {
|
|
46
59
|
t,
|
|
47
60
|
locale,
|
|
@@ -55,7 +68,9 @@ export function useCatalogueResults(spec, { entity: routeEntity = '' } = {}) {
|
|
|
55
68
|
let list = records.value ?? []
|
|
56
69
|
if (s.scope) list = list.filter((record) => s.scope(record, filters, helpers))
|
|
57
70
|
for (const [key, facet] of Object.entries(s.facets ?? {})) {
|
|
58
|
-
|
|
71
|
+
// A facet's `canonical(value)` turns a value the URL may carry in an
|
|
72
|
+
// older spelling (a legacy country code) into the one its records carry.
|
|
73
|
+
const wanted = facet.canonical && filters[key] ? facet.canonical(filters[key]) ?? filters[key] : filters[key]
|
|
59
74
|
if (!wanted) continue
|
|
60
75
|
list = list.filter((record) => facetValues(record, facet).map(String).includes(String(wanted)))
|
|
61
76
|
}
|
|
@@ -56,6 +56,10 @@ export function useGalleryCollection(data, config = {}) {
|
|
|
56
56
|
country: {
|
|
57
57
|
values: (item) => countryUrlCode(countryById.value.get(item.country_id)),
|
|
58
58
|
label: (code) => labelOf('countries', countryIdForCode(code)),
|
|
59
|
+
// A link shared with a legacy code (`uk`) still filters: the code is
|
|
60
|
+
// read as the country's URL code (`gb`). Where a legacy code is another
|
|
61
|
+
// country's ISO code (`ua`), the ISO reading wins.
|
|
62
|
+
canonical: (code) => countryUrlCode(countryById.value.get(countryIdForCode(code))),
|
|
59
63
|
},
|
|
60
64
|
...Object.fromEntries(
|
|
61
65
|
FACET_CATEGORIES.map((category) => [
|
|
@@ -152,7 +156,7 @@ export function useGalleryCollection(data, config = {}) {
|
|
|
152
156
|
/** The filter summary line legacy printed as "Collection | <selections>". */
|
|
153
157
|
function filterSummary(filters, t) {
|
|
154
158
|
const parts = []
|
|
155
|
-
if (filters.country) parts.push(labelOf('countries', countryIdForCode(filters.country)))
|
|
159
|
+
if (filters.country) parts.push(labelOf('countries', countryIdForCode(FACETS.country.canonical(filters.country) ?? filters.country)))
|
|
156
160
|
for (const key of FACET_CATEGORIES) if (filters[key]) parts.push(tagLabelForLegacy(filters[key]))
|
|
157
161
|
if (filters.from) parts.push(`${t('catalogue.filter.from')} ${filters.from}`)
|
|
158
162
|
if (filters.to) parts.push(`${t('catalogue.filter.to')} ${filters.to}`)
|