-
-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add events to file-queue helper, set up TypeScript, drop ember-cli-addon-docs, drop support for Ember < 3.28 #620
Conversation
This is a great contribution – thank you @gossi ! Hugely appreciate you wading in here. TS and docs
Appreciate that TS is very nice and helpful – and I don't want to discourage you – but it's a bit presumptuous to include without at least discussing first. Would also prefer to make this change in a single PR rather than bundle it with an API update.
Are you volunteering to take care of this? I don't want to release without a docsite and the current one hosts versioned docs back to 2.4.4 which we'd have to archive somehow. General responses
Yes we'll need
It was recently added and documented in #578. It has been published in betas but not an official release. Looks like with this api Component API
True. I would be happy to more aggressively update I guess regardless I would recommend addon consumers use the
Adding upload callbacks to the
This can mostly be handled internally since the API changes are happening at the queue level, yeah? We will need to at least allow Full API ExampleFor the sake of clarity I'll try post an example of using every component with this new API. {{#let (file-queue fileAdded=this.addFile fileRemoved=this.removeFile) as |queue|}}
{{#each queue.files as |file|}}
<span data-test-file>
{{file.name}}
</span>
<button type='button' data-test-remove {{on 'click' (fn queue.remove file)}}>
x
</button>
{{/each}}
<label>
<input
type='file'
{{queue.selectFile filter=this.filter filesSelected=this.selectFiles}}
hidden
/>
Select File
</label>
<FileUpload
@queue={{queue}}
@filter={{this.filter}}
@filesSelected={{this.selectFile}}
{{!-- deprecated --}}
@onSelect={{this.filterSelectedFiles}}
@onFileAdd={{this.performUpload}}
>
<a>choose files</a>
</FileUpload>
<FileDropzone
{{!-- we probably need to add --}}
@queue={{queue}}
@filter={{this.filter}}
@filesSelected={{this.selectFile}}
{{!-- deprecated --}}
@onDrop={{this.filesDropped}} {{!-- and many more drag and drop callbacks --}}
@onFileAdd={{this.performUpload}}
/>
{{/let}} I think we should make the naming consistent and replace with deprecation all Performing an uploadThe currently documented way to integrate is for the consumer to pass their own callback to This much nicer API means we can recommend users instead attach the same callback to Final thoughtsHow can I help with this?
|
Thanks @gilest for your feedback. Let me address some of those.
Yeah, I tried to use JS in the first place. But was too often distracted by fields that were "magically" inserted and I needed clarity to access them. So I pulled in TS. I saw discussion about using TS for this addon in the issues. I also thought about doing that in isolation as a "foundation" PR at first. But this PR would be to only install ember-cli-typescript and with subsequent PRs type one file after the other (or you lower the type-checks close to zero, when renaming existing
Yes. It's done when it's documented. I looked into other options than ec-addon-docs, namely field-guide and docfy. Given the later plays well with TS (and probably auto-generates the API for components ?), this seems to be the go to option.
Ok, I had this in. Couldn't find the minimum supported ember-version and because the
Ah, I wasn't precise. It was never public as stable only tagged as beta, which according to semver is "here is a playground for a new API, we need feedback - for the time please don't rely on this". So, it wasn't released with final API guarantees yet - that's my point.
I'm sorry to disappoint you but
Perhaps not needed at all. Since
Yeah, I guess so.
👍
Yes, as said above, this needs a great documentation update.
What I can think of:
What I will do:
But much likely this will all begin to happen next year 🎉 |
24b7aa0
to
8e8ef49
Compare
addon/queue.ts
Outdated
* queue may be `"artworks/{{id}}/photos"`, where `{{id}}` | ||
* is a dynamic segment that is generated from the artwork id. | ||
*/ | ||
name: QueueName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be readonly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it shouldn't mutated.
Ok, fixed the bug I've been seeing, addressed your requested changes and made some cleanup.
These question plus how to deal with That would be the last thing. Apart from that, if there is nothing left from your side, this PR is already good looking and ready to go? |
@gilest Any updates on this? Anything for me to do? Would like to see this merged and published :) |
4b9a174
to
79abc16
Compare
rebased and fixed the linting... which needs approval again (can't this run automatically?) |
selectFiles('input[type=file]', new File([], 'dingus.txt')); | ||
await waitFor('[data-test-file]'); | ||
assert.dom('[data-test-file]').hasText('dingus.txt'); | ||
|
||
await settled(); | ||
assert.dom('[data-test-file]').doesNotExist(); | ||
|
||
// second upload (retention teset) | ||
// to check `Queue.flush()` will keep auto-tracking intact | ||
selectFiles('input[type=file]', new File([], 'dingus.txt')); | ||
await waitFor('[data-test-file]'); | ||
assert.dom('[data-test-file]').hasText('dingus.txt'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gossi Would writing await selectFiles(...)
and removing await waitFor(...)
help with the failing test in CI?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite see what you're trying to do here – but even locally for me the timing of this test seems unreliable.
When a file is selected and immediately uploaded the Queue.flush
method should run, but it all happens in a very short time.
Suspect glimmer is optimising for minimal renders and deciding not to update the DOM with every change here. I got it to pass more often by adjusting the timing of mirage but it still wasn't an acceptable pass rate.
Could you explain clearly what you're trying to test? You're checking rendered page state since you mention autotracking, yeah? Is there a simpler way to test this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I wanna test the "uploading" state and that the UI is reacting to that state change.
When doing await selectFiles()
this will be skipping over the uploading
state to whatever comes after. So, not awaiting this and waitFor()
the element that should pick up the UI change kinda seemed the way to go - and for what it's worth, it worked for the situations I used that. I also had tests, that weren't possible this way.
I also used a waiting timer in the BE (I used polly with a delay in our app code), that didn't worked at all, the waitFor()
was much more reliable than the timer. My very assumptive exaplanation is that the runloop is queuing those steps in and allows testing in that order, if they are very laboratory and an execution in this order can be guaranteed.
That said, I'm happily taking advice for this one. Maybe we can provide better test adapters? (for mirage and polly?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've used a timeout for this case here. Let's see if CI is happy with that. Also this is not a problem introduced as part of this PR, more that this PR uncovered this issue.
As a matter of that, I created an issue to discuss ideas for solving that in the future #641 and keep the scope of this PR to "make-the-CI-green"
Use regular constructor when creating UploadFile objects from File instances. Use UploadFile.fromBlob only when creating UploadFile objects from Blob instances. Make UploadFile.file property public.
3408969
to
335738c
Compare
Based on discussion in #316 - here is what I did:
Modernizations:
ember-cli-typescript
(not entirely, but for the key parts)Ember.A()
(on those files I touched with TS) in favor of@tracked
@ember/destroyables
(depending on support matrix, this requires to ship the polyfill)Changes:
{{file-queue}}
helper, which can be beautifully used like so:<FileUpload>
component and used new helper under the hood, rewired appropriatelyFileQueueService
can now work withDEFAULT_QUEUE
name (instead of super-global queue)Cutbacks:
ember-cli-addon-docs
(maybe it is time to move, ie. field-guide or docfy?)@onSelect
(couldn't rewire to the new API - I don't see this as an issue, the API was never public)Questions:
@TODO
in the code, some things I marked as removal/deprecation candidates or questions I haveWhat I didn't do (yet):
(file-queue uploadStarted=... upload=...)
orQueue.upload()
- where doesupload=()
need to be attached? To(file-queue)
orQueue
?Queue._addFiles()
- which is sooo ready to go 😅-> ALL THAT by keeping the TestSuite green - overall was pretty happy to manage backwards compatibility (that went way better than I thought !!). I also checked with our app, by linking this and let the app testsuite run, green as well.