forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fleet] Better display of fleet requirements (elastic#65027)
- Loading branch information
Showing
22 changed files
with
309 additions
and
91 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
69 changes: 69 additions & 0 deletions
69
x-pack/plugins/ingest_manager/public/applications/ingest_manager/hooks/use_fleet_status.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,69 @@ | ||
/* | ||
* 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, { useState, useContext, useEffect } from 'react'; | ||
import { useConfig } from './use_config'; | ||
import { sendGetFleetStatus } from './use_request'; | ||
import { GetFleetStatusResponse } from '../types'; | ||
|
||
interface FleetStatusState { | ||
enabled: boolean; | ||
isLoading: boolean; | ||
isReady: boolean; | ||
missingRequirements?: GetFleetStatusResponse['missing_requirements']; | ||
} | ||
|
||
interface FleetStatus extends FleetStatusState { | ||
refresh: () => Promise<void>; | ||
} | ||
|
||
const FleetStatusContext = React.createContext<FleetStatus | undefined>(undefined); | ||
|
||
export const FleetStatusProvider: React.FC = ({ children }) => { | ||
const config = useConfig(); | ||
const [state, setState] = useState<FleetStatusState>({ | ||
enabled: config.fleet.enabled, | ||
isLoading: false, | ||
isReady: false, | ||
}); | ||
async function sendGetStatus() { | ||
try { | ||
setState(s => ({ ...s, isLoading: true })); | ||
const res = await sendGetFleetStatus(); | ||
if (res.error) { | ||
throw res.error; | ||
} | ||
|
||
setState(s => ({ | ||
...s, | ||
isLoading: false, | ||
isReady: res.data?.isReady ?? false, | ||
missingRequirements: res.data?.missing_requirements, | ||
})); | ||
} catch (error) { | ||
setState(s => ({ ...s, isLoading: true })); | ||
} | ||
} | ||
useEffect(() => { | ||
sendGetStatus(); | ||
}, []); | ||
|
||
return ( | ||
<FleetStatusContext.Provider value={{ ...state, refresh: () => sendGetStatus() }}> | ||
{children} | ||
</FleetStatusContext.Provider> | ||
); | ||
}; | ||
|
||
export function useFleetStatus(): FleetStatus { | ||
const context = useContext(FleetStatusContext); | ||
|
||
if (!context) { | ||
throw new Error('FleetStatusContext not set'); | ||
} | ||
|
||
return context; | ||
} |
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
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.