fleet/frontend/components/TableContainer/DataTable/PillCell/PillCell.tsx
Jacob Shandling 53f57c44db
UI - Queries page updates, pt.1 (#12784)
## Addresses #12636 – follow-up work for PR #12713

- Update Platforms column to render the user-selected platforms for a
query if any, otherwise those that are compatible
<img width="686" alt="Screenshot 2023-07-14 at 6 03 06 PM"
src="https://github.com/fleetdm/fleet/assets/61553566/abd1f079-bdfe-45be-b1dd-58eb903672ef">

  - Clean up typing and names around this column 
- Encapsulate logic for query automations column cells into new
QueryAutomationsStatusIndicator component
  - Increase modularity and decrease coupling of StatusIndicator
- Cleanly handle overflowing queries table due to very long query name
<img width="512" alt="Screenshot 2023-07-14 at 6 07 20 PM"
src="https://github.com/fleetdm/fleet/assets/61553566/6e970038-0aac-4f71-b21d-ececfa66b94f">

- Small copy and layout fixes

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

---------

Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2023-07-17 14:09:12 -07:00

111 lines
2.7 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";
interface IPillCellProps {
value: { indicator: string; id: number };
customIdPrefix?: string;
}
const generateClassTag = (rawValue: string): string => {
return rawValue.replace(" ", "-").toLowerCase();
};
const PillCell = ({ value, customIdPrefix }: 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 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="#3e4771"
id={`${customIdPrefix || "pill"}__${id?.toString() || tooltipId}`}
data-html
>
<span
className={`tooltip ${generateClassTag(
indicator || ""
)}__tooltip-text`}
>
{tooltipText()}
</span>
</ReactTooltip>
</>
);
};
export default PillCell;