2024-03-12 12:20:45 +05:30
|
|
|
import './LogsExplorer.styles.scss';
|
|
|
|
|
|
2024-06-18 19:04:06 +05:30
|
|
|
import * as Sentry from '@sentry/react';
|
2023-08-30 20:24:16 +05:30
|
|
|
import ExplorerCard from 'components/ExplorerCard/ExplorerCard';
|
2023-07-07 15:49:35 +03:00
|
|
|
import LogExplorerQuerySection from 'container/LogExplorerQuerySection';
|
2023-06-23 11:19:53 +03:00
|
|
|
import LogsExplorerViews from 'container/LogsExplorerViews';
|
2024-02-12 00:23:19 +05:30
|
|
|
import LeftToolbarActions from 'container/QueryBuilder/components/ToolbarActions/LeftToolbarActions';
|
|
|
|
|
import RightToolbarActions from 'container/QueryBuilder/components/ToolbarActions/RightToolbarActions';
|
|
|
|
|
import Toolbar from 'container/Toolbar/Toolbar';
|
|
|
|
|
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
|
2023-11-15 16:46:20 +05:30
|
|
|
import ErrorBoundaryFallback from 'pages/ErrorBoundaryFallback/ErrorBoundaryFallback';
|
2024-08-16 13:11:39 +05:30
|
|
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
2023-08-30 20:24:16 +05:30
|
|
|
import { DataSource } from 'types/common/queryBuilder';
|
2023-06-16 13:38:39 +03:00
|
|
|
|
2023-07-07 15:49:35 +03:00
|
|
|
import { WrapperStyled } from './styles';
|
2024-02-12 00:23:19 +05:30
|
|
|
import { SELECTED_VIEWS } from './utils';
|
2023-06-16 13:38:39 +03:00
|
|
|
|
2023-06-23 21:39:59 +03:00
|
|
|
function LogsExplorer(): JSX.Element {
|
2024-07-08 20:02:10 +05:30
|
|
|
const [showFrequencyChart, setShowFrequencyChart] = useState(true);
|
2024-02-12 00:23:19 +05:30
|
|
|
const [selectedView, setSelectedView] = useState<SELECTED_VIEWS>(
|
|
|
|
|
SELECTED_VIEWS.SEARCH,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const { handleRunQuery, currentQuery } = useQueryBuilder();
|
|
|
|
|
|
2024-08-16 13:11:39 +05:30
|
|
|
const listQueryKeyRef = useRef<any>();
|
|
|
|
|
|
|
|
|
|
const chartQueryKeyRef = useRef<any>();
|
|
|
|
|
|
|
|
|
|
const [isLoadingQueries, setIsLoadingQueries] = useState<boolean>(false);
|
|
|
|
|
|
2024-07-08 20:02:10 +05:30
|
|
|
const handleToggleShowFrequencyChart = (): void => {
|
|
|
|
|
setShowFrequencyChart(!showFrequencyChart);
|
2024-02-12 00:23:19 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleChangeSelectedView = (view: SELECTED_VIEWS): void => {
|
|
|
|
|
setSelectedView(view);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Switch to query builder view if there are more than 1 queries
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (currentQuery.builder.queryData.length > 1) {
|
|
|
|
|
handleChangeSelectedView(SELECTED_VIEWS.QUERY_BUILDER);
|
|
|
|
|
}
|
2024-08-22 23:59:22 +05:30
|
|
|
if (
|
|
|
|
|
currentQuery.builder.queryData.length === 1 &&
|
|
|
|
|
currentQuery.builder.queryData[0].groupBy.length > 0
|
|
|
|
|
) {
|
|
|
|
|
handleChangeSelectedView(SELECTED_VIEWS.QUERY_BUILDER);
|
|
|
|
|
}
|
|
|
|
|
}, [currentQuery.builder.queryData, currentQuery.builder.queryData.length]);
|
2024-02-12 00:23:19 +05:30
|
|
|
|
|
|
|
|
const isMultipleQueries = useMemo(
|
|
|
|
|
() =>
|
2024-08-23 22:29:07 +05:30
|
|
|
currentQuery.builder.queryData?.length > 1 ||
|
|
|
|
|
currentQuery.builder.queryFormulas?.length > 0,
|
2024-02-12 00:23:19 +05:30
|
|
|
[currentQuery],
|
|
|
|
|
);
|
|
|
|
|
|
2024-08-22 23:59:22 +05:30
|
|
|
const isGroupByPresent = useMemo(
|
|
|
|
|
() =>
|
2024-08-23 22:29:07 +05:30
|
|
|
currentQuery.builder.queryData?.length === 1 &&
|
|
|
|
|
currentQuery.builder.queryData?.[0]?.groupBy?.length > 0,
|
2024-08-22 23:59:22 +05:30
|
|
|
[currentQuery.builder.queryData],
|
|
|
|
|
);
|
|
|
|
|
|
2024-02-12 00:23:19 +05:30
|
|
|
const toolbarViews = useMemo(
|
|
|
|
|
() => ({
|
|
|
|
|
search: {
|
|
|
|
|
name: 'search',
|
|
|
|
|
label: 'Search',
|
2024-08-22 23:59:22 +05:30
|
|
|
disabled: isMultipleQueries || isGroupByPresent,
|
2024-02-12 00:23:19 +05:30
|
|
|
show: true,
|
|
|
|
|
},
|
|
|
|
|
queryBuilder: {
|
|
|
|
|
name: 'query-builder',
|
|
|
|
|
label: 'Query Builder',
|
|
|
|
|
disabled: false,
|
|
|
|
|
show: true,
|
|
|
|
|
},
|
|
|
|
|
clickhouse: {
|
|
|
|
|
name: 'clickhouse',
|
|
|
|
|
label: 'Clickhouse',
|
|
|
|
|
disabled: false,
|
|
|
|
|
show: false,
|
|
|
|
|
},
|
|
|
|
|
}),
|
2024-08-22 23:59:22 +05:30
|
|
|
[isGroupByPresent, isMultipleQueries],
|
2024-02-12 00:23:19 +05:30
|
|
|
);
|
|
|
|
|
|
2023-06-16 13:38:39 +03:00
|
|
|
return (
|
2024-06-18 19:04:06 +05:30
|
|
|
<Sentry.ErrorBoundary fallback={<ErrorBoundaryFallback />}>
|
2024-02-12 00:23:19 +05:30
|
|
|
<Toolbar
|
|
|
|
|
showAutoRefresh={false}
|
|
|
|
|
leftActions={
|
|
|
|
|
<LeftToolbarActions
|
|
|
|
|
items={toolbarViews}
|
|
|
|
|
selectedView={selectedView}
|
|
|
|
|
onChangeSelectedView={handleChangeSelectedView}
|
2024-07-08 20:02:10 +05:30
|
|
|
onToggleHistrogramVisibility={handleToggleShowFrequencyChart}
|
|
|
|
|
showFrequencyChart={showFrequencyChart}
|
2024-02-12 00:23:19 +05:30
|
|
|
/>
|
|
|
|
|
}
|
2024-08-16 13:11:39 +05:30
|
|
|
rightActions={
|
|
|
|
|
<RightToolbarActions
|
|
|
|
|
onStageRunQuery={handleRunQuery}
|
|
|
|
|
listQueryKeyRef={listQueryKeyRef}
|
|
|
|
|
chartQueryKeyRef={chartQueryKeyRef}
|
|
|
|
|
isLoadingQueries={isLoadingQueries}
|
|
|
|
|
/>
|
|
|
|
|
}
|
2024-02-12 00:23:19 +05:30
|
|
|
showOldCTA
|
|
|
|
|
/>
|
|
|
|
|
|
2023-08-29 15:23:22 +03:00
|
|
|
<WrapperStyled>
|
2024-03-12 12:20:45 +05:30
|
|
|
<div className="log-explorer-query-container">
|
|
|
|
|
<div>
|
2023-08-30 20:24:16 +05:30
|
|
|
<ExplorerCard sourcepage={DataSource.LOGS}>
|
2024-02-12 00:23:19 +05:30
|
|
|
<LogExplorerQuerySection selectedView={selectedView} />
|
2023-08-29 15:23:22 +03:00
|
|
|
</ExplorerCard>
|
2024-03-12 12:20:45 +05:30
|
|
|
</div>
|
|
|
|
|
<div className="logs-explorer-views">
|
2024-02-12 00:23:19 +05:30
|
|
|
<LogsExplorerViews
|
|
|
|
|
selectedView={selectedView}
|
2024-07-08 20:02:10 +05:30
|
|
|
showFrequencyChart={showFrequencyChart}
|
2024-08-16 13:11:39 +05:30
|
|
|
listQueryKeyRef={listQueryKeyRef}
|
|
|
|
|
chartQueryKeyRef={chartQueryKeyRef}
|
|
|
|
|
setIsLoadingQueries={setIsLoadingQueries}
|
2024-02-12 00:23:19 +05:30
|
|
|
/>
|
2024-03-12 12:20:45 +05:30
|
|
|
</div>
|
|
|
|
|
</div>
|
2023-08-29 15:23:22 +03:00
|
|
|
</WrapperStyled>
|
2024-06-18 19:04:06 +05:30
|
|
|
</Sentry.ErrorBoundary>
|
2023-06-16 13:38:39 +03:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-23 21:39:59 +03:00
|
|
|
export default LogsExplorer;
|