Skip to content

Commit 6139030

Browse files
authored
Merge pull request #1184 from processing/revert-1181-revert-1176-bug/add-file
Revert "Revert "fixes #963: fixes bug in which files/folders would get added to""
2 parents 25e89b1 + 9d8be89 commit 6139030

File tree

5 files changed

+17
-27
lines changed

5 files changed

+17
-27
lines changed

client/modules/IDE/actions/files.js

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,7 @@ export function updateFileContent(id, content) {
4141
export function createFile(formProps) {
4242
return (dispatch, getState) => {
4343
const state = getState();
44-
const selectedFile = state.files.find(file => file.isSelectedFile);
45-
const rootFile = state.files.find(file => file.name === 'root');
46-
let parentId;
47-
if (selectedFile.fileType === 'folder') {
48-
parentId = selectedFile.id;
49-
} else {
50-
parentId = rootFile.id;
51-
}
44+
const { parentId } = state.ide;
5245
if (state.project.id) {
5346
const postParams = {
5447
name: createUniqueName(formProps.name, parentId, state.files),
@@ -99,14 +92,7 @@ export function createFile(formProps) {
9992
export function createFolder(formProps) {
10093
return (dispatch, getState) => {
10194
const state = getState();
102-
const selectedFile = state.files.find(file => file.isSelectedFile);
103-
const rootFile = state.files.find(file => file.name === 'root');
104-
let parentId;
105-
if (selectedFile.fileType === 'folder') {
106-
parentId = selectedFile.id;
107-
} else {
108-
parentId = rootFile.id;
109-
}
95+
const { parentId } = state.ide;
11096
if (state.project.id) {
11197
const postParams = {
11298
name: createUniqueName(formProps.name, parentId, state.files),

client/modules/IDE/actions/ide.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ export function resetSelectedFile(previousId) {
6262
};
6363
}
6464

65-
export function newFile() {
65+
export function newFile(parentId) {
6666
return {
67-
type: ActionTypes.SHOW_MODAL
67+
type: ActionTypes.SHOW_MODAL,
68+
parentId
6869
};
6970
}
7071

@@ -122,9 +123,10 @@ export function closeProjectOptions() {
122123
};
123124
}
124125

125-
export function newFolder() {
126+
export function newFolder(parentId) {
126127
return {
127-
type: ActionTypes.SHOW_NEW_FOLDER_MODAL
128+
type: ActionTypes.SHOW_NEW_FOLDER_MODAL,
129+
parentId
128130
};
129131
}
130132

client/modules/IDE/components/FileNode.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export class FileNode extends React.Component {
188188
<button
189189
aria-label="add file"
190190
onClick={() => {
191-
this.props.newFile();
191+
this.props.newFile(this.props.id);
192192
setTimeout(() => this.hideFileOptions(), 0);
193193
}}
194194
onBlur={this.onBlurComponent}
@@ -208,7 +208,7 @@ export class FileNode extends React.Component {
208208
<button
209209
aria-label="add folder"
210210
onClick={() => {
211-
this.props.newFolder();
211+
this.props.newFolder(this.props.id);
212212
setTimeout(() => this.hideFileOptions(), 0);
213213
}}
214214
onBlur={this.onBlurComponent}

client/modules/IDE/components/Sidebar.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class Sidebar extends React.Component {
6666
'sidebar--project-options': this.props.projectOptionsVisible,
6767
'sidebar--cant-edit': !canEditProject
6868
});
69+
const rootFile = this.props.files.filter(file => file.name === 'root')[0];
6970

7071
return (
7172
<nav className={sidebarClass} title="file-navigation" >
@@ -90,7 +91,7 @@ class Sidebar extends React.Component {
9091
<button
9192
aria-label="add folder"
9293
onClick={() => {
93-
this.props.newFolder();
94+
this.props.newFolder(rootFile.id);
9495
setTimeout(this.props.closeProjectOptions, 0);
9596
}}
9697
onBlur={this.onBlurComponent}
@@ -103,7 +104,7 @@ class Sidebar extends React.Component {
103104
<button
104105
aria-label="add file"
105106
onClick={() => {
106-
this.props.newFile();
107+
this.props.newFile(rootFile.id);
107108
setTimeout(this.props.closeProjectOptions, 0);
108109
}}
109110
onBlur={this.onBlurComponent}
@@ -116,7 +117,7 @@ class Sidebar extends React.Component {
116117
</div>
117118
</div>
118119
<ConnectedFileNode
119-
id={this.props.files.filter(file => file.name === 'root')[0].id}
120+
id={rootFile.id}
120121
canEdit={canEditProject}
121122
/>
122123
</nav>

client/modules/IDE/reducers/ide.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const initialState = {
2424
previousPath: '/',
2525
errorType: undefined,
2626
runtimeErrorWarningVisible: true,
27+
parentId: undefined
2728
};
2829

2930
const ide = (state = initialState, action) => {
@@ -39,7 +40,7 @@ const ide = (state = initialState, action) => {
3940
case ActionTypes.CONSOLE_EVENT:
4041
return Object.assign({}, state, { consoleEvent: action.event });
4142
case ActionTypes.SHOW_MODAL:
42-
return Object.assign({}, state, { modalIsVisible: true });
43+
return Object.assign({}, state, { modalIsVisible: true, parentId: action.parentId });
4344
case ActionTypes.HIDE_MODAL:
4445
return Object.assign({}, state, { modalIsVisible: false });
4546
case ActionTypes.COLLAPSE_SIDEBAR:
@@ -61,7 +62,7 @@ const ide = (state = initialState, action) => {
6162
case ActionTypes.CLOSE_PROJECT_OPTIONS:
6263
return Object.assign({}, state, { projectOptionsVisible: false });
6364
case ActionTypes.SHOW_NEW_FOLDER_MODAL:
64-
return Object.assign({}, state, { newFolderModalVisible: true });
65+
return Object.assign({}, state, { newFolderModalVisible: true, parentId: action.parentId });
6566
case ActionTypes.CLOSE_NEW_FOLDER_MODAL:
6667
return Object.assign({}, state, { newFolderModalVisible: false });
6768
case ActionTypes.SHOW_SHARE_MODAL:

0 commit comments

Comments
 (0)