2017-09-04 02:20:56 +00:00
|
|
|
import _ from 'lodash';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { createSelector } from 'reselect';
|
2020-09-07 01:33:10 +00:00
|
|
|
import { clearPaths, fetchPaths } from 'Store/Actions/pathActions';
|
2018-09-05 02:38:48 +00:00
|
|
|
import createSystemStatusSelector from 'Store/Selectors/createSystemStatusSelector';
|
2017-09-04 02:20:56 +00:00
|
|
|
import FileBrowserModalContent from './FileBrowserModalContent';
|
|
|
|
|
|
|
|
function createMapStateToProps() {
|
|
|
|
return createSelector(
|
|
|
|
(state) => state.paths,
|
2018-09-05 02:38:48 +00:00
|
|
|
createSystemStatusSelector(),
|
|
|
|
(paths, systemStatus) => {
|
2017-09-04 02:20:56 +00:00
|
|
|
const {
|
2018-01-26 03:01:53 +00:00
|
|
|
isFetching,
|
|
|
|
isPopulated,
|
|
|
|
error,
|
2017-09-04 02:20:56 +00:00
|
|
|
parent,
|
|
|
|
currentPath,
|
|
|
|
directories,
|
|
|
|
files
|
|
|
|
} = paths;
|
|
|
|
|
|
|
|
const filteredPaths = _.filter([...directories, ...files], ({ path }) => {
|
|
|
|
return path.toLowerCase().startsWith(currentPath.toLowerCase());
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
2018-01-26 03:01:53 +00:00
|
|
|
isFetching,
|
|
|
|
isPopulated,
|
|
|
|
error,
|
2017-09-04 02:20:56 +00:00
|
|
|
parent,
|
|
|
|
currentPath,
|
|
|
|
directories,
|
|
|
|
files,
|
2018-09-05 02:38:48 +00:00
|
|
|
paths: filteredPaths,
|
2018-09-23 03:10:50 +00:00
|
|
|
isWindowsService: systemStatus.isWindows && systemStatus.mode === 'service'
|
2017-09-04 02:20:56 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = {
|
2019-04-06 02:51:32 +00:00
|
|
|
dispatchFetchPaths: fetchPaths,
|
|
|
|
dispatchClearPaths: clearPaths
|
2017-09-04 02:20:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class FileBrowserModalContentConnector extends Component {
|
|
|
|
|
|
|
|
// Lifecycle
|
|
|
|
|
|
|
|
componentDidMount() {
|
2019-04-06 02:51:32 +00:00
|
|
|
const {
|
|
|
|
value,
|
|
|
|
includeFiles,
|
|
|
|
dispatchFetchPaths
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
dispatchFetchPaths({
|
|
|
|
path: value,
|
|
|
|
allowFoldersWithoutTrailingSlashes: true,
|
|
|
|
includeFiles
|
2018-08-11 00:46:34 +00:00
|
|
|
});
|
2017-09-04 02:20:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Listeners
|
|
|
|
|
|
|
|
onFetchPaths = (path) => {
|
2019-04-06 02:51:32 +00:00
|
|
|
const {
|
|
|
|
includeFiles,
|
|
|
|
dispatchFetchPaths
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
dispatchFetchPaths({
|
2018-08-11 00:46:34 +00:00
|
|
|
path,
|
2019-04-06 02:51:32 +00:00
|
|
|
allowFoldersWithoutTrailingSlashes: true,
|
|
|
|
includeFiles
|
2018-08-11 00:46:34 +00:00
|
|
|
});
|
2021-12-24 18:18:14 +00:00
|
|
|
};
|
2017-09-04 02:20:56 +00:00
|
|
|
|
|
|
|
onClearPaths = () => {
|
2019-04-06 02:51:32 +00:00
|
|
|
// this.props.dispatchClearPaths();
|
2021-12-24 18:18:14 +00:00
|
|
|
};
|
2017-09-04 02:20:56 +00:00
|
|
|
|
|
|
|
onModalClose = () => {
|
2019-04-06 02:51:32 +00:00
|
|
|
this.props.dispatchClearPaths();
|
2017-09-04 02:20:56 +00:00
|
|
|
this.props.onModalClose();
|
2021-12-24 18:18:14 +00:00
|
|
|
};
|
2017-09-04 02:20:56 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Render
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<FileBrowserModalContent
|
|
|
|
onFetchPaths={this.onFetchPaths}
|
|
|
|
onClearPaths={this.onClearPaths}
|
|
|
|
{...this.props}
|
|
|
|
onModalClose={this.onModalClose}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FileBrowserModalContentConnector.propTypes = {
|
|
|
|
value: PropTypes.string,
|
2019-04-06 02:51:32 +00:00
|
|
|
includeFiles: PropTypes.bool.isRequired,
|
|
|
|
dispatchFetchPaths: PropTypes.func.isRequired,
|
|
|
|
dispatchClearPaths: PropTypes.func.isRequired,
|
2017-09-04 02:20:56 +00:00
|
|
|
onModalClose: PropTypes.func.isRequired
|
|
|
|
};
|
|
|
|
|
2019-04-06 02:51:32 +00:00
|
|
|
FileBrowserModalContentConnector.defaultProps = {
|
|
|
|
includeFiles: false
|
|
|
|
};
|
|
|
|
|
2017-09-04 02:20:56 +00:00
|
|
|
export default connect(createMapStateToProps, mapDispatchToProps)(FileBrowserModalContentConnector);
|