From 8a8f1b734d6ba23eb7d89aedceba788deb19df57 Mon Sep 17 00:00:00 2001 From: Delirium Date: Mon, 8 Aug 2022 13:38:55 +0300 Subject: [PATCH] fix(ui): fix predefined metrics data fetch (#661) * fix(ui): fix predefined metrics data fetch * fix(ui): remove unused code --- .../ErrorsByOrigin/ErrorsByOrigin.tsx | 7 ++++--- .../components/WidgetChart/WidgetChart.tsx | 7 ++++--- frontend/app/mstore/dashboardStore.ts | 14 +++++++++----- frontend/app/mstore/index.tsx | 4 ++-- frontend/app/mstore/notificationStore.ts | 9 +++++++-- frontend/app/mstore/userStore.ts | 9 +++++++-- 6 files changed, 33 insertions(+), 17 deletions(-) diff --git a/frontend/app/components/Dashboard/Widgets/PredefinedWidgets/ErrorsByOrigin/ErrorsByOrigin.tsx b/frontend/app/components/Dashboard/Widgets/PredefinedWidgets/ErrorsByOrigin/ErrorsByOrigin.tsx index f50859051..e2a80c736 100644 --- a/frontend/app/components/Dashboard/Widgets/PredefinedWidgets/ErrorsByOrigin/ErrorsByOrigin.tsx +++ b/frontend/app/components/Dashboard/Widgets/PredefinedWidgets/ErrorsByOrigin/ErrorsByOrigin.tsx @@ -4,7 +4,7 @@ import { NoContent } from 'UI'; import { Styles } from '../../common'; import { BarChart, Bar, CartesianGrid, Tooltip, - LineChart, Line, Legend, ResponsiveContainer, + Legend, ResponsiveContainer, XAxis, YAxis } from 'recharts'; @@ -13,7 +13,8 @@ interface Props { metric?: any } function ErrorsByOrigin(props: Props) { - const { data, metric } = props; + const { metric } = props; + return ( { if (prevMetricRef.current && prevMetricRef.current.name !== metric.name) { - prevMetricRef.current = metric; - return + prevMetricRef.current = metric; + return }; prevMetricRef.current = metric; const timestmaps = drillDownPeriod.toTimestamps(); @@ -106,10 +106,11 @@ function WidgetChart(props: Props) { } if (metricType === 'predefined') { + const defaultMetric = metric.data.chart.length === 0 ? metricWithData : metric if (isOverviewWidget) { return } - return + return } if (metricType === 'timeseries') { diff --git a/frontend/app/mstore/dashboardStore.ts b/frontend/app/mstore/dashboardStore.ts index 54fbe1972..5fe8c9eb3 100644 --- a/frontend/app/mstore/dashboardStore.ts +++ b/frontend/app/mstore/dashboardStore.ts @@ -19,7 +19,7 @@ import Session from "./types/session"; import Error from "./types/error"; import { FilterKey } from "Types/filter/filterType"; -export interface IDashboardSotre { +export interface IDashboardStore { dashboards: IDashboard[]; selectedDashboard: IDashboard | null; dashboardInstance: IDashboard; @@ -85,12 +85,12 @@ export interface IDashboardSotre { ): Promise; setPeriod(period: any): void; } -export default class DashboardStore implements IDashboardSotre { +export default class DashboardStore implements IDashboardStore { siteId: any = null; // Dashbaord / Widgets dashboards: Dashboard[] = []; selectedDashboard: Dashboard | null = null; - dashboardInstance: IDashboard = new Dashboard(); + dashboardInstance: Dashboard = new Dashboard(); selectedWidgets: IWidget[] = []; currentWidget: Widget = new Widget(); widgetCategories: any[] = []; @@ -214,7 +214,7 @@ export default class DashboardStore implements IDashboardSotre { } fetch(dashboardId: string): Promise { - this.fetchingDashboard = true; + this.setFetchingDashboard(true); return dashboardService .getDashboard(dashboardId) .then((response) => { @@ -223,10 +223,14 @@ export default class DashboardStore implements IDashboardSotre { }); }) .finally(() => { - this.fetchingDashboard = false; + this.setFetchingDashboard(false); }); } + setFetchingDashboard(value: boolean) { + this.fetchingDashboard = value; + } + save(dashboard: IDashboard): Promise { this.isSaving = true; const isCreating = !dashboard.dashboardId; diff --git a/frontend/app/mstore/index.tsx b/frontend/app/mstore/index.tsx index c6ffeb460..445a174f3 100644 --- a/frontend/app/mstore/index.tsx +++ b/frontend/app/mstore/index.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import DashboardStore, { IDashboardSotre } from './dashboardStore'; +import DashboardStore, { IDashboardStore } from './dashboardStore'; import MetricStore, { IMetricStore } from './metricStore'; import UserStore from './userStore'; import RoleStore from './roleStore'; @@ -12,7 +12,7 @@ import NotificationStore from './notificationStore'; import ErrorStore from './errorStore'; export class RootStore { - dashboardStore: IDashboardSotre; + dashboardStore: IDashboardStore; metricStore: IMetricStore; funnelStore: FunnelStore; settingsStore: SettingsStore; diff --git a/frontend/app/mstore/notificationStore.ts b/frontend/app/mstore/notificationStore.ts index 13124ca62..76f63ac2e 100644 --- a/frontend/app/mstore/notificationStore.ts +++ b/frontend/app/mstore/notificationStore.ts @@ -18,6 +18,7 @@ export default class NotificationStore { fetchNotifications: action, ignoreAllNotifications: action, ignoreNotification: action, + setNotificationsCount: action, }); } @@ -74,15 +75,19 @@ export default class NotificationStore { }); } + setNotificationsCount(count: number) { + this.notificationsCount = count; + } + fetchNotificationsCount(): Promise { return new Promise((resolve, reject) => { userService.getNotificationsCount() .then((response: any) => { - this.notificationsCount = response.count; + this.setNotificationsCount(response.count); resolve(response); }).catch((error: any) => { reject(error); }); }); } -} \ No newline at end of file +} diff --git a/frontend/app/mstore/userStore.ts b/frontend/app/mstore/userStore.ts index 0a5c47f53..523ae04f7 100644 --- a/frontend/app/mstore/userStore.ts +++ b/frontend/app/mstore/userStore.ts @@ -23,6 +23,7 @@ export default class UserStore { updateUser: action, updateKey: action, initUser: action, + setLimits: action, }) } @@ -30,7 +31,7 @@ export default class UserStore { return new Promise((resolve, reject) => { userService.getLimits() .then((response: any) => { - this.limits = response; + this.setLimits(response); resolve(response); }).catch((error: any) => { reject(error); @@ -38,6 +39,10 @@ export default class UserStore { }); } + setLimits(limits: any) { + this.limits = limits; + } + initUser(user?: any ): Promise { return new Promise((resolve, reject) => { if (user) { @@ -175,4 +180,4 @@ export default class UserStore { return promise; } -} \ No newline at end of file +}