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

Remove Newsfeed leftovers from the Legacy codebase #66084

Merged
merged 7 commits into from
May 13, 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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
/packages/kbn-analytics/ @elastic/pulse
/src/legacy/core_plugins/ui_metric/ @elastic/pulse
/src/plugins/kibana_usage_collection/ @elastic/pulse
/src/plugins/newsfeed/ @elastic/pulse
/src/plugins/telemetry/ @elastic/pulse
/src/plugins/telemetry_collection_manager/ @elastic/pulse
/src/plugins/telemetry_management_section/ @elastic/pulse
Expand Down
71 changes: 0 additions & 71 deletions src/legacy/core_plugins/newsfeed/index.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/legacy/core_plugins/newsfeed/package.json

This file was deleted.

3 changes: 0 additions & 3 deletions src/legacy/core_plugins/newsfeed/public/index.scss

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,10 @@
* under the License.
*/

import Hapi from 'hapi';
import { initPlugin as initNewsfeed } from './newsfeed_simulation';
export const NEWSFEED_FALLBACK_LANGUAGE = 'en';
export const NEWSFEED_LAST_FETCH_STORAGE_KEY = 'newsfeed.lastfetchtime';
export const NEWSFEED_HASH_SET_STORAGE_KEY = 'newsfeed.hashes';

const NAME = 'newsfeed-FTS-external-service-simulators';

// eslint-disable-next-line import/no-default-export
export default function(kibana: any) {
return new kibana.Plugin({
name: NAME,
init: (server: Hapi.Server) => {
initNewsfeed(server, `/api/_${NAME}`);
},
});
}
export const NEWSFEED_DEFAULT_SERVICE_BASE_URL = 'https://feeds.elastic.co';
export const NEWSFEED_DEV_SERVICE_BASE_URL = 'https://feeds-staging.elastic.co';
export const NEWSFEED_DEFAULT_SERVICE_PATH = '/kibana/v{VERSION}.json';
2 changes: 1 addition & 1 deletion src/plugins/newsfeed/kibana.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "newsfeed",
"version": "kibana",
"server": false,
"server": true,
"ui": true
}
4 changes: 2 additions & 2 deletions src/plugins/newsfeed/public/components/flyout_list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ import {
EuiButtonEmpty,
EuiText,
EuiBadge,
EuiHeaderAlert,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiHeaderAlert } from '../../../../legacy/core_plugins/newsfeed/public/np_ready/components/header_alert/header_alert';
import { NewsfeedContext } from './newsfeed_header_nav_button';
import { NewsfeedItem } from '../../types';
import { NewsfeedItem } from '../types';
import { NewsEmptyPrompt } from './empty_news';
import { NewsLoadingPrompt } from './loading_news';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import React, { useState, Fragment, useEffect } from 'react';
import * as Rx from 'rxjs';
import { EuiHeaderSectionItemButton, EuiIcon, EuiNotificationBadge } from '@elastic/eui';
import { NewsfeedFlyout } from './flyout_list';
import { FetchResult } from '../../types';
import { FetchResult } from '../types';

export interface INewsfeedContext {
setFlyoutVisible: React.Dispatch<React.SetStateAction<boolean>>;
Expand Down
38 changes: 19 additions & 19 deletions src/plugins/newsfeed/public/lib/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ import { interval, race } from 'rxjs';
import sinon, { stub } from 'sinon';
import moment from 'moment';
import { HttpSetup } from 'src/core/public';
import { NEWSFEED_HASH_SET_STORAGE_KEY, NEWSFEED_LAST_FETCH_STORAGE_KEY } from '../../constants';
import { ApiItem, NewsfeedItem, NewsfeedPluginInjectedConfig } from '../../types';
import {
NEWSFEED_HASH_SET_STORAGE_KEY,
NEWSFEED_LAST_FETCH_STORAGE_KEY,
} from '../../common/constants';
import { ApiItem, NewsfeedItem, NewsfeedPluginBrowserConfig } from '../types';
import { NewsfeedApiDriver, getApi } from './api';

const localStorageGet = sinon.stub();
Expand Down Expand Up @@ -458,23 +461,20 @@ describe('getApi', () => {
}
return Promise.reject('wrong args!');
};
let configMock: NewsfeedPluginInjectedConfig;
let configMock: NewsfeedPluginBrowserConfig;

afterEach(() => {
jest.resetAllMocks();
});

beforeEach(() => {
configMock = {
newsfeed: {
service: {
urlRoot: 'http://fakenews.co',
pathTemplate: '/kibana-test/v{VERSION}.json',
},
defaultLanguage: 'en',
mainInterval: 86400000,
fetchInterval: 86400000,
service: {
urlRoot: 'http://fakenews.co',
pathTemplate: '/kibana-test/v{VERSION}.json',
},
mainInterval: moment.duration(86400000),
fetchInterval: moment.duration(86400000),
};
httpMock = ({
fetch: mockHttpGet,
Expand All @@ -483,7 +483,7 @@ describe('getApi', () => {

it('creates a result', done => {
mockHttpGet.mockImplementationOnce(() => Promise.resolve({ items: [] }));
getApi(httpMock, configMock.newsfeed, '6.8.2').subscribe(result => {
getApi(httpMock, configMock, '6.8.2').subscribe(result => {
expect(result).toMatchInlineSnapshot(`
Object {
"error": null,
Expand Down Expand Up @@ -528,7 +528,7 @@ describe('getApi', () => {

mockHttpGet.mockImplementationOnce(getHttpMockWithItems(mockApiItems));

getApi(httpMock, configMock.newsfeed, '6.8.2').subscribe(result => {
getApi(httpMock, configMock, '6.8.2').subscribe(result => {
expect(result).toMatchInlineSnapshot(`
Object {
"error": null,
Expand Down Expand Up @@ -568,7 +568,7 @@ describe('getApi', () => {
},
];
mockHttpGet.mockImplementationOnce(getHttpMockWithItems(mockApiItems));
getApi(httpMock, configMock.newsfeed, '6.8.2').subscribe(result => {
getApi(httpMock, configMock, '6.8.2').subscribe(result => {
expect(result).toMatchInlineSnapshot(`
Object {
"error": null,
Expand All @@ -595,7 +595,7 @@ describe('getApi', () => {
it('forwards an error', done => {
mockHttpGet.mockImplementationOnce((arg1, arg2) => Promise.reject('sorry, try again later!'));

getApi(httpMock, configMock.newsfeed, '6.8.2').subscribe(result => {
getApi(httpMock, configMock, '6.8.2').subscribe(result => {
expect(result).toMatchInlineSnapshot(`
Object {
"error": "sorry, try again later!",
Expand Down Expand Up @@ -623,14 +623,14 @@ describe('getApi', () => {
];

it("retries until fetch doesn't error", done => {
configMock.newsfeed.mainInterval = 10; // fast retry for testing
configMock.mainInterval = moment.duration(10); // fast retry for testing
mockHttpGet
.mockImplementationOnce(() => Promise.reject('Sorry, try again later!'))
.mockImplementationOnce(() => Promise.reject('Sorry, internal server error!'))
.mockImplementationOnce(() => Promise.reject("Sorry, it's too cold to go outside!"))
.mockImplementationOnce(getHttpMockWithItems(successItems));

getApi(httpMock, configMock.newsfeed, '6.8.2')
getApi(httpMock, configMock, '6.8.2')
.pipe(take(4), toArray())
.subscribe(result => {
expect(result).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -677,13 +677,13 @@ describe('getApi', () => {
});

it("doesn't retry if fetch succeeds", done => {
configMock.newsfeed.mainInterval = 10; // fast retry for testing
configMock.mainInterval = moment.duration(10); // fast retry for testing
mockHttpGet.mockImplementation(getHttpMockWithItems(successItems));

const timeout$ = interval(1000); // lets us capture some results after a short time
let timesFetched = 0;

const get$ = getApi(httpMock, configMock.newsfeed, '6.8.2').pipe(
const get$ = getApi(httpMock, configMock, '6.8.2').pipe(
tap(() => {
timesFetched++;
})
Expand Down
14 changes: 7 additions & 7 deletions src/plugins/newsfeed/public/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import {
NEWSFEED_FALLBACK_LANGUAGE,
NEWSFEED_LAST_FETCH_STORAGE_KEY,
NEWSFEED_HASH_SET_STORAGE_KEY,
} from '../../constants';
import { NewsfeedPluginInjectedConfig, ApiItem, NewsfeedItem, FetchResult } from '../../types';
} from '../../common/constants';
import { ApiItem, NewsfeedItem, FetchResult, NewsfeedPluginBrowserConfig } from '../types';

type ApiConfig = NewsfeedPluginInjectedConfig['newsfeed']['service'];
type ApiConfig = NewsfeedPluginBrowserConfig['service'];

export class NewsfeedApiDriver {
private readonly loadedTime = moment().utc(); // the date is compared to time in UTC format coming from the service
Expand Down Expand Up @@ -167,14 +167,14 @@ export class NewsfeedApiDriver {
*/
export function getApi(
http: HttpSetup,
config: NewsfeedPluginInjectedConfig['newsfeed'],
config: NewsfeedPluginBrowserConfig,
kibanaVersion: string
): Rx.Observable<void | FetchResult> {
const userLanguage = i18n.getLocale() || config.defaultLanguage;
const fetchInterval = config.fetchInterval;
const userLanguage = i18n.getLocale();
const fetchInterval = config.fetchInterval.asMilliseconds();
const driver = new NewsfeedApiDriver(kibanaVersion, userLanguage, fetchInterval);

return Rx.timer(0, config.mainInterval).pipe(
return Rx.timer(0, config.mainInterval.asMilliseconds()).pipe(
filter(() => driver.shouldFetch()),
mergeMap(() =>
driver.fetchNewsfeedItems(http, config.service).pipe(
Expand Down
Loading