Skip to content

Commit

Permalink
fix filter editor by making a copy instead of mutating current state
Browse files Browse the repository at this point in the history
  • Loading branch information
SpencerTorres committed May 17, 2024
1 parent 6e1f86e commit 1be74f1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixes

- Fixed `IN` operator escaping the entire string (specifically with `Nullable(String)`), also added `FixedString(N)` (#830)
- Fixed query builder filter editor on alert rules page (#828)

## 4.0.7

Expand Down
22 changes: 22 additions & 0 deletions src/components/queryBuilder/FilterEditor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,28 @@ describe('FilterEditor', () => {
// type key into the mapKey input
await userEvent.type(result!.getAllByRole('combobox')[1], 'http.status_code');
await userEvent.keyboard('{Enter}');

result.rerender(
<FilterEditor
allColumns={[{ name: 'SpanAttributes', type: 'Map(String, String)', picklistValues: [] }]}
filter={{
key: 'SpanAttributes',
type: 'Map(String, String)',
mapKey: 'http.status_code',
value: '',
operator: FilterOperator.Equals,
condition: 'AND',
filterType: 'custom',
}}
index={0}
onFilterChange={onFilterChange}
removeFilter={() => {}}
datasource={mockDatasource}
database=''
table=''
/>
);

// type value into the input
await userEvent.type(result!.getByTestId('query-builder-filters-single-string-value-input'), '200');
result!.getByTestId('query-builder-filters-single-string-value-input').blur();
Expand Down
6 changes: 3 additions & 3 deletions src/components/queryBuilder/FilterEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,12 @@ export const FilterEditor = (props: {
onFilterChange(index, newFilter);
};
const onFilterMapKeyChange = (mapKey: string) => {
const newFilter: Filter = filter;
const newFilter: Filter = { ...filter };
newFilter.mapKey = mapKey;
onFilterChange(index, newFilter);
};
const onFilterOperatorChange = (operator: FilterOperator) => {
let newFilter: Filter = filter;
const newFilter: Filter = { ...filter };
newFilter.operator = operator;
if (utils.isMultiFilter(newFilter)) {
if (!Array.isArray(newFilter.value)) {
Expand All @@ -343,7 +343,7 @@ export const FilterEditor = (props: {
onFilterChange(index, newFilter);
};
const onFilterConditionChange = (condition: 'AND' | 'OR') => {
let newFilter: Filter = filter;
const newFilter: Filter = { ...filter };
newFilter.condition = condition;
onFilterChange(index, newFilter);
};
Expand Down

0 comments on commit 1be74f1

Please sign in to comment.