import PropTypes from 'prop-types'; import React, { Component } from 'react'; import ReactDOM from 'react-dom'; import Alert from 'Components/Alert'; import PathInput from 'Components/Form/PathInput'; import Button from 'Components/Link/Button'; import Link from 'Components/Link/Link'; import LoadingIndicator from 'Components/Loading/LoadingIndicator'; 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 Scroller from 'Components/Scroller/Scroller'; import Table from 'Components/Table/Table'; import TableBody from 'Components/Table/TableBody'; import { kinds, scrollDirections } from 'Helpers/Props'; import FileBrowserRow from './FileBrowserRow'; import styles from './FileBrowserModalContent.css'; const columns = [ { name: 'type', label: 'Type', isVisible: true }, { name: 'name', label: 'Name', isVisible: true } ]; class FileBrowserModalContent extends Component { // // Lifecycle constructor(props, context) { super(props, context); this._scrollerNode = null; this.state = { isFileBrowserModalOpen: false, currentPath: props.value }; } componentDidUpdate(prevProps, prevState) { const { currentPath } = this.props; if ( currentPath !== this.state.currentPath && currentPath !== prevState.currentPath ) { this.setState({ currentPath }); this._scrollerNode.scrollTop = 0; } } // // Control setScrollerRef = (ref) => { if (ref) { this._scrollerNode = ReactDOM.findDOMNode(ref); } else { this._scrollerNode = null; } } // // Listeners onPathInputChange = ({ value }) => { this.setState({ currentPath: value }); } onRowPress = (path) => { this.props.onFetchPaths(path); } onOkPress = () => { this.props.onChange({ name: this.props.name, value: this.state.currentPath }); this.props.onClearPaths(); this.props.onModalClose(); } // // Render render() { const { isFetching, isPopulated, error, parent, directories, files, isWindowsService, onModalClose, ...otherProps } = this.props; const emptyParent = parent === ''; return ( File Browser { isWindowsService && Mapped network drives are not available when running as a Windows Service, see the FAQ for more information. } { !!error &&
Error loading contents
} { isPopulated && !error && { emptyParent && } { !emptyParent && parent && } { directories.map((directory) => { return ( ); }) } { files.map((file) => { return ( ); }) }
}
{ isFetching && }
); } } FileBrowserModalContent.propTypes = { name: PropTypes.string.isRequired, value: PropTypes.string.isRequired, isFetching: PropTypes.bool.isRequired, isPopulated: PropTypes.bool.isRequired, error: PropTypes.object, parent: PropTypes.string, currentPath: PropTypes.string.isRequired, directories: PropTypes.arrayOf(PropTypes.object).isRequired, files: PropTypes.arrayOf(PropTypes.object).isRequired, isWindowsService: PropTypes.bool.isRequired, onFetchPaths: PropTypes.func.isRequired, onClearPaths: PropTypes.func.isRequired, onChange: PropTypes.func.isRequired, onModalClose: PropTypes.func.isRequired }; export default FileBrowserModalContent;