Skip to content

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

Move copy files dialog fixes (#1940)

Stanimirc38dcb1d8133
diff --git a/app/components/DirectoryListView.tsx b/app/components/DirectoryListView.tsx
index 887574fa7..696afafdb 100644
--- a/app/components/DirectoryListView.tsx
+++ b/app/components/DirectoryListView.tsx
@@ -20,6 +20,7 @@ import { actions as AppActions, getCurrentLocationId } from '-/reducers/app';
import { ParentFolderIcon } from '-/components/CommonIcons';
import { getLocations } from '-/reducers/locations';
import PlatformIO from '-/services/platform-facade';
+import { Pro } from '-/pro';
interface Props {
setTargetDir: (dirPath: string) => void;
@@ -27,11 +28,18 @@ interface Props {
currentLocationId: string;
toggleCreateDirectoryDialog: (props: any) => void;
showUnixHiddenEntries: boolean;
+ currentDirectoryPath?: string;
+ watchForChanges: () => void;
}
function DirectoryListView(props: Props) {
- const { locations, currentLocationId, showUnixHiddenEntries } = props;
+ const {
+ locations,
+ currentLocationId,
+ showUnixHiddenEntries,
+ currentDirectoryPath
+ } = props;
const chosenLocationId = useRef<string>(currentLocationId);
- const chosenDirectory = useRef<string>();
+ const chosenDirectory = useRef<string>(currentDirectoryPath);
const [directoryContent, setDirectoryContent] = useState<
TS.FileSystemEntry[]
>([]);
@@ -41,7 +49,11 @@ function DirectoryListView(props: Props) {
location => location.uuid === chosenLocationId.current
);
if (chosenLocation) {
- listDirectory(chosenLocation.path);
+ const path =
+ chosenLocation.uuid === currentLocationId && currentDirectoryPath
+ ? currentDirectoryPath
+ : chosenLocation.path;
+ listDirectory(path);
}
}, [chosenLocationId.current]);
@@ -52,6 +64,7 @@ function DirectoryListView(props: Props) {
);
if (chosenLocation) {
listDirectory(chosenLocation.path);
+ props.setTargetDir(chosenLocation.path);
}
};
@@ -99,7 +112,7 @@ function DirectoryListView(props: Props) {
})
// .sort((a, b) => b.name - a.name)
);
- props.setTargetDir(directoryPath);
+ // props.setTargetDir(directoryPath);
}
return true;
})
@@ -148,7 +161,9 @@ function DirectoryListView(props: Props) {
if (currentPath.endsWith(PlatformIO.getDirSeparator())) {
currentPath = currentPath.slice(0, -1);
}
- listDirectory(extractContainingDirectoryPath(currentPath));
+ const parentDir = extractContainingDirectoryPath(currentPath);
+ listDirectory(parentDir);
+ props.setTargetDir(parentDir);
}
}}
>
@@ -160,9 +175,16 @@ function DirectoryListView(props: Props) {
style={{ margin: 5 }}
data-tid="newSubdirectoryTID"
onClick={() => {
+ if (Pro && Pro.Watcher) {
+ Pro.Watcher.stopWatching();
+ }
props.toggleCreateDirectoryDialog({
rootDirPath: chosenDirectory.current,
- callback: () => listDirectory(chosenDirectory.current),
+ callback: newDirPath => {
+ listDirectory(chosenDirectory.current);
+ props.setTargetDir(newDirPath);
+ props.watchForChanges();
+ },
reflect: false
});
}}
@@ -194,7 +216,8 @@ function mapStateToProps(state) {
function mapActionCreatorsToProps(dispatch) {
return bindActionCreators(
{
- toggleCreateDirectoryDialog: AppActions.toggleCreateDirectoryDialog
+ toggleCreateDirectoryDialog: AppActions.toggleCreateDirectoryDialog,
+ watchForChanges: AppActions.watchForChanges
},
dispatch
);
diff --git a/app/components/dialogs/MoveCopyFilesDialog.tsx b/app/components/dialogs/MoveCopyFilesDialog.tsx
index db7e1ad01..ad5c0fa36 100644
--- a/app/components/dialogs/MoveCopyFilesDialog.tsx
+++ b/app/components/dialogs/MoveCopyFilesDialog.tsx
@@ -41,7 +41,11 @@ import IOActions from '-/reducers/io-actions';
import DialogCloseButton from '-/components/dialogs/DialogCloseButton';
import useTheme from '@mui/styles/useTheme';
import useMediaQuery from '@mui/material/useMediaQuery';
-import { actions as AppActions, getSelectedEntries } from '-/reducers/app';
+import {
+ actions as AppActions,
+ getDirectoryPath,
+ getSelectedEntries
+} from '-/reducers/app';
import { TS } from '-/tagspaces.namespace';
import DirectoryListView from '-/components/DirectoryListView';
import AppConfig from '-/AppConfig';
@@ -50,6 +54,7 @@ import Tooltip from '-/components/Tooltip';
interface Props {
open: boolean;
onClose: (clearSelection?: boolean) => void;
+ currentDirectoryPath: string | null;
copyFiles: (files: Array<string>, destination: string) => void;
copyDirs: (
dirs: Array<string>,
@@ -73,7 +78,9 @@ interface Props {
function MoveCopyFilesDialog(props: Props) {
// const [disableConfirmButton, setDisableConfirmButton] = useState(true);
- const [targetPath, setTargetPath] = useState('');
+ const [targetPath, setTargetPath] = useState(
+ props.currentDirectoryPath ? props.currentDirectoryPath : ''
+ );
const dirProp = useRef({});
const [ignored, forceUpdate] = useReducer(x => x + 1, 0);
@@ -239,7 +246,10 @@ function MoveCopyFilesDialog(props: Props) {
{i18n.t('chooseTargetLocationAndPath')}
</Typography>
)}
- <DirectoryListView setTargetDir={setTargetPath} />
+ <DirectoryListView
+ setTargetDir={setTargetPath}
+ currentDirectoryPath={props.currentDirectoryPath}
+ />
</DialogContent>
<DialogActions
// style={{
@@ -259,7 +269,11 @@ function MoveCopyFilesDialog(props: Props) {
<span>
<Button
data-tid="confirmMoveFiles"
- disabled={!targetPath || AppConfig.isAndroid}
+ disabled={
+ !targetPath ||
+ AppConfig.isAndroid ||
+ targetPath === props.currentDirectoryPath
+ }
onClick={handleMoveFiles}
color="primary"
>
@@ -270,7 +284,7 @@ function MoveCopyFilesDialog(props: Props) {
<Button
onClick={handleCopyFiles}
data-tid="confirmCopyFiles"
- disabled={!targetPath}
+ disabled={!targetPath || targetPath === props.currentDirectoryPath}
color="primary"
>
{i18n.t('core:copyEntriesButton')}
@@ -282,7 +296,8 @@ function MoveCopyFilesDialog(props: Props) {
function mapStateToProps(state) {
return {
- selectedEntries: getSelectedEntries(state)
+ selectedEntries: getSelectedEntries(state),
+ currentDirectoryPath: getDirectoryPath(state)
};
}
diff --git a/app/services/platform-facade.ts b/app/services/platform-facade.ts
index 2a4f031d9..3846bd8dd 100644
--- a/app/services/platform-facade.ts
+++ b/app/services/platform-facade.ts
@@ -78,6 +78,7 @@ import {
platformUnZip,
platformDirProperties
} from '@tagspaces/tagspaces-platforms/platform-io';
+import { cleanTrailingDirSeparator } from '@tagspaces/tagspaces-common/paths';
import AppConfig from '-/AppConfig';
import { Pro } from '../pro';
import { TS } from '-/tagspaces.namespace';
@@ -229,7 +230,7 @@ export default class PlatformFacade {
ignorePatterns: Array<string> = [],
resultsLimit: any = {}
): Promise<Array<any>> =>
- platformListDirectoryPromise(path, mode, ignorePatterns, resultsLimit);
+ platformListDirectoryPromise(cleanTrailingDirSeparator(path), mode, ignorePatterns, resultsLimit);
static listMetaDirectoryPromise = (path: string): Promise<Array<any>> =>
platformListMetaDirectoryPromise(path);
diff --git a/tests/e2e/perspective-grid-right-button.pw.e2e.js b/tests/e2e/perspective-grid-right-button.pw.e2e.js
index 78c98116d..6b22adbe0 100644
--- a/tests/e2e/perspective-grid-right-button.pw.e2e.js
+++ b/tests/e2e/perspective-grid-right-button.pw.e2e.js
@@ -345,42 +345,32 @@ test.describe('TST50** - Right button on a file', () => {
*/
test('TST5028 - Move - Copy file (file menu) [minio,electron]', async () => {
// Move file in child folder
- // const fileExtension = 'pdf'; //'eml' -> todo search found extra files (.gitkeep) with fuseOptions = {threshold: 0.4,
- // await searchEngine(fileExtension);
const fileName = 'sample.pdf';
+ const folderName = 'empty_folder';
const fileSelector = getGridFileSelector(fileName);
await openContextEntryMenu(fileSelector, 'fileMenuMoveCopyFile');
- await clickOn('[data-tid=MoveTargetempty_folder]');
- /*await setInputKeys(
- 'targetPathInput',
- defaultLocationPath + '/empty_folder'
- );*/
+ await clickOn('[data-tid=MoveTarget' + folderName + ']');
await clickOn('[data-tid=confirmMoveFiles]');
//await waitForNotification();
await expectElementExist(getGridFileSelector(fileName), false);
- // await clickOn('#clearSearchID');
- await global.client.dblclick(selectorFolder);
- // await searchEngine(fileExtension, { reindexing: true }); // TODO temp fix: https://trello.com/c/ZfcGGvOM/527-moved-files-is-not-indexing-not-found-in-search
+ //await global.client.dblclick(selectorFolder);
+ await openContextEntryMenu(getGridFileSelector(folderName), 'openDirectory');
await expectElementExist(getGridFileSelector(fileName), true);
- // let firstFileName = await getGridFileName(0);
- // expect(firstFileName).toBe(fileName);
// Copy file in parent directory
await openContextEntryMenu(fileSelector, 'fileMenuMoveCopyFile');
// await setInputKeys('targetPathInput', defaultLocationPath);
+ await clickOn('[data-tid=navigateToParentTID]');
await clickOn('[data-tid=confirmCopyFiles]');
- //await waitForNotification();
- // await clickOn('#clearSearchID');
+
await clickOn('[data-tid=gridPerspectiveOnBackButton]');
await expectElementExist(getGridFileSelector(fileName), true);
- // await searchEngine(fileExtension);
- /* firstFileName = await getGridFileName(0);
- expect(firstFileName).toBe('sample.' + fileExtension);
-*/
+
// cleanup
- await global.client.dblclick(selectorFolder);
+ // await global.client.dblclick(selectorFolder);
+ await openContextEntryMenu(getGridFileSelector(folderName), 'openDirectory');
await expectElementExist(selectorFile, true);
await deleteFileFromMenu();
await expectElementExist(selectorFile, false);