fleet/frontend/pages/admin/TeamManagementPage/TeamTableConfig.tsx
jacobshandling b990b3c6d9
UI - GitOps Mode, 3/3 (#26537)
## For #26229 

- Remove feature flag
- Undo updates to 4 Policies automation modals to facilitate refactor
being implemented in parallel
- Remaining specs:

**Manage teams:**

![manage-teams](https://github.com/user-attachments/assets/af8d8d10-2add-4d8d-8961-61d0de44b067)

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:**

![team-users](https://github.com/user-attachments/assets/1bf106c1-bdf7-442c-a957-6c9eea6af14d)
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-agent-options](https://github.com/user-attachments/assets/7d4ee8b6-03c7-48d2-8337-b2c33e50abe9)

**Team settings:**

![team-settings](https://github.com/user-attachments/assets/a67b45fc-a5ce-4267-b8fd-2f1e300d1fd8)


- [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>
2025-02-21 16:56:20 -08:00

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 };