-
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
27a9ea7
commit 1e3f492
Showing
7 changed files
with
102 additions
and
95 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,85 @@ | ||
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(() => { | ||
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]); | ||
|
||
if (checkLabels.length === 0) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className="flex flex-row gap-2 mb-4 items-center w-full"> | ||
<span className="text-sm font-medium">Labels:</span> | ||
<Popover | ||
menuClass="w-auto top-6" | ||
toggle={ | ||
<div className="flex flex-row flex-1 items-center"> | ||
<div | ||
id="labels-container" | ||
className="flex w-auto flex-row flex-shrink overflow-hidden h-7 gap-2 flex-wrap cursor-pointer" | ||
> | ||
{checkLabels.map((item) => ( | ||
<TagItem 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} | ||
/> | ||
</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