Commit graph

232 commits

Author SHA1 Message Date
Renée Kooi
2b91a96c95
Release 2020-01-15 16:39:45 +01:00
Renée Kooi
1463ee79ce
Improve performance of adding and removing files (#1949)
* core: add an addFiles() method that only updates state once

Previously, adding 1300-ish files took around 260ms, and looked like
this in Firefox's performance tab:

![Flamegraph](https://i.imgur.com/08veuoU.png)

All of the downward peaks are `setState()` calls and GC.

Now it takes around 60ms, and looks like this:

![Flamegraph](https://i.imgur.com/xFdwVBV.png)

Here, most of the time is spent generating file IDs and guessing file
types. Those would be areas to look at next.

* dashboard: prevent frequent state update if nothing changed

After the last commit, `addFiles()` still spends a lot of time in
`emit()` and `hideAllPanels()`. The reason is that `addFiles()` still
emits all the hundreds of file-added events, and the Dashboard responds
to each with `hideAllPanels()`, which does a state update. But this all
happens synchronously, and the state almost certainly did not change
since the last `file-added` event that fired a millisecond ago.

This adds a check to avoid the state update if it is not necessary.

![Flamegraph](https://i.imgur.com/KhuD035.png)

Adding 1300 files takes about 40ms now.

With this change, the `addFiles()` call is no longer the slowest
part—now preact rendering all the items is!

* utils: optimize generateFileID and getFileNameAndExtension

Replaces some clever things with more mundane and faster things!

Now, generateFileID is a bunch of string concatenations.
Now, getFileNameAndExtension uses `lastIndexOf()` instead of a regex.

![Flamegraph](https://i.imgur.com/ZQ1IhxI.png)

Adding 1300 files takes about 25ms.

* dashboard: use preact-virtual-list

* thumbnail-generator: add `lazy` option

* dashboard: request thumbnails once file item renders the first time

* dashboard: fork preact-virtual-list

* core: add removeFiles() to remove files in bulk

* Implement removeFile() in terms of removeFiles()

* thumbnail-generator: only queue files that can be previewed

* rename size constants to accommodate WIDTH/HEIGHT

* Use new uppy.addFiles in DragDrop and FileInput

* utils: fix getFileNameAndExtension() type

* Rip out the lazy thumbnail generation

* Rip out virtualization.

* Remove virtualization leftovers

* tell future people that this is intentionally verbose

* Update package-lock.json

* henlo i am spell

* Make `addFiles()` respect maxNumberOfFiles

* core: show an informer error if some files fail in bulk add

* locales: fix quotes to make build:locale-pack happy

Co-authored-by: Artur Paikin <artur@arturpaikin.com>
2020-01-13 12:29:08 +01:00
Renée Kooi
18180d5778
Release 2019-12-16 12:53:23 +01:00
Alexis Hope
9abb4e2ba7 add event type (#1923)
* add event type

* event type literal union of string

* modify ts test for custom events and emit

* core: add comment about literalunion hack
2019-11-18 14:49:10 +01:00
Alexis Hope
23b8e820ea Add reset-progress event to docs (#1922)
* document reset-progress event

* reword progress reset behaviour

* remove totalProgress reference
2019-11-08 18:03:52 +03:00
Renée Kooi
c370dba0b6
Release 2019-11-04 10:56:06 +01:00
Artur Paikin
4e54483e61 core: setOptions for Core and plugins (#1728)
* Add a method to update options in Core

* Add a method to update options in Plugin (for any plugins)

* Allow re-initializing i18n locales after they’ve been updated with .setOptions

* use rest spread instead of Object.assign

* override setOptions in plugins to include i18nInit

* merge restrictions object in setOptions

* check that newOpts exists

* add spread ...

* don’t double merge

* add i18nInit to all plugins that use translation strings

* add setOptions tests to Core and Dashboard

* add setOptions docs for Core and Plugins

* fix tests for thumbnail-generator by adding plugins: {} to mock core

cause ThumbnailGenerator now calls this.setPluginState, which expects `core.state.plugins`

* also update meta with setOptions if it’s passed, change the way this.opts is set in core

@goto-bus-stop does this look ok? merging restrictions opts in core

* if locale was passed to setOptions(), call plugin.setOptions() on all plugins, so that i18n updates

* add Dashboard test that checks if locale is updated from Core via setOptions()

* Reafactor website Dashboard example to use setOptions and allow selecting a locale

🎉
2019-11-04 10:33:30 +01:00
Aaron Ross
44bcea6d03 add UppyFile.response typing (#1882)
* add UppyFile.response typing

* add some `file.response` type tests
2019-10-25 16:23:30 +02:00
Juliano
073937d512 fix: skip upload-success event for a file that has been removed (#1875)
* fix: skip upload-success event for a file that has been removed

* eslint --fix
2019-10-25 13:16:59 +02:00
Matthias Kunnen
ddb8f4e702 Allow passing meta type to upload-success and complete events (#1879) 2019-10-23 15:03:46 +02:00
Renée Kooi
b2f158e45e
Release 2019-10-14 16:43:19 +02:00
Renée Kooi
50bbeb0245
core: provide default error message (#1880)
We were already doing `if (file.error)` in places, now that is
guaranteed to work even if the error message was empty or the error
object is custom and doesn't have a `.message` property.
2019-10-11 16:42:40 +02:00
Renée Kooi
4e32e61d7c
Release 2019-10-09 21:00:46 +02:00
Renée Kooi
733de659da
Upgrade standard to v14 (#1860)
* Update eslint dependencies.

* standard --fix

* build: disable handler name lint rule

* status-bar: manually fix lint errors

* webcam: manually fix lint errors

* url: manually fix lint errors

* react-native: manually fix lint errors

* dashboard: manually fix lint errors

* informer: manually fix linting errors

* progress-bar: manually fix lint errors

* provider-views: manually fix lint errors

* redux-dev-tools: manually fix lint errors

* build: disable buggy no-unused-vars rule

* examples: manually fix lint errors

* ` quotes for code things, ' for text things
2019-10-09 14:53:02 +02:00
Ifedapo .A. Olarewaju
c67262028c
Merge branch 'master' into revoke-provider-access 2019-09-25 19:34:57 +01:00
Renée Kooi
bb8b66d918
Use more cancellation-friendly strategy for limit: N uploads (#1736)
* xhr-upload: redo limit option using different strategy

* xhr-upload: fix marking requests as done

* Move duplicate createEventTracker definitions to @uppy/utils

* tus: new cancellation for local uploads

* tus: fix cancelling queued uploads

* tus: fix wrong name

* aws-s3-multipart: smol refactor

* aws-s3-multipart: new cancellation style

* aws-s3: new cancellation

* utils: port limitPromises test to RateLimitedQueue

* timing fix?

* tus: new cancellation on websocket

* xhr-upload: implement cancellation for remote uploads

* aws-s3-multipart: port to new cancellation

* utils: remove limitPromises

* xhr-upload: remove pause/resume code

* xhr-upload: clean up event listeners

* xhr-upload: extract progress timer to separate class

* Move ProgressTimeout class to utils

* utils: update typings

* Fix lint

* tus: make pause/resume respect the rate limiting queue

* tus: try to explain some of the tricky things at play in the Tus#upload method

* aws-s3-multipart: add missing { abort: true }

* aws-s3-multipart: make pause/resume respect the rate limiting queue

* eslintrc.json - fixed eslint warnings for jsdoc

* Revert "eslintrc.json - fixed eslint warnings for jsdoc"

This reverts commit 50b24773ce.

* eslintrc.json - allow indentation in jsdoc comments

* xhr-upload: fix promise return value

* tus: fix promise return value

* tus: add missing `return () => {}`

* utils: typing export type fixes

* tus: add more jsdoc

* companion-client: add missing SocketOptions type

* utils: fix more export typings

* core,companion-client,tus: more typings tweaking

* companion-client: test fix 😩

* companion-client: add type for Socket#open

* tus: fix emit() call

* add local cancellation fuzz....ish? test
2019-09-25 15:21:17 +02:00
Artur Paikin
5f14ad576d Fix duplicate file test
failing because doing new File([sampleImage], { type: 'image/jpeg' }) twice resulted in a different lastModified
2019-09-20 19:31:25 +03:00
ifedapoolarewaju
c3fb49ee47
companion,companion-client,provider-views: revoke provider access on logout 2019-09-20 11:49:45 +01:00
Artur Paikin
e82ac0f137
core: Don’t add/overwrite existing files, allow duplicates from different folders (#1767)
* Add file.data.relativePath to the file.id

* Don’t add/overwrite a file if a file with the same id already exsists, issue a warning

* override @uppy/tus fingerprint to uppy’s file.id

* combine cordove/react native handling, don’t log twice

* always use onError for errors in addFile

* use file.meta.relativePath instead of file.data.relativePath

what do you think, @lakesare?

* update tests to include allowing/diallowing duplicates and file.id generation with relativePath

* update tus-js-client

* refactor error handling for addFile and upload into a mutual  _showOrLogErrorAndThrow method

* explain duplicate files and relativePath

* throw TypeError vs Error when allowedFileTypes is not an array

* fix tests

* tweak docs

* Emit restriction-failed for all restriction errors, move it to _showOrLogErrorAndThrow
2019-09-19 16:43:51 +03:00
Artur Paikin
056a7114a1 Release 2019-08-30 15:24:04 +03:00
Joe Duchnowski
17f862f2ac
Fix "Cannot read property 'log' of undefined" 2019-08-19 10:16:34 -04:00
Artur Paikin
ff7771b2cd
xhr-upload: Throw an error when trying to upload a remote file with bundle: true (#1769)
* Warn that we can’t bundle remote files when uploading in xhr-upload

* allow for `error` type logs in `onError` callback

* refactor error handling

* tweak error copy

* add Promise.reject

* throw always

* update docs to reflect that we now send global metadata with xhr, and that bundle: true is not possible with remote uploads
2019-08-16 18:38:54 +03:00
Renée Kooi
c62ec3665d Update eslint to v6 (#1777)
* Update eslint

* Do eslint --fix

* Do not access Object.prototype method 'hasOwnProperty' from target object

* utils: add hasProperty

* eslint --fix

* Disable quote-props for locale files

* add back quotes in locale files

* revert locale files to state on master

* Update react-scripts
2019-08-13 21:45:30 +03:00
Evgenia Karunus
21db40bb22
Merge pull request #1764 from transloadit/allowMultipleUploads-false-and-cancel
Made sure we can upload new files if we cancel last file (allowMultipleUploads: false)
2019-08-13 18:08:33 +05:00
Evgenia Karunus
8f36b116ea @uppy/core - avoid excessive setState() 2019-08-06 10:00:53 +02:00
Evgenia Karunus
8ac57c1ad8 Fix log duplication and excessive ResizeObserver log (#1747)
* everywhere - decorative changes

* /examples - fix duplicate logs in examples

* @uppy/dashboard - only fire the safety resize if we're not in a closed modal

* website/examples - made sure console.debug works in IE10
2019-08-05 15:16:10 +03:00
Evgenia Karunus
914f119a18 @uppy/core - made sure we can upload new files if we remove the last uploading file
(When allowMultipleUploads: false)
2019-08-03 09:15:47 +02:00
Renée Kooi
d05f37488d
core: use setFileState inside retryUpload (#1759)
Makes it a bit easier to follow. It also logs a warning now when you do
`.retryUpload(SomeNonsenseFileID)` instead of silently adding an invalid
object to the state.
2019-07-31 14:46:49 +02:00
Elio Capella Sánchez
ef2cf98de4 Improve addFile API (#1739)
* return file id of added files

* add documentation for returned value

* fix linting

* update test to new addFile API

* add docs for the change in the addFile API
2019-07-19 14:48:08 +02:00
Renée Kooi
10bc79574e
lerna link convert (#1730)
* lerna link convert

* ci: use npm ci

* update lockfile

* companion: set `bin` to source file

Since typescript doesn't actually transform anything, we can just use
this.

In a next major version we could set `noEmit: true` in the tsconfig and
stop publishing `lib`.

* companion: do chmod +x on start-server.js

* build: remove obsolete lerna config

* build: explicitly install latest versions when building e2e tests for ci

* Remove versions from private packages

* fix regex

* try fix

* ci: force npm to install to endtoend folder

* ci: fold up e2e build output

* Update netlify deploy preview command

* Remove mentions of npm run bootstrap

* Edit .github/CONTRIBUTING.md instead

* companion: add proxy executable

* companion: fix publish

* Downgrade jest to appease create-react-app
2019-07-19 12:16:36 +02:00
Artur Paikin
bd2beedcff Release 2019-07-18 17:21:42 +02:00
Artur Paikin
b3902a1dfc
provider-views: Select 5 files --> Select 5, because there are also folders (#1697)
* Select 5 files --> Select 5, because there are also folders

not ideal, but better

* selectXFiles --> selectX

* update selectX in all locales

* Update fi_FI.js
2019-07-18 14:42:38 +02:00
Artur Paikin
dc4e982280 remove prettier-bytes from dependencies, follow up for #1732 2019-07-17 19:53:14 +02:00
Renée Kooi
b42f904f2b core: adjust ID generation to keep non-latin characters (#1722)
* core: add test for ID generation with non-latin names

* core: adjust ID generation to keep non-latin characters

This shouldn't be bc-breaking!

Now, non-latin characters are encoded as their charcode in base 32, so
files that only differ by name in a non-latin language will generate
different IDs.
2019-07-17 16:12:51 +02:00
Artur Paikin
7873f057ca
utils: prettyBytes 1000 --> 1024 (#1732)
* Replace prettier-bytes with its copy, only use 1024 instead of 1000 to justify KB vs kB

* Add tests

* added License

* pretty-bytes to @uppy/utils/lib/prettyBytes everywhere
2019-07-16 15:21:47 +02:00
Artur Paikin
6b173d8c78
core: Restrictions improvements (#1726)
* Set file.type before calling onBeforeFileAdded, throw in upload so .catch works, emit restriction-failed for minNumberOfFiles, too

We must throw in upload onError, otherwise .catch won’t catch

* It seems startUpload is not used in Dashboard, used in StatusBar instead

probably a leftover from before StautsBar became a standalone plugin

* only log non-restriction errors

* throw early if restrictions.allowedFileTypes is not an array

* flip condition: do emit the event if err.isRestriction
2019-07-15 14:10:04 +02:00
Evgenia Karunus
70acbf7861 Adjust i18n (#1712)
* @uppy/locales - updated Nl translation as per Kevin

* @uppy/provider-views - moved all translations to Core, removed dependency on Dashboard

* @uppy/locales - added missing translations for 'Add more'
2019-07-12 18:04:42 +02:00
Evgenia Karunus
e72c305e0a
Merge pull request #1701 from transloadit/add-pretty-focus-styles-everywhere
Added focus styles for all elements
2019-07-07 19:51:51 +02:00
Artur Paikin
e1f416d019
core: Add an option to supply logger with debug, warn and error methods (#1661)
* Add an option to supply customLogger that will receive message and type from uppy.log

* Always use logger function, set to nullLogger by default

Co-Authored-By: Renée Kooi <github@kooi.me>

* add tests for logging and not logging with a function and debug: true

* Update packages/@uppy/core/src/loggers.js

account for `debug` not being available in IE10

Co-Authored-By: Renée Kooi <renee@kooi.me>

* add .call

* fix tests

* expose Uppy.debugLogger

* document logger

* core cleanup

* add logger to defaultOptions in docs too

* debug: true — only override logger if it has not been set in opts
2019-07-05 20:12:43 +02:00
Renée Kooi
8485fec03a
Progress fixes for unsized files (#1610)
* core: consistently use round() for progress calculations

* core: fix the estimated size for unsized files
2019-07-05 15:59:26 +02:00
Evgenia Karunus
f88b0c5bc1 Add translations for aria labels in provider views (#1696)
* @uppy/provider-views - added translations for aria-labels

* @uppy/locales - added translations for provider views
2019-07-05 15:37:13 +03:00
Evgenia Karunus
bbf0b33bcb everywhere - added focus styles for every element 2019-06-29 09:02:08 +05:00
Artur Paikin
5e35987079
Log error in uppy.addFile try/catch (#1680)
* Log error in uppy.addFile try/catch

* Add `.isRestriction` to a custom RestrictionError, check for that before logging

* keep throwing for robodog.upload

//cc @goto-bus-stop
2019-06-28 20:25:17 +03:00
Alexander Zaytsev
3b4547fa2c More design improvements (#1574)
* Better focus styles

* Improve focus on the remove button

* "Add more" caption to the "+" button (todo: i18n)

* Add i18n (todo: check)

* Fix icon size

* Try removing file source (todo: remove icons)

* Simplify caption

* Revert "Try removing file source (todo: remove icons)"

This reverts commit 20c5ecb554.

* (WIP) Use icons for Edit / Copy link actions

* Class names optimizing

* Subtle shadows

* Optimize code, align action icons on smaller screens

* Reduce Tab-btn horizontal padding on mobile

* Fix padding

* i18n

* replace arabic with persian

* initial refactor

* primarily FileItem's css - reintegrated Alex's changes

* @uppy/dashboard - unnested subcomponents from ./components

* @uppy/dashboard scss - added some spacing as per conventions

* @uppy/dashboard - changed behaviour of truncateString() to always return a predictable number of symbols

* @uppy/dashboard - subdivided FileItem.js and its css into smaller files

Removed unused css classes, made filenames avoid overflow

* @uppy/dashboard - removed unused .currentWidth prop, FileItem.js - made fileName take up at most 2 lines

* test:endtoend:prepare-ci - fix test by reordering locale lines

* @uppy/dashboard - decorative FileItem.js changes

* @uppy/dashboard - made css of FileItem.js more flat

* @uppy/Dashboard - in FileItem.js made max filename length 30 symbols

* fix image getting width: 100% in DashboardFileCard

//cc @lakesare

* FileItem.scss - removed tagnames
2019-06-28 15:20:04 +03:00
Artur Paikin
81a45a01ed eslint jsdoc fixes 2019-06-25 18:27:48 +03:00
Renée Kooi
a6d3132848
core: make meta.name not required in addFile() (#1629) 2019-06-19 10:34:58 +02:00
Andrew Shini
01da52ae22 Check for existing upload (#1367)
* Check for currentUpload

* Update comment
2019-06-17 14:35:50 +02:00
Artur Paikin
9c2bcc8df8
core: Log versions of Uppy plugins for debugging (#1640)
* Log Core’s version in constructor, log each plugin’s version in .use()

* Check that Plugin.VERSION exists before logging it

* Log which DOM element we are mounting to
2019-06-12 21:04:38 +03:00
Evgenia Karunus
6bcf2040e9 Feature/accessibility (#1507)
* @uppy/provider-views - added accessibility

* @uppy/provider-views - simplified checkbox css

* @uppy/dashboard - on tab set focus to the current verlay

* @uppy/dashboard - factored out code related to focus into a separate file

* @uppy/dashboard, and connected plugins - made focus travel well, and be managed in a single place in Dashboard

* @uppy/dashboard - made modal opener button focus keep focus on modal close

* @uppy/dashboard - focus management for uploaded-files

* @uppy/dashboard - made informer read messages without interruption

* @uppy/provider-views - removed the bug of focus jumping on safari

* @uppy/dashboard - made focus travel well in instagram in firefox

* @uppy - moved lodash.debounce dependency from / to @uppy/dashboard

* everywhere - made <ul>s not focusable for firefox

* @uppy/provider-views - unnested scss, copypasted alex's :focus changes

* Added JSDoc eslint package and rules, and fixed some JSDoc comments

* .eslintrc - made jsdoc errors warnings instead

* package-lock.json for new package.json

* eslint fix

* @uppy/dashboard - avoid forcing focus when we are inline

* @uppy/dashboard - in firefox, made sure superfocus is not switching back to uppy

* @uppy/dashboard - no focus jump for .info() inline,  fix for firefox

Made focus not interrupt .info() when we are in the inline mode;
Made firefox start superfocusing when we either tab into, or click on some element in Uppy

* @uppy/dashboard - only listen to click/focus on uppy

* @uppy/dashboard - started trapping focus in inline mode too

* @uppy/dashboard - restricted trapFocus() event listener to this.el

* @uppy/core - started throttling progress emits.

1. To fix heat up in firefox
2. To fix focus in firefox

* @uppy/core - fixed tests by adding .flush()-s for progress emits

* @uppy/dashboard - stopped trapping focus in inline mode, made background inert

* @uppy/dashboard - added MutationObserver polyfill

* tests - made locale-packs.js pass

* REVERTED last 3 commits that introduced inert

Inert requires too many polyfills, atm tests fail in IE 10.0, wicg-inert library reportedly has performance issues. We decided to at least wait until _some_ browser introduce inert html property natively.

* @uppy/dashboard - IE11 fix for focusing

* @uppy/dashboard - fix for a bug in Safari for long uploads with checkbox clicking

* RERUN TESTS - tiny commit to rerun tests

* @uppy/dashboard - removed useless touchstart event listener

* Cancel superFocus in recordIfFocusedOnUppyRecently, when focus moves away from Uppy

* @uppy/provider-views - made Filter not swallow letters

* @uppy/dashboard - stopped superfocus from refocusing if we're already in the overlay
2019-06-11 19:10:32 +03:00
Jan Klimo
03c3c5b1e9 Enable partial assignment of restrictions passed as options (#1654) 2019-06-11 14:19:10 +02:00