diff --git a/devtools/client/debugger/new/src/components/ProjectSearch.js b/devtools/client/debugger/new/src/components/ProjectSearch.js index 29a9443440c2..7a8548614853 100644 --- a/devtools/client/debugger/new/src/components/ProjectSearch.js +++ b/devtools/client/debugger/new/src/components/ProjectSearch.js @@ -157,20 +157,8 @@ export class ProjectSearch extends Component { ); }; - getResults = (): Result[] => { - const { results } = this.props; - return results - .toJS() - .map(result => ({ - type: "RESULT", - ...result, - matches: result.matches.map(m => ({ type: "MATCH", ...m })) - })) - .filter(result => result.filepath && result.matches.length > 0); - }; - getResultCount = () => - this.getResults().reduce((count, file) => count + file.matches.length, 0); + this.props.results.reduce((count, file) => count + file.matches.length, 0); onKeyDown = (e: SyntheticKeyboardEvent) => { if (e.key === "Escape") { @@ -271,8 +259,7 @@ export class ProjectSearch extends Component { }; renderResults = () => { - const results = this.getResults(); - const { status } = this.props; + const { status, results } = this.props; if (!this.props.query) { return; } diff --git a/devtools/client/debugger/new/src/reducers/project-text-search.js b/devtools/client/debugger/new/src/reducers/project-text-search.js index de797ce098b9..babbc4341510 100644 --- a/devtools/client/debugger/new/src/reducers/project-text-search.js +++ b/devtools/client/debugger/new/src/reducers/project-text-search.js @@ -10,17 +10,12 @@ * @module reducers/project-text-search */ -import * as I from "immutable"; -import makeRecord from "../utils/makeRecord"; - import type { Action } from "../actions/types"; -import type { Record } from "../utils/makeRecord"; -import type { List } from "immutable"; export type Search = { - id: string, - filepath: string, - matches: I.List + +sourceId: string, + +filepath: string, + +matches: any[] }; export type StatusType = "INITIAL" | "FETCHING" | "DONE" | "ERROR"; export const statusType = { @@ -30,77 +25,75 @@ export const statusType = { error: "ERROR" }; -export type ResultRecord = Record; -export type ResultList = List; +export type ResultList = Search[]; export type ProjectTextSearchState = { - query: string, - results: ResultList, - status: string + +query: string, + +results: ResultList, + +status: string }; -export function initialProjectTextSearchState(): Record< - ProjectTextSearchState -> { - return makeRecord( - ({ - query: "", - results: I.List(), - status: statusType.initial - }: ProjectTextSearchState) - )(); +export function initialProjectTextSearchState(): ProjectTextSearchState { + return { + query: "", + results: [], + status: statusType.initial + }; } function update( - state: Record = initialProjectTextSearchState(), + state: ProjectTextSearchState = initialProjectTextSearchState(), action: Action -): Record { +): ProjectTextSearchState { switch (action.type) { case "ADD_QUERY": - const actionCopy = action; - return state.update("query", value => actionCopy.query); + return { ...state, query: action.query }; case "CLEAR_QUERY": - return state.merge({ + return { + ...state, query: "", status: statusType.initial - }); + }; case "ADD_SEARCH_RESULT": - const results = state.get("results"); - return state.merge({ results: results.push(action.result) }); + const results = state.results; + if (action.result.matches.length === 0) { + return state; + } + + const result = { + type: "RESULT", + ...action.result, + matches: action.result.matches.map(m => ({ type: "MATCH", ...m })) + }; + return { ...state, results: [...results, result] }; case "UPDATE_STATUS": - return state.merge({ status: action.status }); + return { ...state, status: action.status }; case "CLEAR_SEARCH_RESULTS": - return state.merge({ - results: state.get("results").clear() - }); + return { ...state, results: [] }; case "CLEAR_SEARCH": case "CLOSE_PROJECT_SEARCH": case "NAVIGATE": - return state.merge({ - query: "", - results: state.get("results").clear(), - status: statusType.initial - }); + return initialProjectTextSearchState(); } return state; } -type OuterState = { projectTextSearch: Record }; +type OuterState = { projectTextSearch: ProjectTextSearchState }; export function getTextSearchResults(state: OuterState) { - return state.projectTextSearch.get("results"); + return state.projectTextSearch.results; } export function getTextSearchStatus(state: OuterState) { - return state.projectTextSearch.get("status"); + return state.projectTextSearch.status; } export function getTextSearchQuery(state: OuterState) { - return state.projectTextSearch.get("query"); + return state.projectTextSearch.query; } export default update; diff --git a/devtools/client/debugger/new/test/mochitest/browser_dbg-search-project.js b/devtools/client/debugger/new/test/mochitest/browser_dbg-search-project.js index 2a9e48092219..15d28460f097 100644 --- a/devtools/client/debugger/new/test/mochitest/browser_dbg-search-project.js +++ b/devtools/client/debugger/new/test/mochitest/browser_dbg-search-project.js @@ -26,9 +26,7 @@ async function selectResult(dbg) { function getResultsCount(dbg) { const matches = dbg.selectors .getTextSearchResults(dbg.getState()) - .valueSeq() - .map(file => file.matches) - .toJS(); + .map(file => file.matches); return [...matches].length; }