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
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ac1f5df
Add @uppy/remote-sources preset/plugin
arturi Apr 29, 2022
04dd8c7
yarn.lock
arturi Apr 29, 2022
3fd0002
Update packages/@uppy/remote-sources/README.md
arturi May 3, 2022
3af5fe9
Allow configuring sources, use Dashboard as default target
arturi May 26, 2022
c6cd1bb
Merge branch 'main' into remote-sources
arturi May 26, 2022
54e51e7
Add remote-sources to the CDN bundle
arturi May 26, 2022
d3eb0c0
Added docs, readme, types
arturi May 26, 2022
f65e456
Update yarn.lock
arturi May 26, 2022
d2fe057
Merge branch 'main' of https://github.com/transloadit/uppy into remot…
arturi May 26, 2022
c1bfc95
update readme, dev example, don't expose defaultOptions
arturi May 27, 2022
d249bea
Merge branch 'main' into remote-sources
arturi May 27, 2022
fba2ffe
Alphabetical order
arturi May 27, 2022
76a760c
Increase retryDelays to hopefully make the exponential backoff test m…
arturi May 27, 2022
9bf0d67
Update packages/@uppy/remote-sources/package.json
arturi May 30, 2022
f4ba2aa
Update packages/@uppy/remote-sources/src/index.js
arturi May 30, 2022
8106fda
Update packages/@uppy/remote-sources/src/index.js
arturi May 30, 2022
18b1172
Store installedPlugins in a Set
arturi Jun 1, 2022
d686ebb
Revert "Increase retryDelays to hopefully make the exponential backof…
arturi Jun 1, 2022
454ad85
Require companionUrl and plugins stricly from the included, add tests
arturi Jun 7, 2022
a455bf8
Update packages/@uppy/remote-sources/src/index.js
arturi Jun 7, 2022
15e715d
Update private/dev/Dashboard.js
arturi Jun 7, 2022
e57111e
Update doc option type format
arturi Jun 7, 2022
b498178
Better intro from Merlijn
arturi Jun 7, 2022
fa53fbc
Apply suggestions from code review
aduh95 Jun 7, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/@uppy/remote-sources/package.json
Expand Up @@ -43,5 +43,9 @@
},
"publishConfig": {
"access": "public"
},
"devDependencies": {
"@jest/globals": "^28.1.0",
"resize-observer-polyfill": "^1.5.1"
}
}
16 changes: 12 additions & 4 deletions packages/@uppy/remote-sources/src/index.js
Expand Up @@ -48,6 +48,10 @@ export default class RemoteSources extends BasePlugin {
target: Dashboard,
}
this.opts = { ...defaultOptions, ...opts }

if (this.opts.companionUrl == null) {
throw new Error('Please specify companionUrl for RemoteSources to work, see https://uppy.io/docs/remote-sources#companionUrl')
}
}

setOptions (newOpts) {
Expand All @@ -60,16 +64,20 @@ export default class RemoteSources extends BasePlugin {
this.opts.sources.forEach((pluginId) => {
const optsForRemoteSourcePlugin = { ...this.opts, sources: undefined }
const plugin = availablePlugins.find(p => p.name === pluginId)
if (plugin == null) {
const availablePluginsIds = availablePlugins.map(p => p.name)
const formatter = new Intl.ListFormat('en', { style: 'long', type: 'disjunction' })
throw new Error(`Invalid plugin: "${pluginId}" is not one of: ${formatter.format(availablePluginsIds)}.`)
arturi marked this conversation as resolved.
Show resolved Hide resolved
}
this.uppy.use(plugin, optsForRemoteSourcePlugin)
this.#installedPlugins.add(pluginId)
this.#installedPlugins.add(plugin)
})
}

uninstall () {
for (const pluginId of this.#installedPlugins) {
const plugin = this.uppy.getPlugin(pluginId)
for (const plugin of this.#installedPlugins) {
this.uppy.removePlugin(plugin)
this.#installedPlugins.delete(pluginId)
}
this.#installedPlugins.clear()
}
}
42 changes: 42 additions & 0 deletions packages/@uppy/remote-sources/src/index.test.js
@@ -0,0 +1,42 @@
import { describe, expect, it } from '@jest/globals'
import resizeObserverPolyfill from 'resize-observer-polyfill'
import Core from '@uppy/core'
import Dashboard from '@uppy/dashboard'
import RemoteSources from '.'
aduh95 marked this conversation as resolved.
Show resolved Hide resolved

describe('RemoteSources', () => {
beforeAll(() => {
globalThis.ResizeObserver = resizeObserverPolyfill.default || resizeObserverPolyfill
})

afterAll(() => {
delete globalThis.ResizeObserver
})

it('should install RemoteSources with default options', () => {
expect(() => {
const core = new Core()
core.use(Dashboard)
core.use(RemoteSources, { companionUrl: 'https://example.com' })
}).not.toThrow()
})

it('should throw when a companionUrl is not specified', () => {
expect(() => {
const core = new Core()
core.use(Dashboard)
core.use(RemoteSources, { sources: ['Webcam'] })
}).toThrow(new Error('Please specify companionUrl for RemoteSources to work, see https://uppy.io/docs/remote-sources#companionUrl'))
})

it('should throw when trying to use a plugin which is not included in RemoteSources', () => {
expect(() => {
const core = new Core()
core.use(Dashboard)
core.use(RemoteSources, {
companionUrl: 'https://example.com',
sources: ['Webcam'],
})
}).toThrow()
aduh95 marked this conversation as resolved.
Show resolved Hide resolved
})
})
1 change: 1 addition & 0 deletions packages/@uppy/remote-sources/types/index.d.ts
Expand Up @@ -5,6 +5,7 @@ interface RemoteTargetOptions extends PluginOptions, RequestClientOptions {
target?: PluginTarget
sources?: Array<string>
title?: string
companionUrl: string
}

declare class RemoteTarget extends BasePlugin<RemoteTargetOptions> {}
Expand Down
2 changes: 1 addition & 1 deletion private/dev/Dashboard.js
Expand Up @@ -86,7 +86,7 @@ export default () => {
// .use(Unsplash, { target: Dashboard, companionUrl: COMPANION_URL })
.use(RemoteSources, {
companionUrl: COMPANION_URL,
sources: ['Box', 'Dropbox', 'Facebook', 'GoogleDrive', 'Instagram', 'OneDrive', 'Unsplash', 'Url'],
sources: ['Box', 'Dropbox', 'Webcam', 'Facebook', 'GoogleDrive', 'Instagram', 'OneDrive', 'Unsplash', 'Url'],
arturi marked this conversation as resolved.
Show resolved Hide resolved
})
.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.

target: Dashboard,
Expand Down