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.
[7.4] [Infra + Logs UI] Handle absence of the spaces plugin (#… (elas…
…tic#46345) Backports the following commits to 7.4: - [Infra + Logs UI] Handle absence of the spaces plugin (elastic#46241)
- Loading branch information
1 parent
22743ff
commit 0c241e1
Showing
4 changed files
with
51 additions
and
3 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
19 changes: 19 additions & 0 deletions
19
x-pack/legacy/plugins/infra/public/utils/use_kibana_injected_var.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,19 @@ | ||
/* | ||
* 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 { npSetup } from 'ui/new_platform'; | ||
|
||
/** | ||
* This hook provides access to the "injected variables" provided by the | ||
* platform. While it doesn't need to be a hook right now, it has been written | ||
* as one in order to keep the API stable despite the upcoming injection | ||
* through the context after the new platform migration. | ||
*/ | ||
export const useKibanaInjectedVar = (name: string, defaultValue?: unknown) => { | ||
const injectedMetadata = npSetup.core.injectedMetadata; | ||
|
||
return injectedMetadata.getInjectedVar(name, defaultValue); | ||
}; |
23 changes: 23 additions & 0 deletions
23
x-pack/legacy/plugins/infra/public/utils/use_kibana_space_id.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,23 @@ | ||
/* | ||
* 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 * as rt from 'io-ts'; | ||
|
||
import { useKibanaInjectedVar } from './use_kibana_injected_var'; | ||
|
||
export const useKibanaSpaceId = (): string => { | ||
const activeSpace = useKibanaInjectedVar('activeSpace'); | ||
|
||
return activeSpaceRT | ||
.decode(activeSpace) | ||
.fold(() => 'default', decodedActiveSpace => decodedActiveSpace.space.id); | ||
}; | ||
|
||
const activeSpaceRT = rt.type({ | ||
space: rt.type({ | ||
id: rt.string, | ||
}), | ||
}); |
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