From 42b844543b121da0cd495e0a5b4c6c1925b2f226 Mon Sep 17 00:00:00 2001 From: Praveen K B Date: Thu, 16 Jan 2025 17:16:35 +0530 Subject: [PATCH] fix: Resolved review comments --- src/@types/parseable/api/query.ts | 2 +- src/api/query.ts | 4 ++-- src/hooks/useQueryResult.tsx | 4 ++-- .../Correlation/components/MultiEventTimeLineGraph.tsx | 8 ++++---- src/pages/Stream/components/EventTimeLineGraph.tsx | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/@types/parseable/api/query.ts b/src/@types/parseable/api/query.ts index b2982808..1ffffb67 100644 --- a/src/@types/parseable/api/query.ts +++ b/src/@types/parseable/api/query.ts @@ -5,7 +5,7 @@ export type LogsQuery = { access: string[] | null; }; -export type GraphQuery = { +export type GraphQueryOpts = { stream: string; startTime: string; endTime: string; diff --git a/src/api/query.ts b/src/api/query.ts index 11674a3d..c9bc2c59 100644 --- a/src/api/query.ts +++ b/src/api/query.ts @@ -1,6 +1,6 @@ import { Axios } from './axios'; import { GRAPH_DATA_URL, LOG_QUERY_URL } from './constants'; -import { GraphQuery, Log, LogsQuery, LogsResponseWithHeaders } from '@/@types/parseable/api/query'; +import { GraphQueryOpts, Log, LogsQuery, LogsResponseWithHeaders } from '@/@types/parseable/api/query'; import timeRangeUtils from '@/utils/timeRangeUtils'; import { CorrelationQueryBuilder, QueryBuilder } from '@/utils/queryBuilder'; @@ -92,6 +92,6 @@ export const getQueryResultWithHeaders = (logsQuery: LogsQuery, query = '') => { return Axios().post(endPoint, makeCustomQueryRequestData(logsQuery, query), {}); }; -export const getGraphData = (data: GraphQuery) => { +export const getGraphData = (data: GraphQueryOpts) => { return Axios().post(GRAPH_DATA_URL, data); }; diff --git a/src/hooks/useQueryResult.tsx b/src/hooks/useQueryResult.tsx index 6472c405..a63c2b69 100644 --- a/src/hooks/useQueryResult.tsx +++ b/src/hooks/useQueryResult.tsx @@ -1,5 +1,5 @@ import { getQueryResultWithHeaders, getQueryResult, getGraphData } from '@/api/query'; -import { GraphQuery, LogsQuery } from '@/@types/parseable/api/query'; +import { GraphQueryOpts, LogsQuery } from '@/@types/parseable/api/query'; import { notifications } from '@mantine/notifications'; import { isAxiosError, AxiosError } from 'axios'; import { IconCheck } from '@tabler/icons-react'; @@ -53,7 +53,7 @@ export const useQueryResult = () => { }; export const useGraphData = () => { - const fetchGraphDataHandler = async (data: GraphQuery) => { + const fetchGraphDataHandler = async (data: GraphQueryOpts) => { const response = await getGraphData(data); if (response.status !== 200) { throw new Error(response.statusText); diff --git a/src/pages/Correlation/components/MultiEventTimeLineGraph.tsx b/src/pages/Correlation/components/MultiEventTimeLineGraph.tsx index c603614d..5dae6a3f 100644 --- a/src/pages/Correlation/components/MultiEventTimeLineGraph.tsx +++ b/src/pages/Correlation/components/MultiEventTimeLineGraph.tsx @@ -246,8 +246,8 @@ const MultiEventTimeLineGraph = () => { const streamNames = Object.keys(fields); const streamsToFetch = streamNames.filter((streamName) => !Object.keys(streamData).includes(streamName)); const totalMinutes = interval / (1000 * 60); - const numBins = totalMinutes < 10 ? totalMinutes : totalMinutes < 60 ? 10 : 60; - const queries = streamsToFetch.map((streamKey) => { + const numBins = Math.trunc(totalMinutes < 10 ? totalMinutes : totalMinutes < 60 ? 10 : 60); + const eventTimeLineGraphOpts = streamsToFetch.map((streamKey) => { const logsQuery = { stream: streamKey, startTime: dayjs(startTime).toISOString(), @@ -256,12 +256,12 @@ const MultiEventTimeLineGraph = () => { }; return logsQuery; }); - Promise.all(queries.map((queryData: any) => fetchGraphDataMutation.mutateAsync(queryData))) + Promise.all(eventTimeLineGraphOpts.map((queryData: any) => fetchGraphDataMutation.mutateAsync(queryData))) .then((results) => { setMultipleStreamData((prevData: any) => { const newData = { ...prevData }; results.forEach((result, index) => { - newData[queries[index].stream] = result; + newData[eventTimeLineGraphOpts[index].stream] = result; }); return newData; }); diff --git a/src/pages/Stream/components/EventTimeLineGraph.tsx b/src/pages/Stream/components/EventTimeLineGraph.tsx index 7f2b02f6..f6cfc696 100644 --- a/src/pages/Stream/components/EventTimeLineGraph.tsx +++ b/src/pages/Stream/components/EventTimeLineGraph.tsx @@ -183,7 +183,7 @@ const EventTimeLineGraph = () => { const adjustedEndTime = dayjs(endTime).startOf('minute'); const totalMinutes = interval / (1000 * 60); - const numBins = Math.ceil(totalMinutes < 10 ? totalMinutes : totalMinutes < 60 ? 10 : 60); + const numBins = Math.trunc(totalMinutes < 10 ? totalMinutes : totalMinutes < 60 ? 10 : 60); const logsQuery = { stream: localStream,