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

[WIP] Search redux#3370

Merged
jasonLaster merged 11 commits into
firefox-devtools:nextfrom
bomsy:search-redux
Jul 24, 2017
Merged

[WIP] Search redux#3370
jasonLaster merged 11 commits into
firefox-devtools:nextfrom
bomsy:search-redux

Conversation

@bomsy
Copy link
Copy Markdown
Contributor

@bomsy bomsy commented Jul 19, 2017

Associated Issue: #3342

Summary of Changes

  • Move search functionality to redux
  • Keeping search state
  • Added opening source file on clicking the match

Todo

  • Fix issue with multiple children having the same key

Comment thread src/utils/search/project-search.js Outdated

while ((result = query.exec(_text))) {
indices.push({
id: source.id,
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 enables us know the source attached to the match

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.

perhaps sourceId

Copy link
Copy Markdown
Contributor

@jasonLaster jasonLaster left a comment

Choose a reason for hiding this comment

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

Wow - looking great!

Comment thread src/actions/index.js Outdated
import * as ui from "./ui";
import * as ast from "./ast";
import * as coverage from "./coverage";
import * as search from "./search";
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.

perhaps project-text-search

Comment thread src/actions/search.js Outdated
.filter(source => source.has("text"))
.toJS();

validSources.forEach(source => {
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.

perhaps:

for (const source of validSources) {
  const matches = await searchSource(source, query);
  dispatch({ ya da ya da });
}

This strategy will let us defer the work to the worker. each search will be a new worker call and will wait for the response to come back...


componentDidMount() {
if (this.state.inputValue == "") {
this.props.loadAllSources();
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.

another option would be to move this to the searchSources action...

the advantage is that we always do it before we search. often it will be very fast... and then we know we have everything to search

}

selectMatchItem(matchItem) {
this.props.selectSource(matchItem.id);
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.

👍

className: classnames("result", { focused }),
key: `${match.line}/${match.column}`,
onClick: () => console.log(`clicked ${match}`)
key: `${match.line}-${match.column}`,
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.

we might need to have the source id here too

Comment thread src/reducers/search.js Outdated
case "ADD_QUERY":
return state.update("query", value => action.query);

case "REMOVE_QUERY":
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.

minor thing, but clear is being used in other places clear_query

Comment thread src/reducers/search.js Outdated

case "ADD_SEARCH_RESULT":
return state.updateIn(
["results", action.result.id],
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.

perhaps action.result.sourceId

Comment thread src/reducers/search.js Outdated
type OuterState = { search: Record<SearchState> };

export function getSearchResults(state: OuterState) {
return state.search.get("results").valueSeq().toJS();
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.

lets expose I state.search.get("results")

Copy link
Copy Markdown
Contributor Author

@bomsy bomsy Jul 19, 2017

Choose a reason for hiding this comment

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

@jlast Is there any particular reason behind this? Just for my understanding.

Copy link
Copy Markdown
Contributor

@jasonLaster jasonLaster Jul 20, 2017

Choose a reason for hiding this comment

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

Immutable lets us compare items and see if they change list.get("id") === list.get("id")

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.

Ahh cool!

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can you please tag jasonlaster instead of me?

@codecov
Copy link
Copy Markdown

codecov Bot commented Jul 20, 2017

Codecov Report

Merging #3370 into master will decrease coverage by 0.33%.
The diff coverage is 24.24%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3370      +/-   ##
==========================================
- Coverage   50.76%   50.43%   -0.34%     
==========================================
  Files         105      107       +2     
  Lines        4353     4386      +33     
  Branches      896      900       +4     
==========================================
+ Hits         2210     2212       +2     
- Misses       2143     2174      +31
Impacted Files Coverage Δ
src/selectors.js 100% <ø> (ø) ⬆️
src/utils/search/project-search.js 94.73% <ø> (ø) ⬆️
src/actions/search.js 0% <0%> (ø)
src/reducers/search.js 42.1% <42.1%> (ø)
src/actions/ui.js 76.66% <0%> (-6.67%) ⬇️
src/reducers/ui.js 79.03% <0%> (-6.46%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0533fbd...b0cdd86. Read the comment docs.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jul 20, 2017

Codecov Report

Merging #3370 into next will increase coverage by 0.49%.
The diff coverage is 17.14%.

Impacted file tree graph

@@            Coverage Diff             @@
##             next    #3370      +/-   ##
==========================================
+ Coverage   50.03%   50.52%   +0.49%     
==========================================
  Files         107      107              
  Lines        4457     4388      -69     
  Branches      920      900      -20     
==========================================
- Hits         2230     2217      -13     
+ Misses       2227     2171      -56
Impacted Files Coverage Δ
src/utils/search/project-search.js 94.73% <ø> (ø) ⬆️
src/utils/makeRecord.js 100% <ø> (ø) ⬆️
src/selectors.js 100% <ø> (ø) ⬆️
src/actions/project-text-search.js 0% <0%> (ø)
src/reducers/project-text-search.js 31.57% <31.57%> (ø)
src/utils/breakpoint/index.js 70.9% <0%> (-7.56%) ⬇️
src/utils/source.js 44.64% <0%> (-6.18%) ⬇️
src/actions/ast.js 74.41% <0%> (-2.37%) ⬇️
src/client/firefox.js 87.5% <0%> (-0.74%) ⬇️
src/actions/breakpoints.js 83.11% <0%> (-0.64%) ⬇️
... and 27 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 996d8c8...db97890. Read the comment docs.

Copy link
Copy Markdown
Contributor

@jasonLaster jasonLaster left a comment

Choose a reason for hiding this comment

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

couple small comments, then it's ready to go in!


export function searchSources(query) {
return async ({ dispatch, getState }: ThunkArgs) => {
dispatch(await loadAllSources());
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.

perhaps we want to do something to disallow new searches while one is going on?

I do this with preview, by having an updating state: https://github.com/devtools-html/debugger.html/blob/master/src/reducers/ast.js#L21-L22

Comment thread src/utils/search/project-search.js Outdated

while ((result = query.exec(_text))) {
indices.push({
id: source.id,
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.

perhaps sourceId

Comment thread src/reducers/types.js Outdated
import type { PauseState } from "./pause";
import type { SourcesState } from "./source";
import type { BreakpointsState } from "./breakpoints";
import type { SearchState } from "./search";
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 - does this need to be updated?

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.

opppsieee!! :)

@jasonLaster jasonLaster changed the base branch from master to next July 20, 2017 20:39
Comment thread src/reducers/index.js Outdated
ast,
coverage
coverage,
search
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.

should be projectTextSearch

Comment thread src/selectors.js
ui,
ast,
coverage,
search,
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.

should be projectTextSearch

@jasonLaster
Copy link
Copy Markdown
Contributor

Happy to land this and iterate. I'll leave some UX feedback on the parent issue

Comment thread src/actions/types.js
type: "CLEAR_SELECTION"
};

export type ProjectTextSearchAction = {
Copy link
Copy Markdown
Contributor Author

@bomsy bomsy Jul 23, 2017

Choose a reason for hiding this comment

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

it was a nightmare resolving flow issues

@bomsy
Copy link
Copy Markdown
Contributor Author

bomsy commented Jul 24, 2017

To add tests

Comment thread src/utils/makeRecord.js
deleteIn(keyPath: Array<any>, ...iterables: Array<any>): Record<T>,
update<A>(key: $Keys<T>, value: A): Record<T>,
updateIn(keyPath: Array<any>, ...iterables: Array<any>): Record<T>,
remove<A>(key: $Keys<T>): Record<T>,
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.

oh wow, nice!

@jasonLaster jasonLaster merged commit 804e92d into firefox-devtools:next Jul 24, 2017
@jasonLaster
Copy link
Copy Markdown
Contributor

Great work @bomsy!

jasonLaster pushed a commit to jasonLaster/debugger.html that referenced this pull request Aug 1, 2017
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