From ddec33270e28dc1f46b6f3f1722b69c20e261642 Mon Sep 17 00:00:00 2001 From: ghalestrilo Date: Thu, 16 Apr 2020 10:55:58 -0300 Subject: [PATCH] :ok_hand: undoing changes, fixing call duplication on FileNode#updateFilename --- client/modules/IDE/actions/project.js | 3 +-- client/modules/IDE/components/FileNode.jsx | 27 +++++++++++----------- client/modules/IDE/components/Sidebar.jsx | 1 - client/modules/IDE/reducers/files.js | 2 +- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/client/modules/IDE/actions/project.js b/client/modules/IDE/actions/project.js index 8f2153f5..2621d5c6 100644 --- a/client/modules/IDE/actions/project.js +++ b/client/modules/IDE/actions/project.js @@ -132,8 +132,7 @@ export function saveProject(selectedFile = null, autosave = false) { return Promise.reject(); } const formParams = Object.assign({}, state.project); - formParams.files = [...state.files.map(file => ({ ...file, name: file.updatedName || file.name }))]; - formParams.files.forEach((file) => { delete file.updatedName; }); + formParams.files = [...state.files]; if (selectedFile) { const fileToUpdate = formParams.files.find(file => file.id === selectedFile.id); diff --git a/client/modules/IDE/components/FileNode.jsx b/client/modules/IDE/components/FileNode.jsx index 1b348ea9..c345de87 100644 --- a/client/modules/IDE/components/FileNode.jsx +++ b/client/modules/IDE/components/FileNode.jsx @@ -48,7 +48,7 @@ export class FileNode extends React.Component { }, 200); } - getName() { + get updatedName() { return this.state.updatedName; } @@ -63,7 +63,7 @@ export class FileNode extends React.Component { handleFileClick(e) { e.stopPropagation(); - if (this.getName() !== 'root' && !this.isDeleting) { + if (this.updatedName !== 'root' && !this.isDeleting) { this.props.setSelectedFile(this.props.id); } } @@ -81,9 +81,9 @@ export class FileNode extends React.Component { validateFileName() { const oldFileExtension = this.originalFileName.match(/\.[0-9a-z]+$/i); - const newFileExtension = this.getName().match(/\.[0-9a-z]+$/i); - const hasPeriod = this.getName().match(/\.+/); - const newFileName = this.getName(); + const newFileExtension = this.updatedName.match(/\.[0-9a-z]+$/i); + const hasPeriod = this.updatedName.match(/\.+/); + const newFileName = this.updatedName; const hasNoExtension = oldFileExtension && !newFileExtension; const hasExtensionIfFolder = this.props.fileType === 'folder' && hasPeriod; const notSameExtension = oldFileExtension && newFileExtension @@ -92,7 +92,9 @@ export class FileNode extends React.Component { const hasOnlyExtension = newFileExtension && newFileName === newFileExtension[0]; if (hasEmptyFilename || hasNoExtension || notSameExtension || hasOnlyExtension || hasExtensionIfFolder) { this.props.updateFileName(this.props.id, this.originalFileName); + return; } + this.commitFileNameChange(); } toggleFileOptions(e) { @@ -118,7 +120,6 @@ export class FileNode extends React.Component { hideEditFileName() { this.setState({ isEditingName: false }); - this.commitFileNameChange(); } renderChild(childId) { @@ -131,8 +132,8 @@ export class FileNode extends React.Component { render() { const itemClass = classNames({ - 'sidebar__root-item': this.getName() === 'root', - 'sidebar__file-item': this.getName() !== 'root', + 'sidebar__root-item': this.updatedName === 'root', + 'sidebar__file-item': this.updatedName !== 'root', 'sidebar__file-item--selected': this.props.isSelectedFile, 'sidebar__file-item--open': this.state.isOptionsOpen, 'sidebar__file-item--editing': this.state.isEditingName, @@ -142,7 +143,7 @@ export class FileNode extends React.Component { return (
{(() => { // eslint-disable-line - if (this.getName() !== 'root') { + if (this.updatedName !== 'root') { return (
@@ -171,11 +172,11 @@ export class FileNode extends React.Component {
); })()} - + { this.fileNameInput = element; }} @@ -241,7 +242,7 @@ export class FileNode extends React.Component {