Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SIEM] Adds ability to infer the newsfeed.enabled setting #56236

Merged
merged 6 commits into from
Jan 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/plugins/newsfeed/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
*/

import { PluginInitializerContext } from 'src/core/public';
import { NewsfeedPublicPlugin } from './plugin';
import { Setup, Start, NewsfeedPublicPlugin } from './plugin';

export { Setup, Start };

export function plugin(initializerContext: PluginInitializerContext) {
return new NewsfeedPublicPlugin(initializerContext);
Expand Down
10 changes: 7 additions & 3 deletions src/plugins/newsfeed/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import { FetchResult, NewsfeedPluginInjectedConfig } from '../types';
import { NewsfeedNavButton, NewsfeedApiFetchResult } from './components/newsfeed_header_nav_button';
import { getApi } from './lib/api';

export type Setup = void;
export type Start = void;
export type Setup = object;
export type Start = object;

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

public setup(core: CoreSetup): Setup {}
public setup(core: CoreSetup): Setup {
return {};
}

public start(core: CoreStart): Start {
const api$ = this.fetchNewsfeed(core);
core.chrome.navControls.registerRight({
order: 1000,
mount: target => this.mount(api$, target),
});

return {};
}

public stop() {
Expand Down
12 changes: 8 additions & 4 deletions x-pack/legacy/plugins/siem/public/components/news_feed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@ import React, { useEffect, useState } from 'react';
import chrome from 'ui/chrome';

import { fetchNews, getNewsFeedUrl, getNewsItemsFromApiResponse } from './helpers';
import { useUiSetting$ } from '../../lib/kibana';
import { useKibana, useUiSetting$ } from '../../lib/kibana';
import { NewsFeed } from './news_feed';
import { NewsItem } from './types';

export const StatefulNewsFeed = React.memo<{
enableNewsFeedSetting: string;
newsFeedSetting: string;
}>(({ enableNewsFeedSetting, newsFeedSetting }) => {
const kibanaNewsfeedEnabled = useKibana().services.newsfeed;
const [enableNewsFeed] = useUiSetting$<boolean>(enableNewsFeedSetting);
const [newsFeedUrlSetting] = useUiSetting$<string>(newsFeedSetting);
const [news, setNews] = useState<NewsItem[] | null>(null);

// respect kibana's global newsfeed.enabled setting
const newsfeedEnabled = kibanaNewsfeedEnabled && enableNewsFeed;

const newsFeedUrl = getNewsFeedUrl({
newsFeedUrlSetting,
getKibanaVersion: chrome.getKibanaVersion,
Expand All @@ -42,16 +46,16 @@ export const StatefulNewsFeed = React.memo<{
}
};

if (enableNewsFeed) {
if (newsfeedEnabled) {
fetchData();
}

return () => {
canceled = true;
};
}, [enableNewsFeed, newsFeedUrl]);
}, [newsfeedEnabled, newsFeedUrl]);

return <>{enableNewsFeed ? <NewsFeed news={news} /> : null}</>;
return <>{newsfeedEnabled ? <NewsFeed news={news} /> : null}</>;
});

StatefulNewsFeed.displayName = 'StatefulNewsFeed';
2 changes: 2 additions & 0 deletions x-pack/legacy/plugins/siem/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { HomePublicPluginSetup } from '../../../../../src/plugins/home/public';
import { DataPublicPluginStart } from '../../../../../src/plugins/data/public';
import { IEmbeddableStart } from '../../../../../src/plugins/embeddable/public';
import { Start as NewsfeedStart } from '../../../../../src/plugins/newsfeed/public';
import { Start as InspectorStart } from '../../../../../src/plugins/inspector/public';
import { IUiActionsStart } from '../../../../../src/plugins/ui_actions/public';
import { UsageCollectionSetup } from '../../../../../src/plugins/usage_collection/public';
Expand All @@ -29,6 +30,7 @@ export interface StartPlugins {
data: DataPublicPluginStart;
embeddable: IEmbeddableStart;
inspector: InspectorStart;
newsfeed?: NewsfeedStart;
uiActions: IUiActionsStart;
}
export type StartServices = CoreStart & StartPlugins;
Expand Down