fleet/frontend/components/TableContainer/DataTable/PillCell/PillCell.tsx
Jacob Shandling 333674b051
UI – Host query report page (#15511)
## Addresses second major part of #15011  (item 3) – Host query report

_Note for reviewers: The most important files here are:_
- HostQueryReport.tsx
- HQRTable.tsx
- HQRTableConfig.tsx

_The rest are associated API services, interfaces, helpers, routes,
styles, and miscellanious code improvements I made along the way._

____________

### See linked issue for enumeration of feature-related tasks

<img width="1230" alt="Screenshot 2023-12-08 at 4 23 50 PM"
src="https://github.com/fleetdm/fleet/assets/61553566/4ae4b41b-9209-4afa-ae50-8844d01ff8fd">

<img width="1230" alt="collecting"
src="https://github.com/fleetdm/fleet/assets/61553566/061ac2bc-899f-4b29-91ba-36ebecf5ce58">

<img width="1230" alt="Screenshot 2023-12-08 at 4 24 39 PM"
src="https://github.com/fleetdm/fleet/assets/61553566/f8b25e01-fe3b-47e6-b980-eba9538b1a01">

<img width="1230" alt="Screenshot 2023-12-08 at 4 25 01 PM"
src="https://github.com/fleetdm/fleet/assets/61553566/46360274-8500-494c-8fb7-3a1d45347ce0">

Re-routes to host details > queries if:
- query reports are globally disabled:

https://github.com/fleetdm/fleet/assets/61553566/ac67da8c-57bc-4d9b-96be-daf3b198e704

- query has `Discard data` enabled:

https://github.com/fleetdm/fleet/assets/61553566/b797dd24-9893-4360-bf40-b80298848864

- [x] Manual QA for all new/changed functionality

---------

Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2023-12-08 16:54:24 -08:00

117 lines
2.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React from "react";
import classnames from "classnames";
import { uniqueId } from "lodash";
import ReactTooltip from "react-tooltip";
import { COLORS } from "styles/var/colors";
interface IPillCellProps {
value: { indicator: string; id: number };
customIdPrefix?: string;
hostDetails?: boolean;
}
const generateClassTag = (rawValue: string): string => {
return rawValue.replace(" ", "-").toLowerCase();
};
const PillCell = ({
value,
customIdPrefix,
hostDetails,
}: IPillCellProps): JSX.Element => {
const { indicator, id } = value;
const pillClassName = classnames(
"data-table__pill",
`data-table__pill--${generateClassTag(indicator || "")}`,
"tooltip"
);
const disable = () => {
switch (indicator) {
case "Minimal":
return false;
case "Considerable":
return false;
case "Excessive":
return false;
case "Undetermined":
return false;
default:
return true;
}
};
const tooltipText = () => {
switch (indicator) {
case "Minimal":
return (
<>
Running this query very <br />
frequently has little to no <br /> impact on your devices <br />
performance.
</>
);
case "Considerable":
return (
<>
Running this query <br /> frequently can have a <br /> noticeable
impact on your <br /> devices performance.
</>
);
case "Excessive":
return (
<>
Running this query, even <br /> infrequently, can have a <br />
significant impact on your <br /> devices performance.
</>
);
case "Denylisted":
return (
<>
This query has been <br /> stopped from running <br /> because of
excessive <br /> resource consumption.
</>
);
case "Undetermined":
return (
<>
To see performance impact, this query must have run with{" "}
<b>automations</b> on {hostDetails ? "this" : "at least one"} host.
</>
);
default:
return null;
}
};
const tooltipId = uniqueId();
return (
<>
<span
data-tip
data-for={`${customIdPrefix || "pill"}__${id?.toString() || tooltipId}`}
data-tip-disable={disable()}
>
<span className={pillClassName}>{indicator}</span>
</span>
<ReactTooltip
place="top"
effect="solid"
backgroundColor={COLORS["tooltip-bg"]}
id={`${customIdPrefix || "pill"}__${id?.toString() || tooltipId}`}
data-html
>
<span
className={`tooltip ${generateClassTag(
indicator || ""
)}__tooltip-text`}
>
{tooltipText()}
</span>
</ReactTooltip>
</>
);
};
export default PillCell;