2023-06-23 11:19:53 +03:00
|
|
|
import { Card, Typography } from 'antd';
|
|
|
|
|
// components
|
|
|
|
|
import ListLogView from 'components/Logs/ListLogView';
|
|
|
|
|
import RawLogView from 'components/Logs/RawLogView';
|
|
|
|
|
import Spinner from 'components/Spinner';
|
2023-09-08 12:11:07 +05:30
|
|
|
import { CARD_BODY_STYLE } from 'constants/card';
|
2023-07-07 15:35:07 +03:00
|
|
|
import { LOCALSTORAGE } from 'constants/localStorage';
|
2023-07-06 14:22:44 +03:00
|
|
|
import ExplorerControlPanel from 'container/ExplorerControlPanel';
|
|
|
|
|
import { Heading } from 'container/LogsTable/styles';
|
|
|
|
|
import { useOptionsMenu } from 'container/OptionsMenu';
|
2023-07-30 14:02:18 +03:00
|
|
|
import { useCopyLogLink } from 'hooks/logs/useCopyLogLink';
|
2023-07-06 14:22:44 +03:00
|
|
|
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
|
2023-06-23 11:19:53 +03:00
|
|
|
import useFontFaceObserver from 'hooks/useFontObserver';
|
2023-07-30 14:02:18 +03:00
|
|
|
import { memo, useCallback, useEffect, useMemo, useRef } from 'react';
|
|
|
|
|
import { Virtuoso, VirtuosoHandle } from 'react-virtuoso';
|
2023-06-23 11:19:53 +03:00
|
|
|
// interfaces
|
|
|
|
|
import { ILog } from 'types/api/logs/log';
|
2023-07-06 14:22:44 +03:00
|
|
|
import { DataSource, StringOperators } from 'types/common/queryBuilder';
|
2023-06-23 11:19:53 +03:00
|
|
|
|
2023-07-06 14:22:44 +03:00
|
|
|
import InfinityTableView from './InfinityTableView';
|
2023-06-23 11:19:53 +03:00
|
|
|
import { LogsExplorerListProps } from './LogsExplorerList.interfaces';
|
2023-07-06 14:22:44 +03:00
|
|
|
import { InfinityWrapperStyled } from './styles';
|
|
|
|
|
import { convertKeysToColumnFields } from './utils';
|
|
|
|
|
|
|
|
|
|
function Footer(): JSX.Element {
|
|
|
|
|
return <Spinner height={20} tip="Getting Logs" />;
|
|
|
|
|
}
|
2023-06-23 11:19:53 +03:00
|
|
|
|
|
|
|
|
function LogsExplorerList({
|
|
|
|
|
isLoading,
|
2023-07-06 14:22:44 +03:00
|
|
|
currentStagedQueryData,
|
|
|
|
|
logs,
|
|
|
|
|
onEndReached,
|
2023-06-23 11:19:53 +03:00
|
|
|
}: LogsExplorerListProps): JSX.Element {
|
2023-07-30 14:02:18 +03:00
|
|
|
const ref = useRef<VirtuosoHandle>(null);
|
2023-07-06 14:22:44 +03:00
|
|
|
const { initialDataSource } = useQueryBuilder();
|
2023-06-23 11:19:53 +03:00
|
|
|
|
2023-07-30 14:02:18 +03:00
|
|
|
const { activeLogId } = useCopyLogLink();
|
|
|
|
|
|
2023-07-06 14:22:44 +03:00
|
|
|
const { options, config } = useOptionsMenu({
|
2023-07-07 15:35:07 +03:00
|
|
|
storageKey: LOCALSTORAGE.LOGS_LIST_OPTIONS,
|
2023-07-06 14:22:44 +03:00
|
|
|
dataSource: initialDataSource || DataSource.METRICS,
|
|
|
|
|
aggregateOperator:
|
|
|
|
|
currentStagedQueryData?.aggregateOperator || StringOperators.NOOP,
|
|
|
|
|
});
|
2023-06-23 11:19:53 +03:00
|
|
|
|
2023-07-30 14:02:18 +03:00
|
|
|
const activeLogIndex = useMemo(
|
|
|
|
|
() => logs.findIndex(({ id }) => id === activeLogId),
|
|
|
|
|
[logs, activeLogId],
|
|
|
|
|
);
|
|
|
|
|
|
2023-06-23 11:19:53 +03:00
|
|
|
useFontFaceObserver(
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
family: 'Fira Code',
|
|
|
|
|
weight: '300',
|
|
|
|
|
},
|
|
|
|
|
],
|
2023-07-06 14:22:44 +03:00
|
|
|
options.format === 'raw',
|
2023-06-23 11:19:53 +03:00
|
|
|
{
|
|
|
|
|
timeout: 5000,
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
2023-07-06 14:22:44 +03:00
|
|
|
const selectedFields = useMemo(
|
|
|
|
|
() => convertKeysToColumnFields(options.selectColumns),
|
|
|
|
|
[options],
|
|
|
|
|
);
|
2023-06-23 11:19:53 +03:00
|
|
|
|
2023-07-06 14:22:44 +03:00
|
|
|
const getItemContent = useCallback(
|
|
|
|
|
(_: number, log: ILog): JSX.Element => {
|
|
|
|
|
if (options.format === 'raw') {
|
2023-06-23 11:19:53 +03:00
|
|
|
return (
|
2023-07-30 14:02:18 +03:00
|
|
|
<RawLogView key={log.id} data={log} linesPerRow={options.maxLines} />
|
2023-06-23 11:19:53 +03:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-06 14:22:44 +03:00
|
|
|
return (
|
2023-07-30 14:02:18 +03:00
|
|
|
<ListLogView key={log.id} logData={log} selectedFields={selectedFields} />
|
2023-07-06 14:22:44 +03:00
|
|
|
);
|
2023-06-23 11:19:53 +03:00
|
|
|
},
|
2023-07-30 14:02:18 +03:00
|
|
|
[options.format, options.maxLines, selectedFields],
|
2023-06-23 11:19:53 +03:00
|
|
|
);
|
|
|
|
|
|
2023-07-30 14:02:18 +03:00
|
|
|
useEffect(() => {
|
|
|
|
|
if (!activeLogId || activeLogIndex < 0) return;
|
|
|
|
|
|
|
|
|
|
ref?.current?.scrollToIndex({
|
|
|
|
|
index: activeLogIndex,
|
|
|
|
|
align: 'start',
|
|
|
|
|
behavior: 'smooth',
|
|
|
|
|
});
|
|
|
|
|
}, [activeLogId, activeLogIndex]);
|
|
|
|
|
|
2023-06-23 11:19:53 +03:00
|
|
|
const renderContent = useMemo(() => {
|
2023-07-06 14:22:44 +03:00
|
|
|
const components = isLoading
|
|
|
|
|
? {
|
|
|
|
|
Footer,
|
|
|
|
|
}
|
|
|
|
|
: {};
|
|
|
|
|
|
|
|
|
|
if (options.format === 'table') {
|
2023-06-23 11:19:53 +03:00
|
|
|
return (
|
2023-07-06 14:22:44 +03:00
|
|
|
<InfinityTableView
|
2023-07-30 14:02:18 +03:00
|
|
|
ref={ref}
|
|
|
|
|
isLoading={isLoading}
|
2023-07-06 14:22:44 +03:00
|
|
|
tableViewProps={{
|
|
|
|
|
logs,
|
|
|
|
|
fields: selectedFields,
|
|
|
|
|
linesPerRow: options.maxLines,
|
2023-07-06 18:56:29 +03:00
|
|
|
appendTo: 'end',
|
2023-07-06 14:22:44 +03:00
|
|
|
}}
|
|
|
|
|
infitiyTableProps={{ onEndReached }}
|
2023-06-23 11:19:53 +03:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2023-09-08 12:11:07 +05:30
|
|
|
<Card style={{ width: '100%' }} bodyStyle={CARD_BODY_STYLE}>
|
2023-06-23 11:19:53 +03:00
|
|
|
<Virtuoso
|
2023-07-30 14:02:18 +03:00
|
|
|
ref={ref}
|
2023-07-06 14:22:44 +03:00
|
|
|
data={logs}
|
|
|
|
|
endReached={onEndReached}
|
2023-06-23 11:19:53 +03:00
|
|
|
totalCount={logs.length}
|
|
|
|
|
itemContent={getItemContent}
|
2023-07-06 14:22:44 +03:00
|
|
|
components={components}
|
2023-06-23 11:19:53 +03:00
|
|
|
/>
|
|
|
|
|
</Card>
|
|
|
|
|
);
|
2023-09-10 11:43:17 +05:30
|
|
|
}, [isLoading, options, logs, onEndReached, getItemContent, selectedFields]);
|
2023-06-23 11:19:53 +03:00
|
|
|
|
|
|
|
|
return (
|
2023-07-06 14:22:44 +03:00
|
|
|
<>
|
|
|
|
|
<ExplorerControlPanel
|
2023-08-22 12:12:56 +05:30
|
|
|
selectedOptionFormat={options.format}
|
2023-07-06 14:22:44 +03:00
|
|
|
isLoading={isLoading}
|
|
|
|
|
isShowPageSize={false}
|
|
|
|
|
optionsMenuConfig={config}
|
|
|
|
|
/>
|
2023-07-17 15:27:37 +05:30
|
|
|
|
2023-07-06 14:22:44 +03:00
|
|
|
{options.format !== 'table' && (
|
2023-06-23 11:19:53 +03:00
|
|
|
<Heading>
|
|
|
|
|
<Typography.Text>Event</Typography.Text>
|
|
|
|
|
</Heading>
|
|
|
|
|
)}
|
2023-07-17 15:27:37 +05:30
|
|
|
|
|
|
|
|
{!isLoading && logs.length === 0 && (
|
|
|
|
|
<Typography>No logs lines found</Typography>
|
|
|
|
|
)}
|
|
|
|
|
|
2023-07-06 14:22:44 +03:00
|
|
|
<InfinityWrapperStyled>{renderContent}</InfinityWrapperStyled>
|
|
|
|
|
</>
|
2023-06-23 11:19:53 +03:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default memo(LogsExplorerList);
|