fix(ui): fix routing in dashboards
This commit is contained in:
parent
d7037771ed
commit
749093d9f6
5 changed files with 25 additions and 11 deletions
|
|
@ -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(() => (
|
||||
<Loader loading={loading}>
|
||||
<div className="page-margin container-90">
|
||||
<div className={cn("side-menu", { 'hidden' : isMetricDetails || dashboardsNumber === 0 })}>
|
||||
<div className={cn("side-menu", { 'hidden' : isMetricDetails })}>
|
||||
<DashboardSideMenu siteId={siteId} />
|
||||
</div>
|
||||
<div
|
||||
className={cn({
|
||||
"side-menu-margined" : !isMetricDetails || dashboardsNumber !== 0,
|
||||
"container-70" : isMetricDetails || dashboardsNumber === 0
|
||||
"side-menu-margined" : !isMetricDetails,
|
||||
"container-70" : isMetricDetails
|
||||
})}
|
||||
>
|
||||
<DashboardRouter siteId={siteId} />
|
||||
|
|
|
|||
|
|
@ -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 = () => {
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ function DashboardSideMenu(props: RouteComponentProps<Props>) {
|
|||
|
||||
const onAddDashboardClick = (e) => {
|
||||
dashboardStore.initDashboard();
|
||||
showModal(<DashboardModal />, { right: true })
|
||||
showModal(<DashboardModal siteId={siteId} />, { right: true })
|
||||
}
|
||||
|
||||
const togglePinned = (dashboard) => {
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue