-
Notifications
You must be signed in to change notification settings - Fork 987
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #24011 - Add Patternfly bar chart support
- Loading branch information
1 parent
6044a04
commit 5b7dc0f
Showing
30 changed files
with
721 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,12 @@ | ||
<% @totaltime = metrics.delete('total') %> | ||
<% metrics.delete_if{ |k,v| v < 0.001 } %> | ||
<div class="row"> | ||
<div class="col-md-4"> | ||
<div class="stats-well"> | ||
<h4 class="ca" ><%= _('Report Metrics') %></h4> | ||
<div id="metrics_chart" class='metrics-chart'></div> | ||
<%= mount_react_component('DonutChart', '#metrics_chart', metrics.to_a.to_json) %> | ||
</div> | ||
</div> | ||
<div class="col-md-4"> | ||
<div class="stats-well"> | ||
<h4 class="ca" ><%= _('Report Status') %></h4> | ||
<%= flot_bar_chart("status" ,"", _("Number of Events"), status, :class => "statistics-bar")%> | ||
</div> | ||
</div> | ||
<div class="col-md-4"> | ||
<table class="<%= table_css_classes %>" style="height: 400px;"> | ||
<tbody> | ||
<% metrics.sort.each do |title, value|%> | ||
<tr> | ||
<td class="break-me"> | ||
<%= title %> | ||
</td> | ||
<td> | ||
<%= metric value %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
<tfoot> | ||
<tr> | ||
<th><%= _("Total") %></th><th><%= metric (@totaltime || @config_report.runtime) %></th> | ||
</tr> | ||
</tfoot> | ||
</table> | ||
</div> | ||
</div> | ||
|
||
<div id="config-reports"> | ||
<%= mount_react_component('ConfigReports', '#config-reports', { | ||
metricsChartData: metrics.to_a, | ||
statusChartData: status.to_a, | ||
metricsData: { tableData: metrics_table_data(metrics), | ||
total: metric(@totaltime || @config_report.runtime), | ||
tableClasses: table_css_classes } | ||
}.to_json) | ||
%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
webpack/assets/javascripts/react_app/components/ComponentWrapper/ComponentWrapper.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { shallow } from 'enzyme'; | ||
import toJson from 'enzyme-to-json'; | ||
import React from 'react'; | ||
import componentRegistry from '../componentRegistry'; | ||
import ComponentWrapper from './'; | ||
|
||
jest.mock('../componentRegistry'); | ||
|
||
describe('ComponentWrapper', () => { | ||
it('should render core component', () => { | ||
componentRegistry.getComponent = jest.fn(() => ({ type: 'AwesomeComponent' })); | ||
|
||
const wrapper = shallow(<ComponentWrapper data={{ component: 'AwesomeComponent' }} />); | ||
|
||
expect(toJson(wrapper)).toMatchSnapshot(); | ||
}); | ||
|
||
it('should not render unregistered component', () => { | ||
const render = () => { | ||
componentRegistry.getComponent = jest.fn(() => undefined); | ||
shallow(<ComponentWrapper data={{ component: 'NotAwesomeComponent' }} />); | ||
}; | ||
|
||
expect(render).toThrow(Error); | ||
}); | ||
}); |
3 changes: 3 additions & 0 deletions
3
...scripts/react_app/components/ComponentWrapper/__snapshots__/ComponentWrapper.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`ComponentWrapper should render core component 1`] = `<AwesomeComponent />`; |
30 changes: 30 additions & 0 deletions
30
webpack/assets/javascripts/react_app/components/ComponentWrapper/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import componentRegistry from '../componentRegistry'; | ||
|
||
const ComponentWrapper = (props) => { | ||
const { component, componentProps } = props.data; | ||
|
||
if (component === 'ComponentWrapper') { | ||
throw new Error('Cannot wrap componenet wrapper'); | ||
} | ||
|
||
const registeredComponent = componentRegistry.getComponent(component); | ||
|
||
if (!registeredComponent) { | ||
throw new Error('Component name is missing!'); | ||
} | ||
|
||
const Component = registeredComponent.type; | ||
|
||
return <Component {...componentProps} />; | ||
}; | ||
|
||
ComponentWrapper.propTypes = { | ||
data: PropTypes.shape({ | ||
componentProps: PropTypes.object, | ||
component: PropTypes.string.isRequired, | ||
}).isRequired, | ||
}; | ||
|
||
export default ComponentWrapper; |
74 changes: 74 additions & 0 deletions
74
webpack/assets/javascripts/react_app/components/ConfigReports/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Row, Col } from 'patternfly-react'; | ||
import cx from 'classnames'; | ||
import ChartBox from '../statistics/ChartBox'; | ||
import { translate as __ } from '../../common/I18n'; | ||
import { STATUS } from '../../constants'; | ||
|
||
const ConfigReports = (props) => { | ||
const { metricsChartData, statusChartData, metricsData } = props.data; | ||
|
||
const createRow = (metric, i) => ( | ||
<tr key={i}> | ||
<td className="break-me">{metric[0]}</td> | ||
<td>{metric[1]}</td> | ||
</tr> | ||
); | ||
|
||
const chartBoxProps = { | ||
className: 'report-chart', | ||
noDataMsg: __('No data available'), | ||
status: STATUS.RESOLVED, | ||
config: 'medium', | ||
}; | ||
|
||
return ( | ||
<Row> | ||
<Col md={4}> | ||
<ChartBox | ||
{...chartBoxProps} | ||
type="donut" | ||
chart={{ data: metricsChartData, id: 'report-metrics' }} | ||
title="Report Metrics" | ||
id="report-metrics" | ||
/> | ||
</Col> | ||
|
||
<Col md={4}> | ||
<ChartBox | ||
{...chartBoxProps} | ||
type="bar" | ||
chart={{ data: statusChartData, id: 'report-status' }} | ||
title="Report Status" | ||
id="report-status" | ||
/> | ||
</Col> | ||
<Col md={4}> | ||
<table className={cx(metricsData.tableClasses, 'report-chart')}> | ||
<tbody>{metricsData.tableData.map((metric, i) => createRow(metric, i))}</tbody> | ||
<tfoot> | ||
<tr> | ||
<th>{__('Total')}</th> | ||
<th>{metricsData.total}</th> | ||
</tr> | ||
</tfoot> | ||
</table> | ||
</Col> | ||
</Row> | ||
); | ||
}; | ||
|
||
ConfigReports.propTypes = { | ||
data: PropTypes.shape({ | ||
metricsChartData: PropTypes.array, | ||
statusChartData: PropTypes.array, | ||
metricsData: PropTypes.shape({ | ||
tableData: PropTypes.array, | ||
total: PropTypes.number, | ||
tableClasses: PropTypes.string, | ||
}), | ||
}), | ||
}; | ||
|
||
export default ConfigReports; |
49 changes: 49 additions & 0 deletions
49
webpack/assets/javascripts/react_app/components/common/charts/BarChart/BarChart.fixtures.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
export const barChartData = { | ||
data: [ | ||
['Fedora 21', 3], | ||
['Ubuntu 14.04', 4], | ||
['Centos 7', 2], | ||
['Debian 8', 1], | ||
], | ||
xAxisLabel: 'OS', | ||
yAxisLabel: 'COUNT', | ||
}; | ||
|
||
export const barChartConfig = { | ||
data: { | ||
columns: [['Number of Events', 3, 4, 2, 1]], | ||
type: 'bar', | ||
}, | ||
color: { | ||
pattern: ['#0088ce', '#ec7a08', '#3f9c35', '#005c66', 'f9d67a', '#703fec'], | ||
}, | ||
tooltip: { | ||
format: {}, | ||
}, | ||
legend: { | ||
show: true, | ||
}, | ||
padding: null, | ||
size: { | ||
width: 240, | ||
height: 240, | ||
}, | ||
id: 'operatingsystem', | ||
axis: { | ||
x: { | ||
categories: ['Fedora 21', 'Ubuntu 14.04', 'Centos 7', 'Debian 8'], | ||
type: 'category', | ||
}, | ||
}, | ||
categories: ['Fedora 21', 'Ubuntu 14.04', 'Centos 7', 'Debian 8'], | ||
}; | ||
|
||
export const barChartConfigWithEmptyData = { | ||
...barChartConfig, | ||
data: { | ||
columns: [], | ||
type: 'bar', | ||
}, | ||
}; | ||
|
||
export const emptyData = null; |
7 changes: 7 additions & 0 deletions
7
webpack/assets/javascripts/react_app/components/common/charts/BarChart/BarChart.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@storybook/react'; | ||
import BarChart from './'; | ||
import { barChartData } from './BarChart.fixtures'; | ||
|
||
storiesOf('Components/Charts', module) | ||
.add('Bar Chart', () => <BarChart {...barChartData} />); |
23 changes: 23 additions & 0 deletions
23
webpack/assets/javascripts/react_app/components/common/charts/BarChart/BarChart.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { shallow } from 'enzyme'; | ||
import toJson from 'enzyme-to-json'; | ||
import React from 'react'; | ||
import BarChart from './'; | ||
import * as chartService from '../../../../../services/charts/BarChartService'; | ||
import { barChartConfig, barChartData, emptyData, barChartConfigWithEmptyData } from './BarChart.fixtures'; | ||
|
||
jest.unmock('./'); | ||
describe('renders BarChart', () => { | ||
it('render bar chart', () => { | ||
chartService.getBarChartConfig = jest.fn(() => barChartConfig); | ||
const wrapper = shallow(<BarChart data={barChartData.data} />); | ||
|
||
expect(toJson(wrapper)).toMatchSnapshot(); | ||
}); | ||
|
||
it('render empty state', () => { | ||
chartService.getBarChartConfig = jest.fn(() => barChartConfigWithEmptyData); | ||
const wrapper = shallow(<BarChart data={emptyData} />); | ||
|
||
expect(toJson(wrapper)).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.