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.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
fix(ai-assistant): open explorer chips in the view the query implies (#11733)
Vishal Sharma1be806c58d2e
diff --git a/frontend/src/container/AIAssistant/components/ActionsSection/ActionsSection.tsx b/frontend/src/container/AIAssistant/components/ActionsSection/ActionsSection.tsxindex dac3877aa1..a81df3b7cb 100644--- a/frontend/src/container/AIAssistant/components/ActionsSection/ActionsSection.tsx+++ b/frontend/src/container/AIAssistant/components/ActionsSection/ActionsSection.tsx@@ -26,6 +26,7 @@ import {} from 'api/ai-assistant/chat';import ROUTES from 'constants/routes';import { QueryParams } from 'constants/query';+import { buildExplorerNavigationUrl } from 'utils/buildExplorerNavigationUrl';import { openInNewTab } from 'utils/navigation';import {ArchiveRestore,@@ -47,6 +48,10 @@ import { AIAssistantEvents, SuggestedPromptCategory } from '../../events';import { useAIAssistantAnalyticsContext } from '../../hooks/useAIAssistantAnalyticsContext';import { useAIAssistantStore } from '../../store/useAIAssistantStore';+import {+ getPanelTypeForRequestType,+ requestTypeFromActionQuery,+} from './utils/getPanelTypeForRequestType';import { openSavedViewByKey } from './utils/openSavedView';import {isSavedViewOpenAction,@@ -333,6 +338,11 @@ function applyFilter(action: MessageActionDTO, deps: ApplyFilterDeps): void {);return;}+ // Read before toUrlCompositeQuery, which drops the requestType envelope.+ const panelType = getPanelTypeForRequestType(+ requestTypeFromActionQuery(action.query),+ action.signal,+ );const normalized = withDerivedFilterExpressions(urlQuery as unknown as Query);// eslint-disable-next-line no-consoleconsole.log('[apply_filter] normalized', normalized);@@ -342,7 +352,9 @@ function applyFilter(action: MessageActionDTO, deps: ApplyFilterDeps): void {normalized.builder.queryData.forEach((q, i) => {deps.handleSetQueryData(i, q);});- deps.redirectWithQueryBuilderData(normalized);+ deps.redirectWithQueryBuilderData(normalized, {+ [QueryParams.panelTypes]: panelType,+ });return;}const base = explorerRouteForSignal(action.signal);@@ -353,8 +365,10 @@ function applyFilter(action: MessageActionDTO, deps: ApplyFilterDeps): void {}// eslint-disable-next-line no-consoleconsole.log('[apply_filter] off-page → navigate', base);- const encoded = encodeURIComponent(JSON.stringify(normalized));- navigate(`${base}?${QueryParams.compositeQuery}=${encoded}`);+ const url = buildExplorerNavigationUrl(base, normalized, {+ [QueryParams.panelTypes]: panelType,+ });+ navigate(url);}/** Picks the right rollback API call for a given action kind. */@@ -613,6 +627,7 @@ export default function ActionsSection({disabled={isSuccess}loading={isLoading}aria-label={action.label}+ testId={`ai-action-chip-${action.kind}`}prefix={icon}><span className={styles.chipLabel}>{action.label}</span>diff --git a/frontend/src/container/AIAssistant/components/ActionsSection/__tests__/ActionsSection.test.tsx b/frontend/src/container/AIAssistant/components/ActionsSection/__tests__/ActionsSection.test.tsxindex bc4ce1bbd5..60ba1ebb7f 100644--- a/frontend/src/container/AIAssistant/components/ActionsSection/__tests__/ActionsSection.test.tsx+++ b/frontend/src/container/AIAssistant/components/ActionsSection/__tests__/ActionsSection.test.tsx@@ -1,7 +1,16 @@import { undoExecution } from 'api/ai-assistant/chat';import type { MessageActionDTO } from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';-import { MessageActionKindDTO } from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';+import {+ ApplyFilterSignalDTO,+ MessageActionKindDTO,+} from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';+import { Querybuildertypesv5RequestTypeDTO } from 'api/generated/services/sigNoz.schemas';+import { QueryParams } from 'constants/query';+import { PANEL_TYPES } from 'constants/queryBuilder';+import ROUTES from 'constants/routes';+import { getCurrentLocation } from 'lib/router/navigation';import { render, screen, userEvent, waitFor } from 'tests/test-utils';+import { QueryBuilderContextType } from 'types/common/queryBuilder';import ActionsSection from '../ActionsSection';@@ -28,6 +37,37 @@ function renderUndoChip(): HTMLElement {return screen.getByRole('button', { name: 'Undo change' });}+// Labels differ per test: auto-applied filters are deduped module-wide by label.+function countByServiceAction(label: string): MessageActionDTO {+ return {+ kind: MessageActionKindDTO.apply_filter,+ label,+ signal: ApplyFilterSignalDTO.logs,+ query: {+ requestType: Querybuildertypesv5RequestTypeDTO.scalar,+ compositeQuery: {+ queries: [+ {+ type: 'builder_query',+ spec: {+ name: 'A',+ signal: 'logs',+ aggregations: [{ expression: 'count()' }],+ groupBy: [{ name: 'service.name' }],+ },+ },+ ],+ },+ },+ };+}++function currentPanelTypesParam(): string | null {+ return new URLSearchParams(getCurrentLocation().search).get(+ QueryParams.panelTypes,+ );+}+describe('ActionsSection rollback chip', () => {beforeEach(() => {mockUndo.mockReset();@@ -81,3 +121,52 @@ describe('ActionsSection rollback chip', () => {).resolves.toBeInTheDocument();});});++describe('ActionsSection apply_filter', () => {+ it('opens the explorer in the Table view when the chip is clicked from another page', async () => {+ const user = userEvent.setup({ pointerEventsCheck: 0 });+ render(+ <ActionsSection+ actions={[countByServiceAction('Open in Logs Explorer')]}+ messageId="message-1"+ />,+ undefined,+ { initialRoute: ROUTES.HOME },+ );++ await user.click(screen.getByTestId('ai-action-chip-apply_filter'));++ await waitFor(() =>+ expect(getCurrentLocation().pathname).toBe(ROUTES.LOGS_EXPLORER),+ );+ expect(currentPanelTypesParam()).toBe(JSON.stringify(PANEL_TYPES.TABLE));+ });++ it('switches the open explorer to the Table view when applied on it', async () => {+ const redirectWithQueryBuilderData = jest.fn() as jest.MockedFunction<+ QueryBuilderContextType['redirectWithQueryBuilderData']+ >;+ const handleSetQueryData = jest.fn() as jest.MockedFunction<+ QueryBuilderContextType['handleSetQueryData']+ >;+ render(+ <ActionsSection+ actions={[countByServiceAction('Apply on Logs Explorer')]}+ messageId="message-2"+ />,+ undefined,+ {+ initialRoute: ROUTES.LOGS_EXPLORER,+ queryBuilderOverrides: { redirectWithQueryBuilderData, handleSetQueryData },+ },+ );++ await waitFor(() =>+ expect(redirectWithQueryBuilderData).toHaveBeenCalledTimes(1),+ );+ expect(redirectWithQueryBuilderData).toHaveBeenCalledWith(+ expect.objectContaining({ builder: expect.anything() }),+ { [QueryParams.panelTypes]: PANEL_TYPES.TABLE },+ );+ });+});diff --git a/frontend/src/container/AIAssistant/components/ActionsSection/utils/__tests__/getPanelTypeForRequestType.test.ts b/frontend/src/container/AIAssistant/components/ActionsSection/utils/__tests__/getPanelTypeForRequestType.test.tsnew file mode 100644index 0000000000..8f59820c47--- /dev/null+++ b/frontend/src/container/AIAssistant/components/ActionsSection/utils/__tests__/getPanelTypeForRequestType.test.ts@@ -0,0 +1,106 @@+import { ApplyFilterSignalDTO } from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';+import { Querybuildertypesv5RequestTypeDTO } from 'api/generated/services/sigNoz.schemas';+import { PANEL_TYPES } from 'constants/queryBuilder';++import {+ getPanelTypeForRequestType,+ requestTypeFromActionQuery,+} from '../getPanelTypeForRequestType';++describe('getPanelTypeForRequestType', () => {+ it.each([+ [+ Querybuildertypesv5RequestTypeDTO.scalar,+ ApplyFilterSignalDTO.logs,+ PANEL_TYPES.TABLE,+ ],+ [+ Querybuildertypesv5RequestTypeDTO.time_series,+ ApplyFilterSignalDTO.logs,+ PANEL_TYPES.TIME_SERIES,+ ],+ [+ Querybuildertypesv5RequestTypeDTO.raw,+ ApplyFilterSignalDTO.logs,+ PANEL_TYPES.LIST,+ ],+ [+ Querybuildertypesv5RequestTypeDTO.trace,+ ApplyFilterSignalDTO.traces,+ PANEL_TYPES.TRACE,+ ],+ [+ Querybuildertypesv5RequestTypeDTO.trace,+ ApplyFilterSignalDTO.logs,+ PANEL_TYPES.LIST,+ ],+ [+ Querybuildertypesv5RequestTypeDTO.trace,+ ApplyFilterSignalDTO.metrics,+ PANEL_TYPES.LIST,+ ],+ ])('maps %s on the %s signal to the %s view', (requestType, signal, view) => {+ expect(getPanelTypeForRequestType(requestType, signal)).toBe(view);+ });++ it.each([+ undefined,+ null,+ '',+ Querybuildertypesv5RequestTypeDTO.raw_stream,+ Querybuildertypesv5RequestTypeDTO.heatmap,+ 'distribution',+ 'nonsense',+ 'toString',+ 'constructor',+ 42,+ {},+ ])(+ 'falls back to the List view for unmapped or invalid requestType (%p)',+ (value) => {+ expect(getPanelTypeForRequestType(value, ApplyFilterSignalDTO.traces)).toBe(+ PANEL_TYPES.LIST,+ );+ },+ );+});++describe('requestTypeFromActionQuery', () => {+ it('reads the requestType envelope field and returns undefined when absent', () => {+ expect(+ requestTypeFromActionQuery({+ requestType: 'scalar',+ schemaVersion: 'v5',+ compositeQuery: { queries: [] },+ }),+ ).toBe('scalar');+ expect(requestTypeFromActionQuery({})).toBeUndefined();+ expect(requestTypeFromActionQuery(null)).toBeUndefined();+ expect(requestTypeFromActionQuery(undefined)).toBeUndefined();+ });++ it('maps a grouped count() payload to the Table view', () => {+ const query = {+ requestType: 'scalar',+ schemaVersion: 'v5',+ compositeQuery: {+ queries: [+ {+ type: 'builder_query',+ spec: {+ signal: 'logs',+ aggregations: [{ expression: 'count()' }],+ groupBy: [{ name: 'service.name' }],+ },+ },+ ],+ },+ };+ expect(+ getPanelTypeForRequestType(+ requestTypeFromActionQuery(query),+ ApplyFilterSignalDTO.logs,+ ),+ ).toBe(PANEL_TYPES.TABLE);+ });+});diff --git a/frontend/src/container/AIAssistant/components/ActionsSection/utils/getPanelTypeForRequestType.ts b/frontend/src/container/AIAssistant/components/ActionsSection/utils/getPanelTypeForRequestType.tsnew file mode 100644index 0000000000..38701ea42d--- /dev/null+++ b/frontend/src/container/AIAssistant/components/ActionsSection/utils/getPanelTypeForRequestType.ts@@ -0,0 +1,30 @@+import {+ ApplyFilterSignalDTO,+ type MessageActionDTOQuery,+} from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';+import { Querybuildertypesv5RequestTypeDTO } from 'api/generated/services/sigNoz.schemas';+import { PANEL_TYPES } from 'constants/queryBuilder';++export function getPanelTypeForRequestType(+ requestType: unknown,+ signal: ApplyFilterSignalDTO,+): PANEL_TYPES {+ switch (requestType) {+ case Querybuildertypesv5RequestTypeDTO.scalar:+ return PANEL_TYPES.TABLE;+ case Querybuildertypesv5RequestTypeDTO.time_series:+ return PANEL_TYPES.TIME_SERIES;+ case Querybuildertypesv5RequestTypeDTO.trace:+ return signal === ApplyFilterSignalDTO.traces+ ? PANEL_TYPES.TRACE+ : PANEL_TYPES.LIST;+ default:+ return PANEL_TYPES.LIST;+ }+}++export function requestTypeFromActionQuery(+ query: MessageActionDTOQuery | undefined,+): unknown {+ return query?.requestType;+}diff --git a/frontend/src/utils/__tests__/buildExplorerNavigationUrl.test.ts b/frontend/src/utils/__tests__/buildExplorerNavigationUrl.test.tsindex 3f1045b012..8f84f9f0fc 100644--- a/frontend/src/utils/__tests__/buildExplorerNavigationUrl.test.ts+++ b/frontend/src/utils/__tests__/buildExplorerNavigationUrl.test.ts@@ -1,6 +1,7 @@import ROUTES from 'constants/routes';import { QueryParams } from 'constants/query';-import { PANEL_TYPES } from 'constants/queryBuilder';+import { initialQueriesMap, PANEL_TYPES } from 'constants/queryBuilder';+import { DataSource } from 'types/common/queryBuilder';import { buildExplorerNavigationUrl } from '../buildExplorerNavigationUrl';@@ -19,4 +20,14 @@ describe('buildExplorerNavigationUrl', () => {expect(url).toContain(`${QueryParams.compositeQuery}=`);expect(url).toContain(`${QueryParams.viewKey}=`);});++ it('JSON-encodes panelTypes so the explorer opens the right view', () => {+ const url = buildExplorerNavigationUrl(+ ROUTES.LOGS_EXPLORER,+ initialQueriesMap[DataSource.LOGS],+ { [QueryParams.panelTypes]: PANEL_TYPES.TABLE },+ );++ expect(url).toContain(`${QueryParams.panelTypes}=%22table%22`);+ });});