-
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.
[Logs UI] Replace deprecated getInjectedVar with NP spaces API (#74280)…
… (#74517) * Replace getInjectedVar() with NP spaces API * Fix typo in comment * Fix typo in comment Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
- Loading branch information
1 parent
462b9a6
commit 62cce80
Showing
8 changed files
with
117 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* 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 { CoreStart } from '../../../../../src/core/public'; | ||
import { | ||
createKibanaReactContext, | ||
KibanaReactContextValue, | ||
useKibana, | ||
} from '../../../../../src/plugins/kibana_react/public'; | ||
import { InfraClientStartDeps } from '../types'; | ||
|
||
export type PluginKibanaContextValue = CoreStart & InfraClientStartDeps; | ||
|
||
export const createKibanaContextForPlugin = (core: CoreStart, pluginsStart: InfraClientStartDeps) => | ||
createKibanaReactContext<PluginKibanaContextValue>({ | ||
...core, | ||
...pluginsStart, | ||
}); | ||
|
||
export const useKibanaContextForPlugin = useKibana as () => KibanaReactContextValue< | ||
PluginKibanaContextValue | ||
>; |
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,40 @@ | ||
/* | ||
* 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 { useAsync } from 'react-use'; | ||
import { useKibanaContextForPlugin } from '../hooks/use_kibana'; | ||
import type { Space } from '../../../spaces/public'; | ||
|
||
export type ActiveSpace = | ||
| { isLoading: true; error: undefined; space: undefined } | ||
| { isLoading: false; error: Error; space: undefined } | ||
| { isLoading: false; error: undefined; space: Space }; | ||
|
||
export const useActiveKibanaSpace = (): ActiveSpace => { | ||
const kibana = useKibanaContextForPlugin(); | ||
|
||
const asyncActiveSpace = useAsync(kibana.services.spaces.getActiveSpace); | ||
|
||
if (asyncActiveSpace.loading) { | ||
return { | ||
isLoading: true, | ||
error: undefined, | ||
space: undefined, | ||
}; | ||
} else if (asyncActiveSpace.error) { | ||
return { | ||
isLoading: false, | ||
error: asyncActiveSpace.error, | ||
space: undefined, | ||
}; | ||
} else { | ||
return { | ||
isLoading: false, | ||
error: undefined, | ||
space: asyncActiveSpace.value!, | ||
}; | ||
} | ||
}; |
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 was deleted.
Oops, something went wrong.