-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: improve the canary modal layout
Closes #1288 fix: fix height issues chore: show labels until full width fix: remove bg issues fix: fix height issue in the table
- Loading branch information
1 parent
b6b37b1
commit 4837b24
Showing
7 changed files
with
119 additions
and
97 deletions.
There are no files selected for viewing
44 changes: 0 additions & 44 deletions
44
src/components/Canary/CanaryPopup/CanaryCheckDetailsLabel.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
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,92 @@ | ||
import { useLayoutEffect, useMemo, useState } from "react"; | ||
import { HealthCheck } from "../../../api/types/health"; | ||
import Popover from "../../Popover/Popover"; | ||
import { TagItem, TagList } from "../../TagList/TagList"; | ||
|
||
type Props = { | ||
check: Partial<Pick<HealthCheck, "labels">>; | ||
}; | ||
|
||
export default function CheckLabels({ check }: Props) { | ||
const [isOverflowing, setIsOverflowing] = useState(false); | ||
|
||
const checkLabels = useMemo(() => { | ||
if (check?.labels) { | ||
return Object.entries(check.labels).map(([key, value]) => ({ | ||
key, | ||
value | ||
})); | ||
} | ||
return []; | ||
}, [check?.labels]); | ||
|
||
useLayoutEffect(() => { | ||
if (isOverflowing) { | ||
return; | ||
} | ||
const node = document.getElementById("labels-container"); | ||
if (node) { | ||
const isOverflowing = | ||
node.scrollWidth > node.clientWidth || | ||
node.scrollHeight > node.clientHeight; | ||
|
||
if (isOverflowing) { | ||
const childNodes = Array.from(node.childNodes) as HTMLDivElement[]; | ||
let width = 0; | ||
|
||
childNodes.forEach((childNode) => { | ||
width += childNode.clientWidth; | ||
if (width > node.clientWidth) { | ||
childNode.style.display = "none"; | ||
} | ||
}); | ||
} | ||
setIsOverflowing(isOverflowing); | ||
} | ||
}, [checkLabels, isOverflowing]); | ||
|
||
if (checkLabels.length === 0) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className="flex flex-row gap-2 mb-4 items-center w-full"> | ||
<Popover | ||
menuClass="w-auto top-6" | ||
toggle={ | ||
<div className="flex flex-row flex-1 gap-1 items-center"> | ||
<div | ||
id="labels-container" | ||
className="flex w-auto flex-row flex-shrink overflow-hidden h-7 gap-1 flex-wrap cursor-pointer" | ||
> | ||
{checkLabels.map((item) => ( | ||
<TagItem | ||
className="bg-blue-100 text-blue-800" | ||
key={item.key} | ||
tag={item} | ||
/> | ||
))} | ||
</div> | ||
{isOverflowing && ( | ||
<div className="w-auto gap-2 underline decoration-solid justify-left text-xs cursor-pointer"> | ||
+{checkLabels.length - 1} more | ||
</div> | ||
)} | ||
</div> | ||
} | ||
placement="left" | ||
> | ||
<div className="flex flex-col p-1"> | ||
<div className="flex flex-col items-stretch max-h-96 overflow-y-auto"> | ||
<TagList | ||
className="flex flex-col flex-1" | ||
tags={checkLabels} | ||
minimumItemsToShow={checkLabels.length} | ||
childClassName="bg-blue-100 text-blue-800" | ||
/> | ||
</div> | ||
</div> | ||
</Popover> | ||
</div> | ||
); | ||
} |
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