Skip to content

Commit

Permalink
Refactor date handling in AggregateUtil and XAxisUtil, and improve er…
Browse files Browse the repository at this point in the history
…ror handling in MetricView and IncidentView components
  • Loading branch information
simlarsen committed Dec 16, 2024
1 parent 187d41e commit 53238ae
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Common/Server/Types/AnalyticsDatabase/AggregateBy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import AggregationInterval from "Common/Types/BaseDatabase/AggregationInterval";
import CommonAggregateBy from "Common/Types/BaseDatabase/AggregateBy";
import AnalyticsBaseModel from "Common/Models/AnalyticsModels/AnalyticsBaseModel/AnalyticsBaseModel";
import DatabaseCommonInteractionProps from "Common/Types/BaseDatabase/DatabaseCommonInteractionProps";
import OneUptimeDate from "../../../Types/Date";

export default interface AggregateBy<TBaseModel extends AnalyticsBaseModel>
extends CommonAggregateBy<TBaseModel> {
Expand All @@ -13,6 +14,9 @@ export class AggregateUtil {
startDate: Date;
endDate: Date;
}): AggregationInterval {
data.startDate = OneUptimeDate.fromString(data.startDate);
data.endDate = OneUptimeDate.fromString(data.endDate);

const diff: number = data.endDate.getTime() - data.startDate.getTime();

if (diff <= 1000 * 60 * 60 * 3) {
Expand Down
5 changes: 3 additions & 2 deletions Common/UI/Components/Charts/Utils/XAxis.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import OneUptimeDate from "../../../../Types/Date";
import NotImplementedException from "../../../../Types/Exception/NotImplementedException";
import XAxisMaxMin from "../Types/XAxis/XAxisMaxMin";
import XAxisPrecision from "../Types/XAxis/XAxisPrecision";
Expand All @@ -15,8 +16,8 @@ export default class XAxisUtil {
throw new NotImplementedException();
}

const startDate: Date = data.xAxisMin as Date;
const endDate: Date = data.xAxisMax as Date;
const startDate: Date = OneUptimeDate.fromString(data.xAxisMin as Date);
const endDate: Date = OneUptimeDate.fromString(data.xAxisMax as Date);

const totalMilliseconds: number = endDate.getTime() - startDate.getTime();
const totalSeconds: number = totalMilliseconds / 1000;
Expand Down
6 changes: 6 additions & 0 deletions Dashboard/src/Components/Metrics/MetricView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ const MetricView: FunctionComponent<ComponentProps> = (
],
});
}

if (props.data) {
fetchAggregatedResults().catch((err: Error) => {
setMetricResultsError(API.getFriendlyErrorMessage(err as Error));
});
}
} catch (err) {
setIsPageLoading(false);
setPageError(API.getFriendlyErrorMessage(err as Error));
Expand Down
2 changes: 1 addition & 1 deletion Dashboard/src/Pages/Incidents/View/Index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ const IncidentView: FunctionComponent<
telemetryQuery.metricViewData && (
<Card
title={"Metrics"}
description={"Metrics for this incident."}
description={"Metrics related to this incident."}
rightElement={
telemetryQuery.metricViewData.startAndEndDate ? (
<HeaderAlert
Expand Down

0 comments on commit 53238ae

Please sign in to comment.