2025-05-22 23:45:43 +00:00
|
|
|
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";
|
2025-06-09 17:53:17 +00:00
|
|
|
import ScriptBatchHostCountCell from "../ScriptBatchHostCountCell/ScriptBatchHostCountCell";
|
2025-05-22 23:45:43 +00:00
|
|
|
|
|
|
|
|
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 = (
|
2025-06-09 17:53:17 +00:00
|
|
|
batchExecutionId: string,
|
|
|
|
|
onClickCancel: () => void,
|
|
|
|
|
teamId?: number
|
2025-05-22 23:45:43 +00:00
|
|
|
): 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 (
|
2025-06-09 17:53:17 +00:00
|
|
|
<ScriptBatchHostCountCell
|
2025-05-22 23:45:43 +00:00
|
|
|
count={cell.value}
|
|
|
|
|
status={cell.row.original.status}
|
2025-06-09 17:53:17 +00:00
|
|
|
batchExecutionId={batchExecutionId}
|
2025-05-22 23:45:43 +00:00
|
|
|
onClickCancel={onClickCancel}
|
2025-06-09 17:53:17 +00:00
|
|
|
teamId={teamId}
|
2025-05-22 23:45:43 +00:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const generateTableData = (
|
|
|
|
|
statusData: IScriptBatchSummaryResponse
|
|
|
|
|
): IRowData[] => {
|
|
|
|
|
const tableData = STATUS_ORDER.map((status) => ({
|
|
|
|
|
status,
|
|
|
|
|
hosts: statusData[status as keyof IScriptBatchSummaryResponse] as number,
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
return tableData;
|
|
|
|
|
};
|