Mailspring/internal_packages/thread-list/lib/thread-list-columns.cjsx

195 lines
6.1 KiB
Plaintext
Raw Normal View History

2016-01-15 06:04:51 +08:00
_ = require 'underscore'
React = require 'react'
classNames = require 'classnames'
Better support 24-hour time (#2622) * Added support for 24-hour time to the thread list view (Issue #682) * Add 24-hour time support to the thread list scroll tooltip (Issue #682) * Fix for 24-hour time in the thread list scroll tooltip (#682) Correctly imports the DateUtils module * Add support for 24-hour time to the draft threads list (Issue #682) * Add 24-hour time to the message sidebar * Fix for 24-hour time in the message view so the rollover tooltip is 24hour also (#682) * Removed unused date functions from utils fullTimeString and shortTimeString from src/flux/models/utils.coffee were not compatible with 24-hour time. These functions were modified and moved to DateUtils in src/date-utils. * Fix for display of 24-hour time in the message view (Issue #682) * Removed unused import of Utils in a couple of files Prompted by Travis build errors. * Updates to handling of date/time display Incorporates changes suggested by @bengotow. Re-enables support for the isDetailed property in message-timestamp (if this is set to true, a medium length date/time string will be used for display). Re-enables additional display varieties based on when the email was received. Note that this is implemented slightly different to the orinal version - time is now given as an absolute time rather than "... days ago" format. TZ guessing moved to the global scope of date-utils for performance reasons. * Minor de-linting * Re-enable all tests by unfocusing the test suite A previous commit (ad04775) added an fdescribe() to one of the tests in draft-helpers-spec. This changes that to a regular describe() so that all tests will be run when running ./N1 --test. * Added tests for the new DateUtils functions Added tests for getTimeFormat, mediumTimeString and fullTimeString. Removed no longer relevant tests from message-timestamp-spec as _formattedDate has been removed in favour of the functions in date-utils. To test shortTimeString, we need to be able to set a fake current time which is possible in jasmine 2.0+ but not in 1.3 which is currently in use. As a possible bug, when running more than 10 tests the following warning is raised: "(node:25025) Warning: Possible EventEmitter memory leak detected. 11 on-config-reloaded listeners added. Use emitter.setMaxListeners() to increase limit", source: internal/process/warning.js (24) * Minor de-linting
2016-07-29 08:42:14 +08:00
moment = require 'moment'
2016-01-15 06:04:51 +08:00
{ListTabular,
RetinaImg,
MailLabelSet,
2016-01-15 06:04:51 +08:00
MailImportantIcon,
InjectedComponent,
2016-01-15 06:04:51 +08:00
InjectedComponentSet} = require 'nylas-component-kit'
Better support 24-hour time (#2622) * Added support for 24-hour time to the thread list view (Issue #682) * Add 24-hour time support to the thread list scroll tooltip (Issue #682) * Fix for 24-hour time in the thread list scroll tooltip (#682) Correctly imports the DateUtils module * Add support for 24-hour time to the draft threads list (Issue #682) * Add 24-hour time to the message sidebar * Fix for 24-hour time in the message view so the rollover tooltip is 24hour also (#682) * Removed unused date functions from utils fullTimeString and shortTimeString from src/flux/models/utils.coffee were not compatible with 24-hour time. These functions were modified and moved to DateUtils in src/date-utils. * Fix for display of 24-hour time in the message view (Issue #682) * Removed unused import of Utils in a couple of files Prompted by Travis build errors. * Updates to handling of date/time display Incorporates changes suggested by @bengotow. Re-enables support for the isDetailed property in message-timestamp (if this is set to true, a medium length date/time string will be used for display). Re-enables additional display varieties based on when the email was received. Note that this is implemented slightly different to the orinal version - time is now given as an absolute time rather than "... days ago" format. TZ guessing moved to the global scope of date-utils for performance reasons. * Minor de-linting * Re-enable all tests by unfocusing the test suite A previous commit (ad04775) added an fdescribe() to one of the tests in draft-helpers-spec. This changes that to a regular describe() so that all tests will be run when running ./N1 --test. * Added tests for the new DateUtils functions Added tests for getTimeFormat, mediumTimeString and fullTimeString. Removed no longer relevant tests from message-timestamp-spec as _formattedDate has been removed in favour of the functions in date-utils. To test shortTimeString, we need to be able to set a fake current time which is possible in jasmine 2.0+ but not in 1.3 which is currently in use. As a possible bug, when running more than 10 tests the following warning is raised: "(node:25025) Warning: Possible EventEmitter memory leak detected. 11 on-config-reloaded listeners added. Use emitter.setMaxListeners() to increase limit", source: internal/process/warning.js (24) * Minor de-linting
2016-07-29 08:42:14 +08:00
{Thread, FocusedPerspectiveStore, Utils, DateUtils} = require 'nylas-exports'
2016-01-15 06:04:51 +08:00
{ThreadArchiveQuickAction,
ThreadTrashQuickAction} = require './thread-list-quick-actions'
ThreadListParticipants = require './thread-list-participants'
ThreadListStore = require './thread-list-store'
ThreadListIcon = require './thread-list-icon'
Better support 24-hour time (#2622) * Added support for 24-hour time to the thread list view (Issue #682) * Add 24-hour time support to the thread list scroll tooltip (Issue #682) * Fix for 24-hour time in the thread list scroll tooltip (#682) Correctly imports the DateUtils module * Add support for 24-hour time to the draft threads list (Issue #682) * Add 24-hour time to the message sidebar * Fix for 24-hour time in the message view so the rollover tooltip is 24hour also (#682) * Removed unused date functions from utils fullTimeString and shortTimeString from src/flux/models/utils.coffee were not compatible with 24-hour time. These functions were modified and moved to DateUtils in src/date-utils. * Fix for display of 24-hour time in the message view (Issue #682) * Removed unused import of Utils in a couple of files Prompted by Travis build errors. * Updates to handling of date/time display Incorporates changes suggested by @bengotow. Re-enables support for the isDetailed property in message-timestamp (if this is set to true, a medium length date/time string will be used for display). Re-enables additional display varieties based on when the email was received. Note that this is implemented slightly different to the orinal version - time is now given as an absolute time rather than "... days ago" format. TZ guessing moved to the global scope of date-utils for performance reasons. * Minor de-linting * Re-enable all tests by unfocusing the test suite A previous commit (ad04775) added an fdescribe() to one of the tests in draft-helpers-spec. This changes that to a regular describe() so that all tests will be run when running ./N1 --test. * Added tests for the new DateUtils functions Added tests for getTimeFormat, mediumTimeString and fullTimeString. Removed no longer relevant tests from message-timestamp-spec as _formattedDate has been removed in favour of the functions in date-utils. To test shortTimeString, we need to be able to set a fake current time which is possible in jasmine 2.0+ but not in 1.3 which is currently in use. As a possible bug, when running more than 10 tests the following warning is raised: "(node:25025) Warning: Possible EventEmitter memory leak detected. 11 on-config-reloaded listeners added. Use emitter.setMaxListeners() to increase limit", source: internal/process/warning.js (24) * Minor de-linting
2016-07-29 08:42:14 +08:00
# Get and format either last sent or last received timestamp depending on thread-list being viewed
ThreadListTimestamp = ({thread}) ->
if FocusedPerspectiveStore.current().isSent()
Better support 24-hour time (#2622) * Added support for 24-hour time to the thread list view (Issue #682) * Add 24-hour time support to the thread list scroll tooltip (Issue #682) * Fix for 24-hour time in the thread list scroll tooltip (#682) Correctly imports the DateUtils module * Add support for 24-hour time to the draft threads list (Issue #682) * Add 24-hour time to the message sidebar * Fix for 24-hour time in the message view so the rollover tooltip is 24hour also (#682) * Removed unused date functions from utils fullTimeString and shortTimeString from src/flux/models/utils.coffee were not compatible with 24-hour time. These functions were modified and moved to DateUtils in src/date-utils. * Fix for display of 24-hour time in the message view (Issue #682) * Removed unused import of Utils in a couple of files Prompted by Travis build errors. * Updates to handling of date/time display Incorporates changes suggested by @bengotow. Re-enables support for the isDetailed property in message-timestamp (if this is set to true, a medium length date/time string will be used for display). Re-enables additional display varieties based on when the email was received. Note that this is implemented slightly different to the orinal version - time is now given as an absolute time rather than "... days ago" format. TZ guessing moved to the global scope of date-utils for performance reasons. * Minor de-linting * Re-enable all tests by unfocusing the test suite A previous commit (ad04775) added an fdescribe() to one of the tests in draft-helpers-spec. This changes that to a regular describe() so that all tests will be run when running ./N1 --test. * Added tests for the new DateUtils functions Added tests for getTimeFormat, mediumTimeString and fullTimeString. Removed no longer relevant tests from message-timestamp-spec as _formattedDate has been removed in favour of the functions in date-utils. To test shortTimeString, we need to be able to set a fake current time which is possible in jasmine 2.0+ but not in 1.3 which is currently in use. As a possible bug, when running more than 10 tests the following warning is raised: "(node:25025) Warning: Possible EventEmitter memory leak detected. 11 on-config-reloaded listeners added. Use emitter.setMaxListeners() to increase limit", source: internal/process/warning.js (24) * Minor de-linting
2016-07-29 08:42:14 +08:00
rawTimestamp = thread.lastMessageSentTimestamp
else
Better support 24-hour time (#2622) * Added support for 24-hour time to the thread list view (Issue #682) * Add 24-hour time support to the thread list scroll tooltip (Issue #682) * Fix for 24-hour time in the thread list scroll tooltip (#682) Correctly imports the DateUtils module * Add support for 24-hour time to the draft threads list (Issue #682) * Add 24-hour time to the message sidebar * Fix for 24-hour time in the message view so the rollover tooltip is 24hour also (#682) * Removed unused date functions from utils fullTimeString and shortTimeString from src/flux/models/utils.coffee were not compatible with 24-hour time. These functions were modified and moved to DateUtils in src/date-utils. * Fix for display of 24-hour time in the message view (Issue #682) * Removed unused import of Utils in a couple of files Prompted by Travis build errors. * Updates to handling of date/time display Incorporates changes suggested by @bengotow. Re-enables support for the isDetailed property in message-timestamp (if this is set to true, a medium length date/time string will be used for display). Re-enables additional display varieties based on when the email was received. Note that this is implemented slightly different to the orinal version - time is now given as an absolute time rather than "... days ago" format. TZ guessing moved to the global scope of date-utils for performance reasons. * Minor de-linting * Re-enable all tests by unfocusing the test suite A previous commit (ad04775) added an fdescribe() to one of the tests in draft-helpers-spec. This changes that to a regular describe() so that all tests will be run when running ./N1 --test. * Added tests for the new DateUtils functions Added tests for getTimeFormat, mediumTimeString and fullTimeString. Removed no longer relevant tests from message-timestamp-spec as _formattedDate has been removed in favour of the functions in date-utils. To test shortTimeString, we need to be able to set a fake current time which is possible in jasmine 2.0+ but not in 1.3 which is currently in use. As a possible bug, when running more than 10 tests the following warning is raised: "(node:25025) Warning: Possible EventEmitter memory leak detected. 11 on-config-reloaded listeners added. Use emitter.setMaxListeners() to increase limit", source: internal/process/warning.js (24) * Minor de-linting
2016-07-29 08:42:14 +08:00
rawTimestamp = thread.lastMessageReceivedTimestamp
timestamp = DateUtils.shortTimeString(rawTimestamp)
return <span className="timestamp">{timestamp}</span>
subject = (subj) ->
if (subj ? "").trim().length is 0
return <span className="no-subject">(No Subject)</span>
else if subj.split(/([\uD800-\uDBFF][\uDC00-\uDFFF])/g).length > 1
subjComponents = []
subjParts = subj.split /([\uD800-\uDBFF][\uDC00-\uDFFF])/g
for part, idx in subjParts
if part.match /([\uD800-\uDBFF][\uDC00-\uDFFF])/g
subjComponents.push <span className="emoji" key={idx}>{part}</span>
else
subjComponents.push <span key={idx}>{part}</span>
return subjComponents
else
return subj
getSnippet = (thread) ->
messages = thread.__messages || []
if (messages.length is 0)
return thread.snippet
return messages[messages.length - 1].snippet
2016-01-15 06:04:51 +08:00
c1 = new ListTabular.Column
name: "★"
resolver: (thread) =>
[
<ThreadListIcon key="thread-list-icon" thread={thread} />
<MailImportantIcon
key="mail-important-icon"
thread={thread}
showIfAvailableForAnyAccount={true}
/>
2016-01-15 06:04:51 +08:00
<InjectedComponentSet
key="injected-component-set"
inline={true}
containersRequired={false}
matching={role: "ThreadListIcon"}
className="thread-injected-icons"
exposedProps={thread: thread}
/>
2016-01-15 06:04:51 +08:00
]
c2 = new ListTabular.Column
name: "Participants"
width: 200
resolver: (thread) =>
hasDraft = (thread.__messages || []).find((m) => m.draft)
2016-01-15 06:04:51 +08:00
if hasDraft
<div style={display: 'flex'}>
<ThreadListParticipants thread={thread} />
<RetinaImg name="icon-draft-pencil.png"
className="draft-icon"
mode={RetinaImg.Mode.ContentPreserve} />
</div>
else
<ThreadListParticipants thread={thread} />
c3 = new ListTabular.Column
name: "Message"
flex: 4
resolver: (thread) =>
attachment = false
messages = (thread.__messages || [])
hasAttachments = thread.hasAttachments and messages.find (m) -> Utils.showIconForAttachments(m.files)
if hasAttachments
2016-01-15 06:04:51 +08:00
attachment = <div className="thread-icon thread-icon-attachment"></div>
<span className="details">
<MailLabelSet thread={thread} />
2016-01-15 06:04:51 +08:00
<span className="subject">{subject(thread.subject)}</span>
<span className="snippet">{getSnippet(thread)}</span>
2016-01-15 06:04:51 +08:00
{attachment}
</span>
c4 = new ListTabular.Column
name: "Date"
resolver: (thread) =>
return <ThreadListTimestamp thread={thread} />
2016-01-15 06:04:51 +08:00
c5 = new ListTabular.Column
name: "HoverActions"
resolver: (thread) =>
<div className="inner">
<InjectedComponentSet
key="injected-component-set"
inline={true}
containersRequired={false}
children=
{[
<ThreadTrashQuickAction key="thread-trash-quick-action" thread={thread} />
<ThreadArchiveQuickAction key="thread-archive-quick-action" thread={thread} />
2016-01-15 06:04:51 +08:00
]}
matching={role: "ThreadListQuickAction"}
className="thread-injected-quick-actions"
exposedProps={thread: thread}
/>
2016-01-15 06:04:51 +08:00
</div>
cNarrow = new ListTabular.Column
name: "Item"
flex: 1
resolver: (thread) =>
pencil = false
attachment = false
messages = (thread.__messages || [])
hasAttachments = thread.hasAttachments and messages.find (m) -> Utils.showIconForAttachments(m.files)
if hasAttachments
2016-01-15 06:04:51 +08:00
attachment = <div className="thread-icon thread-icon-attachment"></div>
hasDraft = messages.find((m) => m.draft)
2016-01-15 06:04:51 +08:00
if hasDraft
pencil = <RetinaImg name="icon-draft-pencil.png" className="draft-icon" mode={RetinaImg.Mode.ContentPreserve} />
# TODO We are limiting the amount on injected icons in narrow mode to 1
# until we revisit the UI to accommodate more icons
<div style={display: 'flex', alignItems: 'flex-start'}>
<div className="icons-column">
2016-01-15 06:04:51 +08:00
<ThreadListIcon thread={thread} />
<InjectedComponentSet
inline={true}
matchLimit={1}
direction="column"
containersRequired={false}
key="injected-component-set"
exposedProps={thread: thread}
matching={role: "ThreadListIcon"}
className="thread-injected-icons"
/>
<MailImportantIcon
thread={thread}
showIfAvailableForAnyAccount={true}
/>
2016-01-15 06:04:51 +08:00
</div>
<div className="thread-info-column">
<div className="participants-wrapper">
<ThreadListParticipants thread={thread} />
{pencil}
<span style={flex:1}></span>
{attachment}
<InjectedComponent
key="thread-injected-timestamp"
className="thread-injected-timestamp"
inline={true}
containersRequired={false}
fallback={ThreadListTimestamp}
exposedProps={thread: thread}
matching={role: "ThreadListTimestamp"}
/>
</div>
<div className="subject">{subject(thread.subject)}</div>
<div className="snippet-and-labels">
<div className="snippet">{getSnippet(thread)}&nbsp;</div>
<div style={flex: 1, flexShrink: 1}></div>
<MailLabelSet thread={thread} />
</div>
</div>
2016-01-15 06:04:51 +08:00
</div>
module.exports =
Narrow: [cNarrow]
Wide: [c1, c2, c3, c4, c5]