Skip to content

Commit

Permalink
Refs #29796 - statistics extraction warning
Browse files Browse the repository at this point in the history
(cherry picked from commit f7b79cd)
  • Loading branch information
ezr-ondrej authored and tbrisker committed May 19, 2020
1 parent ca2560a commit 3e7eada
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 6 deletions.
13 changes: 12 additions & 1 deletion app/controllers/links_controller.rb
Expand Up @@ -17,7 +17,7 @@ def external_url(type:, options: {})
when 'chat'
'https://freenode.net'
when 'forums'
'https://community.theforeman.org'
forum_url(options['post'])
when 'issues'
'https://projects.theforeman.org/projects/foreman/issues'
when 'vmrc'
Expand All @@ -34,6 +34,17 @@ def documentation_url(section = "", options = {})
end
end

def plugin_documentation_url(plugin_name, version: nil, options: {})
root_url = options[:root_url] || "https://theforeman.org/plugins"
path = version ? "#{plugin_name}/#{version}" : plugin_name
"#{root_url}/#{path}"
end

def forum_url(post_path = nil, options: {})
root = options[:root] || 'https://community.theforeman.org'
post_path ? "#{root}/#{post_path}" : root
end

def wiki_url(section: '')
"https://projects.theforeman.org/projects/foreman/wiki/#{section}"
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/statistics_controller.rb
Expand Up @@ -2,7 +2,7 @@ class StatisticsController < ApplicationController
before_action :find_stat, :only => [:show]

def index
render :json => charts.map(&:metadata)
render :json => { :charts => charts.map(&:metadata), discussion_url: external_link_path(type: 'forums', post: 't/trends-and-statistics-plugin/18745') }
end

def show
Expand Down
5 changes: 5 additions & 0 deletions app/views/trends/_extraction_warning.html.erb
@@ -0,0 +1,5 @@
<%= alert :class => 'alert-warning', :header => _("This functionality is deprecated"),
:text => ("and will be removed in version 2.2. "\
"If you wish continue using it, you will need to install the Foreman Statistics plugin when upgrading to 2.2. " +
link_to('Join discussion', external_link_path(type: 'forums', post: 't/trends-and-statistics-plugin/18745'), :target => '_blank')
).html_safe %>
@@ -1,8 +1,12 @@
import { statisticsMeta } from '../../../components/StatisticsChartsList/StatisticsChartsList.fixtures';
import { noop } from '../../../common/helpers';

export const discussionUrl =
'/links/forums?post=t/trends-and-statistics-plugin/18745/4';

export const statisticsProps = {
statisticsMeta,
discussionUrl,
isLoading: false,
hasData: true,
hasError: false,
Expand Down
@@ -1,21 +1,36 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Alert } from 'patternfly-react';
import PageLayout from '../../common/PageLayout/PageLayout';
import Statistics from './Statistics/Statistics';
import { translate as __ } from '../../../common/I18n';

const StatisticsPage = ({ statisticsMeta, ...props }) => (
const StatisticsPage = ({ statisticsMeta, discussionUrl, ...props }) => (
<PageLayout header={__('Statistics')} searchable={false}>
<Alert type="warning">
<span className="pficon pficon-warning-triangle-o" />
<strong>This functionality is deprecated </strong>
<span className="text">
and will be removed in version 2.2. If you wish continue using it, you
will need to install the Foreman Statistics plugin when upgrading to
2.2.
<a href={discussionUrl} target="_blank" rel="noreferrer">
Join discussion
</a>
</span>
</Alert>
<Statistics statisticsMeta={statisticsMeta} {...props} />
</PageLayout>
);

StatisticsPage.propTypes = {
statisticsMeta: PropTypes.array,
discussionUrl: PropTypes.string,
};

StatisticsPage.defaultProps = {
statisticsMeta: [],
discussionUrl: '',
};

export default StatisticsPage;
Expand Up @@ -14,7 +14,11 @@ export const getStatisticsMeta = (
dispatch(hideLoading());
dispatch({
type: STATISTICS_PAGE_DATA_RESOLVED,
payload: { metadata: data, hasData: data.length > 0 },
payload: {
metadata: data.charts,
hasData: data.charts.length > 0,
discussionUrl: data.discussion_url,
},
});
};

Expand Down
Expand Up @@ -2,6 +2,8 @@ export const selectStatisticsPage = state => state.statisticsPage;

export const selectStatisticsMetadata = state =>
selectStatisticsPage(state).metadata;
export const selectStatisticsDiscussionUrl = state =>
selectStatisticsPage(state).discussionUrl;
export const selectStatisticsIsLoading = state =>
selectStatisticsPage(state).isLoading;
export const selectStatisticsMessage = state =>
Expand Down
Expand Up @@ -2,7 +2,7 @@ import API from '../../../../redux/API/API';

import { testActionSnapshotWithFixtures } from '../../../../common/testHelpers';
import { getStatisticsMeta } from '../StatisticsPageActions';
import { statisticsProps } from '../StatisticsPage.fixtures';
import { statisticsProps, discussionUrl } from '../StatisticsPage.fixtures';

jest.mock('../../../../redux/API/API');

Expand All @@ -15,7 +15,10 @@ const runStatisticsAction = (callback, props, serverMock) => {
const fixtures = {
'should fetch statisticsMeta': () =>
runStatisticsAction(getStatisticsMeta, {}, async () => ({
data: statisticsProps.statisticsMeta,
data: {
charts: statisticsProps.statisticsMeta,
discussion_url: discussionUrl,
},
})),
'should fetch statisticsMeta and fail': () =>
runStatisticsAction(getStatisticsMeta, {}, async () => {
Expand Down
Expand Up @@ -15,6 +15,30 @@ exports[`StatisticsPage rendering render with props 1`] = `
toastNotifications={null}
toolbarButtons={null}
>
<Alert
className=""
onDismiss={null}
type="warning"
>
<span
className="pficon pficon-warning-triangle-o"
/>
<strong>
This functionality is deprecated
</strong>
<span
className="text"
>
and will be removed in version 2.2. If you wish continue using it, you will need to install the Foreman Statistics plugin when upgrading to 2.2.
<a
href="/links/forums?post=t/trends-and-statistics-plugin/18745/4"
rel="noreferrer"
target="_blank"
>
Join discussion
</a>
</span>
</Alert>
<Component
getStatisticsMeta={[Function]}
hasData={true}
Expand Down
Expand Up @@ -10,6 +10,7 @@ Array [
Array [
Object {
"payload": Object {
"discussionUrl": "/links/forums?post=t/trends-and-statistics-plugin/18745/4",
"hasData": true,
"metadata": Array [
Object {
Expand Down
Expand Up @@ -4,6 +4,7 @@ exports[`StatisticsPage selectors should return StatisticsHasMetadata 1`] = `tru

exports[`StatisticsPage selectors should return StatisticsPage 1`] = `
Object {
"discussionUrl": "/links/forums?post=t/trends-and-statistics-plugin/18745/4",
"getStatisticsMeta": [Function],
"hasData": true,
"hasError": false,
Expand Down
Expand Up @@ -6,6 +6,7 @@ import * as actions from './StatisticsPageActions';
import withDataReducer from '../../common/reducerHOC/withDataReducer';
import {
selectStatisticsMetadata,
selectStatisticsDiscussionUrl,
selectStatisticsMessage,
selectStatisticsIsLoading,
selectStatisticsHasMetadata,
Expand All @@ -17,6 +18,7 @@ import StatisticsPage from './StatisticsPage';
// map state to props
const mapStateToProps = state => ({
statisticsMeta: selectStatisticsMetadata(state),
discussionUrl: selectStatisticsDiscussionUrl(state),
isLoading: selectStatisticsIsLoading(state),
message: selectStatisticsMessage(state),
hasData: selectStatisticsHasMetadata(state),
Expand Down

0 comments on commit 3e7eada

Please sign in to comment.