fleet/frontend/components/TableContainer/TableContainerUtils.ts
Jacob Shandling d49255dfdb
UI - clip live query results (#15760)
## Addresses #14874 
- once 250,000 (results + errors) return, end the query campaign and
display the "clipped" banner
- Format host counts with commas
- misc. cleanup

<img width="1796" alt="Screenshot 2023-12-19 at 4 37 28 PM"
src="https://github.com/fleetdm/fleet/assets/61553566/353ae5a0-24f0-49c5-b48c-555ff83567e9">

<img width="1796" alt="Screenshot 2023-12-19 at 4 37 02 PM"
src="https://github.com/fleetdm/fleet/assets/61553566/e5722dc5-07b4-4173-8eb3-8d00b3f327ab">


## Checklist for submitter

- [x] Changes file added for user-visible changes in `changes/`
- [x] Manual QA for all new/changed functionality

---------

Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2023-12-21 09:23:07 -08:00

30 lines
1 KiB
TypeScript

const DEFAULT_RESULTS_NAME = "results";
const generateResultsCountText = (
name: string = DEFAULT_RESULTS_NAME,
resultsCount: number
): string => {
if (resultsCount === 0) return `No ${name}`;
// If there is 1 result and the last 3 letters in the result
// name are "ies," we remove the "ies" and add "y"
// to make the name singular
if (resultsCount === 1 && name.slice(-3) === "ies") {
return `${resultsCount} ${name.slice(0, -3)}y`;
}
// If there is 1 result and the last 2 letters in the result
// name are "es," we remove the "es" to make the name singular
if (resultsCount === 1 && name.slice(-2) === "es") {
return `${resultsCount} ${name.slice(0, -2)}y`;
}
// If there is 1 result and the last letter in the result
// name is "s," we remove the "s" to make the name singular
if (resultsCount === 1 && name[name.length - 1] === "s") {
return `${resultsCount} ${name.slice(0, -1)}`;
}
return `${resultsCount.toLocaleString()} ${name}`;
};
export default { generateResultsCountText };