Skip to content

Commit

Permalink
fix: handle removed options in reduceSelect
Browse files Browse the repository at this point in the history
  • Loading branch information
arildm committed Dec 4, 2024
1 parent 4bd05d4 commit 7805cc1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 6 additions & 3 deletions app/scripts/components/reduce-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ angular.module("korpApp").component("reduceSelect", {
}

// Only after initialization
if ($ctrl.items && $ctrl.selected && $ctrl.insensitive) validate()
if ($ctrl.items && $ctrl.selected && $ctrl.insensitive) updateSelected()
}

/** Report any changes upwards */
Expand All @@ -120,11 +120,14 @@ angular.module("korpApp").component("reduceSelect", {
const selected = $ctrl.items.filter((item) => item.selected).map((item) => item.value)
const insensitive = $ctrl.items.filter((item) => item.insensitive).map((item) => item.value)

$ctrl.onChange({
const changes = {
// Only set values that have changed
selected: !_.isEqual(selected, $ctrl.selected) ? selected : undefined,
insensitive: !_.isEqual(insensitive, $ctrl.insensitive) ? insensitive : undefined,
})
}

// Only notify if something changed
if (changes.selected || changes.insensitive) $ctrl.onChange(changes)
}

/** Fix state inconsistencies */
Expand Down
4 changes: 1 addition & 3 deletions app/scripts/components/searchtabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,7 @@ angular.module("korpApp").component("searchtabs", {
$ctrl.statCurrentAttrs = _.filter(allAttrs, (item) => !item["hide_statistics"])
$ctrl.statSelectedAttrs = ($location.search().stats_reduce || "word").split(",")
const insensitiveAttrs = $location.search().stats_reduce_insensitive
if (insensitiveAttrs) {
$ctrl.statInsensitiveAttrs = insensitiveAttrs.split(",")
}
$ctrl.statInsensitiveAttrs = insensitiveAttrs?.split(",") || []
})

$ctrl.reduceOnChange = ({ selected, insensitive }) => {
Expand Down

0 comments on commit 7805cc1

Please sign in to comment.