Skip to content

Commit c2c262c

Browse files
[SIEM] Adds ability to infer the newsfeed.enabled setting (#56236) (#56265)
* Always return a contract from the newsfeed plugin Without a contract, dependent plugins have no way of knowing whether the plugin is enabled or not as the contract will always be undefined. * Export newsfeed contract types from public index So that dependent plugins can use them. * Declare newsfeed as an optional dependency of SIEM We're going to use the availability of the newsfeed plugin as part of our determination for whether or not to show the security newsfeed. If users set `newsfeed.enabled: false`, the plugin will be unavailable and the security feed will not be shown. * Respect global newsfeed.enabled config in Security newsfeed The presence of the newsfeed plugin means that newsfeed.enabled is true. If both that and our local setting are true, we will show the Security feed. * Prefer object type over empty interface Co-authored-by: Elastic Machine <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
1 parent 4eb0516 commit c2c262c

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

src/plugins/newsfeed/public/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
*/
1919

2020
import { PluginInitializerContext } from 'src/core/public';
21-
import { NewsfeedPublicPlugin } from './plugin';
21+
import { Setup, Start, NewsfeedPublicPlugin } from './plugin';
22+
23+
export { Setup, Start };
2224

2325
export function plugin(initializerContext: PluginInitializerContext) {
2426
return new NewsfeedPublicPlugin(initializerContext);

src/plugins/newsfeed/public/plugin.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import { FetchResult, NewsfeedPluginInjectedConfig } from '../types';
2727
import { NewsfeedNavButton, NewsfeedApiFetchResult } from './components/newsfeed_header_nav_button';
2828
import { getApi } from './lib/api';
2929

30-
export type Setup = void;
31-
export type Start = void;
30+
export type Setup = object;
31+
export type Start = object;
3232

3333
export class NewsfeedPublicPlugin implements Plugin<Setup, Start> {
3434
private readonly kibanaVersion: string;
@@ -38,14 +38,18 @@ export class NewsfeedPublicPlugin implements Plugin<Setup, Start> {
3838
this.kibanaVersion = initializerContext.env.packageInfo.version;
3939
}
4040

41-
public setup(core: CoreSetup): Setup {}
41+
public setup(core: CoreSetup): Setup {
42+
return {};
43+
}
4244

4345
public start(core: CoreStart): Start {
4446
const api$ = this.fetchNewsfeed(core);
4547
core.chrome.navControls.registerRight({
4648
order: 1000,
4749
mount: target => this.mount(api$, target),
4850
});
51+
52+
return {};
4953
}
5054

5155
public stop() {

x-pack/legacy/plugins/siem/public/components/news_feed/index.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,22 @@ import React, { useEffect, useState } from 'react';
88
import chrome from 'ui/chrome';
99

1010
import { fetchNews, getNewsFeedUrl, getNewsItemsFromApiResponse } from './helpers';
11-
import { useUiSetting$ } from '../../lib/kibana';
11+
import { useKibana, useUiSetting$ } from '../../lib/kibana';
1212
import { NewsFeed } from './news_feed';
1313
import { NewsItem } from './types';
1414

1515
export const StatefulNewsFeed = React.memo<{
1616
enableNewsFeedSetting: string;
1717
newsFeedSetting: string;
1818
}>(({ enableNewsFeedSetting, newsFeedSetting }) => {
19+
const kibanaNewsfeedEnabled = useKibana().services.newsfeed;
1920
const [enableNewsFeed] = useUiSetting$<boolean>(enableNewsFeedSetting);
2021
const [newsFeedUrlSetting] = useUiSetting$<string>(newsFeedSetting);
2122
const [news, setNews] = useState<NewsItem[] | null>(null);
2223

24+
// respect kibana's global newsfeed.enabled setting
25+
const newsfeedEnabled = kibanaNewsfeedEnabled && enableNewsFeed;
26+
2327
const newsFeedUrl = getNewsFeedUrl({
2428
newsFeedUrlSetting,
2529
getKibanaVersion: chrome.getKibanaVersion,
@@ -42,16 +46,16 @@ export const StatefulNewsFeed = React.memo<{
4246
}
4347
};
4448

45-
if (enableNewsFeed) {
49+
if (newsfeedEnabled) {
4650
fetchData();
4751
}
4852

4953
return () => {
5054
canceled = true;
5155
};
52-
}, [enableNewsFeed, newsFeedUrl]);
56+
}, [newsfeedEnabled, newsFeedUrl]);
5357

54-
return <>{enableNewsFeed ? <NewsFeed news={news} /> : null}</>;
58+
return <>{newsfeedEnabled ? <NewsFeed news={news} /> : null}</>;
5559
});
5660

5761
StatefulNewsFeed.displayName = 'StatefulNewsFeed';

x-pack/legacy/plugins/siem/public/plugin.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
import { HomePublicPluginSetup } from '../../../../../src/plugins/home/public';
1515
import { DataPublicPluginStart } from '../../../../../src/plugins/data/public';
1616
import { IEmbeddableStart } from '../../../../../src/plugins/embeddable/public';
17+
import { Start as NewsfeedStart } from '../../../../../src/plugins/newsfeed/public';
1718
import { Start as InspectorStart } from '../../../../../src/plugins/inspector/public';
1819
import { IUiActionsStart } from '../../../../../src/plugins/ui_actions/public';
1920
import { UsageCollectionSetup } from '../../../../../src/plugins/usage_collection/public';
@@ -29,6 +30,7 @@ export interface StartPlugins {
2930
data: DataPublicPluginStart;
3031
embeddable: IEmbeddableStart;
3132
inspector: InspectorStart;
33+
newsfeed?: NewsfeedStart;
3234
uiActions: IUiActionsStart;
3335
}
3436
export type StartServices = CoreStart & StartPlugins;

0 commit comments

Comments
 (0)