Skip to content

Commit

Permalink
fix: assign default comparison (#5452)
Browse files Browse the repository at this point in the history
* init commit

* fallback comparison for custom ISO ranges
  • Loading branch information
briangregoryholmes authored and ericpgreen2 committed Aug 23, 2024
1 parent 26e661b commit da80772
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
DateTime.fromJSDate(selectedComparison.start).setZone(zone),
DateTime.fromJSDate(selectedComparison.end).setZone(zone),
)
: currentInterval;
: undefined;
$: firstVisibleMonth = interval?.start ?? DateTime.now();
Expand Down Expand Up @@ -104,7 +104,7 @@
<p>no comparison period</p>
{:else}
<b class="line-clamp-1">{label}</b>
{#if interval.isValid}
{#if interval?.isValid}
<RangeDisplay {interval} {grain} />
{/if}
{/if}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -371,22 +368,23 @@ 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,
timeRange.end,
);

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;
Expand All @@ -396,13 +394,11 @@ function getComparisonTimeRange(
comparisonOption,
);

selectedComparisonTimeRange = {
return {
...range,
name: comparisonOption,
};
}

return selectedComparisonTimeRange;
}

/**
Expand Down

2 comments on commit da80772

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Published on https://ui.rilldata.com as production
🚀 Deployed on https://66c9153c57638b3848a0e636--rill-ui.netlify.app

Please sign in to comment.