Skip to content
This repository was archived by the owner on Apr 1, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions browser/src/Services/Explorer/ExplorerStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,11 @@ const Actions = {
children: sortedFilesAndFolders,
}
},

selectFile: (filePath: string): ISelectFileAction => ({
type: "SELECT_FILE",
filePath,
}),
}

// Yank, Paste Delete register =============================
Expand Down Expand Up @@ -1004,11 +1009,10 @@ export const createNodeEpic: ExplorerEpic = (action$, store, { fileSystem }) =>
create: { nodeType },
},
} = store.getState()
const shouldExpand = Actions.expandDirectory(path.dirname(name))
const createFileOrFolder =
nodeType === "file" ? fileSystem.writeFile(name) : fileSystem.mkdir(name)
return fromPromise(createFileOrFolder)
.flatMap(() => [Actions.createNode({ nodeType, name }), shouldExpand, Actions.refresh])
.flatMap(() => [Actions.createNode({ nodeType, name }), Actions.selectFile(name)])
.catch(error => [Actions.createNodeFail(error.message)])
})

Expand Down
22 changes: 14 additions & 8 deletions browser/test/Services/Explorer/ExplorerStoreTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ describe("ExplorerStore", () => {
.subscribe(actualAction => assert.deepEqual(actualAction, expected))
})

it("Should return a create node success action if a creation is committed", () => {
it("Should return a create node success action if a creation is committed", async () => {
const action$ = ActionsObservable.of({
type: "CREATE_NODE_COMMIT",
name: "/test/dir/file.txt",
Expand All @@ -604,16 +604,21 @@ describe("ExplorerStore", () => {

const expected = [
{ type: "CREATE_NODE_SUCCESS", nodeType: "file", name: "/test/dir/file.txt" },
{ type: "EXPAND_DIRECTORY", directoryPath: "/test/dir" },
{ type: "REFRESH" },
{ type: "SELECT_FILE", filePath: "/test/dir/file.txt" },
]

ExplorerState.createNodeEpic(action$, createState, { fileSystem: fs, notifications })
return ExplorerState.createNodeEpic(action$, createState, {
fileSystem: fs,
notifications,
})
.toArray()
.subscribe(actualActions => assert.deepEqual(actualActions, expected))
.toPromise()
.then(actualActions => {
assert.deepEqual(actualActions, expected)
})
})

it("Should return an error action if a creation fails", () => {
it("Should return an error action if a creation fails", async () => {
const action$ = ActionsObservable.of({
type: "CREATE_NODE_COMMIT",
name: "/test/dir/file.txt",
Expand All @@ -636,7 +641,7 @@ describe("ExplorerStore", () => {

const expected = [{ type: "CREATE_NODE_FAIL", reason: "Duplicate" }]

ExplorerState.createNodeEpic(action$, createState, {
return ExplorerState.createNodeEpic(action$, createState, {
fileSystem: {
...fs,
writeFile: async folderpath => {
Expand All @@ -646,7 +651,8 @@ describe("ExplorerStore", () => {
notifications,
})
.toArray()
.subscribe(actualActions => {
.toPromise()
.then(actualActions => {
assert.deepEqual(actualActions, expected)
})
})
Expand Down