change(ui) - redirect to the created dashboard
This commit is contained in:
parent
7b7eefe8f5
commit
c3869c9f18
4 changed files with 19 additions and 14 deletions
|
|
@ -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));
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ function DashboardSideMenu(props: Props) {
|
|||
|
||||
const onAddDashboardClick = (e) => {
|
||||
dashboardStore.initDashboard();
|
||||
showModal(<DashboardModal />, {})
|
||||
showModal(<DashboardModal siteId={siteId} />, {})
|
||||
}
|
||||
|
||||
const togglePinned = (dashboard) => {
|
||||
|
|
|
|||
|
|
@ -118,11 +118,11 @@ function WidgetWrapper(props: Props) {
|
|||
)}
|
||||
</div>
|
||||
|
||||
<LazyLoad height={!isTemplate ? 300 : 10} offset={!isTemplate ? 100 : 10} >
|
||||
{/* <LazyLoad height={!isTemplate ? 300 : 10} offset={!isTemplate ? 100 : 10} > */}
|
||||
<div className="px-4" onClick={onChartClick}>
|
||||
<WidgetChart metric={widget} isWidget={isWidget} />
|
||||
</div>
|
||||
</LazyLoad>
|
||||
{/* </LazyLoad> */}
|
||||
</div>
|
||||
));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<any>
|
||||
setSiteId(siteId: any): void
|
||||
selectDefaultDashboard(): Promise<IDashboard>
|
||||
|
||||
|
|
@ -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<any> {
|
||||
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)
|
||||
// }
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue