fix(uploads): no more from picker & uploads use correct accountId

Test Plan: edgehill --test

Reviewers: dillon, bengotow

Reviewed By: bengotow

Differential Revision: https://phab.nylas.com/D1955
This commit is contained in:
Evan Morikawa 2015-08-28 20:35:43 -04:00
parent e639afae1e
commit a0307d4d88
4 changed files with 76 additions and 51 deletions

View file

@ -27,22 +27,28 @@ class AccountContactField extends React.Component
render: =>
return <span></span> unless @state.accounts.length > 1
<div className="composer-participant-field">
<div className="composer-field-label">{"From:"}</div>
{@_renderFromPicker()}
</div>
_renderFromPicker: ->
current = _.find @state.accounts, (acct) =>
acct.emailAddress is @props.value?.email
if current
currentLabel = current.me().toString()
else
currentLabel = "Choose an account..."
currentLabel = "Please select one of your accounts"
# currentLabel = "Choose an account..."
<div className="composer-participant-field">
<div className="composer-field-label">{"From:"}</div>
<ButtonDropdown
ref="dropdown"
bordered={false}
primaryItem={<span>{currentLabel}</span>}
menu={@_renderMenu()}/>
</div>
return <span className="from-picker" style={position: "relative", top: "5px", left: "0.5em"}>{currentLabel}</span>
# <ButtonDropdown
# ref="dropdown"
# bordered={false}
# primaryItem={<span>{currentLabel}</span>}
# menu={@_renderMenu()}/>
_renderMenu: =>
others = _.reject @state.accounts, (acct) =>

View file

@ -237,6 +237,12 @@
min-height: @line-height-computed;
}
}
.from-picker {
&:hover {
cursor: default;
}
}
}
// Overrides for the composer in a message-list

View file

@ -77,6 +77,18 @@ describe "FileUploadTask", ->
if @simulateRequestSuccessImmediately
@simulateRequestSuccess(testResponse)
@testFiles = []
@changes = []
spyOn(DraftStore, "sessionForClientId").andCallFake =>
Promise.resolve(
draft: =>
accountId: "account-id-of-draft"
files: @testFiles
changes:
add: ({files}) => @changes = @changes.concat(files)
commit: -> Promise.resolve()
)
it "rejects if not initialized with a path name", (done) ->
waitsForPromise ->
(new FileUploadTask).performLocal().catch (err) ->
@ -154,18 +166,8 @@ describe "FileUploadTask", ->
describe "when the remote API request succeeds", ->
beforeEach ->
@testFiles = []
@changes = []
@simulateRequestSuccessImmediately = true
spyOn(Actions, "uploadStateChanged")
spyOn(DraftStore, "sessionForClientId").andCallFake =>
Promise.resolve(
draft: => files: @testFiles
changes:
add: ({files}) => @changes = @changes.concat(files)
commit: -> Promise.resolve()
)
it "notifies when the task starts remote", ->
waitsForPromise =>
@ -178,10 +180,14 @@ describe "FileUploadTask", ->
waitsForPromise => @task.performRemote().then ->
options = NylasAPI.makeRequest.mostRecentCall.args[0]
expect(options.path).toBe("/files")
expect(options.accountId).toBe(TEST_ACCOUNT_ID)
expect(options.method).toBe('POST')
expect(options.formData.file.value).toBe("Read Stream")
it "should use the accountID of the draft", ->
waitsForPromise => @task.performRemote().then ->
options = NylasAPI.makeRequest.mostRecentCall.args[0]
expect(options.accountId).toBe("account-id-of-draft")
it "attaches the file to the draft", ->
waitsForPromise => @task.performRemote().then =>
delete @changes[0].clientId

View file

@ -34,32 +34,14 @@ class FileUploadTask extends Task
performRemote: ->
Actions.uploadStateChanged @_uploadData("started")
started = (req) =>
@req = req
@progress = setInterval =>
Actions.uploadStateChanged(@_uploadData("progress"))
, 250
cleanup = =>
clearInterval(@progress)
@req = null
NylasAPI.makeRequest
path: "/files"
accountId: @_accountId()
method: "POST"
json: false
formData: @_formData()
started: started
.finally(cleanup)
.then(@performRemoteParseFile)
.then(@performRemoteAttachFile)
@_loadRelatedDraft()
.then @_makeRequest
.then @_performRemoteParseFile
.then @_performRemoteAttachFile
.then (file) =>
Actions.uploadStateChanged @_uploadData("completed")
Actions.fileUploaded(file: file, uploadData: @_uploadData("completed"))
return Promise.resolve(Task.Status.Finished)
.catch APIError, (err) =>
if err.statusCode in NylasAPI.PermanentErrorCodes
msg = "There was a problem uploading this file. Please try again later."
@ -73,7 +55,34 @@ class FileUploadTask extends Task
else
return Promise.resolve(Task.Status.Retry)
performRemoteParseFile: (rawResponseString) =>
_loadRelatedDraft: =>
DraftStore = require '../stores/draft-store'
DraftStore.sessionForClientId(@messageClientId).then (session) =>
@draftSession = session
@draft = session.draft()
return @draft
_makeRequest: =>
started = (req) =>
@req = req
@progress = setInterval =>
Actions.uploadStateChanged(@_uploadData("progress"))
, 250
cleanup = =>
clearInterval(@progress)
@req = null
NylasAPI.makeRequest
path: "/files"
accountId: @draft.accountId
method: "POST"
json: false
formData: @_formData()
started: started
.finally(cleanup)
_performRemoteParseFile: (rawResponseString) =>
# The Nylas API returns the file json wrapped in an array.
# Since we requested `json:false` the response will come back as
# a raw string.
@ -81,7 +90,7 @@ class FileUploadTask extends Task
file = (new File).fromJSON(json[0])
Promise.resolve(file)
performRemoteAttachFile: (file) =>
_performRemoteAttachFile: (file) =>
# The minute we know what file is associated with the upload, we need
# to fire an Action to notify a popout window's FileUploadStore that
# these two objects are linked. We unfortunately can't wait until
@ -96,13 +105,11 @@ class FileUploadTask extends Task
# listing.
Actions.linkFileToUpload(file: file, uploadData: @_uploadData("completed"))
DraftStore = require '../stores/draft-store'
DraftStore.sessionForClientId(@messageClientId).then (session) =>
files = _.clone(session.draft().files) ? []
files.push(file)
session.changes.add({files})
session.changes.commit().then ->
Promise.resolve(file)
files = _.clone(@draft.files) ? []
files.push(file)
@draftSession.changes.add({files})
@draftSession.changes.commit().then ->
return file
cancel: ->
super