mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 21:47:20 +00:00
## For #29444 - Update script batch summary modal status rows to link to the hosts page filtered by the appropriate batch script run and status - Add above filtering capabilities to the hosts page <img width="1912" alt="Screenshot 2025-05-30 at 12 39 54 PM" src="https://github.com/user-attachments/assets/4299ecaa-10bd-49f4-b0f8-cd0e71108e04" /> <img width="1912" alt="Screenshot 2025-05-30 at 12 40 22 PM" src="https://github.com/user-attachments/assets/8252560e-59a2-42a9-bd0c-e5ca05c53390" /> - [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>
95 lines
2.3 KiB
TypeScript
95 lines
2.3 KiB
TypeScript
import React from "react";
|
|
import { Column } from "react-table";
|
|
|
|
import StatusIndicatorWithIcon from "components/StatusIndicatorWithIcon";
|
|
import {
|
|
INumberCellProps,
|
|
IStringCellProps,
|
|
} from "interfaces/datatable_config";
|
|
import { IScriptBatchSummaryResponse } from "services/entities/scripts";
|
|
import ScriptBatchHostCountCell from "../ScriptBatchHostCountCell/ScriptBatchHostCountCell";
|
|
|
|
type IStatus = "ran" | "pending" | "errored";
|
|
|
|
interface IRowData {
|
|
status: string;
|
|
hosts: number;
|
|
}
|
|
|
|
const STATUS_ORDER = ["ran", "pending", "errored"];
|
|
|
|
export interface IStatusCellValue {
|
|
displayName: string;
|
|
statusName: IStatus;
|
|
value: IStatus;
|
|
}
|
|
|
|
const STATUS_DISPLAY_OPTIONS = {
|
|
ran: {
|
|
displayName: "Ran",
|
|
indicatorStatus: "success",
|
|
},
|
|
pending: {
|
|
displayName: "Pending",
|
|
indicatorStatus: "pendingPartial",
|
|
},
|
|
errored: {
|
|
displayName: "Error",
|
|
indicatorStatus: "error",
|
|
},
|
|
} as const;
|
|
|
|
type IColumnConfig = Column<IRowData>;
|
|
type IStatusCellProps = IStringCellProps<IRowData>;
|
|
type IHostCellProps = INumberCellProps<IRowData>;
|
|
|
|
export const generateTableConfig = (
|
|
batchExecutionId: string,
|
|
onClickCancel: () => void,
|
|
teamId?: number
|
|
): IColumnConfig[] => {
|
|
return [
|
|
{
|
|
Header: "Status",
|
|
disableSortBy: true,
|
|
accessor: "status",
|
|
Cell: ({ cell: { value } }: IStatusCellProps) => {
|
|
const statusOption =
|
|
STATUS_DISPLAY_OPTIONS[value as keyof typeof STATUS_DISPLAY_OPTIONS];
|
|
return (
|
|
<StatusIndicatorWithIcon
|
|
status={statusOption.indicatorStatus}
|
|
value={statusOption.displayName}
|
|
/>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
Header: "Hosts",
|
|
accessor: "hosts",
|
|
disableSortBy: true,
|
|
Cell: ({ cell }: IHostCellProps) => {
|
|
return (
|
|
<ScriptBatchHostCountCell
|
|
count={cell.value}
|
|
status={cell.row.original.status}
|
|
batchExecutionId={batchExecutionId}
|
|
onClickCancel={onClickCancel}
|
|
teamId={teamId}
|
|
/>
|
|
);
|
|
},
|
|
},
|
|
];
|
|
};
|
|
|
|
export const generateTableData = (
|
|
statusData: IScriptBatchSummaryResponse
|
|
): IRowData[] => {
|
|
const tableData = STATUS_ORDER.map((status) => ({
|
|
status,
|
|
hosts: statusData[status as keyof IScriptBatchSummaryResponse] as number,
|
|
}));
|
|
|
|
return tableData;
|
|
};
|