-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add filter button to job table cells (#4105)
In a similar way to the copy button, this adds an icon button which appears when the user hovers over the cell. It applies a filter to the cell's column for the cell's value. It appears only for cells for whose columns can be filtered by.
- Loading branch information
1 parent
9967a86
commit 6b15e67
Showing
6 changed files
with
125 additions
and
50 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
internal/lookout/ui/src/components/ActionableValueOnHover.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,76 @@ | ||
import { ReactNode, useState } from "react" | ||
|
||
import { IconButton, IconButtonProps, styled } from "@mui/material" | ||
|
||
import { CopyIconButton } from "./CopyIconButton" | ||
import { AddFilter } from "./icons" | ||
|
||
const OuterContainer = styled("div")({ | ||
display: "flex", | ||
flexDirection: "row", | ||
gap: "0.5ch", | ||
}) | ||
|
||
const StyledIconButton = styled(IconButton)<IconButtonProps & { hidden: boolean }>(({ hidden }) => ({ | ||
padding: 0, | ||
visibility: hidden ? "hidden" : "unset", | ||
})) | ||
|
||
export interface CopyActionProps { | ||
copyContent: string | ||
} | ||
|
||
export interface FilterActionProps { | ||
onFilter: () => void | ||
} | ||
|
||
export interface ActionableValueOnHoverProps { | ||
children: ReactNode | ||
copyAction?: CopyActionProps | ||
filterAction?: FilterActionProps | ||
stopPropogationOnActionClick?: boolean | ||
} | ||
|
||
export const ActionableValueOnHover = ({ | ||
children, | ||
copyAction, | ||
filterAction, | ||
stopPropogationOnActionClick = false, | ||
}: ActionableValueOnHoverProps) => { | ||
const [hovering, setHovering] = useState(false) | ||
return ( | ||
<OuterContainer onMouseEnter={() => setHovering(true)} onMouseLeave={() => setHovering(false)}> | ||
<div>{children}</div> | ||
{copyAction && ( | ||
<div> | ||
<CopyIconButton | ||
content={copyAction.copyContent} | ||
size="small" | ||
onClick={(e) => { | ||
if (stopPropogationOnActionClick) { | ||
e.stopPropagation() | ||
} | ||
}} | ||
hidden={!hovering} | ||
/> | ||
</div> | ||
)} | ||
{filterAction && ( | ||
<div> | ||
<StyledIconButton | ||
size="small" | ||
hidden={!hovering} | ||
onClick={(e) => { | ||
if (stopPropogationOnActionClick) { | ||
e.stopPropagation() | ||
} | ||
filterAction.onFilter() | ||
}} | ||
> | ||
<AddFilter fontSize="inherit" /> | ||
</StyledIconButton> | ||
</div> | ||
)} | ||
</OuterContainer> | ||
) | ||
} |
32 changes: 0 additions & 32 deletions
32
internal/lookout/ui/src/components/CopyableValueOnHover.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Add, FilterAlt } from "@mui/icons-material" | ||
import { SvgIcon, SvgIconProps } from "@mui/material" | ||
|
||
export const AddFilter: typeof SvgIcon = (props: SvgIconProps) => ( | ||
<SvgIcon {...props}> | ||
<Add {...props} viewBox="-20 -20 44 44" /> | ||
<FilterAlt {...props} viewBox="0 0 28 28" /> | ||
</SvgIcon> | ||
) | ||
|
||
AddFilter.muiName = "AddFilter" |
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
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