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-5.1.0 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-5.0.1 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-5.0.0 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-4.8.0 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-4.5.6 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-4.5.5 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-4.5.4 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-4.7.0 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-4.5.3 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-4.5.2 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-4.5.1 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-4.6.0 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-4.5.0 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-4.4.0 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-4.3.1 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-4.3.0 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-4.2.3 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-4.2.2 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-4.2.1 webpack/react_app/components/jobInvocations/index.js
foreman_remote_execution-4.2.0 webpack/react_app/components/jobInvocations/index.js