Sha256: 781326a1a62617fcfafe95b0ea1e60ea92f08e9b22be7849794d5f68524add2d

Contents?: true

Size: 1.69 KB

Versions: 2

Compression:

Stored size: 1.69 KB

Contents

import React from 'react';
import { useAPI } from 'foremanReact/common/hooks/API/APIHooks';
import PropTypes from 'prop-types';

import Skeleton from 'react-loading-skeleton';
import EmptyState from 'foremanReact/components/common/EmptyState/EmptyStatePattern';
import { STATUS } from 'foremanReact/constants';
import { EmptyStateIcon } from '@patternfly/react-core';
import { ExclamationCircleIcon } from '@patternfly/react-icons';
import { global_danger_color_200 as dangerColor } from '@patternfly/react-tokens';
import { translate as __ } from 'foremanReact/common/I18n';
import { ENCTab } from './ENCTab';

const ENCPreview = ({ hostName }) => {
  const options = {
    params: { name: hostName, format: 'yml' },
    key: 'PUPPET_ENC_PREVIEW',
  };
  const url = `${window.location.origin.toString()}/foreman_puppet/hosts/${hostName}/externalNodes`;
  const { response, status } = useAPI('get', url, options);

  if (status === STATUS.PENDING) {
    return <Skeleton count={5} />;
  }

  if (status === STATUS.ERROR || !hostName) {
    const description = !hostName
      ? __("Couldn't find any ENC data for this host")
      : response?.response?.data?.message;
    const icon = (
      <EmptyStateIcon icon={ExclamationCircleIcon} color={dangerColor.value} />
    );
    return (
      <EmptyState header={__('Error!')} icon={icon} description={description} />
    );
  }
  if (response !== '' || response !== undefined) {
    return (
      <div className="enc-preview-tab" padding="16px 24px">
        <ENCTab encData={response} />
      </div>
    );
  }

  return null;
};

ENCPreview.propTypes = {
  hostName: PropTypes.string,
};

ENCPreview.defaultProps = {
  hostName: undefined,
};

export default ENCPreview;

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
foreman_puppet-4.0.3 webpack/src/Extends/Host/PuppetTab/SubTabs/ENCPreview/index.js
foreman_puppet-4.0.2 webpack/src/Extends/Host/PuppetTab/SubTabs/ENCPreview/index.js