Skip to content

Commit

Permalink
Merge branch 'main' of github.com:elastic/kibana into remove_bfetch
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasolson committed Dec 10, 2024
2 parents 3011ee9 + c787e41 commit 28d35d4
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 189 deletions.
46 changes: 1 addition & 45 deletions x-pack/plugins/enterprise_search/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
Logger,
SavedObjectsServiceStart,
IRouter,
KibanaRequest,
DEFAULT_APP_CATEGORIES,
} from '@kbn/core/server';
import { CustomIntegrationsPluginSetup } from '@kbn/custom-integrations-plugin/server';
Expand Down Expand Up @@ -65,7 +64,6 @@ import { registerTelemetryUsageCollector as registerESTelemetryUsageCollector }
import { registerTelemetryUsageCollector as registerWSTelemetryUsageCollector } from './collectors/workplace_search/telemetry';
import { registerEnterpriseSearchIntegrations } from './integrations';

import { checkAccess } from './lib/check_access';
import { entSearchHttpAgent } from './lib/enterprise_search_http_agent';
import {
EnterpriseSearchRequestHandler,
Expand Down Expand Up @@ -141,17 +139,9 @@ export class EnterpriseSearchPlugin implements Plugin {
}

public setup(
{
capabilities,
elasticsearch,
http,
savedObjects,
getStartServices,
uiSettings,
}: CoreSetup<PluginsStart>,
{ elasticsearch, http, savedObjects, getStartServices, uiSettings }: CoreSetup<PluginsStart>,
{
usageCollection,
security,
features,
globalSearch,
logsShared,
Expand Down Expand Up @@ -285,40 +275,6 @@ export class EnterpriseSearchPlugin implements Plugin {
*/
uiSettings.register(enterpriseSearchUISettings);

/**
* Register user access to the Enterprise Search plugins
*/
capabilities.registerSwitcher(
async (request: KibanaRequest) => {
const [, { spaces }] = await getStartServices();

const dependencies = {
config,
security,
spaces,
request,
log,
ml,
};

const { hasAppSearchAccess, hasWorkplaceSearchAccess } = await checkAccess(dependencies);

return {
navLinks: {
appSearch: hasAppSearchAccess && config.canDeployEntSearch,
workplaceSearch: hasWorkplaceSearchAccess && config.canDeployEntSearch,
},
catalogue: {
appSearch: hasAppSearchAccess && config.canDeployEntSearch,
workplaceSearch: hasWorkplaceSearchAccess && config.canDeployEntSearch,
},
};
},
{
capabilityPath: ['navLinks.*', 'catalogue.*'],
}
);

/**
* Register routes
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { EuiLoadingSpinner, EuiFlexItem } from '@elastic/eui';
import { EuiFlexItem } from '@elastic/eui';
import { css } from '@emotion/css';
import { ReactEmbeddableRenderer } from '@kbn/embeddable-plugin/public';
import type { GlobalWidgetParameters } from '@kbn/investigate-plugin/public';
import { useAbortableAsync } from '@kbn/observability-utils-browser/hooks/use_abortable_async';
import React, { useEffect, useMemo, useRef, useState } from 'react';
import { v4 } from 'uuid';
import { ErrorMessage } from '../../components/error_message';
import { useKibana } from '../../hooks/use_kibana';
import React, { useMemo, useRef } from 'react';
import { Options } from '../register_items';

export const EMBEDDABLE_ITEM_TYPE = 'embeddable';
Expand Down Expand Up @@ -62,101 +58,6 @@ function ReactEmbeddable({ type, config, timeRange: { from, to }, savedObjectId
);
}

function LegacyEmbeddable({ type, config, timeRange: { from, to }, savedObjectId }: Props) {
const {
dependencies: {
start: { embeddable },
},
} = useKibana();

const [targetElement, setTargetElement] = useState<HTMLElement | null>(null);

const embeddableInstanceAsync = useAbortableAsync(async () => {
const factory = embeddable.getEmbeddableFactory(type);

if (!factory) {
throw new Error(`Cannot find embeddable factory for ${type}`);
}

const configWithId = {
id: savedObjectId ?? v4(),
...config,
};

const configWithOverrides = {
...configWithId,
timeRange: {
from,
to,
},
overrides: {
axisX: { hide: true },
axisLeft: { style: { axisTitle: { visible: false } } },
settings: { showLegend: false },
},
};

if (savedObjectId) {
return factory.createFromSavedObject(configWithOverrides.id, configWithOverrides);
}

const instance = await factory.create(configWithOverrides);

return instance;
}, [type, savedObjectId, config, from, to, embeddable]);

const embeddableInstance = embeddableInstanceAsync.value;

useEffect(() => {
if (!targetElement || !embeddableInstance) {
return;
}

embeddableInstance.render(targetElement);

return () => {};
}, [embeddableInstance, targetElement]);

useEffect(() => {
return () => {
if (embeddableInstance) {
embeddableInstance.destroy();
}
};
}, [embeddableInstance]);

if (embeddableInstanceAsync.error) {
return <ErrorMessage error={embeddableInstanceAsync.error} />;
}

if (!embeddableInstance) {
return <EuiLoadingSpinner />;
}

return (
<div
className={embeddableClassName}
ref={(element) => {
setTargetElement(element);
}}
/>
);
}

function EmbeddableWidget(props: Props) {
const {
dependencies: {
start: { embeddable },
},
} = useKibana();

if (embeddable.reactEmbeddableRegistryHasKey(props.type)) {
return <ReactEmbeddable {...props} />;
}

return <LegacyEmbeddable {...props} />;
}

interface EmbeddableItemParams {
type: string;
config: Record<string, any>;
Expand Down Expand Up @@ -197,7 +98,7 @@ export function registerEmbeddableItem({
}
`}
>
<EmbeddableWidget {...parameters} />
<ReactEmbeddable {...parameters} />
</EuiFlexItem>
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function StreamDetailManagement({
);
}

if (!definition?.managed) {
if (definition && !definition.managed) {
return (
<RedirectTo
path="/{key}/management/{subtab}"
Expand Down
3 changes: 2 additions & 1 deletion x-pack/test/functional/apps/infra/node_details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,8 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
});
});

describe('Processes Tab', () => {
// FLAKY: https://github.com/elastic/kibana/issues/192891
describe.skip('Processes Tab', () => {
before(async () => {
await esArchiver.load('x-pack/test/functional/es_archives/infra/metrics_hosts_processes');
await esArchiver.load('x-pack/test/functional/es_archives/infra/metrics_and_logs');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,9 @@ export default function catalogueTests({ getService }: FtrProviderContext) {
case 'everything_space_all at everything_space': {
expect(uiCapabilities.success).to.be(true);
expect(uiCapabilities.value).to.have.property('catalogue');
// everything except spaces, monitoring, the classic enterprise search suite (app search/workplace search), and ES features are enabled
// everything except spaces, monitoring, and ES features are enabled
// (easier to say: all "proper" Kibana features are enabled)
const exceptions = [
'monitoring',
'appSearch',
'workplaceSearch',
'spaces',
...esFeatureExceptions,
];
const exceptions = ['monitoring', 'spaces', ...esFeatureExceptions];
const expected = mapValues(
uiCapabilities.value!.catalogue,
(enabled, catalogueId) => !exceptions.includes(catalogueId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,7 @@ export default function navLinksTests({ getService }: FtrProviderContext) {
case 'everything_space_all at everything_space':
expect(uiCapabilities.success).to.be(true);
expect(uiCapabilities.value).to.have.property('navLinks');
expect(uiCapabilities.value!.navLinks).to.eql(
navLinksBuilder.except('monitoring', {
feature: 'enterpriseSearch',
apps: ['appSearch', 'workplaceSearch'],
})
);
expect(uiCapabilities.value!.navLinks).to.eql(navLinksBuilder.except('monitoring'));
break;
case 'global_read at everything_space':
case 'dual_privileges_read at everything_space':
Expand Down
15 changes: 2 additions & 13 deletions x-pack/test/ui_capabilities/spaces_only/tests/catalogue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ export default function catalogueTests({ getService }: FtrProviderContext) {
'watcher',
];

const uiCapabilitiesExceptions = [
// appSearch and workplace Search are loaded but disabled because the ent-search application isn't running.
// That means the following capabilities are disabled:
'appSearch',
'workplaceSearch',
];

describe('catalogue', () => {
SpaceScenarios.forEach((scenario) => {
it(`${scenario.name}`, async () => {
Expand All @@ -41,10 +34,7 @@ export default function catalogueTests({ getService }: FtrProviderContext) {
expect(uiCapabilities.success).to.be(true);
expect(uiCapabilities.value).to.have.property('catalogue');
// everything is enabled
const expected = mapValues(
uiCapabilities.value!.catalogue,
(enabled, catalogueId) => !uiCapabilitiesExceptions.includes(catalogueId)
);
const expected = mapValues(uiCapabilities.value!.catalogue, (enabled) => enabled);
expect(uiCapabilities.value!.catalogue).to.eql(expected);
break;
}
Expand All @@ -66,8 +56,7 @@ export default function catalogueTests({ getService }: FtrProviderContext) {
// only foo is disabled
const expected = mapValues(
uiCapabilities.value!.catalogue,
(enabled, catalogueId) =>
!uiCapabilitiesExceptions.includes(catalogueId) && catalogueId !== 'foo'
(enabled, catalogueId) => catalogueId !== 'foo' && enabled
);
expect(uiCapabilities.value!.catalogue).to.eql(expected);
break;
Expand Down
15 changes: 2 additions & 13 deletions x-pack/test/ui_capabilities/spaces_only/tests/nav_links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ export default function navLinksTests({ getService }: FtrProviderContext) {
const uiCapabilitiesService: UICapabilitiesService = getService('uiCapabilities');
const featuresService: FeaturesService = getService('features');

const uiCapabilitiesExceptions = {
// appSearch and workplace Search are loaded but disabled because the ent-search application isn't running.
// That means the following capabilities are disabled:
feature: 'enterpriseSearch',
apps: ['appSearch', 'workplaceSearch'],
};

describe('navLinks', () => {
let navLinksBuilder: NavLinksBuilder;
before(async () => {
Expand All @@ -38,9 +31,7 @@ export default function navLinksTests({ getService }: FtrProviderContext) {
case 'everything_space':
expect(uiCapabilities.success).to.be(true);
expect(uiCapabilities.value).to.have.property('navLinks');
expect(uiCapabilities.value!.navLinks).to.eql(
navLinksBuilder.except(uiCapabilitiesExceptions)
);
expect(uiCapabilities.value!.navLinks).to.eql(navLinksBuilder.all());
break;
case 'nothing_space':
expect(uiCapabilities.success).to.be(true);
Expand All @@ -50,9 +41,7 @@ export default function navLinksTests({ getService }: FtrProviderContext) {
case 'foo_disabled_space':
expect(uiCapabilities.success).to.be(true);
expect(uiCapabilities.value).to.have.property('navLinks');
expect(uiCapabilities.value!.navLinks).to.eql(
navLinksBuilder.except('foo', uiCapabilitiesExceptions)
);
expect(uiCapabilities.value!.navLinks).to.eql(navLinksBuilder.except('foo'));
break;
default:
throw new UnreachableError(scenario);
Expand Down

0 comments on commit 28d35d4

Please sign in to comment.