-
Notifications
You must be signed in to change notification settings - Fork 177
Add tags support for pivot tables #9514
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
34438d1
feat: tag support in pivot table sidebar
nishantmonu51 493f6dc
chore: fix prettier formatting
nishantmonu51 ee01b86
refactor: address review on pivot tag bulk-add
nishantmonu51 7619b23
fix: restore exploreName imports in DragList for sidebar chip clicks
nishantmonu51 9f89c9b
fix: declare dragOffset with $state in PivotTagRow
nishantmonu51 500a4f9
refactor: address follow-up review on pivot tag bulk-add
nishantmonu51 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| <script lang="ts"> | ||
| import * as Tooltip from "@rilldata/web-common/components/tooltip-v2"; | ||
| import CancelCircle from "../icons/CancelCircle.svelte"; | ||
|
|
||
| type Props = { | ||
| tagName: string; | ||
| onClear: () => void; | ||
| }; | ||
|
|
||
| let { tagName, onClear }: Props = $props(); | ||
| </script> | ||
|
|
||
| <div class="flex items-center gap-x-1.5 px-3 py-1.5 bg-popover-accent border-b"> | ||
| <span class="text-xs text-fg-secondary flex-none">Filter:</span> | ||
| <span class="truncate text-xs text-fg-primary font-medium flex-1 min-w-0"> | ||
| {tagName} | ||
| </span> | ||
| <Tooltip.Root delayDuration={200}> | ||
| <Tooltip.Trigger> | ||
| {#snippet child({ props })} | ||
| <button | ||
| {...props} | ||
| type="button" | ||
| class="flex-none text-icon-muted hover:text-fg-primary transition-colors" | ||
| onclick={onClear} | ||
| aria-label="Clear tag filter" | ||
| > | ||
| <CancelCircle size="14px" /> | ||
| </button> | ||
| {/snippet} | ||
| </Tooltip.Trigger> | ||
| <Tooltip.Content | ||
| side="top" | ||
| class="bg-popover text-fg-primary z-popover text-xs px-2 py-1" | ||
| > | ||
| Clear filter | ||
| </Tooltip.Content> | ||
| </Tooltip.Root> | ||
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,12 +26,28 @@ | |
| } from "@rilldata/web-common/features/dashboards/pivot/time-pill-utils"; | ||
| import { timePillSelectors } from "./time-pill-store"; | ||
|
|
||
| export type Zone = "rows" | "columns" | "Time" | "Measures" | "Dimensions"; | ||
| export type Zone = | ||
| | "rows" | ||
| | "columns" | ||
| | "Time" | ||
| | "Measures" | ||
| | "Dimensions" | ||
| | "tags"; | ||
|
|
||
| // When a tag chip is being dragged the drop receivers do a bulk-add instead | ||
| // of the per-chip splice path. The dimensions and measures arrays are | ||
| // precomputed at drag-start so each receiver does not have to re-split. | ||
| export type TagDragPayload = { | ||
| tagName: string; | ||
| dimensions: PivotChipData[]; | ||
| measures: PivotChipData[]; | ||
| }; | ||
|
|
||
| export type DragData = { | ||
| source: Zone; | ||
| width: number; | ||
| chip: PivotChipData; | ||
| tagPayload?: TagDragPayload; | ||
| }; | ||
|
|
||
| export const dragDataStore = writable<null | DragData>(null); | ||
|
|
@@ -70,10 +86,14 @@ | |
| (i) => i.type !== PivotChipType.Measure, | ||
| ); | ||
|
|
||
| $: isTagDrag = !!dragData?.tagPayload; | ||
|
|
||
| $: isValidDropZone = | ||
| isDropLocation && | ||
| dragData && | ||
| (zone === "columns" || dragChip?.type !== PivotChipType.Measure); | ||
| (isTagDrag || | ||
| zone === "columns" || | ||
| dragChip?.type !== PivotChipType.Measure); | ||
|
|
||
| // Get available grains from the store | ||
| const availableGrainsStore = timePillSelectors.getAvailableGrains("time"); | ||
|
|
@@ -134,12 +154,31 @@ | |
| window.removeEventListener("mousemove", detectDragStart); | ||
| } | ||
|
|
||
| function handleDrop() { | ||
| function handleDrop(e: MouseEvent) { | ||
| if (zoneStartedDrag) | ||
| $controllerStore?.abort("Drag cancelled - item dropped"); | ||
|
|
||
| // Holding CMD (mac) or Ctrl flips the tag drop from append to replace, | ||
| // matching the click-side affordance on the tag row. | ||
| const replace = e.metaKey || e.ctrlKey; | ||
|
|
||
| if (isValidDropZone) { | ||
| if (dragChip && ghostIndex !== null) { | ||
| if (dragData?.tagPayload) { | ||
| // Bulk-add path for tag drops. Skips ghost-index positioning since | ||
| // we are inserting multiple chips, not a single one. Cross-zone | ||
| // cleanup on replace happens in the auto-arrange zone or the click | ||
| // affordances on the tag row — DragList only manages its own zone. | ||
| const { dimensions, measures } = dragData.tagPayload; | ||
|
AdityaHegde marked this conversation as resolved.
|
||
| const newItems = | ||
| zone === "rows" ? dimensions : [...dimensions, ...measures]; | ||
| if (replace) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| onUpdate(newItems); | ||
| } else if (newItems.length > 0) { | ||
| const existing = new Set(items.map((c) => c.id)); | ||
| const additions = newItems.filter((c) => !existing.has(c.id)); | ||
| if (additions.length > 0) onUpdate([...items, ...additions]); | ||
| } | ||
| } else if (dragChip && ghostIndex !== null) { | ||
| const temp = [...items]; | ||
|
|
||
| let chipToAdd = dragChip; | ||
|
|
||
120 changes: 120 additions & 0 deletions
120
web-common/src/features/dashboards/pivot/PivotAutoArrangeZone.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| <script lang="ts"> | ||
| import Pivot from "@rilldata/web-common/components/icons/Pivot.svelte"; | ||
| import { modifierHeld } from "@rilldata/web-common/lib/modifier-key"; | ||
| import { slide } from "svelte/transition"; | ||
| import { dragDataStore } from "./DragList.svelte"; | ||
| import type { PivotChipData } from "./types"; | ||
|
|
||
| export let rows: PivotChipData[]; | ||
| export let columns: PivotChipData[]; | ||
| export let setRows: (items: PivotChipData[]) => void; | ||
| export let setColumns: (items: PivotChipData[]) => void; | ||
|
|
||
| $: dragData = $dragDataStore; | ||
| // Auto-arrange only makes sense for mixed tags: a pure-dim or pure-measure | ||
| // tag has a single natural target so the user can drop on Rows or Columns | ||
| // directly. | ||
| $: visible = | ||
| !!dragData?.tagPayload && | ||
| dragData.tagPayload.dimensions.length > 0 && | ||
| dragData.tagPayload.measures.length > 0; | ||
|
|
||
| let hover = false; | ||
|
|
||
| function handleDrop(e: MouseEvent) { | ||
| if (!dragData?.tagPayload) return; | ||
| const replace = e.metaKey || e.ctrlKey; | ||
| const { dimensions, measures } = dragData.tagPayload; | ||
| if (replace) { | ||
| // Both zones are set to the natural slice of the tag; cross-zone | ||
| // cleanup happens implicitly since the zones don't overlap. | ||
| setRows(dimensions); | ||
| setColumns(measures); | ||
| } else { | ||
| if (dimensions.length > 0) { | ||
| const existingRows = new Set(rows.map((c) => c.id)); | ||
| const dimAdds = dimensions.filter((d) => !existingRows.has(d.id)); | ||
| if (dimAdds.length > 0) setRows([...rows, ...dimAdds]); | ||
| } | ||
| if (measures.length > 0) { | ||
| const existingCols = new Set(columns.map((c) => c.id)); | ||
| const measAdds = measures.filter((m) => !existingCols.has(m.id)); | ||
| if (measAdds.length > 0) setColumns([...columns, ...measAdds]); | ||
| } | ||
| } | ||
| dragDataStore.set(null); | ||
| hover = false; | ||
| } | ||
| </script> | ||
|
|
||
| {#if visible && dragData?.tagPayload} | ||
| <div class="header-row" transition:slide={{ duration: 160, axis: "y" }}> | ||
| <span class="row-label"> | ||
| <Pivot size="16px" /> Auto | ||
| </span> | ||
| <div | ||
| role="presentation" | ||
| class="auto-arrange-zone" | ||
| class:hover | ||
| class:replace={$modifierHeld} | ||
| onmouseenter={() => (hover = true)} | ||
| onmouseleave={() => (hover = false)} | ||
| onmouseup={handleDrop} | ||
| aria-label={$modifierHeld | ||
| ? "Drop here to replace rows and columns with this tag" | ||
| : "Drop here to auto-arrange tag"} | ||
| > | ||
| {#if $modifierHeld} | ||
| Drop to <strong>replace</strong>: | ||
| <strong>{dragData.tagPayload.dimensions.length}</strong> | ||
| {dragData.tagPayload.dimensions.length === 1 ? "dim" : "dims"} | ||
| → rows, | ||
| <strong>{dragData.tagPayload.measures.length}</strong> | ||
| {dragData.tagPayload.measures.length === 1 ? "measure" : "measures"} | ||
| → columns | ||
| {:else} | ||
| Drop here to split: | ||
| <strong>{dragData.tagPayload.dimensions.length}</strong> | ||
| {dragData.tagPayload.dimensions.length === 1 ? "dim" : "dims"} | ||
| → rows, | ||
| <strong>{dragData.tagPayload.measures.length}</strong> | ||
| {dragData.tagPayload.measures.length === 1 ? "measure" : "measures"} | ||
| → columns (<span class="kbd">⌘</span> + Drop to replace) | ||
| {/if} | ||
| </div> | ||
| </div> | ||
| {/if} | ||
|
|
||
| <style lang="postcss"> | ||
| .header-row { | ||
| @apply flex items-center gap-x-2 px-2; | ||
| } | ||
|
|
||
| .row-label { | ||
| @apply w-20 flex items-center gap-x-1 flex-shrink-0 text-fg-secondary; | ||
| } | ||
|
|
||
| .auto-arrange-zone { | ||
| @apply flex-1 flex items-center justify-center gap-x-1; | ||
| @apply rounded-sm border border-dashed border-blue-400; | ||
| @apply bg-blue-50/50 text-fg-secondary text-xs; | ||
| @apply py-2 px-3; | ||
| } | ||
|
|
||
| .auto-arrange-zone.hover { | ||
| @apply bg-blue-100 border-blue-500 text-fg-primary; | ||
| } | ||
|
|
||
| .auto-arrange-zone.replace { | ||
| @apply border-amber-500 bg-amber-50/50; | ||
| } | ||
|
|
||
| .auto-arrange-zone.replace.hover { | ||
| @apply bg-amber-100 border-amber-600; | ||
| } | ||
|
|
||
| .kbd { | ||
| @apply inline-block px-1 py-px ml-1 rounded-sm border; | ||
| @apply text-[10px] font-mono text-fg-secondary; | ||
| } | ||
| </style> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One edge case that this leads to is there is no dedupe. Lets reuse
appendChipsToZoneand also replace all calls ofaddPivotFieldin this file.