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

Add @uppy/remote-sources preset/plugin #3676

Merged
merged 24 commits into from Jun 7, 2022
Merged

Add @uppy/remote-sources preset/plugin #3676

merged 24 commits into from Jun 7, 2022

Conversation

arturi
Copy link
Contributor

@arturi arturi commented Apr 29, 2022

With the new preset / after:

import Uppy from '@uppy/core'
import Dashboard from '@uppy/dashboard'
import RemoteSources from '@uppy/remote-sources'
import Webcam from '@uppy/webcam'
import Audio from '@uppy/audio'
import ScreenCapture from '@uppy/screen-capture'
import ImageEditor from '@uppy/image-editor'
import Compressor from '@uppy/compressor'
import Transloadit from '@uppy/transloadit'

const uppy = new Uppy()
  .use(Webcam)
  .use(Audio)
  .use(ImageEditor)
  .use(ScreenCapture)
  .use(Compressor)
  .use(Dashboard)
  .use(RemoteSources, { companionUrl: COMPANION_URL })
  .use(Transloadit, { waitForEncoding: true })

Without the new preset / before:

import Uppy from '@uppy/core'
import Dashboard from '@uppy/dashboard'
import Instagram from '@uppy/instagram'
import Facebook from '@uppy/facebook'
import OneDrive from '@uppy/onedrive'
import Dropbox from '@uppy/dropbox'
import Box from '@uppy/box'
import GoogleDrive from '@uppy/google-drive'
import Unsplash from '@uppy/unsplash'
import Zoom from '@uppy/zoom'
import Url from '@uppy/url'
import Webcam from '@uppy/webcam'
import ScreenCapture from '@uppy/screen-capture'
import Transloadit from '@uppy/transloadit'
import ImageEditor from '@uppy/image-editor'
import Audio from '@uppy/audio'
import Compressor from '@uppy/compressor'

const uppy = new Uppy()
  .use(Webcam)
  .use(Audio)
  .use(ImageEditor)
  .use(ScreenCapture)
  .use(Compressor)
  .use(Dashboard)
  .use(GoogleDrive, { target: Dashboard, companionUrl: COMPANION_URL })
  .use(Instagram, { target: Dashboard, companionUrl: COMPANION_URL })
  .use(Dropbox, { target: Dashboard, companionUrl: COMPANION_URL })
  .use(Box, { target: Dashboard, companionUrl: COMPANION_URL })
  .use(Facebook, { target: Dashboard, companionUrl: COMPANION_URL })
  .use(OneDrive, { target: Dashboard, companionUrl: COMPANION_URL })
  .use(Zoom, { target: Dashboard, companionUrl: COMPANION_URL })
  .use(Url, { target: Dashboard, companionUrl: COMPANION_URL })
  .use(Unsplash, { target: Dashboard, companionUrl: COMPANION_URL })
  .use(Transloadit, { waitForEncoding: true })

Copy link
Member

@Murderlon Murderlon left a comment

Choose a reason for hiding this comment

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

I know it's WIP but there still needs to be a way to pass options. I think (hope) that all remote plugins share the exact same options.

packages/@uppy/remote-sources/README.md Outdated Show resolved Hide resolved
packages/@uppy/remote-sources/types/index.d.ts Outdated Show resolved Hide resolved
@arturi
Copy link
Contributor Author

arturi commented May 2, 2022

I know it's WIP but there still needs to be a way to pass options. I think (hope) that all remote plugins share the exact same options.

As far as I know, the only option for remote sources is companionUrl, is there something I'm missing?

@Murderlon
Copy link
Member

As far as I know, the only option for remote sources is companionUrl, is there something I'm missing?

All these options and the ones in other docs.

@arturi arturi marked this pull request as ready for review May 26, 2022 19:55
@arturi arturi requested review from Murderlon and aduh95 May 26, 2022 19:55
.eslintrc.js Outdated Show resolved Hide resolved
packages/@uppy/remote-sources/README.md Outdated Show resolved Hide resolved
packages/@uppy/remote-sources/src/index.js Outdated Show resolved Hide resolved
packages/uppy/index.mjs Outdated Show resolved Hide resolved
.eslintrc.js Show resolved Hide resolved
packages/@uppy/remote-sources/package.json Show resolved Hide resolved
packages/@uppy/remote-sources/src/index.js Outdated Show resolved Hide resolved
packages/@uppy/remote-sources/src/index.js Outdated Show resolved Hide resolved
Comment on lines 67 to 70
this.opts.sources.forEach((pluginName) => {
const plugin = this.uppy.getPlugin(pluginName)
this.uppy.removePlugin(plugin)
})
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't be worried that this.opts.sources can be modified by the user and the uninstall would not work correctly? Another (better?) way of handling it would be to have a private Set on the instance that caches all the plugins that were installed.

Suggested change
this.opts.sources.forEach((pluginName) => {
const plugin = this.uppy.getPlugin(pluginName)
this.uppy.removePlugin(plugin)
})
this.#installedPlugins.forEach(plugin => this.uppy.removePlugin(plugin))
this.#installedPlugins.clear()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it sounds better, not sure if Set is required or just a private array. But I did think of this, if you modify options the correct way via uppy.getPlugin('RemoteSources').setOptions({ sources: ['Instagram'] }), the plugin will first uninstall everything, then update options and install back: https://github.com/transloadit/uppy/pull/3676/files#diff-3b90938b025125a702e11b69f66acdd0c6985a892f64f4a28b06f0dcdb24e873R51-R55

Copy link
Member

Choose a reason for hiding this comment

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

I think we should not assume that users will always use the correct way.

const sources = ['Instagram']
uppy.use(RemoteSources, { sources })

sources.pop() // The user mutates the array for some reason

uppy.getPlugin('RemoteSources').uninstall() // The Instagram plugin is still installed

I think Set is more suited for our use case, but I suppose an array would also work.

arturi and others added 3 commits May 30, 2022 11:53
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
.use(Tus, {
endpoint: 'https://tusd.tusdemo.net/files',
onShouldRetry,
retryDelays: [2000, 3000, 4000],
Copy link
Member

Choose a reason for hiding this comment

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

That looks unrelated, can we put it in its own PR (or remove it)

Comment on lines 32 to 37
cy.intercept(
{ method: 'PATCH', pathname: '/files/*', times: 2 },
{ method: 'PATCH', pathname: '/files/*', times: 1 },
{ statusCode: 429, body: {} },
).as('patch')

cy.wait('@patch')
cy.wait('@patch')
Copy link
Member

Choose a reason for hiding this comment

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

Same here

@arturi arturi requested a review from aduh95 June 1, 2022 17:00
@arturi
Copy link
Contributor Author

arturi commented Jun 1, 2022

@aduh95 please take another look, cause I’m not sure what I’m doing with Set() 🙏

packages/@uppy/remote-sources/src/index.js Outdated Show resolved Hide resolved
packages/@uppy/remote-sources/src/index.js Outdated Show resolved Hide resolved
Comment on lines 61 to 63
const optsForRemoteSourcePlugin = { ...this.opts, sources: undefined }
const plugin = availablePlugins.find(p => p.name === pluginId)
this.uppy.use(plugin, optsForRemoteSourcePlugin)
Copy link
Member

Choose a reason for hiding this comment

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

We could have a more useful error message here (maybe it'd be worth having a unit test btw?)

Suggested change
const optsForRemoteSourcePlugin = { ...this.opts, sources: undefined }
const plugin = availablePlugins.find(p => p.name === pluginId)
this.uppy.use(plugin, optsForRemoteSourcePlugin)
const plugin = availablePlugins.find(p => p.name === pluginId)
if (plugin == null) {
const formatter = new Intl.ListFormat('en', { style: 'long', type: 'disjunction' });
throw new Error(`Invalid plugin name: "${pluginId}" is not one of ${formatter.format(availablePlugins)}.`)
}
this.uppy.use(plugin, { ...this.opts, sources: undefined })

Comment on lines 89 to 91
sources: ['Box', 'Dropbox', 'Webcam', 'Facebook', 'GoogleDrive', 'Instagram', 'OneDrive', 'Unsplash', 'Url'],
})
.use(Webcam, {
Copy link
Member

Choose a reason for hiding this comment

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

Is it expected that Webcam is both in RemoteSources and as standalone?
Also, optional nit, can we sort the list to be in alphabetical order.

packages/@uppy/remote-sources/src/index.js Outdated Show resolved Hide resolved
private/dev/Dashboard.js Outdated Show resolved Hide resolved
tagline: "Uppy plugin that includes all remote sources that Uppy+Companion offer, like Instagram, Google Drive, Dropox, Box, Unsplash, Url etc"
---

Remote Sources plugin makes it convinient to add all the available remote sources — Instagram, Google Drive, Unsplash, Url, etc — to Uppy Dashboard in one convinient package.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Remote Sources plugin makes it convinient to add all the available remote sources — Instagram, Google Drive, Unsplash, Url, etc — to Uppy Dashboard in one convinient package.
@uppy/remote-sources is a preset plugin to add all the available remote sources, such Instagram, Google Drive, Dropbox, and others to Uppy Dashboard in one package.

})
```

You can possible to control which plugins will be used and the order they appear in the Dashboard, see below for `sources` option. All Companion-related options, such as `companionUrl`, are passed to the underlining plugins.
Copy link
Member

Choose a reason for hiding this comment

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

I think this sentence is redundant (it also has quite a few typos) as it just says 'hey we also have these two options' but you can also see that below in more detail

Suggested change
You can possible to control which plugins will be used and the order they appear in the Dashboard, see below for `sources` option. All Companion-related options, such as `companionUrl`, are passed to the underlining plugins.

Comment on lines 47 to 48
* Type: `string`
* Default: `RemoteSources`
Copy link
Member

Choose a reason for hiding this comment

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

Could you align all of these with how I have been doing this in the new website? It would save me a rewrite.

The format is:

[one sentence explanation] ([type], Default: [default])

Example:

Render the Dashboard as a modal or inline (`Boolean`, default: `false`).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I like your way, just did this for consistency with the current docs.

arturi and others added 4 commits June 7, 2022 14:08
@arturi
Copy link
Contributor Author

arturi commented Jun 7, 2022

All feedback addressed, I think this is ready to be merged.

@aduh95 aduh95 merged commit 9a59711 into main Jun 7, 2022
@aduh95 aduh95 deleted the remote-sources branch June 7, 2022 16:56
@github-actions github-actions bot mentioned this pull request Jun 7, 2022
github-actions bot added a commit that referenced this pull request Jun 7, 2022
| Package                | Version | Package                | Version |
| ---------------------- | ------- | ---------------------- | ------- |
| @uppy/aws-s3           |   2.2.1 | @uppy/tus              |   2.4.1 |
| @uppy/aws-s3-multipart |   2.4.1 | @uppy/url              |   2.2.0 |
| @uppy/companion-client |   2.2.1 | @uppy/xhr-upload       |   2.1.2 |
| @uppy/core             |   2.3.1 | @uppy/robodog          |   2.8.0 |
| @uppy/react            |   2.2.2 | uppy                   |  2.12.0 |
| @uppy/remote-sources   |   0.1.0 |                        |         |

- @uppy/remote-sources: Add @uppy/remote-sources preset/plugin (Artur Paikin / #3676)
- @uppy/react: Reset uppy instance when React component is unmounted (Tomasz Pęksa / #3814)
- @uppy/aws-s3-multipart,@uppy/aws-s3,@uppy/tus: queue socket token requests for remote files (Merlijn Vos / #3797)
- @uppy/xhr-upload: replace `ev.target.status` with `xhr.status` (Wes Sankey / #3782)
- @uppy/core: fix `TypeError` when file was deleted (Antoine du Hamel / #3811)
- @uppy/robodog: fix linter warnings (Antoine du Hamel / #3808)
- meta: fix GHA workflow for prereleases (Antoine du Hamel)
- @uppy/aws-s3-multipart: allow `companionHeaders` to be modified with `setOptions` (Paulo Lemos Neto / #3770)
- @uppy/url: enable passing optional meta data to `addFile` (Brad Edelman / #3788)
- @uppy/url: fix `getFileNameFromUrl` (Brad Edelman / #3804)
- @uppy/tus: make onShouldRetry type optional (Merlijn Vos / #3800)
- doc: fix React examples (Antoine du Hamel / #3799)
- meta: add GHA workflow for prereleases (Antoine du Hamel)
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.

None yet

3 participants