Skip to content

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

fix: issues with file slection

Ilian Sapundsheivcfd48bd1b23d
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"