Sha256: 30ca375b4a51ab169adcdce0e164a30056890d8ec1b480de3e4c285aba954121

Contents?: true

Size: 1.78 KB

Versions: 13

Compression:

Stored size: 1.78 KB

Contents

import React, { useEffect, useRef } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import PropTypes from 'prop-types';

import PreupgradeReports from './PreupgradeReports';

import getCsrfToken from '../../csrf';

import {
  selectPreupgradeReports,
  selectLoadingPreupgradeReports,
  selectReportsExpected,
  selectError,
  selectJobInvocationsPolling,
} from './PreupgradeReportsSelectors';

import { getPreupgradeReportsAction } from './PreupgradeReportsActions';

const WrappedPreupgradeReports = ({ url, newJobInvocationUrl }) => {
  const loading = useSelector(state => selectLoadingPreupgradeReports(state));
  const preupgradeReports = useSelector(state =>
    selectPreupgradeReports(state)
  );
  const error = useSelector(state => selectError(state));

  const invocationPending = useSelector(state =>
    selectJobInvocationsPolling(state)
  );

  const reportsExpected = useSelector(state => selectReportsExpected(state));

  const previousInvocationRef = useRef();
  useEffect(() => {
    previousInvocationRef.current = invocationPending;
  });

  const previousInvocationPending = previousInvocationRef.current;

  const dispatch = useDispatch();

  useEffect(() => {
    if (previousInvocationPending && !invocationPending) {
      dispatch(getPreupgradeReportsAction(url));
    }
  }, [dispatch, url, invocationPending, previousInvocationPending]);

  return (
    <PreupgradeReports
      preupgradeReports={preupgradeReports}
      error={error}
      loading={loading}
      csrfToken={getCsrfToken()}
      newJobInvocationUrl={newJobInvocationUrl}
      reportsExpected={reportsExpected}
    />
  );
};

WrappedPreupgradeReports.propTypes = {
  url: PropTypes.string.isRequired,
  newJobInvocationUrl: PropTypes.string.isRequired,
};

export default WrappedPreupgradeReports;

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
foreman_leapp-0.1.12 webpack/components/PreupgradeReports/index.js
foreman_leapp-0.1.11 webpack/components/PreupgradeReports/index.js
foreman_leapp-0.1.10 webpack/components/PreupgradeReports/index.js
foreman_leapp-0.1.9 webpack/components/PreupgradeReports/index.js
foreman_leapp-0.1.8 webpack/components/PreupgradeReports/index.js
foreman_leapp-0.1.7 webpack/components/PreupgradeReports/index.js
foreman_leapp-0.1.6 webpack/components/PreupgradeReports/index.js
foreman_leapp-0.1.5 webpack/components/PreupgradeReports/index.js
foreman_leapp-0.1.4 webpack/components/PreupgradeReports/index.js
foreman_leapp-0.1.3 webpack/components/PreupgradeReports/index.js
foreman_leapp-0.1.2 webpack/components/PreupgradeReports/index.js
foreman_leapp-0.1.1 webpack/components/PreupgradeReports/index.js
foreman_leapp-0.1.0 webpack/components/PreupgradeReports/index.js