Skip to content

Revert "Revert "fixes #963: fixes bug in which files/folders would get added to"" #1184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions client/modules/IDE/actions/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,7 @@ export function updateFileContent(id, content) {
export function createFile(formProps) {
return (dispatch, getState) => {
const state = getState();
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;
}
const { parentId } = state.ide;
if (state.project.id) {
const postParams = {
name: createUniqueName(formProps.name, parentId, state.files),
Expand Down Expand Up @@ -99,14 +92,7 @@ export function createFile(formProps) {
export function createFolder(formProps) {
return (dispatch, getState) => {
const state = getState();
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;
}
const { parentId } = state.ide;
if (state.project.id) {
const postParams = {
name: createUniqueName(formProps.name, parentId, state.files),
Expand Down
10 changes: 6 additions & 4 deletions client/modules/IDE/actions/ide.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ export function resetSelectedFile(previousId) {
};
}

export function newFile() {
export function newFile(parentId) {
return {
type: ActionTypes.SHOW_MODAL
type: ActionTypes.SHOW_MODAL,
parentId
};
}

Expand Down Expand Up @@ -122,9 +123,10 @@ export function closeProjectOptions() {
};
}

export function newFolder() {
export function newFolder(parentId) {
return {
type: ActionTypes.SHOW_NEW_FOLDER_MODAL
type: ActionTypes.SHOW_NEW_FOLDER_MODAL,
parentId
};
}

Expand Down
4 changes: 2 additions & 2 deletions client/modules/IDE/components/FileNode.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export class FileNode extends React.Component {
<button
aria-label="add file"
onClick={() => {
this.props.newFile();
this.props.newFile(this.props.id);
setTimeout(() => this.hideFileOptions(), 0);
}}
onBlur={this.onBlurComponent}
Expand All @@ -208,7 +208,7 @@ export class FileNode extends React.Component {
<button
aria-label="add folder"
onClick={() => {
this.props.newFolder();
this.props.newFolder(this.props.id);
setTimeout(() => this.hideFileOptions(), 0);
}}
onBlur={this.onBlurComponent}
Expand Down
7 changes: 4 additions & 3 deletions client/modules/IDE/components/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class Sidebar extends React.Component {
'sidebar--project-options': this.props.projectOptionsVisible,
'sidebar--cant-edit': !canEditProject
});
const rootFile = this.props.files.filter(file => file.name === 'root')[0];

return (
<nav className={sidebarClass} title="file-navigation" >
Expand All @@ -90,7 +91,7 @@ class Sidebar extends React.Component {
<button
aria-label="add folder"
onClick={() => {
this.props.newFolder();
this.props.newFolder(rootFile.id);
setTimeout(this.props.closeProjectOptions, 0);
}}
onBlur={this.onBlurComponent}
Expand All @@ -103,7 +104,7 @@ class Sidebar extends React.Component {
<button
aria-label="add file"
onClick={() => {
this.props.newFile();
this.props.newFile(rootFile.id);
setTimeout(this.props.closeProjectOptions, 0);
}}
onBlur={this.onBlurComponent}
Expand All @@ -116,7 +117,7 @@ class Sidebar extends React.Component {
</div>
</div>
<ConnectedFileNode
id={this.props.files.filter(file => file.name === 'root')[0].id}
id={rootFile.id}
canEdit={canEditProject}
/>
</nav>
Expand Down
5 changes: 3 additions & 2 deletions client/modules/IDE/reducers/ide.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const initialState = {
previousPath: '/',
errorType: undefined,
runtimeErrorWarningVisible: true,
parentId: undefined
};

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