2018-02-07 19:06:07 +01:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
2016-08-23 06:10:42 +02:00
|
|
|
import { bindActionCreators } from 'redux';
|
|
|
|
import { connect } from 'react-redux';
|
2017-02-22 20:29:35 +01:00
|
|
|
import classNames from 'classnames';
|
2020-08-19 11:40:05 +02:00
|
|
|
import { withTranslation } from 'react-i18next';
|
|
|
|
|
2017-02-22 20:29:35 +01:00
|
|
|
import * as IDEActions from '../actions/ide';
|
|
|
|
import * as FileActions from '../actions/files';
|
2020-04-30 00:34:37 +02:00
|
|
|
import DownArrowIcon from '../../../images/down-filled-triangle.svg';
|
|
|
|
import FolderRightIcon from '../../../images/triangle-arrow-right.svg';
|
|
|
|
import FolderDownIcon from '../../../images/triangle-arrow-down.svg';
|
|
|
|
import FileIcon from '../../../images/file.svg';
|
2016-08-23 06:10:42 +02:00
|
|
|
|
2020-08-03 19:52:07 +02:00
|
|
|
function parseFileName(name) {
|
2020-07-31 00:59:12 +02:00
|
|
|
const nameArray = name.split('.');
|
|
|
|
if (nameArray.length > 1) {
|
|
|
|
const extension = `.${nameArray[nameArray.length - 1]}`;
|
2020-08-03 19:52:07 +02:00
|
|
|
const baseName = nameArray.slice(0, -1).join('');
|
|
|
|
const firstLetter = baseName[0];
|
|
|
|
const lastLetter = baseName[baseName.length - 1];
|
|
|
|
const middleText = baseName.slice(1, -1);
|
|
|
|
return {
|
|
|
|
baseName,
|
|
|
|
firstLetter,
|
|
|
|
lastLetter,
|
|
|
|
middleText,
|
|
|
|
extension
|
|
|
|
};
|
2020-07-31 00:59:12 +02:00
|
|
|
}
|
|
|
|
const firstLetter = name[0];
|
|
|
|
const lastLetter = name[name.length - 1];
|
|
|
|
const middleText = name.slice(1, -1);
|
2020-08-03 19:52:07 +02:00
|
|
|
return {
|
|
|
|
baseName: name,
|
|
|
|
firstLetter,
|
|
|
|
lastLetter,
|
|
|
|
middleText
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function FileName({ name }) {
|
|
|
|
const {
|
|
|
|
baseName,
|
|
|
|
firstLetter,
|
|
|
|
lastLetter,
|
|
|
|
middleText,
|
|
|
|
extension
|
|
|
|
} = parseFileName(name);
|
2020-07-31 00:59:12 +02:00
|
|
|
return (
|
|
|
|
<span className="sidebar__file-item-name-text">
|
|
|
|
<span>{firstLetter}</span>
|
2020-08-03 19:52:07 +02:00
|
|
|
{baseName.length > 2 &&
|
2020-07-31 00:59:12 +02:00
|
|
|
<span className="sidebar__file-item-name--ellipsis">{middleText}</span>
|
|
|
|
}
|
2020-08-03 19:52:07 +02:00
|
|
|
{baseName.length > 1 &&
|
2020-07-31 00:59:12 +02:00
|
|
|
<span>{lastLetter}</span>
|
|
|
|
}
|
2020-08-03 19:52:07 +02:00
|
|
|
{extension &&
|
|
|
|
<span>{extension}</span>
|
|
|
|
}
|
2020-07-31 00:59:12 +02:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
FileName.propTypes = {
|
|
|
|
name: PropTypes.string.isRequired
|
|
|
|
};
|
|
|
|
|
2020-08-26 14:19:34 +02:00
|
|
|
class FileNode extends React.Component {
|
2016-08-23 06:10:42 +02:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2018-09-07 21:48:25 +02:00
|
|
|
|
|
|
|
this.state = {
|
|
|
|
isOptionsOpen: false,
|
|
|
|
isEditingName: false,
|
2019-03-27 20:52:57 +01:00
|
|
|
isFocused: false,
|
2020-04-16 21:53:32 +02:00
|
|
|
isDeleting: false,
|
2020-04-10 18:42:33 +02:00
|
|
|
updatedName: this.props.name
|
2018-09-07 21:48:25 +02:00
|
|
|
};
|
2016-08-23 19:52:31 +02:00
|
|
|
}
|
|
|
|
|
2020-04-16 21:53:32 +02:00
|
|
|
onFocusComponent = () => {
|
2019-03-27 20:52:57 +01:00
|
|
|
this.setState({ isFocused: true });
|
|
|
|
}
|
|
|
|
|
2020-04-16 21:53:32 +02:00
|
|
|
onBlurComponent = () => {
|
2019-03-27 20:52:57 +01:00
|
|
|
this.setState({ isFocused: false });
|
|
|
|
setTimeout(() => {
|
|
|
|
if (!this.state.isFocused) {
|
|
|
|
this.hideFileOptions();
|
|
|
|
}
|
|
|
|
}, 200);
|
|
|
|
}
|
|
|
|
|
2020-04-16 21:53:32 +02:00
|
|
|
|
|
|
|
setUpdatedName = (updatedName) => {
|
|
|
|
this.setState({ updatedName });
|
2020-04-10 18:42:33 +02:00
|
|
|
}
|
|
|
|
|
2020-04-16 21:53:32 +02:00
|
|
|
saveUpdatedFileName = () => {
|
2020-04-10 18:42:33 +02:00
|
|
|
const { updatedName } = this.state;
|
|
|
|
const { name, updateFileName, id } = this.props;
|
|
|
|
|
|
|
|
if (updatedName !== name) {
|
|
|
|
updateFileName(id, updatedName);
|
|
|
|
}
|
2020-04-08 00:47:51 +02:00
|
|
|
}
|
|
|
|
|
2020-04-16 21:53:32 +02:00
|
|
|
handleFileClick = (event) => {
|
|
|
|
event.stopPropagation();
|
|
|
|
const { isDeleting } = this.state;
|
2020-08-07 23:48:39 +02:00
|
|
|
const {
|
|
|
|
id, setSelectedFile, name, onClickFile
|
|
|
|
} = this.props;
|
2020-04-16 21:53:32 +02:00
|
|
|
if (name !== 'root' && !isDeleting) {
|
|
|
|
setSelectedFile(id);
|
2016-08-25 00:52:08 +02:00
|
|
|
}
|
2020-08-07 23:48:39 +02:00
|
|
|
|
|
|
|
// debugger; // eslint-disable-line
|
|
|
|
if (onClickFile) { onClickFile(); }
|
2016-08-23 06:10:42 +02:00
|
|
|
}
|
|
|
|
|
2020-04-16 21:53:32 +02:00
|
|
|
handleFileNameChange = (event) => {
|
|
|
|
const newName = event.target.value;
|
|
|
|
this.setUpdatedName(newName);
|
2016-08-23 06:10:42 +02:00
|
|
|
}
|
|
|
|
|
2020-04-16 21:53:32 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-04-16 22:08:51 +02:00
|
|
|
handleClickUploadFile = () => {
|
|
|
|
this.props.openUploadFileModal(this.props.id);
|
|
|
|
setTimeout(this.hideFileOptions, 0);
|
|
|
|
}
|
|
|
|
|
2020-04-16 21:53:32 +02:00
|
|
|
handleClickDelete = () => {
|
2020-08-19 11:40:05 +02:00
|
|
|
const prompt = this.props.t('Common.DeleteConfirmation', { name: this.props.name });
|
|
|
|
|
|
|
|
if (window.confirm(prompt)) {
|
2020-04-16 21:53:32 +02:00
|
|
|
this.setState({ isDeleting: true });
|
|
|
|
this.props.resetSelectedFile(this.props.id);
|
|
|
|
setTimeout(() => this.props.deleteFile(this.props.id, this.props.parentId), 100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleKeyPress = (event) => {
|
2016-08-23 06:10:42 +02:00
|
|
|
if (event.key === 'Enter') {
|
2018-09-07 21:48:25 +02:00
|
|
|
this.hideEditFileName();
|
2016-08-23 06:10:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-16 21:53:32 +02:00
|
|
|
validateFileName = () => {
|
|
|
|
const currentName = this.props.name;
|
|
|
|
const { updatedName } = this.state;
|
|
|
|
const oldFileExtension = currentName.match(/\.[0-9a-z]+$/i);
|
|
|
|
const newFileExtension = updatedName.match(/\.[0-9a-z]+$/i);
|
|
|
|
const hasPeriod = updatedName.match(/\.+/);
|
2019-07-11 08:05:43 +02:00
|
|
|
const hasNoExtension = oldFileExtension && !newFileExtension;
|
2019-07-17 18:30:26 +02:00
|
|
|
const hasExtensionIfFolder = this.props.fileType === 'folder' && hasPeriod;
|
|
|
|
const notSameExtension = oldFileExtension && newFileExtension
|
|
|
|
&& oldFileExtension[0].toLowerCase() !== newFileExtension[0].toLowerCase();
|
2020-04-16 22:22:59 +02:00
|
|
|
const hasEmptyFilename = updatedName.trim() === '';
|
|
|
|
const hasOnlyExtension = newFileExtension && updatedName.trim() === newFileExtension[0];
|
2019-07-17 18:30:26 +02:00
|
|
|
if (hasEmptyFilename || hasNoExtension || notSameExtension || hasOnlyExtension || hasExtensionIfFolder) {
|
2020-04-16 21:53:32 +02:00
|
|
|
this.setUpdatedName(currentName);
|
|
|
|
} else {
|
|
|
|
this.saveUpdatedFileName();
|
|
|
|
}
|
2016-08-23 06:10:42 +02:00
|
|
|
}
|
|
|
|
|
2020-04-16 21:53:32 +02:00
|
|
|
toggleFileOptions = (event) => {
|
|
|
|
event.preventDefault();
|
2019-03-14 21:10:50 +01:00
|
|
|
if (!this.props.canEdit) {
|
|
|
|
return;
|
|
|
|
}
|
2018-09-07 21:48:25 +02:00
|
|
|
if (this.state.isOptionsOpen) {
|
|
|
|
this.setState({ isOptionsOpen: false });
|
2017-01-09 18:47:32 +01:00
|
|
|
} else {
|
2017-02-22 20:29:35 +01:00
|
|
|
this[`fileOptions-${this.props.id}`].focus();
|
2018-09-07 21:48:25 +02:00
|
|
|
this.setState({ isOptionsOpen: true });
|
2017-01-09 18:47:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-16 21:53:32 +02:00
|
|
|
hideFileOptions = () => {
|
2018-09-07 21:48:25 +02:00
|
|
|
this.setState({ isOptionsOpen: false });
|
|
|
|
}
|
|
|
|
|
2020-04-16 21:53:32 +02:00
|
|
|
showEditFileName = () => {
|
2018-09-07 21:48:25 +02:00
|
|
|
this.setState({ isEditingName: true });
|
|
|
|
}
|
|
|
|
|
2020-04-16 21:53:32 +02:00
|
|
|
hideEditFileName = () => {
|
2018-09-07 21:48:25 +02:00
|
|
|
this.setState({ isEditingName: false });
|
|
|
|
}
|
|
|
|
|
2020-04-16 21:53:32 +02:00
|
|
|
showFolderChildren = () => {
|
|
|
|
this.props.showFolderChildren(this.props.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
hideFolderChildren = () => {
|
|
|
|
this.props.hideFolderChildren(this.props.id);
|
2016-08-23 06:10:42 +02:00
|
|
|
}
|
|
|
|
|
2020-04-16 21:53:32 +02:00
|
|
|
renderChild = childId => (
|
|
|
|
<li key={childId}>
|
2020-08-07 23:48:39 +02:00
|
|
|
<ConnectedFileNode id={childId} parentId={this.props.id} canEdit={this.props.canEdit} onClickFile={this.props.onClickFile} />
|
2020-04-16 21:53:32 +02:00
|
|
|
</li>
|
|
|
|
)
|
|
|
|
|
2016-08-23 06:10:42 +02:00
|
|
|
render() {
|
2017-02-22 20:29:35 +01:00
|
|
|
const itemClass = classNames({
|
2020-04-16 21:53:32 +02:00
|
|
|
'sidebar__root-item': this.props.name === 'root',
|
|
|
|
'sidebar__file-item': this.props.name !== 'root',
|
2016-09-14 21:57:52 +02:00
|
|
|
'sidebar__file-item--selected': this.props.isSelectedFile,
|
2018-09-07 21:48:25 +02:00
|
|
|
'sidebar__file-item--open': this.state.isOptionsOpen,
|
|
|
|
'sidebar__file-item--editing': this.state.isEditingName,
|
2016-08-31 00:46:59 +02:00
|
|
|
'sidebar__file-item--closed': this.props.isFolderClosed
|
2016-08-23 06:10:42 +02:00
|
|
|
});
|
2019-03-27 20:52:57 +01:00
|
|
|
|
2020-04-16 21:53:32 +02:00
|
|
|
const isFile = this.props.fileType === 'file';
|
|
|
|
const isFolder = this.props.fileType === 'folder';
|
|
|
|
const isRoot = this.props.name === 'root';
|
|
|
|
|
2020-08-19 11:40:05 +02:00
|
|
|
const { t } = this.props;
|
|
|
|
|
2016-08-23 06:10:42 +02:00
|
|
|
return (
|
2020-08-07 23:48:39 +02:00
|
|
|
<div className={itemClass} >
|
2020-04-16 21:53:32 +02:00
|
|
|
{ !isRoot &&
|
|
|
|
<div className="file-item__content" onContextMenu={this.toggleFileOptions}>
|
|
|
|
<span className="file-item__spacer"></span>
|
|
|
|
{ isFile &&
|
|
|
|
<span className="sidebar__file-item-icon">
|
2020-05-06 01:03:58 +02:00
|
|
|
<FileIcon focusable="false" aria-hidden="true" />
|
2020-04-16 21:53:32 +02:00
|
|
|
</span>
|
|
|
|
}
|
|
|
|
{ isFolder &&
|
|
|
|
<div className="sidebar__file-item--folder">
|
|
|
|
<button
|
|
|
|
className="sidebar__file-item-closed"
|
|
|
|
onClick={this.showFolderChildren}
|
2020-08-19 11:40:05 +02:00
|
|
|
aria-label={t('FileNode.OpenFolderARIA')}
|
2020-04-16 21:53:32 +02:00
|
|
|
>
|
2020-05-06 01:03:58 +02:00
|
|
|
<FolderRightIcon className="folder-right" focusable="false" aria-hidden="true" />
|
2020-04-16 21:53:32 +02:00
|
|
|
</button>
|
2016-08-23 19:52:31 +02:00
|
|
|
<button
|
2020-04-16 21:53:32 +02:00
|
|
|
className="sidebar__file-item-open"
|
|
|
|
onClick={this.hideFolderChildren}
|
2020-08-19 11:40:05 +02:00
|
|
|
aria-label={t('FileNode.CloseFolderARIA')}
|
2016-08-23 19:52:31 +02:00
|
|
|
>
|
2020-05-06 01:03:58 +02:00
|
|
|
<FolderDownIcon className="folder-down" focusable="false" aria-hidden="true" />
|
2016-08-23 19:52:31 +02:00
|
|
|
</button>
|
2020-04-16 21:53:32 +02:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
<button
|
2020-08-05 23:50:07 +02:00
|
|
|
aria-label={this.state.updatedName}
|
2020-04-16 21:53:32 +02:00
|
|
|
className="sidebar__file-item-name"
|
|
|
|
onClick={this.handleFileClick}
|
2020-08-06 00:27:38 +02:00
|
|
|
data-testid="file-name"
|
2020-04-16 21:53:32 +02:00
|
|
|
>
|
2020-07-31 00:59:12 +02:00
|
|
|
<FileName name={this.state.updatedName} />
|
2020-04-16 21:53:32 +02:00
|
|
|
</button>
|
|
|
|
<input
|
2020-06-28 15:05:33 +02:00
|
|
|
data-testid="input"
|
2020-04-16 21:53:32 +02:00
|
|
|
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"
|
2020-08-19 11:40:05 +02:00
|
|
|
aria-label={t('FileNode.ToggleFileOptionsARIA')}
|
2020-04-16 21:53:32 +02:00
|
|
|
ref={(element) => { this[`fileOptions-${this.props.id}`] = element; }}
|
|
|
|
tabIndex="0"
|
|
|
|
onClick={this.toggleFileOptions}
|
|
|
|
onBlur={this.onBlurComponent}
|
|
|
|
onFocus={this.onFocusComponent}
|
|
|
|
>
|
2020-05-06 01:03:58 +02:00
|
|
|
<DownArrowIcon focusable="false" aria-hidden="true" />
|
2020-04-16 21:53:32 +02:00
|
|
|
</button>
|
|
|
|
<div className="sidebar__file-item-options">
|
|
|
|
<ul title="file options">
|
|
|
|
{ isFolder &&
|
|
|
|
<React.Fragment>
|
2016-08-23 19:52:31 +02:00
|
|
|
<li>
|
2017-02-22 20:29:35 +01:00
|
|
|
<button
|
2020-08-19 11:40:05 +02:00
|
|
|
aria-label={t('FileNode.AddFolderARIA')}
|
2020-04-16 21:59:09 +02:00
|
|
|
onClick={this.handleClickAddFolder}
|
|
|
|
onBlur={this.onBlurComponent}
|
|
|
|
onFocus={this.onFocusComponent}
|
|
|
|
className="sidebar__file-item-option"
|
|
|
|
>
|
2020-08-19 11:40:05 +02:00
|
|
|
{t('FileNode.AddFolder')}
|
2020-04-16 21:59:09 +02:00
|
|
|
</button>
|
|
|
|
</li>
|
2016-08-23 19:52:31 +02:00
|
|
|
<li>
|
2017-02-22 20:29:35 +01:00
|
|
|
<button
|
2020-08-19 11:40:05 +02:00
|
|
|
aria-label={t('FileNode.AddFileARIA')}
|
2020-04-16 21:53:32 +02:00
|
|
|
onClick={this.handleClickAddFile}
|
2019-03-27 20:52:57 +01:00
|
|
|
onBlur={this.onBlurComponent}
|
|
|
|
onFocus={this.onFocusComponent}
|
2017-02-22 20:29:35 +01:00
|
|
|
className="sidebar__file-item-option"
|
2016-08-23 19:52:31 +02:00
|
|
|
>
|
2020-08-19 11:40:05 +02:00
|
|
|
{t('FileNode.AddFile')}
|
2017-02-22 20:29:35 +01:00
|
|
|
</button>
|
2016-08-23 19:52:31 +02:00
|
|
|
</li>
|
2020-04-16 22:08:51 +02:00
|
|
|
{ this.props.authenticated &&
|
|
|
|
<li>
|
|
|
|
<button
|
2020-08-19 11:40:05 +02:00
|
|
|
aria-label={t('FileNode.UploadFileARIA')}
|
2020-04-16 22:08:51 +02:00
|
|
|
onClick={this.handleClickUploadFile}
|
|
|
|
onBlur={this.onBlurComponent}
|
|
|
|
onFocus={this.onFocusComponent}
|
|
|
|
>
|
2020-08-19 11:40:05 +02:00
|
|
|
{t('FileNode.UploadFile')}
|
2020-04-16 22:08:51 +02:00
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
}
|
2020-04-16 21:53:32 +02:00
|
|
|
</React.Fragment>
|
|
|
|
}
|
|
|
|
<li>
|
|
|
|
<button
|
|
|
|
onClick={this.handleClickRename}
|
|
|
|
onBlur={this.onBlurComponent}
|
|
|
|
onFocus={this.onFocusComponent}
|
|
|
|
className="sidebar__file-item-option"
|
|
|
|
>
|
2020-08-19 11:40:05 +02:00
|
|
|
{t('FileNode.Rename')}
|
2020-04-16 21:53:32 +02:00
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<button
|
|
|
|
onClick={this.handleClickDelete}
|
|
|
|
onBlur={this.onBlurComponent}
|
|
|
|
onFocus={this.onFocusComponent}
|
|
|
|
className="sidebar__file-item-option"
|
|
|
|
>
|
2020-08-19 11:40:05 +02:00
|
|
|
{t('FileNode.Delete')}
|
2020-04-16 21:53:32 +02:00
|
|
|
</button>
|
|
|
|
</li>
|
2016-08-23 06:10:42 +02:00
|
|
|
</ul>
|
2020-04-16 21:53:32 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
{ this.props.children &&
|
|
|
|
<ul className="file-item__children">
|
|
|
|
{this.props.children.map(this.renderChild)}
|
|
|
|
</ul>
|
|
|
|
}
|
2016-08-23 06:10:42 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FileNode.propTypes = {
|
|
|
|
id: PropTypes.string.isRequired,
|
2016-08-24 22:06:28 +02:00
|
|
|
parentId: PropTypes.string,
|
2017-02-22 20:29:35 +01:00
|
|
|
children: PropTypes.arrayOf(PropTypes.string.isRequired).isRequired,
|
2016-08-23 06:10:42 +02:00
|
|
|
name: PropTypes.string.isRequired,
|
2016-08-30 05:23:10 +02:00
|
|
|
fileType: PropTypes.string.isRequired,
|
2016-09-14 21:57:52 +02:00
|
|
|
isSelectedFile: PropTypes.bool,
|
2016-08-31 00:46:59 +02:00
|
|
|
isFolderClosed: PropTypes.bool,
|
2016-08-23 06:10:42 +02:00
|
|
|
setSelectedFile: PropTypes.func.isRequired,
|
|
|
|
deleteFile: PropTypes.func.isRequired,
|
2016-08-23 19:52:31 +02:00
|
|
|
updateFileName: PropTypes.func.isRequired,
|
2016-08-30 05:43:02 +02:00
|
|
|
resetSelectedFile: PropTypes.func.isRequired,
|
|
|
|
newFile: PropTypes.func.isRequired,
|
2016-08-31 00:46:59 +02:00
|
|
|
newFolder: PropTypes.func.isRequired,
|
|
|
|
showFolderChildren: PropTypes.func.isRequired,
|
2019-03-14 21:10:50 +01:00
|
|
|
hideFolderChildren: PropTypes.func.isRequired,
|
2020-04-08 22:18:10 +02:00
|
|
|
canEdit: PropTypes.bool.isRequired,
|
2020-04-16 22:08:51 +02:00
|
|
|
openUploadFileModal: PropTypes.func.isRequired,
|
2020-08-07 23:48:39 +02:00
|
|
|
authenticated: PropTypes.bool.isRequired,
|
2020-08-19 11:40:05 +02:00
|
|
|
t: PropTypes.func.isRequired,
|
2020-08-07 23:48:39 +02:00
|
|
|
onClickFile: PropTypes.func
|
2016-08-23 06:10:42 +02:00
|
|
|
};
|
|
|
|
|
2017-02-22 20:29:35 +01:00
|
|
|
FileNode.defaultProps = {
|
2020-08-07 23:48:39 +02:00
|
|
|
onClickFile: null,
|
2017-02-22 20:29:35 +01:00
|
|
|
parentId: '0',
|
|
|
|
isSelectedFile: false,
|
2020-04-08 00:47:51 +02:00
|
|
|
isFolderClosed: false,
|
2017-02-22 20:29:35 +01:00
|
|
|
};
|
|
|
|
|
2016-08-23 06:10:42 +02:00
|
|
|
function mapStateToProps(state, ownProps) {
|
2018-05-05 02:22:39 +02:00
|
|
|
// this is a hack, state is updated before ownProps
|
2020-04-16 22:08:51 +02:00
|
|
|
const fileNode = state.files.find(file => file.id === ownProps.id) || { name: 'test', fileType: 'file' };
|
|
|
|
return Object.assign({}, fileNode, { authenticated: state.user.authenticated });
|
2016-08-23 06:10:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function mapDispatchToProps(dispatch) {
|
2016-08-23 19:52:31 +02:00
|
|
|
return bindActionCreators(Object.assign(FileActions, IDEActions), dispatch);
|
2016-08-23 06:10:42 +02:00
|
|
|
}
|
|
|
|
|
2020-08-19 11:40:05 +02:00
|
|
|
const TranslatedFileNode = withTranslation()(FileNode);
|
|
|
|
|
|
|
|
const ConnectedFileNode = connect(mapStateToProps, mapDispatchToProps)(TranslatedFileNode);
|
|
|
|
|
2020-08-26 14:19:34 +02:00
|
|
|
export {
|
|
|
|
TranslatedFileNode as FileNode,
|
|
|
|
ConnectedFileNode as default
|
|
|
|
};
|