Sha256: 854b61c7bfd64d45570eb51c55b2edea95345774cb1d25d5311d57e34596e05c

Contents?: true

Size: 1.96 KB

Versions: 22

Compression:

Stored size: 1.96 KB

Contents

import React from 'react';
import PropTypes from 'prop-types';
import { useSelector } from 'react-redux';
import URI from 'urijs';
import { List, ListItem, Modal, Button } from '@patternfly/react-core';
import { translate as __, sprintf } from 'foremanReact/common/I18n';
import { foremanUrl } from 'foremanReact/common/helpers';
import { selectHosts, selectHostCount } from '../../JobWizardSelectors';
import { HOSTS_TO_PREVIEW_AMOUNT } from '../../JobWizardConstants';

export const HostPreviewModal = ({ isOpen, setIsOpen, searchQuery }) => {
  const hosts = useSelector(selectHosts);
  const hostsCount = useSelector(selectHostCount);
  const url = new URI(foremanUrl('/hosts'));

  return (
    <Modal
      title={__('Preview Hosts')}
      isOpen={isOpen}
      onClose={() => setIsOpen(false)}
      appendTo={() => document.getElementsByClassName('job-wizard')[0]}
    >
      <List isPlain>
        {hosts.map(host => (
          <ListItem key={host}>
            <Button
              component="a"
              href={foremanUrl(`/hosts/${host}`)}
              variant="link"
              target="_blank"
              rel="noreferrer"
              isInline
            >
              {host}
            </Button>
          </ListItem>
        ))}
        {hostsCount > HOSTS_TO_PREVIEW_AMOUNT && (
          <ListItem>
            <Button
              component="a"
              href={url.addSearch({ search: searchQuery })}
              variant="link"
              target="_blank"
              rel="noreferrer"
              isInline
            >
              {sprintf(
                __('...and %s more'),
                hostsCount - HOSTS_TO_PREVIEW_AMOUNT
              )}
            </Button>
          </ListItem>
        )}
      </List>
    </Modal>
  );
};

HostPreviewModal.propTypes = {
  isOpen: PropTypes.bool.isRequired,
  setIsOpen: PropTypes.func.isRequired,
  searchQuery: PropTypes.string.isRequired,
};
HostPreviewModal.defaultPropTypes = {
  searchQuery: '',
};

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
foreman_remote_execution-12.0.7 webpack/JobWizard/steps/HostsAndInputs/HostPreviewModal.js
foreman_remote_execution-10.1.3 webpack/JobWizard/steps/HostsAndInputs/HostPreviewModal.js
foreman_remote_execution-12.0.5 webpack/JobWizard/steps/HostsAndInputs/HostPreviewModal.js
foreman_remote_execution-12.0.4 webpack/JobWizard/steps/HostsAndInputs/HostPreviewModal.js
foreman_remote_execution-12.0.1 webpack/JobWizard/steps/HostsAndInputs/HostPreviewModal.js
foreman_remote_execution-12.0.2 webpack/JobWizard/steps/HostsAndInputs/HostPreviewModal.js
foreman_remote_execution-11.1.3 webpack/JobWizard/steps/HostsAndInputs/HostPreviewModal.js
foreman_remote_execution-10.1.2 webpack/JobWizard/steps/HostsAndInputs/HostPreviewModal.js
foreman_remote_execution-12.0.0 webpack/JobWizard/steps/HostsAndInputs/HostPreviewModal.js
foreman_remote_execution-10.1.1 webpack/JobWizard/steps/HostsAndInputs/HostPreviewModal.js
foreman_remote_execution-11.1.1 webpack/JobWizard/steps/HostsAndInputs/HostPreviewModal.js
foreman_remote_execution-11.1.0 webpack/JobWizard/steps/HostsAndInputs/HostPreviewModal.js
foreman_remote_execution-10.1.0 webpack/JobWizard/steps/HostsAndInputs/HostPreviewModal.js
foreman_remote_execution-11.0.0 webpack/JobWizard/steps/HostsAndInputs/HostPreviewModal.js
foreman_remote_execution-10.0.7 webpack/JobWizard/steps/HostsAndInputs/HostPreviewModal.js
foreman_remote_execution-10.0.6 webpack/JobWizard/steps/HostsAndInputs/HostPreviewModal.js
foreman_remote_execution-10.0.5 webpack/JobWizard/steps/HostsAndInputs/HostPreviewModal.js
foreman_remote_execution-10.0.4 webpack/JobWizard/steps/HostsAndInputs/HostPreviewModal.js
foreman_remote_execution-10.0.3 webpack/JobWizard/steps/HostsAndInputs/HostPreviewModal.js
foreman_remote_execution-10.0.2 webpack/JobWizard/steps/HostsAndInputs/HostPreviewModal.js