import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { Col, Tabs, Tab, Form, FormGroup, FormControl, ControlLabel } from 'react-bootstrap'; import { Button, Icon, Modal, Spinner, OverlayTrigger, Tooltip, MessageDialog } from 'patternfly-react'; import { isEqual } from 'lodash'; import TooltipButton from '../../../move_to_pf/TooltipButton'; import { LoadingState } from '../../../move_to_pf/LoadingState'; import { Table } from '../../../move_to_foreman/components/common/table'; import { manifestExists } from '../SubscriptionHelpers'; import { columns } from './ManifestHistoryTableSchema'; import DeleteManifestModalText from './DeleteManifestModalText'; class ManageManifestModal extends Component { constructor(props) { super(props); this.state = { showModal: props.showModal, actionInProgress: props.taskInProgress, showDeleteManifestModalDialog: false, }; } static getDerivedStateFromProps(newProps, prevState) { if ( !isEqual(newProps.showModal, prevState.showModal) || !isEqual(newProps.taskInProgress, prevState.actionInProgress) ) { return { showModal: newProps.showModal, actionInProgress: newProps.taskInProgress, }; } return null; } componentDidMount() { this.loadData(); } componentDidUpdate(prevProp, prevState) { const { actionInProgress } = this.state; if (prevState.actionInProgress && !actionInProgress) { this.props.loadOrganization(); } } loadData() { this.props.loadManifestHistory(); } hideModal = () => { this.setState({ showModal: false, showDeleteManifestModalDialog: false }); this.props.onClose(); }; updateRepositoryUrl = (event) => { this.setState({ redhat_repository_url: event.target.value }); }; saveOrganization = () => { this.props.saveOrganization({ redhat_repository_url: this.state.redhat_repository_url }); }; uploadManifest = (fileList) => { this.hideModal(); this.setState({ actionInProgress: true }); if (fileList.length > 0) { this.props.upload(fileList[0]); } }; refreshManifest = () => { this.hideModal(); this.setState({ actionInProgress: true }); this.props.refresh(); }; deleteManifest = () => { this.hideModal(); this.setState({ actionInProgress: true }); this.props.delete(); this.showDeleteManifestModal(false); }; showDeleteManifestModal = (show) => { this.setState({ showDeleteManifestModalDialog: show, }); }; disabledTooltipText = () => { if (this.state.actionInProgress) { return __('This is disabled because a manifest task is in progress'); } return __('This is disabled because no manifest exists'); }; render() { const { manifestHistory, organization, disableManifestActions, disabledReason, } = this.props; const { actionInProgress } = this.state; const emptyStateData = () => ({ header: __('There is no Manifest History to display.'), description: __('Import a Manifest using the manifest tab above.'), documentation: { label: __('Learn more about adding Subscription Manifests'), url: 'http://redhat.com', }, }); const buttonLoading = ( {__('Updating...')} ); const getManifestName = () => { let name = __('No Manifest Uploaded'); if ( organization.owner_details && organization.owner_details.upstreamConsumer ) { const link = [ 'https://', organization.owner_details.upstreamConsumer.webUrl, organization.owner_details.upstreamConsumer.uuid, ].join('/'); name = ( {organization.owner_details.upstreamConsumer.name} ); } return name; }; return ( {__('Manage Manifest')}
{__('Red Hat Provider Details')}

{__('Red Hat CDN URL')}
{__('Subscription Manifest')}

{__('Upstream Subscription Management Application')} } placement="bottom" trigger={['hover', 'focus']} rootClose={false} > {__('USMA')} {getManifestName()} this.uploadManifest(e.target.files)} /> this.showDeleteManifestModal(true)} > {__('Delete')} )} tooltipId="delete-manifest-button-tooltip" tooltipText={this.disabledTooltipText()} tooltipPlacement="top" /> } primaryActionButtonContent={__('Delete')} primaryActionButtonBsStyle="danger" primaryAction={() => this.deleteManifest()} secondaryActionButtonContent={__('Cancel')} secondaryAction={() => this.showDeleteManifestModal(false)} onHide={() => this.showDeleteManifestModal(false)} accessibleName="deleteConfirmationDialog" accessibleDescription="deleteConfirmationDialogContent" />
); } } ManageManifestModal.propTypes = { upload: PropTypes.func.isRequired, refresh: PropTypes.func.isRequired, delete: PropTypes.func.isRequired, loadManifestHistory: PropTypes.func.isRequired, organization: PropTypes.shape({ loading: PropTypes.bool, redhat_repository_url: PropTypes.string, owner_details: PropTypes.shape({ upstreamConsumer: PropTypes.shape({ uuid: PropTypes.string, name: PropTypes.string, webUrl: PropTypes.string, }), }), }).isRequired, disableManifestActions: PropTypes.bool, disabledReason: PropTypes.string, loadOrganization: PropTypes.func.isRequired, saveOrganization: PropTypes.func.isRequired, taskInProgress: PropTypes.bool.isRequired, manifestHistory: PropTypes.shape({ loading: PropTypes.bool, results: PropTypes.array, }).isRequired, showModal: PropTypes.bool.isRequired, onClose: PropTypes.func, }; ManageManifestModal.defaultProps = { disableManifestActions: false, disabledReason: '', onClose() {}, }; export default ManageManifestModal;