Repository navigation
refactor(desktop): cleaner, compact inline agent/port sections in v2 sidebar #5426
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 all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0bcd600
refactor(desktop): compact inline agent/port sections in v2 sidebar
Kitenite 3e5fb83
feat(desktop): port pill opens in browser on click, actions behind ho…
Kitenite 60e72c7
feat(desktop): split port menu open action into external and Superset…
Kitenite 2fc582f
fix(desktop): address PR review feedback on sidebar chip strip
Kitenite 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
80 changes: 80 additions & 0 deletions
80
...nents/DashboardSidebar/components/DashboardSidebarChipStrip/DashboardSidebarChipStrip.tsx
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,80 @@ | ||
| import { OverflowFadeContainer } from "@superset/ui/overflow-fade-container"; | ||
| import { cn } from "@superset/ui/utils"; | ||
| import { | ||
| type ReactNode, | ||
| useCallback, | ||
| useLayoutEffect, | ||
| useRef, | ||
| useState, | ||
| } from "react"; | ||
|
|
||
| /** Must match the `gap-1.5` class on the container below. */ | ||
| const CHIP_GAP_PX = 6; | ||
|
|
||
| interface DashboardSidebarChipStripProps { | ||
| className?: string; | ||
| children: ReactNode; | ||
| } | ||
|
|
||
| /** | ||
| * Strip of chips (ports, agents) that stays a single row while everything | ||
| * fits, wraps into a two-row grid once it doesn't, and scrolls horizontally | ||
| * (two rows deep) beyond that. | ||
| * | ||
| * Layout is chosen by comparing the chips' natural widths against the | ||
| * container, re-measured on every render and on container resizes. Pure-CSS | ||
| * child growth (e.g. a chip revealing hover actions) deliberately doesn't | ||
| * trigger a re-measure, so hovering can't flip the layout. | ||
| */ | ||
| export function DashboardSidebarChipStrip({ | ||
| className, | ||
| children, | ||
| }: DashboardSidebarChipStripProps) { | ||
| const containerRef = useRef<HTMLDivElement>(null); | ||
| const [isTwoRows, setIsTwoRows] = useState(false); | ||
|
|
||
| const measure = useCallback(() => { | ||
| const node = containerRef.current; | ||
| if (!node) return; | ||
| const styles = getComputedStyle(node); | ||
| const available = | ||
| node.clientWidth - | ||
| Number.parseFloat(styles.paddingLeft) - | ||
| Number.parseFloat(styles.paddingRight); | ||
| let needed = -CHIP_GAP_PX; | ||
| for (const child of Array.from(node.children)) { | ||
| needed += (child as HTMLElement).offsetWidth + CHIP_GAP_PX; | ||
| } | ||
| setIsTwoRows(needed > available); | ||
| }, []); | ||
|
|
||
| // No dependency array: chips mounting/unmounting re-renders this component, | ||
| // and re-measuring is cheap (setState bails when the boolean is unchanged). | ||
| useLayoutEffect(measure); | ||
|
|
||
| useLayoutEffect(() => { | ||
| const node = containerRef.current; | ||
| if (!node) return; | ||
| const observer = new ResizeObserver(measure); | ||
| observer.observe(node); | ||
| return () => observer.disconnect(); | ||
| }, [measure]); | ||
|
|
||
| return ( | ||
| <OverflowFadeContainer | ||
| ref={containerRef} | ||
| observeChildren | ||
| className={cn( | ||
| // justify-items-start keeps chips at natural width in grid mode; | ||
| // stretched chips would inflate the offsetWidths measure() sums. | ||
| isTwoRows | ||
| ? "grid auto-cols-max grid-flow-col grid-rows-2 justify-items-start" | ||
| : "flex", | ||
| "items-center gap-1.5 overflow-x-auto hide-scrollbar", | ||
| className, | ||
| )} | ||
| > | ||
| {children} | ||
| </OverflowFadeContainer> | ||
| ); | ||
| } | ||
1 change: 1 addition & 0 deletions
1
...ated/_dashboard/components/DashboardSidebar/components/DashboardSidebarChipStrip/index.ts
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 @@ | ||
| export { DashboardSidebarChipStrip } from "./DashboardSidebarChipStrip"; |
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
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.
When
isTwoRowsistrue, the container renders as a CSS Grid withauto-cols-max grid-flow-col. Grid items stretch to fill their column area by default (justify-self: stretch), so a narrow chip sharing a column with a wider chip will reportoffsetWidthequal to the wider chip's width. Themeasurefunction then sums these inflated values and consistently decidesneeded > available, keeping the layout in two-row mode even after enough chips are removed to fit in a single row.The fix is to add
justify-items-startto the grid variant so chips only occupy their natural content width, keepingoffsetWidthaccurate in both layout modes. For example,isTwoRows ? "grid auto-cols-max grid-flow-col grid-rows-2 justify-items-start" : "flex".Prompt To Fix With AI
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!