Skip to content

Commit d4deb50

Browse files
jasonLasterdarkwing
authored andcommitted
[Tree] Switch to relative sources (firefox-devtools#6455)
1 parent 232017c commit d4deb50

7 files changed

Lines changed: 12 additions & 81 deletions

File tree

src/components/PrimaryPanes/SourcesTree.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
getDebuggeeUrl,
1919
getExpandedState,
2020
getProjectDirectoryRoot,
21-
getSources
21+
getRelativeSources
2222
} from "../../selectors";
2323

2424
// Actions
@@ -119,6 +119,7 @@ class SourcesTree extends Component<Props, State> {
119119
})
120120
);
121121
}
122+
122123
if (nextProps.shownSource && nextProps.shownSource != shownSource) {
123124
const listItems = getDirectories(nextProps.shownSource, sourceTree);
124125

@@ -341,18 +342,11 @@ class SourcesTree extends Component<Props, State> {
341342
renderProjectRootHeader() {
342343
const { projectRoot } = this.props;
343344

344-
const { sourceTree } = this.state;
345-
346345
if (!projectRoot) {
347346
return null;
348347
}
349348

350-
const sourceContents = sourceTree.contents[0];
351-
let rootLabel = projectRoot.split("/").pop();
352-
353-
if (sourceContents && sourceContents.name !== rootLabel) {
354-
rootLabel = sourceContents.contents[0].name;
355-
}
349+
const rootLabel = projectRoot.split("/").pop();
356350

357351
return (
358352
<div key="root" className="sources-clear-root-container">
@@ -460,7 +454,7 @@ const mapStateToProps = state => {
460454
debuggeeUrl: getDebuggeeUrl(state),
461455
expanded: getExpandedState(state),
462456
projectRoot: getProjectDirectoryRoot(state),
463-
sources: getSources(state)
457+
sources: getRelativeSources(state)
464458
};
465459
};
466460

src/components/QuickOpenModal.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,7 @@ function mapStateToProps(state) {
422422

423423
return {
424424
enabled: getQuickOpenEnabled(state),
425-
sources: formatSources(
426-
getRelativeSources(state).toArray(),
427-
getTabs(state).toArray()
428-
),
425+
sources: formatSources(getRelativeSources(state), getTabs(state).toArray()),
429426
selectedSource,
430427
symbols: formatSymbols(getSymbols(state, selectedSource)),
431428
symbolsLoading: isSymbolsLoading(state, selectedSource),

src/selectors/getRelativeSources.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export const getRelativeSources = createSelector(
3434
getProjectDirectoryRoot,
3535
(sources, root) => {
3636
return sources
37-
.valueSeq()
3837
.filter(source => source.url && source.url.includes(root))
3938
.map(source => formatSource(source, root));
4039
}

src/utils/quick-open.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type { QuickOpenType } from "../reducers/quick-open";
1313
import type { TabList } from "../reducers/sources";
1414
import type { RelativeSource } from "../types";
1515
import type { SymbolDeclaration } from "../workers/parser";
16+
import type { Map } from "immutable";
1617

1718
export const MODIFIERS = {
1819
"@": "functions",
@@ -125,10 +126,12 @@ export function formatShortcutResults(): Array<QuickOpenResult> {
125126
}
126127

127128
export function formatSources(
128-
sources: RelativeSource[],
129+
sources: Map<RelativeSource>,
129130
tabs: TabList
130131
): Array<QuickOpenResult> {
131132
return sources
133+
.valueSeq()
134+
.toArray()
132135
.filter(source => !isPretty(source))
133136
.filter(({ relativeUrl }) => !!relativeUrl)
134137
.map(source => formatSourcesForList(source, tabs));

src/utils/sources-tree/addToTree.js

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,6 @@ import type { ParsedURL } from "./getURL";
2222
import type { Node } from "./types";
2323
import type { SourceRecord } from "../../types";
2424

25-
function isUnderRoot(url, projectRoot) {
26-
if (!projectRoot) {
27-
return true;
28-
}
29-
30-
return `${url.group}${url.path}`.startsWith(projectRoot);
31-
}
32-
33-
function removeProjectRoot(parts, projectRoot) {
34-
const rootParts = projectRoot.replace("://", "").split("/");
35-
return parts.splice(0, rootParts.length - 2);
36-
}
37-
3825
function createNodeInTree(
3926
part: string,
4027
path: string,
@@ -95,21 +82,12 @@ function findOrCreateNode(
9582
* walk the source tree to the final node for a given url,
9683
* adding new nodes along the way
9784
*/
98-
function traverseTree(
99-
url: Object,
100-
tree: Node,
101-
debuggeeHost: ?string,
102-
projectRoot: string
103-
) {
85+
function traverseTree(url: Object, tree: Node, debuggeeHost: ?string) {
10486
url.path = decodeURIComponent(url.path);
10587

10688
const parts = url.path.split("/").filter(p => p !== "");
10789
parts.unshift(url.group);
10890

109-
if (projectRoot) {
110-
removeProjectRoot(parts, projectRoot);
111-
}
112-
11391
let path = "";
11492
return parts.reduce((subTree, part, index) => {
11593
path = path ? `${path}/${part}` : part;
@@ -172,10 +150,10 @@ export function addToTree(
172150
const url = getURL(source.get ? source.get("url") : source.url, debuggeeUrl);
173151
const debuggeeHost = getDomain(debuggeeUrl);
174152

175-
if (isInvalidUrl(url, source) || !isUnderRoot(url, projectRoot)) {
153+
if (isInvalidUrl(url, source)) {
176154
return;
177155
}
178156

179-
const finalNode = traverseTree(url, tree, debuggeeHost, projectRoot);
157+
const finalNode = traverseTree(url, tree, debuggeeHost);
180158
finalNode.contents = addSourceToNode(finalNode, url, source);
181159
}

src/utils/sources-tree/tests/__snapshots__/addToTree.spec.js.snap

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,3 @@ exports[`sources-tree addToTree uses debuggeeUrl as default 1`] = `
8080
- TodoItem.js path=voz37vlg5.codesandbox.io/static/js/components/TodoItem.js source_id=undefined
8181
"
8282
`;
83-
84-
exports[`sources-tree addToTree uses projectRoot to filter the list 1`] = `
85-
" - root path=
86-
"
87-
`;

src/utils/sources-tree/tests/addToTree.spec.js

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -251,40 +251,5 @@ describe("sources-tree", () => {
251251
sources.forEach(source => addToTree(tree, source, domain));
252252
expect(formatTree(tree)).toMatchSnapshot();
253253
});
254-
255-
it("uses projectRoot to filter the list", () => {
256-
const testData = [
257-
{
258-
url: "http://example.com/components/TodoTextInput.js"
259-
},
260-
{
261-
url: "http://example.com/components/Header.js"
262-
},
263-
{
264-
url: "http://example.com/reducers/index.js"
265-
},
266-
{
267-
url: "http://example.com/components/TodoItem.js"
268-
},
269-
{
270-
url: "resource://gre/modules/ExtensionContent.jsm"
271-
},
272-
{
273-
url:
274-
"https://voz37vlg5.codesandbox.io/static/js/components/TodoItem.js"
275-
},
276-
{
277-
url: "http://example.com/index.js"
278-
}
279-
];
280-
281-
const domain = "http://example.com/";
282-
const sources = createSourcesList(testData);
283-
const root = "/example.com/components";
284-
285-
const tree = createNode("root", "", []);
286-
sources.forEach(source => addToTree(tree, source, domain, root));
287-
expect(formatTree(tree)).toMatchSnapshot();
288-
});
289254
});
290255
});

0 commit comments

Comments
 (0)