Merge pull request #1181 from processing/revert-1176-bug/add-file

Revert "fixes #963: fixes bug in which files/folders would get added to"
This commit is contained in:
Cassie Tarakajian 2019-10-07 18:24:13 -04:00 committed by GitHub
commit 25e89b1172
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 17 deletions

View file

@ -41,7 +41,14 @@ export function updateFileContent(id, content) {
export function createFile(formProps) { export function createFile(formProps) {
return (dispatch, getState) => { return (dispatch, getState) => {
const state = getState(); const state = getState();
const { parentId } = state.ide; const selectedFile = state.files.find(file => file.isSelectedFile);
const rootFile = state.files.find(file => file.name === 'root');
let parentId;
if (selectedFile.fileType === 'folder') {
parentId = selectedFile.id;
} else {
parentId = rootFile.id;
}
if (state.project.id) { if (state.project.id) {
const postParams = { const postParams = {
name: createUniqueName(formProps.name, parentId, state.files), name: createUniqueName(formProps.name, parentId, state.files),
@ -92,7 +99,14 @@ export function createFile(formProps) {
export function createFolder(formProps) { export function createFolder(formProps) {
return (dispatch, getState) => { return (dispatch, getState) => {
const state = getState(); const state = getState();
const { parentId } = state.ide; const selectedFile = state.files.find(file => file.isSelectedFile);
const rootFile = state.files.find(file => file.name === 'root');
let parentId;
if (selectedFile.fileType === 'folder') {
parentId = selectedFile.id;
} else {
parentId = rootFile.id;
}
if (state.project.id) { if (state.project.id) {
const postParams = { const postParams = {
name: createUniqueName(formProps.name, parentId, state.files), name: createUniqueName(formProps.name, parentId, state.files),

View file

@ -62,10 +62,9 @@ export function resetSelectedFile(previousId) {
}; };
} }
export function newFile(parentId) { export function newFile() {
return { return {
type: ActionTypes.SHOW_MODAL, type: ActionTypes.SHOW_MODAL
parentId
}; };
} }
@ -123,10 +122,9 @@ export function closeProjectOptions() {
}; };
} }
export function newFolder(parentId) { export function newFolder() {
return { return {
type: ActionTypes.SHOW_NEW_FOLDER_MODAL, type: ActionTypes.SHOW_NEW_FOLDER_MODAL
parentId
}; };
} }

View file

@ -188,7 +188,7 @@ export class FileNode extends React.Component {
<button <button
aria-label="add file" aria-label="add file"
onClick={() => { onClick={() => {
this.props.newFile(this.props.id); this.props.newFile();
setTimeout(() => this.hideFileOptions(), 0); setTimeout(() => this.hideFileOptions(), 0);
}} }}
onBlur={this.onBlurComponent} onBlur={this.onBlurComponent}
@ -208,7 +208,7 @@ export class FileNode extends React.Component {
<button <button
aria-label="add folder" aria-label="add folder"
onClick={() => { onClick={() => {
this.props.newFolder(this.props.id); this.props.newFolder();
setTimeout(() => this.hideFileOptions(), 0); setTimeout(() => this.hideFileOptions(), 0);
}} }}
onBlur={this.onBlurComponent} onBlur={this.onBlurComponent}

View file

@ -66,7 +66,6 @@ class Sidebar extends React.Component {
'sidebar--project-options': this.props.projectOptionsVisible, 'sidebar--project-options': this.props.projectOptionsVisible,
'sidebar--cant-edit': !canEditProject 'sidebar--cant-edit': !canEditProject
}); });
const rootFile = this.props.files.filter(file => file.name === 'root')[0];
return ( return (
<nav className={sidebarClass} title="file-navigation" > <nav className={sidebarClass} title="file-navigation" >
@ -91,7 +90,7 @@ class Sidebar extends React.Component {
<button <button
aria-label="add folder" aria-label="add folder"
onClick={() => { onClick={() => {
this.props.newFolder(rootFile.id); this.props.newFolder();
setTimeout(this.props.closeProjectOptions, 0); setTimeout(this.props.closeProjectOptions, 0);
}} }}
onBlur={this.onBlurComponent} onBlur={this.onBlurComponent}
@ -104,7 +103,7 @@ class Sidebar extends React.Component {
<button <button
aria-label="add file" aria-label="add file"
onClick={() => { onClick={() => {
this.props.newFile(rootFile.id); this.props.newFile();
setTimeout(this.props.closeProjectOptions, 0); setTimeout(this.props.closeProjectOptions, 0);
}} }}
onBlur={this.onBlurComponent} onBlur={this.onBlurComponent}
@ -117,7 +116,7 @@ class Sidebar extends React.Component {
</div> </div>
</div> </div>
<ConnectedFileNode <ConnectedFileNode
id={rootFile.id} id={this.props.files.filter(file => file.name === 'root')[0].id}
canEdit={canEditProject} canEdit={canEditProject}
/> />
</nav> </nav>

View file

@ -24,7 +24,6 @@ const initialState = {
previousPath: '/', previousPath: '/',
errorType: undefined, errorType: undefined,
runtimeErrorWarningVisible: true, runtimeErrorWarningVisible: true,
parentId: undefined
}; };
const ide = (state = initialState, action) => { const ide = (state = initialState, action) => {
@ -40,7 +39,7 @@ const ide = (state = initialState, action) => {
case ActionTypes.CONSOLE_EVENT: case ActionTypes.CONSOLE_EVENT:
return Object.assign({}, state, { consoleEvent: action.event }); return Object.assign({}, state, { consoleEvent: action.event });
case ActionTypes.SHOW_MODAL: case ActionTypes.SHOW_MODAL:
return Object.assign({}, state, { modalIsVisible: true, parentId: action.parentId }); return Object.assign({}, state, { modalIsVisible: true });
case ActionTypes.HIDE_MODAL: case ActionTypes.HIDE_MODAL:
return Object.assign({}, state, { modalIsVisible: false }); return Object.assign({}, state, { modalIsVisible: false });
case ActionTypes.COLLAPSE_SIDEBAR: case ActionTypes.COLLAPSE_SIDEBAR:
@ -62,7 +61,7 @@ const ide = (state = initialState, action) => {
case ActionTypes.CLOSE_PROJECT_OPTIONS: case ActionTypes.CLOSE_PROJECT_OPTIONS:
return Object.assign({}, state, { projectOptionsVisible: false }); return Object.assign({}, state, { projectOptionsVisible: false });
case ActionTypes.SHOW_NEW_FOLDER_MODAL: case ActionTypes.SHOW_NEW_FOLDER_MODAL:
return Object.assign({}, state, { newFolderModalVisible: true, parentId: action.parentId }); return Object.assign({}, state, { newFolderModalVisible: true });
case ActionTypes.CLOSE_NEW_FOLDER_MODAL: case ActionTypes.CLOSE_NEW_FOLDER_MODAL:
return Object.assign({}, state, { newFolderModalVisible: false }); return Object.assign({}, state, { newFolderModalVisible: false });
case ActionTypes.SHOW_SHARE_MODAL: case ActionTypes.SHOW_SHARE_MODAL: