mirror of
https://github.com/Graylog2/graylog2-server.git
synced 2026-03-13 09:32:21 +08:00
Fix issue when running add to query action for multiple values from chart creates wrong query. (#24003)
This commit is contained in:
committed by
GitHub
parent
78c3a7d992
commit
a6bbe1a25b
5
changelog/unreleased/issue-24002.toml
Normal file
5
changelog/unreleased/issue-24002.toml
Normal 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"]
|
||||
@@ -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);
|
||||
|
||||
@@ -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 }],
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user