2023-07-30 14:02:18 +03:00
|
|
|
import LogDetail from 'components/LogDetail';
|
2024-02-12 00:23:19 +05:30
|
|
|
import { VIEW_TYPES } from 'components/LogDetail/constants';
|
2024-10-18 18:19:42 +05:30
|
|
|
import { getLogIndicatorType } from 'components/Logs/LogStateIndicator/utils';
|
2023-07-06 14:22:44 +03:00
|
|
|
import { useTableView } from 'components/Logs/TableView/useTableView';
|
2023-07-18 14:48:34 +03:00
|
|
|
import { LOCALSTORAGE } from 'constants/localStorage';
|
2023-07-30 14:02:18 +03:00
|
|
|
import { useActiveLog } from 'hooks/logs/useActiveLog';
|
|
|
|
|
import { useCopyLogLink } from 'hooks/logs/useCopyLogLink';
|
2023-09-10 11:43:17 +05:30
|
|
|
import { useIsDarkMode } from 'hooks/useDarkMode';
|
2023-07-18 14:48:34 +03:00
|
|
|
import useDragColumns from 'hooks/useDragColumns';
|
|
|
|
|
import { getDraggedColumns } from 'hooks/useDragColumns/utils';
|
2024-02-12 00:23:19 +05:30
|
|
|
import { forwardRef, memo, useCallback, useMemo } from 'react';
|
2023-07-30 14:02:18 +03:00
|
|
|
import {
|
|
|
|
|
TableComponents,
|
|
|
|
|
TableVirtuoso,
|
|
|
|
|
TableVirtuosoHandle,
|
|
|
|
|
} from 'react-virtuoso';
|
|
|
|
|
import { ILog } from 'types/api/logs/log';
|
2023-07-06 14:22:44 +03:00
|
|
|
|
2024-08-22 23:56:51 +05:30
|
|
|
import { getInfinityDefaultStyles } from './config';
|
2023-07-18 14:48:34 +03:00
|
|
|
import { LogsCustomTable } from './LogsCustomTable';
|
2024-02-12 00:23:19 +05:30
|
|
|
import { TableHeaderCellStyled, TableRowStyled } from './styles';
|
|
|
|
|
import TableRow from './TableRow';
|
2023-07-06 14:22:44 +03:00
|
|
|
import { InfinityTableProps } from './types';
|
|
|
|
|
|
2024-10-18 18:19:42 +05:30
|
|
|
interface CustomTableRowProps {
|
|
|
|
|
activeContextLogId: string;
|
|
|
|
|
activeLogId: string;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-06 14:22:44 +03:00
|
|
|
// eslint-disable-next-line react/function-component-definition
|
2023-07-30 14:02:18 +03:00
|
|
|
const CustomTableRow: TableComponents<ILog>['TableRow'] = ({
|
2023-07-06 14:22:44 +03:00
|
|
|
children,
|
|
|
|
|
context,
|
|
|
|
|
...props
|
2023-07-30 14:02:18 +03:00
|
|
|
}) => {
|
|
|
|
|
const { isHighlighted } = useCopyLogLink(props.item.id);
|
2023-07-18 14:48:34 +03:00
|
|
|
|
2023-09-10 11:43:17 +05:30
|
|
|
const isDarkMode = useIsDarkMode();
|
|
|
|
|
|
2024-10-18 18:19:42 +05:30
|
|
|
const logType = getLogIndicatorType(props.item);
|
|
|
|
|
|
2023-07-30 14:02:18 +03:00
|
|
|
return (
|
|
|
|
|
<TableRowStyled
|
2023-09-10 11:43:17 +05:30
|
|
|
$isDarkMode={isDarkMode}
|
2024-10-18 18:19:42 +05:30
|
|
|
$isActiveLog={
|
|
|
|
|
isHighlighted ||
|
|
|
|
|
(context as CustomTableRowProps).activeContextLogId === props.item.id ||
|
|
|
|
|
(context as CustomTableRowProps).activeLogId === props.item.id
|
|
|
|
|
}
|
|
|
|
|
$logType={logType}
|
2023-07-30 14:02:18 +03:00
|
|
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
|
|
|
{...props}
|
|
|
|
|
>
|
|
|
|
|
{children}
|
|
|
|
|
</TableRowStyled>
|
2023-07-18 14:48:34 +03:00
|
|
|
);
|
2023-07-30 14:02:18 +03:00
|
|
|
};
|
2023-07-06 14:22:44 +03:00
|
|
|
|
2023-07-30 14:02:18 +03:00
|
|
|
const InfinityTable = forwardRef<TableVirtuosoHandle, InfinityTableProps>(
|
|
|
|
|
function InfinityTableView(
|
|
|
|
|
{ isLoading, tableViewProps, infitiyTableProps },
|
|
|
|
|
ref,
|
|
|
|
|
): JSX.Element | null {
|
|
|
|
|
const {
|
|
|
|
|
activeLog: activeContextLog,
|
|
|
|
|
onSetActiveLog: handleSetActiveContextLog,
|
|
|
|
|
onClearActiveLog: handleClearActiveContextLog,
|
2024-02-12 00:23:19 +05:30
|
|
|
onAddToQuery: handleAddToQuery,
|
2023-07-30 14:02:18 +03:00
|
|
|
} = useActiveLog();
|
|
|
|
|
const {
|
|
|
|
|
activeLog,
|
|
|
|
|
onSetActiveLog,
|
|
|
|
|
onClearActiveLog,
|
|
|
|
|
onAddToQuery,
|
2024-08-22 23:59:22 +05:30
|
|
|
onGroupByAttribute,
|
2023-07-30 14:02:18 +03:00
|
|
|
} = useActiveLog();
|
2023-07-06 14:22:44 +03:00
|
|
|
|
2023-07-30 14:02:18 +03:00
|
|
|
const { dataSource, columns } = useTableView({
|
|
|
|
|
...tableViewProps,
|
|
|
|
|
onClickExpand: onSetActiveLog,
|
|
|
|
|
onOpenLogsContext: handleSetActiveContextLog,
|
|
|
|
|
});
|
2024-02-20 16:21:07 +05:30
|
|
|
|
2023-07-30 14:02:18 +03:00
|
|
|
const { draggedColumns, onDragColumns } = useDragColumns<
|
|
|
|
|
Record<string, unknown>
|
|
|
|
|
>(LOCALSTORAGE.LOGS_LIST_COLUMNS);
|
2023-07-06 14:22:44 +03:00
|
|
|
|
2023-09-10 11:43:17 +05:30
|
|
|
const isDarkMode = useIsDarkMode();
|
|
|
|
|
|
2023-07-30 14:02:18 +03:00
|
|
|
const tableColumns = useMemo(
|
|
|
|
|
() => getDraggedColumns<Record<string, unknown>>(columns, draggedColumns),
|
|
|
|
|
[columns, draggedColumns],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const handleDragEnd = useCallback(
|
|
|
|
|
(fromIndex: number, toIndex: number) =>
|
|
|
|
|
onDragColumns(tableColumns, fromIndex, toIndex),
|
|
|
|
|
[tableColumns, onDragColumns],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const itemContent = useCallback(
|
|
|
|
|
(index: number, log: Record<string, unknown>): JSX.Element => (
|
2024-02-12 00:23:19 +05:30
|
|
|
<TableRow
|
|
|
|
|
tableColumns={tableColumns}
|
|
|
|
|
index={index}
|
|
|
|
|
log={log}
|
|
|
|
|
handleSetActiveContextLog={handleSetActiveContextLog}
|
|
|
|
|
logs={tableViewProps.logs}
|
|
|
|
|
hasActions
|
2024-08-22 23:56:51 +05:30
|
|
|
fontSize={tableViewProps.fontSize}
|
2024-02-12 00:23:19 +05:30
|
|
|
/>
|
2023-07-30 14:02:18 +03:00
|
|
|
),
|
2024-08-22 23:56:51 +05:30
|
|
|
[
|
|
|
|
|
handleSetActiveContextLog,
|
|
|
|
|
tableColumns,
|
|
|
|
|
tableViewProps.fontSize,
|
|
|
|
|
tableViewProps.logs,
|
|
|
|
|
],
|
2023-07-30 14:02:18 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const tableHeader = useCallback(
|
|
|
|
|
() => (
|
|
|
|
|
<tr>
|
2025-01-20 10:13:48 +04:30
|
|
|
{tableColumns
|
|
|
|
|
.filter((column) => column.key)
|
|
|
|
|
.map((column) => {
|
|
|
|
|
const isDragColumn = column.key !== 'expand';
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<TableHeaderCellStyled
|
|
|
|
|
$isLogIndicator={column.key === 'state-indicator'}
|
|
|
|
|
$isDarkMode={isDarkMode}
|
|
|
|
|
$isDragColumn={isDragColumn}
|
|
|
|
|
key={column.key}
|
|
|
|
|
fontSize={tableViewProps?.fontSize}
|
|
|
|
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
|
|
|
{...(isDragColumn && { className: 'dragHandler' })}
|
|
|
|
|
>
|
|
|
|
|
{(column.title as string).replace(/^\w/, (c) => c.toUpperCase())}
|
|
|
|
|
</TableHeaderCellStyled>
|
|
|
|
|
);
|
|
|
|
|
})}
|
2023-07-30 14:02:18 +03:00
|
|
|
</tr>
|
|
|
|
|
),
|
2024-08-22 23:56:51 +05:30
|
|
|
[tableColumns, isDarkMode, tableViewProps?.fontSize],
|
2023-07-30 14:02:18 +03:00
|
|
|
);
|
|
|
|
|
|
2024-02-12 00:23:19 +05:30
|
|
|
const handleClickExpand = (index: number): void => {
|
|
|
|
|
if (!onSetActiveLog) return;
|
|
|
|
|
|
|
|
|
|
onSetActiveLog(tableViewProps.logs[index]);
|
|
|
|
|
};
|
|
|
|
|
|
2023-07-30 14:02:18 +03:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<TableVirtuoso
|
|
|
|
|
ref={ref}
|
2024-03-05 21:31:15 +05:30
|
|
|
initialTopMostItemIndex={
|
|
|
|
|
tableViewProps.activeLogIndex !== -1 ? tableViewProps.activeLogIndex : 0
|
|
|
|
|
}
|
2024-08-22 23:56:51 +05:30
|
|
|
style={getInfinityDefaultStyles(tableViewProps.fontSize)}
|
2023-07-30 14:02:18 +03:00
|
|
|
data={dataSource}
|
|
|
|
|
components={{
|
|
|
|
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
|
|
|
Table: LogsCustomTable({ isLoading, handleDragEnd }),
|
|
|
|
|
// TODO: fix it in the future
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
|
|
|
// @ts-ignore
|
2024-10-18 18:19:42 +05:30
|
|
|
TableRow: (props): any =>
|
|
|
|
|
CustomTableRow({
|
|
|
|
|
...props,
|
|
|
|
|
context: {
|
|
|
|
|
activeContextLogId: activeContextLog?.id,
|
|
|
|
|
activeLogId: activeLog?.id,
|
|
|
|
|
},
|
|
|
|
|
} as any),
|
2023-07-30 14:02:18 +03:00
|
|
|
}}
|
|
|
|
|
itemContent={itemContent}
|
|
|
|
|
fixedHeaderContent={tableHeader}
|
|
|
|
|
totalCount={dataSource.length}
|
2023-08-29 15:23:22 +03:00
|
|
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
|
|
|
{...(infitiyTableProps?.onEndReached
|
|
|
|
|
? { endReached: infitiyTableProps.onEndReached }
|
|
|
|
|
: {})}
|
2024-02-12 00:23:19 +05:30
|
|
|
onClick={(event: any): void => {
|
|
|
|
|
handleClickExpand(event.target.parentElement.parentElement.dataset.index);
|
|
|
|
|
}}
|
2023-07-30 14:02:18 +03:00
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
{activeContextLog && (
|
2024-02-12 00:23:19 +05:30
|
|
|
<LogDetail
|
2023-07-30 14:02:18 +03:00
|
|
|
log={activeContextLog}
|
|
|
|
|
onClose={handleClearActiveContextLog}
|
2024-02-12 00:23:19 +05:30
|
|
|
onAddToQuery={handleAddToQuery}
|
|
|
|
|
selectedTab={VIEW_TYPES.CONTEXT}
|
2024-08-22 23:59:22 +05:30
|
|
|
onGroupByAttribute={onGroupByAttribute}
|
2023-07-30 14:02:18 +03:00
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
<LogDetail
|
2024-02-12 00:23:19 +05:30
|
|
|
selectedTab={VIEW_TYPES.OVERVIEW}
|
2023-07-30 14:02:18 +03:00
|
|
|
log={activeLog}
|
|
|
|
|
onClose={onClearActiveLog}
|
|
|
|
|
onAddToQuery={onAddToQuery}
|
|
|
|
|
onClickActionItem={onAddToQuery}
|
2024-08-22 23:59:22 +05:30
|
|
|
onGroupByAttribute={onGroupByAttribute}
|
2023-07-30 14:02:18 +03:00
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
2023-07-06 14:22:44 +03:00
|
|
|
|
2023-08-29 15:23:22 +03:00
|
|
|
export default memo(InfinityTable);
|