-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEVPROD-10195: Add task stats tooltip to waterfall (#480)
- Loading branch information
Showing
17 changed files
with
425 additions
and
137 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { useRef, useState } from "react"; | ||
import styled from "@emotion/styled"; | ||
import IconButton from "@leafygreen-ui/icon-button"; | ||
import Popover, { Align } from "@leafygreen-ui/popover"; | ||
import { taskStatusToCopy } from "@evg-ui/lib/constants/task"; | ||
import { TaskStatus } from "@evg-ui/lib/types/task"; | ||
import Icon from "components/Icon"; | ||
import { Divider } from "components/styles"; | ||
import { PopoverContainer } from "components/styles/Popover"; | ||
import { size } from "constants/tokens"; | ||
import { WaterfallVersionFragment } from "gql/generated/types"; | ||
import { useOnClickOutside } from "hooks"; | ||
import { SQUARE_SIZE, taskStatusStyleMap } from "./styles"; | ||
|
||
export const TaskStatsTooltip: React.FC< | ||
Pick<WaterfallVersionFragment, "taskStatusStats"> | ||
> = ({ taskStatusStats }) => { | ||
const [open, setOpen] = useState(false); | ||
|
||
const buttonRef = useRef<HTMLButtonElement>(null); | ||
const popoverRef = useRef<HTMLDivElement>(null); | ||
|
||
useOnClickOutside([buttonRef, popoverRef], () => setOpen(false)); | ||
|
||
const totalTaskCount = | ||
taskStatusStats?.counts?.reduce((total, { count }) => total + count, 0) ?? | ||
0; | ||
|
||
return ( | ||
<> | ||
<BtnContainer> | ||
<IconButton | ||
ref={buttonRef} | ||
aria-label="Show task stats" | ||
data-cy="task-stats-tooltip-button" | ||
onClick={() => setOpen((o) => !o)} | ||
> | ||
<Icon glyph="Charts" /> | ||
</IconButton> | ||
</BtnContainer> | ||
<Popover ref={popoverRef} active={open} align={Align.Right}> | ||
<PopoverContainer data-cy="task-stats-tooltip"> | ||
<Table> | ||
{taskStatusStats?.counts?.map(({ count, status }) => ( | ||
<Row> | ||
<Count>{count}</Count> | ||
<Cell> | ||
<Square status={status as TaskStatus} /> | ||
</Cell> | ||
<Cell>{taskStatusToCopy[status as TaskStatus]}</Cell> | ||
</Row> | ||
))} | ||
<Row> | ||
<Cell colSpan={3}> | ||
<Divider /> | ||
</Cell> | ||
</Row> | ||
<Row> | ||
<Count>{totalTaskCount}</Count> | ||
<Cell colSpan={2}>Total tasks</Cell> | ||
</Row> | ||
</Table> | ||
</PopoverContainer> | ||
</Popover> | ||
</> | ||
); | ||
}; | ||
|
||
const BtnContainer = styled.div` | ||
display: inline-block; | ||
`; | ||
|
||
const Table = styled.table``; | ||
|
||
const Row = styled.tr``; | ||
|
||
const Cell = styled.td` | ||
padding: 0 ${size.xxs}; | ||
`; | ||
|
||
const Count = styled(Cell)` | ||
font-feature-settings: "tnum"; | ||
text-align: right; | ||
`; | ||
|
||
const Square = styled.div<{ status: TaskStatus }>` | ||
${({ status }) => taskStatusStyleMap[status]} | ||
height: ${SQUARE_SIZE}px; | ||
width: ${SQUARE_SIZE}px; | ||
`; |
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
Oops, something went wrong.