-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Alerting UI] Don't wait for health check before showing Create Alert…
… flyout (#80996) * wip * Adding health context provider and option to block waiting for health check * Adding tests * Removing forced lag * Fixing action form not rendering pre selected action * PR fixes * Updating i18n ids Co-authored-by: Mike Côté <[email protected]> * Applying i18n fix Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Mike Côté <[email protected]>
- Loading branch information
1 parent
ac640f1
commit 7e34bf2
Showing
10 changed files
with
282 additions
and
149 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
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
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
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
45 changes: 45 additions & 0 deletions
45
x-pack/plugins/triggers_actions_ui/public/application/context/health_context.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,45 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { createContext, useCallback, useContext, useMemo, useState } from 'react'; | ||
|
||
export interface HealthContextValue { | ||
loadingHealthCheck: boolean; | ||
setLoadingHealthCheck: (loading: boolean) => void; | ||
} | ||
|
||
const defaultHealthContext: HealthContextValue = { | ||
loadingHealthCheck: false, | ||
setLoadingHealthCheck: (loading: boolean) => { | ||
throw new Error( | ||
'setLoadingHealthCheck was not initialized, set it when you invoke the context' | ||
); | ||
}, | ||
}; | ||
|
||
const HealthContext = createContext<HealthContextValue>(defaultHealthContext); | ||
|
||
export const HealthContextProvider = ({ children }: { children: React.ReactNode }) => { | ||
const [loading, setLoading] = useState<boolean>(false); | ||
|
||
const setLoadingHealthCheck = useCallback((isLoading: boolean) => { | ||
setLoading(isLoading); | ||
}, []); | ||
|
||
const value = useMemo(() => { | ||
return { loadingHealthCheck: loading, setLoadingHealthCheck }; | ||
}, [loading, setLoadingHealthCheck]); | ||
|
||
return <HealthContext.Provider value={value}>{children}</HealthContext.Provider>; | ||
}; | ||
|
||
export const useHealthContext = () => { | ||
const ctx = useContext(HealthContext); | ||
if (!ctx) { | ||
throw new Error('HealthContext has not been set.'); | ||
} | ||
return ctx; | ||
}; |
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
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
Oops, something went wrong.