forked from nylas/nylas-mail
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tags): Tags dropdown and new features for Menu and Popover
Summary: Focused Content Store should notify observers when focused items change, not just when they're reassigned Popovers should have a `direction` and optional event onOpened Menu divider documentation was wrong, menus should support checked items by default Pressing escape in a popover's input should dismiss the popover Other changes Remove specs that make no sense anymore Small tweak to report build breaking. Shouldn't happen often ;) Test Plan: Run tests, which will now phone home if they break Reviewers: evan Reviewed By: evan Differential Revision: https://review.inboxapp.com/D1493
- Loading branch information
Showing
17 changed files
with
349 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
internal_packages/message-list/lib/thread-archive-button.cjsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
_ = require 'underscore-plus' | ||
React = require 'react' | ||
{Actions, Utils} = require 'inbox-exports' | ||
{RetinaImg} = require 'ui-components' | ||
|
||
class ArchiveButton extends React.Component | ||
@displayName: "ArchiveButton" | ||
|
||
render: => | ||
<button className="btn btn-toolbar btn-archive" | ||
data-tooltip="Archive" | ||
onClick={@_onArchive}> | ||
<RetinaImg name="toolbar-archive.png" /> | ||
</button> | ||
|
||
_onArchive: (e) => | ||
return unless Utils.nodeIsVisible(e.currentTarget) | ||
Actions.archive() | ||
e.stopPropagation() | ||
|
||
|
||
module.exports = ArchiveButton |
151 changes: 151 additions & 0 deletions
151
internal_packages/message-list/lib/thread-tags-button.cjsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
_ = require 'underscore-plus' | ||
React = require 'react' | ||
Reflux = require 'reflux' | ||
classNames = require 'classnames' | ||
{Actions, | ||
Utils, | ||
AddRemoveTagsTask, | ||
FocusedContentStore, | ||
FocusedContentStore, | ||
DatabaseStore, | ||
Tag, | ||
Thread, | ||
TaskQueue} = require 'inbox-exports' | ||
{RetinaImg, | ||
Popover, | ||
Menu} = require 'ui-components' | ||
|
||
TagsStore = Reflux.createStore | ||
init: -> | ||
@_setStoreDefaults() | ||
@_registerListeners() | ||
@_fetch() | ||
|
||
items: -> | ||
@_items | ||
|
||
_setStoreDefaults: -> | ||
@_items = [] | ||
|
||
_registerListeners: -> | ||
@listenTo DatabaseStore, @_onDataChanged | ||
|
||
_onDataChanged: (change) -> | ||
if change and change.objectClass is Tag.name | ||
@_fetch() | ||
|
||
_fetch: -> | ||
DatabaseStore.findAll(Tag).then (tags) => | ||
@_items = tags | ||
@trigger() | ||
|
||
|
||
# Note | ||
class ThreadTagsButton extends React.Component | ||
@displayName: 'ThreadTagsButton' | ||
|
||
constructor: (@props) -> | ||
@state = @_getStateForSearch('') | ||
@ | ||
|
||
componentDidMount: -> | ||
@unsubscribers = [] | ||
@unsubscribers.push TagsStore.listen @_onStoreChange | ||
@unsubscribers.push FocusedContentStore.listen @_onFocusChange | ||
|
||
componentWillUnmount: => | ||
return unless @unsubscribers | ||
unsubscribe() for unsubscribe in @unsubscribers | ||
|
||
render: => | ||
button = <button className="btn btn-toolbar"> | ||
<RetinaImg name="toolbar-tags.png"/> | ||
<RetinaImg name="toolbar-chevron.png"/> | ||
</button> | ||
|
||
headerComponents = [ | ||
<input type="text" | ||
tabIndex="1" | ||
key="textfield" | ||
className="search" | ||
value={@state.searchValue} | ||
onChange={@_onSearchValueChange}/> | ||
] | ||
|
||
<Popover className="tag-picker" | ||
direction="down" | ||
onOpened={@_onShowTags} | ||
buttonComponent={button}> | ||
<Menu ref="menu" | ||
headerComponents={headerComponents} | ||
footerComponents={[]} | ||
items={@state.tags} | ||
itemKey={ (item) -> item.id } | ||
itemContent={@_itemContent} | ||
itemChecked={@_itemChecked} | ||
onSelect={@_onToggleTag} | ||
/> | ||
</Popover> | ||
|
||
_itemContent: (tag) => | ||
if tag.id is 'divider' | ||
<Menu.Item divider={tag.name} /> | ||
else | ||
tag.name.charAt(0).toUpperCase() + tag.name.slice(1) | ||
|
||
_itemChecked: (tag) => | ||
return false unless @state.thread | ||
@state.thread.hasTagId(tag.id) | ||
|
||
_onShowTags: => | ||
# Always reset search state when the popover is shown | ||
if @state.searchValue.length > 0 | ||
@setState @_getStateForSearch('') | ||
|
||
_onToggleTag: (tag) => | ||
return unless @state.thread | ||
|
||
if @state.thread.hasTagId(tag.id) | ||
task = new AddRemoveTagsTask(@state.thread, [], [tag.id]) | ||
else | ||
task = new AddRemoveTagsTask(@state.thread, [tag.id], []) | ||
|
||
@refs.menu.setSelectedItem(null) | ||
|
||
TaskQueue.enqueue(task) | ||
|
||
_onFocusChange: (change) => | ||
if change.impactsCollection('thread') | ||
@_onStoreChange() | ||
|
||
_onStoreChange: => | ||
@setState @_getStateForSearch(@state.searchValue) | ||
|
||
_onSearchValueChange: (event) => | ||
@setState @_getStateForSearch(event.target.value) | ||
|
||
_getStateForSearch: (searchValue = '') => | ||
searchTerm = searchValue.toLowerCase() | ||
thread = FocusedContentStore.focused('thread') | ||
return [] unless thread | ||
|
||
tags = _.filter TagsStore.items(), (tag) -> tag.name.toLowerCase().indexOf(searchTerm) is 0 | ||
|
||
# Some tags are "magic" state and can't be added/removed | ||
tags = _.filter tags, (tag) -> not (tag.id in ['unseen', 'attachment', 'sending', 'drafts', 'sent']) | ||
|
||
# Some tags are readonly | ||
tags = _.filter tags, (tag) -> not tag.readonly | ||
|
||
# Organize tags into currently applied / not applied | ||
active = [] | ||
inactive = [] | ||
for tag in tags | ||
if thread.hasTagId(tag.id) | ||
active.push(tag) | ||
else | ||
inactive.push(tag) | ||
|
||
{searchValue, thread, tags: [].concat(active, inactive)} | ||
|
||
module.exports = ThreadTagsButton |
25 changes: 0 additions & 25 deletions
25
internal_packages/message-list/spec/message-toolbar-items-spec.cjsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.