Merge pull request #1372 from ghalestrilo/fix/rename-file-set-unsaved
Fixes #681 - File name update triggers editor change detection
This commit is contained in:
commit
33db5fb1ef
5 changed files with 314 additions and 212 deletions
71
client/components/__test__/FileNode.test.jsx
Normal file
71
client/components/__test__/FileNode.test.jsx
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
import React from 'react';
|
||||||
|
import { shallow } from 'enzyme';
|
||||||
|
import { FileNode } from '../../modules/IDE/components/FileNode';
|
||||||
|
|
||||||
|
beforeAll(() => {});
|
||||||
|
describe('<FileNode />', () => {
|
||||||
|
let component;
|
||||||
|
let props = {};
|
||||||
|
|
||||||
|
describe('with valid props', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
props = {
|
||||||
|
...props,
|
||||||
|
id: '0',
|
||||||
|
children: [],
|
||||||
|
name: 'test.jsx',
|
||||||
|
fileType: 'dunno',
|
||||||
|
setSelectedFile: jest.fn(),
|
||||||
|
deleteFile: jest.fn(),
|
||||||
|
updateFileName: jest.fn(),
|
||||||
|
resetSelectedFile: jest.fn(),
|
||||||
|
newFile: jest.fn(),
|
||||||
|
newFolder: jest.fn(),
|
||||||
|
showFolderChildren: jest.fn(),
|
||||||
|
hideFolderChildren: jest.fn(),
|
||||||
|
canEdit: true,
|
||||||
|
authenticated: false
|
||||||
|
};
|
||||||
|
component = shallow(<FileNode {...props} />);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when changing name', () => {
|
||||||
|
let input;
|
||||||
|
let renameTriggerButton;
|
||||||
|
const changeName = (newFileName) => {
|
||||||
|
renameTriggerButton.simulate('click');
|
||||||
|
input.simulate('change', { target: { value: newFileName } });
|
||||||
|
input.simulate('blur');
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
input = component.find('.sidebar__file-item-input');
|
||||||
|
renameTriggerButton = component
|
||||||
|
.find('.sidebar__file-item-option')
|
||||||
|
.first();
|
||||||
|
component.setState({ isEditing: true });
|
||||||
|
});
|
||||||
|
it('should render', () => expect(component).toBeDefined());
|
||||||
|
|
||||||
|
// it('should debug', () => console.log(component.debug()));
|
||||||
|
|
||||||
|
describe('to a valid filename', () => {
|
||||||
|
const newName = 'newname.jsx';
|
||||||
|
beforeEach(() => changeName(newName));
|
||||||
|
|
||||||
|
it('should save the name', () => {
|
||||||
|
expect(props.updateFileName).toBeCalledWith(props.id, newName);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('to an empty filename', () => {
|
||||||
|
const newName = '';
|
||||||
|
beforeEach(() => changeName(newName));
|
||||||
|
|
||||||
|
it('should not save the name', () => {
|
||||||
|
expect(props.updateFileName).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -136,10 +136,13 @@ export function createFolder(formProps) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateFileName(id, name) {
|
export function updateFileName(id, name) {
|
||||||
return {
|
return (dispatch) => {
|
||||||
type: ActionTypes.UPDATE_FILE_NAME,
|
dispatch(setUnsavedChanges(true));
|
||||||
id,
|
dispatch({
|
||||||
name
|
type: ActionTypes.UPDATE_FILE_NAME,
|
||||||
|
id,
|
||||||
|
name
|
||||||
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -133,6 +133,7 @@ export function saveProject(selectedFile = null, autosave = false) {
|
||||||
}
|
}
|
||||||
const formParams = Object.assign({}, state.project);
|
const formParams = Object.assign({}, state.project);
|
||||||
formParams.files = [...state.files];
|
formParams.files = [...state.files];
|
||||||
|
|
||||||
if (selectedFile) {
|
if (selectedFile) {
|
||||||
const fileToUpdate = formParams.files.find(file => file.id === selectedFile.id);
|
const fileToUpdate = formParams.files.find(file => file.id === selectedFile.id);
|
||||||
fileToUpdate.content = selectedFile.content;
|
fileToUpdate.content = selectedFile.content;
|
||||||
|
|
|
@ -6,39 +6,29 @@ import InlineSVG from 'react-inlinesvg';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import * as IDEActions from '../actions/ide';
|
import * as IDEActions from '../actions/ide';
|
||||||
import * as FileActions from '../actions/files';
|
import * as FileActions from '../actions/files';
|
||||||
|
import downArrowUrl from '../../../images/down-filled-triangle.svg';
|
||||||
const downArrowUrl = require('../../../images/down-filled-triangle.svg');
|
import folderRightUrl from '../../../images/triangle-arrow-right.svg';
|
||||||
const folderRightUrl = require('../../../images/triangle-arrow-right.svg');
|
import folderDownUrl from '../../../images/triangle-arrow-down.svg';
|
||||||
const folderDownUrl = require('../../../images/triangle-arrow-down.svg');
|
import fileUrl from '../../../images/file.svg';
|
||||||
const fileUrl = require('../../../images/file.svg');
|
|
||||||
|
|
||||||
export class FileNode extends React.Component {
|
export class FileNode extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.renderChild = this.renderChild.bind(this);
|
|
||||||
this.handleKeyPress = this.handleKeyPress.bind(this);
|
|
||||||
this.handleFileNameChange = this.handleFileNameChange.bind(this);
|
|
||||||
this.validateFileName = this.validateFileName.bind(this);
|
|
||||||
this.handleFileClick = this.handleFileClick.bind(this);
|
|
||||||
this.toggleFileOptions = this.toggleFileOptions.bind(this);
|
|
||||||
this.hideFileOptions = this.hideFileOptions.bind(this);
|
|
||||||
this.showEditFileName = this.showEditFileName.bind(this);
|
|
||||||
this.hideEditFileName = this.hideEditFileName.bind(this);
|
|
||||||
this.onBlurComponent = this.onBlurComponent.bind(this);
|
|
||||||
this.onFocusComponent = this.onFocusComponent.bind(this);
|
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
isOptionsOpen: false,
|
isOptionsOpen: false,
|
||||||
isEditingName: false,
|
isEditingName: false,
|
||||||
isFocused: false,
|
isFocused: false,
|
||||||
|
isDeleting: false,
|
||||||
|
updatedName: this.props.name
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
onFocusComponent() {
|
onFocusComponent = () => {
|
||||||
this.setState({ isFocused: true });
|
this.setState({ isFocused: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
onBlurComponent() {
|
onBlurComponent = () => {
|
||||||
this.setState({ isFocused: false });
|
this.setState({ isFocused: false });
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (!this.state.isFocused) {
|
if (!this.state.isFocused) {
|
||||||
|
@ -47,41 +37,96 @@ export class FileNode extends React.Component {
|
||||||
}, 200);
|
}, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleFileClick(e) {
|
|
||||||
e.stopPropagation();
|
setUpdatedName = (updatedName) => {
|
||||||
if (this.props.name !== 'root' && !this.isDeleting) {
|
this.setState({ updatedName });
|
||||||
this.props.setSelectedFile(this.props.id);
|
}
|
||||||
|
|
||||||
|
saveUpdatedFileName = () => {
|
||||||
|
const { updatedName } = this.state;
|
||||||
|
const { name, updateFileName, id } = this.props;
|
||||||
|
|
||||||
|
if (updatedName !== name) {
|
||||||
|
updateFileName(id, updatedName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleFileNameChange(event) {
|
handleFileClick = (event) => {
|
||||||
this.props.updateFileName(this.props.id, event.target.value);
|
event.stopPropagation();
|
||||||
|
const { isDeleting } = this.state;
|
||||||
|
const { id, setSelectedFile, name } = this.props;
|
||||||
|
if (name !== 'root' && !isDeleting) {
|
||||||
|
setSelectedFile(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleKeyPress(event) {
|
handleFileNameChange = (event) => {
|
||||||
|
const newName = event.target.value;
|
||||||
|
this.setUpdatedName(newName);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleFileNameBlur = () => {
|
||||||
|
this.validateFileName();
|
||||||
|
this.hideEditFileName();
|
||||||
|
}
|
||||||
|
|
||||||
|
handleClickRename = () => {
|
||||||
|
this.setUpdatedName(this.props.name);
|
||||||
|
this.showEditFileName();
|
||||||
|
setTimeout(() => this.fileNameInput.focus(), 0);
|
||||||
|
setTimeout(() => this.hideFileOptions(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleClickAddFile = () => {
|
||||||
|
this.props.newFile(this.props.id);
|
||||||
|
setTimeout(() => this.hideFileOptions(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleClickAddFolder = () => {
|
||||||
|
this.props.newFolder(this.props.id);
|
||||||
|
setTimeout(() => this.hideFileOptions(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleClickUploadFile = () => {
|
||||||
|
this.props.openUploadFileModal(this.props.id);
|
||||||
|
setTimeout(this.hideFileOptions, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleClickDelete = () => {
|
||||||
|
if (window.confirm(`Are you sure you want to delete ${this.props.name}?`)) {
|
||||||
|
this.setState({ isDeleting: true });
|
||||||
|
this.props.resetSelectedFile(this.props.id);
|
||||||
|
setTimeout(() => this.props.deleteFile(this.props.id, this.props.parentId), 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleKeyPress = (event) => {
|
||||||
if (event.key === 'Enter') {
|
if (event.key === 'Enter') {
|
||||||
this.hideEditFileName();
|
this.hideEditFileName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
validateFileName() {
|
validateFileName = () => {
|
||||||
const oldFileExtension = this.originalFileName.match(/\.[0-9a-z]+$/i);
|
const currentName = this.props.name;
|
||||||
const newFileExtension = this.props.name.match(/\.[0-9a-z]+$/i);
|
const { updatedName } = this.state;
|
||||||
const hasPeriod = this.props.name.match(/\.+/);
|
const oldFileExtension = currentName.match(/\.[0-9a-z]+$/i);
|
||||||
const newFileName = this.props.name;
|
const newFileExtension = updatedName.match(/\.[0-9a-z]+$/i);
|
||||||
|
const hasPeriod = updatedName.match(/\.+/);
|
||||||
const hasNoExtension = oldFileExtension && !newFileExtension;
|
const hasNoExtension = oldFileExtension && !newFileExtension;
|
||||||
const hasExtensionIfFolder = this.props.fileType === 'folder' && hasPeriod;
|
const hasExtensionIfFolder = this.props.fileType === 'folder' && hasPeriod;
|
||||||
const notSameExtension = oldFileExtension && newFileExtension
|
const notSameExtension = oldFileExtension && newFileExtension
|
||||||
&& oldFileExtension[0].toLowerCase() !== newFileExtension[0].toLowerCase();
|
&& oldFileExtension[0].toLowerCase() !== newFileExtension[0].toLowerCase();
|
||||||
const hasEmptyFilename = newFileName === '';
|
const hasEmptyFilename = updatedName.trim() === '';
|
||||||
const hasOnlyExtension = newFileExtension && newFileName === newFileExtension[0];
|
const hasOnlyExtension = newFileExtension && updatedName.trim() === newFileExtension[0];
|
||||||
if (hasEmptyFilename || hasNoExtension || notSameExtension || hasOnlyExtension || hasExtensionIfFolder) {
|
if (hasEmptyFilename || hasNoExtension || notSameExtension || hasOnlyExtension || hasExtensionIfFolder) {
|
||||||
this.props.updateFileName(this.props.id, this.originalFileName);
|
this.setUpdatedName(currentName);
|
||||||
|
} else {
|
||||||
|
this.saveUpdatedFileName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleFileOptions(e) {
|
toggleFileOptions = (event) => {
|
||||||
e.preventDefault();
|
event.preventDefault();
|
||||||
if (!this.props.canEdit) {
|
if (!this.props.canEdit) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -93,26 +138,32 @@ export class FileNode extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hideFileOptions() {
|
hideFileOptions = () => {
|
||||||
this.setState({ isOptionsOpen: false });
|
this.setState({ isOptionsOpen: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
showEditFileName() {
|
showEditFileName = () => {
|
||||||
this.setState({ isEditingName: true });
|
this.setState({ isEditingName: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
hideEditFileName() {
|
hideEditFileName = () => {
|
||||||
this.setState({ isEditingName: false });
|
this.setState({ isEditingName: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
renderChild(childId) {
|
showFolderChildren = () => {
|
||||||
return (
|
this.props.showFolderChildren(this.props.id);
|
||||||
<li key={childId}>
|
|
||||||
<ConnectedFileNode id={childId} parentId={this.props.id} canEdit={this.props.canEdit} />
|
|
||||||
</li>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hideFolderChildren = () => {
|
||||||
|
this.props.hideFolderChildren(this.props.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
renderChild = childId => (
|
||||||
|
<li key={childId}>
|
||||||
|
<ConnectedFileNode id={childId} parentId={this.props.id} canEdit={this.props.canEdit} />
|
||||||
|
</li>
|
||||||
|
)
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const itemClass = classNames({
|
const itemClass = classNames({
|
||||||
'sidebar__root-item': this.props.name === 'root',
|
'sidebar__root-item': this.props.name === 'root',
|
||||||
|
@ -123,161 +174,132 @@ export class FileNode extends React.Component {
|
||||||
'sidebar__file-item--closed': this.props.isFolderClosed
|
'sidebar__file-item--closed': this.props.isFolderClosed
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const isFile = this.props.fileType === 'file';
|
||||||
|
const isFolder = this.props.fileType === 'folder';
|
||||||
|
const isRoot = this.props.name === 'root';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={itemClass}>
|
<div className={itemClass}>
|
||||||
{(() => { // eslint-disable-line
|
{ !isRoot &&
|
||||||
if (this.props.name !== 'root') {
|
<div className="file-item__content" onContextMenu={this.toggleFileOptions}>
|
||||||
return (
|
<span className="file-item__spacer"></span>
|
||||||
<div className="file-item__content" onContextMenu={this.toggleFileOptions}>
|
{ isFile &&
|
||||||
<span className="file-item__spacer"></span>
|
<span className="sidebar__file-item-icon">
|
||||||
{(() => { // eslint-disable-line
|
<InlineSVG src={fileUrl} />
|
||||||
if (this.props.fileType === 'file') {
|
</span>
|
||||||
return (
|
}
|
||||||
<span className="sidebar__file-item-icon">
|
{ isFolder &&
|
||||||
<InlineSVG src={fileUrl} />
|
<div className="sidebar__file-item--folder">
|
||||||
</span>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<div className="sidebar__file-item--folder">
|
|
||||||
<button
|
|
||||||
className="sidebar__file-item-closed"
|
|
||||||
onClick={() => this.props.showFolderChildren(this.props.id)}
|
|
||||||
>
|
|
||||||
<InlineSVG className="folder-right" src={folderRightUrl} />
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
className="sidebar__file-item-open"
|
|
||||||
onClick={() => this.props.hideFolderChildren(this.props.id)}
|
|
||||||
>
|
|
||||||
<InlineSVG className="folder-down" src={folderDownUrl} />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
})()}
|
|
||||||
<button className="sidebar__file-item-name" onClick={this.handleFileClick}>{this.props.name}</button>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
className="sidebar__file-item-input"
|
|
||||||
value={this.props.name}
|
|
||||||
maxLength="128"
|
|
||||||
onChange={this.handleFileNameChange}
|
|
||||||
ref={(element) => { this.fileNameInput = element; }}
|
|
||||||
onBlur={() => {
|
|
||||||
this.validateFileName();
|
|
||||||
this.hideEditFileName();
|
|
||||||
}}
|
|
||||||
onKeyPress={this.handleKeyPress}
|
|
||||||
/>
|
|
||||||
<button
|
<button
|
||||||
className="sidebar__file-item-show-options"
|
className="sidebar__file-item-closed"
|
||||||
aria-label="view file options"
|
onClick={this.showFolderChildren}
|
||||||
ref={(element) => { this[`fileOptions-${this.props.id}`] = element; }}
|
|
||||||
tabIndex="0"
|
|
||||||
onClick={this.toggleFileOptions}
|
|
||||||
onBlur={this.onBlurComponent}
|
|
||||||
onFocus={this.onFocusComponent}
|
|
||||||
>
|
>
|
||||||
<InlineSVG src={downArrowUrl} />
|
<InlineSVG className="folder-right" src={folderRightUrl} />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="sidebar__file-item-open"
|
||||||
|
onClick={this.hideFolderChildren}
|
||||||
|
>
|
||||||
|
<InlineSVG className="folder-down" src={folderDownUrl} />
|
||||||
</button>
|
</button>
|
||||||
<div className="sidebar__file-item-options">
|
|
||||||
<ul title="file options">
|
|
||||||
{(() => { // eslint-disable-line
|
|
||||||
if (this.props.fileType === 'folder') {
|
|
||||||
return (
|
|
||||||
<React.Fragment>
|
|
||||||
<li>
|
|
||||||
<button
|
|
||||||
aria-label="add folder"
|
|
||||||
onClick={() => {
|
|
||||||
this.props.newFolder(this.props.id);
|
|
||||||
setTimeout(this.hideFileOptions, 0);
|
|
||||||
}}
|
|
||||||
onBlur={this.onBlurComponent}
|
|
||||||
onFocus={this.onFocusComponent}
|
|
||||||
className="sidebar__file-item-option"
|
|
||||||
>
|
|
||||||
Create folder
|
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<button
|
|
||||||
aria-label="add file"
|
|
||||||
onClick={() => {
|
|
||||||
this.props.newFile(this.props.id);
|
|
||||||
setTimeout(this.hideFileOptions, 0);
|
|
||||||
}}
|
|
||||||
onBlur={this.onBlurComponent}
|
|
||||||
onFocus={this.onFocusComponent}
|
|
||||||
className="sidebar__file-item-option"
|
|
||||||
>
|
|
||||||
Create file
|
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<button
|
|
||||||
aria-label="upload file"
|
|
||||||
onClick={() => {
|
|
||||||
this.props.openUploadFileModal(this.props.id);
|
|
||||||
setTimeout(this.hideFileOptions, 0);
|
|
||||||
}}
|
|
||||||
onBlur={this.onBlurComponent}
|
|
||||||
onFocus={this.onFocusComponent}
|
|
||||||
>
|
|
||||||
Upload file
|
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
</React.Fragment>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
})()}
|
|
||||||
<li>
|
|
||||||
<button
|
|
||||||
onClick={() => {
|
|
||||||
this.originalFileName = this.props.name;
|
|
||||||
this.showEditFileName();
|
|
||||||
setTimeout(() => this.fileNameInput.focus(), 0);
|
|
||||||
setTimeout(() => this.hideFileOptions(), 0);
|
|
||||||
}}
|
|
||||||
onBlur={this.onBlurComponent}
|
|
||||||
onFocus={this.onFocusComponent}
|
|
||||||
className="sidebar__file-item-option"
|
|
||||||
>
|
|
||||||
Rename
|
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<button
|
|
||||||
onClick={() => {
|
|
||||||
if (window.confirm(`Are you sure you want to delete ${this.props.name}?`)) {
|
|
||||||
this.isDeleting = true;
|
|
||||||
this.props.resetSelectedFile(this.props.id);
|
|
||||||
setTimeout(() => this.props.deleteFile(this.props.id, this.props.parentId), 100);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
onBlur={this.onBlurComponent}
|
|
||||||
onFocus={this.onFocusComponent}
|
|
||||||
className="sidebar__file-item-option"
|
|
||||||
>
|
|
||||||
Delete
|
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
}
|
||||||
}
|
<button
|
||||||
})()}
|
className="sidebar__file-item-name"
|
||||||
{(() => { // eslint-disable-line
|
onClick={this.handleFileClick}
|
||||||
if (this.props.children) {
|
>
|
||||||
return (
|
{this.state.updatedName}
|
||||||
<ul className="file-item__children">
|
</button>
|
||||||
{this.props.children.map(this.renderChild)}
|
<input
|
||||||
|
type="text"
|
||||||
|
className="sidebar__file-item-input"
|
||||||
|
value={this.state.updatedName}
|
||||||
|
maxLength="128"
|
||||||
|
onChange={this.handleFileNameChange}
|
||||||
|
ref={(element) => { this.fileNameInput = element; }}
|
||||||
|
onBlur={this.handleFileNameBlur}
|
||||||
|
onKeyPress={this.handleKeyPress}
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
className="sidebar__file-item-show-options"
|
||||||
|
aria-label="view file options"
|
||||||
|
ref={(element) => { this[`fileOptions-${this.props.id}`] = element; }}
|
||||||
|
tabIndex="0"
|
||||||
|
onClick={this.toggleFileOptions}
|
||||||
|
onBlur={this.onBlurComponent}
|
||||||
|
onFocus={this.onFocusComponent}
|
||||||
|
>
|
||||||
|
<InlineSVG src={downArrowUrl} />
|
||||||
|
</button>
|
||||||
|
<div className="sidebar__file-item-options">
|
||||||
|
<ul title="file options">
|
||||||
|
{ isFolder &&
|
||||||
|
<React.Fragment>
|
||||||
|
<li>
|
||||||
|
<button
|
||||||
|
aria-label="add folder"
|
||||||
|
onClick={this.handleClickAddFolder}
|
||||||
|
onBlur={this.onBlurComponent}
|
||||||
|
onFocus={this.onFocusComponent}
|
||||||
|
className="sidebar__file-item-option"
|
||||||
|
>
|
||||||
|
Create folder
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<button
|
||||||
|
aria-label="add file"
|
||||||
|
onClick={this.handleClickAddFile}
|
||||||
|
onBlur={this.onBlurComponent}
|
||||||
|
onFocus={this.onFocusComponent}
|
||||||
|
className="sidebar__file-item-option"
|
||||||
|
>
|
||||||
|
Create file
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
{ this.props.authenticated &&
|
||||||
|
<li>
|
||||||
|
<button
|
||||||
|
aria-label="upload file"
|
||||||
|
onClick={this.handleClickUploadFile}
|
||||||
|
onBlur={this.onBlurComponent}
|
||||||
|
onFocus={this.onFocusComponent}
|
||||||
|
>
|
||||||
|
Upload file
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
</React.Fragment>
|
||||||
|
}
|
||||||
|
<li>
|
||||||
|
<button
|
||||||
|
onClick={this.handleClickRename}
|
||||||
|
onBlur={this.onBlurComponent}
|
||||||
|
onFocus={this.onFocusComponent}
|
||||||
|
className="sidebar__file-item-option"
|
||||||
|
>
|
||||||
|
Rename
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<button
|
||||||
|
onClick={this.handleClickDelete}
|
||||||
|
onBlur={this.onBlurComponent}
|
||||||
|
onFocus={this.onFocusComponent}
|
||||||
|
className="sidebar__file-item-option"
|
||||||
|
>
|
||||||
|
Delete
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
);
|
</div>
|
||||||
}
|
</div>
|
||||||
})()}
|
}
|
||||||
|
{ this.props.children &&
|
||||||
|
<ul className="file-item__children">
|
||||||
|
{this.props.children.map(this.renderChild)}
|
||||||
|
</ul>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -300,18 +322,20 @@ FileNode.propTypes = {
|
||||||
showFolderChildren: PropTypes.func.isRequired,
|
showFolderChildren: PropTypes.func.isRequired,
|
||||||
hideFolderChildren: PropTypes.func.isRequired,
|
hideFolderChildren: PropTypes.func.isRequired,
|
||||||
canEdit: PropTypes.bool.isRequired,
|
canEdit: PropTypes.bool.isRequired,
|
||||||
openUploadFileModal: PropTypes.func.isRequired
|
openUploadFileModal: PropTypes.func.isRequired,
|
||||||
|
authenticated: PropTypes.bool.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
FileNode.defaultProps = {
|
FileNode.defaultProps = {
|
||||||
parentId: '0',
|
parentId: '0',
|
||||||
isSelectedFile: false,
|
isSelectedFile: false,
|
||||||
isFolderClosed: false
|
isFolderClosed: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
function mapStateToProps(state, ownProps) {
|
function mapStateToProps(state, ownProps) {
|
||||||
// this is a hack, state is updated before ownProps
|
// this is a hack, state is updated before ownProps
|
||||||
return state.files.find(file => file.id === ownProps.id) || { name: 'test', fileType: 'file' };
|
const fileNode = state.files.find(file => file.id === ownProps.id) || { name: 'test', fileType: 'file' };
|
||||||
|
return Object.assign({}, fileNode, { authenticated: state.user.authenticated });
|
||||||
}
|
}
|
||||||
|
|
||||||
function mapDispatchToProps(dispatch) {
|
function mapDispatchToProps(dispatch) {
|
||||||
|
|
|
@ -113,19 +113,22 @@ class Sidebar extends React.Component {
|
||||||
Create file
|
Create file
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
{
|
||||||
<button
|
this.props.user.authenticated &&
|
||||||
aria-label="upload file"
|
<li>
|
||||||
onClick={() => {
|
<button
|
||||||
this.props.openUploadFileModal(rootFile.id);
|
aria-label="upload file"
|
||||||
setTimeout(this.props.closeProjectOptions, 0);
|
onClick={() => {
|
||||||
}}
|
this.props.openUploadFileModal(rootFile.id);
|
||||||
onBlur={this.onBlurComponent}
|
setTimeout(this.props.closeProjectOptions, 0);
|
||||||
onFocus={this.onFocusComponent}
|
}}
|
||||||
>
|
onBlur={this.onBlurComponent}
|
||||||
Upload file
|
onFocus={this.onFocusComponent}
|
||||||
</button>
|
>
|
||||||
</li>
|
Upload file
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue