diff --git a/web-common/src/features/dashboards/dimension-table/DimensionFilterGutter.svelte b/web-common/src/features/dashboards/dimension-table/DimensionFilterGutter.svelte index 52ab1276bbf..86d03f0fb75 100644 --- a/web-common/src/features/dashboards/dimension-table/DimensionFilterGutter.svelte +++ b/web-common/src/features/dashboards/dimension-table/DimensionFilterGutter.svelte @@ -18,6 +18,7 @@ export let excludeMode = false; export let isBeingCompared = false; export let dimensionName: string; + export let toggleComparisonDimension: (dimensionName: string) => void; function getColor(i: number) { const posInSelection = selectedIndex.indexOf(i); @@ -37,7 +38,11 @@ style:height="{config.columnHeaderHeight}px" class="sticky left-0 top-0 surface z-40 flex items-center" > - + {#each virtualRowItems as row (`row-${row.key}`)} {@const isSelected = selectedIndex.includes(row.index)} diff --git a/web-common/src/features/dashboards/dimension-table/DimensionTable.svelte b/web-common/src/features/dashboards/dimension-table/DimensionTable.svelte index 1e9fb399028..260b4cd2b14 100644 --- a/web-common/src/features/dashboards/dimension-table/DimensionTable.svelte +++ b/web-common/src/features/dashboards/dimension-table/DimensionTable.svelte @@ -29,7 +29,10 @@ TableCells – the cell contents. export let isFetching: boolean; const { - actions: { dimensionTable }, + actions: { + dimensionTable, + comparison: { toggleComparisonDimension }, + }, selectors: { sorting: { sortMeasure }, dimensionFilters: { isFilterExcludeMode }, @@ -228,6 +231,7 @@ TableCells – the cell contents. {isBeingCompared} {excludeMode} {dimensionName} + {toggleComparisonDimension} on:select-item={(event) => onSelectItem(event)} /> void; { - if (isBeingCompared) { - setComparisonDimension(undefined); - } else { - setComparisonDimension(dimensionName); - } e.stopPropagation(); + if (dimensionName) toggleComparisonDimension(dimensionName); }} > diff --git a/web-common/src/features/dashboards/leaderboard/Leaderboard.svelte b/web-common/src/features/dashboards/leaderboard/Leaderboard.svelte index f933e822f6d..c917e9740fe 100644 --- a/web-common/src/features/dashboards/leaderboard/Leaderboard.svelte +++ b/web-common/src/features/dashboards/leaderboard/Leaderboard.svelte @@ -87,6 +87,9 @@ | ((value: string | number) => string); export let setPrimaryDimension: (dimensionName: string) => void; export let toggleSort: (sortType: DashboardState_LeaderboardSortType) => void; + export let toggleComparisonDimension: ( + dimensionName: string | undefined, + ) => void; const observer = new IntersectionObserver( ([entry]) => { @@ -311,6 +314,7 @@ isTimeComparisonActive={!!comparisonTimeRange} {toggleSort} {setPrimaryDimension} + {toggleComparisonDimension} /> diff --git a/web-common/src/features/dashboards/leaderboard/LeaderboardDisplay.svelte b/web-common/src/features/dashboards/leaderboard/LeaderboardDisplay.svelte index 6a6fb779ec7..d3ce2a6623d 100644 --- a/web-common/src/features/dashboards/leaderboard/LeaderboardDisplay.svelte +++ b/web-common/src/features/dashboards/leaderboard/LeaderboardDisplay.svelte @@ -43,6 +43,7 @@ dimensions: { setPrimaryDimension }, sorting: { toggleSort }, dimensionsFilter: { toggleDimensionValueSelection }, + comparison: { toggleComparisonDimension }, }, exploreName, } = StateManagers; @@ -111,6 +112,7 @@ {setPrimaryDimension} {toggleSort} {toggleDimensionValueSelection} + {toggleComparisonDimension} /> {/if} {/each} diff --git a/web-common/src/features/dashboards/leaderboard/LeaderboardHeader.svelte b/web-common/src/features/dashboards/leaderboard/LeaderboardHeader.svelte index 0a2695f2b46..1185d3cef82 100644 --- a/web-common/src/features/dashboards/leaderboard/LeaderboardHeader.svelte +++ b/web-common/src/features/dashboards/leaderboard/LeaderboardHeader.svelte @@ -23,6 +23,9 @@ export let sortType: SortType; export let toggleSort: (sortType: SortType) => void; export let setPrimaryDimension: (dimensionName: string) => void; + export let toggleComparisonDimension: ( + dimensionName: string | undefined, + ) => void; @@ -31,7 +34,11 @@ {#if isFetching} {:else if hovered || isBeingCompared} - + {/if} diff --git a/web-common/src/features/dashboards/state-managers/actions/comparison.ts b/web-common/src/features/dashboards/state-managers/actions/comparison.ts index 86fc54cc4d7..8a7c8faefdc 100644 --- a/web-common/src/features/dashboards/state-managers/actions/comparison.ts +++ b/web-common/src/features/dashboards/state-managers/actions/comparison.ts @@ -1,17 +1,24 @@ import type { DashboardMutables } from "./types"; -export const setComparisonDimension = ( +export const toggleComparisonDimension = ( { dashboard }: DashboardMutables, - dimensionName: string | undefined, + dimensionName: string, ) => { // Temporary until we make these not mutually exclusive dashboard.showTimeComparison = false; - dashboard.selectedComparisonDimension = dimensionName; + const isCurrentDimension = + dashboard.selectedComparisonDimension === dimensionName; + + if (!isCurrentDimension) { + dashboard.selectedComparisonDimension = dimensionName; + } else { + dashboard.selectedComparisonDimension = undefined; + } }; export const comparisonActions = { /** * Sets the comparison dimension for the dashboard. */ - setComparisonDimension, + toggleComparisonDimension, };