diff --git a/frontend/app/components/Dashboard/components/DashboardModal/DashboardModal.tsx b/frontend/app/components/Dashboard/components/DashboardModal/DashboardModal.tsx index 575cb7de8..055833ee7 100644 --- a/frontend/app/components/Dashboard/components/DashboardModal/DashboardModal.tsx +++ b/frontend/app/components/Dashboard/components/DashboardModal/DashboardModal.tsx @@ -6,7 +6,7 @@ import { Button } from 'UI'; import { withRouter } from 'react-router-dom'; import { useStore } from 'App/mstore'; import { useModal } from 'App/components/Modal'; -import { dashboardMetricCreate, withSiteId } from 'App/routes'; +import { dashboardMetricCreate, withSiteId, dashboardSelected } from 'App/routes'; interface Props { history: any @@ -22,10 +22,11 @@ function DashboardModal(props) { const loading = useObserver(() => dashboardStore.isSaving); const onSave = () => { - dashboardStore.save(dashboard).then(hideModal).then(() => { - if (dashboard.exists()) { - dashboardStore.fetch(dashboard.dashboardId) - } + dashboardStore.save(dashboard).then((_dashboard: any) => { + hideModal(); + dashboardStore.selectDashboardById(_dashboard.dashboardId).then(() => { + history.push(withSiteId(dashboardSelected(_dashboard.dashboardId), siteId)); + }); }) } diff --git a/frontend/app/components/Dashboard/components/DashboardSideMenu/DashboardSideMenu.tsx b/frontend/app/components/Dashboard/components/DashboardSideMenu/DashboardSideMenu.tsx index 9dd64733c..ea6191062 100644 --- a/frontend/app/components/Dashboard/components/DashboardSideMenu/DashboardSideMenu.tsx +++ b/frontend/app/components/Dashboard/components/DashboardSideMenu/DashboardSideMenu.tsx @@ -40,7 +40,7 @@ function DashboardSideMenu(props: Props) { const onAddDashboardClick = (e) => { dashboardStore.initDashboard(); - showModal(, {}) + showModal(, {}) } const togglePinned = (dashboard) => { diff --git a/frontend/app/components/Dashboard/components/WidgetWrapper/WidgetWrapper.tsx b/frontend/app/components/Dashboard/components/WidgetWrapper/WidgetWrapper.tsx index b29ab800c..589d0c084 100644 --- a/frontend/app/components/Dashboard/components/WidgetWrapper/WidgetWrapper.tsx +++ b/frontend/app/components/Dashboard/components/WidgetWrapper/WidgetWrapper.tsx @@ -118,11 +118,11 @@ function WidgetWrapper(props: Props) { )} - + {/* */}
-
+ {/*
*/} )); } diff --git a/frontend/app/mstore/dashboardStore.ts b/frontend/app/mstore/dashboardStore.ts index 56c92e4b9..65dcaf82b 100644 --- a/frontend/app/mstore/dashboardStore.ts +++ b/frontend/app/mstore/dashboardStore.ts @@ -55,7 +55,7 @@ export interface IDashboardSotre { getDashboard(dashboardId: string): IDashboard|null getDashboardCount(): void updateDashboard(dashboard: IDashboard): void - selectDashboardById(dashboardId: string): void + selectDashboardById(dashboardId: string): Promise setSiteId(siteId: any): void selectDefaultDashboard(): Promise @@ -219,14 +219,15 @@ export default class DashboardStore implements IDashboardSotre { return new Promise((resolve, reject) => { dashboardService.saveDashboard(dashboard).then(_dashboard => { runInAction(() => { + const newDashboard = new Dashboard().fromJson(_dashboard) if (isCreating) { toast.success('Dashboard created successfully') - this.addDashboard(new Dashboard().fromJson(_dashboard)) + this.addDashboard(newDashboard) } else { toast.success('Dashboard updated successfully') - this.updateDashboard(new Dashboard().fromJson(_dashboard)) + this.updateDashboard(newDashboard) } - resolve(_dashboard) + resolve(newDashboard) }) }).catch(error => { toast.error('Error saving dashboard') @@ -321,8 +322,11 @@ export default class DashboardStore implements IDashboardSotre { } } - selectDashboardById = (dashboardId: any) => { - this.selectedDashboard = this.dashboards.find(d => d.dashboardId == dashboardId) || new Dashboard(); + selectDashboardById(dashboardId: any): Promise { + return new Promise((resolve, reject) => { + this.selectedDashboard = this.dashboards.find(d => d.dashboardId == dashboardId) || new Dashboard(); + resolve(this.selectedDashboard) + }) // if (this.selectedDashboard.dashboardId) { // this.fetch(this.selectedDashboard.dashboardId) // }