mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Infra + Logs UI] Handle absence of the spaces plugin (#46241)
This fixes the Infra and Logs UIs to keep functioning without the spaces plugin enabled. In those cases the assumed space id is `default`. That way all saved objects and ML jobs created while the spaces plugin is absent should show up in the default space if the spaces plugin is added after the fact. fixes #46226
This commit is contained in:
parent
cbe9161eb5
commit
cb15c58e1a
4 changed files with 54 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,26 @@
|
|||
/*
|
||||
* 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 { fold } from 'fp-ts/lib/Either';
|
||||
import { pipe } from 'fp-ts/lib/pipeable';
|
||||
import * as rt from 'io-ts';
|
||||
|
||||
import { useKibanaInjectedVar } from './use_kibana_injected_var';
|
||||
|
||||
export const useKibanaSpaceId = (): string => {
|
||||
const activeSpace = useKibanaInjectedVar('activeSpace');
|
||||
|
||||
return pipe(
|
||||
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