mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
Manage policies page: Add search functionality (#10967)
This commit is contained in:
parent
6f836d60cb
commit
7198026f91
1 changed files with 22 additions and 3 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import React, { useContext } from "react";
|
||||
import React, { useContext, useState } from "react";
|
||||
import { AppContext } from "context/app";
|
||||
import { noop } from "lodash";
|
||||
import paths from "router/paths";
|
||||
|
|
@ -9,7 +9,7 @@ import { IEmptyTableProps } from "interfaces/empty_table";
|
|||
|
||||
import Button from "components/buttons/Button";
|
||||
import Spinner from "components/Spinner";
|
||||
import TableContainer from "components/TableContainer";
|
||||
import TableContainer, { ITableQueryData } from "components/TableContainer";
|
||||
import EmptyTable from "components/EmptyTable";
|
||||
import { generateTableHeaders, generateDataSet } from "./PoliciesTableConfig";
|
||||
|
||||
|
|
@ -46,6 +46,12 @@ const PoliciesTable = ({
|
|||
|
||||
const { config } = useContext(AppContext);
|
||||
|
||||
const [searchString, setSearchString] = useState("");
|
||||
|
||||
const handleSearchChange = ({ searchQuery }: ITableQueryData) => {
|
||||
setSearchString(searchQuery);
|
||||
};
|
||||
|
||||
const emptyState = () => {
|
||||
const emptyPolicies: IEmptyTableProps = {
|
||||
iconName: "empty-policies",
|
||||
|
|
@ -90,10 +96,19 @@ const PoliciesTable = ({
|
|||
</Button>
|
||||
);
|
||||
}
|
||||
if (searchString) {
|
||||
delete emptyPolicies.iconName;
|
||||
delete emptyPolicies.primaryButton;
|
||||
emptyPolicies.header = "No policies match the current search criteria.";
|
||||
emptyPolicies.info =
|
||||
"Expecting to see policies? Try again in a few seconds as the system catches up.";
|
||||
}
|
||||
|
||||
return emptyPolicies;
|
||||
};
|
||||
|
||||
const searchable = !(policiesList?.length === 0 && searchString === "");
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`${baseClass} ${
|
||||
|
|
@ -134,9 +149,13 @@ const PoliciesTable = ({
|
|||
primaryButton: emptyState().primaryButton,
|
||||
})
|
||||
}
|
||||
onQueryChange={noop}
|
||||
disableCount={tableType === "inheritedPolicies"}
|
||||
isClientSidePagination
|
||||
isClientSideFilter
|
||||
searchQueryColumn="name"
|
||||
onQueryChange={handleSearchChange}
|
||||
inputPlaceHolder="Search by name"
|
||||
searchable={searchable}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in a new issue