Skip to content

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

fix revision issues v5.3 (#1885)

Stanimir459477aacf4b
diff --git a/app/components/EntryContainer.tsx b/app/components/EntryContainer.tsx
index a38ed4959..2342f0e2f 100644
--- a/app/components/EntryContainer.tsx
+++ b/app/components/EntryContainer.tsx
@@ -168,7 +168,7 @@ interface Props {
autohide?: boolean
) => void;
removeAllTags: () => void;
- deleteFile: (path: string) => void;
+ deleteFile: (path: string, uuid: string) => void;
toggleEntryFullWidth: () => void;
isReadOnlyMode: boolean;
setEntryPropertiesSplitSize: (size: string) => void;
@@ -718,17 +718,26 @@ function EntryContainer(props: Props) {
}
};
- const togglePanel = () => {
+ const toggleProperties = () => {
if (isPropPanelVisible && !isRevisionPanelVisible) {
closePanel();
} else {
openPanel();
}
+
+ if (isRevisionPanelVisible) {
+ setRevisionPanelVisible(false);
+ }
};
const toggleRevisions = () => {
- setRevisionPanelVisible(!isRevisionPanelVisible);
- openPanel();
+ if (isRevisionPanelVisible) {
+ setRevisionPanelVisible(false);
+ closePanel();
+ } else {
+ setRevisionPanelVisible(true);
+ openPanel();
+ }
};
const openNextFile = () => {
@@ -826,12 +835,7 @@ function EntryContainer(props: Props) {
<Tooltip title={i18n.t('core:toggleProperties')}>
<IconButton
aria-label={i18n.t('core:toggleProperties')}
- onClick={() => {
- togglePanel();
- if (isRevisionPanelVisible) {
- setRevisionPanelVisible(false);
- }
- }}
+ onClick={toggleProperties}
data-tid="fileContainerToggleProperties"
size="large"
>
@@ -1383,7 +1387,11 @@ function EntryContainer(props: Props) {
}}
>
{openedFile.isFile ? renderFileToolbar(classes) : renderFolderToolbar()}
- {isRevisionPanelVisible ? (
+ {isRevisionPanelVisible &&
+ openedFile.isFile &&
+ Pro &&
+ isEditable &&
+ props.revisionsEnabled ? (
<Revisions />
) : (
<EntryProperties
@@ -1530,7 +1538,7 @@ function EntryContainer(props: Props) {
}
confirmCallback={result => {
if (result) {
- deleteFile(openedFile.path);
+ deleteFile(openedFile.path, openedFile.uuid);
}
}}
cancelDialogTID="cancelSaveBeforeCloseDialog"
diff --git a/app/components/Revisions.tsx b/app/components/Revisions.tsx
index 8397d2531..e3e5c5b7b 100644
--- a/app/components/Revisions.tsx
+++ b/app/components/Revisions.tsx
@@ -57,7 +57,10 @@ import FilePreviewDialog from '-/components/dialogs/FilePreviewDialog';
interface Props {
// openedFile: OpenedEntry;
openedFiles: Array<OpenedEntry>;
- openEntry: (path: string) => void;
+ updateOpenedFile: (
+ entryPath: string,
+ fsEntryMeta: any // FileSystemEntryMeta
+ ) => Promise<boolean>;
theme: any;
}
@@ -120,6 +123,15 @@ function Revisions(props: Props) {
);
}
+ function deleteRevisions() {
+ if (rows.length > 0) {
+ const promises = rows.map(row =>
+ PlatformIO.deleteFilePromise(row.path, true)
+ );
+ Promise.all(promises).then(() => loadHistoryItems(openedFiles[0]));
+ }
+ }
+
function restoreRevision(revisionPath) {
const openedFile = openedFiles[0];
const targetPath = getBackupFileLocation(
@@ -127,13 +139,18 @@ function Revisions(props: Props) {
openedFile.uuid,
PlatformIO.getDirSeparator()
);
- PlatformIO.copyFilePromiseOverwrite(openedFile.path, targetPath).then(
- () => {
- PlatformIO.copyFilePromiseOverwrite(
- revisionPath,
- openedFile.path
- ).then(() => props.openEntry(openedFile.path)); // loadHistoryItems(openedFile));
- }
+ return PlatformIO.copyFilePromiseOverwrite(
+ openedFile.path,
+ targetPath
+ ).then(() =>
+ PlatformIO.copyFilePromiseOverwrite(revisionPath, openedFile.path).then(
+ () =>
+ props.updateOpenedFile(openedFile.path, {
+ ...openedFile,
+ editMode: false,
+ shouldReload: !openedFile.shouldReload
+ })
+ )
);
}
@@ -161,7 +178,23 @@ function Revisions(props: Props) {
>
<TableHead>
<TableRow>
- <TableCell>{i18n.t('revisions')}</TableCell>
+ <TableCell>
+ {i18n.t('revisions')}
+ <Tooltip title={i18n.t('core:deleteAll')}>
+ <IconButton
+ aria-label="delete all revisions"
+ onClick={() =>
+ confirm(
+ 'The all revisions will be deleted. Do you want to continue?'
+ ) && deleteRevisions()
+ }
+ data-tid="deleteRevisionsTID"
+ size="large"
+ >
+ <DeleteIcon color="primary" />
+ </IconButton>
+ </Tooltip>
+ </TableCell>
<TableCell align="right">{i18n.t('created')}</TableCell>
<TableCell align="right">{i18n.t('actions')}</TableCell>
</TableRow>
@@ -175,7 +208,11 @@ function Revisions(props: Props) {
key={row.path}
sx={{ '&:last-child td, &:last-child th': { border: 0 } }}
>
- <TableCell component="th" scope="row">
+ <TableCell
+ component="th"
+ scope="row"
+ onClick={() => setPreviewDialogEntry(row)}
+ >
{row.name}
</TableCell>
<TableCell
@@ -252,7 +289,7 @@ function mapStateToProps(state) {
function mapActionCreatorsToProps(dispatch) {
return bindActionCreators(
{
- openEntry: AppActions.openEntry
+ updateOpenedFile: AppActions.updateOpenedFile
},
dispatch
);
diff --git a/app/containers/MainPage.tsx b/app/containers/MainPage.tsx
index c02435414..74f3ed978 100644
--- a/app/containers/MainPage.tsx
+++ b/app/containers/MainPage.tsx
@@ -214,7 +214,7 @@ interface Props {
isImportKanBanDialogOpened: boolean;
toggleDeleteMultipleEntriesDialog: () => void;
selectedEntries: Array<any>;
- deleteFile: (path: string) => void;
+ deleteFile: (path: string, uuid: string) => void;
deleteDirectory: (path: string) => void;
user: CognitoUserInterface;
setSearchQuery: (searchQuery: TS.SearchQuery) => void;
@@ -803,7 +803,7 @@ function MainPage(props: Props) {
if (result && props.selectedEntries) {
const deletePromises = props.selectedEntries.map(fsEntry => {
if (fsEntry.isFile) {
- return props.deleteFile(fsEntry.path);
+ return props.deleteFile(fsEntry.path, fsEntry.uuid);
}
return props.deleteDirectory(fsEntry.path);
});
diff --git a/app/locales/en/core.json b/app/locales/en/core.json
index 3f4b30ae9..bf5a29df2 100644
--- a/app/locales/en/core.json
+++ b/app/locales/en/core.json
@@ -694,6 +694,7 @@
"showBookmarks": "Bookmarks",
"refresh": "Refresh",
"deleteBookmarks": "Delete All Bookmarks",
+ "deleteAllRevisions": "Delete All Revisions",
"quickAccess": "Quick access",
"resetLocalSettings": "Reset Custom Settings",
"folderWithCustomPerspectiveSetting": "Current folder has custom settings for this perspective",
diff --git a/app/package.json b/app/package.json
index 21aff51e4..2feae06e9 100644
--- a/app/package.json
+++ b/app/package.json
@@ -16,7 +16,7 @@
"@tagspaces/extensions": "1.0.75"
},
"nodeDependencies": {
- "@tagspaces/tagspaces-ws": "2.1.21",
+ "@tagspaces/tagspaces-ws": "2.1.24",
"@tagspaces/extensions": "1.0.75",
"sharp": "0.31.3"
}
diff --git a/app/reducers/app.ts b/app/reducers/app.ts
index 368820d14..becb560b7 100644
--- a/app/reducers/app.ts
+++ b/app/reducers/app.ts
@@ -32,7 +32,8 @@ import {
normalizePath,
extractContainingDirectoryPath,
getMetaFileLocationForDir,
- generateSharingLink
+ generateSharingLink,
+ getBackupFileLocation
} from '@tagspaces/tagspaces-common/paths';
import {
getURLParameter,
@@ -55,7 +56,8 @@ import {
setLocationType,
getRelativeEntryPath,
getCleanLocationPath,
- updateFsEntries
+ updateFsEntries,
+ loadMetaDataPromise
} from '-/services/utils-io';
import { getUuid } from '@tagspaces/tagspaces-common/utils-io';
import i18n from '../services/i18n';
@@ -2417,7 +2419,7 @@ export const actions = {
dispatch(LocationIndexActions.reflectUpdateSidecarTags(path, tags));
}
},
- deleteFile: (filePath: string) => (
+ deleteFile: (filePath: string, uuid: string) => (
dispatch: (action) => void,
getState: () => any
) => {
@@ -2433,6 +2435,24 @@ export const actions = {
true
)
);
+ // Delete revisions
+ const backupFilePath = getBackupFileLocation(
+ filePath,
+ uuid,
+ PlatformIO.getDirSeparator()
+ );
+ const backupPath = extractContainingDirectoryPath(
+ backupFilePath,
+ PlatformIO.getDirSeparator()
+ );
+ PlatformIO.deleteDirectoryPromise(backupPath)
+ .then(() => {
+ console.log('Cleaning revisions successful for ' + filePath);
+ return true;
+ })
+ .catch(err => {
+ console.warn('Cleaning revisions failed ', err);
+ });
// Delete sidecar file and thumb
deleteFilesPromise([
getMetaFileLocationForFile(filePath, PlatformIO.getDirSeparator()),
diff --git a/app/reducers/io-actions.ts b/app/reducers/io-actions.ts
index 6bbe050b2..fdac3a9d5 100644
--- a/app/reducers/io-actions.ts
+++ b/app/reducers/io-actions.ts
@@ -25,6 +25,7 @@ import {
extractFileName,
getMetaFileLocationForFile,
getThumbFileLocationForFile,
+ getBackupFileDir,
normalizePath
} from '@tagspaces/tagspaces-common/paths';
import AppConfig from '-/AppConfig';
@@ -32,6 +33,7 @@ import { actions as AppActions } from './app';
import {
copyFilesPromise,
getThumbPath,
+ loadFileMetaDataPromise,
renameFilesPromise
} from '-/services/utils-io';
import i18n from '../services/i18n';
@@ -83,24 +85,57 @@ const actions = {
console.warn('Moving files failed with ' + err)
dispatch(AppActions.showNotification(i18n.t('core:movingFilesFailed')));
}); */
- const moveJobs = [];
- paths.map(path => {
- moveJobs.push([
- path,
- normalizePath(targetPath) +
- PlatformIO.getDirSeparator() +
- extractFileName(path, PlatformIO.getDirSeparator())
- ]);
- return true;
- });
+ const moveJobs = paths.map(path => [
+ path,
+ normalizePath(targetPath) +
+ PlatformIO.getDirSeparator() +
+ extractFileName(path, PlatformIO.getDirSeparator())
+ ]);
return renameFilesPromise(moveJobs)
.then(() => {
dispatch(
AppActions.showNotification(i18n.t('core:filesMovedSuccessful'))
);
+
const moveMetaJobs = [];
moveJobs.map(job => {
dispatch(AppActions.reflectDeleteEntry(job[0])); // moved files should be added to the index, if the target dir in index
+
+ // Move revisions
+ loadFileMetaDataPromise(job[0]).then(
+ (fsEntryMeta: TS.FileSystemEntryMeta) => {
+ if (fsEntryMeta.id) {
+ const backupDir = getBackupFileDir(
+ job[0],
+ fsEntryMeta.id,
+ PlatformIO.getDirSeparator()
+ );
+ const newBackupDir = getBackupFileDir(
+ job[1],
+ fsEntryMeta.id,
+ PlatformIO.getDirSeparator()
+ );
+ return PlatformIO.moveDirectoryPromise(
+ backupDir,
+ newBackupDir
+ )
+ .then(() => {
+ console.log(
+ 'Moving revisions successful from ' +
+ backupDir +
+ ' to ' +
+ newBackupDir
+ );
+ return true;
+ })
+ .catch(err => {
+ console.warn('Moving revisions failed ', err);
+ });
+ }
+ }
+ );
+
+ // move meta
moveMetaJobs.push([
getMetaFileLocationForFile(job[0], PlatformIO.getDirSeparator()),
getMetaFileLocationForFile(job[1], PlatformIO.getDirSeparator())
diff --git a/app/services/platform-facade.ts b/app/services/platform-facade.ts
index 9cb02a92d..201ea33bb 100644
--- a/app/services/platform-facade.ts
+++ b/app/services/platform-facade.ts
@@ -56,6 +56,7 @@ import {
platformCopyFilePromise,
platformRenameFilePromise,
platformRenameDirectoryPromise,
+ platformMoveDirectoryPromise,
platformDeleteFilePromise,
platformDeleteDirectoryPromise,
platformOpenDirectory,
@@ -333,6 +334,18 @@ export default class PlatformFacade {
});
};
+ static moveDirectoryPromise = (
+ dirPath: string,
+ newDirPath: string
+ ): Promise<any> => {
+ PlatformFacade.ignoreByWatcher(dirPath, newDirPath);
+
+ return platformMoveDirectoryPromise(dirPath, newDirPath).then(result => {
+ PlatformFacade.deignoreByWatcher(dirPath, newDirPath);
+ return result;
+ });
+ };
+
static loadTextFilePromise = (
filePath: string,
isPreview?: boolean
diff --git a/app/services/utils-io.ts b/app/services/utils-io.ts
index 1ebdfe87b..5c8386827 100644
--- a/app/services/utils-io.ts
+++ b/app/services/utils-io.ts
@@ -1472,13 +1472,13 @@ export function updateFsEntries(
export function mergeFsEntryMeta(props: any = {}): TS.FileSystemEntryMeta {
return {
- id: props.id || getUuid(),
appName: versionMeta.name,
appVersion: versionMeta.version,
description: '',
lastUpdated: new Date().getTime(),
tags: [],
- ...props
+ ...props,
+ id: props.id || getUuid()
};
}
diff --git a/package-lock.json b/package-lock.json
index f522ffa25..0af618440 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -22,7 +22,7 @@
"@mui/styles": "5.10.15",
"@mui/x-date-pickers": "^5.0.8",
"@tagspaces/tagspaces-md": "2.1.6",
- "@tagspaces/tagspaces-platforms": "2.1.20",
+ "@tagspaces/tagspaces-platforms": "2.1.24",
"aws-amplify": "^4.3.8",
"aws-sdk": "^2.1036.0",
"babel-polyfill": "^6.26.0",
@@ -13825,9 +13825,9 @@
}
},
"node_modules/@tagspaces/tagspaces-platforms": {
- "version": "2.1.20",
- "resolved": "https://registry.npmjs.org/@tagspaces/tagspaces-platforms/-/tagspaces-platforms-2.1.20.tgz",
- "integrity": "sha512-zR7Wx9QAplLIxekLJbCMfPkfprlxq7a4ZP0bqw9BIHsWgOoXe2HHnUR10jr8rTWhTBgFkZ7G4z371kV37K/zBQ==",
+ "version": "2.1.24",
+ "resolved": "https://registry.npmjs.org/@tagspaces/tagspaces-platforms/-/tagspaces-platforms-2.1.24.tgz",
+ "integrity": "sha512-NYWOV4CDoX/PYExtpFqqXSll43QEjcNpy/e6j2HTd91ZF0OVdhPrN+oSUjAFuW8q8OjA1Jz8LBAYDWKr42rlLg==",
"hasInstallScript": true
},
"node_modules/@testim/chrome-version": {
@@ -59537,9 +59537,9 @@
}
},
"@tagspaces/tagspaces-platforms": {
- "version": "2.1.20",
- "resolved": "https://registry.npmjs.org/@tagspaces/tagspaces-platforms/-/tagspaces-platforms-2.1.20.tgz",
- "integrity": "sha512-zR7Wx9QAplLIxekLJbCMfPkfprlxq7a4ZP0bqw9BIHsWgOoXe2HHnUR10jr8rTWhTBgFkZ7G4z371kV37K/zBQ=="
+ "version": "2.1.24",
+ "resolved": "https://registry.npmjs.org/@tagspaces/tagspaces-platforms/-/tagspaces-platforms-2.1.24.tgz",
+ "integrity": "sha512-NYWOV4CDoX/PYExtpFqqXSll43QEjcNpy/e6j2HTd91ZF0OVdhPrN+oSUjAFuW8q8OjA1Jz8LBAYDWKr42rlLg=="
},
"@testim/chrome-version": {
"version": "1.1.3",
diff --git a/package.json b/package.json
index 4f20f6eb1..241853246 100644
--- a/package.json
+++ b/package.json
@@ -161,7 +161,7 @@
"@mui/styles": "5.10.15",
"@mui/x-date-pickers": "^5.0.8",
"@tagspaces/tagspaces-md": "2.1.6",
- "@tagspaces/tagspaces-platforms": "2.1.21",
+ "@tagspaces/tagspaces-platforms": "2.1.24",
"aws-amplify": "^4.3.8",
"aws-sdk": "^2.1036.0",
"babel-polyfill": "^6.26.0",