Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Commit

Permalink
Jump to files/directories created in the Explorer (#2468)
Browse files Browse the repository at this point in the history
* Add a `SELECT_FILE` action as the last step in `CREATE_NODE_COMMIT` so
that files created in the explorer are scrolled and highlighted.
* `SELECT_FILE` has the same effect as `EXPAND_DIRECTORY` + `REFRESH`,
so no need to include those as well.
* Updated unit tests.
  • Loading branch information
feltech authored and akinsho committed Jul 27, 2018
1 parent b6bdb4b commit b2ef17f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
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

0 comments on commit b2ef17f

Please sign in to comment.