import React from 'react';
import PropTypes from 'prop-types';
import { Grid, GridItem } from '@patternfly/react-core';
import { cloneDeep, remove } from 'lodash';
import ChartBox from 'foremanReact/components/ChartBox/ChartBox';
import { translate as __ } from 'foremanReact/common/I18n';
import { STATUS } from 'foremanReact/constants';
import './HostReportMetrics.scss';
const HostReportMetrics = ({
metrics: {
time: { values: timeValues },
resources: { values: resValues },
},
}) => {
const clonedTimeValues = cloneDeep(timeValues).filter(v => v[2] >= 0.001);
const totalTime = remove(clonedTimeValues, val => val[0] === 'total');
const metricsChartData = clonedTimeValues
.map(v => [v[1], parseFloat(v[2].toFixed(4))])
.sort((a, b) => b[1] - a[1]);
const clonedStatuses = cloneDeep(resValues);
const totalStatuses = remove(clonedStatuses, val => val[0] === 'total');
const statuses = clonedStatuses
.map(v => [v[1], v[2]])
.sort((a, b) => b[1] - a[1]);
const createRow = ([name, value], i) => (
{name} |
{value} |
);
const chartBoxProps = {
className: 'report-chart',
noDataMsg: __('No data available'),
status: STATUS.RESOLVED,
config: 'medium',
};
return (
{statuses.map((label, v) => createRow(label, v))}
{totalStatuses.length ? (
{__('Total')} |
{totalStatuses[0][2]} |
) : null}
{metricsChartData.map((label, t) => createRow(label, t))}
{totalTime.length ? (
{__('Total')} |
{parseFloat(totalTime[0][2].toFixed(4))} |
) : null}
);
};
HostReportMetrics.propTypes = {
metrics: PropTypes.shape({
time: PropTypes.shape({
values: PropTypes.array,
}),
resources: PropTypes.shape({
values: PropTypes.array,
}),
}).isRequired,
};
export default HostReportMetrics;