fleet/frontend/components/ViewAllHostsLink/ViewAllHostsLink.tsx
jacobshandling 7085a731d6
UI: Labels page (#33079)
## For #29721 
- Build the new Labels page
- Forward to the Labels page after saving a label

### [Demo
video](https://drive.google.com/file/d/1iArnSiVn7CSwOpCrKEdO9HByHu9qga3L/view?usp=sharing)

<img width="1798" height="1082" alt="Screenshot 2025-09-17 at 4 00
55 PM"
src="https://github.com/user-attachments/assets/6a51f48c-07c3-44d9-b2bf-07025ffa61ed"
/>



- [x] Changes file added for user-visible changes in `changes/`
- [x] Added/updated automated tests
- [x] QA'd all new/changed functionality manually

---------

Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2025-09-18 09:38:45 -07:00

81 lines
2.2 KiB
TypeScript

import React from "react";
import PATHS from "router/paths";
import { Link } from "react-router";
import classnames from "classnames";
import Icon from "components/Icon";
import { getPathWithQueryParams, QueryParams } from "utilities/url";
interface IHostLinkProps {
queryParams?: QueryParams;
className?: string;
/** Including the platformId will view all hosts for the platform provided */
platformLabelId?: number;
/** Shows right chevron without text */
condensed?: boolean;
excludeChevron?: boolean;
responsive?: boolean;
customContent?: React.ReactNode;
/** Table links shows on row hover and tab focus only */
rowHover?: boolean;
/** Don't actually create a link, useful when click is handled by an ancestor */
noLink?: boolean;
}
const baseClass = "view-all-hosts-link";
const ViewAllHostsLink = ({
queryParams,
className,
platformLabelId,
condensed = false,
excludeChevron = false,
responsive = false,
customContent,
rowHover = false,
noLink = false,
}: IHostLinkProps): JSX.Element => {
const viewAllHostsLinkClass = classnames(baseClass, className, {
[`${baseClass}__condensed`]: condensed,
"row-hover-link": rowHover,
});
const endpoint = platformLabelId
? PATHS.MANAGE_HOSTS_LABEL(platformLabelId)
: PATHS.MANAGE_HOSTS;
const path = getPathWithQueryParams(endpoint, queryParams);
return (
<Link
className={viewAllHostsLinkClass}
to={noLink ? "" : path}
onClick={(e) => {
if (!noLink) {
e.stopPropagation(); // Allows for link to have different onClick behavior than the row's onClick behavior
}
}}
onKeyDown={(e) => {
if (e.key === "Enter") {
e.stopPropagation(); // Allows for link to be keyboard accessible in a clickable row
}
}}
>
{!condensed && (
<span
className={`${baseClass}__text${responsive ? "--responsive" : ""}`}
>
{customContent ?? "View all hosts"}
</span>
)}
{!excludeChevron && (
<Icon
name="chevron-right"
className={`${baseClass}__icon`}
color="core-fleet-blue"
/>
)}
</Link>
);
};
export default ViewAllHostsLink;