Move handleUploadClick from inline function, prevent user from uploading to folder if not authenticated

This commit is contained in:
Cassie Tarakajian 2020-04-16 16:08:51 -04:00
parent 9185447168
commit 41637d2837
2 changed files with 22 additions and 15 deletions

View file

@ -24,6 +24,7 @@ describe('<FileNode />', () => {
showFolderChildren: jest.fn(), showFolderChildren: jest.fn(),
hideFolderChildren: jest.fn(), hideFolderChildren: jest.fn(),
canEdit: true, canEdit: true,
authenticated: false
}; };
component = shallow(<FileNode {...props} />); component = shallow(<FileNode {...props} />);
}); });

View file

@ -87,6 +87,11 @@ export class FileNode extends React.Component {
setTimeout(() => this.hideFileOptions(), 0); setTimeout(() => this.hideFileOptions(), 0);
} }
handleClickUploadFile = () => {
this.props.openUploadFileModal(this.props.id);
setTimeout(this.hideFileOptions, 0);
}
handleClickDelete = () => { handleClickDelete = () => {
if (window.confirm(`Are you sure you want to delete ${this.props.name}?`)) { if (window.confirm(`Are you sure you want to delete ${this.props.name}?`)) {
this.setState({ isDeleting: true }); this.setState({ isDeleting: true });
@ -252,19 +257,18 @@ export class FileNode extends React.Component {
Create file Create file
</button> </button>
</li> </li>
<li> { this.props.authenticated &&
<button <li>
aria-label="upload file" <button
onClick={() => { aria-label="upload file"
this.props.openUploadFileModal(this.props.id); onClick={this.handleClickUploadFile}
setTimeout(this.hideFileOptions, 0); onBlur={this.onBlurComponent}
}} onFocus={this.onFocusComponent}
onBlur={this.onBlurComponent} >
onFocus={this.onFocusComponent} Upload file
> </button>
Upload file </li>
</button> }
</li>
</React.Fragment> </React.Fragment>
} }
<li> <li>
@ -318,7 +322,8 @@ FileNode.propTypes = {
showFolderChildren: PropTypes.func.isRequired, showFolderChildren: PropTypes.func.isRequired,
hideFolderChildren: PropTypes.func.isRequired, hideFolderChildren: PropTypes.func.isRequired,
canEdit: PropTypes.bool.isRequired, canEdit: PropTypes.bool.isRequired,
openUploadFileModal: PropTypes.func.isRequired openUploadFileModal: PropTypes.func.isRequired,
authenticated: PropTypes.bool.isRequired
}; };
FileNode.defaultProps = { FileNode.defaultProps = {
@ -329,7 +334,8 @@ FileNode.defaultProps = {
function mapStateToProps(state, ownProps) { function mapStateToProps(state, ownProps) {
// this is a hack, state is updated before ownProps // this is a hack, state is updated before ownProps
return state.files.find(file => file.id === ownProps.id) || { name: 'test', fileType: 'file' }; const fileNode = state.files.find(file => file.id === ownProps.id) || { name: 'test', fileType: 'file' };
return Object.assign({}, fileNode, { authenticated: state.user.authenticated });
} }
function mapDispatchToProps(dispatch) { function mapDispatchToProps(dispatch) {