import React from 'react';
import PropTypes from 'prop-types';
import { capitalize } from 'lodash';
import classNames from 'classnames';
import { Icon, Button } from 'patternfly-react';
import { translate as __ } from 'foremanReact/common/I18n';
import {
TASKS_DASHBOARD_AVAILABLE_QUERY_STATES,
TASKS_DASHBOARD_AVAILABLE_QUERY_MODES,
} from '../../../../TasksDashboardConstants';
import { getQueryValueText } from '../../../../TasksDashboardHelper';
import {
timePropType,
queryPropType,
} from '../../../../TasksDashboardPropTypes';
const resultIcons = {
error: ,
warning: ,
success: ,
};
const StoppedTableCells = (data, query, time, updateQuery) =>
Object.entries(data).map(([result, { total, last }]) => {
const { STOPPED } = TASKS_DASHBOARD_AVAILABLE_QUERY_STATES;
const { LAST } = TASKS_DASHBOARD_AVAILABLE_QUERY_MODES;
const { state, mode } = query;
const active = state === STOPPED && query.result === result;
const activeTotal = active && mode !== LAST;
const activeLast = active && mode === LAST && query.time === time;
const notFocusedTotal =
state && !(state === STOPPED && !query.result) && !activeTotal;
const notFocusedLast =
state && !(state === STOPPED && !query.result) && !activeLast;
return (
{resultIcons[result]}
{capitalize(result)}
|
updateQuery({ state: STOPPED, result })}
>
|
updateQuery({
state: STOPPED,
result,
mode: LAST,
time,
})
}
>
|
);
});
export const StoppedTable = ({ data, query, time, updateQuery }) => (
|
{__('Total')} |
{getQueryValueText(time)} |
{StoppedTableCells(data, query, time, updateQuery)}
);
StoppedTable.propTypes = {
data: PropTypes.object.isRequired,
query: queryPropType.isRequired,
time: timePropType.isRequired,
updateQuery: PropTypes.func.isRequired,
};