From da80772de0bbaf61615df57873f5aa899aed7da3 Mon Sep 17 00:00:00 2001 From: Brian Holmes <120223836+briangregoryholmes@users.noreply.github.com> Date: Tue, 20 Aug 2024 12:40:34 -0400 Subject: [PATCH] fix: assign default comparison (#5452) * init commit * fallback comparison for custom ISO ranges --- .../super-pill/components/Comparison.svelte | 4 ++-- .../time-controls/time-control-store.ts | 16 ++++++---------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/web-common/src/features/dashboards/time-controls/super-pill/components/Comparison.svelte b/web-common/src/features/dashboards/time-controls/super-pill/components/Comparison.svelte index a8d37522fe3..6d45853b4ad 100644 --- a/web-common/src/features/dashboards/time-controls/super-pill/components/Comparison.svelte +++ b/web-common/src/features/dashboards/time-controls/super-pill/components/Comparison.svelte @@ -38,7 +38,7 @@ DateTime.fromJSDate(selectedComparison.start).setZone(zone), DateTime.fromJSDate(selectedComparison.end).setZone(zone), ) - : currentInterval; + : undefined; $: firstVisibleMonth = interval?.start ?? DateTime.now(); @@ -104,7 +104,7 @@

no comparison period

{:else} {label} - {#if interval.isValid} + {#if interval?.isValid} {/if} {/if} diff --git a/web-common/src/features/dashboards/time-controls/time-control-store.ts b/web-common/src/features/dashboards/time-controls/time-control-store.ts index c9a31589e34..57ab72d2288 100644 --- a/web-common/src/features/dashboards/time-controls/time-control-store.ts +++ b/web-common/src/features/dashboards/time-controls/time-control-store.ts @@ -358,11 +358,8 @@ function getComparisonTimeRange( timeRange: DashboardTimeControls | undefined, comparisonTimeRange: DashboardTimeControls | undefined, ) { - if (!comparisonTimeRange || !timeRange || !timeRange.name || !allTimeRange) - return undefined; + if (!timeRange || !timeRange.name || !allTimeRange) return undefined; - let selectedComparisonTimeRange: DashboardTimeControls | undefined = - undefined; if (!comparisonTimeRange?.name) { const comparisonOption = DEFAULT_TIME_RANGES[ timeRange.name as TimeComparisonOption @@ -371,7 +368,8 @@ function getComparisonTimeRange( comparisonOption ?? metricsView.availableTimeRanges?.find( (tr) => tr.range === timeRange.name, - )?.comparisonOffsets?.[0]?.offset, + )?.comparisonOffsets?.[0]?.offset ?? + TimeComparisonOption.CONTIGUOUS, allTimeRange.start, allTimeRange.end, timeRange.start, @@ -379,14 +377,14 @@ function getComparisonTimeRange( ); if (range.isComparisonRangeAvailable && range.start && range.end) { - selectedComparisonTimeRange = { + return { start: range.start, end: range.end, name: comparisonOption, }; } } else if (comparisonTimeRange.name === TimeComparisonOption.CUSTOM) { - selectedComparisonTimeRange = comparisonTimeRange; + return comparisonTimeRange; } else { // variable time range of some kind. const comparisonOption = comparisonTimeRange.name as TimeComparisonOption; @@ -396,13 +394,11 @@ function getComparisonTimeRange( comparisonOption, ); - selectedComparisonTimeRange = { + return { ...range, name: comparisonOption, }; } - - return selectedComparisonTimeRange; } /**