mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 13:37:30 +00:00
# Details This PR merges the feature branch for the scheduled scripts UI into main. This includes the following previously-approved PRs: * https://github.com/fleetdm/fleet/pull/31750 * https://github.com/fleetdm/fleet/pull/31604 * https://github.com/fleetdm/fleet/pull/31797 # Checklist for submitter If some of the following don't apply, delete the relevant line. - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. ## Testing - [X] Added/updated automated tests - [X] Where appropriate, [automated tests simulate multiple hosts and test for host isolation](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/reference/patterns-backend.md#unit-testing) (updates to one hosts's records do not affect another) - [X] QA'd all new/changed functionality manually --------- Co-authored-by: jacobshandling <61553566+jacobshandling@users.noreply.github.com> Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
99 lines
2.4 KiB
TypeScript
99 lines
2.4 KiB
TypeScript
import React from "react";
|
|
import { Column } from "react-table";
|
|
|
|
import StatusIndicatorWithIcon from "components/StatusIndicatorWithIcon";
|
|
import {
|
|
INumberCellProps,
|
|
IStringCellProps,
|
|
} from "interfaces/datatable_config";
|
|
import { IScriptBatchSummaryResponseV1 } 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", "canceled"];
|
|
|
|
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",
|
|
},
|
|
canceled: {
|
|
displayName: "Canceled",
|
|
indicatorStatus: "failure",
|
|
},
|
|
} 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: IScriptBatchSummaryResponseV1
|
|
): IRowData[] => {
|
|
const tableData = STATUS_ORDER.map((status) => ({
|
|
status,
|
|
hosts: statusData[status as keyof IScriptBatchSummaryResponseV1] as number,
|
|
}));
|
|
|
|
return tableData;
|
|
};
|