diff --git a/frontend/app/components/Dashboard/NewDashboard.tsx b/frontend/app/components/Dashboard/NewDashboard.tsx index ae00c2034..b3e6ac59f 100644 --- a/frontend/app/components/Dashboard/NewDashboard.tsx +++ b/frontend/app/components/Dashboard/NewDashboard.tsx @@ -6,6 +6,7 @@ import DashboardSideMenu from './components/DashboardSideMenu'; import { Loader } from 'UI'; import DashboardRouter from './components/DashboardRouter'; import cn from 'classnames'; +import { withSiteId } from 'App/routes'; function NewDashboard(props: RouteComponentProps<{}>) { const { history, match: { params: { siteId, dashboardId, metricId } } } = props; @@ -20,18 +21,26 @@ function NewDashboard(props: RouteComponentProps<{}>) { dashboardStore.selectDashboardById(dashboardId); } }); + if (!dashboardId) { + dashboardStore.selectDefaultDashboard().then(({ dashboardId }) => { + props.history.push(withSiteId(`/dashboard/${dashboardId}`, siteId)); + }, () => { + props.history.push(withSiteId('/dashboard', siteId)); + }) + } + }, [siteId]); return useObserver(() => (
-
+
diff --git a/frontend/app/components/Dashboard/components/DashboardModal/DashboardModal.tsx b/frontend/app/components/Dashboard/components/DashboardModal/DashboardModal.tsx index f310cc824..719729432 100644 --- a/frontend/app/components/Dashboard/components/DashboardModal/DashboardModal.tsx +++ b/frontend/app/components/Dashboard/components/DashboardModal/DashboardModal.tsx @@ -22,11 +22,15 @@ function DashboardModal(props) { const loading = useObserver(() => dashboardStore.isSaving); const onSave = () => { - dashboardStore.save(dashboard).then(hideModal).then(() => { + dashboardStore.save(dashboard).then(async (syncedDashboard) => { if (dashboard.exists()) { - dashboardStore.fetch(dashboard.dashboardId) + await dashboardStore.fetch(dashboard.dashboardId) } + console.log(syncedDashboard, history, siteId, withSiteId(`/dashboard/${syncedDashboard.dashboardId}`, siteId)) + dashboardStore.selectDashboardById(syncedDashboard.dashboardId); + history.push(withSiteId(`/dashboard/${syncedDashboard.dashboardId}`, siteId)) }) + .then(hideModal) } const handleCreateNew = () => { diff --git a/frontend/app/components/Dashboard/components/DashboardSideMenu/DashboardSideMenu.tsx b/frontend/app/components/Dashboard/components/DashboardSideMenu/DashboardSideMenu.tsx index 7d2ca62b4..a2a582a76 100644 --- a/frontend/app/components/Dashboard/components/DashboardSideMenu/DashboardSideMenu.tsx +++ b/frontend/app/components/Dashboard/components/DashboardSideMenu/DashboardSideMenu.tsx @@ -43,7 +43,7 @@ function DashboardSideMenu(props: RouteComponentProps) { const onAddDashboardClick = (e) => { dashboardStore.initDashboard(); - showModal(, { right: true }) + showModal(, { right: true }) } const togglePinned = (dashboard) => { diff --git a/frontend/app/components/Dashboard/components/DashboardView/DashboardView.tsx b/frontend/app/components/Dashboard/components/DashboardView/DashboardView.tsx index 69f7b7297..c3502f7eb 100644 --- a/frontend/app/components/Dashboard/components/DashboardView/DashboardView.tsx +++ b/frontend/app/components/Dashboard/components/DashboardView/DashboardView.tsx @@ -62,8 +62,10 @@ function DashboardView(props: Props) { })) { dashboardStore.deleteDashboard(dashboard).then(() => { dashboardStore.selectDefaultDashboard().then(({ dashboardId }) => { - props.history.push(withSiteId(dashboard(), siteId)); - }); + props.history.push(withSiteId(`/dashboard/${dashboardId}`, siteId)); + }, () => { + props.history.push(withSiteId('/dashboard', siteId)); + }) }); } } diff --git a/frontend/app/mstore/dashboardStore.ts b/frontend/app/mstore/dashboardStore.ts index 922b83536..de61cacd3 100644 --- a/frontend/app/mstore/dashboardStore.ts +++ b/frontend/app/mstore/dashboardStore.ts @@ -341,11 +341,10 @@ export default class DashboardStore implements IDashboardSotre { } else { this.selectedDashboard = this.dashboards[0] } - } - if (this.selectedDashboard) { + resolve(this.selectedDashboard) } - // reject(new Error("No dashboards found")) + reject(new Error("No dashboards found")) }) }