-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sidebar): connections filter popover COMPASS-8503 (#6486)
* Refactor ConnectionsNavigation into NavigationItemsFilter * Refactor to a popover * Delete unused icons * Add activated indicator * Blur trigger when closing popover * Fix failing tests * Avoid className prop on NavigationItemsFilter * fixup! Refactor to a popover Pass hideCloseButton instead of using display none * fixup! Blur trigger when closing popover Fix generating unique ids * Remove comments * Revert "Blur trigger when closing popover" This reverts part of commit 6d19bbe. * Control tooltip to avoid it showing when closing popover
- Loading branch information
1 parent
28bb675
commit 5a6c445
Showing
10 changed files
with
301 additions
and
240 deletions.
There are no files selected for viewing
46 changes: 0 additions & 46 deletions
46
packages/compass-components/src/components/icons/connected-plugs.tsx
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
packages/compass-components/src/components/icons/disconnected-plug.tsx
This file was deleted.
Oops, something went wrong.
This file contains 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
141 changes: 141 additions & 0 deletions
141
packages/compass-sidebar/src/components/connections-filter-popover.tsx
This file contains 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,141 @@ | ||
import React, { useCallback, useState, type PropsWithChildren } from 'react'; | ||
|
||
import { | ||
css, | ||
Icon, | ||
IconButton, | ||
InteractivePopover, | ||
Label, | ||
Overline, | ||
palette, | ||
spacing, | ||
Toggle, | ||
Tooltip, | ||
useId, | ||
} from '@mongodb-js/compass-components'; | ||
import type { ConnectionsFilter } from './use-filtered-connections'; | ||
|
||
const containerStyles = css({ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
alignItems: 'flex-start', | ||
padding: spacing[300], | ||
minWidth: 270, | ||
}); | ||
|
||
const activatedIndicatorStyles = css({ | ||
position: 'absolute', | ||
top: spacing[50], | ||
right: spacing[50], | ||
}); | ||
|
||
const groupStyles = css({ | ||
display: 'flex', | ||
flexDirection: 'row', | ||
gap: spacing[200], | ||
marginTop: spacing[200], | ||
}); | ||
|
||
type ConnectionsFilterPopoverProps = PropsWithChildren<{ | ||
open: boolean; | ||
setOpen: (open: boolean) => void; | ||
filter: ConnectionsFilter; | ||
onFilterChange( | ||
updater: (filter: ConnectionsFilter) => ConnectionsFilter | ||
): void; | ||
}>; | ||
|
||
export default function ConnectionsFilterPopover({ | ||
open, | ||
setOpen, | ||
filter, | ||
onFilterChange, | ||
}: ConnectionsFilterPopoverProps) { | ||
const onExcludeInactiveChange = useCallback( | ||
(excludeInactive: boolean) => { | ||
onFilterChange((filter) => ({ | ||
...filter, | ||
excludeInactive, | ||
})); | ||
}, | ||
[onFilterChange] | ||
); | ||
|
||
const excludeInactiveToggleId = useId(); | ||
const excludeInactiveLabelId = useId(); | ||
|
||
// Add future filters to the boolean below | ||
const isActivated = filter.excludeInactive; | ||
|
||
// Manually handling the tooltip state instead of supplying a trigger | ||
// we do this to avoid the tooltip from rendering when the popover is open | ||
// and when the IconButton regains focus as the | ||
const [isTooltipOpen, setTooltipOpen] = useState(false); | ||
const handleButtonMouseEnter = useCallback( | ||
() => setTooltipOpen(true), | ||
[setTooltipOpen] | ||
); | ||
const handleButtonMouseLeave = useCallback( | ||
() => setTooltipOpen(false), | ||
[setTooltipOpen] | ||
); | ||
|
||
return ( | ||
<> | ||
<Tooltip | ||
align="right" | ||
open={isTooltipOpen && !open} | ||
setOpen={setTooltipOpen} | ||
> | ||
Filter connections | ||
</Tooltip> | ||
<InteractivePopover | ||
open={open} | ||
setOpen={setOpen} | ||
containerClassName={containerStyles} | ||
hideCloseButton | ||
trigger={({ onClick, children, ref }) => ( | ||
<> | ||
<IconButton | ||
onClick={onClick} | ||
onMouseEnter={handleButtonMouseEnter} | ||
onMouseLeave={handleButtonMouseLeave} | ||
active={open} | ||
aria-label="Filter connections" | ||
ref={ref as React.Ref<unknown>} | ||
> | ||
<Icon glyph="Filter" /> | ||
{isActivated && ( | ||
<svg | ||
className={activatedIndicatorStyles} | ||
width="6" | ||
height="6" | ||
viewBox="0 0 6 6" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<circle cx="3" cy="3" r="3" fill={palette.blue.base} /> | ||
</svg> | ||
)} | ||
</IconButton> | ||
{children} | ||
</> | ||
)} | ||
> | ||
<Overline>Filter Options</Overline> | ||
<div className={groupStyles}> | ||
<Toggle | ||
id={excludeInactiveToggleId} | ||
aria-labelledby={excludeInactiveLabelId} | ||
checked={filter.excludeInactive} | ||
onChange={onExcludeInactiveChange} | ||
size="small" | ||
/> | ||
<Label htmlFor={excludeInactiveToggleId} id={excludeInactiveLabelId}> | ||
Show only active connections | ||
</Label> | ||
</div> | ||
</InteractivePopover> | ||
</> | ||
); | ||
} |
This file contains 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 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.