fleet/frontend/components/TableContainer/utilities/TableContainerUtils.ts

32 lines
840 B
TypeScript
Raw Normal View History

2021-04-14 16:52:15 +00:00
const DEFAULT_RESULTS_NAME = "results";
/**
* Returns a proper results count text singular or plural as needed.
* For regular cases, computes singular by removing "ies" or "s".
* For irregular cases, pass singularName.
*/
export const generateResultsCountText = (
2021-04-14 16:52:15 +00:00
name: string = DEFAULT_RESULTS_NAME,
resultsCount?: number,
singularName?: string
): string => {
if (!resultsCount || resultsCount === 0) return `0 ${name}`;
// If exactly 1 result, return singular form.
if (resultsCount === 1) {
if (singularName) {
return `1 ${singularName}`;
}
if (name.endsWith("ies")) {
return `1 ${name.slice(0, -3)}y`;
}
if (name.endsWith("s")) {
return `1 ${name.slice(0, -1)}`;
}
}
implement user table with new table and hook up create and edit and delete users (#587) * hook up user and invite data together for data table * added client derived data to user table * hooked up action dropdown to table * hooked up edit modal and password reset * started adding editing user functiaonlity * add query params to /invite call * clean up editing teams * update select team from to handle existing users with teams * update closes modal now * reuse getUser to clean up code in userManagementpage * pass form data to updating user that is not the current User * add dynamic userform submit text and fix tests * fix lint error in table component * added empty state for user table * clean up unused data table props * added delete modal * add delete user functionality * add delete option for invite * Add styles for rows in user table and action dropdown cell * hook up user and invite data together for data table * added client derived data to user table * hooked up action dropdown to table * hooked up edit modal and password reset * started adding editing user functiaonlity * add query params to /invite call * clean up editing teams * update select team from to handle existing users with teams * update closes modal now * reuse getUser to clean up code in userManagementpage * pass form data to updating user that is not the current User * add dynamic userform submit text and fix tests * fix lint error in table component * added empty state for user table * clean up unused data table props * added delete modal * add delete user functionality * add delete option for invite * Merge in generateClassTag * Refactor table styles * Add newline to DropdownCell style sheet Co-authored-by: Gabriel Hernandez <ghernandez345@gmail.com> * update checking for admin through global_role in nav * added defaultGloablRole for creat user modal * remove unused comment * fix broken tests * reenabled search for users tests Co-authored-by: noahtalerman <47070608+noahtalerman@users.noreply.github.com>
2021-04-09 10:44:57 +00:00
return `${resultsCount.toLocaleString()} ${name}`;
};
export default { generateResultsCountText };