Skip to content
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

Fix/on before file added not called #1597

Merged
merged 5 commits into from
May 31, 2019
Merged

Conversation

lakesare
Copy link
Contributor

@lakesare lakesare commented May 24, 2019

Small refactoring of the <AddFiles/> (to avoid repeating the fix for hidden inputs in multiple files),
and fixes #768.

renderPoweredByUppy () {
return <a tabindex="-1" href="https://uppy.io" rel="noreferrer noopener" target="_blank" class="uppy-Dashboard-poweredBy">
{this.props.i18n('poweredBy')}
<svg aria-hidden="true" class="UppyIcon uppy-Dashboard-poweredByIcon" width="11" height="11" viewBox="0 0 11 11">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spacing between “powered by” text and “Uppy” with icon is gone, adding something like {' '} should fix it, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-o Yes

}

renderAcquirer (acquirer) {
return <div class="uppy-DashboardTab" role="presentation">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: since you’ve refactored this (thanks!), could we add () after all of the return statements, maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arturi, let's, but let's add eslint rules for these cases?
I also see both lowercase props (e.g. onpaste) and camelCase (onPaste) used interchangeably, that's something that's nice to have handled by eslint.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good idea about eslint for those. But maybe in a separate PR after accessibility and Alex’s PRs are merged? Cause we’ll need to touch everything with strict rules.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

type="file"
name="files[]"
multiple={this.props.maxNumberOfFiles !== 1}
// Clear file input
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add that setting an empty value="" wasn’t enough, and we are doing this to fix onBeforeFileAdded? Not sure, but might be helpful in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arturi, agreed, I'll add it.

Copy link
Contributor

@arturi arturi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks. Left some minor comments.

Another issue is that this addresses Dashboard, while the issue is talking about FileInput, and DragDrop probably has the same issue? So we need this change across all 3 plugins, right?

If needed, we can merge the DragDrop PR first, if you anticipate conflicts there.

@lakesare
Copy link
Contributor Author

@arturi, good note, I could handle these:

  1. make whole Drag n Drop clickable (Is it possible to make the whole Drag n Drop clickable, instead of just the browse text? #1593)
  2. fix onBeforeFileAdded() not called twice issue
  3. onPaste
    All in one commit.

Will you check /feature/accessibility today?
/drag-drop PR isn't stifled by that PR, only package-lock.json will conflict, so if we anticipate some more work on accessibility, - I'll make /drag-drop mergeable today, and maybe add these features to that PR.

@arturi
Copy link
Contributor

arturi commented May 27, 2019

Ideally we handle onBeforeFileAdded() here, maybe after the DnD PR is merged, so there are no conflicts, while onPaste and “make whole Drag n Drop clickable” could be added to DnD PR?

@lakesare
Copy link
Contributor Author

lakesare commented May 27, 2019

Ideally we handle onBeforeFileAdded() here, maybe after the DnD PR is merged,

I think it's a small enough change for conflicts to not arise, I'll add it.

@arturi
Copy link
Contributor

arturi commented May 29, 2019

Could you update the FileInput plugin too, please?


// ___Why not use value="" on <input/> instead?
// Because if we use that method of clearing the input, Chrome will not trigger onChange={} if we drop the same file twice (Issue #768).
event.target.value = null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We pass ev to the callback, but event works anyway. What sort of sorcery is this? 🙀 Been trying to find documentation for a while, nothing so far.

Copy link
Contributor

@goto-bus-stop goto-bus-stop May 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a (very old) global property: https://developer.mozilla.org/en-US/docs/Web/API/window/event

It allows you to refer to the event in an inline on* event handler attribute, eg <input onclick="event.target.value = undefined">

best not to rely on it :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, thanks! Crazy. A thought about it being global occurred to me briefly when eslint didn’t complain.

Is it safe to call the callback argument event: (event) => { ... }? Thus overriding this global event.

Copy link
Contributor Author

@lakesare lakesare May 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't fucking notice! It wasn't intentional, I'm amazed it worked too.
Eslint usually catches undeclared variables, we seem to be having a very lenient configuration? I also noticed it doesn't tell me what class methods are not used.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it safe to call the callback argument event: (event) => { ... }? Thus overriding this global event.

yes

i'm also surprised that this isn't caught, I thought standard has a no-confusing-globals rule or something, may need to look into that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Standard includes this http://eslint.org/docs/rules/no-undef, couldn’t figure out why that wouldn’t work yet.

There is another rule we could add, it’s talking about event specifically: https://eslint.org/docs/rules/no-restricted-globals

@arturi
Copy link
Contributor

arturi commented May 30, 2019

Pushed a change for FileInput, updated comments and changed ev to event for consistency, hope it’s ok.

Could you check that it works on your end again, please?

@lakesare
Copy link
Contributor Author

Looks good, works for Dashboard, DragDrop and FileInput.

@lakesare lakesare merged commit 87b64a1 into master May 31, 2019
@lakesare lakesare deleted the fix/onBeforeFileAdded-not-called branch May 31, 2019 05:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

onBeforeFileAdded callback issue
3 participants