Sha256: 76ba87f77617fef70e5915b1ec53e154a18c96efa0745804b4118345ac3063b6

Contents?: true

Size: 1.93 KB

Versions: 16

Compression:

Stored size: 1.93 KB

Contents

import { connect } from 'react-redux';
import React from 'react';
import Immutable from 'seamless-immutable';
import PropTypes from 'prop-types';
// eslint-disable-next-line import/no-extraneous-dependencies
import DonutChart from 'foremanReact/components/common/charts/DonutChart';
import AggregateStatus from './AggregateStatus/index.js';
import * as JobInvocationActions from '../../redux/actions/jobInvocations';

const colIndexOfMaxValue = columns => columns.reduce((iMax, x, i, arr) => (x[1] > arr[iMax][1] ? i : iMax), 0);

class JobInvocationContainer extends React.Component {
  componentDidMount() {
    const { startJobInvocationsPolling, data: { url } } = this.props;

    startJobInvocationsPolling(url);
  }

  render() {
    const { jobInvocations, statuses } = this.props;
    const iMax = colIndexOfMaxValue(jobInvocations);

    return (
      <div id="job_invocations_chart_container">
        <DonutChart data={Immutable.asMutable(jobInvocations)}
                    title={{type: 'percent', secondary: (jobInvocations[iMax] || [])[0]}}/>
        <AggregateStatus statuses={statuses} />
      </div>
    );
  }
}

const mapStateToProps = (state) => {
  const {
    jobInvocations,
    statuses,
  } = state.foremanRemoteExecutionReducers.jobInvocations;

  return {
    jobInvocations,
    statuses,
  };
};

JobInvocationContainer.propTypes = {
  startJobInvocationsPolling: PropTypes.func,
  data: PropTypes.shape({
    url: PropTypes.string,
  }),
  jobInvocations: PropTypes.arrayOf(PropTypes.array),
  statuses: PropTypes.shape({
    cancelled: PropTypes.number,
    failed: PropTypes.number,
    pending: PropTypes.number,
    success: PropTypes.number,
  }),
};

JobInvocationContainer.defaultProps = {
  startJobInvocationsPolling: JobInvocationActions.startJobInvocationsPolling,
  data: {},
  jobInvocations: [['property', 3, 'color']],
  statuses: {},
};
export default connect(mapStateToProps, JobInvocationActions)(JobInvocationContainer);

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
foreman_remote_execution-3.2.2 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-3.2.1 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-3.2.0 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-3.1.0 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-2.0.10 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-2.0.9 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-2.0.8 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-3.0.3 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-3.0.2 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-2.0.7 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-3.0.1 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-3.0.0 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-2.0.6 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-2.0.5 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-2.0.4 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-2.0.3 webpack/react_app/components/jobInvocations/index.js