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 1 commit
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
2 changes: 1 addition & 1 deletion src/plugins/newsfeed/public/components/flyout_list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
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
2 changes: 1 addition & 1 deletion src/plugins/newsfeed/public/lib/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
NEWSFEED_HASH_SET_STORAGE_KEY,
NEWSFEED_LAST_FETCH_STORAGE_KEY,
} from '../../common/constants';
import { ApiItem, NewsfeedItem, NewsfeedPluginBrowserConfig } from '../../types';
import { ApiItem, NewsfeedItem, NewsfeedPluginBrowserConfig } from '../types';
import { NewsfeedApiDriver, getApi } from './api';

const localStorageGet = sinon.stub();
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/newsfeed/public/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
NEWSFEED_LAST_FETCH_STORAGE_KEY,
NEWSFEED_HASH_SET_STORAGE_KEY,
} from '../../common/constants';
import { ApiItem, NewsfeedItem, FetchResult, NewsfeedPluginBrowserConfig } from '../../types';
import { ApiItem, NewsfeedItem, FetchResult, NewsfeedPluginBrowserConfig } from '../types';

type ApiConfig = NewsfeedPluginBrowserConfig['service'];

Expand Down Expand Up @@ -171,10 +171,10 @@ export function getApi(
kibanaVersion: string
): Rx.Observable<void | FetchResult> {
const userLanguage = i18n.getLocale();
const fetchInterval = config.fetchInterval;
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
11 changes: 9 additions & 2 deletions src/plugins/newsfeed/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import * as Rx from 'rxjs';
import { catchError, takeUntil } from 'rxjs/operators';
import ReactDOM from 'react-dom';
import React from 'react';
import moment from 'moment';
import { I18nProvider } from '@kbn/i18n/react';
import { PluginInitializerContext, CoreSetup, CoreStart, Plugin } from 'src/core/public';
import { NewsfeedPluginBrowserConfig } from '../types';
import { NewsfeedPluginBrowserConfig } from './types';
import { NewsfeedNavButton, NewsfeedApiFetchResult } from './components/newsfeed_header_nav_button';
import { getApi } from './lib/api';

Expand All @@ -36,8 +37,14 @@ export class NewsfeedPublicPlugin implements Plugin<Setup, Start> {
private readonly stop$ = new Rx.ReplaySubject(1);

constructor(initializerContext: PluginInitializerContext<NewsfeedPluginBrowserConfig>) {
this.config = initializerContext.config.get();
this.kibanaVersion = initializerContext.env.packageInfo.version;
const config = initializerContext.config.get();
this.config = Object.freeze({
...config,
// We need wrap them in moment.duration because exposeToBrowser stringifies it.
mainInterval: moment.duration(config.mainInterval),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a real problem that a plugin has to do it manually

fetchInterval: moment.duration(config.fetchInterval),
});
}

public setup(core: CoreSetup): Setup {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
* under the License.
*/

import { Moment } from 'moment';
import { Duration, Moment } from 'moment';

// Ideally, we may want to obtain the type from the configSchema and exposeToBrowser keys...
export interface NewsfeedPluginBrowserConfig {
service: {
urlRoot: string;
pathTemplate: string;
};
mainInterval: number; // how often to check last updated time
fetchInterval: number; // how often to fetch remote service and set last updated
mainInterval: Duration; // how often to check last updated time
fetchInterval: Duration; // how often to fetch remote service and set last updated
}

export interface ApiItem {
Expand Down