Skip to content

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

fix: some issues related to the new dialogs, correcting some e2e

Ilian Sapundshiev8c18bb0d3ad5
diff --git a/src/renderer/components/FolderBrowser/FolderBrowser.tsx b/src/renderer/components/FolderBrowser/FolderBrowser.tsx
index 8867e55c3..08165a75c 100644
--- a/src/renderer/components/FolderBrowser/FolderBrowser.tsx
+++ b/src/renderer/components/FolderBrowser/FolderBrowser.tsx
@@ -29,13 +29,24 @@ import Box from '@mui/material/Box';
import InputAdornment from '@mui/material/InputAdornment';
import Paper from '@mui/material/Paper';
import TextField from '@mui/material/TextField';
-import { extractParentDirectoryPath } from '@tagspaces/tagspaces-common/paths';
+import {
+ cleanFrontDirSeparator,
+ cleanTrailingDirSeparator,
+ extractParentDirectoryPath,
+} from '@tagspaces/tagspaces-common/paths';
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
import FolderList, { FolderListFilter } from './FolderList';
import LocationBreadcrumb from './LocationBreadcrumb';
import LocationPicker from './LocationPicker';
+function normalizePath(p: string): string {
+ if (!p) return '';
+ return cleanTrailingDirSeparator(
+ cleanFrontDirSeparator(p.replace(/\\/g, '/')),
+ );
+}
+
interface Props {
locations: CommonLocation[];
activeLocationId: string;
@@ -59,6 +70,8 @@ interface Props {
onQueryChange?: (query: string) => void;
/** Fixed height of the folder list area. */
listHeight?: number | string;
+ /** Bump to force the folder list to re-fetch its current path. */
+ refreshKey?: number;
}
function FolderBrowser({
@@ -75,16 +88,31 @@ function FolderBrowser({
onCreateFolder,
onQueryChange,
listHeight = 240,
+ refreshKey,
}: Props) {
const { t } = useTranslation();
const [query, setQuery] = useState('');
const activeLocation = locations.find((l) => l.uuid === activeLocationId);
const sep = activeLocation?.getDirSeparator?.() || '/';
+ // We can't always compare `path` against `activeLocation.path` directly:
+ // extconfig-defined locations carry a *relative* path like
+ // `./tests/testdata-0/file-structure/supported-filestypes` while the
+ // runtime `path` is absolute (`/Users/.../supported-filestypes`). Anchor
+ // the "are we at the location root?" check on the location's leaf folder
+ // name (basename) so the equality holds in both shapes.
+ const rootNorm = normalizePath(activeLocation?.path || '');
+ const pathNorm = normalizePath(path || '');
+ const rootSegments = rootNorm.split('/').filter((s) => s.length > 0);
+ const rootLeaf = rootSegments[rootSegments.length - 1];
+ const pathSegments = pathNorm.split('/').filter((s) => s.length > 0);
+ const pathLeaf = pathSegments[pathSegments.length - 1];
+
const atLocationRoot =
!!activeLocation &&
- (path === (activeLocation.path || '') ||
- (path === '' && !activeLocation.path));
+ (pathNorm === rootNorm ||
+ (pathNorm === '' && !rootNorm) ||
+ (!!rootLeaf && !!pathLeaf && rootLeaf === pathLeaf));
function setQueryAndNotify(next: string) {
setQuery(next);
@@ -93,17 +121,7 @@ function FolderBrowser({
function handleUp() {
if (atLocationRoot || !activeLocation) return;
- const parent = extractParentDirectoryPath(path, sep);
- if (
- activeLocation.path &&
- (parent === activeLocation.path ||
- parent === '' ||
- !parent.startsWith(activeLocation.path))
- ) {
- onPathChange(activeLocation.path);
- } else {
- onPathChange(parent);
- }
+ onPathChange(extractParentDirectoryPath(path, sep));
}
if (!activeLocation) {
@@ -216,6 +234,7 @@ function FolderBrowser({
onDescend={onPathChange}
onFileSelect={onFileSelect}
height={listHeight}
+ refreshKey={refreshKey}
/>
</Box>
</Box>
diff --git a/src/renderer/components/FolderBrowser/FolderList.tsx b/src/renderer/components/FolderBrowser/FolderList.tsx
index fa9558b56..ac1fd6d8c 100644
--- a/src/renderer/components/FolderBrowser/FolderList.tsx
+++ b/src/renderer/components/FolderBrowser/FolderList.tsx
@@ -103,6 +103,8 @@ interface Props {
/** Fixed visible height for the list area. Content scrolls; loading and
* empty states center inside this area so the parent's layout stays stable. */
height?: number | string;
+ /** Bump to force a re-fetch of the current path (e.g. after creating a folder). */
+ refreshKey?: number;
}
function FolderList({
@@ -114,6 +116,7 @@ function FolderList({
onDescend,
onFileSelect,
height = 240,
+ refreshKey = 0,
}: Props) {
const { t } = useTranslation();
const supportedFileTypes = useSelector(getSupportedFileTypes);
@@ -187,7 +190,7 @@ function FolderList({
return () => {
cancelled = true;
};
- }, [location, path]);
+ }, [location, path, refreshKey]);
const visible = useMemo(() => {
const q = (query || '').trim().toLowerCase();
diff --git a/src/renderer/components/FolderBrowser/LocationBreadcrumb.tsx b/src/renderer/components/FolderBrowser/LocationBreadcrumb.tsx
index 9283fa95f..cf71eacbd 100644
--- a/src/renderer/components/FolderBrowser/LocationBreadcrumb.tsx
+++ b/src/renderer/components/FolderBrowser/LocationBreadcrumb.tsx
@@ -50,12 +50,25 @@ function LocationBreadcrumb({ location, path, onJump }: Props) {
const pathNorm = normalize(path || '');
// Compute the segments inside the location.
+ // The "root" segment is anchored on the basename of location.path — this
+ // tolerates locations whose configured path is relative (e.g. extconfig
+ // entries used by the e2e tests) while the runtime `path` is absolute.
+ // Without this, every ancestor of the location surface (e.g. `/Users/na/…`)
+ // would leak into the breadcrumb.
+ const rootSegments = rootNorm.split('/').filter((s) => s.length > 0);
+ const rootLeaf = rootSegments[rootSegments.length - 1];
let inside = pathNorm;
if (
rootNorm &&
(pathNorm === rootNorm || pathNorm.startsWith(rootNorm + '/'))
) {
inside = pathNorm.slice(rootNorm.length).replace(/^\/+/, '');
+ } else if (rootLeaf) {
+ const pathSegments = pathNorm.split('/').filter((s) => s.length > 0);
+ const rootIdx = pathSegments.lastIndexOf(rootLeaf);
+ if (rootIdx >= 0) {
+ inside = pathSegments.slice(rootIdx + 1).join('/');
+ }
}
const segments = inside.split('/').filter((s) => s.length > 0);
diff --git a/src/renderer/components/dialogs/FilePickerDialog.tsx b/src/renderer/components/dialogs/FilePickerDialog.tsx
index 597918ff3..806091c93 100644
--- a/src/renderer/components/dialogs/FilePickerDialog.tsx
+++ b/src/renderer/components/dialogs/FilePickerDialog.tsx
@@ -319,7 +319,7 @@ function FilePickerDialog(props: FilePickerDialogProps) {
onClose={onClose}
/>
<DialogContent sx={{ overflowX: 'hidden', overflowY: 'auto' }}>
- {targetLocation && (
+ {open && targetLocation && (
<FolderBrowser
locations={locations}
activeLocationId={targetLocation.uuid}
diff --git a/src/renderer/components/dialogs/MoveCopyFilesDialog.tsx b/src/renderer/components/dialogs/MoveCopyFilesDialog.tsx
index 530d807aa..7bbb76601 100644
--- a/src/renderer/components/dialogs/MoveCopyFilesDialog.tsx
+++ b/src/renderer/components/dialogs/MoveCopyFilesDialog.tsx
@@ -121,6 +121,10 @@ function MoveCopyFilesDialog(props: Props) {
// Phase 7 will use `searchQuery` to hide the Recent destinations row while typing.
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [searchQuery, setSearchQuery] = useState('');
+ // Bumped after creating a subfolder via the picker so FolderList re-fetches
+ // and the new folder appears in the current path's list (instead of silently
+ // navigating into it, which would hide MoveTarget<name> from the picker).
+ const [dirVersion, setDirVersion] = useState(0);
function handlePickLocation(loc: any) {
setActiveTargetLocationId(loc.uuid);
@@ -405,7 +409,7 @@ function MoveCopyFilesDialog(props: Props) {
</Box>
{/* Regions 3 + 4 + 6: Destination row + Tools row + Folder list (single composition) */}
- {!skipTargetPicker && targetLocation && (
+ {open && !skipTargetPicker && targetLocation && (
<>
<Typography
variant="overline"
@@ -467,12 +471,17 @@ function MoveCopyFilesDialog(props: Props) {
locationDisabledTooltip={t('core:cloudCrossLocationNotSupported')}
filter="folders"
onCreateFolder={(parent) =>
- openCreateDirectoryDialog(parent, (newDirPath: string) =>
- setTargetPath(newDirPath),
- )
+ openCreateDirectoryDialog(parent, () => {
+ // Stay at the parent path; bump the version so FolderList
+ // re-fetches and the new folder shows up. Auto-navigating
+ // into the new folder would hide it from the picker list
+ // and break the create-then-select flow.
+ setDirVersion((v) => v + 1);
+ })
}
onQueryChange={setSearchQuery}
listHeight={smallScreen ? '50vh' : 240}
+ refreshKey={dirVersion}
/>
{showInlineError && validityMessageKey && (
<Box
diff --git a/src/renderer/components/dialogs/components/computeMoveCopyValidity.ts b/src/renderer/components/dialogs/components/computeMoveCopyValidity.ts
index 2c5d73ac6..c763b628f 100644
--- a/src/renderer/components/dialogs/components/computeMoveCopyValidity.ts
+++ b/src/renderer/components/dialogs/components/computeMoveCopyValidity.ts
@@ -58,7 +58,9 @@ export function computeMoveCopyValidity({
sourceLocation,
mode,
}: Params): MoveCopyValidity {
- if (!targetPath || !targetLocation) {
+ // S3 bucket roots have an empty `path`, so treat any non-null `targetPath`
+ // as a valid destination as long as the location itself is selected.
+ if (!targetLocation || targetPath === undefined || targetPath === null) {
return { disabled: true, reason: 'no-target' };
}
diff --git a/tests/e2e/cmdopen.pw.e2e.js b/tests/e2e/cmdopen.pw.e2e.js
index 3594be55b..70c735688 100644
--- a/tests/e2e/cmdopen.pw.e2e.js
+++ b/tests/e2e/cmdopen.pw.e2e.js
@@ -169,9 +169,9 @@ test.describe('TST51 - Command line file opening', () => {
15000,
);
- // Switch to description tab and add description
+ // Switch to description tab and enter edit mode
await clickOn('[data-tid=descriptionTabTID]');
- await clickOn('[data-tid=descriptionTID]');
+ await clickOn('[data-tid=editDescriptionTID]');
const editor = await global.client.waitForSelector(
'[data-tid=descriptionTID] [contenteditable=true]',
{ timeout: 8000 },
diff --git a/tests/e2e/folder.pw.e2e.js b/tests/e2e/folder.pw.e2e.js
index 9b9c31d26..0adf541c0 100644
--- a/tests/e2e/folder.pw.e2e.js
+++ b/tests/e2e/folder.pw.e2e.js
@@ -188,7 +188,11 @@ test.describe('TST01 - Folder management', () => {
await clickOn('[data-tid=confirmCreateNewDirectory]');
await clickOn('[data-tid=MoveTarget' + folderToMove + ']');
await clickOn('[data-tid=confirmMoveFiles]');
+ // For directory moves on a local location the file-upload dialog opens
+ // but reports no progress (0/0) so the "closeAndClear" button is hidden;
+ // fall through to the always-present "minimize" button.
await clickOnIfVisible('[data-tid=uploadCloseAndClearTID]');
+ await clickOnIfVisible('[data-tid=uploadMinimizeDialogTID]');
await clickOn('[data-tid=location_' + defaultLocationName + ']');
await expectElementExist(getGridFileSelector(testFolder), false, 5000);
await global.client.dblclick('[data-tid=fsEntryName_' + folderToMove + ']');
@@ -220,7 +224,10 @@ test.describe('TST01 - Folder management', () => {
await clickOn('[data-tid=MoveTarget' + folderToCopy + ']');
await clickOn('[data-tid=mcfModeCopy]');
await clickOn('[data-tid=confirmCopyFiles]');
+ // Same reasoning as TST0108: dir copies on a local location skip the
+ // "closeAndClear" button, so fall through to "minimize".
await clickOnIfVisible('[data-tid=uploadCloseAndClearTID]');
+ await clickOnIfVisible('[data-tid=uploadMinimizeDialogTID]');
await clickOn('[data-tid=location_' + defaultLocationName + ']');
await expectElementExist(getGridFileSelector('empty_folder'), true, 5000);
await global.client.dblclick(getGridFileSelector(folderToCopy));
diff --git a/tests/e2e/folderprops.pw.e2e.js b/tests/e2e/folderprops.pw.e2e.js
index c801b9042..414ee75ac 100644
--- a/tests/e2e/folderprops.pw.e2e.js
+++ b/tests/e2e/folderprops.pw.e2e.js
@@ -184,8 +184,13 @@ test.describe('TST02 - Folder properties', () => {
// select folder to move
await clickOn('[data-tid=gridPerspectiveCopySelectedFiles]'); //todo moveCopyEntryTID
await clickOn('[data-tid=MoveTarget' + targetFolder + ']');
+ // The dialog persists the last-used mode in Redux; pin it to Move here.
+ await clickOn('[data-tid=mcfModeMove]');
await clickOn('[data-tid=confirmMoveFiles]');
+ // For directory moves on a local location the file-upload dialog shows
+ // no progress (0/0) so only the minimize button is rendered.
await clickOnIfVisible('[data-tid=uploadCloseAndClearTID]');
+ await clickOnIfVisible('[data-tid=uploadMinimizeDialogTID]');
await expectElementExist(getGridFileSelector(newFolder), false, 5000);
await global.client.dblclick('[data-tid=fsEntryName_' + targetFolder + ']');
await expectElementExist(getGridFileSelector(newFolder), true, 5000);
diff --git a/tests/e2e/general.helpers.js b/tests/e2e/general.helpers.js
index a2ce32537..0b69670bc 100644
--- a/tests/e2e/general.helpers.js
+++ b/tests/e2e/general.helpers.js
@@ -942,7 +942,10 @@ export async function waitForNotification(
export async function addDescription(desc) {
await clickOn('[data-tid=descriptionTabTID]');
- await clickOn('[data-tid=descriptionTID]');
+ // The Milkdown editor only exposes a contenteditable host once edit mode
+ // is on. A single click on the description body does NOT toggle edit mode
+ // (only `onDoubleClick` does), so click the dedicated edit button instead.
+ await clickOn('[data-tid=editDescriptionTID]');
const editor = await global.client.waitForSelector(
'[data-tid=descriptionTID] [contenteditable=true]',
);
@@ -951,11 +954,7 @@ export async function addDescription(desc) {
} catch (e) {
await editor.type(desc);
}
- if (await isDisplayed('[data-tid=descriptionChangedTID]', true, 8000)) {
- await clickOn('[data-tid=saveDescriptionTID]');
- } else {
- await clickOn('[data-tid=saveDescriptionTID]');
- }
+ await clickOn('[data-tid=saveDescriptionTID]');
}
export async function createFile(
diff --git a/tests/e2e/perspective-grid.pw.e2e.js b/tests/e2e/perspective-grid.pw.e2e.js
index fce276753..d0b369b84 100644
--- a/tests/e2e/perspective-grid.pw.e2e.js
+++ b/tests/e2e/perspective-grid.pw.e2e.js
@@ -19,7 +19,7 @@ import {
selectRowFiles,
setSettings
} from './general.helpers';
-import { startTestingApp, stopApp } from './hook';
+import { startTestingApp, stopApp, testDataRefresh } from './hook';
import {
createPwLocation,
createS3Location,
@@ -153,7 +153,10 @@ test.describe('TST50 - Perspective Grid', () => {
}
});
- test('TST5008 - Copy file [web,s3,electron]', async () => {
+ test('TST5008 - Copy file [web,s3,electron]', async ({
+ isS3,
+ testDataDir,
+ }) => {
const fileName = 'sample.svg';
await openFile(fileName, 'showPropertiesTID');
// add meta json to file
@@ -183,6 +186,10 @@ test.describe('TST50 - Perspective Grid', () => {
await expectElementExist(getGridFileSelector(fileName), true);
await expectMetaFilesExist(arrayMeta, true);
+ // Reset the source sidecar (and the toggled persist-tags setting via the
+ // mode toggle persisting through Redux) before the next test reuses
+ // sample.svg with a clean state.
+ await testDataRefresh(isS3, testDataDir);
});
test.skip('TST5009 - Copy file on different partition [manual]', async () => {});
@@ -200,6 +207,9 @@ test.describe('TST50 - Perspective Grid', () => {
// open Copy/Move File Dialog
await clickOn('[data-tid=gridPerspectiveCopySelectedFiles]');
await clickOn('[data-tid=MoveTargetempty_folder]');
+ // The dialog persists the last-used mode in Redux, so explicitly switch
+ // back to Move here — a prior test (TST5008) may have left it on Copy.
+ await clickOn('[data-tid=mcfModeMove]');
await clickOn('[data-tid=confirmMoveFiles]');
// Wait for S3 move operation to complete
await global.client.waitForTimeout(1500);