-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RAM] Move maintenance window callout to @kbn/alerts-ui-shared package (
#160678) ## Summary Moves the Security Solution's `MaintenanceWindowCallout` into a shared KBN package to make it more accessible by other plugins. ### Checklist - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
bcb1649
commit 0dc7312
Showing
16 changed files
with
289 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/kbn-alerts-ui-shared/src/maintenance_window_callout/api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { KibanaServices } from './types'; | ||
|
||
export const fetchActiveMaintenanceWindows = async ( | ||
http: KibanaServices['http'], | ||
signal?: AbortSignal | ||
) => | ||
http.fetch(INTERNAL_ALERTING_API_GET_ACTIVE_MAINTENANCE_WINDOWS_PATH, { | ||
method: 'GET', | ||
signal, | ||
}); | ||
|
||
const INTERNAL_ALERTING_API_GET_ACTIVE_MAINTENANCE_WINDOWS_PATH = `/internal/alerting/rules/maintenance_window/_active`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
packages/kbn-alerts-ui-shared/src/maintenance_window_callout/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { EuiCallOut } from '@elastic/eui'; | ||
import { MaintenanceWindow, MaintenanceWindowStatus, KibanaServices } from './types'; | ||
import { useFetchActiveMaintenanceWindows } from './use_fetch_active_maintenance_windows'; | ||
|
||
const MAINTENANCE_WINDOW_FEATURE_ID = 'maintenanceWindow'; | ||
const MAINTENANCE_WINDOW_RUNNING = i18n.translate( | ||
'alertsUIShared.maintenanceWindowCallout.maintenanceWindowActive', | ||
{ | ||
defaultMessage: 'Maintenance window is running', | ||
} | ||
); | ||
const MAINTENANCE_WINDOW_RUNNING_DESCRIPTION = i18n.translate( | ||
'alertsUIShared.maintenanceWindowCallout.maintenanceWindowActiveDescription', | ||
{ | ||
defaultMessage: 'Rule notifications are stopped while the maintenance window is running.', | ||
} | ||
); | ||
|
||
export function MaintenanceWindowCallout({ | ||
kibanaServices, | ||
}: { | ||
kibanaServices: KibanaServices; | ||
}): JSX.Element | null { | ||
const { | ||
application: { capabilities }, | ||
} = kibanaServices; | ||
|
||
const isMaintenanceWindowDisabled = | ||
!capabilities[MAINTENANCE_WINDOW_FEATURE_ID].show && | ||
!capabilities[MAINTENANCE_WINDOW_FEATURE_ID].save; | ||
const { data } = useFetchActiveMaintenanceWindows(kibanaServices, { | ||
enabled: !isMaintenanceWindowDisabled, | ||
}); | ||
|
||
if (isMaintenanceWindowDisabled) { | ||
return null; | ||
} | ||
|
||
const activeMaintenanceWindows = (data as MaintenanceWindow[]) || []; | ||
|
||
if (activeMaintenanceWindows.some(({ status }) => status === MaintenanceWindowStatus.Running)) { | ||
return ( | ||
<EuiCallOut title={MAINTENANCE_WINDOW_RUNNING} color="warning" iconType="iInCircle"> | ||
{MAINTENANCE_WINDOW_RUNNING_DESCRIPTION} | ||
</EuiCallOut> | ||
); | ||
} | ||
|
||
return null; | ||
} |
Oops, something went wrong.