TagSpaces is an offline, open source, document manager with tagging support
e2e fixes and tags with watcher
sytolke753c50c2949
diff --git a/src/renderer/components/EntryProperties.tsx b/src/renderer/components/EntryProperties.tsxindex 25b02e0c5..d149f140f 100644--- a/src/renderer/components/EntryProperties.tsx+++ b/src/renderer/components/EntryProperties.tsx@@ -24,7 +24,10 @@ import React, {useState,} from 'react';import { styled, useTheme } from '@mui/material/styles';-import { getBgndFileLocationForDirectory } from '@tagspaces/tagspaces-common/paths';+import {+ getBgndFileLocationForDirectory,+ getMetaFileLocationForFile,+} from '@tagspaces/tagspaces-common/paths';import L from 'leaflet';import {Grid,@@ -99,6 +102,7 @@ import { useFsActionsContext } from '-/hooks/useFsActionsContext';import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';import { useNotificationContext } from '-/hooks/useNotificationContext';+import { useFSWatcherContext } from '-/hooks/useFSWatcherContext';const PREFIX = 'EntryProperties';@@ -209,6 +213,7 @@ function EntryProperties(props: Props) {const { switchLocationTypeByID, switchCurrentLocationType, readOnlyMode } =useCurrentLocationContext();const { showNotification } = useNotificationContext();+ const { ignoreByWatcher, deignoreByWatcher } = useFSWatcherContext();const dispatch: AppDispatch = useDispatch();const fileNameRef = useRef<HTMLInputElement>(null);@@ -467,43 +472,42 @@ function EntryProperties(props: Props) {};*/const handleChange = (name: string, value: Array<TS.Tag>, action: string) => {- switchLocationTypeByID(currentEntry.locationId).then(- (currentLocationId) => {+ const metaFilePath = getMetaFileLocationForFile(+ currentEntry.path,+ PlatformIO.getDirSeparator(),+ );+ // tmp fix; saving meta sidecar file is not ignored by watcher+ ignoreByWatcher(metaFilePath);+ switchLocationTypeByID(currentEntry.locationId)+ .then((currentLocationId) => {if (action === 'remove-value') {if (!value) {// no tags left in the select element- removeAllTags([currentEntry.path]).then(() => {+ return removeAllTags([currentEntry.path]).then(() =>updateOpenedFile(currentEntry.path, {id: '',tags: [],- }).then(() => {- switchCurrentLocationType();- });- });- } else {- removeTags([currentEntry.path], value).then(() =>- switchCurrentLocationType(),+ }),);+ } else {+ return removeTags([currentEntry.path], value);}} else if (action === 'clear') {- removeAllTags([currentEntry.path]).then(() =>- switchCurrentLocationType(),- );- } else {- // create-option or select-option- const tags =- currentEntry.tags === undefined- ? value- : value.filter(- (tag) =>- !currentEntry.tags.some((obj) => obj.title === tag.title),- );- return addTags([currentEntry.path], tags).then(() =>- switchCurrentLocationType(),- );+ return removeAllTags([currentEntry.path]);}- },- );+ // create-option or select-option+ const tags =+ currentEntry.tags === undefined+ ? value+ : value.filter(+ (tag) =>+ !currentEntry.tags.some((obj) => obj.title === tag.title),+ );+ return addTags([currentEntry.path], tags);+ })+ .then(() => {+ switchCurrentLocationType().then(() => deignoreByWatcher(metaFilePath));+ });};if (!currentEntry || !currentEntry.path || currentEntry.path === '') {diff --git a/src/renderer/components/dialogs/AddRemoveTagsDialog.tsx b/src/renderer/components/dialogs/AddRemoveTagsDialog.tsxindex 9ebdb0024..0450c699b 100644--- a/src/renderer/components/dialogs/AddRemoveTagsDialog.tsx+++ b/src/renderer/components/dialogs/AddRemoveTagsDialog.tsx@@ -34,6 +34,7 @@ import TagsSelect from '../TagsSelect';import {extractFileName,extractDirectoryName,+ getMetaFileLocationForFile,} from '@tagspaces/tagspaces-common/paths';import PlatformIO from '-/services/platform-facade';import { TS } from '-/tagspaces.namespace';@@ -43,6 +44,7 @@ import useMediaQuery from '@mui/material/useMediaQuery';import { useTranslation } from 'react-i18next';import { useTaggingActionsContext } from '-/hooks/useTaggingActionsContext';import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';+import { useFSWatcherContext } from '-/hooks/useFSWatcherContext';interface Props {open: boolean;@@ -56,6 +58,7 @@ function AddRemoveTagsDialog(props: Props) {const { selectedEntries } = useSelectedEntriesContext();const selected = props.selected ? props.selected : selectedEntries;const { addTags, removeTags, removeAllTags } = useTaggingActionsContext();+ const { ignoreByWatcher, deignoreByWatcher } = useFSWatcherContext();const [newlyAddedTags, setNewlyAddedTags] = useState<Array<TS.Tag>>([]);const handleChange = (name: string, value: Array<TS.Tag>, action: string) => {@@ -80,9 +83,14 @@ function AddRemoveTagsDialog(props: Props) {const addTagsAction = () => {if (selected && selected.length > 0) {- addTags(- selected.map((entry) => entry.path),- newlyAddedTags,+ const paths = selected.map((entry) => entry.path);+ const metaFilePaths: string[] = paths.map((p) =>+ getMetaFileLocationForFile(p, PlatformIO.getDirSeparator()),+ );+ // tmp fix; saving meta sidecar file is not ignored by watcher+ ignoreByWatcher(...metaFilePaths);+ addTags(paths, newlyAddedTags).then(() =>+ deignoreByWatcher(...metaFilePaths),);}onCloseDialog(true);@@ -90,9 +98,14 @@ function AddRemoveTagsDialog(props: Props) {const removeTagsAction = () => {if (selected && selected.length > 0) {- removeTags(- selected.map((entry) => entry.path),- newlyAddedTags,+ const paths = selected.map((entry) => entry.path);+ const metaFilePaths: string[] = paths.map((p) =>+ getMetaFileLocationForFile(p, PlatformIO.getDirSeparator()),+ );+ // tmp fix; saving meta sidecar file is not ignored by watcher+ ignoreByWatcher(...metaFilePaths);+ removeTags(paths, newlyAddedTags).then(() =>+ deignoreByWatcher(...metaFilePaths),);}onCloseDialog(true);@@ -100,7 +113,13 @@ function AddRemoveTagsDialog(props: Props) {const removeAllTagsAction = () => {if (selected && selected.length > 0) {- removeAllTags(selected.map((entry) => entry.path));+ const paths = selected.map((entry) => entry.path);+ const metaFilePaths: string[] = paths.map((p) =>+ getMetaFileLocationForFile(p, PlatformIO.getDirSeparator()),+ );+ // tmp fix; saving meta sidecar file is not ignored by watcher+ ignoreByWatcher(...metaFilePaths);+ removeAllTags(paths).then(() => deignoreByWatcher(...metaFilePaths));}onCloseDialog(true);};diff --git a/src/renderer/hooks/DirectoryContentContextProvider.tsx b/src/renderer/hooks/DirectoryContentContextProvider.tsxindex 7653c39db..7f921d2e0 100644--- a/src/renderer/hooks/DirectoryContentContextProvider.tsx+++ b/src/renderer/hooks/DirectoryContentContextProvider.tsx@@ -25,11 +25,7 @@ import React, {} from 'react';import { useDispatch, useSelector } from 'react-redux';import { locationType } from '@tagspaces/tagspaces-common/misc';-import {- actions as AppActions,- AppDispatch,- getEditedEntryPaths,-} from '-/reducers/app';+import { actions as AppActions, AppDispatch } from '-/reducers/app';import { TS } from '-/tagspaces.namespace';import { useTranslation } from 'react-i18next';import {diff --git a/src/renderer/hooks/FSWatcherContextProvider.tsx b/src/renderer/hooks/FSWatcherContextProvider.tsxindex 4ac385a58..6fd77d70f 100644--- a/src/renderer/hooks/FSWatcherContextProvider.tsx+++ b/src/renderer/hooks/FSWatcherContextProvider.tsx@@ -27,10 +27,8 @@ import {import { locationType } from '@tagspaces/tagspaces-common/misc';import { PerspectiveIDs } from '-/perspectives';import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';-import { actions as AppActions, AppDispatch } from '-/reducers/app';import { toFsEntry } from '-/services/utils-io';import { useLocationIndexContext } from '-/hooks/useLocationIndexContext';-import { useDispatch } from 'react-redux';import { Changed } from '../../main/chokidarWatcher';type FSWatcherContextData = {@@ -119,10 +117,14 @@ export const FSWatcherContextProvider = ({const folderChanged = useMemo(() => {return (event, path): void => {console.log(`File ${path} has been ${event}`);+ if (watchingFolderPath.current === undefined) {+ return;+ }if (path.endsWith(AppConfig.metaFolder)) {// .ts dir createdreturn;}+ // console.log(`ignored list:` + JSON.stringify(ignored.current));const pathParts = path.split(PlatformIO.getDirSeparator());for (let i = 0; i < ignored.current.length; i++) {if (@@ -184,6 +186,7 @@ export const FSWatcherContextProvider = ({// watching for changed sidecar files .ts/file.jpg.jsonif (path.includes(AppConfig.metaFolder)) {+ // todo reload meta for changed file onlyif (path.endsWith(AppConfig.metaFileExt)) {const directoryPath = getFileLocationFromMetaFile(path,diff --git a/src/renderer/hooks/OpenedEntryContextProvider.tsx b/src/renderer/hooks/OpenedEntryContextProvider.tsxindex ed362be1a..68140b8f3 100644--- a/src/renderer/hooks/OpenedEntryContextProvider.tsx+++ b/src/renderer/hooks/OpenedEntryContextProvider.tsx@@ -112,6 +112,7 @@ type OpenedEntryContextData = {newEntryPath: string,reload?: boolean,) => void;+ reflectSidecarTagsUpdate: (entryPath: string, tags: TS.Tag[]) => void;reflectDeleteDirectory: (directoryPath: string) => void;reflectDeleteFile: (filePath: string) => void;};@@ -138,6 +139,7 @@ export const OpenedEntryContext = createContext<OpenedEntryContextData>({createFile: () => {},createFileAdvanced: () => {},reflectRenameOpenedEntry: () => {},+ reflectSidecarTagsUpdate: undefined,reflectDeleteDirectory: undefined,reflectDeleteFile: undefined,});@@ -287,7 +289,7 @@ export const OpenedEntryContextProvider = ({/*** HANDLE REFLECT_RENAME_ENTRY*/- useEffect(() => {+ /*useEffect(() => {if (!firstRender && editedEntryPaths && editedEntryPaths.length > 0) {let action;for (const editedEntryPath of editedEntryPaths) {@@ -298,36 +300,11 @@ export const OpenedEntryContextProvider = ({const newFilePath = editedEntryPaths[1].path;if (openedEntries.some((entry) => entry.path === oldFilePath)) {- const extractedTags = extractTagsAsObjects(- newFilePath,- AppConfig.tagDelimiter,- PlatformIO.getDirSeparator(),- );-- const newEntries = openedEntries.map((entry) => {- if (entry.path !== oldFilePath) {- return entry;- }- const fileNameTags = entry.isFile ? extractedTags : []; // dirs dont have tags in filename- // const { url, ...rest } = entry;- const sidecarTags =- entry.tags && entry.tags.length > 0- ? entry.tags.filter((tag) => tag.type !== 'plain')- : [];- return {- ...entry,- path: newFilePath, // TODO handle change extension case- tags: [- ...sidecarTags, // add only sidecar tags- ...fileNameTags,- ],- // shouldReload: true- };- });+ const newEntries = getRenamedEntries(oldFilePath, newFilePath);setSharedLinks(newEntries[0]);setOpenedEntries(newEntries);}- } /*else if (action === 'delete') {+ } /!*else if (action === 'delete') {const filePath = editedEntryPaths[0].path;if (openedEntries &&@@ -336,9 +313,47 @@ export const OpenedEntryContextProvider = ({) {closeAllFiles();}- }*/+ }*!/}- }, [editedEntryPaths]);+ }, [editedEntryPaths]);*/++ function getRenamedEntry(oldFilePath, newFilePath, scarTags?) {+ const extractedTags = extractTagsAsObjects(+ newFilePath,+ AppConfig.tagDelimiter,+ PlatformIO.getDirSeparator(),+ );+ if (currentEntry.current) {+ if (currentEntry.current.path !== oldFilePath) {+ return currentEntry.current;+ }+ const fileNameTags = currentEntry.current.isFile ? extractedTags : []; // dirs dont have tags in filename++ let sidecarTags;+ if (scarTags !== undefined) {+ sidecarTags = scarTags;+ } else if (+ currentEntry.current.tags &&+ currentEntry.current.tags.length > 0+ ) {+ sidecarTags = currentEntry.current.tags.filter(+ (tag) => tag.type !== 'plain',+ );+ } else {+ sidecarTags = [];+ }+ return {+ ...currentEntry.current,+ path: newFilePath, // TODO handle change extension case+ tags: [+ ...sidecarTags, // add only sidecar tags+ ...fileNameTags,+ ],+ // shouldReload: true+ };+ }+ return undefined;+ }function setSharedLinks(openedFile?) {if (openedFile) {@@ -1019,7 +1034,7 @@ export const OpenedEntryContextProvider = ({function reflectRenameOpenedEntry(entryPath, newEntryPath, reload = false) {if (openedEntries && openedEntries.length > 0) {- if (openedEntries[0].path === entryPath) {+ if (openedEntries.some((entry) => entry.path === entryPath)) {if (currentLocation) {updateHistory({ ...currentLocation, path: currentLocationPath },@@ -1030,12 +1045,21 @@ export const OpenedEntryContextProvider = ({if (reload) {openEntry(newEntryPath);} else {- addToEntryContainer({ ...openedEntries[0], path: newEntryPath });+ const newEntry = getRenamedEntry(entryPath, newEntryPath);+ setSharedLinks(newEntry);+ setOpenedEntries([newEntry]);+ //addToEntryContainer({ ...openedEntries[0], path: newEntryPath });}}}}+ function reflectSidecarTagsUpdate(entryPath, tags) {+ const newEntry = getRenamedEntry(entryPath, entryPath, tags);+ setSharedLinks(newEntry);+ setOpenedEntries([newEntry]);+ }+const reflectDeleteDirectory = useMemo(() => {return (directoryPath: string) => {if (@@ -1089,6 +1113,7 @@ export const OpenedEntryContextProvider = ({createFile,createFileAdvanced,reflectRenameOpenedEntry,+ reflectSidecarTagsUpdate,reflectDeleteDirectory,reflectDeleteFile,};diff --git a/src/renderer/hooks/TaggingActionsContextProvider.tsx b/src/renderer/hooks/TaggingActionsContextProvider.tsxindex 017df6c7f..4a1a3c34c 100644--- a/src/renderer/hooks/TaggingActionsContextProvider.tsx+++ b/src/renderer/hooks/TaggingActionsContextProvider.tsx@@ -96,8 +96,12 @@ export const TaggingActionsContextProvider = ({children,}: TaggingActionsContextProviderProps) => {const { t } = useTranslation();- const { openedEntries, updateOpenedFile, reflectRenameOpenedEntry } =- useOpenedEntryContext();+ const {+ openedEntries,+ updateOpenedFile,+ reflectSidecarTagsUpdate,+ reflectRenameOpenedEntry,+ } = useOpenedEntryContext();const { updateCurrentDirEntry, reflectRenameEntries } =useDirectoryContentContext();const { persistTagsInSidecarFile } = useCurrentLocationContext();@@ -303,10 +307,10 @@ export const TaggingActionsContextProvider = ({.then(() => {// TODO rethink this updateCurrentDirEntry and not need for KanBanreflectUpdateSidecarTags(path, newTags, updateIndex);- updateOpenedFile(path, {+ /* updateOpenedFile(path, {id: 'opened_entry_id',tags: newTags,- });+ });*/return [path, path];}).catch((err) => {@@ -325,10 +329,11 @@ export const TaggingActionsContextProvider = ({.then(() => {// TODO rethink this updateCurrentDirEntry and not need for KanBanreflectUpdateSidecarTags(path, tags, updateIndex);- return updateOpenedFile(path, { id: '', tags }).then(() => [+ /*return updateOpenedFile(path, { id: '', tags }).then(() => [path,path,- ]);+ ]);*/+ return [path, path];}).catch((error) => {console.warn('Error adding tags for ' + path + ' with ' + error);@@ -548,10 +553,10 @@ export const TaggingActionsContextProvider = ({tags: newTagsArray,}).then(() => {- updateOpenedFile(path, {+ /*updateOpenedFile(path, {id: '',tags: newTagsArray,- });+ });*/// TODO rethink this updateCurrentDirEntry and not need for KanBanreflectUpdateSidecarTags(path, newTagsArray, true);return true;@@ -577,10 +582,10 @@ export const TaggingActionsContextProvider = ({const fsEntryMeta = { tags: [tag] };saveMetaDataPromise(path, fsEntryMeta).then(() => {- updateOpenedFile(path, {+ /*updateOpenedFile(path, {id: '',tags: fsEntryMeta.tags,- });+ });*/// TODO rethink this updateCurrentDirEntry and not need for KanBanreflectUpdateSidecarTags(path, fsEntryMeta.tags);return true;@@ -772,7 +777,7 @@ export const TaggingActionsContextProvider = ({reject(new Error('Error renaming file'));return;}- reflectRenameOpenedEntry(path, newFilePath, true);+ // reflectRenameOpenedEntry(path, newFilePath, true);}resolve(newFilePath);} else {@@ -841,6 +846,7 @@ export const TaggingActionsContextProvider = ({dispatch(AppActions.reflectEditedEntryPaths([{ action, path }])); //[{ [path]: tags }]));// @ts-ignoreupdateCurrentDirEntry(path, { tags });+ reflectSidecarTagsUpdate(path, tags);if (updateIndex) {indexUpdateSidecarTags(path, tags);diff --git a/tests/e2e/fileopener.pw.e2e.js b/tests/e2e/fileopener.pw.e2e.jsindex 0f9214b49..f77676afd 100644--- a/tests/e2e/fileopener.pw.e2e.js+++ b/tests/e2e/fileopener.pw.e2e.js@@ -71,7 +71,7 @@ test.describe('TST08 - File folder properties', () => {await clickOn(selectorFile);//Toggle Properties//await clickOn('[data-tid=fileContainerToggleProperties]');-+ await expectElementExist('[data-tid=detailsTabTID]', true, 5000);await clickOn('[data-tid=detailsTabTID]');const propsFileName = await getPropertiesFileName();const firstFileName = await getGridFileName(0);@@ -111,7 +111,7 @@ test.describe('TST08 - File folder properties', () => {await clickOn(selectorFile);//Toggle Properties//await clickOn('[data-tid=fileContainerToggleProperties]');-+ await expectElementExist('[data-tid=detailsTabTID]', true, 5000);await clickOn('[data-tid=detailsTabTID]');const propsFileName = await getPropertiesFileName();const firstFileName = await getGridFileName(0);@@ -419,6 +419,7 @@ test.describe('TST08 - File folder properties', () => {test('TST0827 - Link for internal sharing + copy [web,minio,electron]', async () => {const fileName = 'sample.jpg';await clickOn(getGridFileSelector(fileName));+ await expectElementExist('[data-tid=detailsTabTID]', true, 5000);await clickOn('[data-tid=detailsTabTID]');const sharingLink = await global.client.$(diff --git a/tests/e2e/general.helpers.js b/tests/e2e/general.helpers.jsindex 984d63f22..f3232c022 100644--- a/tests/e2e/general.helpers.js+++ b/tests/e2e/general.helpers.js@@ -182,7 +182,7 @@ export async function getGridFileName(fileIndex) {//file = await file.$('div');const fileNameElem = await file.$('div div div:nth-child(2) p');const fileName = await fileNameElem.getAttribute('title');- return fileName;+ return fileName.replace(/ *\[[^\]]*]/, '');/*const fileName = await getElementText(fileNameElem);const divs = await file.$$('div');const lastDiv = await divs[divs.length - 1];diff --git a/tests/e2e/perspective-grid.pw.e2e.js b/tests/e2e/perspective-grid.pw.e2e.jsindex 33f2c57cf..bf03d57b3 100644--- a/tests/e2e/perspective-grid.pw.e2e.js+++ b/tests/e2e/perspective-grid.pw.e2e.js@@ -68,6 +68,7 @@ test.describe('TST50 - Perspective Grid', () => {// const firstFileName = await getGridFileName(0);await clickOn(getGridFileSelector(fileName));+ await expectElementExist('[data-tid=detailsTabTID]', true, 5000);await clickOn('[data-tid=detailsTabTID]');// Toggle Properties//await clickOn('[data-tid=fileContainerToggleProperties]');@@ -176,6 +177,7 @@ test.describe('TST50 - Perspective Grid', () => {test('TST5008 - Copy file [web,minio,electron]', async () => {const fileName = 'sample.svg';await clickOn(getGridFileSelector(fileName));+ await expectElementExist('[data-tid=detailsTabTID]', true, 5000);//Toggle Propertiesawait clickOn('[data-tid=detailsTabTID]');// add meta json to file@@ -211,6 +213,7 @@ test.describe('TST50 - Perspective Grid', () => {test('TST5010 - Move file [web,minio,electron]', async () => {const fileName = 'sample.svg';await clickOn(getGridFileSelector(fileName));+ await expectElementExist('[data-tid=detailsTabTID]', true, 5000);//Toggle Propertiesawait clickOn('[data-tid=detailsTabTID]');// add meta json to file