diff --git a/frontend/src/container/LogsExplorerViews/index.tsx b/frontend/src/container/LogsExplorerViews/index.tsx index aaff83ab3d42..8063bc62b630 100644 --- a/frontend/src/container/LogsExplorerViews/index.tsx +++ b/frontend/src/container/LogsExplorerViews/index.tsx @@ -59,6 +59,7 @@ import { Query, TagFilter, } from 'types/api/queryBuilder/queryBuilderData'; +import { Filter } from 'types/api/v5/queryRange'; import { QueryDataV3 } from 'types/api/widgets/getQuery'; import { DataSource, LogsAggregatorOperator } from 'types/common/queryBuilder'; import { GlobalReducer } from 'types/reducer/globalTime'; @@ -171,6 +172,11 @@ function LogsExplorerViewsContainer({ return; } + let updatedFilterExpression = listQuery.filter?.expression || ''; + if (activeLogId) { + updatedFilterExpression = `${updatedFilterExpression} id <= '${activeLogId}'`.trim(); + } + const modifiedQueryData: IBuilderQuery = { ...listQuery, aggregateOperator: LogsAggregatorOperator.COUNT, @@ -183,6 +189,10 @@ function LogsExplorerViewsContainer({ }, ], legend: '{{severity_text}}', + filter: { + ...listQuery?.filter, + expression: updatedFilterExpression || '', + }, ...(activeLogId && { filters: { ...listQuery?.filters, @@ -286,6 +296,7 @@ function LogsExplorerViewsContainer({ page: number; pageSize: number; filters: TagFilter; + filter: Filter; }, ): Query | null => { if (!query) return null; @@ -297,6 +308,7 @@ function LogsExplorerViewsContainer({ // Add filter for activeLogId if present let updatedFilters = params.filters; + let updatedFilterExpression = params.filter?.expression || ''; if (activeLogId) { updatedFilters = { ...params.filters, @@ -315,6 +327,7 @@ function LogsExplorerViewsContainer({ ], op: 'AND', }; + updatedFilterExpression = `${updatedFilterExpression} id <= '${activeLogId}'`.trim(); } // Create orderBy array based on orderDirection @@ -336,6 +349,9 @@ function LogsExplorerViewsContainer({ ...(listQuery || initialQueryBuilderFormValues), ...paginateData, ...(updatedFilters ? { filters: updatedFilters } : {}), + filter: { + expression: updatedFilterExpression || '', + }, ...(selectedView === ExplorerViews.LIST ? { order: newOrderBy, orderBy: newOrderBy } : { order: [] }), @@ -368,7 +384,7 @@ function LogsExplorerViewsContainer({ if (isLimit) return; if (logs.length < pageSize) return; - const { limit, filters } = listQuery; + const { limit, filters, filter } = listQuery; const nextLogsLength = logs.length + pageSize; @@ -379,6 +395,7 @@ function LogsExplorerViewsContainer({ const newRequestData = getRequestData(stagedQuery, { filters: filters || { items: [], op: 'AND' }, + filter: filter || { expression: '' }, page: page + 1, pageSize: nextPageSize, }); @@ -526,6 +543,7 @@ function LogsExplorerViewsContainer({ const newRequestData = getRequestData(stagedQuery, { filters: listQuery?.filters || initialFilters, + filter: listQuery?.filter || { expression: '' }, page: 1, pageSize, }); diff --git a/frontend/src/container/LogsExplorerViews/tests/LogsExplorerViews.test.tsx b/frontend/src/container/LogsExplorerViews/tests/LogsExplorerViews.test.tsx index bf9690fb7651..f5a72e2ce9c8 100644 --- a/frontend/src/container/LogsExplorerViews/tests/LogsExplorerViews.test.tsx +++ b/frontend/src/container/LogsExplorerViews/tests/LogsExplorerViews.test.tsx @@ -1,3 +1,4 @@ +import { PANEL_TYPES } from 'constants/queryBuilder'; import ROUTES from 'constants/routes'; import { useCopyLogLink } from 'hooks/logs/useCopyLogLink'; import { useGetExplorerQueryRange } from 'hooks/queryBuilder/useGetExplorerQueryRange'; @@ -261,6 +262,68 @@ describe('LogsExplorerViews -', () => { // Verify the total number of filters (original + 1 new activeLogId filter) expect(firstQuery.filters?.items.length).toBe(expectedFiltersLength); + + // Verify the filter expression + expect(firstQuery.filter?.expression).toBe(`id <= '${ACTIVE_LOG_ID}'`); + } + }); + }); + + it('should update filter expression with activeLogId when present with existing filter expression', async () => { + // Mock useCopyLogLink to return an activeLogId + (useCopyLogLink as jest.Mock).mockReturnValue({ + activeLogId: ACTIVE_LOG_ID, + }); + + // Create a custom QueryBuilderContext with an existing filter expression + const customContext = { + ...mockQueryBuilderContextValue, + panelType: PANEL_TYPES.LIST, + stagedQuery: { + ...mockQueryBuilderContextValue.stagedQuery, + builder: { + ...mockQueryBuilderContextValue.stagedQuery.builder, + queryData: [ + { + ...mockQueryBuilderContextValue.stagedQuery.builder.queryData[0], + filter: { expression: "service = 'frontend'" }, + }, + ], + }, + }, + }; + + lodsQueryServerRequest(); + + render( + + + {}} + listQueryKeyRef={{ current: {} }} + chartQueryKeyRef={{ current: {} }} + setWarning={(): void => {}} + showLiveLogs={false} + /> + + , + ); + + await waitFor(() => { + // Find the call made for LIST panel type (main logs list request) + const listCall = (useGetExplorerQueryRange as jest.Mock).mock.calls.find( + (call) => call[1] === PANEL_TYPES.LIST && call[0], + ); + + expect(listCall).toBeDefined(); + if (listCall) { + const queryArg = listCall[0]; + const firstQuery = queryArg.builder.queryData[0]; + // It should append the activeLogId condition to existing expression + expect(firstQuery.filter?.expression).toBe( + "service = 'frontend' id <= 'test-log-id'", + ); } }); });