mirror of
https://github.com/SigNoz/signoz.git
synced 2025-12-17 15:36:48 +00:00
fix: added fix for incorrect query in dashboard on panel change to list panel (#8994)
* fix: added fix for incorrect query in dashboard on panel change to list issue * test: added test for handleQueryChange * chore: pr reviews
This commit is contained in:
parent
10c6e1fac7
commit
68d9c6c3cc
80
frontend/src/container/NewWidget/__test__/utils.test.ts
Normal file
80
frontend/src/container/NewWidget/__test__/utils.test.ts
Normal file
@ -0,0 +1,80 @@
|
||||
import {
|
||||
initialQueryBuilderFormValuesMap,
|
||||
PANEL_TYPES,
|
||||
} from 'constants/queryBuilder';
|
||||
import { Query } from 'types/api/queryBuilder/queryBuilderData';
|
||||
import { EQueryType } from 'types/common/dashboard';
|
||||
import { DataSource } from 'types/common/queryBuilder';
|
||||
|
||||
import type { PartialPanelTypes } from '../utils';
|
||||
import { handleQueryChange } from '../utils';
|
||||
|
||||
const buildSupersetQuery = (extras?: Record<string, unknown>): Query => ({
|
||||
queryType: EQueryType.QUERY_BUILDER,
|
||||
promql: [],
|
||||
clickhouse_sql: [],
|
||||
id: '1',
|
||||
unit: '1',
|
||||
builder: {
|
||||
queryFormulas: [],
|
||||
queryData: [
|
||||
{
|
||||
...initialQueryBuilderFormValuesMap[DataSource.LOGS],
|
||||
queryName: 'A',
|
||||
orderBy: [{ columnName: 'x', order: 'asc' }],
|
||||
limit: 10,
|
||||
...(extras || {}),
|
||||
},
|
||||
{
|
||||
...initialQueryBuilderFormValuesMap[DataSource.LOGS],
|
||||
queryName: 'B',
|
||||
orderBy: [{ columnName: 'x', order: 'desc' }],
|
||||
limit: 20,
|
||||
...(extras || {}),
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
describe('handleQueryChange', () => {
|
||||
test('sets list-specific fields when switching to LIST', () => {
|
||||
const superset = buildSupersetQuery();
|
||||
const output = handleQueryChange(
|
||||
PANEL_TYPES.LIST as keyof PartialPanelTypes,
|
||||
superset as Query,
|
||||
PANEL_TYPES.TABLE,
|
||||
);
|
||||
const firstQuery = output.builder.queryData[0];
|
||||
expect(firstQuery.aggregateOperator).toBe('noop');
|
||||
expect(firstQuery.offset).toBe(0);
|
||||
expect(firstQuery.pageSize).toBe(10);
|
||||
expect(firstQuery.orderBy).toBeUndefined();
|
||||
expect(firstQuery.queryName).toBe('A');
|
||||
|
||||
const secondQuery = output.builder.queryData[1];
|
||||
expect(secondQuery.aggregateOperator).toBe('noop');
|
||||
expect(secondQuery.offset).toBe(0);
|
||||
expect(secondQuery.pageSize).toBe(10);
|
||||
expect(secondQuery.orderBy).toBeUndefined();
|
||||
expect(secondQuery.queryName).toBe('B');
|
||||
});
|
||||
|
||||
test('resets noop and pagination when leaving LIST', () => {
|
||||
const superset = buildSupersetQuery({
|
||||
aggregateOperator: 'noop',
|
||||
offset: 5,
|
||||
pageSize: 50,
|
||||
});
|
||||
const output = handleQueryChange(
|
||||
PANEL_TYPES.TABLE as keyof PartialPanelTypes,
|
||||
superset as Query,
|
||||
PANEL_TYPES.LIST,
|
||||
);
|
||||
const q = output.builder.queryData[0];
|
||||
expect(q.aggregateOperator).not.toBe('noop');
|
||||
expect(q.offset).toBeUndefined();
|
||||
expect(q.pageSize).toBeUndefined();
|
||||
expect(q.orderBy).toBeUndefined();
|
||||
expect(q.queryName).toBe('A');
|
||||
});
|
||||
});
|
||||
@ -393,6 +393,7 @@ export const panelTypeDataSourceFormValuesMap: Record<
|
||||
[DataSource.LOGS]: {
|
||||
builder: {
|
||||
queryData: [
|
||||
'queryName',
|
||||
'filters',
|
||||
'filter',
|
||||
'limit',
|
||||
@ -404,12 +405,13 @@ export const panelTypeDataSourceFormValuesMap: Record<
|
||||
},
|
||||
[DataSource.METRICS]: {
|
||||
builder: {
|
||||
queryData: ['filters', 'filter', 'aggregations'],
|
||||
queryData: ['queryName', 'filters', 'filter', 'aggregations'],
|
||||
},
|
||||
},
|
||||
[DataSource.TRACES]: {
|
||||
builder: {
|
||||
queryData: [
|
||||
'queryName',
|
||||
'filters',
|
||||
'filter',
|
||||
'limit',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user