From ecaea6104de643c8e84f3d93c72c8271eb67e68f Mon Sep 17 00:00:00 2001 From: Sarah Gillespie <73313222+gillespi314@users.noreply.github.com> Date: Thu, 27 Feb 2025 05:33:49 -0600 Subject: [PATCH] Add host certificates refetch to UI (#26630) Fix unreleased UI bugs --- frontend/interfaces/platform.ts | 2 +- .../details/DeviceUserPage/DeviceUserPage.tsx | 45 +++++++------ .../HostDetailsPage/HostDetailsPage.tsx | 67 ++++++++++--------- 3 files changed, 60 insertions(+), 54 deletions(-) diff --git a/frontend/interfaces/platform.ts b/frontend/interfaces/platform.ts index 753cfc41b8..511b8b4f47 100644 --- a/frontend/interfaces/platform.ts +++ b/frontend/interfaces/platform.ts @@ -128,7 +128,7 @@ export const isLinuxLike = (platform: string) => { ); }; -export const isAppleDevice = (platform: string) => { +export const isAppleDevice = (platform = "") => { return HOST_APPLE_PLATFORMS.includes( platform as typeof HOST_APPLE_PLATFORMS[number] ); diff --git a/frontend/pages/hosts/details/DeviceUserPage/DeviceUserPage.tsx b/frontend/pages/hosts/details/DeviceUserPage/DeviceUserPage.tsx index d90ceebd29..ac66fd66e9 100644 --- a/frontend/pages/hosts/details/DeviceUserPage/DeviceUserPage.tsx +++ b/frontend/pages/hosts/details/DeviceUserPage/DeviceUserPage.tsx @@ -157,8 +157,31 @@ const DeviceUserPage = ({ } ); + const { + data: deviceCertificates, + isLoading: isLoadingDeviceCertificates, + isError: isErrorDeviceCertificates, + refetch: refetchDeviceCertificates, + } = useQuery( + ["hostCertificates", deviceAuthToken], + () => + deviceUserAPI.getDeviceCertificates( + deviceAuthToken, + DEFAULT_CERTIFICATES_PAGE, + DEFAULT_CERTIFICATES_PAGE_SIZE + ), + { + ...DEFAULT_USE_QUERY_OPTIONS, + // FIXME: is it worth disabling for unsupported platforms? we'd have to workaround the a + // catch-22 where we need to know the platform to know if it's supported but we also need to + // be able to include the cert refetch in the hosts query hook. + enabled: !!deviceUserAPI, + } + ); + const refetchExtensions = () => { deviceMapping !== null && refetchDeviceMapping(); + deviceCertificates && refetchDeviceCertificates(); }; const isRefetching = ({ @@ -253,25 +276,7 @@ const DeviceUserPage = ({ self_service: hasSelfService = false, } = dupResponse || {}; const isPremiumTier = license?.tier === "premium"; - const isAppleHost = host && isAppleDevice(host.platform); - - const { - data: deviceCertificates, - isLoading: isLoadingDeviceCertificates, - isError: isErrorDeviceCertificates, - } = useQuery( - ["hostCertificates", deviceAuthToken], - () => - deviceUserAPI.getDeviceCertificates( - deviceAuthToken, - DEFAULT_CERTIFICATES_PAGE, - DEFAULT_CERTIFICATES_PAGE_SIZE - ), - { - ...DEFAULT_USE_QUERY_OPTIONS, - enabled: !!deviceUserAPI && isAppleHost, - } - ); + const isAppleHost = isAppleDevice(host?.platform); const summaryData = normalizeEmptyValues(pick(host, HOST_SUMMARY_DATA)); @@ -453,7 +458,7 @@ const DeviceUserPage = ({ deviceMapping={deviceMapping} munki={deviceMacAdminsData?.munki} /> - {isAppleHost && deviceCertificates?.certificates.length && ( + {isAppleHost && !!deviceCertificates?.certificates.length && ( ( + [ + "host-certificates", + host_id, + DEFAULT_CERTIFICATES_PAGE, + DEFAULT_CERTIFICATES_PAGE_SIZE, + ], + () => + hostAPI.getHostCertificates( + hostIdFromURL, + DEFAULT_CERTIFICATES_PAGE, + DEFAULT_CERTIFICATES_PAGE_SIZE + ), + { + ...DEFAULT_USE_QUERY_OPTIONS, + // FIXME: is it worth disabling for unsupported platforms? we'd have to workaround the a + // catch-22 where we need to know the platform to know if it's supported but we also need to + // be able to include the cert refetch in the hosts query hook. + enabled: !!hostIdFromURL, + } + ); + const refetchExtensions = () => { deviceMapping !== null && refetchDeviceMapping(); macadmins !== null && refetchMacadmins(); mdm?.enrollment_status !== null && refetchMdm(); + hostCertificates && refetchHostCertificates(); }; const { @@ -462,37 +494,6 @@ const HostDetailsPage = ({ } ); - const { - data: hostCertificates, - isLoading: isLoadingHostCertificates, - isError: isErrorHostCertificates, - } = useQuery< - IGetHostCertificatesResponse, - Error, - IGetHostCertificatesResponse - >( - [ - "host-certificates", - host_id, - DEFAULT_CERTIFICATES_PAGE, - DEFAULT_CERTIFICATES_PAGE_SIZE, - ], - () => - hostAPI.getHostCertificates( - hostIdFromURL, - DEFAULT_CERTIFICATES_PAGE, - DEFAULT_CERTIFICATES_PAGE_SIZE - ), - { - ...DEFAULT_USE_QUERY_OPTIONS, - enabled: - !!hostIdFromURL && - (host?.platform === "darwin" || - host?.platform === "ios" || - host?.platform === "ipados"), - } - ); - const featuresConfig = host?.team_id ? teams?.find((t) => t.id === host.team_id)?.features : config?.features; @@ -957,7 +958,7 @@ const HostDetailsPage = ({ /> )} {(isIosOrIpadosHost || isDarwinHost) && - hostCertificates?.certificates.length && ( + !!hostCertificates?.certificates.length && ( - {host?.platform === "darwin" && macadmins?.munki?.version && ( + {isDarwinHost && macadmins?.munki?.version && (