bug: useHistory is removed and dashboard loading component is removed (#802)

* bug: useHistory is removed and dashboard loading component is removed

* chore: new dashboard is updated

* chore: new dashboard is updated

* chore: sidenav is updated

* chore: getX console is removed

* chore: sidenav is updated with correct pathname
This commit is contained in:
palash-signoz 2022-03-22 21:56:12 +05:30 committed by GitHub
parent b2e78b9358
commit 1c5c65ddf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 39 additions and 52 deletions

View File

@ -3,8 +3,8 @@ import {
EditFilled, EditFilled,
FullscreenOutlined, FullscreenOutlined,
} from '@ant-design/icons'; } from '@ant-design/icons';
import React, { useCallback } from 'react'; import history from 'lib/history';
import { useHistory, useLocation } from 'react-router'; import React from 'react';
import { Widgets } from 'types/api/dashboard/getAll'; import { Widgets } from 'types/api/dashboard/getAll';
import { Container } from './styles'; import { Container } from './styles';
@ -14,13 +14,12 @@ function Bar({
onViewFullScreenHandler, onViewFullScreenHandler,
onDeleteHandler, onDeleteHandler,
}: BarProps): JSX.Element { }: BarProps): JSX.Element {
const { push } = useHistory(); const onEditHandler = (): void => {
const { pathname } = useLocation();
const onEditHandler = useCallback(() => {
const widgetId = widget.id; const widgetId = widget.id;
push(`${pathname}/new?widgetId=${widgetId}&graphType=${widget.panelTypes}`); history.push(
}, [push, pathname, widget]); `${window.location.pathname}/new?widgetId=${widgetId}&graphType=${widget.panelTypes}`,
);
};
return ( return (
<Container> <Container>

View File

@ -1,12 +1,16 @@
/* eslint-disable react/jsx-no-useless-fragment */
/* eslint-disable react/no-unstable-nested-components */
/* eslint-disable react/display-name */ /* eslint-disable react/display-name */
import { SaveFilled } from '@ant-design/icons'; import { SaveFilled } from '@ant-design/icons';
import { notification } from 'antd'; import { notification } from 'antd';
import updateDashboardApi from 'api/dashboard/update'; import updateDashboardApi from 'api/dashboard/update';
import Spinner from 'components/Spinner'; import Spinner from 'components/Spinner';
import { GRAPH_TYPES } from 'container/NewDashboard/ComponentsSlider'; import { GRAPH_TYPES } from 'container/NewDashboard/ComponentsSlider';
import history from 'lib/history';
import React, { memo, useCallback, useEffect, useRef, useState } from 'react'; import React, { memo, useCallback, useEffect, useRef, useState } from 'react';
import { Layout } from 'react-grid-layout'; import { Layout } from 'react-grid-layout';
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
import { useLocation } from 'react-router-dom';
import { AppState } from 'store/reducers'; import { AppState } from 'store/reducers';
import DashboardReducer from 'types/reducer/dashboards'; import DashboardReducer from 'types/reducer/dashboards';
import { v4 } from 'uuid'; import { v4 } from 'uuid';
@ -97,15 +101,13 @@ function GridGraph(): JSX.Element {
setLayout(() => { setLayout(() => {
const getX = (): number => { const getX = (): number => {
if (preLayouts && preLayouts?.length > 0) { if (preLayouts && preLayouts?.length > 0) {
const last = preLayouts[preLayouts?.length - 1]; const last = preLayouts[(preLayouts?.length || 0) - 1];
return (last.w + last.x) % 12; return (last.w + last.x) % 12;
} }
return 0; return 0;
}; };
console.log({ x: getX() });
return [ return [
...preLayouts, ...preLayouts,
{ {

View File

@ -16,13 +16,11 @@ const routesToSkip = [
]; ];
function TopNav(): JSX.Element | null { function TopNav(): JSX.Element | null {
const { pathname } = useLocation();
if (history.location.pathname === ROUTES.SIGN_UP) { if (history.location.pathname === ROUTES.SIGN_UP) {
return null; return null;
} }
const checkRouteExists = (currentPath: string) => { const checkRouteExists = (currentPath: string): boolean => {
for (let i = 0; i < routesToSkip.length; ++i) { for (let i = 0; i < routesToSkip.length; ++i) {
if ( if (
matchPath(currentPath, { path: routesToSkip[i], exact: true, strict: true }) matchPath(currentPath, { path: routesToSkip[i], exact: true, strict: true })
@ -39,7 +37,7 @@ function TopNav(): JSX.Element | null {
<ShowBreadcrumbs /> <ShowBreadcrumbs />
</Col> </Col>
{!checkRouteExists(pathname) && ( {!checkRouteExists(history.location.pathname) && (
<Col span={8}> <Col span={8}>
<DateTimeSelector /> <DateTimeSelector />
</Col> </Col>

View File

@ -1,12 +1,14 @@
/* eslint-disable react/no-unstable-nested-components */
import { PlusOutlined } from '@ant-design/icons'; import { PlusOutlined } from '@ant-design/icons';
import { Row, Table, TableColumnProps, Typography } from 'antd'; import { Row, Table, TableColumnProps, Typography } from 'antd';
import createDashboard from 'api/dashboard/create'; import createDashboard from 'api/dashboard/create';
import { AxiosError } from 'axios'; import { AxiosError } from 'axios';
import TextToolTip from 'components/TextToolTip'; import TextToolTip from 'components/TextToolTip';
import ROUTES from 'constants/routes'; import ROUTES from 'constants/routes';
import history from 'lib/history';
import React, { useCallback, useState } from 'react'; import React, { useCallback, useState } from 'react';
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
import { generatePath, useHistory } from 'react-router-dom'; import { generatePath } from 'react-router-dom';
import { AppState } from 'store/reducers'; import { AppState } from 'store/reducers';
import DashboardReducer from 'types/reducer/dashboards'; import DashboardReducer from 'types/reducer/dashboards';
import { v4 } from 'uuid'; import { v4 } from 'uuid';
@ -19,7 +21,7 @@ import Name from './TableComponents/Name';
import Tags from './TableComponents/Tags'; import Tags from './TableComponents/Tags';
function ListOfAllDashboard(): JSX.Element { function ListOfAllDashboard(): JSX.Element {
const { dashboards } = useSelector<AppState, DashboardReducer>( const { dashboards, loading } = useSelector<AppState, DashboardReducer>(
(state) => state.dashboards, (state) => state.dashboards,
); );
@ -29,8 +31,6 @@ function ListOfAllDashboard(): JSX.Element {
errorMessage: '', errorMessage: '',
}); });
const { push } = useHistory();
const columns: TableColumnProps<Data>[] = [ const columns: TableColumnProps<Data>[] = [
{ {
title: 'Name', title: 'Name',
@ -103,7 +103,7 @@ function ListOfAllDashboard(): JSX.Element {
...newDashboardState, ...newDashboardState,
loading: false, loading: false,
}); });
push( history.push(
generatePath(ROUTES.DASHBOARD, { generatePath(ROUTES.DASHBOARD, {
dashboardId: newDashboardId, dashboardId: newDashboardId,
}), }),
@ -123,7 +123,7 @@ function ListOfAllDashboard(): JSX.Element {
errorMessage: (error as AxiosError).toString() || 'Something went Wrong', errorMessage: (error as AxiosError).toString() || 'Something went Wrong',
}); });
} }
}, [newDashboardState, push]); }, [newDashboardState]);
const getText = (): string => { const getText = (): string => {
if (!newDashboardState.error && !newDashboardState.loading) { if (!newDashboardState.error && !newDashboardState.loading) {
@ -147,6 +147,7 @@ function ListOfAllDashboard(): JSX.Element {
showHeader showHeader
bordered bordered
sticky sticky
loading={loading}
title={(): JSX.Element => { title={(): JSX.Element => {
return ( return (
<Row justify="space-between"> <Row justify="space-between">

View File

@ -4,17 +4,17 @@ import { METRICS_PAGE_QUERY_PARAM } from 'constants/query';
import ROUTES from 'constants/routes'; import ROUTES from 'constants/routes';
import React from 'react'; import React from 'react';
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
import { useHistory, useParams } from 'react-router-dom'; import { useParams } from 'react-router-dom';
import { topEndpointListItem } from 'store/actions/MetricsActions'; import { topEndpointListItem } from 'store/actions/MetricsActions';
import { AppState } from 'store/reducers'; import { AppState } from 'store/reducers';
import { GlobalReducer } from 'types/reducer/globalTime'; import { GlobalReducer } from 'types/reducer/globalTime';
import history from 'lib/history';
function TopEndpointsTable(props: TopEndpointsTableProps): JSX.Element { function TopEndpointsTable(props: TopEndpointsTableProps): JSX.Element {
const { minTime, maxTime } = useSelector<AppState, GlobalReducer>( const { minTime, maxTime } = useSelector<AppState, GlobalReducer>(
(state) => state.globalTime, (state) => state.globalTime,
); );
const history = useHistory();
const params = useParams<{ servicename: string }>(); const params = useParams<{ servicename: string }>();
const handleOnClick = (operation: string): void => { const handleOnClick = (operation: string): void => {

View File

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { notification } from 'antd'; import { notification } from 'antd';
import { updateDashboard } from 'container/GridGraphLayout/utils'; import { updateDashboard } from 'container/GridGraphLayout/utils';
import React, { useCallback } from 'react'; import React, { useCallback } from 'react';
@ -32,7 +33,7 @@ function DashboardGraphSlider(): JSX.Element {
const getX = (): number => { const getX = (): number => {
if (data.layout && data.layout?.length > 0) { if (data.layout && data.layout?.length > 0) {
const lastIndexX = data.layout[data.layout?.length - 1]; const lastIndexX = data.layout[(data.layout?.length || 0) - 1];
return (lastIndexX.w + lastIndexX.x) % 12; return (lastIndexX.w + lastIndexX.x) % 12;
} }
return 0; return 0;
@ -46,7 +47,7 @@ function DashboardGraphSlider(): JSX.Element {
...(data.layout || []), ...(data.layout || []),
{ {
h: 2, h: 2,
i: ((data.layout || [])?.length + 1).toString(), i: (((data.layout || [])?.length || 0) + 1).toString(),
w: 6, w: 6,
x: getX(), x: getX(),
y: 0, y: 0,

View File

@ -1,10 +1,11 @@
import { Button } from 'antd'; import { Button } from 'antd';
import ROUTES from 'constants/routes'; import ROUTES from 'constants/routes';
import { GRAPH_TYPES } from 'container/NewDashboard/ComponentsSlider'; import { GRAPH_TYPES } from 'container/NewDashboard/ComponentsSlider';
import history from 'lib/history';
import { DashboardWidgetPageParams } from 'pages/DashboardWidget'; import { DashboardWidgetPageParams } from 'pages/DashboardWidget';
import React, { useCallback, useEffect, useMemo, useState } from 'react'; import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { connect, useSelector } from 'react-redux'; import { connect, useSelector } from 'react-redux';
import { useHistory, useLocation, useParams } from 'react-router'; import { useLocation, useParams } from 'react-router';
import { generatePath } from 'react-router-dom'; import { generatePath } from 'react-router-dom';
import { bindActionCreators, Dispatch } from 'redux'; import { bindActionCreators, Dispatch } from 'redux';
import { ThunkDispatch } from 'redux-thunk'; import { ThunkDispatch } from 'redux-thunk';
@ -57,7 +58,6 @@ function NewWidget({
const { widgets } = selectedDashboard.data; const { widgets } = selectedDashboard.data;
const { push } = useHistory();
const { search } = useLocation(); const { search } = useLocation();
const query = useMemo(() => { const query = useMemo(() => {
@ -154,8 +154,8 @@ function NewWidget({
}; };
const onClickDiscardHandler = useCallback(() => { const onClickDiscardHandler = useCallback(() => {
push(generatePath(ROUTES.DASHBOARD, { dashboardId })); history.push(generatePath(ROUTES.DASHBOARD, { dashboardId }));
}, [dashboardId, push]); }, [dashboardId]);
const getQueryResult = useCallback(() => { const getQueryResult = useCallback(() => {
if (selectedWidget?.id.length !== 0) { if (selectedWidget?.id.length !== 0) {

View File

@ -31,9 +31,10 @@ function SideNav({ toggleDarkMode }: Props): JSX.Element {
const [collapsed, setCollapsed] = useState<boolean>( const [collapsed, setCollapsed] = useState<boolean>(
getLocalStorageKey(IS_SIDEBAR_COLLAPSED) === 'true', getLocalStorageKey(IS_SIDEBAR_COLLAPSED) === 'true',
); );
const { pathname } = useLocation();
const { isDarkMode } = useSelector<AppState, AppReducer>((state) => state.app); const { isDarkMode } = useSelector<AppState, AppReducer>((state) => state.app);
const { pathname } = useLocation();
const toggleTheme = useCallback(() => { const toggleTheme = useCallback(() => {
const preMode: appMode = isDarkMode ? 'lightMode' : 'darkMode'; const preMode: appMode = isDarkMode ? 'lightMode' : 'darkMode';
setTheme(preMode); setTheme(preMode);
@ -61,7 +62,7 @@ function SideNav({ toggleDarkMode }: Props): JSX.Element {
useLayoutEffect(() => { useLayoutEffect(() => {
dispatch(SideBarCollapse(collapsed)); dispatch(SideBarCollapse(collapsed));
}, [collapsed]); }, [collapsed, dispatch]);
const onClickHandler = useCallback( const onClickHandler = useCallback(
(to: string) => { (to: string) => {

View File

@ -1,27 +1,16 @@
import Spinner from 'components/Spinner';
import ListOfAllDashboard from 'container/ListOfDashboard'; import ListOfAllDashboard from 'container/ListOfDashboard';
import React, { useEffect } from 'react'; import React, { useEffect } from 'react';
import { connect, useSelector } from 'react-redux'; import { connect } from 'react-redux';
import { bindActionCreators } from 'redux'; import { bindActionCreators } from 'redux';
import { ThunkDispatch } from 'redux-thunk'; import { ThunkDispatch } from 'redux-thunk';
import { GetAllDashboards } from 'store/actions'; import { GetAllDashboards } from 'store/actions';
import { AppState } from 'store/reducers';
import AppActions from 'types/actions'; import AppActions from 'types/actions';
import DashboardReducer from 'types/reducer/dashboards';
function Dashboard({ getAllDashboards }: DashboardProps): JSX.Element { function Dashboard({ getAllDashboards }: DashboardProps): JSX.Element {
const { loading } = useSelector<AppState, DashboardReducer>(
(state) => state.dashboards,
);
useEffect(() => { useEffect(() => {
getAllDashboards(); getAllDashboards();
}, [getAllDashboards]); }, [getAllDashboards]);
if (loading) {
return <Spinner size="large" tip="Loading.." />;
}
return <ListOfAllDashboard />; return <ListOfAllDashboard />;
} }

View File

@ -5,24 +5,19 @@ import { GRAPH_TYPES } from 'container/NewDashboard/ComponentsSlider';
import NewWidget from 'container/NewWidget'; import NewWidget from 'container/NewWidget';
import React, { useEffect, useRef, useState } from 'react'; import React, { useEffect, useRef, useState } from 'react';
import { connect, useSelector } from 'react-redux'; import { connect, useSelector } from 'react-redux';
import { import { generatePath, useLocation, useParams } from 'react-router-dom';
generatePath,
useHistory,
useLocation,
useParams,
} from 'react-router-dom';
import { bindActionCreators, Dispatch } from 'redux'; import { bindActionCreators, Dispatch } from 'redux';
import { ThunkDispatch } from 'redux-thunk'; import { ThunkDispatch } from 'redux-thunk';
import { GetDashboard, GetDashboardProps } from 'store/actions'; import { GetDashboard, GetDashboardProps } from 'store/actions';
import { AppState } from 'store/reducers'; import { AppState } from 'store/reducers';
import AppActions from 'types/actions'; import AppActions from 'types/actions';
import DashboardReducer from 'types/reducer/dashboards'; import DashboardReducer from 'types/reducer/dashboards';
import history from 'lib/history';
function DashboardWidget({ getDashboard }: NewDashboardProps): JSX.Element { function DashboardWidget({ getDashboard }: NewDashboardProps): JSX.Element {
const { search } = useLocation(); const { search } = useLocation();
const { dashboardId } = useParams<DashboardWidgetPageParams>(); const { dashboardId } = useParams<DashboardWidgetPageParams>();
const { push } = useHistory();
const [selectedGraph, setSelectedGraph] = useState<GRAPH_TYPES>(); const [selectedGraph, setSelectedGraph] = useState<GRAPH_TYPES>();
const { loading, dashboards, error, errorMessage } = useSelector< const { loading, dashboards, error, errorMessage } = useSelector<
AppState, AppState,
@ -42,11 +37,11 @@ function DashboardWidget({ getDashboard }: NewDashboardProps): JSX.Element {
const graphType = params.get('graphType') as GRAPH_TYPES | null; const graphType = params.get('graphType') as GRAPH_TYPES | null;
if (graphType === null) { if (graphType === null) {
push(generatePath(ROUTES.DASHBOARD, { dashboardId })); history.push(generatePath(ROUTES.DASHBOARD, { dashboardId }));
} else { } else {
setSelectedGraph(graphType); setSelectedGraph(graphType);
} }
}, [dashboardId, push, search]); }, [dashboardId, search]);
const counter = useRef(0); const counter = useRef(0);

View File

@ -21,4 +21,5 @@ export interface ApplySettingsToPanelProps {
timePreferance: Widgets['timePreferance']; timePreferance: Widgets['timePreferance'];
nullZeroValues: Widgets['nullZeroValues']; nullZeroValues: Widgets['nullZeroValues'];
widgetId: Widgets['id']; widgetId: Widgets['id'];
yAxisUnit: Widgets['yAxisUnit'];
} }