Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

fix(query-builder): stop the panel-type field list growing on every change (#12782)

Abhi kumar1c1a5dc54488
diff --git a/frontend/src/constants/queryBuilder.ts b/frontend/src/constants/queryBuilder.ts
index 9e291296e1..9063fd9f77 100644
--- a/frontend/src/constants/queryBuilder.ts
+++ b/frontend/src/constants/queryBuilder.ts
@@ -614,18 +614,6 @@ export const listViewInitialLogQuery: Query = {
},
};
-export const PANEL_TYPES_INITIAL_QUERY: Record<PANEL_TYPES, Query> = {
- [PANEL_TYPES.TIME_SERIES]: initialQueriesMap.metrics,
- [PANEL_TYPES.VALUE]: initialQueriesMap.metrics,
- [PANEL_TYPES.TABLE]: initialQueriesMap.metrics,
- [PANEL_TYPES.LIST]: listViewInitialLogQuery,
- [PANEL_TYPES.TRACE]: initialQueriesMap.traces,
- [PANEL_TYPES.BAR]: initialQueriesMap.metrics,
- [PANEL_TYPES.PIE]: initialQueriesMap.metrics,
- [PANEL_TYPES.HISTOGRAM]: initialQueriesMap.metrics,
- [PANEL_TYPES.EMPTY_WIDGET]: initialQueriesMap.metrics,
-};
-
export const listViewInitialTraceQuery: Query = {
// it should be the above commented query
...initialQueriesMap.traces,
diff --git a/frontend/src/providers/QueryBuilder.tsx b/frontend/src/providers/QueryBuilder.tsx
index cac01d54dc..2f65ef93a3 100644
--- a/frontend/src/providers/QueryBuilder.tsx
+++ b/frontend/src/providers/QueryBuilder.tsx
@@ -767,10 +767,15 @@ export function QueryBuilderProvider({
queryItem.dataSource
].builder.queryData;
- propsRequired?.push('dataSource');
- propsRequired?.forEach((p: any) => {
- set(queryItem, p, get(newQueryItem, p));
- });
+ // `dataSource` travels with the panel type's fields, but is appended to a
+ // copy: `propsRequired` is the list held in
+ // `panelTypeDataSourceFormValuesMap`, and pushing onto it grew that
+ // module-level array by one entry on every call.
+ if (propsRequired) {
+ [...propsRequired, 'dataSource'].forEach((p: any) => {
+ set(queryItem, p, get(newQueryItem, p));
+ });
+ }
return queryItem;
}
diff --git a/frontend/src/types/common/queryBuilder.ts b/frontend/src/types/common/queryBuilder.ts
index afafde129f..4ae64e5331 100644
--- a/frontend/src/types/common/queryBuilder.ts
+++ b/frontend/src/types/common/queryBuilder.ts
@@ -211,13 +211,11 @@ export enum QueryFunctionsTypes {
FILL_ZERO = 'fillZero',
}
-export type PanelTypeKeys =
- | 'TIME_SERIES'
- | 'VALUE'
- | 'TABLE'
- | 'LIST'
- | 'TRACE'
- | 'EMPTY_WIDGET';
+/**
+ * Key names of {@link PANEL_TYPES}. Derived rather than listed: the hand-written
+ * version had fallen behind the enum by three members (`BAR`, `PIE`, `HISTOGRAM`).
+ */
+export type PanelTypeKeys = keyof typeof PANEL_TYPES;
export enum ReduceOperators {
LAST = 'last',