Skip to content

TagSpaces is an offline, open source, document manager with tagging support

Tsn411 migration to mui treeview component (#1151)

Stanimirbb18ccf965f3
diff --git a/app/assets/rc-table.css b/app/assets/rc-table.css
index fbabc0bfc..926817a23 100644
--- a/app/assets/rc-table.css
+++ b/app/assets/rc-table.css
@@ -7,6 +7,7 @@
}
.rc-table-cell:hover {
+ border-radius: 5px;
background-color: #dcf3ec !important;
}
@@ -14,6 +15,7 @@
border: none;
padding: 8px;
background: transparent !important;
+ white-space: nowrap;
}
.rc-table tr.dropzone td {
diff --git a/app/components/DirectoryTreeView.tsx b/app/components/DirectoryTreeView.tsx
new file mode 100644
index 000000000..1729dfeaa
--- /dev/null
+++ b/app/components/DirectoryTreeView.tsx
@@ -0,0 +1,383 @@
+/**
+ * TagSpaces - universal file and folder organizer
+ * Copyright (C) 2017-present TagSpaces UG (haftungsbeschraenkt)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License (version 3) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+import React, { useState, forwardRef, useImperativeHandle } from 'react';
+import Table from 'rc-table';
+import FolderIcon from '@material-ui/icons/FolderOpen';
+import { Location, locationType } from '-/reducers/locations';
+import DragItemTypes from '-/components/DragItemTypes';
+import AppConfig from '-/config';
+import PlatformIO from '-/services/platform-io';
+import TargetTableMoveFileBox from '-/components/TargetTableMoveFileBox';
+
+interface Props {
+ classes: any;
+ loadDirectoryContent: (path: string) => void;
+ location: Location;
+ data?: any;
+ isReadOnlyMode?: boolean;
+ showUnixHiddenEntries: boolean;
+ showNotification?: (
+ text: string,
+ notificationType: string,
+ autohide: boolean
+ ) => void;
+ handleFileMoveDrop: (item, monitor) => void;
+}
+
+const DirectoryTreeView = forwardRef((props: Props, ref) => {
+ const [data, setData] = useState(undefined);
+ const [isExpanded, setExpanded] = useState(false);
+
+ useImperativeHandle(ref, () => ({
+ changeLocation(location: Location) {
+ if (isExpanded && data[location.uuid] !== undefined) {
+ /*const dirsTree = data;
+ dirsTree[location.uuid] = undefined;
+ setData(dirsTree);*/
+ //setData(undefined);
+ setExpanded(false);
+ } else {
+ if (location.type === locationType.TYPE_CLOUD) {
+ PlatformIO.enableObjectStoreSupport(location)
+ .then(() => {
+ loadSubDirectories(location, 1);
+ props.loadDirectoryContent(location.paths[0]);
+ })
+ .catch(error => {
+ console.log('enableObjectStoreSupport', error);
+ });
+ } else if (location.type === locationType.TYPE_LOCAL) {
+ PlatformIO.disableObjectStoreSupport();
+ loadSubDirectories(location, 1);
+ props.loadDirectoryContent(location.paths[0]);
+ }
+ }
+ },
+ closeLocation() {
+ setData(undefined);
+ }
+ }));
+
+ /*const changeLocation = (location: Location) => {
+ const dirsTree = data;
+ dirsTree[location.uuid] = undefined;
+ setData(dirsTree);
+ };*/
+
+ /*const renderBodyCell = props => (
+ <td {...props}>
+ <TargetMoveFileBox
+ // @ts-ignore
+ accepts={[DragItemTypes.FILE]}
+ onDrop={props.handleFileMoveDrop}
+ >
+ {props.children}
+ </TargetMoveFileBox>
+ </td>
+ );*/
+
+ const renderBodyRow = props => (
+ <TargetTableMoveFileBox
+ // @ts-ignore
+ accepts={[DragItemTypes.FILE]}
+ onDrop={props.handleFileMoveDrop}
+ location={props.location}
+ {...props}
+ />
+ );
+
+ const renderNameColumnAction = field => {
+ const children = (
+ <span style={{ fontSize: 15, marginLeft: 5 }} title={field}>
+ <FolderIcon
+ style={{ marginTop: 0, marginBottom: -8 }}
+ className={props.classes.icon}
+ />
+ {field && field.length > 25 ? field.substr(0, 25) + '...' : field}
+ </span>
+ );
+ return {
+ children,
+ props: {}
+ };
+ };
+
+ const handleCellClick = (record, index) => ({
+ /* onContextMenu: (e) => {
+ this.handleFileContextMenu(e, record.path);
+ }, */
+ onClick: () => {
+ onRowClick(record);
+ }
+ /* onDoubleClick: (e) => {
+ this.onRowClick(record, index, e);
+ } */
+ });
+
+ const onExpand = (expanded, record) => {
+ // console.log('onExpand', expanded + JSON.stringify(record));
+ if (expanded) {
+ // this.onRowClick(record);
+ loadSubDirectories(record, 1);
+ }
+ };
+
+ const onRowClick = subDir => {
+ if (subDir.type === locationType.TYPE_CLOUD) {
+ PlatformIO.enableObjectStoreSupport(subDir)
+ .then(() => {
+ loadSubDirectories(subDir, 1);
+ props.loadDirectoryContent(subDir.path);
+ })
+ .catch(error => {
+ console.log('enableObjectStoreSupport', error);
+ });
+ } else if (subDir.type === locationType.TYPE_LOCAL) {
+ PlatformIO.disableObjectStoreSupport();
+ loadSubDirectories(subDir, 1);
+ props.loadDirectoryContent(subDir.path);
+ }
+ };
+
+ const columns = [
+ {
+ title: undefined,
+ dataIndex: 'name',
+ key: 'name',
+ width: '80%',
+ render: renderNameColumnAction,
+ onCell: handleCellClick
+ }
+ ];
+
+ const loadSubDirectories = (location: Location, deepLevel: number) => {
+ const subFolder = {
+ ...(location.accessKeyId && { accessKeyId: location.accessKeyId }),
+ ...(location.bucketName && { bucketName: location.bucketName }),
+ ...(location.region && { region: location.region }),
+ ...(location.secretAccessKey && {
+ secretAccessKey: location.secretAccessKey
+ }),
+ uuid: location.uuid,
+ name: location.name,
+ type: location.type,
+ path: location.path || location.paths[0]
+ };
+ getDirectoriesTree(subFolder, deepLevel)
+ .then(children => {
+ if (children instanceof Array) {
+ if (location.uuid) {
+ const dirsTree = {}; // this.state.dirs; (uncomment to allow open multiple Locations folders) //TODO set settings for this
+ if (location.path === undefined) {
+ // location
+ dirsTree[location.uuid] = children;
+ } else {
+ const dirsCopy = getMergedDirsCopy(location.path, children);
+ if (dirsCopy) {
+ dirsTree[location.uuid] = dirsCopy;
+ } else {
+ // eslint-disable-next-line no-param-reassign
+ location.children = children;
+ dirsTree[location.uuid] = [location];
+ }
+ }
+ setData(dirsTree);
+ setExpanded(true);
+ }
+ } else if (location.path === undefined) {
+ // if is Location
+ //setData({});
+ }
+ return true;
+ })
+ .catch(error => {
+ console.log('loadSubDirectories', error);
+ });
+ };
+
+ type SubFolder = {
+ accessKeyId?: string;
+ bucketName?: string;
+ region?: string;
+ secretAccessKey?: string;
+ uuid: string;
+ name: string;
+ type: string;
+ path: string;
+ children?: Array<SubFolder>;
+ };
+
+ const getDirectoriesTree = (subFolder: SubFolder, deepLevel: number) =>
+ // const { settings } = getState();
+ PlatformIO.listDirectoryPromise(subFolder.path, false)
+ // @ts-ignore
+ .then(dirEntries => {
+ const directoryContent = [];
+ dirEntries.map(entry => {
+ if (
+ entry.name === AppConfig.metaFolder ||
+ entry.name.endsWith('/' + AppConfig.metaFolder) ||
+ (!props.showUnixHiddenEntries && entry.name.startsWith('.'))
+ ) {
+ return true;
+ }
+ // const enhancedEntry = enhanceEntry(entry);
+ if (!entry.isFile) {
+ // eslint-disable-next-line no-param-reassign
+ if (subFolder.accessKeyId) {
+ entry.accessKeyId = subFolder.accessKeyId;
+ }
+ if (subFolder.bucketName) {
+ entry.bucketName = subFolder.bucketName;
+ }
+ if (subFolder.region) {
+ entry.region = subFolder.region;
+ }
+ if (subFolder.secretAccessKey) {
+ entry.secretAccessKey = subFolder.secretAccessKey;
+ }
+ entry.uuid = subFolder.uuid;
+ entry.type = subFolder.type;
+ directoryContent.push(entry);
+ }
+ return true;
+ });
+ if (directoryContent.length > 0) {
+ // eslint-disable-next-line no-param-reassign
+ subFolder.children = directoryContent;
+ if (deepLevel > 0) {
+ const promisesArr = [];
+ directoryContent.map(directory =>
+ promisesArr.push(getDirectoriesTree(directory, deepLevel - 1))
+ );
+ return Promise.all(promisesArr);
+ }
+ }
+ return subFolder;
+ })
+ .catch(error => {
+ console.log('getDirectoriesTree', error);
+ });
+
+ /**
+ * https://codereview.stackexchange.com/questions/47932/recursion-vs-iteration-of-tree-structure
+ * Dynamically set property of nested object
+ * */
+ const getMergedDirsCopy = (path: string, arrChildren: Array<SubFolder>) => {
+ const entries = Object.entries(data);
+ for (const [uuid, arrSubDirs] of entries) {
+ const arr: number = (arrSubDirs as Array<any>).length;
+ let a;
+ for (a = 0; a < arr; a += 1) {
+ if (path === arrSubDirs[a].path) {
+ const copyObj = [...data[uuid]];
+ copyObj[a].children = arrChildren;
+ return copyObj;
+ }
+ if (arrSubDirs[a].children !== undefined) {
+ const stack = [
+ {
+ depth: 0,
+ element: arrSubDirs[a],
+ propPath: ''
+ }
+ ];
+ let stackItem = 0;
+ let current;
+ let children;
+ let depth;
+ let stackPath;
+ let propPath = a + '.children';
+
+ while ((current = stack[stackItem++])) {
+ // get the arguments
+ stackPath = current.propPath;
+ depth = current.depth;
+ current = current.element;
+ children = current.children;
+ if (children !== undefined) {
+ const len = children.length;
+ for (let i = 0; i < len; i++) {
+ if (path === children[i].path) {
+ propPath =
+ propPath +
+ '.' +
+ (stackPath ? stackPath + '.' : '') +
+ i +
+ '.children';
+ const copyObj = [...data[uuid]];
+
+ let schema = copyObj; // a moving reference to internal objects within obj
+ const pList = propPath.split('.');
+ const leng = pList.length;
+ for (let c = 0; c < leng - 1; c++) {
+ const elem = pList[c];
+ if (!schema[elem]) schema[elem] = {};
+ schema = schema[elem];
+ }
+ schema[pList[leng - 1]] = arrChildren;
+ return copyObj;
+ }
+
+ stack.push({
+ // pass args via object or array
+ element: children[i],
+ depth: depth + 1,
+ propPath: (stackPath ? stackPath + '.' : '') + i + '.children'
+ });
+ }
+ }
+ }
+ }
+ }
+ }
+ };
+
+ if (isExpanded && data != undefined) {
+ // @ts-ignore
+ return (
+ <Table
+ // defaultExpandAllRows
+ // className={classes.locationListArea}
+ components={{
+ // header: { cell: this.renderHeaderRow },
+ body: { row: renderBodyRow }
+ }}
+ showHeader={false}
+ // className="table"
+ rowKey="path"
+ data={data[props.location.uuid]}
+ columns={columns}
+ indentSize={20}
+ expandable={{ onExpand: onExpand }}
+ // expandIcon={this.CustomExpandIcon}
+ // expandIconAsCell
+ // @ts-ignore
+ onRow={(record, index) => ({
+ index,
+ location: record,
+ handleFileMoveDrop: props.handleFileMoveDrop
+ })}
+ />
+ );
+ }
+ return null;
+});
+
+export default DirectoryTreeView;
diff --git a/app/components/LocationManager.tsx b/app/components/LocationManager.tsx
index 6edfda69c..f66aad481 100644
--- a/app/components/LocationManager.tsx
+++ b/app/components/LocationManager.tsx
@@ -18,7 +18,6 @@
*/
import React from 'react';
-import Table from 'rc-table';
import { bindActionCreators } from 'redux';
import uuidv1 from 'uuid';
import classNames from 'classnames';
@@ -35,7 +34,6 @@ import MenuItem from '@material-ui/core/MenuItem';
import Typography from '@material-ui/core/Typography';
import IconButton from '@material-ui/core/IconButton';
import Button from '@material-ui/core/Button';
-import FolderIcon from '@material-ui/icons/FolderOpen';
import LocationIcon from '@material-ui/icons/WorkOutline';
import CloudLocationIcon from '@material-ui/icons/CloudQueue';
import EditIcon from '@material-ui/icons/Edit';
@@ -67,17 +65,14 @@ import {
isReadOnlyMode
} from '../reducers/app';
import { actions as LocationIndexActions } from '../reducers/location-index';
-import {
- getPerspectives,
- getShowUnixHiddenEntries
-} from '../reducers/settings';
+import { getPerspectives, getShowUnixHiddenEntries } from '-/reducers/settings';
import i18n from '../services/i18n';
import AppConfig from '../config';
import PlatformIO from '../services/platform-io';
import TargetMoveFileBox from './TargetMoveFileBox';
-import TargetTableMoveFileBox from './TargetTableMoveFileBox';
import DragItemTypes from './DragItemTypes';
import IOActions from '../reducers/io-actions';
+import DirectoryTreeView from '-/components/DirectoryTreeView';
const isLocationsReadOnly = window.ExtLocationsReadOnly;
@@ -106,7 +101,6 @@ interface Props {
moveLocationDown: (locationId: string) => void;
closeLocation: (locationId: string) => void;
removeLocation: (location: Location) => void;
- // renameDirectory: (directoryPath: string, newDirectoryName: string) => void,
reflectCreateEntry: (path: string, isFile: boolean) => void;
deleteDirectory: (directoryPath: string) => void;
showUnixHiddenEntries: boolean;
@@ -126,7 +120,6 @@ interface State {
directoryContextMenuOpened?: boolean;
selectedLocation: Location | null;
selectedDirectoryPath?: string | null;
- locationRootPath?: string | null;
isCreateLocationDialogOpened?: boolean;
isEditLocationDialogOpened?: boolean;
isDeleteLocationDialogOpened?: boolean;
@@ -135,7 +128,6 @@ interface State {
isCreateDirectoryDialogOpened?: boolean;
locationManagerMenuOpened: boolean;
locationManagerMenuAnchorEl: Object | null;
- dirs?: Object;
}
type SubFolder = {
@@ -146,15 +138,18 @@ type SubFolder = {
};
class LocationManager extends React.Component<Props, State> {
+ constructor(props) {
+ super(props);
+ this.directoryTreeRef = [];
+ }
+
state = {
- open: false,
locationDirectoryContextMenuAnchorEl: null,
locationContextMenuOpened: false,
directoryContextMenuAnchorEl: null,
directoryContextMenuOpened: false,
selectedLocation: null,
selectedDirectoryPath: null,
- locationRootPath: null,
isCreateLocationDialogOpened: false,
isEditLocationDialogOpened: false,
isDeleteLocationDialogOpened: false,
@@ -163,8 +158,7 @@ class LocationManager extends React.Component<Props, State> {
locationManagerMenuOpened: false,
locationManagerMenuAnchorEl: null,
createLocationDialogKey: uuidv1(),
- editLocationDialogKey: uuidv1(),
- dirs: {}
+ editLocationDialogKey: uuidv1()
};
componentDidMount() {
@@ -188,162 +182,6 @@ class LocationManager extends React.Component<Props, State> {
}
}
- loadSubDirectories = (location: Location, deepLevel: number) => {
- const subFolder = {
- uuid: location.uuid,
- name: location.name,
- path: location.path || location.paths[0]
- };
- this.getDirectoriesTree(subFolder, deepLevel)
- .then(children => {
- if (children instanceof Array) {
- if (location.uuid) {
- const dirsTree = {}; // this.state.dirs; (uncomment to allow open multiple Locations folders) //TODO set settings for this
- if (location.path === undefined) {
- // location
- dirsTree[location.uuid] = children;
- } else {
- const dirsCopy = this.getMergedDirsCopy(location.path, children);
- if (dirsCopy) {
- dirsTree[location.uuid] = dirsCopy;
- } else {
- // eslint-disable-next-line no-param-reassign
- location.children = children;
- dirsTree[location.uuid] = [location];
- }
- }
- this.setState({
- dirs: dirsTree
- });
- }
- } else if (location.path === undefined) {
- // if is Location
- this.setState({
- dirs: {}
- });
- }
- return true;
- })
- .catch(error => {
- console.log('loadSubDirectories', error);
- });
- };
-
- getDirectoriesTree = (subFolder: SubFolder, deepLevel: number) =>
- // const { settings } = getState();
- PlatformIO.listDirectoryPromise(subFolder.path, false)
- // @ts-ignore
- .then(dirEntries => {
- const directoryContent = [];
- dirEntries.map(entry => {
- if (
- entry.name === AppConfig.metaFolder ||
- entry.name.endsWith('/' + AppConfig.metaFolder) ||
- (!this.props.showUnixHiddenEntries && entry.name.startsWith('.'))
- ) {
- return true;
- }
- // const enhancedEntry = enhanceEntry(entry);
- if (!entry.isFile) {
- // eslint-disable-next-line no-param-reassign
- entry.uuid = subFolder.uuid;
- directoryContent.push(entry);
- }
- return true;
- });
- if (directoryContent.length > 0) {
- // eslint-disable-next-line no-param-reassign
- subFolder.children = directoryContent;
- if (deepLevel > 0) {
- const promisesArr = [];
- directoryContent.map(directory =>
- promisesArr.push(
- this.getDirectoriesTree(directory, deepLevel - 1)
- )
- );
- return Promise.all(promisesArr);
- }
- }
- return subFolder;
- })
- .catch(error => {
- console.log('getDirectoriesTree', error);
- });
-
- /**
- * https://codereview.stackexchange.com/questions/47932/recursion-vs-iteration-of-tree-structure
- * Dynamically set property of nested object
- * */
- getMergedDirsCopy = (path: string, arrChildren: Array<SubFolder>) => {
- const entries = Object.entries(this.state.dirs);
- for (const [uuid, arrSubDirs] of entries) {
- const arr: number = (arrSubDirs as Array<any>).length;
- let a;
- for (a = 0; a < arr; a += 1) {
- if (path === arrSubDirs[a].path) {
- const copyObj = [...this.state.dirs[uuid]];
- copyObj[a].children = arrChildren;
- return copyObj;
- }
- if (arrSubDirs[a].children !== undefined) {
- const stack = [
- {
- depth: 0,
- element: arrSubDirs[a],
- propPath: ''
- }
- ];
- let stackItem = 0;
- let current;
- let children;
- let depth;
- let stackPath;
- let propPath = a + '.children';
-
- while ((current = stack[stackItem++])) {
- // get the arguments
- stackPath = current.propPath;
- depth = current.depth;
- current = current.element;
- children = current.children;
- if (children !== undefined) {
- const len = children.length;
- for (let i = 0; i < len; i++) {
- if (path === children[i].path) {
- propPath =
- propPath +
- '.' +
- (stackPath ? stackPath + '.' : '') +
- i +
- '.children';
- const copyObj = [...this.state.dirs[uuid]];
-
- let schema = copyObj; // a moving reference to internal objects within obj
- const pList = propPath.split('.');
- const leng = pList.length;
- for (let c = 0; c < leng - 1; c++) {
- const elem = pList[c];
- if (!schema[elem]) schema[elem] = {};
- schema = schema[elem];
- }
- schema[pList[leng - 1]] = arrChildren;
- return copyObj;
- }
-
- stack.push({
- // pass args via object or array
- element: children[i],
- depth: depth + 1,
- propPath: (stackPath ? stackPath + '.' : '') + i + '.children'
- });
- }
- }
- }
- }
- }
- }
- };
-
handleCloseDialogs = () => {
this.setState({
isCreateLocationDialogOpened: false,
@@ -405,9 +243,11 @@ class LocationManager extends React.Component<Props, State> {
this.handleRequestCloseContextMenus();
if (this.state.selectedLocation && this.state.selectedLocation.uuid) {
this.props.closeLocation(this.state.selectedLocation.uuid);
- this.setState({
+ this.directoryTreeRef[this.state.selectedLocation.uuid] = undefined;
+ // this.directoryTreeRef[this.state.selectedLocation.uuid].closeLocation();
+ /* this.setState({
dirs: {}
- });
+ }); */
}
};
@@ -433,8 +273,9 @@ class LocationManager extends React.Component<Props, State> {
};
toggleDirectoryMenuClose = (event: React.ChangeEvent<HTMLInputElement>) => {
+ const opened = this.state.directoryContextMenuOpened;
this.setState({
- directoryContextMenuOpened: !this.state.directoryContextMenuOpened,
+ directoryContextMenuOpened: !opened,
directoryContextMenuAnchorEl: event ? event.currentTarget : null
});
};
@@ -489,23 +330,17 @@ class LocationManager extends React.Component<Props, State> {
});
};
+ // todo https://stackoverflow.com/questions/37949981/call-child-method-from-parent
+ // const directoryTreeRef = useRef();
+
handleLocationClick = (location: Location) => {
+ this.directoryTreeRef[location.uuid].changeLocation(location);
if (location.uuid === this.props.currentLocationId) {
- if (this.state.dirs[location.uuid] !== undefined) {
- const dirsTree = this.state.dirs;
- dirsTree[location.uuid] = undefined;
- this.setState({
- dirs: dirsTree
- });
- } else {
- this.loadSubDirectories(location, 1);
- }
this.props.loadDirectoryContent(location.paths[0]);
} else {
+ // this.directoryTreeRef[location.uuid].loadSubDir(location, 1);
this.props.setSelectedEntries([]);
- this.loadSubDirectories(location, 1);
this.props.openLocation(location);
- this.state.locationRootPath = location.paths[0];
if (this.props.hideDrawer) {
this.props.hideDrawer();
}
@@ -532,47 +367,6 @@ class LocationManager extends React.Component<Props, State> {
});
};
- renderNameColumnAction = field => {
- const children = (
- <span style={{ fontSize: 15, marginLeft: 5 }} title={field}>
- <FolderIcon
- style={{ marginTop: 0, marginBottom: -8 }}
- className={this.props.classes.icon}
- />
- {field && field.length > 25 ? field.substr(0, 25) + '...' : field}
- </span>
- );
- return {
- children,
- props: {}
- };
- };
-
- handleCellClick = (record, index) => ({
- /* onContextMenu: (e) => {
- this.handleFileContextMenu(e, record.path);
- }, */
- onClick: () => {
- this.onRowClick(record);
- }
- /* onDoubleClick: (e) => {
- this.onRowClick(record, index, e);
- } */
- });
-
- onExpand = (expanded, record) => {
- // console.log('onExpand', expanded + JSON.stringify(record));
- if (expanded) {
- // this.onRowClick(record);
- this.loadSubDirectories(record, 1);
- }
- };
-
- onRowClick = subDir => {
- this.loadSubDirectories(subDir, 1);
- this.props.loadDirectoryContent(subDir.path);
- };
-
/**
* https://github.com/react-component/table/blob/master/examples/react-dnd.js
* @param item
@@ -584,6 +378,7 @@ class LocationManager extends React.Component<Props, State> {
if (selectedEntries && selectedEntries.length > 0) {
selectedEntries.map(entry => {
arrPath.push(entry.path);
+ return true;
});
} else {
arrPath.push(path);
@@ -617,79 +412,35 @@ class LocationManager extends React.Component<Props, State> {
if (targetPath === undefined) {
targetPath = targetLocation.path;
}
- /*if (item.children && item.children.props && item.children.props.path) {
+ /* if (item.children && item.children.props && item.children.props.path) {
targetPath = item.children.props.path;
} else {
targetPath = item.children[1].props.record.path;
- }*/
- if (monitor && targetPath != undefined) {
+ } */
+ if (monitor && targetPath !== undefined && targetLocation !== undefined) {
// TODO handle monitor -> isOver and change folder icon
console.log('Dropped files: ' + path);
- if (targetLocation && targetLocation.type === locationType.TYPE_CLOUD) {
- PlatformIO.enableObjectStoreSupport(targetLocation).then(() => {
- this.props.uploadFiles(arrPath, targetPath);
- });
- } else {
- //if (targetLocationType === locationType.TYPE_LOCAL) {
+ if (targetLocation.type === locationType.TYPE_CLOUD) {
+ PlatformIO.enableObjectStoreSupport(targetLocation)
+ .then(() => {
+ this.props.uploadFiles(arrPath, targetPath);
+ return true;
+ })
+ .catch(error => {
+ console.log('enableObjectStoreSupport', error);
+ });
+ } else if (targetLocation.type === locationType.TYPE_LOCAL) {
+ PlatformIO.disableObjectStoreSupport();
this.props.moveFiles(arrPath, targetPath);
}
this.props.setSelectedEntries([]);
}
};
- renderBodyRow = props => (
- <TargetTableMoveFileBox
- // @ts-ignore
- accepts={[DragItemTypes.FILE]}
- onDrop={this.handleFileMoveDrop}
- location={props.location}
- {...props}
- />
- );
-
// <Tooltip id="tooltip-icon" title={i18n.t('core:moreOperations')} placement="bottom"></Tooltip>
renderLocation = (location: Location) => {
- let table;
const isCloudLocation = location.type === locationType.TYPE_CLOUD;
- if (this.state.dirs[location.uuid] !== undefined) {
- const columns = [
- {
- title: undefined,
- dataIndex: 'name',
- key: 'name',
- width: '80%',
- render: this.renderNameColumnAction,
- onCell: this.handleCellClick
- }
- ];
- table = (
- <Table
- // defaultExpandAllRows
- // className={classes.locationListArea}
- components={{
- // header: { cell: this.renderHeaderRow },
- body: { row: this.renderBodyRow }
- }}
- showHeader={false}
- // className="table"
- rowKey="path"
- data={this.state.dirs[location.uuid]}
- columns={columns}
- indentSize={20}
- // expandedRowRender={this.expandedRowRender}
- expandable={{ onExpand: this.onExpand }}
- // expandIcon={this.CustomExpandIcon}
- // expandIconAsCell
- /* onRow={(record, index) => ({
- onClick: this.onRowClick.bind(null, record, index),
- })} */
- onRow={(record, index) => ({
- index,
- location: record
- })}
- />
- );
- }
+
return (
<div key={location.uuid}>
<ListItem
@@ -719,7 +470,7 @@ class LocationManager extends React.Component<Props, State> {
// }}
style={{ minWidth: 'auto' }}
>
- {location.type === locationType.TYPE_CLOUD ? (
+ {isCloudLocation ? (
<CloudLocationIcon className={this.props.classes.icon} />
) : (
<LocationIcon className={this.props.classes.icon} />
@@ -780,7 +531,17 @@ class LocationManager extends React.Component<Props, State> {
</ListItemSecondaryAction>
)}
</ListItem>
- {table}
+ <DirectoryTreeView
+ ref={dirTree => {
+ this.directoryTreeRef[location.uuid] = dirTree;
+ }}
+ classes={this.props.classes}
+ loadDirectoryContent={this.props.loadDirectoryContent}
+ location={location}
+ showUnixHiddenEntries={this.props.showUnixHiddenEntries}
+ moveFiles={this.props.moveFiles}
+ handleFileMoveDrop={this.handleFileMoveDrop}
+ />
</div>
);
};
@@ -871,8 +632,8 @@ class LocationManager extends React.Component<Props, State> {
this.props.removeLocation(this.state.selectedLocation);
}
}}
- cancelDialogTID={'cancelDeleteLocationDialog'}
- confirmDialogTID={'confirmDeleteLocationDialog'}
+ cancelDialogTID="cancelDeleteLocationDialog"
+ confirmDialogTID="confirmDeleteLocationDialog"
/>
<SelectDirectoryDialog
open={this.state.isSelectDirectoryDialogOpened}
diff --git a/app/components/dialogs/AddRemoveTagsDialog.tsx b/app/components/dialogs/AddRemoveTagsDialog.tsx
index fb04b57a6..f92bf3699 100644
--- a/app/components/dialogs/AddRemoveTagsDialog.tsx
+++ b/app/components/dialogs/AddRemoveTagsDialog.tsx
@@ -39,7 +39,7 @@ interface Props {
open: boolean;
fullScreen: boolean;
selectedEntries: Array<any>;
- onClose: () => void;
+ onClose: (clearSelection?: boolean) => void;
addTags: (paths: Array<string>, tags: Array<Tag>) => void;
removeTags: (paths: Array<string>, tags: Array<Tag>) => void;
removeAllTags: (paths: Array<string>) => void;
@@ -66,9 +66,9 @@ class AddRemoveTagsDialog extends React.Component<Props, State> {
});
};
- onClose = () => {
+ onClose = (clearSelection?: boolean) => {
this.setState({ newlyAddedTags: [] });
- this.props.onClose();
+ this.props.onClose(clearSelection);
};
addTags = () => {
@@ -80,9 +80,42 @@ class AddRemoveTagsDialog extends React.Component<Props, State> {
});
this.props.addTags(paths, this.state.newlyAddedTags);
}
- this.onClose();
+ this.onClose(true);
};
+ removeTags = () => {
+ const {
+ selectedEntries = [],
+ removeTags,
+ } = this.props;
+ const { newlyAddedTags = [] } = this.state;
+ if (selectedEntries && selectedEntries.length > 0) {
+ const paths = [];
+ selectedEntries.map(entry => {
+ paths.push(entry.path);
+ return true;
+ });
+ removeTags(paths, newlyAddedTags);
+ }
+ this.onClose(true);
+ }
+
+ removeAllTags = () => {
+ const {
+ selectedEntries = [],
+ removeAllTags,
+ } = this.props;
+ if (selectedEntries && selectedEntries.length > 0) {
+ const paths = [];
+ selectedEntries.map(entry => {
+ paths.push(entry.path);
+ return true;
+ });
+ removeAllTags(paths);
+ }
+ this.onClose(true);
+ }
+
render() {
const {
open,
@@ -93,6 +126,7 @@ class AddRemoveTagsDialog extends React.Component<Props, State> {
onClose
} = this.props;
const { newlyAddedTags = [] } = this.state;
+ const disabledButtons = !newlyAddedTags || newlyAddedTags.length < 1 ||selectedEntries.length < 1;
return (
<Dialog
@@ -127,56 +161,28 @@ class AddRemoveTagsDialog extends React.Component<Props, State> {
</List>
</DialogContent>
<DialogActions>
- <Button data-tid="cancel" onClick={this.onClose} color="primary">
+ <Button data-tid="cancel" onClick={() => this.onClose()} color="primary">
{i18n.t('core:cancel')}
</Button>
<Button
data-tid="cleanTagsMultipleEntries"
disabled={selectedEntries.length < 1}
color="primary"
- onClick={() => {
- if (selectedEntries && selectedEntries.length > 0) {
- const paths = [];
- selectedEntries.map(entry => {
- paths.push(entry.path);
- return true;
- });
- removeAllTags(paths);
- }
- this.onClose();
- }}
+ onClick={this.removeAllTags}
>
{i18n.t('core:tagOperationCleanTags')}
</Button>
<Button
data-tid="removeTagsMultipleEntries"
- disabled={
- !newlyAddedTags ||
- newlyAddedTags.length < 1 ||
- selectedEntries.length < 1
- }
+ disabled={disabledButtons}
color="primary"
- onClick={() => {
- if (selectedEntries && selectedEntries.length > 0) {
- const paths = [];
- selectedEntries.map(entry => {
- paths.push(entry.path);
- return true;
- });
- removeTags(paths, newlyAddedTags);
- }
- this.onClose();
- }}
+ onClick={this.removeTags}
>
{i18n.t('core:tagOperationRemoveTag')}
</Button>
<Button
data-tid="addTagsMultipleEntries"
- disabled={
- !newlyAddedTags ||
- newlyAddedTags.length < 1 ||
- selectedEntries.length < 1
- }
+ disabled={disabledButtons}
color="primary"
onClick={this.addTags}
>
diff --git a/app/components/dialogs/MoveCopyFilesDialog.tsx b/app/components/dialogs/MoveCopyFilesDialog.tsx
index 7292f5962..c6c88a75f 100644
--- a/app/components/dialogs/MoveCopyFilesDialog.tsx
+++ b/app/components/dialogs/MoveCopyFilesDialog.tsx
@@ -45,7 +45,7 @@ import { extractFileName } from '-/utils/paths';
interface Props {
open: boolean;
fullScreen: boolean;
- onClose: () => void;
+ onClose: (clearSelection?: boolean) => void;
copyFiles: (files: Array<string>, destination: string) => void;
moveFiles: (files: Array<string>, destination: string) => void;
selectedFiles: Array<string>;
@@ -78,7 +78,7 @@ const MoveCopyFilesDialog = (props: Props) => {
setDisableConfirmButton(true);
setTargetPath('');
}
- props.onClose();
+ props.onClose(true);
}
function handleMoveFiles() {
@@ -88,7 +88,7 @@ const MoveCopyFilesDialog = (props: Props) => {
setDisableConfirmButton(true);
setTargetPath('');
}
- props.onClose();
+ props.onClose(true);
}
function selectDirectory() {
@@ -165,7 +165,7 @@ const MoveCopyFilesDialog = (props: Props) => {
</FormControl>
</DialogContent>
<DialogActions>
- <Button data-tid="closeMoveCopyDialog" onClick={props.onClose}>
+ <Button data-tid="closeMoveCopyDialog" onClick={() => props.onClose()}>
{i18n.t('core:cancel')}
</Button>
<Button
diff --git a/app/components/dialogs/RenameFileDialog.tsx b/app/components/dialogs/RenameFileDialog.tsx
index 56a6f4fb1..013c6c424 100644
--- a/app/components/dialogs/RenameFileDialog.tsx
+++ b/app/components/dialogs/RenameFileDialog.tsx
@@ -39,7 +39,7 @@ interface Props {
selectedFilePath: string;
classes: any;
renameFile: (source: string, target: string) => void;
- onClose: () => void;
+ onClose: (clearSelection?: boolean) => void;
}
interface State {
@@ -118,7 +118,7 @@ class RenameFileDialog extends React.Component<Props, State> {
const newFilePath =
fileDirectory + PlatformIO.getDirSeparator() + this.state.fileName;
this.props.renameFile(this.props.selectedFilePath, newFilePath);
- this.props.onClose();
+ this.props.onClose(true);
this.setState({ inputError: false, disableConfirmButton: true });
} else {
this.handleValidation();
@@ -161,7 +161,7 @@ class RenameFileDialog extends React.Component<Props, State> {
<DialogActions>
<Button
data-tid="closeRenameFileDialog"
- onClick={this.props.onClose}
+ onClick={() => this.props.onClose()}
color="primary"
>
{i18n.t('core:cancel')}
diff --git a/app/perspectives/grid-perspective/components/MainContainer.tsx b/app/perspectives/grid-perspective/components/MainContainer.tsx
index ec26f9743..4885e40c0 100644
--- a/app/perspectives/grid-perspective/components/MainContainer.tsx
+++ b/app/perspectives/grid-perspective/components/MainContainer.tsx
@@ -521,14 +521,16 @@ class GridPerspective extends React.Component<Props, State> {
});
};
- handleCloseDialogs = () => {
+ handleCloseDialogs = (clearSelection: boolean = false) => {
this.setState({
isFileRenameDialogOpened: false,
isDeleteMultipleFilesDialogOpened: false,
isAddRemoveTagsDialogOpened: false,
isMoveCopyFilesDialogOpened: false
});
- // this.clearSelection();
+ if (clearSelection) {
+ this.clearSelection();
+ }
};
openFileRenameDialog = () => {
@@ -569,6 +571,7 @@ class GridPerspective extends React.Component<Props, State> {
}
console.log('Dropped files: ' + path);
this.props.moveFiles(arrPath, item.path);
+ this.clearSelection();
}
};
@@ -870,6 +873,7 @@ class GridPerspective extends React.Component<Props, State> {
return true;
});
}
+ this.handleCloseDialogs(true);
}}
cancelDialogTID="cancelDeleteFileDialog"
confirmDialogTID="confirmDeleteFileDialog"
diff --git a/app/reducers/io-actions.ts b/app/reducers/io-actions.ts
index 7f9d6d27c..22a33412d 100644
--- a/app/reducers/io-actions.ts
+++ b/app/reducers/io-actions.ts
@@ -249,11 +249,19 @@ const actions = {
) => {
const uploadJobs = [];
paths.map(path => {
- uploadJobs.push([
- path,
+ const target =
normalizePath(targetPath) +
- PlatformIO.getDirSeparator() +
- extractFileName(path, PlatformIO.getDirSeparator())
+ PlatformIO.getDirSeparator() +
+ extractFileName(path, PlatformIO.getDirSeparator());
+ uploadJobs.push([path, target]);
+ // copy meta
+ uploadJobs.push([
+ getMetaFileLocationForFile(path, PlatformIO.getDirSeparator()),
+ getMetaFileLocationForFile(target, PlatformIO.getDirSeparator())
+ ]);
+ uploadJobs.push([
+ getThumbFileLocationForFile(path, PlatformIO.getDirSeparator()),
+ getThumbFileLocationForFile(target, PlatformIO.getDirSeparator())
]);
return true;
});
diff --git a/app/services/platform-io.ts b/app/services/platform-io.ts
index 7d9e2a592..f1f39cdfb 100644
--- a/app/services/platform-io.ts
+++ b/app/services/platform-io.ts
@@ -25,19 +25,32 @@ const nativeAPI: any = new NativePlatformIO();
let objectStoreAPI;
export default class PlatformIO {
- static enableObjectStoreSupport = (objectStoreConfig: Object): Promise<any> =>
+ static enableObjectStoreSupport = (
+ objectStoreConfig: any // S3.Types.ClientConfiguration
+ ): Promise<any> =>
new Promise((resolve, reject) => {
if (Pro && Pro.ObjectStoreIO) {
- objectStoreAPI = new Pro.ObjectStoreIO();
- objectStoreAPI
- .configure(objectStoreConfig)
- .then(() => {
- resolve();
- return true;
- })
- .catch(e => {
- reject(e);
- });
+ if (
+ objectStoreAPI !== undefined &&
+ objectStoreAPI.config.bucketName === objectStoreConfig.bucketName &&
+ objectStoreAPI.config.secretAccessKey ===
+ objectStoreConfig.secretAccessKey &&
+ objectStoreAPI.config.region === objectStoreConfig.region &&
+ objectStoreAPI.config.accessKeyId === objectStoreConfig.accessKeyId
+ ) {
+ resolve();
+ } else {
+ objectStoreAPI = new Pro.ObjectStoreIO();
+ objectStoreAPI
+ .configure(objectStoreConfig)
+ .then(() => {
+ resolve();
+ return true;
+ })
+ .catch(e => {
+ reject(e);
+ });
+ }
} else {
reject('ObjectStore support available in the PRO version');
}