change(ui): remove additional calls to api after dashb update

This commit is contained in:
nick-delirium 2023-02-24 15:59:16 +01:00
parent 539b91a6e6
commit 0aa5dbb4ac

View file

@ -189,19 +189,19 @@ export default class DashboardStore {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
dashboardService dashboardService
.saveDashboard(dashboard) .saveDashboard(dashboard)
.then((_dashboard) => { .then((_dashboard: any) => {
runInAction(() => { runInAction(() => {
if (isCreating) { if (isCreating) {
toast.success('Dashboard created successfully'); toast.success('Dashboard created successfully');
this.addDashboard(new Dashboard().fromJson(_dashboard)); this.addDashboard(new Dashboard().fromJson(_dashboard));
} else { } else {
toast.success('Dashboard successfully updated '); toast.success('Dashboard successfully updated ');
this.updateDashboard(new Dashboard().fromJson(_dashboard)); this.syncDashboardInfo(_dashboard.dashboardId!, _dashboard);
} }
resolve(_dashboard); resolve(_dashboard);
}); });
}) })
.catch((error) => { .catch(() => {
toast.error('Error saving dashboard'); toast.error('Error saving dashboard');
reject(); reject();
}) })
@ -213,6 +213,14 @@ export default class DashboardStore {
}); });
} }
syncDashboardInfo(id: string, info: { name: string, description: string, isPublic: boolean, createdAt: number }) {
if (this.selectedDashboard !== null) {
this.selectedDashboard.update(info)
const index = this.dashboards.findIndex((d) => d.dashboardId === id);
Object.assign(this.dashboards[index], info)
}
}
saveMetric(metric: Widget, dashboardId: string): Promise<any> { saveMetric(metric: Widget, dashboardId: string): Promise<any> {
const isCreating = !metric.widgetId; const isCreating = !metric.widgetId;
return dashboardService.saveMetric(metric, dashboardId).then((metric) => { return dashboardService.saveMetric(metric, dashboardId).then((metric) => {