[SourcesTree] Set root directory#4962
Conversation
| click: () => setProjectDirectoryRoot(item.path) | ||
| click: () => { | ||
| const curRoot = this.props.projectRoot; | ||
| let newRoot = item.path; |
There was a problem hiding this comment.
Should I move this calculation in setProjectDirectoryRoot ?
|
Great work! Can't wait to review :) |
|
dont worry about the travis test. that is a known bug |
| click: () => setProjectDirectoryRoot(item.path) | ||
| click: () => { | ||
| const curRoot = this.props.projectRoot; | ||
| let newRoot = item.path; |
| temp.splice(0, 2); | ||
| newRoot = `${curRoot}/${temp.join("/")}`; | ||
| } | ||
| this.props.setProjectDirectoryRoot(newRoot); |
There was a problem hiding this comment.
do you think we can do this in this.props.setProjectDirectoryRoot?
|
|
||
| if (projectRoot) { | ||
| const rootParts = projectRoot.replace("://", "").split("/"); | ||
| parts.splice(0, rootParts.length - 2); |
There was a problem hiding this comment.
this logic looks really similar to the other logic. What's going on here?
There was a problem hiding this comment.
If the project root is set, let's say /example.com/components, then it's path is /components
so we just keep the last part (I am thinking of making it easy to grasp, maybe use url library)
Now we start the tree path with /components.
|
Waiting to see if this should be cleaned up and maybe another test... |
b5502ea to
2d5f6a6
Compare
| } | ||
|
|
||
| export function setProjectDirectoryRoot(url: Object) { | ||
| export function setProjectDirectoryRoot(curRoot: string, newRoot: string) { |
There was a problem hiding this comment.
Do we need to change anything if curRoor == newRoot? Maybe perform setProjectDirectoryRoot only after checking that the two roots are different.
There was a problem hiding this comment.
I thought it'd be better if we keep the logic inside the function.
| } | ||
|
|
||
| function isUnderRoot(url, projectRoot) { | ||
| if (!projectRoot) { |
There was a problem hiding this comment.
Not sure I'd expect isUnderRoot to return true if there is no root.
There was a problem hiding this comment.
It's a hack when the project root is not set :P
| disabled: false, | ||
| click: () => setProjectDirectoryRoot(item.path) | ||
| click: () => | ||
| this.props.setProjectDirectoryRoot(this.props.projectRoot, item.path) |
There was a problem hiding this comment.
maybe we spread this.props before putting it into the clickhandler ... seems a bit hard to read as it is now.
| const domain = "http://example.com/"; | ||
| const sources = createSourcesList(testData); | ||
| const root = "/example.com/components"; | ||
| // const root = ""; |
| - components | ||
| - TodoTextInput.js | ||
| - Header.js | ||
| */ |
There was a problem hiding this comment.
is it a working version, or does the comment indicate there is something special to note here?
There was a problem hiding this comment.
Comments were there to remind the tree structure, but they are not required, i'll remove them
05ac108 to
c3ca3bf
Compare
|
Looks good! I'll test soon |
c3ca3bf to
3e00b93
Compare
diff --git a/src/actions/ui.js b/src/actions/ui.js
index 7e823d7..c2f03a8 100644
--- a/src/actions/ui.js
+++ b/src/actions/ui.js
@@ -138,9 +138,19 @@ export function closeConditionalPanel() {
}
export function setProjectDirectoryRoot(url: Object) {
- return {
- type: "SET_PROJECT_DIRECTORY_ROOT",
- url
+ return ({ dispatch, getState }: ThunkArgs) => {
+ const curRoot = getProjectRoot(getState());
+
+ let newRoot = item.path;
+ if (curRoot) {
+ const temp = newRoot.replace("://", "").split("/");
+ temp.splice(0, 2);
+ newRoot = `${curRoot}/${temp.join("/")}`;
+ }
+ dispatch({
+ type: "SET_PROJECT_DIRECTORY_ROOT",
+ url
+ });
};
}
diff --git a/src/components/PrimaryPanes/SourcesTree.js b/src/components/PrimaryPanes/SourcesTree.js
index c45398f..000e5cb 100644
--- a/src/components/PrimaryPanes/SourcesTree.js
+++ b/src/components/PrimaryPanes/SourcesTree.js
@@ -246,22 +246,13 @@ class SourcesTree extends Component<Props, State> {
menuOptions.push(copySourceUri2);
}
- if (isDirectory(item) && features.root) {
+ if (isDirectory(item) && isCurrentRoot(item.path, props.projectRoot)) {
menuOptions.push({
id: "node-set-directory-root",
label: setDirectoryRootLabel,
accesskey: setDirectoryRootKey,
disabled: false,
- click: () => {
- const curRoot = this.props.projectRoot;
- let newRoot = item.path;
- if (curRoot) {
- const temp = newRoot.replace("://", "").split("/");
- temp.splice(0, 2);
- newRoot = `${curRoot}/${temp.join("/")}`;
- }
- this.props.setProjectDirectoryRoot(newRoot);
- }
+ click: () => this.props.setProjectDirectoryRoot(item.path)
});
}
|
| export function setProjectDirectoryRoot(newRoot: string) { | ||
| return ({ dispatch, getState }: ThunkArgs) => { | ||
| const curRoot = getProjectDirectoryRoot(getState()); | ||
| if (newRoot.length === 0) { |
There was a problem hiding this comment.
hmm, it would be nice to call a separate action clearProjectDirectoryRoot or pass in null
| .then(([{ actualLocation }, bpClient]) => { | ||
| actualLocation = createBreakpointLocation(location, actualLocation); | ||
| const id = makeLocationId(actualLocation); | ||
| const id = makePendingLocationId(actualLocation); |
There was a problem hiding this comment.
where is this coming from :)
looks like this PR desperately needs a rebase
0e1c3ba to
70a25c1
Compare
e12e817 to
6ac1baf
Compare
6912047 to
db7a1fc
Compare
| const { dispatch, getState } = createStore(); | ||
| const projectRoot = getProjectDirectoryRoot(getState()); | ||
| dispatch(actions.setProjectDirectoryRoot(projectRoot)); | ||
| dispatch(actions.setProjectDirectoryRoot(projectRoot, projectRoot)); |
There was a problem hiding this comment.
This change is not present locally to me, don't know why it's showing here
db7a1fc to
cd6693f
Compare
|
started some jest tests and found some weird issues... |
d9504f2 to
c4636f7
Compare
|
fixed! |
Associated Issue: #4121
Summary of Changes
Screenshots/Videos (OPTIONAL)