Skip to content

Commit

Permalink
[Rename] newsfeed plug (#117)
Browse files Browse the repository at this point in the history
Signed-off-by: Kawika Avilla <[email protected]>
  • Loading branch information
kavilla committed Mar 20, 2021
1 parent 6e00c8b commit 999bec0
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/plugins/newsfeed/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ export const NEWSFEED_HASH_SET_STORAGE_KEY = 'newsfeed.hashes';

export const NEWSFEED_DEFAULT_SERVICE_BASE_URL = '';
export const NEWSFEED_DEV_SERVICE_BASE_URL = '';
export const NEWSFEED_DEFAULT_SERVICE_PATH = '/kibana/v{VERSION}.json';
export const NEWSFEED_DEFAULT_SERVICE_PATH = '/opensearch-dashboards/v{VERSION}.json';
4 changes: 2 additions & 2 deletions src/plugins/newsfeed/public/components/empty_news.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/
import React from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { FormattedMessage } from '@osd/i18n/react';
import { EuiEmptyPrompt } from '@elastic/eui';

export const NewsEmptyPrompt = () => {
Expand All @@ -35,7 +35,7 @@ export const NewsEmptyPrompt = () => {
<p>
<FormattedMessage
id="newsfeed.emptyPrompt.noNewsText"
defaultMessage="If your Kibana instance doesn’t have internet access, ask your administrator to disable this feature. Otherwise, we’ll keep trying to fetch the news."
defaultMessage="If your OpenSearch Dashboards instance doesn’t have internet access, ask your administrator to disable this feature. Otherwise, we’ll keep trying to fetch the news."
/>
</p>
}
Expand Down
10 changes: 5 additions & 5 deletions src/plugins/newsfeed/public/components/flyout_list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
EuiHeaderAlert,
EuiPortal,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { FormattedMessage } from '@osd/i18n/react';
import { NewsfeedContext } from './newsfeed_header_nav_button';
import { NewsfeedItem } from '../types';
import { NewsEmptyPrompt } from './empty_news';
Expand All @@ -48,20 +48,20 @@ export const NewsfeedFlyout = () => {
onClose={closeFlyout}
size="s"
aria-labelledby="flyoutSmallTitle"
className="kbnNews__flyout"
className="osdNews__flyout"
data-test-subj="NewsfeedFlyout"
>
<EuiFlyoutHeader hasBorder>
<EuiTitle size="s">
<h2 id="flyoutSmallTitle">
<FormattedMessage
id="newsfeed.flyoutList.whatsNewTitle"
defaultMessage="What's new at Elastic"
defaultMessage="What's new at OpenSearch"
/>
</h2>
</EuiTitle>
</EuiFlyoutHeader>
<EuiFlyoutBody className={'kbnNews__flyoutAlerts'}>
<EuiFlyoutBody className={'osdNews__flyoutAlerts'}>
{!newsFetchResult ? (
<NewsLoadingPrompt />
) : newsFetchResult.feedItems.length > 0 ? (
Expand Down Expand Up @@ -103,7 +103,7 @@ export const NewsfeedFlyout = () => {
<FormattedMessage
id="newsfeed.flyoutList.versionTextLabel"
defaultMessage="{version}"
values={{ version: `Version ${newsFetchResult.kibanaVersion}` }}
values={{ version: `Version ${newsFetchResult.opensearchDashboardsVersion}` }}
/>
</p>
</EuiText>
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/newsfeed/public/components/loading_news.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/
import React from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { FormattedMessage } from '@osd/i18n/react';

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

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 @@ -52,10 +52,10 @@ jest.mock('uuid', () => ({
}));

describe.skip('NewsfeedApiDriver', () => {
const kibanaVersion = '99.999.9-test_version'; // It'll remove the `-test_version` bit
const opensearchDashboardsVersion = '99.999.9-test_version'; // It'll remove the `-test_version` bit
const userLanguage = 'en';
const fetchInterval = 2000;
const getDriver = () => new NewsfeedApiDriver(kibanaVersion, userLanguage, fetchInterval);
const getDriver = () => new NewsfeedApiDriver(opensearchDashboardsVersion, userLanguage, fetchInterval);

afterEach(() => {
sinon.reset();
Expand Down Expand Up @@ -187,7 +187,7 @@ describe.skip('NewsfeedApiDriver', () => {
"error": null,
"feedItems": Array [],
"hasNew": false,
"kibanaVersion": "99.999.9",
"opensearchDashboardsVersion": "99.999.9",
}
`);
});
Expand Down Expand Up @@ -235,13 +235,13 @@ describe.skip('NewsfeedApiDriver', () => {
},
],
hasNew: true,
kibanaVersion: '99.999.9',
opensearchDashboardsVersion: '99.999.9',
});
});

it("Falls back to English when user language isn't present", () => {
// Set Language to French
const driver = new NewsfeedApiDriver(kibanaVersion, 'fr', fetchInterval);
const driver = new NewsfeedApiDriver(opensearchDashboardsVersion, 'fr', fetchInterval);
const apiItems: ApiItem[] = [
{
title: {
Expand Down Expand Up @@ -317,7 +317,7 @@ describe.skip('NewsfeedApiDriver', () => {
},
],
hasNew: true,
kibanaVersion: '99.999.9',
opensearchDashboardsVersion: '99.999.9',
});
});

Expand Down Expand Up @@ -383,7 +383,7 @@ describe.skip('NewsfeedApiDriver', () => {
},
],
hasNew: true,
kibanaVersion: '99.999.9',
opensearchDashboardsVersion: '99.999.9',
});
});

Expand Down Expand Up @@ -413,7 +413,7 @@ describe.skip('NewsfeedApiDriver', () => {
"error": null,
"feedItems": Array [],
"hasNew": false,
"kibanaVersion": "99.999.9",
"opensearchDashboardsVersion": "99.999.9",
}
`);
});
Expand Down Expand Up @@ -444,7 +444,7 @@ describe.skip('NewsfeedApiDriver', () => {
"error": null,
"feedItems": Array [],
"hasNew": false,
"kibanaVersion": "99.999.9",
"opensearchDashboardsVersion": "99.999.9",
}
`);
});
Expand All @@ -461,7 +461,7 @@ describe.skip('getApi', () => {
arg2: { method: string }
) => {
if (
arg1 === 'http://fakenews.co/kibana-test/v6.8.2.json' &&
arg1 === 'http://fakenews.co/opensearch-dashboards-test/v6.8.2.json' &&
arg2.method &&
arg2.method === 'GET'
) {
Expand All @@ -479,7 +479,7 @@ describe.skip('getApi', () => {
configMock = {
service: {
urlRoot: 'http://fakenews.co',
pathTemplate: '/kibana-test/v{VERSION}.json',
pathTemplate: '/opensearch-dashboards-test/v{VERSION}.json',
},
mainInterval: moment.duration(86400000),
fetchInterval: moment.duration(86400000),
Expand All @@ -497,7 +497,7 @@ describe.skip('getApi', () => {
"error": null,
"feedItems": Array [],
"hasNew": false,
"kibanaVersion": "6.8.2",
"opensearchDashboardsVersion": "6.8.2",
}
`);
done();
Expand Down Expand Up @@ -553,7 +553,7 @@ describe.skip('getApi', () => {
},
],
"hasNew": true,
"kibanaVersion": "6.8.2",
"opensearchDashboardsVersion": "6.8.2",
}
`);
done();
Expand Down Expand Up @@ -593,7 +593,7 @@ describe.skip('getApi', () => {
},
],
"hasNew": false,
"kibanaVersion": "6.8.2",
"opensearchDashboardsVersion": "6.8.2",
}
`);
done();
Expand All @@ -609,7 +609,7 @@ describe.skip('getApi', () => {
"error": "sorry, try again later!",
"feedItems": Array [],
"hasNew": false,
"kibanaVersion": "6.8.2",
"opensearchDashboardsVersion": "6.8.2",
}
`);
done();
Expand Down Expand Up @@ -647,19 +647,19 @@ describe.skip('getApi', () => {
"error": "Sorry, try again later!",
"feedItems": Array [],
"hasNew": false,
"kibanaVersion": "6.8.2",
"opensearchDashboardsVersion": "6.8.2",
},
Object {
"error": "Sorry, internal server error!",
"feedItems": Array [],
"hasNew": false,
"kibanaVersion": "6.8.2",
"opensearchDashboardsVersion": "6.8.2",
},
Object {
"error": "Sorry, it's too cold to go outside!",
"feedItems": Array [],
"hasNew": false,
"kibanaVersion": "6.8.2",
"opensearchDashboardsVersion": "6.8.2",
},
Object {
"error": null,
Expand All @@ -676,7 +676,7 @@ describe.skip('getApi', () => {
},
],
"hasNew": false,
"kibanaVersion": "6.8.2",
"opensearchDashboardsVersion": "6.8.2",
},
]
`);
Expand Down
22 changes: 11 additions & 11 deletions src/plugins/newsfeed/public/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import * as Rx from 'rxjs';
import moment from 'moment';
import uuid from 'uuid';
import { i18n } from '@kbn/i18n';
import { i18n } from '@osd/i18n';
import { catchError, filter, mergeMap, tap } from 'rxjs/operators';
import { HttpSetup } from 'src/core/public';
import {
Expand All @@ -34,26 +34,26 @@ import { ApiItem, NewsfeedItem, FetchResult, NewsfeedPluginBrowserConfig } from
type ApiConfig = NewsfeedPluginBrowserConfig['service'];

export enum NewsfeedApiEndpoint {
KIBANA = 'kibana',
KIBANA_ANALYTICS = 'kibana-analytics',
OPENSEARCH_DASHBOARDS = 'opensearch-dashboards',
OPENSEARCH_DASHBOARDS_ANALYTICS = 'opensearch-dashboards-analytics',
SECURITY_SOLUTION = 'security-solution',
OBSERVABILITY = 'observability',
}

export class NewsfeedApiDriver {
private readonly id = uuid.v4();
private readonly kibanaVersion: string;
private readonly opensearchDashboardsVersion: string;
private readonly loadedTime = moment().utc(); // the date is compared to time in UTC format coming from the service
private readonly lastFetchStorageKey: string;
private readonly hashSetStorageKey: string;

constructor(
kibanaVersion: string,
opensearchDashboardsVersion: string,
private readonly userLanguage: string,
private readonly fetchInterval: number
) {
// The API only accepts versions in the format `X.Y.Z`, so we need to drop the `-SNAPSHOT` or any other label after it
this.kibanaVersion = kibanaVersion.replace(/^(\d+\.\d+\.\d+).*/, '$1');
this.opensearchDashboardsVersion = opensearchDashboardsVersion.replace(/^(\d+\.\d+\.\d+).*/, '$1');
this.lastFetchStorageKey = `${NEWSFEED_LAST_FETCH_STORAGE_KEY}.${this.id}`;
this.hashSetStorageKey = `${NEWSFEED_HASH_SET_STORAGE_KEY}.${this.id}`;
}
Expand Down Expand Up @@ -96,7 +96,7 @@ export class NewsfeedApiDriver {
}

fetchNewsfeedItems(http: HttpSetup, config: ApiConfig): Rx.Observable<FetchResult> {
const urlPath = config.pathTemplate.replace('{VERSION}', this.kibanaVersion);
const urlPath = config.pathTemplate.replace('{VERSION}', this.opensearchDashboardsVersion);
const fullUrl = (config.urlRoot || NEWSFEED_DEFAULT_SERVICE_BASE_URL) + urlPath;

return Rx.from(
Expand Down Expand Up @@ -174,7 +174,7 @@ export class NewsfeedApiDriver {

return {
error: null,
kibanaVersion: this.kibanaVersion,
opensearchDashboardsVersion: this.opensearchDashboardsVersion,
hasNew,
feedItems,
};
Expand All @@ -188,12 +188,12 @@ export class NewsfeedApiDriver {
export function getApi(
http: HttpSetup,
config: NewsfeedPluginBrowserConfig,
kibanaVersion: string
opensearchDashboardsVersion: string
): Rx.Observable<void | FetchResult> {
const userLanguage = i18n.getLocale();
const fetchInterval = config.fetchInterval.asMilliseconds();
const mainInterval = config.mainInterval.asMilliseconds();
const driver = new NewsfeedApiDriver(kibanaVersion, userLanguage, fetchInterval);
const driver = new NewsfeedApiDriver(opensearchDashboardsVersion, userLanguage, fetchInterval);

return Rx.timer(0, mainInterval).pipe(
filter(() => driver.shouldFetch()),
Expand All @@ -203,7 +203,7 @@ export function getApi(
window.console.error(err);
return Rx.of({
error: err,
kibanaVersion,
opensearchDashboardsVersion,
hasNew: false,
feedItems: [],
});
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/newsfeed/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { catchError, takeUntil, share } from 'rxjs/operators';
import ReactDOM from 'react-dom';
import React from 'react';
import moment from 'moment';
import { I18nProvider } from '@kbn/i18n/react';
import { I18nProvider } from '@osd/i18n/react';
import { PluginInitializerContext, CoreSetup, CoreStart, Plugin } from 'src/core/public';
import { NewsfeedPluginBrowserConfig, FetchResult } from './types';
import { NewsfeedNavButton, NewsfeedApiFetchResult } from './components/newsfeed_header_nav_button';
Expand All @@ -33,12 +33,12 @@ export type NewsfeedPublicPluginStart = ReturnType<NewsfeedPublicPlugin['start']

export class NewsfeedPublicPlugin
implements Plugin<NewsfeedPublicPluginSetup, NewsfeedPublicPluginStart> {
private readonly kibanaVersion: string;
private readonly opensearchDashboardsVersion: string;
private readonly config: NewsfeedPluginBrowserConfig;
private readonly stop$ = new Rx.ReplaySubject(1);

constructor(initializerContext: PluginInitializerContext<NewsfeedPluginBrowserConfig>) {
this.kibanaVersion = initializerContext.env.packageInfo.version;
this.opensearchDashboardsVersion = initializerContext.env.packageInfo.version;
const config = initializerContext.config.get();
this.config = Object.freeze({
...config,
Expand Down Expand Up @@ -78,7 +78,7 @@ export class NewsfeedPublicPlugin
config: NewsfeedPluginBrowserConfig
): Rx.Observable<FetchResult | null | void> {
const { http } = core;
return getApi(http, config, this.kibanaVersion).pipe(
return getApi(http, config, this.opensearchDashboardsVersion).pipe(
takeUntil(this.stop$), // stop the interval when stop method is called
catchError(() => Rx.of(null)) // do not throw error
);
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/newsfeed/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export interface NewsfeedItem {
}

export interface FetchResult {
kibanaVersion: string;
opensearchDashboardsVersion: string;
hasNew: boolean;
feedItems: NewsfeedItem[];
error: Error | null;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/newsfeed/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { schema, TypeOf } from '@kbn/config-schema';
import { schema, TypeOf } from '@osd/config-schema';
import {
NEWSFEED_DEFAULT_SERVICE_PATH,
NEWSFEED_DEFAULT_SERVICE_BASE_URL,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/newsfeed/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { PluginConfigDescriptor } from 'kibana/server';
import { PluginConfigDescriptor } from 'opensearch-dashboards/server';
import { NewsfeedPlugin } from './plugin';
import { configSchema, NewsfeedConfigType } from './config';

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/newsfeed/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { Plugin } from 'kibana/server';
import { Plugin } from 'opensearch-dashboards/server';

export class NewsfeedPlugin implements Plugin {
public setup() {}
Expand Down

0 comments on commit 999bec0

Please sign in to comment.