|
1 | 1 | import { CategoryConfig } from "../common/categories/config/types"; |
2 | 2 | import { findSelectCategoryConfig } from "../common/categories/config/utils"; |
3 | 3 | import { isRangeCategory } from "../common/categories/models/range/typeGuards"; |
4 | | -import { assertIsRange } from "../common/categories/models/range/utils"; |
| 4 | +import { buildNextRangeFilterState } from "../common/categories/models/range/utils"; |
| 5 | +import { buildNextSelectFilterState } from "../common/categories/models/select/utils"; |
5 | 6 | import { Category } from "../common/categories/models/types"; |
6 | 7 | import { buildRangeCategoryView } from "../common/categories/views/range/utils"; |
7 | 8 | import { CategoryView, VIEW_KIND } from "../common/categories/views/types"; |
@@ -174,28 +175,21 @@ export function buildNextFilterState( |
174 | 175 | value: categorySelectedFilter ? [...categorySelectedFilter.value] : [], |
175 | 176 | }; |
176 | 177 |
|
177 | | - // Handle case where category value is selected. |
178 | | - if (selected) { |
179 | | - if (viewKind === VIEW_KIND.RANGE) { |
180 | | - // Assert that the selected value is a range. |
181 | | - assertIsRange(selectedValue); |
182 | | - // Set the selected range. |
183 | | - nextCategorySelectedFilter.value = selectedValue; |
184 | | - } else { |
185 | | - // Set the selected value. |
186 | | - nextCategorySelectedFilter.value.push(selectedValue); |
187 | | - } |
188 | | - } |
189 | | - // Otherwise, category value has been de-selected; remove the selected value from the selected set of values. |
190 | | - else { |
191 | | - if (viewKind === VIEW_KIND.RANGE) { |
192 | | - nextCategorySelectedFilter.value = []; |
193 | | - } else { |
194 | | - nextCategorySelectedFilter.value = |
195 | | - nextCategorySelectedFilter.value.filter( |
196 | | - (value: CategoryValueKey) => value !== selectedValue |
197 | | - ); |
198 | | - } |
| 178 | + // Build next filter state for category. |
| 179 | + if (viewKind === VIEW_KIND.RANGE) { |
| 180 | + // Handle range category. |
| 181 | + buildNextRangeFilterState( |
| 182 | + nextCategorySelectedFilter, |
| 183 | + selectedValue, |
| 184 | + selected |
| 185 | + ); |
| 186 | + } else { |
| 187 | + // Handle select category. |
| 188 | + buildNextSelectFilterState( |
| 189 | + nextCategorySelectedFilter, |
| 190 | + selectedValue, |
| 191 | + selected |
| 192 | + ); |
199 | 193 | } |
200 | 194 |
|
201 | 195 | // Add the new selected filter for this category to the set of selected filters, if there are selected values for it. |
|
0 commit comments