for 989, updated folder cannot be renamed to empty string

This commit is contained in:
Rachel Lim 2019-07-11 02:05:43 -04:00 committed by Cassie Tarakajian
parent b94ca8a52d
commit 1dd723cb9f

View file

@ -68,20 +68,12 @@ export class FileNode extends React.Component {
const oldFileExtension = this.originalFileName.match(/\.[0-9a-z]+$/i);
const newFileExtension = this.props.name.match(/\.[0-9a-z]+$/i);
const newFileName = this.props.name;
if (oldFileExtension && !newFileExtension) {
this.props.updateFileName(this.props.id, this.originalFileName);
}
if (
oldFileExtension &&
newFileExtension &&
oldFileExtension[0].toLowerCase() !== newFileExtension[0].toLowerCase()
) {
this.props.updateFileName(this.props.id, this.originalFileName);
}
if (newFileName === '') {
this.props.updateFileName(this.props.id, this.originalFileName);
}
if (newFileName === newFileExtension[0]) {
const hasNoExtension = oldFileExtension && !newFileExtension;
const notSameExtension = oldFileExtension && newFileExtension &&
oldFileExtension[0].toLowerCase() !== newFileExtension[0].toLowerCase();
const hasEmptyFilename = newFileName === '';
const hasOnlyExtension = newFileExtension && newFileName === newFileExtension[0];
if (hasEmptyFilename || hasNoExtension || notSameExtension || hasOnlyExtension) {
this.props.updateFileName(this.props.id, this.originalFileName);
}
}