mirror of
https://github.com/fleetdm/fleet
synced 2026-05-14 20:48:35 +00:00
## For #28159 - Implement UI capability to run scripts on batches of hosts at a time - Add new hosts table `Run script` primary action, triggers - new `RunScriptBatch` modal, allows running scripts on the selected batch of hosts - new `RunScriptBatchPaginatedList`, handles logic specific to this modal, and utilizes the now more flexible `PaginatedList` component - Widen capabilities of `PaginatedList` component to elegantly handle more diverse applications, including this one - Widen capabilities of `ScriptDetailsModal` component to elegantly handle more diverse applications, including this one - Streamline updating `state`s on manage hosts page - Clearer, more concise naming - [x] Changes file added for user-visible changes in `changes/` - [x] 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>
126 lines
3.6 KiB
TypeScript
126 lines
3.6 KiB
TypeScript
import React, { useState } from "react";
|
|
|
|
import simpleSearch from "utilities/simple_search";
|
|
import { IScheduledQuery } from "interfaces/scheduled_query";
|
|
|
|
import TableContainer from "components/TableContainer";
|
|
import { ITableQueryData } from "components/TableContainer/TableContainer";
|
|
import Button from "components/buttons/Button";
|
|
import EmptyTable from "components/EmptyTable";
|
|
import Icon from "components/Icon/Icon";
|
|
import {
|
|
generateTableHeaders,
|
|
generateDataSet,
|
|
} from "./PackQueriesTable/PackQueriesTableConfig";
|
|
|
|
const baseClass = "pack-queries-table";
|
|
|
|
interface IPackQueriesTableProps {
|
|
onAddPackQuery: () => void;
|
|
onEditPackQuery: (selectedQuery: IScheduledQuery) => void;
|
|
onRemovePackQueries: (selectedTableQueryIds: number[]) => void;
|
|
scheduledQueries: IScheduledQuery[] | undefined;
|
|
isLoadingPackQueries: boolean;
|
|
}
|
|
|
|
const PackQueriesTable = ({
|
|
onAddPackQuery,
|
|
onEditPackQuery,
|
|
onRemovePackQueries,
|
|
scheduledQueries,
|
|
isLoadingPackQueries,
|
|
}: IPackQueriesTableProps): JSX.Element => {
|
|
const [querySearchText, setQuerySearchText] = useState("");
|
|
|
|
// NOTE: this is called once on the initial rendering. The initial render of
|
|
// the TableContainer child component will call this handler.
|
|
const onTableQueryChange = (queryData: ITableQueryData) => {
|
|
const { searchQuery, sortHeader, sortDirection } = queryData;
|
|
let sortBy = [];
|
|
if (sortHeader !== "") {
|
|
sortBy = [{ id: sortHeader, direction: sortDirection }];
|
|
}
|
|
|
|
if (!searchQuery) {
|
|
setQuerySearchText("");
|
|
return;
|
|
}
|
|
|
|
setQuerySearchText(searchQuery);
|
|
};
|
|
|
|
const getQueries = () => {
|
|
return simpleSearch(querySearchText, scheduledQueries);
|
|
};
|
|
|
|
const onActionSelection = (
|
|
action: string,
|
|
selectedQuery: IScheduledQuery
|
|
) => {
|
|
switch (action) {
|
|
case "edit":
|
|
onEditPackQuery(selectedQuery);
|
|
break;
|
|
case "remove":
|
|
onRemovePackQueries([selectedQuery.id]);
|
|
break;
|
|
default:
|
|
}
|
|
};
|
|
|
|
const tableHeaders = generateTableHeaders(onActionSelection);
|
|
const tableData = generateDataSet(getQueries());
|
|
|
|
return (
|
|
<div className={`${baseClass}`}>
|
|
{scheduledQueries?.length ? (
|
|
<TableContainer
|
|
columnConfigs={tableHeaders}
|
|
data={tableData}
|
|
isLoading={isLoadingPackQueries}
|
|
defaultSortHeader="name"
|
|
defaultSortDirection="asc"
|
|
inputPlaceHolder="Search queries"
|
|
onQueryChange={onTableQueryChange}
|
|
resultsTitle="queries"
|
|
emptyComponent={() =>
|
|
EmptyTable({
|
|
header: "No queries match your search criteria",
|
|
info: "Try a different search.",
|
|
})
|
|
}
|
|
showMarkAllPages={false}
|
|
actionButton={{
|
|
name: "add query",
|
|
buttonText: "Add query",
|
|
iconSvg: "plus",
|
|
variant: "text-icon",
|
|
onClick: onAddPackQuery,
|
|
}}
|
|
primarySelectAction={{
|
|
name: "remove query",
|
|
buttonText: "Remove",
|
|
iconSvg: "close",
|
|
variant: "text-icon",
|
|
onClick: onRemovePackQueries,
|
|
}}
|
|
searchable
|
|
disablePagination
|
|
isAllPagesSelected={false}
|
|
/>
|
|
) : (
|
|
<div className={`${baseClass}__no-queries`}>
|
|
<p>Your pack has no queries.</p>
|
|
<Button onClick={onAddPackQuery} variant="text-icon" iconStroke>
|
|
<>
|
|
Add query
|
|
<Icon name="plus" />
|
|
</>
|
|
</Button>
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default PackQueriesTable;
|