import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { Grid, Col, Row, Tabs, Tab, Form, FormGroup, FormControl, ControlLabel } from 'react-bootstrap'; import { Button, Spinner } from 'patternfly-react'; import ForemanModal from 'foremanReact/components/ForemanModal'; import { translate as __ } from 'foremanReact/common/I18n'; import TooltipButton from '../../../components/TooltipButton'; import { LoadingState } from '../../../components/LoadingState'; import { Table } from '../../../components/pf3Table'; import { columns } from './ManifestHistoryTableSchema'; import DeleteManifestModalText from './DeleteManifestModalText'; import { MANAGE_MANIFEST_MODAL_ID, DELETE_MANIFEST_MODAL_ID } from './ManifestConstants'; import SimpleContentAccess from './SimpleContentAccess'; import './ManageManifestModal.scss'; class ManageManifestModal extends Component { constructor(props) { super(props); this.state = { redhat_repository_url: null, }; } componentDidMount() { this.props.loadManifestHistory(); } componentDidUpdate(prevProps) { if (!prevProps.taskInProgress && this.props.taskInProgress) { this.hideModal(); } if (prevProps.taskInProgress && !this.props.taskInProgress) { this.props.loadOrganization(); this.props.loadManifestHistory(); } if (!prevProps.manifestActionStarted && this.props.manifestActionStarted) { this.hideDeleteManifestModal(); } } hideModal = () => { this.props.setModalClosed({ id: MANAGE_MANIFEST_MODAL_ID }); }; showDeleteManifestModal = () => this.props.setModalOpen({ id: DELETE_MANIFEST_MODAL_ID }); hideDeleteManifestModal = () => this.props.setModalClosed({ id: DELETE_MANIFEST_MODAL_ID }); updateRepositoryUrl = (event) => { this.setState({ redhat_repository_url: event.target.value }); }; saveOrganization = () => { this.props.saveOrganization({ redhat_repository_url: this.state.redhat_repository_url }); }; uploadManifest = (fileList) => { if (fileList.length > 0) { this.props.upload(fileList[0]); } }; refreshManifest = () => { this.props.refresh(); }; deleteManifest = () => { this.props.delete(); }; disabledTooltipText = () => { if (this.props.taskInProgress) { 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, canImportManifest, canDeleteManifest, isManifestImported, canEditOrganizations, simpleContentAccess, enableSimpleContentAccess, disableSimpleContentAccess, taskInProgress, manifestActionStarted, } = this.props; const actionInProgress = (taskInProgress || manifestActionStarted); const showRedHatProviderDetails = canEditOrganizations; const showSubscriptionManifest = (canImportManifest || canDeleteManifest); const showManifestTab = (showRedHatProviderDetails || showSubscriptionManifest); const disableSCASwitch = ( disableManifestActions || !isManifestImported || actionInProgress || organization.loading ); 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 ( {showManifestTab && {showRedHatProviderDetails && {__('Red Hat Provider Details')} {__('Red Hat CDN URL')} {organization.loading ? buttonLoading : __('Update')} } {showSubscriptionManifest && {__('Subscription Manifest')} {__('Subscription Allocation')} {getManifestName()} {canImportManifest && {__('Import New Manifest')} } {canImportManifest && this.uploadManifest(e.target.files)} /> } {canImportManifest && } {canDeleteManifest && } {__('Cancel')} {__('Delete')} } } {__('Close')} ); } } ManageManifestModal.propTypes = { upload: PropTypes.func.isRequired, refresh: PropTypes.func.isRequired, delete: PropTypes.func.isRequired, enableSimpleContentAccess: PropTypes.func.isRequired, disableSimpleContentAccess: 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, canImportManifest: PropTypes.bool, canDeleteManifest: PropTypes.bool, isManifestImported: PropTypes.bool, canEditOrganizations: PropTypes.bool, disableManifestActions: PropTypes.bool, disabledReason: PropTypes.string, loadOrganization: PropTypes.func.isRequired, saveOrganization: PropTypes.func.isRequired, taskInProgress: PropTypes.bool.isRequired, simpleContentAccess: PropTypes.bool, manifestHistory: PropTypes.shape({ loading: PropTypes.bool, // Disabling rule as existing code failed due to an eslint-plugin-react update // eslint-disable-next-line react/forbid-prop-types results: PropTypes.array, }).isRequired, setModalClosed: PropTypes.func.isRequired, setModalOpen: PropTypes.func.isRequired, manifestActionStarted: PropTypes.bool, }; ManageManifestModal.defaultProps = { disableManifestActions: false, disabledReason: '', canImportManifest: false, canDeleteManifest: false, isManifestImported: false, canEditOrganizations: false, simpleContentAccess: false, manifestActionStarted: false, }; export default ManageManifestModal;