-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add copy buttons to lookout UI (#4094)
Add copy icon buttons, which appear on hover, next to appropriate values in the jobs table and in the key-value pair rows in the details sidebar. Also add a copy button for the job ID at the top of the sidebar, which always remains visible. When the user clicks the button, a tooltip displays *Copied!* to confirm to the user that the value has been copied to their clipboard. Co-authored-by: Maurice Yap <[email protected]>
- Loading branch information
1 parent
3bddd53
commit 81c2942
Showing
9 changed files
with
136 additions
and
20 deletions.
There are no files selected for viewing
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,39 @@ | ||
import { useState } from "react" | ||
|
||
import { ContentCopy } from "@mui/icons-material" | ||
import { IconButton, IconButtonProps, styled, Tooltip } from "@mui/material" | ||
|
||
const LEAVE_DELAY_MS = 1_000 | ||
|
||
const StyledIconButton = styled(IconButton)<IconButtonProps & { hidden: boolean }>(({ hidden }) => ({ | ||
padding: 0, | ||
visibility: hidden ? "hidden" : "unset", | ||
})) | ||
|
||
export interface CopyIconButtonProps { | ||
content: string | ||
size?: IconButtonProps["size"] | ||
onClick?: IconButtonProps["onClick"] | ||
hidden?: boolean | ||
} | ||
|
||
export const CopyIconButton = ({ content, size, onClick, hidden = false }: CopyIconButtonProps) => { | ||
const [tooltipOpen, setTooltipOpen] = useState(false) | ||
|
||
return ( | ||
<Tooltip title="Copied!" onClose={() => setTooltipOpen(false)} open={tooltipOpen} leaveDelay={LEAVE_DELAY_MS}> | ||
<StyledIconButton | ||
size={size} | ||
onClick={(e) => { | ||
onClick?.(e) | ||
navigator.clipboard.writeText(content) | ||
setTooltipOpen(true) | ||
}} | ||
aria-label="copy" | ||
hidden={hidden && !tooltipOpen} | ||
> | ||
<ContentCopy fontSize="inherit" /> | ||
</StyledIconButton> | ||
</Tooltip> | ||
) | ||
} |
32 changes: 32 additions & 0 deletions
32
internal/lookout/ui/src/components/CopyableValueOnHover.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,32 @@ | ||
import { ReactNode, useState } from "react" | ||
|
||
import { styled } from "@mui/material" | ||
|
||
import { CopyIconButton, CopyIconButtonProps } from "./CopyIconButton" | ||
|
||
const OuterContainer = styled("div")({ | ||
display: "flex", | ||
flexDirection: "row", | ||
gap: "1ch", | ||
}) | ||
|
||
export interface CopyableValueOnHoverProps { | ||
children: ReactNode | ||
copyContent: string | ||
onCopyButtonClick?: CopyIconButtonProps["onClick"] | ||
} | ||
|
||
export const CopyableValueOnHover = ({ children, copyContent, onCopyButtonClick }: CopyableValueOnHoverProps) => { | ||
const [copyIconButtonHidden, setCopyIconButtonHidden] = useState(true) | ||
return ( | ||
<OuterContainer | ||
onMouseEnter={() => setCopyIconButtonHidden(false)} | ||
onMouseLeave={() => setCopyIconButtonHidden(true)} | ||
> | ||
<div>{children}</div> | ||
<div> | ||
<CopyIconButton content={copyContent} size="small" onClick={onCopyButtonClick} hidden={copyIconButtonHidden} /> | ||
</div> | ||
</OuterContainer> | ||
) | ||
} |
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
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
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