Skip to content

Commit

Permalink
tweak: pass toggle function as prop
Browse files Browse the repository at this point in the history
  • Loading branch information
briangregoryholmes committed Dec 5, 2024
1 parent 364d21b commit b3fcd54
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,19 @@
import Compare from "@rilldata/web-common/components/icons/Compare.svelte";
import Tooltip from "@rilldata/web-common/components/tooltip/Tooltip.svelte";
import TooltipContent from "@rilldata/web-common/components/tooltip/TooltipContent.svelte";
import { getStateManagers } from "../state-managers/state-managers";
export let dimensionName: string | undefined;
const {
selectors: {
comparison: { isBeingCompared: isBeingComparedReadable },
},
actions: {
comparison: { setComparisonDimension },
},
} = getStateManagers();
$: isBeingCompared =
dimensionName !== undefined && $isBeingComparedReadable(dimensionName);
export let isBeingCompared: boolean;
export let toggleComparisonDimension: (
dimensionName: string | undefined,
) => void;
</script>

<IconButton
ariaLabel="Toggle breakdown for {dimensionName} dimension"
on:click={(e) => {
if (isBeingCompared) {
setComparisonDimension(undefined);
} else {
setComparisonDimension(dimensionName);
}
e.stopPropagation();
toggleComparisonDimension(dimensionName);
}}
>
<Tooltip location="left" distance={8}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]) => {
Expand Down Expand Up @@ -311,6 +314,7 @@
isTimeComparisonActive={!!comparisonTimeRange}
{toggleSort}
{setPrimaryDimension}
{toggleComparisonDimension}
/>

<tbody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
dimensions: { setPrimaryDimension },
sorting: { toggleSort },
dimensionsFilter: { toggleDimensionValueSelection },
comparison: { toggleComparisonDimension },
},
exploreName,
} = StateManagers;
Expand Down Expand Up @@ -111,6 +112,7 @@
{setPrimaryDimension}
{toggleSort}
{toggleDimensionValueSelection}
{toggleComparisonDimension}
/>
{/if}
{/each}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
</script>

<thead>
Expand All @@ -31,7 +34,11 @@
{#if isFetching}
<DelayedSpinner isLoading={isFetching} size="16px" />
{:else if hovered || isBeingCompared}
<DimensionCompareMenu {dimensionName} />
<DimensionCompareMenu
{dimensionName}
{isBeingCompared}
{toggleComparisonDimension}
/>
{/if}
</th>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import type { DashboardMutables } from "./types";

export const setComparisonDimension = (
export const toggleComparisonDimension = (
{ dashboard }: DashboardMutables,
dimensionName: string | undefined,
) => {
// 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,
};

0 comments on commit b3fcd54

Please sign in to comment.