mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[7.4] [Infra + Logs UI] Handle absence of the spaces plugin (#… (#46345)
Backports the following commits to 7.4: - [Infra + Logs UI] Handle absence of the spaces plugin (#46241)
This commit is contained in:
parent
22743ff643
commit
0c241e1be0
4 changed files with 51 additions and 3 deletions
|
@ -5,14 +5,14 @@
|
|||
*/
|
||||
|
||||
import React, { useContext } from 'react';
|
||||
import chrome from 'ui/chrome';
|
||||
|
||||
import { LogAnalysisJobs } from '../../../containers/logs/log_analysis';
|
||||
import { Source } from '../../../containers/source';
|
||||
import { useKibanaSpaceId } from '../../../utils/use_kibana_space_id';
|
||||
|
||||
export const AnalysisPageProviders: React.FunctionComponent = ({ children }) => {
|
||||
const { sourceId, source } = useContext(Source.Context);
|
||||
const spaceId = chrome.getInjected('activeSpace').space.id;
|
||||
const spaceId = useKibanaSpaceId();
|
||||
|
||||
return (
|
||||
<LogAnalysisJobs.Provider
|
||||
|
|
|
@ -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);
|
||||
};
|
|
@ -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,
|
||||
}),
|
||||
});
|
|
@ -153,7 +153,13 @@ export class InfraKibanaBackendFrameworkAdapter implements InfraBackendFramework
|
|||
}
|
||||
|
||||
public getSpaceId(request: InfraFrameworkRequest): string {
|
||||
return this.server.plugins.spaces.getSpaceId(request[internalInfraFrameworkRequest]);
|
||||
const spacesPlugin = this.server.plugins.spaces;
|
||||
|
||||
if (spacesPlugin && typeof spacesPlugin.getSpaceId === 'function') {
|
||||
return spacesPlugin.getSpaceId(request[internalInfraFrameworkRequest]);
|
||||
} else {
|
||||
return 'default';
|
||||
}
|
||||
}
|
||||
|
||||
public getSavedObjectsService() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue