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

[7.5] [Newsfeed] UI plugin for Kibana (#49579) #50504

Merged
merged 5 commits into from
Nov 13, 2019
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 .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"visTypeMetric": "src/legacy/core_plugins/vis_type_metric",
"visTypeVega": "src/legacy/core_plugins/vis_type_vega",
"visTypeTable": "src/legacy/core_plugins/vis_type_table",
"newsfeed": "src/plugins/newsfeed",
"regionMap": "src/legacy/core_plugins/region_map",
"statusPage": "src/legacy/core_plugins/status_page",
"tileMap": "src/legacy/core_plugins/tile_map",
Expand Down
4 changes: 4 additions & 0 deletions docs/setup/settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ override this parameter to use their own Tile Map Service. For example:
`ops.interval:`:: *Default: 5000* Set the interval in milliseconds to sample
system and process performance metrics. The minimum value is 100.

`newsfeed.enabled:` :: *Default: `true`* Controls whether to enable the newsfeed
system for the Kibana UI notification center. Set to `false` to disable the
newsfeed system.

`path.data:`:: *Default: `data`* The path where Kibana stores persistent data
not saved in Elasticsearch.

Expand Down
1 change: 1 addition & 0 deletions scripts/functional_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ require('@kbn/test').runTestsCli([
require.resolve('../test/api_integration/config.js'),
require.resolve('../test/plugin_functional/config.js'),
require.resolve('../test/interpreter_functional/config.js'),
require.resolve('../test/ui_capabilities/newsfeed_err/config.ts'),
]);
23 changes: 23 additions & 0 deletions src/legacy/core_plugins/newsfeed/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export const PLUGIN_ID = 'newsfeed';
export const DEFAULT_SERVICE_URLROOT = 'https://feeds.elastic.co';
export const DEV_SERVICE_URLROOT = 'https://feeds-staging.elastic.co';
export const DEFAULT_SERVICE_PATH = '/kibana/v{VERSION}.json';
71 changes: 71 additions & 0 deletions src/legacy/core_plugins/newsfeed/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { resolve } from 'path';
import { LegacyPluginApi, LegacyPluginSpec, ArrayOrItem } from 'src/legacy/plugin_discovery/types';
import { Legacy } from 'kibana';
import { NewsfeedPluginInjectedConfig } from '../../../plugins/newsfeed/types';
import {
PLUGIN_ID,
DEFAULT_SERVICE_URLROOT,
DEV_SERVICE_URLROOT,
DEFAULT_SERVICE_PATH,
} from './constants';

// eslint-disable-next-line import/no-default-export
export default function(kibana: LegacyPluginApi): ArrayOrItem<LegacyPluginSpec> {
const pluginSpec: Legacy.PluginSpecOptions = {
id: PLUGIN_ID,
config(Joi: any) {
// NewsfeedPluginInjectedConfig in Joi form
return Joi.object({
enabled: Joi.boolean().default(true),
service: Joi.object({
pathTemplate: Joi.string().default(DEFAULT_SERVICE_PATH),
urlRoot: Joi.when('$prod', {
is: true,
then: Joi.string().default(DEFAULT_SERVICE_URLROOT),
otherwise: Joi.string().default(DEV_SERVICE_URLROOT),
}),
}).default(),
defaultLanguage: Joi.string().default('en'),
mainInterval: Joi.number().default(120 * 1000), // (2min) How often to retry failed fetches, and/or check if newsfeed items need to be refreshed from remote
fetchInterval: Joi.number().default(86400 * 1000), // (1day) How often to fetch remote and reset the last fetched time
}).default();
},
uiExports: {
styleSheetPaths: resolve(__dirname, 'public/index.scss'),
injectDefaultVars(server): NewsfeedPluginInjectedConfig {
const config = server.config();
return {
newsfeed: {
service: {
pathTemplate: config.get('newsfeed.service.pathTemplate') as string,
urlRoot: config.get('newsfeed.service.urlRoot') as string,
},
defaultLanguage: config.get('newsfeed.defaultLanguage') as string,
mainInterval: config.get('newsfeed.mainInterval') as number,
fetchInterval: config.get('newsfeed.fetchInterval') as number,
},
};
},
},
};
return new kibana.Plugin(pluginSpec);
}
4 changes: 4 additions & 0 deletions src/legacy/core_plugins/newsfeed/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "newsfeed",
"version": "kibana"
}
3 changes: 3 additions & 0 deletions src/legacy/core_plugins/newsfeed/public/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@import 'src/legacy/ui/public/styles/styling_constants';

@import './np_ready/components/header_alert/_index';
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@import '@elastic/eui/src/components/header/variables';

.kbnNews__flyout {
top: $euiHeaderChildSize + 1px;
height: calc(100% - #{$euiHeaderChildSize});
}

.kbnNewsFeed__headerAlert.euiHeaderAlert {
margin-bottom: $euiSizeL;
padding: 0 $euiSizeS $euiSizeL;
border-bottom: $euiBorderThin;
border-top: none;

.euiHeaderAlert__title {
@include euiTitle('xs');
margin-bottom: $euiSizeS;
}

.euiHeaderAlert__text {
@include euiFontSizeS;
margin-bottom: $euiSize;
}

.euiHeaderAlert__action {
@include euiFontSizeS;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

import { EuiFlexGroup, EuiFlexItem, EuiI18n } from '@elastic/eui';

interface IEuiHeaderAlertProps {
action: JSX.Element;
className?: string;
date: string;
text: string;
title: string;
badge?: JSX.Element;
rest?: string[];
}

export const EuiHeaderAlert = ({
action,
className,
date,
text,
title,
badge,
...rest
}: IEuiHeaderAlertProps) => {
const classes = classNames('euiHeaderAlert', 'kbnNewsFeed__headerAlert', className);

const badgeContent = badge || null;

return (
<EuiI18n token="euiHeaderAlert.dismiss" default="Dismiss">
{(dismiss: any) => (
<div className={classes} {...rest}>
<EuiFlexGroup justifyContent="spaceBetween">
<EuiFlexItem>
<div className="euiHeaderAlert__date">{date}</div>
</EuiFlexItem>
<EuiFlexItem grow={false}>{badgeContent}</EuiFlexItem>
</EuiFlexGroup>

<div className="euiHeaderAlert__title">{title}</div>
<div className="euiHeaderAlert__text">{text}</div>
<div className="euiHeaderAlert__action euiLink">{action}</div>
</div>
)}
</EuiI18n>
);
};

EuiHeaderAlert.propTypes = {
action: PropTypes.node,
className: PropTypes.string,
date: PropTypes.node.isRequired,
text: PropTypes.node,
title: PropTypes.node.isRequired,
badge: PropTypes.node,
};
22 changes: 22 additions & 0 deletions src/plugins/newsfeed/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export const NEWSFEED_FALLBACK_LANGUAGE = 'en';
export const NEWSFEED_LAST_FETCH_STORAGE_KEY = 'newsfeed.lastfetchtime';
export const NEWSFEED_HASH_SET_STORAGE_KEY = 'newsfeed.hashes';
6 changes: 6 additions & 0 deletions src/plugins/newsfeed/kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"id": "newsfeed",
"version": "kibana",
"server": false,
"ui": true
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions src/plugins/newsfeed/public/components/empty_news.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import * as React from 'react';
import { shallow } from 'enzyme';
import toJson from 'enzyme-to-json';
import { NewsEmptyPrompt } from './empty_news';

describe('empty_news', () => {
describe('rendering', () => {
it('renders the default Empty News', () => {
const wrapper = shallow(<NewsEmptyPrompt />);
expect(toJson(wrapper)).toMatchSnapshot();
});
});
});
44 changes: 44 additions & 0 deletions src/plugins/newsfeed/public/components/empty_news.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied.  See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import React from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiEmptyPrompt } from '@elastic/eui';

export const NewsEmptyPrompt = () => {
return (
<EuiEmptyPrompt
iconType="documents"
titleSize="s"
data-test-subj="emptyNewsfeed"
title={
<h2>
<FormattedMessage id="newsfeed.emptyPrompt.noNewsTitle" defaultMessage="No news?" />
</h2>
}
body={
<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."
/>
</p>
}
/>
);
};
Loading