Skip to content

Commit

Permalink
tweak: pass toggle function as prop (#6221)
Browse files Browse the repository at this point in the history
* tweak: pass toggle function as prop

* cleanup
  • Loading branch information
briangregoryholmes authored Dec 11, 2024
1 parent cc49072 commit b268f39
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -37,7 +38,11 @@
style:height="{config.columnHeaderHeight}px"
class="sticky left-0 top-0 surface z-40 flex items-center"
>
<DimensionCompareMenu {dimensionName} />
<DimensionCompareMenu
{dimensionName}
{isBeingCompared}
{toggleComparisonDimension}
/>
</div>
{#each virtualRowItems as row (`row-${row.key}`)}
{@const isSelected = selectedIndex.includes(row.index)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ TableCells – the cell contents.
export let isFetching: boolean;
const {
actions: { dimensionTable },
actions: {
dimensionTable,
comparison: { toggleComparisonDimension },
},
selectors: {
sorting: { sortMeasure },
dimensionFilters: { isFilterExcludeMode },
Expand Down Expand Up @@ -228,6 +231,7 @@ TableCells – the cell contents.
{isBeingCompared}
{excludeMode}
{dimensionName}
{toggleComparisonDimension}
on:select-item={(event) => onSelectItem(event)}
/>
<DimensionValueHeader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,17 @@
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) => void;
</script>

<IconButton
ariaLabel="Toggle breakdown for {dimensionName} dimension"
on:click={(e) => {
if (isBeingCompared) {
setComparisonDimension(undefined);
} else {
setComparisonDimension(dimensionName);
}
e.stopPropagation();
if (dimensionName) 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,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,
};

1 comment on commit b268f39

@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.

Please sign in to comment.