Skip to content

Commit

Permalink
Resolved few Deepsource comments
Browse files Browse the repository at this point in the history
  • Loading branch information
praveen5959 committed Dec 17, 2024
1 parent f4d17cd commit d610ee3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
27 changes: 15 additions & 12 deletions src/pages/Stream/Views/Explore/StaticLogTable.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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<SetStateAction<ContextMenuState>>,
) => {
return _.reduce(
headers,
Expand Down Expand Up @@ -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<ContextMenuState>({
visible: false,
x: 0,
y: 0,
Expand All @@ -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;

Expand Down Expand Up @@ -242,7 +245,7 @@ const Table = (props: { primaryHeaderHeight: number }) => {
<MantineReactTable
enableBottomToolbar={false}
enableTopToolbar={false}
enableColumnResizing={true}
enableColumnResizing
mantineTableBodyCellProps={({ column: { id } }) => makeCellCustomStyles(id)}
mantineTableHeadRowProps={{ style: { border: 'none' } }}
mantineTableHeadCellProps={{
Expand Down Expand Up @@ -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={{
Expand Down
20 changes: 10 additions & 10 deletions src/pages/Stream/hooks/useParamsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ const useParamsController = () => {

const [searchParams, setSearchParams] = useSearchParams();

const syncRowNumber = useCallback((storeAsParams: Record<string, string>, presentParams: Record<string, string>) => {
if (_.has(presentParams, 'rowNumber')) {
if (storeAsParams.rowNumber !== presentParams.rowNumber) {
setLogsStore((store) => setRowNumber(store, presentParams.rowNumber));
}
}
}, []);

useEffect(() => {
const storeAsParams = storeToParamsObj({
timeRange,
Expand Down Expand Up @@ -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;
Expand All @@ -169,7 +177,7 @@ const useParamsController = () => {
rows: `${perPage}`,
query: custQuerySearchState.custSearchQuery,
filterType: custQuerySearchState.viewMode,
rowNumber: rowNumber,
rowNumber,
});
const presentParams = paramsStringToParamsObj(searchParams);

Expand All @@ -195,14 +203,6 @@ const useParamsController = () => {
syncRowNumber(storeAsParams, presentParams);
}, [searchParams]);

const syncRowNumber = useCallback((storeAsParams: Record<string, string>, presentParams: Record<string, string>) => {
if (_.has(presentParams, 'rowNumber')) {
if (storeAsParams.rowNumber !== presentParams.rowNumber) {
setLogsStore((store) => setRowNumber(store, presentParams.rowNumber));
}
}
}, []);

const syncTimeRangeToStore = useCallback(
(storeAsParams: Record<string, string>, presentParams: Record<string, string>) => {
if (_.has(presentParams, 'interval')) {
Expand Down

0 comments on commit d610ee3

Please sign in to comment.