Skip to content
Open
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
22 changes: 20 additions & 2 deletions datagouv-components/src/components/Search/GlobalSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,11 @@
{{ t('Pertinence') }}
</option>
<option
v-for="option in activeSortOptions"
v-for="option in allSortOptions"
:key="option.value"
:value="option.value"
:hidden="!activeSortValues.has(option.value)"
:disabled="!activeSortValues.has(option.value)"
>
{{ option.label }}
</option>
Expand Down Expand Up @@ -333,7 +335,7 @@ import type { Dataset } from '../../types/datasets'
import type { Dataservice } from '../../types/dataservices'
import type { Organization } from '../../types/organizations'
import type { Reuse } from '../../types/reuses'
import type { GlobalSearchConfig, SearchType, DatasetSearchResponse, DataserviceSearchResponse, ReuseSearchResponse, OrganizationSearchResponse, FacetItem } from '../../types/search'
import type { GlobalSearchConfig, SearchType, SortOption, DatasetSearchResponse, DataserviceSearchResponse, ReuseSearchResponse, OrganizationSearchResponse, FacetItem } from '../../types/search'
import { getDefaultGlobalSearchConfig } from '../../types/search'
import BrandedButton from '../BrandedButton.vue'
import LoadingBlock from '../LoadingBlock.vue'
Expand Down Expand Up @@ -396,6 +398,22 @@ const activeSortOptions = computed(() =>
currentTypeConfig.value?.sortOptions ?? [],
)

const activeSortValues = computed(() =>
new Set(activeSortOptions.value.map(o => o.value as string)),
)

// Deduplicated union of all sort options across all search types.
// Rendered as hidden <option> elements so the <select> always has a stable
// intrinsic width regardless of which type is currently active.
const allSortOptions = computed(() => {
const seen = new Set<string>()
return props.config.flatMap(c => (c.sortOptions ?? []) as SortOption<string>[]).filter((o) => {
if (seen.has(o.value)) return false
seen.add(o.value)
return true
})
})

const activeFilters = computed(() => [
...(currentTypeConfig.value?.basicFilters ?? []),
...(currentTypeConfig.value?.advancedFilters ?? []),
Expand Down
Loading