From 5730c1c3c855ff8837b7475cd5b5c02bd8b122a8 Mon Sep 17 00:00:00 2001 From: jacobshandling <61553566+jacobshandling@users.noreply.github.com> Date: Mon, 5 Aug 2024 12:57:53 -0700 Subject: [PATCH] =?UTF-8?q?UI=20=E2=80=93=20Render=20"vulns=20not=20suppor?= =?UTF-8?q?ted"=20empty=20state=20for=20iphone/ipad=20host=20software=20fi?= =?UTF-8?q?ltered=20by=20vuln=20(#21029)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## #21027 Screenshot 2024-08-02 at 4 12 52 PM - [x] Manual QA for all new/changed functionality Co-authored-by: Jacob Shandling --- .../HostDetailsPage/HostDetailsPage.tsx | 3 ++ .../details/cards/Software/HostSoftware.tsx | 31 ++++++++++++++++--- .../HostSoftwareTable/HostSoftwareTable.tsx | 24 ++++++++++++-- 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/frontend/pages/hosts/details/HostDetailsPage/HostDetailsPage.tsx b/frontend/pages/hosts/details/HostDetailsPage/HostDetailsPage.tsx index 5f4a57a356..cf63e55962 100644 --- a/frontend/pages/hosts/details/HostDetailsPage/HostDetailsPage.tsx +++ b/frontend/pages/hosts/details/HostDetailsPage/HostDetailsPage.tsx @@ -53,6 +53,8 @@ import { HOST_OSQUERY_DATA, } from "utilities/constants"; +import { Platform } from "interfaces/platform"; + import Spinner from "components/Spinner"; import TabsWrapper from "components/TabsWrapper"; import MainContent from "components/MainContent"; @@ -921,6 +923,7 @@ const HostDetailsPage = ({ { interface IHostSoftwareProps { /** This is the host id or the device token */ id: number | string; + /** The host's platform. Only used for the host details page, so can be omited on the Device User Page. */ + platform?: Platform; softwareUpdatedAt?: string; hostCanInstallSoftware: boolean; router: InjectedRouter; @@ -82,6 +85,7 @@ export const parseHostSoftwareQueryParams = (queryParams: { const HostSoftware = ({ id, + platform, softwareUpdatedAt, hostCanInstallSoftware, router, @@ -93,6 +97,8 @@ const HostSoftware = ({ isMyDevicePage = false, }: IHostSoftwareProps) => { const { renderFlash } = useContext(NotificationContext); + const vulnFilterAndNotSupported = + ["ios", "ipados"].includes(platform ?? "") && queryParams.vulnerable; const { isGlobalAdmin, isGlobalMaintainer, @@ -129,7 +135,8 @@ const HostSoftware = ({ }, { ...DEFAULT_USE_QUERY_OPTIONS, - enabled: isSoftwareEnabled && !isMyDevicePage, // if disabled, we'll always show a generic "No software detected" message + enabled: + isSoftwareEnabled && !isMyDevicePage && !vulnFilterAndNotSupported, keepPreviousData: true, staleTime: 7000, } @@ -158,7 +165,7 @@ const HostSoftware = ({ ({ queryKey }) => deviceAPI.getDeviceSoftware(queryKey[0]), { ...DEFAULT_USE_QUERY_OPTIONS, - enabled: isSoftwareEnabled && isMyDevicePage, // if disabled, we'll always show a generic "No software detected" message + enabled: isSoftwareEnabled && isMyDevicePage, // if disabled, we'll always show a generic "No software detected" message. No DUP for iPad/iPhone keepPreviousData: true, staleTime: 7000, } @@ -251,7 +258,10 @@ const HostSoftware = ({ if (isLoading) { return ; } - + // will never be the case - to handle `platform` typing discrepancy with DeviceUserPage + if (!platform) { + return null; + } return ( <> {isError && } @@ -260,7 +270,20 @@ const HostSoftware = ({ isLoading={ isMyDevicePage ? deviceSoftwareFetching : hostSoftwareFetching } - data={data} + // this could be cleaner, however, we are going to revert this commit anyway once vulns are + // supported for iPad/iPhone, by the end of next sprint + data={ + vulnFilterAndNotSupported + ? ({ + count: 0, + meta: { + has_next_results: false, + has_previous_results: false, + }, + } as IGetHostSoftwareResponse) + : data + } // eshould be mpty for iPad/iPhone since API call is disabled, but to be sure to trigger empty state + platform={platform} router={router} tableConfig={tableConfig} sortHeader={queryParams.order_key} diff --git a/frontend/pages/hosts/details/cards/Software/HostSoftwareTable/HostSoftwareTable.tsx b/frontend/pages/hosts/details/cards/Software/HostSoftwareTable/HostSoftwareTable.tsx index 6ac5f7a4a9..cf37cd0065 100644 --- a/frontend/pages/hosts/details/cards/Software/HostSoftwareTable/HostSoftwareTable.tsx +++ b/frontend/pages/hosts/details/cards/Software/HostSoftwareTable/HostSoftwareTable.tsx @@ -8,6 +8,12 @@ import { QueryParams } from "utilities/url"; import { ISoftwareDropdownFilterVal } from "pages/SoftwarePage/SoftwareTitles/SoftwareTable/helpers"; +import { + ApplePlatform, + APPLE_PLATFORM_DISPLAY_NAMES, + Platform, +} from "interfaces/platform"; + import TableContainer from "components/TableContainer"; import { ITableQueryData } from "components/TableContainer/TableContainer"; // @ts-ignore @@ -15,6 +21,7 @@ import Dropdown from "components/forms/fields/Dropdown"; import EmptySoftwareTable from "pages/SoftwarePage/components/EmptySoftwareTable"; import TableCount from "components/TableContainer/TableCount"; +import { VulnsNotSupported } from "pages/SoftwarePage/components/SoftwareVulnerabilitiesTable/SoftwareVulnerabilitiesTable"; const DEFAULT_PAGE_SIZE = 20; @@ -45,6 +52,7 @@ export const DROPDOWN_OPTIONS = [ interface IHostSoftwareTableProps { tableConfig: any; // TODO: type data?: IGetHostSoftwareResponse | IGetDeviceSoftwareResponse; + platform: Platform; isLoading: boolean; router: InjectedRouter; sortHeader: string; @@ -60,6 +68,7 @@ interface IHostSoftwareTableProps { const HostSoftwareTable = ({ tableConfig, data, + platform, isLoading, router, sortHeader, @@ -167,7 +176,7 @@ const HostSoftwareTable = ({ [determineQueryParamChange, pagePath, generateNewQueryParams, router] ); - const count = data?.count || data?.software.length || 0; + const count = data?.count || data?.software?.length || 0; const isSoftwareNotDetected = count === 0 && searchQuery === ""; const memoizedSoftwareCount = useCallback(() => { @@ -179,8 +188,17 @@ const HostSoftwareTable = ({ }, [count, isSoftwareNotDetected]); const memoizedEmptyComponent = useCallback(() => { - return ; - }, [searchQuery]); + const vulnFilterAndNotSupported = + ["ios", "ipados"].includes(platform) && + hostSoftwareFilter === "vulnerableSoftware"; + return vulnFilterAndNotSupported ? ( + + ) : ( + + ); + }, [hostSoftwareFilter, platform, searchQuery]); return (