Sha256: c9b3496395101de23bde56b8cb7c6222cf0fc11e0d056c36d19294ec08638fb8

Contents?: true

Size: 1.99 KB

Versions: 50

Compression:

Stored size: 1.99 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';
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

50 entries across 50 versions & 1 rubygems

Version Path
foreman_remote_execution-8.1.2 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-8.1.1 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-8.1.0 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-7.2.2 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-7.2.1 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-7.2.0 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-5.0.8 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-8.0.0 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-7.1.1 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-7.1.0 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-7.0.0 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-5.0.7 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-5.0.6 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-6.2.0 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-5.0.5 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-6.1.0 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-5.0.4 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-5.0.3 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-6.0.0 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-5.0.2 webpack/react_app/components/jobInvocations/index.js