Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tweak: disable comparisons when viewing max range #6274

Merged
merged 5 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion web-common/src/components/date-picker/DateInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
const dateString = e.currentTarget.value;

let date: DateTime = DateTime.invalid("invalid");

let format: string | null = null;

for (const potentialFormat of formats) {
Expand Down
13 changes: 9 additions & 4 deletions web-common/src/features/dashboards/stores/dashboard-stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import {
} from "@rilldata/web-common/features/dashboards/stores/filter-utils";
import type { MetricsExplorerEntity } from "@rilldata/web-common/features/dashboards/stores/metrics-explorer-entity";
import { TDDChart } from "@rilldata/web-common/features/dashboards/time-dimension-details/types";
import type {
DashboardTimeControls,
ScrubRange,
TimeRange,
import {
TimeRangePreset,
type DashboardTimeControls,
type ScrubRange,
type TimeRange,
} from "@rilldata/web-common/lib/time/types";
import { DashboardState_ActivePage } from "@rilldata/web-common/proto/gen/rill/ui/v1/dashboard_pb";
import type {
Expand Down Expand Up @@ -531,6 +532,10 @@ const metricsViewReducers = {
// Reset scrub when range changes
setSelectedScrubRange(metricsExplorer, undefined);

if (timeRange.name === TimeRangePreset.ALL_TIME) {
metricsExplorer.showTimeComparison = false;
}

metricsExplorer.selectedTimeRange = {
...timeRange,
interval: timeGrain,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { getStateManagers } from "@rilldata/web-common/features/dashboards/state-managers/state-managers";
import {
TimeComparisonOption,
TimeRangePreset,
type DashboardTimeControls,
type TimeRange,
} from "@rilldata/web-common/lib/time/types";
Expand Down Expand Up @@ -69,10 +70,17 @@
metricsViewSpec,
);
}

$: disabled =
selectedTimeRange?.name === TimeRangePreset.ALL_TIME || undefined;
</script>

<div class="wrapper">
<div
class="wrapper"
title={disabled && "Comparison not available when viewing all time range"}
>
<button
{disabled}
class="flex gap-x-1.5 cursor-pointer"
on:click={() => {
metricsExplorerStore.displayTimeComparison(
Expand All @@ -91,10 +99,15 @@
}}
>
<div class="pointer-events-none flex items-center gap-x-1.5">
<Switch checked={showTimeComparison} id="comparing" small />
<Switch
checked={showTimeComparison}
id="comparing"
small
disabled={disabled ?? false}
/>

<Label class="font-normal text-xs cursor-pointer" for="comparing">
<span>Comparing</span>
<span class:opacity-50={disabled}>Comparing</span>
</Label>
</div>
</button>
Expand All @@ -109,6 +122,7 @@
grain={activeTimeGrain}
zone={activeTimeZone}
{onSelectComparisonRange}
disabled={disabled ?? false}
/>
{/if}
</div>
Expand All @@ -117,7 +131,7 @@
.wrapper {
@apply flex w-fit;
@apply h-7 rounded-full;
@apply overflow-hidden;
@apply overflow-hidden select-none;
}

:global(.wrapper > button) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
export let showComparison: boolean | undefined;
export let selectedComparison: DashboardTimeControls | undefined;
export let zone: string;
export let disabled: boolean;
export let grain: string;
export let minDate: DateTime | undefined = undefined;
export let maxDate: DateTime | undefined = undefined;
Expand Down Expand Up @@ -97,6 +98,7 @@
>
<DropdownMenu.Trigger asChild let:builder>
<button
{disabled}
use:builder.action
{...builder}
aria-label="Select time comparison option"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ test.describe("leaderboard and dimension table sorting", () => {
page.getByRole("row", { name: "null 32.9k" }),
);

// add time comparison and select Pct change
await page.getByRole("button", { name: "Comparing" }).click();

await openTimeRangeMenu();
await page.getByRole("menuitem", { name: "Last 24 Hours" }).click();

// add time comparison and select Pct change
await page.getByRole("button", { name: "Comparing" }).click();

// need a slight delay for the time range to update
// and the "Pct change" option to be available
// in the context column dropdown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ test.describe("leaderboard context column", () => {
await interactWithTimeRangeMenu(page, async () => {
await page.getByRole("menuitem", { name: "All Time" }).click();
});
await page.getByRole("button", { name: "Comparing" }).click();

// Check that time comparison context column is hidden
await expect(page.getByText(comparisonColumnRegex)).not.toBeVisible();
Expand Down
Loading