signoz/frontend/src/hooks/queryBuilder/useGetExplorerQueryRange.ts

75 lines
2.4 KiB
TypeScript
Raw Normal View History

2025-07-31 12:16:55 +05:30
import { ENTITY_VERSION_V5 } from 'constants/app';
import { initialQueriesMap, PANEL_TYPES } from 'constants/queryBuilder';
import { REACT_QUERY_KEY } from 'constants/reactQueryKeys';
refactor: update logs explorer pagination logic (#7010) * refactor: pagination changes in query range custom hook * refactor: handle pagination changes in k8s logs and host logs * refactor: logs panel component pagination changes * fix: handle resetting offset on changing page size * fix: optimize context log rendering and prevent duplicate logs * chore: revert pagination handling changes for logs context view * chore: remove unused function and prop * refactor: handle the updated pagination logic in k8s entity events * refactor: refactor queryPayload generation in logs pagination custom hook * fix: remove handling for last log timestamp being sent with query_range * chore: remove the unnecessary last log related changes from LogsExplorerViews * Revert "fix: optimize context log rendering and prevent duplicate logs" This reverts commit ad9ef188651e5106cbc84fe40fc36061c2b9fd40. * fix: prevent recalculating the start/end timestamps while fetching next/prev pages * chore: logs explorer pagination tests * fix: rewrite test and mock scroll * chore: use real timers to detect the start/end timestamps mismatch + enhance tests * refactor: extract filters and order by into a separate function * chore: add tests for logs context pagination * chore: write tests for host logs pagination * chore: overall improvements to host logs tests * chore: k8s entity logs pagination tests * chore: reset capturedQueryRangePayloads in beforeEach * chore: dashboard logs panel component pagination tests * fix: fix the breaking logs pagination test by change /v3 to /v4 * chore: remove the unused prop from HostMetricsLogs
2025-05-22 14:12:51 +04:30
import { GetQueryResultsProps } from 'lib/dashboard/getQueryResults';
import { MutableRefObject, useMemo } from 'react';
import { UseQueryOptions, UseQueryResult } from 'react-query';
import { useSelector } from 'react-redux';
import { AppState } from 'store/reducers';
import { SuccessResponse, Warning } from 'types/api';
import { MetricRangePayloadProps } from 'types/api/metrics/getQueryRange';
import { Query } from 'types/api/queryBuilder/queryBuilderData';
import { GlobalReducer } from 'types/reducer/globalTime';
import { useGetQueryRange } from './useGetQueryRange';
import { useQueryBuilder } from './useQueryBuilder';
export const useGetExplorerQueryRange = (
requestData: Query | null,
panelType: PANEL_TYPES | null,
version: string,
options?: UseQueryOptions<SuccessResponse<MetricRangePayloadProps>, Error>,
params?: Record<string, unknown>,
isDependentOnQB = true,
keyRef?: MutableRefObject<any>,
headers?: Record<string, string>,
refactor: update logs explorer pagination logic (#7010) * refactor: pagination changes in query range custom hook * refactor: handle pagination changes in k8s logs and host logs * refactor: logs panel component pagination changes * fix: handle resetting offset on changing page size * fix: optimize context log rendering and prevent duplicate logs * chore: revert pagination handling changes for logs context view * chore: remove unused function and prop * refactor: handle the updated pagination logic in k8s entity events * refactor: refactor queryPayload generation in logs pagination custom hook * fix: remove handling for last log timestamp being sent with query_range * chore: remove the unnecessary last log related changes from LogsExplorerViews * Revert "fix: optimize context log rendering and prevent duplicate logs" This reverts commit ad9ef188651e5106cbc84fe40fc36061c2b9fd40. * fix: prevent recalculating the start/end timestamps while fetching next/prev pages * chore: logs explorer pagination tests * fix: rewrite test and mock scroll * chore: use real timers to detect the start/end timestamps mismatch + enhance tests * refactor: extract filters and order by into a separate function * chore: add tests for logs context pagination * chore: write tests for host logs pagination * chore: overall improvements to host logs tests * chore: k8s entity logs pagination tests * chore: reset capturedQueryRangePayloads in beforeEach * chore: dashboard logs panel component pagination tests * fix: fix the breaking logs pagination test by change /v3 to /v4 * chore: remove the unused prop from HostMetricsLogs
2025-05-22 14:12:51 +04:30
selectedTimeInterval?: GetQueryResultsProps['globalSelectedInterval'],
): UseQueryResult<
SuccessResponse<MetricRangePayloadProps> & { warning?: Warning },
Error
> => {
const { isEnabledQuery } = useQueryBuilder();
const { selectedTime: globalSelectedInterval, minTime, maxTime } = useSelector<
AppState,
GlobalReducer
>((state) => state.globalTime);
Signoz cloud onboarding v1 (#3525) * Signoz Cloud - Onboarding Flow - Getting Started page * Signoz Cloud - Onboarding Flow - Java lang setup flow * Signoz Cloud - Onboarding Flow - Wireup other lang docs for APM and create empty base component for other modules * Signoz Cloud - Onboarding Flow - remove try signoz cloud button, Update code background * Signoz Cloud - Onboarding Flow - Wire up all docs and modules * Signoz Cloud - Onboarding Flow - Integrate Intercom and other minor fixes * Signoz Cloud - Onboarding Flow - Logs Management - Update Connection Status component * Signoz Cloud - Onboarding Flow - Logs Management - Update light mode styles * Signoz Cloud - Onboarding Flow - Logs Management - Update Logs * Signoz Cloud - Update yarn.lock * Signoz Cloud - Delete Progress Steps component * Signoz Cloud - Poll for connection status, created common Header component * Signoz Cloud - Add polling to check connection status, update components to use common Header component * Signoz Cloud - Render onboarding only if feature flag is enabled * Signoz Cloud - Configure Logs Management Steps * Signoz Cloud - Update intercom snippet and set max width for onboarding flow container to 1440px * Signoz Cloud - Use andD card component for displaying modules * chore: first clean up * Signoz Cloud - Use ONBOARDING and CHAT_SUPPORT FF * Signoz Cloud - Update version check logic and fix minor css issues * fix: feature flag is updated * chore: docusaurus is removed * chore: docusaurus is removed * feat: signoz cloud - fix typecheck errors * feat: signoz cloud - enable chat support based on FF * feat: signoz cloud - fix type errors * feat: signoz cloud - fix type errors * feat: signoz cloud - update webpack config rules --------- Co-authored-by: Palash Gupta <palashgdev@gmail.com>
2023-09-12 19:20:14 +05:30
const key =
typeof options?.queryKey === 'string'
? options?.queryKey
: REACT_QUERY_KEY.GET_QUERY_RANGE;
const isEnabled = useMemo(() => {
if (!options) return isEnabledQuery;
if (typeof options.enabled === 'boolean') {
return options.enabled && (!isDependentOnQB || isEnabledQuery);
}
return isEnabledQuery;
}, [options, isEnabledQuery, isDependentOnQB]);
if (keyRef) {
// eslint-disable-next-line no-param-reassign
keyRef.current = [key, globalSelectedInterval, requestData, minTime, maxTime];
}
return useGetQueryRange(
{
graphType: panelType || PANEL_TYPES.LIST,
selectedTime: 'GLOBAL_TIME',
refactor: update logs explorer pagination logic (#7010) * refactor: pagination changes in query range custom hook * refactor: handle pagination changes in k8s logs and host logs * refactor: logs panel component pagination changes * fix: handle resetting offset on changing page size * fix: optimize context log rendering and prevent duplicate logs * chore: revert pagination handling changes for logs context view * chore: remove unused function and prop * refactor: handle the updated pagination logic in k8s entity events * refactor: refactor queryPayload generation in logs pagination custom hook * fix: remove handling for last log timestamp being sent with query_range * chore: remove the unnecessary last log related changes from LogsExplorerViews * Revert "fix: optimize context log rendering and prevent duplicate logs" This reverts commit ad9ef188651e5106cbc84fe40fc36061c2b9fd40. * fix: prevent recalculating the start/end timestamps while fetching next/prev pages * chore: logs explorer pagination tests * fix: rewrite test and mock scroll * chore: use real timers to detect the start/end timestamps mismatch + enhance tests * refactor: extract filters and order by into a separate function * chore: add tests for logs context pagination * chore: write tests for host logs pagination * chore: overall improvements to host logs tests * chore: k8s entity logs pagination tests * chore: reset capturedQueryRangePayloads in beforeEach * chore: dashboard logs panel component pagination tests * fix: fix the breaking logs pagination test by change /v3 to /v4 * chore: remove the unused prop from HostMetricsLogs
2025-05-22 14:12:51 +04:30
globalSelectedInterval: selectedTimeInterval ?? globalSelectedInterval,
query: requestData || initialQueriesMap.metrics,
params,
},
2025-07-31 12:16:55 +05:30
// version,
ENTITY_VERSION_V5,
{
...options,
queryKey: [key, globalSelectedInterval, requestData, minTime, maxTime],
enabled: isEnabled,
},
headers,
);
};