mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 09:36:27 +00:00
explorer: active file after duplicating
When duplicating a file users expect the file to be opened as in other applications. Fixes: https://github.com/pybricks/support/issues/1084
This commit is contained in:
committed by
David Lechner
parent
9263dc0cfd
commit
fc89c7b329
@@ -777,7 +777,9 @@ describe('handleExplorerDuplicateFile', () => {
|
||||
});
|
||||
|
||||
it('should dispatch action on fileStorageDuplicateFile success', async () => {
|
||||
saga.put(fileStorageDidCopyFile('old.file'));
|
||||
saga.put(fileStorageDidCopyFile('old.file', uuid(1)));
|
||||
|
||||
await expect(saga.take()).resolves.toEqual(editorActivateFile(uuid(1)));
|
||||
|
||||
await expect(saga.take()).resolves.toEqual(
|
||||
explorerDidDuplicateFile('old.file'),
|
||||
|
||||
@@ -439,7 +439,7 @@ function* handleExplorerDuplicateFile(
|
||||
|
||||
yield* put(fileStorageCopyFile(action.fileName, didAccept.newName));
|
||||
|
||||
const { didFailToCopy } = yield* race({
|
||||
const { didCopy, didFailToCopy } = yield* race({
|
||||
didCopy: take(
|
||||
fileStorageDidCopyFile.when((a) => a.path === action.fileName),
|
||||
),
|
||||
@@ -452,6 +452,10 @@ function* handleExplorerDuplicateFile(
|
||||
throw didFailToCopy.error;
|
||||
}
|
||||
|
||||
defined(didCopy);
|
||||
|
||||
yield* put(editorActivateFile(didCopy.newUuid));
|
||||
|
||||
yield* put(explorerDidDuplicateFile(action.fileName));
|
||||
} catch (err) {
|
||||
yield* put(explorerDidFailToDuplicateFile(action.fileName, ensureError(err)));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2022 The Pybricks Authors
|
||||
// Copyright (c) 2022-2023 The Pybricks Authors
|
||||
|
||||
import type * as monaco from 'monaco-editor';
|
||||
import { createAction } from '../actions';
|
||||
@@ -236,11 +236,13 @@ export const fileStorageCopyFile = createAction((path: string, newPath: string)
|
||||
|
||||
/**
|
||||
* Indicates that {@link fileStorageCopyFile} succeeded.
|
||||
* @param path: The file path.
|
||||
* @param path: The original file path.
|
||||
* @param newUuid: The UUID of the new copy.
|
||||
*/
|
||||
export const fileStorageDidCopyFile = createAction((path: string) => ({
|
||||
export const fileStorageDidCopyFile = createAction((path: string, newUuid: UUID) => ({
|
||||
type: 'fileStorage.action.didCopyFile',
|
||||
path,
|
||||
newUuid,
|
||||
}));
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2022 The Pybricks Authors
|
||||
// Copyright (c) 2022-2023 The Pybricks Authors
|
||||
|
||||
import 'fake-indexeddb/auto';
|
||||
import Dexie from 'dexie';
|
||||
@@ -590,7 +590,9 @@ describe('copyFile', () => {
|
||||
it('should copy file', async () => {
|
||||
saga.put(fileStorageCopyFile('test.file', 'new.file'));
|
||||
|
||||
await expect(saga.take()).resolves.toEqual(fileStorageDidCopyFile('test.file'));
|
||||
await expect(saga.take()).resolves.toEqual(
|
||||
fileStorageDidCopyFile('test.file', uuid(1)),
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2022 The Pybricks Authors
|
||||
// Copyright (c) 2022-2023 The Pybricks Authors
|
||||
|
||||
import Dexie from 'dexie';
|
||||
import {
|
||||
@@ -375,6 +375,8 @@ function* handleCopyFile(
|
||||
action: ReturnType<typeof fileStorageCopyFile>,
|
||||
): Generator {
|
||||
try {
|
||||
let uuid: UUID | undefined = undefined;
|
||||
|
||||
yield* call(() =>
|
||||
navigator.locks.request(
|
||||
lockNameForPath(action.newPath),
|
||||
@@ -403,7 +405,7 @@ function* handleCopyFile(
|
||||
throw new Error(`file '${action.newPath}' already exists`);
|
||||
}
|
||||
|
||||
await db.metadata.add((<Omit<FileMetadata, 'uuid'>>{
|
||||
uuid = await db.metadata.add((<Omit<FileMetadata, 'uuid'>>{
|
||||
...metadata,
|
||||
uuid: undefined,
|
||||
path: action.newPath,
|
||||
@@ -424,7 +426,9 @@ function* handleCopyFile(
|
||||
),
|
||||
);
|
||||
|
||||
yield* put(fileStorageDidCopyFile(action.path));
|
||||
defined(uuid);
|
||||
|
||||
yield* put(fileStorageDidCopyFile(action.path, uuid));
|
||||
} catch (err) {
|
||||
yield* put(fileStorageDidFailToCopyFile(action.path, ensureError(err)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user