Skip to content

Commit

Permalink
selector: Allow the same value in multiple children aggregations
Browse files Browse the repository at this point in the history
  • Loading branch information
psaiz committed Jan 16, 2024
1 parent 9a3ce63 commit a355832
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ const ValueElement = ({
? bucket.label
: `${keyField} (${bucket.doc_count.toLocaleString("en-US")})`;
const childAggCmps = getChildAggCmps(bucket);

/* Note that the checkbox does not have any `id`. It used to have one, based on the value, and the issue
was that, if the same value appeared more than once, react didn't like having two items with the same id,
and clicking on the second would select the first one */
return (
<Overridable
id={buildUID("BucketAggregationValues.element", overridableId)}
Expand All @@ -152,7 +154,6 @@ const ValueElement = ({
<List.Item key={bucket.key}>
<Checkbox
label={label}
id={`${bucket.key}-agg-value-checkbox`}
value={bucket.key}
onClick={() => onFilterClicked(bucket.key)}
checked={isSelected}
Expand Down
35 changes: 35 additions & 0 deletions src/lib/state/selectors/query.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,41 @@ describe("queries with second level filters.", () => {
["type", "Publication"],
]);
});

test("query with `subtype: Validation` should add it to the correct type", () => {
const state = [
["file_type", "pdf"],
["type", "Documentation", ["subtype", "Validation"]],
];

const query = ["type", "Publication", ["subtype", "Validation"]];

const newState = updateQueryFilters(query, state);

expect(newState).toEqual([
["file_type", "pdf"],
["type", "Documentation", ["subtype", "Validation"]],
["type", "Publication", ["subtype", "Validation"]],
]);
});

test("query with `subtype: Validation` should remove it from the correct type", () => {
const state = [
["file_type", "pdf"],
["type", "Documentation", ["subtype", "Validation"]],
["type", "Publication", ["subtype", "Validation"]],
];

const query = ["type", "Publication", ["subtype", "Validation"]];

const newState = updateQueryFilters(query, state);

expect(newState).toEqual([
["file_type", "pdf"],
["type", "Documentation", ["subtype", "Validation"]],
["type", "Publication"],
]);
});
});

describe("queries with third level filters.", () => {
Expand Down

0 comments on commit a355832

Please sign in to comment.