Commit graph

184 commits

Author SHA1 Message Date
Renée Kooi
6b63325035
core: do not create an upload in retryAll() if there were no errors (#2361)
fixes #2298
2020-07-13 18:33:45 +02:00
Artur Paikin
eab4ddd55c Add reason argument to removeFiles 2020-06-24 18:27:19 +01:00
Artur Paikin
68f36b1ac2
Refactor FileProgress component (#2303)
* refactor FileProgress component; pass hideCancelButton, hidePauseResumeButton and hideRetryButton

* move icons to where they are rendered, rename UppyIcon to uppy-u-icon

* cleanup: rename DashboardItem, remove xmlns

* update docs to specify the option also hides action button on each individual file
2020-06-06 04:10:01 +02:00
Renée Kooi
811d763e16
core: add some more suggestions to the incorrect target warning (#2242) 2020-05-15 20:41:39 +02:00
Kevin van Zonneveld
803611ed04
Move @uppy/utils/lib/prettyBytes -> @transloadit/prettier-bytes (#2231)
* Move @uppy/utils/lib/prettyBytes -> @transloadit/prettier-bytes so we can more easily re-use it across projects

* Switch to MIT licensed @transloadit/prettier-bytes

* lockfile fun

* build: add dep for website/inject.js

Co-authored-by: Renée Kooi <renee@kooi.me>
2020-05-07 16:54:13 +02:00
Alexander Zaytsev
57da3a5a80
Dark mode design improvements (#2232)
* Modify highlight/link color

* Paler dashed outline

* Simpler input focus

* Tweak statuses' gray

* Tweak & fix :focus colors

* Swap TabBtn hover/focus colors

* Tweak dark focus outline

* Darker actionBtn

* Webcam button support

* Add isDraggingOver support

* Add ScreenCapture support

* ProviderBrowserItem-inner support

* Better fakeCheckbox support
2020-05-05 18:02:24 +02:00
Artur Paikin
53138f48f8 move from white to off-white 2020-04-24 09:17:37 +02:00
Artur Paikin
ed8a494875
Mark network errors as NetworkError (#2110)
* Add NetworkError error type and isNetworkError utility check

* Detect network errors in tus and xhr-upload

Co-Authored-By: Ifedapo .A. Olarewaju <ifedapoolarewaju@gmail.com>

* add NetworkError check to RequestClient in companion-client

* return false if !xhr 🙈

* move catch so that only errors from _checkMinNumberOfFiles are caught — errors from uploads are logged in `upload-error` already

//cc @goto-bus-stop

* Add NetworkError to MiniXHRUpload in aws-s3

//cc @goto-bus-stop

* Add tests

//cc @ifedapoolarewaju

* pass xhr to NetworkError

* add logging in catch of uppy.upload()

* start error message with “This looks like a network error”

* originalRequest --> request, return NetworkError right away

* check for NetworkError in `delete` as well

do we need it in preflight too, @ifedapoolarewaju?

* remove redundant error message re-declaration

* _showOrLogErrorAndThrow, but don’t showInformer

Co-authored-by: Ifedapo .A. Olarewaju <ifedapoolarewaju@gmail.com>
2020-04-21 10:36:49 +02:00
Renée Kooi
ab76448508
aws-s3: handle upload internally instead of deferring to xhr-up… (#2060)
* aws-s3: handle actual upload internally instead of deferring to XHRUpload

* aws-s3: add a comment explaining the mess

* aws-s3: move XHRUpload code into a separate class

* utils: support prioritization in rate limiting queue

* aws-s3: remove old implementation

* core,status-bar: account for pre/postprocessing files in progress calculations

* changelog: add entry for this PR

* utils: Support cancellation in `RateLimitedQueue#wrapPromiseFunction`

* s3: remove preprocessing stage, only use upload-* events

* utils: remove console.log

* aws-s3: comment out duplicate `upload-started`

* xhr-upload: reorder `ProgressTimeout` creation for readability

* aws-s3: apply 7d972e0 to MiniXHRUpload

* aws-s3: apply 4ed7508 to MiniXHRUpload
2020-04-06 13:53:21 +02:00
Artur Paikin
5079d98584
dashboard: 2020 redesign 🍿 (#2015)
* ProviderViews: Improve Instagram’s “video thumbnail”

* Update all provider icons to nicer round ones

* Change “drop files” copy depending on number of acquirers and Dashboard width

* Translator: support multiple components in options

When the source contains multiple placeholders for interpolation, we should ignore chunks that are not strings, because those can be JSX objects and will be otherwise incorrectly turned into strings.

Without this condition we’d get this: [object Object] hello [object Object] my <button>

* Remove unused locale strings

* Rever renderSingleInlineProvider, use Browse button instead of link, tweak styles

* Try “Browse My Device” button

* Introduce “Dark Mode“: new Dashboard option 'theme': 'light', 'dark' or 'auto'

* Refactor to also add uninstall/removeListener for the darkModeMediaQuery; remove all bindings in favor of class properties

* More dark mode styles: Providers, FileCard, tweaking focus, inputs, etc

* My Device: mobile and desktop icons

* add isMobileDevice capability, very simple detection

* More dark mode styles

* refactor

* switch back to single simple my device icon

* chrome 78 for android doesn’t support document.querySelector 👌

* nobr --> span white-space: nowrap

* Major style tweaks for mobile provider list, show dashed borders only when DnD is supported

* Add color after “import from”

just for Russian for now, because I’m thinking if this should be a part of the language string or html? @goto-bus-stop @kvz, what do you think?

* improve isMobileDevice, add tests

* don’t set the isMobileDevice capability in core for now

* add checks for typeof window !== 'undefined', otherwise fails in Node/RN

* update locales

* refactor renderDropFilesSubtitle
2020-03-24 18:05:11 +01:00
Artur Paikin
f4497838da
Only _startIfAutoProceed if some files were actually added (#2146) 2020-03-21 11:03:56 +01:00
Renée Kooi
5e25b2a939
Fix translations that did not respect word order (#2077)
* Fix translations that did not respect word order

Fixes #2069

We were still using raw string concatenation in these two places. To
maintain backwards compatibility, this commit adds _new_ translations
that are substitution-based instead of concatenation-based. The old
translation is passed in as a possible substitution parameter
`backwardsCompat`, and the default (English) translations use this
parameter.

With this, if you are using a custom locale that overrides eg. the
`exceedsSize` string, Uppy will first get your `exceedsSize`
translation, and then use the default `exceedsSize2` translation which
concatenates that result and the file size. So it works the same as it
did in the past.
If a translation requires a different word order, it can override the
`exceedsSize2` translation instead.
```js
new Uppy({
  locale: {
    strings: {
      exceedsSize2: 'Maximum file size of %{size} exceeded',
      poweredBy2: '%{uppy} made this!'
    }
  }
})
```

In 2.0, we can remove all the old strings and only use `poweredBy2` (and
probably rename them to `poweredBy` too, heh)

* website: add missing dashboard strings to docs

* locales: remove unused second plural form from EN and NL

* build: allow different numbers of plural forms

* utils: add test for new throwing behaviour

* docs: insert PR url

* locales: revert ko_KR changes

* changelog: add 2.0 backlog entry

* locales: var → const

* docs: add brief note that translators should supply a pluralize function

* locales: update en_US with new template

* fix HEIGHT_MD = 400

Co-authored-by: Artur Paikin <artur@arturpaikin.com>
2020-03-19 14:41:14 +01:00
Artur Paikin
856243a149
core, transloadit: Allow new uploads when retrying; improve error handling (#1960)
* Set `allowNewUpload: true` when an error occurs to allow retryAll

* Add assembly error message and assembly_id

* Pass debug option to Robodog

* Add forceAllowNewUpload to use in retry and retryAll, improve calls to _showOrLogErrorAndThrow

* Capitalize Create Assembly message

* don’t throw error from 'upload-error' event,  improved error message structure

* handle errors better

* check if error.details exists

* Doc tweaks: added error.assembly
2020-02-11 17:06:33 +01:00
Artur Paikin
d0f181caeb
core: Add noNewAlreadyUploading and noDuplicates (#2057)
* Add noNewAlreadyUploading and noDuplicates

* Update en_US.js

* fix test

* Update index.js

* Update en_US.js
2020-02-10 14:54:40 +01:00
Mohammed Shahim
6bef0a0314
Fix mime type checking bug (#2004)
* fix for mimetype issue #1988

* core: disregard mime parameters

Co-authored-by: Renée Kooi <renee@kooi.me>
2020-02-05 12:17:34 +01:00
Artur Paikin
d385d2c84e
Clear state error after the last file is removed (#2041) 2020-02-03 13:07:47 +03:00
Artur Paikin
1ea950d5d2
core: Always log errors (#2029)
* Show errors in logs always. nullLogger --> justErrorsLogger

Reasoning: too often we ended up showing errors in the Informer bubble, but not in the console, which is wrong and annoying. Devs still have an option to silence logs or direct them elsewhere by setting a custom logger

* Hide pause/resume buttons when error occures

* Update tests

* Update website/src/docs/uppy.md

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

Co-authored-by: Renée Kooi <renee@kooi.me>
2020-01-28 18:45:23 +03:00
Artur Paikin
7eda2346a8
core: setState(modifiedFiles) in onBeforeUpload (#2028)
* Updating files in state, too, because uploader plugins receive file IDs only, not actual files

* Update doc examples with simpler spread syntax
2020-01-20 15:33:38 +03: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
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
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
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
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
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
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
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
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
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