Thanks to visit codestin.com
Credit goes to github.com

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

Conversation

@jasonLaster
Copy link
Contributor

Summary of Changes

I realized #3888 was too big, so i'm taking the file search redux part out and making it its own PR.

Why extract:

  • I'm realizing now that actions/ui was primarily file search.
  • Now that we have redux backends for project search, text search etc, it only seems fair
  • the file search (SearchBar) component is way too complicated
  • I'd like to have the search bar component only mounted when it is shown, to do this we need a permanent store.

Other questions / Musings:

The redux api (actions/selectors) need to be be really long like setFileSearchQuery because they are shared among the entire app. It would be really cool if we could begin having sub-apps which are redux backends that are only connected to their root component.

Test Plan

Re-use existing tests


/**
* UI reducer
* @module reducers/ui
Copy link
Contributor

@bomsy bomsy Sep 5, 2017

Choose a reason for hiding this comment

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

should be reducers/file-search

import { getMatches } from "../utils/search";
import type { ThunkArgs } from "./types";

// import {} from "./index";
Copy link
Contributor

Choose a reason for hiding this comment

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

remove this line

Copy link
Contributor

@codehag codehag left a comment

Choose a reason for hiding this comment

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

this looks really good! coupla nits


async function searchContents(query: string, editor: Object) {
return async ({ getState, dispatch }) => {
// const { selectedSource, modifiers, editor: ed } = this.props;
Copy link
Contributor

Choose a reason for hiding this comment

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

we can remove this line as well

const query = getFileSearchQuery(getState());
const modifiers = getFileSearchModifiers(getState());
const { searchResults: matches } = getFileSearchResults();
// const { query, modifiers, searchResults: { matches } } = this.props;
Copy link
Contributor

Choose a reason for hiding this comment

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

this one too

count: number
};

export type UIState = {
Copy link
Contributor

Choose a reason for hiding this comment

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

should this also be FileSearchState?

}

case "TOGGLE_MODIFIER": {
const actionVal = !state.getIn(["modifiers", action.modifier]);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm on the fence about this but i will mention it anyway; is action.modifier a string? could we do something like

prefs[`fileSearch${action.modifier}`]

(i think it needs a first letter uppercase, but you get the idea)

since we seem to be doing the same thing each time, and we might not need this extra layer

@codecov
Copy link

codecov bot commented Sep 8, 2017

Codecov Report

Merging #3889 into master will decrease coverage by 0.02%.
The diff coverage is 33.62%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3889      +/-   ##
==========================================
- Coverage   54.69%   54.66%   -0.03%     
==========================================
  Files         141      143       +2     
  Lines        5125     5098      -27     
  Branches     1056     1050       -6     
==========================================
- Hits         2803     2787      -16     
+ Misses       2322     2311      -11
Impacted Files Coverage Δ
src/utils/result-list.js 83.33% <ø> (+46.74%) ⬆️
src/actions/ui.js 70.96% <ø> (-4.71%) ⬇️
src/selectors.js 100% <ø> (ø) ⬆️
src/components/Editor/index.js 21.24% <ø> (ø) ⬆️
src/reducers/ui.js 76.59% <ø> (-3.71%) ⬇️
src/components/shared/SearchInput.js 93.54% <100%> (+0.44%) ⬆️
src/actions/file-search.js 13.79% <13.79%> (ø)
src/components/Editor/SearchBar.js 28.84% <16.66%> (-4.49%) ⬇️
src/reducers/file-search.js 92% <92%> (ø)
... and 1 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 c517758...943c7d9. Read the comment docs.

}

case "TOGGLE_MODIFIER": {
const actionVal = !state.getIn(["modifiers", action.modifier]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

lol we tried to do this kind of thing before, but it is too magical.

a big style reason not to, is that it is nice to grep for pref keys, just like it's nice to grep for l10n keys

shiftSearchAgainShortcut
} = getShortcuts();

shortcuts.on(searchShortcut, (_, e) => this.toggleSearch(e));
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you mean to remove the search shortcut?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, because the search bar is now unmounted when it is not open. See the Editor/index render method

Copy link
Contributor

Choose a reason for hiding this comment

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

I see that. But now there isn't a way to enable the search bar?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, we should probably fix that :)

I think i was going to add a shortcut in App.js or Editor/index

@wldcordeiro wldcordeiro force-pushed the fix-project-search2 branch 3 times, most recently from c0efbe1 to 4b410e0 Compare September 11, 2017 18:39
@wldcordeiro
Copy link
Contributor

Working on this some more. Had to rework some of the code and rebase. Apologies for the delays.

@wldcordeiro wldcordeiro force-pushed the fix-project-search2 branch 2 times, most recently from 56f55af to 4d8c9a9 Compare September 22, 2017 00:50
dispatch(actions.toggleFileSearchModifier("caseSensitive"));
fileSearchModState = getFileSearchModifiers(getState());
expect(fileSearchModState.get("caseSensitive")).toBe(true);
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i bet we can do some doSearch tests now where we stub codemirror. Obviously not a blocker, just excited

@jasonLaster jasonLaster force-pushed the fix-project-search2 branch 3 times, most recently from 6bbe8ca to 42bfd73 Compare September 29, 2017 00:17
@wldcordeiro
Copy link
Contributor

Almost ready to go! One last behavior to test and this is ready. 😄

@wldcordeiro wldcordeiro force-pushed the fix-project-search2 branch 3 times, most recently from 5d6f79e to 9cb13dd Compare October 1, 2017 07:03
@wldcordeiro
Copy link
Contributor

Travis keeps failing but I believe I've got it working like expected 😁

@jasonLaster
Copy link
Contributor Author

hmm, the failure seems relevant. I'll look tomorrow.

Lets finish this up

Screen Shot 2017-10-01 at 11.55.48 PM.png

@wldcordeiro wldcordeiro force-pushed the fix-project-search2 branch 2 times, most recently from d4e76fe to 21fed11 Compare October 3, 2017 04:17
@wldcordeiro
Copy link
Contributor

Got it down to one failing mochitest that's unrelated? It's the browser_debug-console.js test. 🤔


// Second time to hide console
pressKey(dbg, "Escape");
pressKey(dbg, "CtrlEscape");
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding this key code worked but it feels wrong. 🙁 @jasonLaster Care to dig in a bit?

const state = cm.state.search;

pressKey(dbg, "Enter");
pressKey(dbg, "Enter");
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know why the second ent here seems to be the trick.

Copy link
Contributor

Choose a reason for hiding this comment

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

looks like it might be a timing issue


// Second time to hide console
pressKey(dbg, "Escape");
pressKey(dbg, "CtrlEscape");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure...

const state = cm.state.search;

pressKey(dbg, "Enter");
pressKey(dbg, "Enter");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

also weird...

@codehag
Copy link
Contributor

codehag commented Oct 11, 2017

can you rebase and I will take a look at the mochi test issue?

@codehag codehag mentioned this pull request Oct 13, 2017
Copy link
Contributor

@codehag codehag left a comment

Choose a reason for hiding this comment

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

Hey everyone. I will close this PR in favor of #4368

While i was able to fix the escape button bug, I also found that ctrl-cmd-i was no longer working in this branch. Unforunately too many changes were made in this pr for me to be able to accurately diagnose it, and some of them would need some work yet. The above pr is just a simplified version of this one

shortcuts.on(
L10N.getStr("symbolSearch.search.key2"),
this.toggleSymbolModal
this.toggleVisible.bind(this, "symbol")
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we have this name change here? it doesnt seem part of the reducer work

ref: c => (this.$input = c)
ref: c => {
this.$input = c;
this.props.refFunc != null && this.props.refFunc(c);
Copy link
Contributor

Choose a reason for hiding this comment

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

why are we making this change?

renderEditorPane: Function;
renderVerticalLayout: Function;
toggleSymbolModal: Function;
toggleVisible: Function;
Copy link
Contributor

Choose a reason for hiding this comment

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

also here: what is this change doing? can we leave it out?

setSearchValue(value: string) {
const searchInput = this.searchInput();
if (value == "" || !searchInput) {
if (!this.props.editor) {
Copy link
Contributor

Choose a reason for hiding this comment

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

moving this below e.stopPropagation and e.preventDefault is what was causing the escape button bug.

}

getInputRef(c) {
this.searchInput = c;
Copy link
Contributor

Choose a reason for hiding this comment

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

this change doesnt make much sense to me, because this allows us to highjack the search and allows us to set the search field in two ways, via props and through setSearchValue.

we should instead have local state and props, props being the state that is sent to the search worker.

@codehag
Copy link
Contributor

codehag commented Oct 13, 2017

Closing as mentioned above.

@codehag codehag closed this Oct 13, 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.

4 participants