From dcc2d3fb2e437ea49cacd482249b6548125aa6b5 Mon Sep 17 00:00:00 2001 From: Alexis Deschamps Date: Sat, 20 Jan 2018 15:33:02 -0500 Subject: [PATCH 1/2] [Project Search] Removed sources that have a minified version --- src/actions/project-text-search.js | 9 +++++++-- src/reducers/sources.js | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/actions/project-text-search.js b/src/actions/project-text-search.js index 7e406a3ee9..0d07ec7112 100644 --- a/src/actions/project-text-search.js +++ b/src/actions/project-text-search.js @@ -10,7 +10,7 @@ */ import { findSourceMatches } from "../workers/search"; -import { getSources, getSource } from "../selectors"; +import { getSources, getSource, hasPrettySource } from "../selectors"; import { isThirdParty, isLoaded } from "../utils/source"; import { loadAllSources } from "./sources"; import { statusType } from "../reducers/project-text-search"; @@ -52,7 +52,12 @@ export function searchSources(query: string) { const sources = getSources(getState()); const validSources = sources .valueSeq() - .filter(source => isLoaded(source) && !isThirdParty(source)); + .filter( + source => + isLoaded(source) && + !hasPrettySource(getState(), source.get("id")) && + !isThirdParty(source) + ); for (const source of validSources) { await dispatch(searchSource(source.get("id"), query)); } diff --git a/src/reducers/sources.js b/src/reducers/sources.js index 7829da6af6..cc741f3ef8 100644 --- a/src/reducers/sources.js +++ b/src/reducers/sources.js @@ -315,6 +315,10 @@ export function getPrettySource(state: OuterState, id: string) { return getSourceByURL(state, getPrettySourceURL(source.get("url"))); } +export function hasPrettySource(state: OuterState, id: string) { + return !!getPrettySource(state, id); +} + function getSourceByUrlInSources(sources: SourcesMap, url: string) { if (!url) { return null; From ee60b9ff35e2d89dff82ecb075ca0054d7cea4e6 Mon Sep 17 00:00:00 2001 From: Alexis Deschamps Date: Sun, 21 Jan 2018 09:18:37 -0500 Subject: [PATCH 2/2] Added test --- .../project-text-search.spec.js.snap | 47 +++++++++++++++++++ src/actions/tests/project-text-search.spec.js | 21 +++++++++ 2 files changed, 68 insertions(+) diff --git a/src/actions/tests/__snapshots__/project-text-search.spec.js.snap b/src/actions/tests/__snapshots__/project-text-search.spec.js.snap index 581d313d0c..d6391ca878 100644 --- a/src/actions/tests/__snapshots__/project-text-search.spec.js.snap +++ b/src/actions/tests/__snapshots__/project-text-search.spec.js.snap @@ -140,6 +140,53 @@ Immutable.List [ ] `; +exports[`project text search should ignore sources with minified versions 1`] = ` +Immutable.List [ + Object { + "filepath": "http://localhost:8000/examples/bar", + "matches": Array [ + Object { + "column": 9, + "line": 1, + "match": "bla", + "sourceId": "bar", + "text": "function bla(x, y) {", + "value": "function bla(x, y) {", + }, + ], + "sourceId": "bar", + }, + Object { + "filepath": "http://localhost:8000/examples/bar:formatted", + "matches": Array [ + Object { + "column": 9, + "line": 1, + "match": "bla", + "sourceId": "bar:formatted", + "text": "function bla(x, y) {", + "value": "function bla(x, y) {", + }, + ], + "sourceId": "bar:formatted", + }, + Object { + "filepath": "http://localhost:8000/examples/bar:formatted", + "matches": Array [ + Object { + "column": 9, + "line": 1, + "match": "bla", + "sourceId": "bar:formatted", + "text": "function bla(x, y) {", + "value": "function bla(x, y) {", + }, + ], + "sourceId": "bar:formatted", + }, +] +`; + exports[`project text search should search a specific source 1`] = ` Immutable.List [ Object { diff --git a/src/actions/tests/project-text-search.spec.js b/src/actions/tests/project-text-search.spec.js index 3d742b731e..ff1678b2ce 100644 --- a/src/actions/tests/project-text-search.spec.js +++ b/src/actions/tests/project-text-search.spec.js @@ -36,6 +36,12 @@ const threadClient = { contentType: "text/javascript" }); break; + case "bar:formatted": + resolve({ + source: "function bla(x, y) {\n const bar = 4; return 2;\n}", + contentType: "text/javascript" + }); + break; } reject(`unknown source: ${sourceId}`); @@ -79,6 +85,21 @@ describe("project text search", () => { expect(results).toMatchSnapshot(); }); + it("should ignore sources with minified versions", async () => { + const { dispatch, getState } = createStore(threadClient); + const mockQuery = "bla"; + const source1 = makeSource("bar"); + const source2 = makeSource("bar:formatted"); + + await dispatch(actions.newSource(source1)); + await dispatch(actions.newSource(source2)); + + await dispatch(actions.searchSources(mockQuery)); + + const results = getTextSearchResults(getState()); + expect(results).toMatchSnapshot(); + }); + it("should search a specific source", async () => { const { dispatch, getState } = createStore(threadClient);