Skip to content

Commit

Permalink
[7.x] Remove Newsfeed leftovers from the Legacy codebase (#66084) (#6…
Browse files Browse the repository at this point in the history
  • Loading branch information
afharo authored May 13, 2020
1 parent c63d600 commit fa4cd2c
Show file tree
Hide file tree
Showing 21 changed files with 255 additions and 386 deletions.
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

0 comments on commit fa4cd2c

Please sign in to comment.