2021-09-10 19:06:37 +00:00
|
|
|
/* eslint-disable react/prop-types */
|
|
|
|
|
|
|
|
|
|
import React from "react";
|
2022-06-10 18:29:45 +00:00
|
|
|
import { Row } from "react-table";
|
2021-09-10 19:06:37 +00:00
|
|
|
|
|
|
|
|
import { IDataColumn } from "interfaces/datatable_config";
|
2023-02-22 21:27:02 +00:00
|
|
|
import { IHost } from "interfaces/host";
|
2021-09-10 19:06:37 +00:00
|
|
|
|
|
|
|
|
import TextCell from "components/TableContainer/DataTable/TextCell";
|
2023-02-22 21:27:02 +00:00
|
|
|
import LiveQueryIssueCell from "components/TableContainer/DataTable/LiveQueryIssueCell/LiveQueryIssueCell";
|
2022-12-13 18:04:07 +00:00
|
|
|
import StatusIndicator from "components/StatusIndicator";
|
2022-06-10 18:29:45 +00:00
|
|
|
import RemoveIcon from "../../../../assets/images/icon-action-remove-20x20@2x.png";
|
2021-09-10 19:06:37 +00:00
|
|
|
|
2023-02-22 21:27:02 +00:00
|
|
|
interface ICellProps {
|
|
|
|
|
cell: {
|
|
|
|
|
value: string;
|
|
|
|
|
};
|
|
|
|
|
row: {
|
|
|
|
|
original: IHost;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-10 19:06:37 +00:00
|
|
|
// NOTE: cellProps come from react-table
|
|
|
|
|
// more info here https://react-table.tanstack.com/docs/api/useTable#cell-properties
|
2022-06-10 18:29:45 +00:00
|
|
|
export const generateTableHeaders = (
|
|
|
|
|
handleRowRemove?: (value: Row) => void
|
|
|
|
|
): IDataColumn[] => {
|
|
|
|
|
const deleteHeader = handleRowRemove
|
2021-09-10 19:06:37 +00:00
|
|
|
? [
|
|
|
|
|
{
|
2021-11-08 22:12:58 +00:00
|
|
|
id: "delete",
|
|
|
|
|
Header: "",
|
2022-06-10 18:29:45 +00:00
|
|
|
Cell: (cellProps: { row: Row }): JSX.Element => (
|
|
|
|
|
<div onClick={() => handleRowRemove(cellProps.row)}>
|
2021-11-08 22:12:58 +00:00
|
|
|
<img alt="Remove" src={RemoveIcon} />
|
|
|
|
|
</div>
|
|
|
|
|
),
|
2021-09-10 19:06:37 +00:00
|
|
|
disableHidden: true,
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
: [];
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
{
|
2022-10-14 19:26:15 +00:00
|
|
|
title: "Host",
|
|
|
|
|
Header: "Host",
|
|
|
|
|
accessor: "display_name",
|
2023-02-22 21:27:02 +00:00
|
|
|
Cell: (cellProps: ICellProps) => {
|
|
|
|
|
return (
|
|
|
|
|
<LiveQueryIssueCell
|
|
|
|
|
displayName={cellProps.cell.value}
|
|
|
|
|
distributedInterval={cellProps.row.original.distributed_interval}
|
|
|
|
|
status={cellProps.row.original.status}
|
|
|
|
|
rowId={cellProps.row.original.id}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
},
|
2021-09-10 19:06:37 +00:00
|
|
|
},
|
2022-06-10 18:29:45 +00:00
|
|
|
// TODO: Consider removing status column from selected hosts table because
|
|
|
|
|
// status info is not refreshed once a target has been selected
|
2021-09-10 19:06:37 +00:00
|
|
|
{
|
|
|
|
|
title: "Status",
|
|
|
|
|
Header: "Status",
|
|
|
|
|
disableSortBy: true,
|
|
|
|
|
accessor: "status",
|
2022-12-13 18:04:07 +00:00
|
|
|
Cell: (cellProps) => <StatusIndicator value={cellProps.cell.value} />,
|
2021-09-10 19:06:37 +00:00
|
|
|
},
|
|
|
|
|
{
|
2022-10-25 15:56:09 +00:00
|
|
|
title: "Private IP address",
|
|
|
|
|
Header: "Private IP address",
|
2021-09-10 19:06:37 +00:00
|
|
|
accessor: "primary_ip",
|
|
|
|
|
Cell: (cellProps) => <TextCell value={cellProps.cell.value} />,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: "MAC address",
|
|
|
|
|
Header: "MAC address",
|
|
|
|
|
accessor: "primary_mac",
|
|
|
|
|
Cell: (cellProps) => <TextCell value={cellProps.cell.value} />,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: "OS",
|
|
|
|
|
Header: "OS",
|
|
|
|
|
accessor: "os_version",
|
|
|
|
|
Cell: (cellProps) => <TextCell value={cellProps.cell.value} />,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: "Osquery",
|
|
|
|
|
Header: "Osquery",
|
|
|
|
|
accessor: "osquery_version",
|
|
|
|
|
Cell: (cellProps) => <TextCell value={cellProps.cell.value} />,
|
|
|
|
|
},
|
2021-11-08 22:12:58 +00:00
|
|
|
...deleteHeader,
|
2021-09-10 19:06:37 +00:00
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default null;
|