Skip to content

Commit 2f21130

Browse files
jareddonovancatarak
authored andcommitted
Fix needs saving mark 2 - for #576 (#658)
* Comment out show/hide file options action creators. * Comment out show/hide file options properties * Comment out show/hide file options action definitions * Comment out constants for show/hide options action types * Comment out props for show/hide options and replace with component state. * Comment out show/hide edit file name reducers. * Comment out show/hide edit file name actions. * comment out show/hide edit file name action types. * Comment out show/edit file name props from IDEView component * Replace show/hide edit filename props in FileNode component with local state * Remove commented out code from previous changes for moving redux state back into component state. * Add binding to this for new functions. And tidy up of code.
1 parent 4a2d6d3 commit 2f21130

File tree

5 files changed

+29
-90
lines changed

5 files changed

+29
-90
lines changed

client/constants.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,8 @@ export const COLLAPSE_CONSOLE = 'COLLAPSE_CONSOLE';
5959
export const UPDATE_LINT_MESSAGE = 'UPDATE_LINT_MESSAGE';
6060
export const CLEAR_LINT_MESSAGE = 'CLEAR_LINT_MESSAGE';
6161

62-
export const SHOW_FILE_OPTIONS = 'SHOW_FILE_OPTIONS';
63-
export const HIDE_FILE_OPTIONS = 'HIDE_FILE_OPTIONS';
64-
6562
export const UPDATE_FILE_NAME = 'UPDATE_FILE_NAME';
6663
export const DELETE_FILE = 'DELETE_FILE';
67-
export const SHOW_EDIT_FILE_NAME = 'SHOW_EDIT_FILE_NAME';
68-
export const HIDE_EDIT_FILE_NAME = 'HIDE_EDIT_FILE_NAME';
6964

7065
export const SET_AUTOSAVE = 'SET_AUTOSAVE';
7166
export const SET_LINT_WARNING = 'SET_LINT_WARNING';

client/modules/IDE/actions/files.js

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -147,34 +147,6 @@ export function createFolder(formProps) {
147147
};
148148
}
149149

150-
export function showFileOptions(fileId) {
151-
return {
152-
type: ActionTypes.SHOW_FILE_OPTIONS,
153-
id: fileId
154-
};
155-
}
156-
157-
export function hideFileOptions(fileId) {
158-
return {
159-
type: ActionTypes.HIDE_FILE_OPTIONS,
160-
id: fileId
161-
};
162-
}
163-
164-
export function showEditFileName(id) {
165-
return {
166-
type: ActionTypes.SHOW_EDIT_FILE_NAME,
167-
id
168-
};
169-
}
170-
171-
export function hideEditFileName(id) {
172-
return {
173-
type: ActionTypes.HIDE_EDIT_FILE_NAME,
174-
id
175-
};
176-
}
177-
178150
export function updateFileName(id, name) {
179151
return {
180152
type: ActionTypes.UPDATE_FILE_NAME,

client/modules/IDE/components/FileNode.jsx

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ export class FileNode extends React.Component {
2121
this.validateFileName = this.validateFileName.bind(this);
2222
this.handleFileClick = this.handleFileClick.bind(this);
2323
this.toggleFileOptions = this.toggleFileOptions.bind(this);
24+
this.hideFileOptions = this.hideFileOptions.bind(this);
25+
this.showEditFileName = this.showEditFileName.bind(this);
26+
this.hideEditFileName = this.hideEditFileName.bind(this);
27+
28+
this.state = {
29+
isOptionsOpen: false,
30+
isEditingName: false,
31+
};
2432
}
2533

2634
handleFileClick(e) {
@@ -36,7 +44,7 @@ export class FileNode extends React.Component {
3644

3745
handleKeyPress(event) {
3846
if (event.key === 'Enter') {
39-
this.props.hideEditFileName(this.props.id);
47+
this.hideEditFileName();
4048
}
4149
}
4250

@@ -57,14 +65,26 @@ export class FileNode extends React.Component {
5765

5866
toggleFileOptions(e) {
5967
e.preventDefault();
60-
if (this.props.isOptionsOpen) {
61-
this.props.hideFileOptions(this.props.id);
68+
if (this.state.isOptionsOpen) {
69+
this.setState({ isOptionsOpen: false });
6270
} else {
6371
this[`fileOptions-${this.props.id}`].focus();
64-
this.props.showFileOptions(this.props.id);
72+
this.setState({ isOptionsOpen: true });
6573
}
6674
}
6775

76+
hideFileOptions() {
77+
this.setState({ isOptionsOpen: false });
78+
}
79+
80+
showEditFileName() {
81+
this.setState({ isEditingName: true });
82+
}
83+
84+
hideEditFileName() {
85+
this.setState({ isEditingName: false });
86+
}
87+
6888
renderChild(childId) {
6989
return (
7090
<li key={childId}>
@@ -78,8 +98,8 @@ export class FileNode extends React.Component {
7898
'sidebar__root-item': this.props.name === 'root',
7999
'sidebar__file-item': this.props.name !== 'root',
80100
'sidebar__file-item--selected': this.props.isSelectedFile,
81-
'sidebar__file-item--open': this.props.isOptionsOpen,
82-
'sidebar__file-item--editing': this.props.isEditingName,
101+
'sidebar__file-item--open': this.state.isOptionsOpen,
102+
'sidebar__file-item--editing': this.state.isEditingName,
83103
'sidebar__file-item--closed': this.props.isFolderClosed
84104
});
85105
return (
@@ -123,7 +143,7 @@ export class FileNode extends React.Component {
123143
ref={(element) => { this.fileNameInput = element; }}
124144
onBlur={() => {
125145
this.validateFileName();
126-
this.props.hideEditFileName(this.props.id);
146+
this.hideEditFileName();
127147
}}
128148
onKeyPress={this.handleKeyPress}
129149
/>
@@ -133,7 +153,7 @@ export class FileNode extends React.Component {
133153
ref={(element) => { this[`fileOptions-${this.props.id}`] = element; }}
134154
tabIndex="0"
135155
onClick={this.toggleFileOptions}
136-
onBlur={() => setTimeout(() => this.props.hideFileOptions(this.props.id), 200)}
156+
onBlur={() => setTimeout(this.hideFileOptions, 200)}
137157
>
138158
<InlineSVG src={downArrowUrl} />
139159
</button>
@@ -173,7 +193,7 @@ export class FileNode extends React.Component {
173193
<button
174194
onClick={() => {
175195
this.originalFileName = this.props.name;
176-
this.props.showEditFileName(this.props.id);
196+
this.showEditFileName();
177197
setTimeout(() => this.fileNameInput.focus(), 0);
178198
}}
179199
className="sidebar__file-item-option"
@@ -222,15 +242,9 @@ FileNode.propTypes = {
222242
name: PropTypes.string.isRequired,
223243
fileType: PropTypes.string.isRequired,
224244
isSelectedFile: PropTypes.bool,
225-
isOptionsOpen: PropTypes.bool,
226-
isEditingName: PropTypes.bool,
227245
isFolderClosed: PropTypes.bool,
228246
setSelectedFile: PropTypes.func.isRequired,
229-
showFileOptions: PropTypes.func.isRequired,
230-
hideFileOptions: PropTypes.func.isRequired,
231247
deleteFile: PropTypes.func.isRequired,
232-
showEditFileName: PropTypes.func.isRequired,
233-
hideEditFileName: PropTypes.func.isRequired,
234248
updateFileName: PropTypes.func.isRequired,
235249
resetSelectedFile: PropTypes.func.isRequired,
236250
newFile: PropTypes.func.isRequired,
@@ -242,8 +256,6 @@ FileNode.propTypes = {
242256
FileNode.defaultProps = {
243257
parentId: '0',
244258
isSelectedFile: false,
245-
isOptionsOpen: false,
246-
isEditingName: false,
247259
isFolderClosed: false
248260
};
249261

client/modules/IDE/pages/IDEView.jsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,7 @@ class IDEView extends React.Component {
296296
setSelectedFile={this.props.setSelectedFile}
297297
newFile={this.props.newFile}
298298
isExpanded={this.props.ide.sidebarIsExpanded}
299-
showFileOptions={this.props.showFileOptions}
300-
hideFileOptions={this.props.hideFileOptions}
301299
deleteFile={this.props.deleteFile}
302-
showEditFileName={this.props.showEditFileName}
303-
hideEditFileName={this.props.hideEditFileName}
304300
updateFileName={this.props.updateFileName}
305301
projectOptionsVisible={this.props.ide.projectOptionsVisible}
306302
openProjectOptions={this.props.openProjectOptions}
@@ -624,11 +620,7 @@ IDEView.propTypes = {
624620
cloneProject: PropTypes.func.isRequired,
625621
expandConsole: PropTypes.func.isRequired,
626622
collapseConsole: PropTypes.func.isRequired,
627-
showFileOptions: PropTypes.func.isRequired,
628-
hideFileOptions: PropTypes.func.isRequired,
629623
deleteFile: PropTypes.func.isRequired,
630-
showEditFileName: PropTypes.func.isRequired,
631-
hideEditFileName: PropTypes.func.isRequired,
632624
updateFileName: PropTypes.func.isRequired,
633625
showEditProjectName: PropTypes.func.isRequired,
634626
hideEditProjectName: PropTypes.func.isRequired,

client/modules/IDE/reducers/files.js

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -155,22 +155,6 @@ const files = (state, action) => {
155155
fileType: action.fileType || 'file'
156156
}];
157157
}
158-
case ActionTypes.SHOW_FILE_OPTIONS:
159-
return state.map((file) => {
160-
if (file.id !== action.id) {
161-
return file;
162-
}
163-
164-
return Object.assign({}, file, { isOptionsOpen: true });
165-
});
166-
case ActionTypes.HIDE_FILE_OPTIONS:
167-
return state.map((file) => {
168-
if (file.id !== action.id) {
169-
return file;
170-
}
171-
172-
return Object.assign({}, file, { isOptionsOpen: false });
173-
});
174158
case ActionTypes.UPDATE_FILE_NAME:
175159
return state.map((file) => {
176160
if (file.id !== action.id) {
@@ -192,22 +176,6 @@ const files = (state, action) => {
192176
// });
193177
// return newState.filter(file => file.id !== action.id);
194178
}
195-
case ActionTypes.SHOW_EDIT_FILE_NAME:
196-
return state.map((file) => {
197-
if (file.id !== action.id) {
198-
return file;
199-
}
200-
201-
return Object.assign({}, file, { isEditingName: true });
202-
});
203-
case ActionTypes.HIDE_EDIT_FILE_NAME:
204-
return state.map((file) => {
205-
if (file.id !== action.id) {
206-
return file;
207-
}
208-
209-
return Object.assign({}, file, { isEditingName: false });
210-
});
211179
case ActionTypes.SET_SELECTED_FILE:
212180
return state.map((file) => {
213181
if (file.id === action.selectedFile) {

0 commit comments

Comments
 (0)