-
Notifications
You must be signed in to change notification settings - Fork 33
feat: DH-19722: Better handling for large numbers of open dashboards #2481
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
mofojed
merged 7 commits into
deephaven:main
from
gzh2003:DH-19722-better-handling-for-large-numbers-of-open-dashboards
Jul 25, 2025
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c9e8783
Create dropdown to filter dashboards
gzh2003 7db8f1c
Update shortcut
gzh2003 3abbd8e
Set shortcut as Cmd+Shift+D
gzh2003 b95b13b
Update snapshots
gzh2003 d2cee32
Address revisions
gzh2003 c587f40
Prevent some actions taking focus away from search input
gzh2003 148590a
Fix docstrings
gzh2003 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
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,63 @@ | ||
@import '@deephaven/components/scss/custom.scss'; | ||
|
||
$dashboard-list-color: $gray-200; | ||
$dashboard-list-hover-color: $foreground; | ||
$dashboard-list-background-hover-color: var(--dh-color-highlight-hover); | ||
|
||
$dashboard-list-owner-color: $gray-400; | ||
$dashboard-list-owner-hover-color: $gray-200; | ||
|
||
.dashboard-list-container { | ||
height: 25.6rem; | ||
padding: 0 0.5rem; | ||
text-align: left; | ||
width: 23rem; | ||
|
||
&:focus { | ||
outline: none; | ||
} | ||
|
||
.dashboard-list { | ||
margin: 0.5rem -0.5rem 0; | ||
padding: 0; | ||
text-align: left; | ||
overflow: auto; | ||
li { | ||
list-style: none; | ||
padding: 0; | ||
margin: 0; | ||
} | ||
.btn { | ||
border: none; | ||
border-radius: 0; | ||
display: block; | ||
text-align: left; | ||
margin: 0; | ||
padding: 0.35rem 0.5rem; | ||
width: 100%; | ||
color: $dashboard-list-color; | ||
&:hover, | ||
&:focus, | ||
&.focused { | ||
color: $dashboard-list-hover-color; | ||
background-color: $dashboard-list-background-hover-color; | ||
text-decoration: none; | ||
} | ||
} | ||
.dashboard-list-item-icon { | ||
margin-right: $spacer-2; | ||
} | ||
.dashboard-list-message { | ||
padding: 0 $spacer-2; | ||
} | ||
} | ||
|
||
.dashboard-list-header { | ||
padding-top: $spacer-2; | ||
padding-bottom: $spacer-2; | ||
|
||
.btn .fa-md { | ||
margin-right: $spacer-2; | ||
} | ||
} | ||
} |
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,156 @@ | ||
import React, { | ||
type ChangeEvent, | ||
useCallback, | ||
useEffect, | ||
useMemo, | ||
useRef, | ||
useState, | ||
} from 'react'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import { type IconDefinition } from '@fortawesome/fontawesome-svg-core'; | ||
import { Button } from '../Button'; | ||
import SearchInput from '../SearchInput'; | ||
import type { NavTabItem } from './NavTabList'; | ||
import './DashboardList.scss'; | ||
import { GLOBAL_SHORTCUTS } from '../shortcuts'; | ||
|
||
export interface DashboardListProps { | ||
onSelect: (tab: NavTabItem) => void; | ||
tabs?: NavTabItem[]; | ||
} | ||
|
||
/** | ||
* Display a search field and a list of dashboard tabs | ||
* @param props The tabs and handlers to use for this list | ||
* @returns A JSX element for the list of dashboard tabs, along with search | ||
*/ | ||
export function DashboardList(props: DashboardListProps): JSX.Element { | ||
const { onSelect, tabs = [] } = props; | ||
gzh2003 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
const [searchText, setSearchText] = useState(''); | ||
const [focusedIndex, setFocusedIndex] = useState(0); | ||
const searchField = useRef<SearchInput>(null); | ||
const listRef = useRef<HTMLUListElement>(null); | ||
const itemRefs = useRef<(HTMLLIElement | null)[]>([]); | ||
|
||
useEffect(() => { | ||
if (searchField.current) { | ||
searchField.current.focus(); | ||
} | ||
gzh2003 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
}, []); | ||
|
||
useEffect(() => { | ||
setFocusedIndex(0); | ||
}, [searchText]); | ||
|
||
useEffect(() => { | ||
if (focusedIndex >= 0 && itemRefs.current[focusedIndex]) { | ||
itemRefs.current[focusedIndex]?.scrollIntoView({ | ||
behavior: 'smooth', | ||
gzh2003 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
block: 'nearest', | ||
}); | ||
} | ||
}, [focusedIndex]); | ||
|
||
const handleSearchChange = useCallback((e: ChangeEvent<HTMLInputElement>) => { | ||
setSearchText(e.target.value); | ||
}, []); | ||
|
||
const handleTabSelect = useCallback( | ||
(tab: NavTabItem) => { | ||
onSelect(tab); | ||
}, | ||
[onSelect] | ||
); | ||
|
||
const filteredTabs = useMemo( | ||
() => | ||
tabs.filter(tab => | ||
tab.title.toLowerCase().includes(searchText.toLowerCase()) | ||
), | ||
[searchText, tabs] | ||
).sort((a, b) => a.title.localeCompare(b.title) ?? 0); | ||
|
||
const handleSearchKeyDown = useCallback( | ||
(event: React.KeyboardEvent) => { | ||
if (event.key === 'ArrowDown' && filteredTabs.length > 0) { | ||
event.preventDefault(); | ||
setFocusedIndex(prev => | ||
prev === -1 ? 0 : (prev + 1) % filteredTabs.length | ||
); | ||
} else if (event.key === 'ArrowUp' && filteredTabs.length > 0) { | ||
event.preventDefault(); | ||
setFocusedIndex(prev => { | ||
if (prev === -1) return filteredTabs.length - 1; | ||
return (prev - 1 + filteredTabs.length) % filteredTabs.length; | ||
}); | ||
} else if (event.key === 'Enter' && filteredTabs.length > 0) { | ||
event.preventDefault(); | ||
const selectedIndex = focusedIndex >= 0 ? focusedIndex : 0; | ||
handleTabSelect(filteredTabs[selectedIndex]); | ||
} else if (event.key === 'Tab') { | ||
event.preventDefault(); | ||
} | ||
}, | ||
[filteredTabs, focusedIndex, handleTabSelect] | ||
); | ||
|
||
const tabElements = useMemo( | ||
() => | ||
filteredTabs.map((tab, index) => ( | ||
<li | ||
key={tab.key} | ||
ref={(el: HTMLLIElement | null) => { | ||
itemRefs.current[index] = el; | ||
}} | ||
> | ||
<Button | ||
kind="ghost" | ||
data-testid={`dashboard-list-item-${tab.key ?? ''}-button`} | ||
onClick={() => handleTabSelect(tab)} | ||
className={focusedIndex === index ? 'focused' : ''} | ||
gzh2003 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
> | ||
{tab.icon ? ( | ||
<span className="dashboard-list-item-icon"> | ||
{React.isValidElement(tab.icon) ? ( | ||
tab.icon | ||
) : ( | ||
<FontAwesomeIcon icon={tab.icon as IconDefinition} /> | ||
)} | ||
</span> | ||
) : null} | ||
{tab.title} | ||
</Button> | ||
</li> | ||
)), | ||
[filteredTabs, handleTabSelect, focusedIndex] | ||
); | ||
|
||
const errorElement = useMemo( | ||
() => | ||
tabElements.length === 0 ? <span>No open dashboard found.</span> : null, | ||
[tabElements] | ||
); | ||
|
||
return ( | ||
<div className="dashboard-list-container d-flex flex-column"> | ||
<div className="dashboard-list-header"> | ||
<SearchInput | ||
value={searchText} | ||
placeholder="Find open dashboard" | ||
endPlaceholder={GLOBAL_SHORTCUTS.OPEN_DASHBOARD_SEARCH_MENU.getDisplayText()} | ||
onChange={handleSearchChange} | ||
onKeyDown={handleSearchKeyDown} | ||
ref={searchField} | ||
/> | ||
</div> | ||
<ul className="dashboard-list flex-grow-1" ref={listRef}> | ||
{errorElement && ( | ||
<li className="dashboard-list-message">{errorElement}</li> | ||
)} | ||
{!errorElement && tabElements} | ||
</ul> | ||
</div> | ||
); | ||
} | ||
|
||
export default DashboardList; |
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
Binary file modified
BIN
+170 Bytes
(100%)
tests/styleguide.spec.ts-snapshots/navigations-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-118 Bytes
(100%)
tests/styleguide.spec.ts-snapshots/navigations-firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+181 Bytes
(100%)
tests/styleguide.spec.ts-snapshots/navigations-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
Uh oh!
There was an error while loading. Please reload this page.