Map raw label membership type to copy meant for render (#34387)

<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #34239

<img width="1765" height="1146" alt="Screenshot 2025-10-16 at 12 11
39 PM"
src="https://github.com/user-attachments/assets/4735012d-6ddc-45cd-87a8-f92c9b7283b0"
/>

- [x] Added/updated automated tests
- [x] QA'd all new/changed functionality manually
This commit is contained in:
jacobshandling
2025-10-16 13:05:43 -07:00
committed by GitHub
parent 24ceeee0b4
commit 45eccc1be1
3 changed files with 31 additions and 7 deletions
+9
View File
@@ -16,6 +16,15 @@ export default PropTypes.shape({
export type LabelType = "regular" | "builtin";
export type LabelMembershipType = "dynamic" | "manual" | "host_vitals";
export const LabelMembershipTypeToDisplayCopy: Record<
LabelMembershipType,
string
> = {
dynamic: "Dynamic",
manual: "Manual",
host_vitals: "Host vitals",
};
export type LabelHostVitalsCriterion =
| "end_user_idp_group"
| "end_user_idp_department"; // for now, may expand to be configurable
@@ -48,6 +48,7 @@ describe("LabelsTable", () => {
name: "Custom label 1",
label_type: "regular",
description: "First custom label",
label_membership_type: "dynamic",
}),
createMockLabel({
id: 3,
@@ -59,6 +60,14 @@ describe("LabelsTable", () => {
name: "Custom label 2",
label_type: "regular",
description: "Second custom label",
label_membership_type: "manual",
}),
createMockLabel({
id: 5,
name: "Custom label 3",
label_type: "regular",
description: "Third custom label",
label_membership_type: "host_vitals",
}),
];
@@ -75,9 +84,16 @@ describe("LabelsTable", () => {
// Custom labels should be visible, each with the regular copy and the full name in a tooltip
expect(screen.queryAllByText("Custom label 1")).toHaveLength(2);
expect(screen.queryAllByText("Custom label 2")).toHaveLength(2);
expect(screen.queryAllByText("First custom label")).toHaveLength(2);
expect(screen.queryAllByText("Dynamic")).toHaveLength(1);
expect(screen.queryAllByText("Custom label 2")).toHaveLength(2);
expect(screen.queryAllByText("Second custom label")).toHaveLength(2);
expect(screen.queryAllByText("Manual")).toHaveLength(1);
expect(screen.queryAllByText("Custom label 3")).toHaveLength(2);
expect(screen.queryAllByText("Third custom label")).toHaveLength(2);
expect(screen.queryAllByText("Host vitals")).toHaveLength(1);
// Builtin labels should not be visible
expect(screen.queryByText("All hosts")).not.toBeInTheDocument();
@@ -1,16 +1,14 @@
import React from "react";
import { ILabel } from "interfaces/label";
import { ILabel, LabelMembershipTypeToDisplayCopy } from "interfaces/label";
import { IDropdownOption } from "interfaces/dropdownOption";
import TextCell from "components/TableContainer/DataTable/TextCell";
import ActionsDropdown from "components/ActionsDropdown";
import {
isGlobalAdmin,
isGlobalMaintainer,
isAnyTeamMaintainerOrTeamAdmin,
} from "utilities/permissions/permissions";
import { IUser } from "interfaces/user";
import { capitalize } from "lodash";
import HeaderCell from "components/TableContainer/DataTable/HeaderCell";
import ViewAllHostsLink from "components/ViewAllHostsLink";
import TooltipTruncatedTextCell from "components/TableContainer/DataTable/TooltipTruncatedTextCell";
@@ -131,9 +129,10 @@ const generateTableHeaders = (
/>
),
accessor: "label_membership_type",
Cell: (cellProps: ICellProps) => (
<TextCell value={capitalize(cellProps.cell.value)} />
),
Cell: (cellProps: ICellProps) => {
const type = cellProps.row.original.label_membership_type;
return <TextCell value={LabelMembershipTypeToDisplayCopy[type]} />;
},
},
{
title: "Actions",