fleet/frontend/pages/SoftwarePage/SoftwareVulnerabilities/SoftwareVulnerabilities.tsx
jacobshandling 36485bed7e
UI – 3 bugs on Software pages (#20098)
## Addresses #19694 

<img width="1100" alt="Screenshot 2024-06-28 at 12 22 02 PM"
src="https://github.com/fleetdm/fleet/assets/61553566/527f3744-b532-4fdb-b43a-f7e10bb62189">
<img width="999" alt="Screenshot 2024-06-28 at 12 15 04 PM"
src="https://github.com/fleetdm/fleet/assets/61553566/407701ba-6d81-43b2-b193-217df1a93698">
<img width="999" alt="Screenshot 2024-06-28 at 12 12 10 PM"
src="https://github.com/fleetdm/fleet/assets/61553566/0e6aa2e3-a190-4db9-9468-d8dc3ad6ddcb">

- [x] Changes file added for user-visible changes in `changes/`,
- [x] Manual QA for all new/changed functionality

---------

Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2024-07-03 09:35:59 -07:00

101 lines
2.3 KiB
TypeScript

/** software/vulnerabilities Vulnerabilities tab */
import React from "react";
import { useQuery } from "react-query";
import { InjectedRouter } from "react-router";
import {
IGetVulnerabilitiesQueryKey,
IVulnerabilitiesResponse,
getVulnerabilities,
} from "services/entities/vulnerabilities";
import TableDataError from "components/DataError";
import Spinner from "components/Spinner";
import SoftwareVulnerabilitiesTable from "./SoftwareVulnerabilitiesTable";
const baseClass = "software-vulnerabilities";
interface ISoftwareVulnerabilitiesProps {
router: InjectedRouter;
isSoftwareEnabled: boolean;
perPage: number;
query?: string;
orderDirection: "asc" | "desc";
orderKey: string;
currentPage: number;
teamId?: number;
showExploitedVulnerabilitiesOnly: boolean;
resetPageIndex: boolean;
}
const SoftwareVulnerabilities = ({
router,
isSoftwareEnabled,
query,
perPage,
orderDirection,
orderKey,
currentPage,
teamId,
showExploitedVulnerabilitiesOnly,
resetPageIndex,
}: ISoftwareVulnerabilitiesProps) => {
const queryParams = {
page: currentPage,
per_page: perPage,
order_direction: orderDirection,
order_key: orderKey,
teamId,
query,
exploit: showExploitedVulnerabilitiesOnly,
};
const { data, isFetching, isLoading, isError } = useQuery<
IVulnerabilitiesResponse,
Error,
IVulnerabilitiesResponse,
IGetVulnerabilitiesQueryKey[]
>(
[
{
scope: "software-vulnerabilities",
...queryParams,
},
],
() => getVulnerabilities(queryParams),
{
keepPreviousData: true,
staleTime: 30000,
}
);
if (isLoading) {
return <Spinner />;
}
if (isError) {
return <TableDataError className={`${baseClass}__table-error`} />;
}
return (
<div className={baseClass}>
<SoftwareVulnerabilitiesTable
router={router}
data={data}
query={query}
showExploitedVulnerabilitiesOnly={showExploitedVulnerabilitiesOnly}
isSoftwareEnabled={isSoftwareEnabled}
perPage={perPage}
orderDirection={orderDirection}
orderKey={orderKey}
currentPage={currentPage}
teamId={teamId}
isLoading={isFetching}
resetPageIndex={resetPageIndex}
/>
</div>
);
};
export default SoftwareVulnerabilities;