mirror of
https://github.com/fleetdm/fleet
synced 2026-05-20 07:29:08 +00:00
## For #26229 - Remove feature flag - Undo updates to 4 Policies automation modals to facilitate refactor being implemented in parallel - Remaining specs: **Manage teams:**  Empty: <img width="1464" alt="Screenshot 2025-02-21 at 4 27 30 PM" src="https://github.com/user-attachments/assets/17cf4fc2-cc4e-4f63-8276-3db79b44e9e1" /> **Team users:**  Empty: <img width="1464" alt="Screenshot 2025-02-21 at 4 29 01 PM" src="https://github.com/user-attachments/assets/46dd0e44-2af3-4ca7-a0be-628e358a61d7" /> **Team agent options:**  **Team settings:**  - [x] Changes file added for user-visible changes in `changes/` - [x] Added/updated automated tests - [ ] A detailed QA plan exists on the associated ticket (if it isn't there, work with the product group's QA engineer to add it) - [x] Manual QA for all new/changed functionality --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
149 lines
3.6 KiB
TypeScript
149 lines
3.6 KiB
TypeScript
import React from "react";
|
|
|
|
import { ITeam } from "interfaces/team";
|
|
import { IDropdownOption } from "interfaces/dropdownOption";
|
|
import PATHS from "router/paths";
|
|
|
|
import LinkCell from "components/TableContainer/DataTable/LinkCell";
|
|
import TextCell from "components/TableContainer/DataTable/TextCell";
|
|
import ActionsDropdown from "components/ActionsDropdown";
|
|
import GitOpsModeTooltipWrapper from "components/GitOpsModeTooltipWrapper";
|
|
|
|
interface IHeaderProps {
|
|
column: {
|
|
title: string;
|
|
isSortedDesc: boolean;
|
|
};
|
|
}
|
|
|
|
interface IRowProps {
|
|
row: {
|
|
original: ITeam;
|
|
};
|
|
}
|
|
interface ICellProps extends IRowProps {
|
|
cell: {
|
|
value: string;
|
|
};
|
|
}
|
|
|
|
interface IDropdownCellProps extends IRowProps {
|
|
cell: {
|
|
value: IDropdownOption[];
|
|
};
|
|
}
|
|
|
|
interface IDataColumn {
|
|
title: string;
|
|
Header: ((props: IHeaderProps) => JSX.Element) | string;
|
|
accessor: string;
|
|
Cell:
|
|
| ((props: ICellProps) => JSX.Element)
|
|
| ((props: IDropdownCellProps) => JSX.Element);
|
|
disableHidden?: boolean;
|
|
disableSortBy?: boolean;
|
|
sortType?: string;
|
|
}
|
|
|
|
interface ITeamTableData extends ITeam {
|
|
actions: IDropdownOption[];
|
|
}
|
|
|
|
// NOTE: cellProps come from react-table
|
|
// more info here https://react-table.tanstack.com/docs/api/useTable#cell-properties
|
|
const generateTableHeaders = (
|
|
actionSelectHandler: (value: string, team: ITeam) => void
|
|
): IDataColumn[] => {
|
|
return [
|
|
{
|
|
title: "Name",
|
|
Header: "Name",
|
|
disableSortBy: true,
|
|
sortType: "caseInsensitive",
|
|
accessor: "name",
|
|
Cell: (cellProps: ICellProps) => (
|
|
<LinkCell
|
|
value={cellProps.cell.value}
|
|
path={PATHS.TEAM_DETAILS_USERS(cellProps.row.original.id)}
|
|
/>
|
|
),
|
|
},
|
|
// TODO: need to add this info to API
|
|
{
|
|
title: "Hosts",
|
|
Header: "Hosts",
|
|
disableSortBy: true,
|
|
accessor: "host_count",
|
|
Cell: (cellProps: ICellProps) => (
|
|
<TextCell value={cellProps.cell.value} />
|
|
),
|
|
},
|
|
{
|
|
title: "Users",
|
|
Header: "Users",
|
|
disableSortBy: true,
|
|
accessor: "user_count",
|
|
Cell: (cellProps: ICellProps) => (
|
|
<TextCell value={cellProps.cell.value} />
|
|
),
|
|
},
|
|
{
|
|
title: "Actions",
|
|
Header: "",
|
|
disableSortBy: true,
|
|
accessor: "actions",
|
|
Cell: (cellProps: IDropdownCellProps) => (
|
|
<GitOpsModeTooltipWrapper
|
|
position="left"
|
|
renderChildren={(disableChildren) => (
|
|
<div className={disableChildren ? "disabled-by-gitops-mode" : ""}>
|
|
<ActionsDropdown
|
|
options={cellProps.cell.value}
|
|
onChange={(value: string) =>
|
|
actionSelectHandler(value, cellProps.row.original)
|
|
}
|
|
placeholder="Actions"
|
|
disabled={disableChildren}
|
|
/>
|
|
</div>
|
|
)}
|
|
/>
|
|
),
|
|
},
|
|
];
|
|
};
|
|
|
|
// NOTE: may need current user ID later for permission on actions.
|
|
const generateActionDropdownOptions = (): IDropdownOption[] => {
|
|
return [
|
|
{
|
|
label: "Rename",
|
|
disabled: false,
|
|
value: "rename",
|
|
},
|
|
{
|
|
label: "Delete",
|
|
disabled: false,
|
|
value: "delete",
|
|
},
|
|
];
|
|
};
|
|
|
|
const enhanceTeamData = (teams: ITeam[]): ITeamTableData[] => {
|
|
return Object.values(teams).map((team) => {
|
|
return {
|
|
description: team.description,
|
|
name: team.name,
|
|
host_count: team.host_count,
|
|
user_count: team.user_count,
|
|
actions: generateActionDropdownOptions(),
|
|
id: team.id,
|
|
};
|
|
});
|
|
};
|
|
|
|
const generateDataSet = (teams: ITeam[]): ITeamTableData[] => {
|
|
return [...enhanceTeamData(teams)];
|
|
};
|
|
|
|
export { generateTableHeaders, generateDataSet };
|