Fix issue when running add to query action for multiple values from chart creates wrong query. (#24003)

This commit is contained in:
Maksym Yadlovskyi
2025-10-31 10:46:41 +01:00
committed by GitHub
parent 78c3a7d992
commit a6bbe1a25b
3 changed files with 46 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
type = "f"
message = "Fix issue when running add to query action for multiple values from chart creates wrong query."
issues = ["24002"]
pulls = ["24003"]

View File

@@ -24,6 +24,10 @@ import SearchExecutionState from 'views/logic/search/SearchExecutionState';
import mockDispatch from 'views/test/mockDispatch';
import { updateQueryString } from 'views/logic/slices/viewSlice';
import type { RootState } from 'views/types';
import AggregationWidget from 'views/logic/aggregationbuilder/AggregationWidget';
import AggregationWidgetConfig from 'views/logic/aggregationbuilder/AggregationWidgetConfig';
import { alice } from 'fixtures/users';
import type { Message } from 'views/components/messagelist/Types';
import AddToQueryHandler from './AddToQueryHandler';
@@ -92,6 +96,38 @@ describe('AddToQueryHandler', () => {
expect(updateQueryString).toHaveBeenCalledWith('anotherQueryId', 'foo:23 AND bar:42');
});
it('updates query string for multiple values from context', async () => {
const query = createQuery('anotherQueryId', 'foo:23');
const view = createViewWithQuery(query);
const state = { ...mockRootState, view: { view } } as RootState;
const dispatch = mockDispatch(state);
const widget = AggregationWidget.builder()
.id('widget1')
.config(AggregationWidgetConfig.builder().visualization('bar').build())
.build();
const contexts = {
view,
widget,
valuePath: [{ bar: 43 }, { baz: 44 }],
analysisDisabledFields: [],
currentUser: alice,
message: {} as Message,
isLocalNode: true,
};
await dispatch(
AddToQueryHandler({
queryId: 'anotherQueryId',
field: 'bar',
value: 42,
type: new FieldType('keyword', [], []),
contexts,
}),
);
expect(updateQueryString).toHaveBeenCalledWith('anotherQueryId', 'foo:23 AND bar:43 AND baz:44');
});
it('appends NOT _exists_ fragment for proper field in case of missing bucket in input', async () => {
const query = createQuery('anotherQueryId', 'foo:23');
const view = createViewWithQuery(query);

View File

@@ -45,7 +45,11 @@ const AddToQueryHandler =
const oldQuery = selectQueryString(queryId)(getState());
const valuesToAdd = uniq(
hasMultipleValueForActions(contexts)
? contexts.valuePath.map(() => ({ field, value, type: fieldTypeFor(field, contexts?.fieldTypes) }))
? contexts.valuePath.map((path) => {
const [pathField, pathValue] = Object.entries(path)[0];
return { field: pathField, value: pathValue, type: fieldTypeFor(field, contexts?.fieldTypes) };
})
: [{ field, value, type }],
);