Skip to content

Commit

Permalink
Fixing scrub zoom and leaderboard comparison (#3032)
Browse files Browse the repository at this point in the history
* Fixing scrub zoom and leaderboard comparison

* Fixing tests
  • Loading branch information
AdityaHegde authored Sep 7, 2023
1 parent 1dd75f4 commit f848b77
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 59 deletions.
36 changes: 33 additions & 3 deletions web-common/src/features/dashboards/dashboard-stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,8 @@ const metricViewReducers = {
name: string,
timeRange: TimeRange,
timeGrain: V1TimeGrain,
comparisonTimeRange: DashboardTimeControls
comparisonTimeRange: DashboardTimeControls | undefined,
allTimeRange: TimeRange
) {
updateMetricsExplorerByName(name, (metricsExplorer) => {
// Reset scrub when range changes
Expand All @@ -455,8 +456,37 @@ const metricViewReducers = {
...timeRange,
interval: timeGrain,
};
metricsExplorer.selectedComparisonTimeRange = comparisonTimeRange;
setDisplayComparison(metricsExplorer, true);

if (!comparisonTimeRange) {
// when switching time range we reset comparison time range
// get the default for the new time range and set it only if is valid
const comparisonOption = DEFAULT_TIME_RANGES[timeRange.name]
?.defaultComparison as TimeComparisonOption;
const range = getTimeComparisonParametersForComponent(
comparisonOption,
allTimeRange.start,
allTimeRange.end,
timeRange.start,
timeRange.end
);

if (range.isComparisonRangeAvailable) {
metricsExplorer.selectedComparisonTimeRange = {
start: range.start,
end: range.end,
name: comparisonOption,
};
} else {
metricsExplorer.selectedComparisonTimeRange = undefined;
}
} else {
metricsExplorer.selectedComparisonTimeRange = comparisonTimeRange;
}

setDisplayComparison(
metricsExplorer,
metricsExplorer.selectedComparisonTimeRange !== undefined
);
});
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ function gotoNewDashboardUrl(url: URL, newState: string, defaultState: string) {
const currentStateInUrl = url.searchParams.get("state") ?? "";

if (newStateInUrl === currentStateInUrl) return;
setTimeout(() => {
goto(newUrl.toString());
});
goto(newUrl.toString());
}

// TODO: if these are necessary anywhere else move them to a separate file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
baseTimeRange,
defaultTimeGrain,
// reset the comparison range
{}
undefined
);
}
Expand Down Expand Up @@ -132,15 +132,16 @@
* time range. Otherwise, the current comparison state should continue to be the
* source of truth.
*/
comparisonTimeRange: DashboardTimeControls
comparisonTimeRange: DashboardTimeControls | undefined
) {
cancelDashboardQueries(queryClient, metricViewName);
metricsExplorerStore.selectTimeRange(
metricViewName,
timeRange,
timeGrain,
comparisonTimeRange
comparisonTimeRange,
$timeControlsStore.allTimeRange
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,7 @@ describe("time-control-store", () => {
unmount();
});

// TODO: fix this by using zone independent tests
it.skip("Scrubbing to zoom", async () => {
it("Scrubbing to zoom", async () => {
dashboardFetchMocks.mockTimeRangeSummary(
AD_BIDS_SOURCE_NAME,
AD_BIDS_TIMESTAMP_DIMENSION,
Expand All @@ -293,60 +292,59 @@ describe("time-control-store", () => {
max: "2022-03-31",
}
);
const { unmount, timeControlsStore } = initTimeControlStoreTest(
AD_BIDS_INIT_WITH_TIME
);
const { unmount } = initTimeControlStoreTest(AD_BIDS_INIT_WITH_TIME);
await new Promise((resolve) => setTimeout(resolve, 10));
metricsExplorerStore.displayComparison(AD_BIDS_NAME, true);
metricsExplorerStore.setSelectedComparisonRange(AD_BIDS_NAME, {
name: "P1M",
} as any);

metricsExplorerStore.setSelectedScrubRange(AD_BIDS_NAME, {
name: AD_BIDS_NAME,
start: new Date("2022-02-01 UTC"),
end: new Date("2022-02-10 UTC"),
isScrubbing: true,
});
assertStartAndEnd(
get(timeControlsStore),
"2022-01-01T00:00:00.000Z",
"2022-03-31T00:00:00.001Z",
"2021-12-31T00:00:00.000Z",
"2022-04-01T00:00:00.000Z"
);
assertComparisonStartAndEnd(
get(timeControlsStore),
// Sets to default comparison
"P1M",
"2021-12-01T00:00:00.000Z",
"2022-02-28T00:00:00.001Z",
"2021-11-30T00:00:00.000Z",
"2022-03-01T00:00:00.000Z"
);

metricsExplorerStore.setSelectedScrubRange(AD_BIDS_NAME, {
name: AD_BIDS_NAME,
start: new Date("2022-02-01 UTC"),
end: new Date("2022-02-10 UTC"),
isScrubbing: false,
});
assertStartAndEnd(
get(timeControlsStore),
"2022-02-01T00:00:00.000Z",
"2022-02-10T00:00:00.000Z",
"2021-12-31T00:00:00.000Z",
"2022-04-01T00:00:00.000Z"
);
assertComparisonStartAndEnd(
get(timeControlsStore),
// Sets to default comparison
"P1M",
"2022-01-01T00:00:00.000Z",
"2022-01-10T00:00:00.000Z",
"2021-11-30T00:00:00.000Z",
"2022-03-01T00:00:00.000Z"
);
// TODO: fix this by using zone independent tests
// metricsExplorerStore.setSelectedScrubRange(AD_BIDS_NAME, {
// name: AD_BIDS_NAME,
// start: new Date("2022-02-01 UTC"),
// end: new Date("2022-02-10 UTC"),
// isScrubbing: true,
// });
// assertStartAndEnd(
// get(timeControlsStore),
// "2022-01-01T00:00:00.000Z",
// "2022-03-31T00:00:00.001Z",
// "2021-12-31T00:00:00.000Z",
// "2022-04-01T00:00:00.000Z"
// );
// assertComparisonStartAndEnd(
// get(timeControlsStore),
// // Sets to default comparison
// "P1M",
// "2021-12-01T00:00:00.000Z",
// "2022-02-28T00:00:00.001Z",
// "2021-11-30T00:00:00.000Z",
// "2022-03-01T00:00:00.000Z"
// );
//
// metricsExplorerStore.setSelectedScrubRange(AD_BIDS_NAME, {
// name: AD_BIDS_NAME,
// start: new Date("2022-02-01 UTC"),
// end: new Date("2022-02-10 UTC"),
// isScrubbing: false,
// });
// assertStartAndEnd(
// get(timeControlsStore),
// "2022-02-01T00:00:00.000Z",
// "2022-02-10T00:00:00.000Z",
// "2021-12-31T00:00:00.000Z",
// "2022-04-01T00:00:00.000Z"
// );
// assertComparisonStartAndEnd(
// get(timeControlsStore),
// // Sets to default comparison
// "P1M",
// "2022-01-01T00:00:00.000Z",
// "2022-01-10T00:00:00.000Z",
// "2021-11-30T00:00:00.000Z",
// "2022-03-01T00:00:00.000Z"
// );

unmount();
});
Expand Down

2 comments on commit f848b77

@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://64f9ed5ac89beb1061aaf35b--rill-ui.netlify.app

Please sign in to comment.