diff --git a/x-pack/plugins/alerting/public/hooks/use_find_maintenance_windows.test.tsx b/x-pack/plugins/alerting/public/hooks/use_find_maintenance_windows.test.tsx index cdd188af84f8b..2080b9ff39d43 100644 --- a/x-pack/plugins/alerting/public/hooks/use_find_maintenance_windows.test.tsx +++ b/x-pack/plugins/alerting/public/hooks/use_find_maintenance_windows.test.tsx @@ -53,4 +53,12 @@ describe('useFindMaintenanceWindows', () => { expect(mockAddDanger).toBeCalledWith('Unable to load maintenance windows.') ); }); + + it('should not try to find maintenance windows if not enabled', async () => { + renderHook(() => useFindMaintenanceWindows({ enabled: false }), { + wrapper: appMockRenderer.AppWrapper, + }); + + await waitFor(() => expect(findMaintenanceWindows).toHaveBeenCalledTimes(0)); + }); }); diff --git a/x-pack/plugins/alerting/public/hooks/use_find_maintenance_windows.ts b/x-pack/plugins/alerting/public/hooks/use_find_maintenance_windows.ts index 10b7f3402aca1..ab36720e893a5 100644 --- a/x-pack/plugins/alerting/public/hooks/use_find_maintenance_windows.ts +++ b/x-pack/plugins/alerting/public/hooks/use_find_maintenance_windows.ts @@ -10,7 +10,13 @@ import { useQuery } from '@tanstack/react-query'; import { useKibana } from '../utils/kibana_react'; import { findMaintenanceWindows } from '../services/maintenance_windows_api/find'; -export const useFindMaintenanceWindows = () => { +interface UseFindMaintenanceWindowsProps { + enabled?: boolean; +} + +export const useFindMaintenanceWindows = (props?: UseFindMaintenanceWindowsProps) => { + const { enabled = true } = props || {}; + const { http, notifications: { toasts }, @@ -32,6 +38,7 @@ export const useFindMaintenanceWindows = () => { const { isLoading, + isFetching, data = [], refetch, } = useQuery({ @@ -41,11 +48,12 @@ export const useFindMaintenanceWindows = () => { refetchOnWindowFocus: false, retry: false, cacheTime: 0, + enabled, }); return { maintenanceWindows: data, - isLoading, + isLoading: enabled && (isLoading || isFetching), refetch, }; }; diff --git a/x-pack/plugins/alerting/public/pages/maintenance_windows/components/license_prompt.tsx b/x-pack/plugins/alerting/public/pages/maintenance_windows/components/license_prompt.tsx index 4d1b0588fda4a..c7c6a41cf7e93 100644 --- a/x-pack/plugins/alerting/public/pages/maintenance_windows/components/license_prompt.tsx +++ b/x-pack/plugins/alerting/public/pages/maintenance_windows/components/license_prompt.tsx @@ -44,7 +44,6 @@ export const LicensePrompt = React.memo(() => { > {i18n.UPGRADE_SUBSCRIPTION} - , { > {i18n.START_TRIAL} - , diff --git a/x-pack/plugins/alerting/public/pages/maintenance_windows/index.tsx b/x-pack/plugins/alerting/public/pages/maintenance_windows/index.tsx index 5eae620c5a3e5..052fe5d271ec5 100644 --- a/x-pack/plugins/alerting/public/pages/maintenance_windows/index.tsx +++ b/x-pack/plugins/alerting/public/pages/maintenance_windows/index.tsx @@ -37,10 +37,13 @@ export const MaintenanceWindowsPage = React.memo(() => { docLinks, } = useKibana().services; const { isAtLeastPlatinum } = useLicense(); + const hasLicense = isAtLeastPlatinum(); const { navigateToCreateMaintenanceWindow } = useCreateMaintenanceWindowNavigation(); - const { isLoading, maintenanceWindows, refetch } = useFindMaintenanceWindows(); + const { isLoading, maintenanceWindows, refetch } = useFindMaintenanceWindows({ + enabled: hasLicense, + }); useBreadcrumbs(AlertingDeepLinkId.maintenanceWindows); @@ -56,7 +59,6 @@ export const MaintenanceWindowsPage = React.memo(() => { maintenanceWindows.length === 0 && showWindowMaintenance && writeWindowMaintenance; - const hasLicense = isAtLeastPlatinum(); const readOnly = showWindowMaintenance && !writeWindowMaintenance;