Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

[SourcesTree] Set root directory#4962

Merged
jasonLaster merged 2 commits into
firefox-devtools:masterfrom
AnshulMalik:change-root-sources
Jan 29, 2018
Merged

[SourcesTree] Set root directory#4962
jasonLaster merged 2 commits into
firefox-devtools:masterfrom
AnshulMalik:change-root-sources

Conversation

@AnshulMalik
Copy link
Copy Markdown
Contributor

Associated Issue: #4121

Summary of Changes

  • Change the root of sources tree to custom one

Screenshots/Videos (OPTIONAL)

t

click: () => setProjectDirectoryRoot(item.path)
click: () => {
const curRoot = this.props.projectRoot;
let newRoot = item.path;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I move this calculation in setProjectDirectoryRoot ?

@jasonLaster
Copy link
Copy Markdown
Contributor

Great work! Can't wait to review :)

@AnshulMalik AnshulMalik changed the title [WIP] [SourcesTree] Set root directory [SourcesTree] Set root directory Dec 21, 2017
@jasonLaster
Copy link
Copy Markdown
Contributor

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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, that makes sense

temp.splice(0, 2);
newRoot = `${curRoot}/${temp.join("/")}`;
}
this.props.setProjectDirectoryRoot(newRoot);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you think we can do this in this.props.setProjectDirectoryRoot?

Comment thread src/utils/sources-tree/addToTree.js Outdated

if (projectRoot) {
const rootParts = projectRoot.replace("://", "").split("/");
parts.splice(0, rootParts.length - 2);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this logic looks really similar to the other logic. What's going on here?

Copy link
Copy Markdown
Contributor Author

@AnshulMalik AnshulMalik Jan 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it

@jasonLaster
Copy link
Copy Markdown
Contributor

Waiting to see if this should be cleaned up and maybe another test...

Comment thread src/actions/ui.js Outdated
}

export function setProjectDirectoryRoot(url: Object) {
export function setProjectDirectoryRoot(curRoot: string, newRoot: string) {
Copy link
Copy Markdown
Contributor

@lukaszsobek lukaszsobek Jan 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to change anything if curRoor == newRoot? Maybe perform setProjectDirectoryRoot only after checking that the two roots are different.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it'd be better if we keep the logic inside the function.

Comment thread src/utils/sources-tree/addToTree.js Outdated
}

function isUnderRoot(url, projectRoot) {
if (!projectRoot) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I'd expect isUnderRoot to return true if there is no root.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 = "";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

- components
- TodoTextInput.js
- Header.js
*/
Copy link
Copy Markdown
Contributor

@lukaszsobek lukaszsobek Jan 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it a working version, or does the comment indicate there is something special to note here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments were there to remind the tree structure, but they are not required, i'll remove them

@jasonLaster
Copy link
Copy Markdown
Contributor

Looks good! I'll test soon

@jasonLaster
Copy link
Copy Markdown
Contributor

  • Did a quick rebase
  • I found a couple rough edges
    • it requires 2 times to set the root dir
    • re-selecting the same node should show "Remove Root Directory"
  • I think the redux action should have the curRoot check based on a redux call...
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)
       });
     }
 

@AnshulMalik AnshulMalik requested a review from flodolo as a code owner January 25, 2018 17:25
Comment thread src/actions/ui.js Outdated
export function setProjectDirectoryRoot(newRoot: string) {
return ({ dispatch, getState }: ThunkArgs) => {
const curRoot = getProjectDirectoryRoot(getState());
if (newRoot.length === 0) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, it would be nice to call a separate action clearProjectDirectoryRoot or pass in null

Comment thread src/client/firefox/commands.js Outdated
.then(([{ actualLocation }, bpClient]) => {
actualLocation = createBreakpointLocation(location, actualLocation);
const id = makeLocationId(actualLocation);
const id = makePendingLocationId(actualLocation);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this coming from :)

looks like this PR desperately needs a rebase ⤴️ ⤵️

@AnshulMalik AnshulMalik force-pushed the change-root-sources branch 2 times, most recently from 6912047 to db7a1fc Compare January 28, 2018 10:24
Comment thread src/actions/tests/ui.spec.js Outdated
const { dispatch, getState } = createStore();
const projectRoot = getProjectDirectoryRoot(getState());
dispatch(actions.setProjectDirectoryRoot(projectRoot));
dispatch(actions.setProjectDirectoryRoot(projectRoot, projectRoot));
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not present locally to me, don't know why it's showing here

@jasonLaster
Copy link
Copy Markdown
Contributor

started some jest tests and found some weird issues...

@jasonLaster
Copy link
Copy Markdown
Contributor

fixed!

@jasonLaster jasonLaster merged commit 57035f7 into firefox-devtools:master Jan 29, 2018
@AnshulMalik AnshulMalik deleted the change-root-sources branch January 29, 2018 19:04
jasonLaster pushed a commit that referenced this pull request Jan 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants