fix(search): fix UI issues with search and add test

Summary:
Fixes:
- Search bar dropdown doesn’t go away if you focus into a message
- If a search times out, it continues to display nothing
- Clicked “Inbox” from a search and it didn’t clear the search box

Test Plan: edgehill --test

Reviewers: dillon, bengotow

Reviewed By: dillon, bengotow

Differential Revision: https://phab.nylas.com/D2000
This commit is contained in:
Evan Morikawa 2015-09-09 16:04:13 -07:00
parent 6a6619a106
commit 5fdafcb899
4 changed files with 30 additions and 19 deletions

View file

@ -1,6 +1,6 @@
React = require 'react/addons'
classNames = require 'classnames'
{Actions} = require 'nylas-exports'
{Actions, WorkspaceStore} = require 'nylas-exports'
{Menu, RetinaImg} = require 'nylas-component-kit'
SearchSuggestionStore = require './search-suggestion-store'
_ = require 'underscore'
@ -16,7 +16,10 @@ class SearchBar extends React.Component
committedQuery: null
componentDidMount: =>
@unsubscribe = SearchSuggestionStore.listen @_onChange
@usub = []
@usub.push SearchSuggestionStore.listen @_onChange
@usub.push WorkspaceStore.listen =>
@setState(focused: false) if @state.focused
@body_unsubscriber = atom.commands.add 'body', {
'application:focus-search': @_onFocusSearch
}
@ -28,7 +31,7 @@ class SearchBar extends React.Component
# atom events before it unmounts. Thank you event-kit
# This can be fixed via a Reflux mixin
componentWillUnmount: =>
@unsubscribe()
usub() for usub in @usub
@body_unsubscriber.dispose()
@search_unsubscriber.dispose()

View file

@ -1,5 +1,6 @@
_ = require 'underscore'
Actions = require '../../src/flux/actions'
Label = require '../../src/flux/models/label'
Folder = require '../../src/flux/models/folder'
MailViewFilter = require '../../src/mail-view-filter'
@ -58,6 +59,12 @@ describe "FocusedMailViewStore", ->
FocusedMailViewStore._onFocusMailView(@inboxFilter)
expect(FocusedMailViewStore._setMailView).not.toHaveBeenCalled()
it "should clear existing searches if any other category is focused", ->
spyOn(Actions, 'searchQueryCommitted')
FocusedMailViewStore._onSearchQueryCommitted('bla')
FocusedMailViewStore._onFocusMailView(@userFilter)
expect(Actions.searchQueryCommitted).toHaveBeenCalledWith('')
describe 'when using labels', ->
beforeEach ->
atom.testOrganizationUnit = 'label'

View file

@ -20,8 +20,7 @@ class FocusedMailViewStore extends NylasStore
_onFocusMailView: (filter) ->
return if filter.isEqual(@_mailView)
if @_mailView is null and filter
Actions.searchQueryCommitted('')
Actions.searchQueryCommitted('')
@_setMailView(filter)
_onSearchQueryCommitted: (query="") ->

View file

@ -60,25 +60,27 @@ class SearchView extends ModelView
accountId: @_accountId
json: true
returnsModel: false
error: =>
page.loading = false
@_emitter.emit('trigger')
success: (json) =>
objects = []
.then (json) =>
objects = []
@_queryResultTotal = json.length
@_queryResultTotal = json.length
for resultJSON in json
obj = (new Thread).fromJSON(resultJSON)
objects.push(obj)
for resultJSON in json
obj = (new Thread).fromJSON(resultJSON)
objects.push(obj)
DatabaseStore.persistModels(objects) if objects.length > 0
DatabaseStore.persistModels(objects) if objects.length > 0
page.items = objects
page.loading = false
@_emitter.emit('trigger')
page.items = objects
page.loading = false
@_emitter.emit('trigger')
console.log("Search view fetched #{idx} in #{Date.now() - start} msec.")
console.log("Search view fetched #{idx} in #{Date.now() - start} msec.")
.catch (error) =>
@_queryResultTotal = 0
page.items = []
page.loading = false
@_emitter.emit('trigger')
module.exports = SearchView