import PropTypes from 'prop-types'; import React, { Component } from 'react'; import Form from 'Components/Form/Form'; import FormGroup from 'Components/Form/FormGroup'; import FormInputGroup from 'Components/Form/FormInputGroup'; import FormLabel from 'Components/Form/FormLabel'; import Button from 'Components/Link/Button'; import SpinnerErrorButton from 'Components/Link/SpinnerErrorButton'; import LoadingIndicator from 'Components/Loading/LoadingIndicator'; import Measure from 'Components/Measure'; import ModalBody from 'Components/Modal/ModalBody'; import ModalContent from 'Components/Modal/ModalContent'; import ModalFooter from 'Components/Modal/ModalFooter'; import ModalHeader from 'Components/Modal/ModalHeader'; import { inputTypes, kinds, sizes } from 'Helpers/Props'; import dimensions from 'Styles/Variables/dimensions'; import QualityProfileItems from './QualityProfileItems'; import styles from './EditQualityProfileModalContent.css'; const MODAL_BODY_PADDING = parseInt(dimensions.modalBodyPadding); class EditQualityProfileModalContent extends Component { // // Lifecycle constructor(props, context) { super(props, context); this.state = { headerHeight: 0, bodyHeight: 0, footerHeight: 0 }; } componentDidUpdate(prevProps, prevState) { const { headerHeight, bodyHeight, footerHeight } = this.state; if ( headerHeight > 0 && bodyHeight > 0 && footerHeight > 0 && ( headerHeight !== prevState.headerHeight || bodyHeight !== prevState.bodyHeight || footerHeight !== prevState.footerHeight ) ) { const padding = MODAL_BODY_PADDING * 2; this.props.onContentHeightChange( headerHeight + bodyHeight + footerHeight + padding ); } } // // Listeners onHeaderMeasure = ({ height }) => { if (height > this.state.headerHeight) { this.setState({ headerHeight: height }); } } onBodyMeasure = ({ height }) => { if (height > this.state.bodyHeight) { this.setState({ bodyHeight: height }); } } onFooterMeasure = ({ height }) => { if (height > this.state.footerHeight) { this.setState({ footerHeight: height }); } } // // Render render() { const { editGroups, isFetching, error, isSaving, saveError, qualities, item, isInUse, onInputChange, onCutoffChange, onSavePress, onModalClose, onDeleteQualityProfilePress, ...otherProps } = this.props; const { id, name, upgradeAllowed, cutoff, items } = item; return ( {id ? 'Edit Quality Profile' : 'Add Quality Profile'}
{ isFetching && } { !isFetching && !!error &&
Unable to add a new quality profile, please try again.
} { !isFetching && !error &&
Name Upgrades Allowed { upgradeAllowed.value && Upgrade Until }
}
{ id &&
} Save
); } } EditQualityProfileModalContent.propTypes = { editGroups: PropTypes.bool.isRequired, isFetching: PropTypes.bool.isRequired, error: PropTypes.object, isSaving: PropTypes.bool.isRequired, saveError: PropTypes.object, qualities: PropTypes.arrayOf(PropTypes.object).isRequired, item: PropTypes.object.isRequired, isInUse: PropTypes.bool.isRequired, onInputChange: PropTypes.func.isRequired, onCutoffChange: PropTypes.func.isRequired, onSavePress: PropTypes.func.isRequired, onContentHeightChange: PropTypes.func.isRequired, onModalClose: PropTypes.func.isRequired, onDeleteQualityProfilePress: PropTypes.func }; export default EditQualityProfileModalContent;