2023-06-19 15:57:58 +03:00
|
|
|
import { Tabs } from 'antd';
|
2023-06-28 15:55:20 +03:00
|
|
|
import axios from 'axios';
|
|
|
|
|
import { QueryParams } from 'constants/query';
|
2023-06-23 21:39:59 +03:00
|
|
|
import { initialQueriesMap, PANEL_TYPES } from 'constants/queryBuilder';
|
2023-06-28 15:55:20 +03:00
|
|
|
import {
|
|
|
|
|
COMPOSITE_QUERY,
|
|
|
|
|
PANEL_TYPES_QUERY,
|
|
|
|
|
} from 'constants/queryBuilderQueryNames';
|
|
|
|
|
import ROUTES from 'constants/routes';
|
|
|
|
|
import ExportPanel from 'container/ExportPanel';
|
2023-06-23 21:39:59 +03:00
|
|
|
import { GRAPH_TYPES } from 'container/NewDashboard/ComponentsSlider';
|
2023-06-19 15:57:58 +03:00
|
|
|
import QuerySection from 'container/TracesExplorer/QuerySection';
|
2023-06-28 15:55:20 +03:00
|
|
|
import { useUpdateDashboard } from 'hooks/dashboard/useUpdateDashboard';
|
|
|
|
|
import { addEmptyWidgetInDashboardJSONWithQuery } from 'hooks/dashboard/utils';
|
2023-06-23 21:39:59 +03:00
|
|
|
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
|
2023-06-19 15:57:58 +03:00
|
|
|
import { useShareBuilderUrl } from 'hooks/queryBuilder/useShareBuilderUrl';
|
2023-06-28 15:55:20 +03:00
|
|
|
import { useNotifications } from 'hooks/useNotifications';
|
|
|
|
|
import history from 'lib/history';
|
2023-06-23 21:39:59 +03:00
|
|
|
import { useCallback, useMemo } from 'react';
|
2023-06-28 15:55:20 +03:00
|
|
|
import { generatePath } from 'react-router-dom';
|
|
|
|
|
import { Dashboard } from 'types/api/dashboard/getAll';
|
2023-06-23 21:39:59 +03:00
|
|
|
import { DataSource } from 'types/common/queryBuilder';
|
2023-06-19 15:57:58 +03:00
|
|
|
|
2023-06-28 15:55:20 +03:00
|
|
|
import { ActionsWrapper, Container } from './styles';
|
2023-06-19 15:57:58 +03:00
|
|
|
import { getTabsItems } from './utils';
|
|
|
|
|
|
|
|
|
|
function TracesExplorer(): JSX.Element {
|
2023-06-28 15:55:20 +03:00
|
|
|
const { notifications } = useNotifications();
|
2023-06-23 21:39:59 +03:00
|
|
|
const {
|
|
|
|
|
currentQuery,
|
2023-06-28 15:55:20 +03:00
|
|
|
stagedQuery,
|
2023-06-23 21:39:59 +03:00
|
|
|
panelType,
|
2023-06-28 15:55:20 +03:00
|
|
|
updateAllQueriesOperators,
|
|
|
|
|
redirectWithQueryBuilderData,
|
2023-06-23 21:39:59 +03:00
|
|
|
} = useQueryBuilder();
|
|
|
|
|
|
2023-06-19 15:57:58 +03:00
|
|
|
const tabsItems = getTabsItems();
|
2023-06-23 21:39:59 +03:00
|
|
|
const currentTab = panelType || PANEL_TYPES.TIME_SERIES;
|
2023-06-19 15:57:58 +03:00
|
|
|
|
2023-06-28 15:55:20 +03:00
|
|
|
const defaultQuery = useMemo(
|
|
|
|
|
() =>
|
|
|
|
|
updateAllQueriesOperators(
|
|
|
|
|
initialQueriesMap.traces,
|
|
|
|
|
PANEL_TYPES.TIME_SERIES,
|
|
|
|
|
DataSource.TRACES,
|
|
|
|
|
),
|
|
|
|
|
[updateAllQueriesOperators],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const exportDefaultQuery = useMemo(
|
|
|
|
|
() =>
|
|
|
|
|
updateAllQueriesOperators(
|
|
|
|
|
stagedQuery || initialQueriesMap.traces,
|
|
|
|
|
PANEL_TYPES.TIME_SERIES,
|
|
|
|
|
DataSource.TRACES,
|
|
|
|
|
),
|
|
|
|
|
[stagedQuery, updateAllQueriesOperators],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const { mutate: updateDashboard, isLoading } = useUpdateDashboard();
|
|
|
|
|
|
|
|
|
|
const handleExport = useCallback(
|
|
|
|
|
(dashboard: Dashboard | null): void => {
|
|
|
|
|
if (!dashboard) return;
|
|
|
|
|
|
|
|
|
|
const updatedDashboard = addEmptyWidgetInDashboardJSONWithQuery(
|
|
|
|
|
dashboard,
|
|
|
|
|
exportDefaultQuery,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
updateDashboard(updatedDashboard, {
|
|
|
|
|
onSuccess: (data) => {
|
|
|
|
|
const dashboardEditView = `${generatePath(ROUTES.DASHBOARD, {
|
|
|
|
|
dashboardId: data?.payload?.uuid,
|
|
|
|
|
})}/new?${QueryParams.graphType}=graph&${
|
|
|
|
|
QueryParams.widgetId
|
2023-06-30 11:18:12 +05:30
|
|
|
}=empty&${COMPOSITE_QUERY}=${encodeURIComponent(
|
|
|
|
|
JSON.stringify(exportDefaultQuery),
|
|
|
|
|
)}`;
|
2023-06-28 15:55:20 +03:00
|
|
|
|
|
|
|
|
history.push(dashboardEditView);
|
|
|
|
|
},
|
|
|
|
|
onError: (error) => {
|
|
|
|
|
if (axios.isAxiosError(error)) {
|
|
|
|
|
notifications.error({
|
|
|
|
|
message: error.message,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
[exportDefaultQuery, notifications, updateDashboard],
|
|
|
|
|
);
|
|
|
|
|
|
2023-06-19 15:57:58 +03:00
|
|
|
const handleTabChange = useCallback(
|
2023-06-23 21:39:59 +03:00
|
|
|
(newPanelType: string): void => {
|
|
|
|
|
if (panelType === newPanelType) return;
|
|
|
|
|
|
|
|
|
|
const query = updateAllQueriesOperators(
|
|
|
|
|
currentQuery,
|
|
|
|
|
newPanelType as GRAPH_TYPES,
|
|
|
|
|
DataSource.TRACES,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
redirectWithQueryBuilderData(query, { [PANEL_TYPES_QUERY]: newPanelType });
|
2023-06-19 15:57:58 +03:00
|
|
|
},
|
2023-06-23 21:39:59 +03:00
|
|
|
[
|
|
|
|
|
currentQuery,
|
|
|
|
|
panelType,
|
|
|
|
|
redirectWithQueryBuilderData,
|
|
|
|
|
updateAllQueriesOperators,
|
|
|
|
|
],
|
2023-06-19 15:57:58 +03:00
|
|
|
);
|
|
|
|
|
|
2023-06-28 15:55:20 +03:00
|
|
|
useShareBuilderUrl(defaultQuery);
|
2023-06-19 15:57:58 +03:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<QuerySection />
|
|
|
|
|
|
|
|
|
|
<Container>
|
2023-06-28 15:55:20 +03:00
|
|
|
<ActionsWrapper>
|
2023-06-30 11:18:12 +05:30
|
|
|
<ExportPanel
|
|
|
|
|
query={stagedQuery}
|
|
|
|
|
isLoading={isLoading}
|
|
|
|
|
onExport={handleExport}
|
|
|
|
|
/>
|
2023-06-28 15:55:20 +03:00
|
|
|
</ActionsWrapper>
|
|
|
|
|
|
2023-06-23 21:39:59 +03:00
|
|
|
<Tabs
|
|
|
|
|
defaultActiveKey={currentTab}
|
|
|
|
|
activeKey={currentTab}
|
|
|
|
|
items={tabsItems}
|
|
|
|
|
onChange={handleTabChange}
|
|
|
|
|
/>
|
2023-06-19 15:57:58 +03:00
|
|
|
</Container>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default TracesExplorer;
|