Skip to content

Commit

Permalink
Add sort to lines
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibaudDauce committed May 7, 2024
1 parent c4a29a6 commit c7c6404
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
22 changes: 21 additions & 1 deletion frontend/site/.vitepress/theme/components/HighValueDatasets.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<Table :filters="filters" endpoint="high_value_datasets">
<Table :filters endpoint="high_value_datasets" :sortFunc>
<template #thead>
<th>Titre</th>
<th>Ensemble de données</th>
Expand Down Expand Up @@ -36,4 +36,24 @@ const filters = [
{ slug: 'producer', key_in_api: 'PRODUCTEUR', placeholder: 'Tous les producteurs', label: 'Producteur des données' },
{ slug: 'status', key_in_api: 'STATUT', placeholder: 'Tous les statuts', label: 'Statut' },
]
let nextId = 0
let categoriesIds = {}
const sortFunc = (line) => {
const themeValue = {
"Données géospatiales": 1,
"Observation de la Terre et environnement": 2,
"Météorologie": 3,
"Statistiques": 4,
"Entreprises et propriétés d'entreprises": 5,
"Mobilité": 6,
}[line['THÉMATIQUE']]
if (! categoriesIds[line['ENSEMBLE DE DONNÉES']]) {
categoriesIds[line['ENSEMBLE DE DONNÉES']] = nextId++
}
return themeValue * 100 + categoriesIds[line['ENSEMBLE DE DONNÉES']]
}
</script>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<Table :filters="filters" endpoint="ministerial_commitments">
<Table :filters endpoint="ministerial_commitments">
<template #thead>
<th>Titre</th>
<th>Ministère</th>
Expand Down
24 changes: 17 additions & 7 deletions frontend/site/.vitepress/theme/components/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ const props = defineProps<{
key_in_api: string;
label: string;
placeholder: string;
}>
}>;
sortFunc?: (value: any) => number;
}>()
// If the selected is not set, the value is undefined (the placeholder inside the `Select` has a `:value="undefined"` too)
Expand Down Expand Up @@ -91,14 +92,23 @@ const allValues = Object.fromEntries(
])
)
const filteredLines = computed(() => lines.value.filter((line) => {
// If one of the filters doesn't match, reject the line.
for (let filter of props.filters) {
if (selectedFilters[filter.slug] && selectedFilters[filter.slug] !== line[filter.key_in_api]) return false
const filteredLines = computed(() => {
const results = lines.value.filter((line) => {
// If one of the filters doesn't match, reject the line.
for (let filter of props.filters) {
if (selectedFilters[filter.slug] && selectedFilters[filter.slug] !== line[filter.key_in_api]) return false
}
return true
})
if (props.sortFunc) {
const sortFunc = props.sortFunc // To make TS happy… :-(
results.sort((a, b) => sortFunc(a) - sortFunc(b))
}
return true
}))
return results
})
const loading = ref<'loading' | 'failed' | 'done'>('loading')
const load = async () => {
Expand Down

0 comments on commit c7c6404

Please sign in to comment.