From d610ee3be1f65821256f702084ee1d6e9f111060 Mon Sep 17 00:00:00 2001 From: Praveen K B Date: Tue, 17 Dec 2024 21:41:35 +0530 Subject: [PATCH] Resolved few Deepsource comments --- .../Stream/Views/Explore/StaticLogTable.tsx | 27 ++++++++++--------- src/pages/Stream/hooks/useParamsController.ts | 20 +++++++------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/pages/Stream/Views/Explore/StaticLogTable.tsx b/src/pages/Stream/Views/Explore/StaticLogTable.tsx index dbcd5932..15236d27 100644 --- a/src/pages/Stream/Views/Explore/StaticLogTable.tsx +++ b/src/pages/Stream/Views/Explore/StaticLogTable.tsx @@ -1,6 +1,6 @@ import { Box, Menu } from '@mantine/core'; import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; -import type { ReactNode } from 'react'; +import type { Dispatch, ReactNode, SetStateAction } from 'react'; import EmptyBox from '@/components/Empty'; import FilterPills from '../../components/FilterPills'; import tableStyles from '../../styles/Logs.module.css'; @@ -57,12 +57,19 @@ const getSanitizedValue = (value: CellType, isTimestamp: boolean) => { return String(value); }; +type ContextMenuState = { + visible: boolean; + x: number; + y: number; + row: Log | null; +}; + const makeHeaderOpts = ( headers: string[], isSecureHTTPContext: boolean, fieldTypeMap: FieldTypeMap, rowNumber: string, - setContextMenu: any, + setContextMenu: Dispatch>, ) => { return _.reduce( headers, @@ -135,12 +142,7 @@ const makeColumnVisiblityOpts = (columns: string[]) => { }; const Table = (props: { primaryHeaderHeight: number }) => { - const [contextMenu, setContextMenu] = useState<{ - visible: boolean; - x: number; - y: number; - row: any | null; - }>({ + const [contextMenu, setContextMenu] = useState({ visible: false, x: 0, y: 0, @@ -158,7 +160,8 @@ const Table = (props: { primaryHeaderHeight: number }) => { [orderedHeaders, rowNumber], ); const columnVisibility = useMemo(() => makeColumnVisiblityOpts(disabledColumns), [disabledColumns, orderedHeaders]); - const selectLog = useCallback((log: Log) => { + const selectLog = useCallback((log: Log | null) => { + if (!log) return; const selectedText = window.getSelection()?.toString(); if (selectedText !== undefined && selectedText?.length > 0) return; @@ -242,7 +245,7 @@ const Table = (props: { primaryHeaderHeight: number }) => { makeCellCustomStyles(id)} mantineTableHeadRowProps={{ style: { border: 'none' } }} mantineTableHeadCellProps={{ @@ -283,13 +286,13 @@ const Table = (props: { primaryHeaderHeight: number }) => { data={pageData} mantinePaperProps={{ style: { border: 'none' } }} enablePagination={false} - enableColumnPinning={true} + enableColumnPinning initialState={{ columnPinning: { left: ['rowNumber'], }, }} - enableStickyHeader={true} + enableStickyHeader defaultColumn={{ minSize: 100 }} layoutMode="grid" state={{ diff --git a/src/pages/Stream/hooks/useParamsController.ts b/src/pages/Stream/hooks/useParamsController.ts index 5449dc0a..c048edbd 100644 --- a/src/pages/Stream/hooks/useParamsController.ts +++ b/src/pages/Stream/hooks/useParamsController.ts @@ -108,6 +108,14 @@ const useParamsController = () => { const [searchParams, setSearchParams] = useSearchParams(); + const syncRowNumber = useCallback((storeAsParams: Record, presentParams: Record) => { + if (_.has(presentParams, 'rowNumber')) { + if (storeAsParams.rowNumber !== presentParams.rowNumber) { + setLogsStore((store) => setRowNumber(store, presentParams.rowNumber)); + } + } + }, []); + useEffect(() => { const storeAsParams = storeToParamsObj({ timeRange, @@ -150,7 +158,7 @@ const useParamsController = () => { rows: `${perPage}`, query: custQuerySearchState.custSearchQuery, filterType: custQuerySearchState.viewMode, - rowNumber: rowNumber, + rowNumber, }); const presentParams = paramsStringToParamsObj(searchParams); if (_.isEqual(storeAsParams, presentParams)) return; @@ -169,7 +177,7 @@ const useParamsController = () => { rows: `${perPage}`, query: custQuerySearchState.custSearchQuery, filterType: custQuerySearchState.viewMode, - rowNumber: rowNumber, + rowNumber, }); const presentParams = paramsStringToParamsObj(searchParams); @@ -195,14 +203,6 @@ const useParamsController = () => { syncRowNumber(storeAsParams, presentParams); }, [searchParams]); - const syncRowNumber = useCallback((storeAsParams: Record, presentParams: Record) => { - if (_.has(presentParams, 'rowNumber')) { - if (storeAsParams.rowNumber !== presentParams.rowNumber) { - setLogsStore((store) => setRowNumber(store, presentParams.rowNumber)); - } - } - }, []); - const syncTimeRangeToStore = useCallback( (storeAsParams: Record, presentParams: Record) => { if (_.has(presentParams, 'interval')) {