ui: fix pathname reset
This commit is contained in:
parent
78bb1c3c6b
commit
735b86d778
1 changed files with 12 additions and 5 deletions
|
|
@ -3,6 +3,7 @@ import { observer } from 'mobx-react-lite';
|
|||
import { useStore } from 'App/mstore';
|
||||
import { withRouter, RouteComponentProps } from 'react-router-dom';
|
||||
import { Loader } from 'UI';
|
||||
import { withSiteId, dashboard, metrics } from "App/routes";
|
||||
import DashboardRouter from './components/DashboardRouter';
|
||||
import withPermissions from 'HOCs/withPermissions';
|
||||
|
||||
|
|
@ -15,13 +16,19 @@ interface RouterProps {
|
|||
function NewDashboard(props: RouteComponentProps<RouterProps>) {
|
||||
const { history, match: { params: { siteId, dashboardId } } } = props;
|
||||
const { dashboardStore } = useStore();
|
||||
const initId = React.useRef(siteId)
|
||||
const loading = dashboardStore.isLoading;
|
||||
const isMetricDetails = history.location.pathname.includes('/metrics/') || history.location.pathname.includes('/metric/');
|
||||
const isDashboardDetails = history.location.pathname.includes('/dashboard/');
|
||||
const isAlertsDetails = history.location.pathname.includes('/alert/');
|
||||
|
||||
const shouldHideMenu = isMetricDetails || isDashboardDetails || isAlertsDetails;
|
||||
const isDbMetric = /\/dashboard\/\d+\/metric\/\d+/.test(history.location.pathname);
|
||||
const isMetricListMetric = /\/metrics\/\d+/.test(history.location.pathname);
|
||||
useEffect(() => {
|
||||
if (siteId !== initId.current) {
|
||||
if (isMetricListMetric) {
|
||||
history.push(withSiteId(metrics(), siteId))
|
||||
}
|
||||
if (isDbMetric) {
|
||||
history.push(withSiteId(dashboard(), siteId))
|
||||
}
|
||||
}
|
||||
dashboardStore.fetchList().then((resp) => {
|
||||
if (parseInt(dashboardId) > 0) {
|
||||
dashboardStore.selectDashboardById(dashboardId);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue