Skip to content

Commit

Permalink
fix: deselect unavailable global filter values
Browse files Browse the repository at this point in the history
  • Loading branch information
arildm committed Jan 30, 2025
1 parent 1311e4e commit b6c7444
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

### Fixed

- Deselect unavailable global filter values after changing corpus selection
- Error when loading a non-`visible_modes` mode [#426](https://github.com/spraakbanken/korp-frontend/issues/426)

## [9.8.1] - 2025-01-23
Expand Down
12 changes: 11 additions & 1 deletion app/scripts/global-filter/global-filter-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ angular.module("korpApp").factory("globalFilterService", [
const attrs = Object.keys($rootScope.globalFilterData)
const multiAttrs = attrs.filter((attr) => $rootScope.globalFilterData[attr].attribute.type === "set")
currentData = corpora.length && attrs.length ? await countAttrValues(corpora, attrs, multiAttrs) : {}
$timeout(() => updateData())
$timeout(() => {
updateData()
filterSelection()
})
}

// when user selects an attribute, update all possible filter values and counts
Expand Down Expand Up @@ -119,6 +122,13 @@ angular.module("korpApp").factory("globalFilterService", [
}
}

/** Deselect values that are not in the options */
function filterSelection() {
for (const filter of Object.values($rootScope.globalFilterData)) {
filter.value = filter.value.filter((value) => filter.options.some(([v]) => v === value))
}
}

/** Parse encoded url param value to local data. */
function setFromLocation(globalFilter?: string) {
if (!globalFilter) {
Expand Down

0 comments on commit b6c7444

Please sign in to comment.