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

meta: add react dev dashboard #5338

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 39 additions & 33 deletions private/dev/Dashboard.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// The @uppy/ dependencies are resolved from source
/* eslint-disable import/no-extraneous-dependencies */
import Uppy, { debugLogger } from '@uppy/core'
// eslint-disable-next-line import/no-extraneous-dependencies
import Dashboard from '@uppy/dashboard'
// eslint-disable-next-line import/no-extraneous-dependencies
import Form from '@uppy/form'
import RemoteSources from '@uppy/remote-sources'
import Webcam from '@uppy/webcam'
import ScreenCapture from '@uppy/screen-capture'
Expand All @@ -11,7 +14,6 @@ import AwsS3 from '@uppy/aws-s3'
import AwsS3Multipart from '@uppy/aws-s3-multipart'
import XHRUpload from '@uppy/xhr-upload'
import Transloadit from '@uppy/transloadit'
import Form from '@uppy/form'
import ImageEditor from '@uppy/image-editor'
import DropTarget from '@uppy/drop-target'
import Audio from '@uppy/audio'
Expand Down Expand Up @@ -77,10 +79,7 @@ function getCompanionKeysParams (name) {

// Rest is implementation! Obviously edit as necessary...

export default () => {
const restrictions = undefined
// const restrictions = { requiredMetaFields: ['caption'], maxNumberOfFiles: 3 }

export function UppyDashboard({ restrictions } = {}) {
const uppyDashboard = new Uppy({
logger: debugLogger,
meta: {
Expand All @@ -90,44 +89,29 @@ export default () => {
allowMultipleUploadBatches: false,
restrictions,
})
.use(Dashboard, {
trigger: '#pick-files',
// inline: true,
target: '.foo',
metaFields: [
{ id: 'license', name: 'License', placeholder: 'specify license' },
{ id: 'caption', name: 'Caption', placeholder: 'add caption' },
],
showProgressDetails: true,
proudlyDisplayPoweredByUppy: true,
note: `${JSON.stringify(restrictions)}`,
})
.use(GoogleDrive, { target: Dashboard, companionUrl: COMPANION_URL, companionAllowedHosts, ...getCompanionKeysParams('GOOGLE_DRIVE') })
// .use(Instagram, { target: Dashboard, companionUrl: COMPANION_URL, companionAllowedHosts })
// .use(Dropbox, { target: Dashboard, companionUrl: COMPANION_URL, companionAllowedHosts })
// .use(Box, { target: Dashboard, companionUrl: COMPANION_URL, companionAllowedHosts })
// .use(Facebook, { target: Dashboard, companionUrl: COMPANION_URL, companionAllowedHosts })
// .use(OneDrive, { target: Dashboard, companionUrl: COMPANION_URL, companionAllowedHosts })
// .use(Zoom, { target: Dashboard, companionUrl: COMPANION_URL, companionAllowedHosts })
// .use(Url, { target: Dashboard, companionUrl: COMPANION_URL, companionAllowedHosts })
// .use(Unsplash, { target: Dashboard, companionUrl: COMPANION_URL, companionAllowedHosts })
.use(GoogleDrive, { companionUrl: COMPANION_URL, companionAllowedHosts, ...getCompanionKeysParams('GOOGLE_DRIVE') })
// .use(Instagram, { companionUrl: COMPANION_URL, companionAllowedHosts })
// .use(Dropbox, { companionUrl: COMPANION_URL, companionAllowedHosts })
// .use(Box, { companionUrl: COMPANION_URL, companionAllowedHosts })
// .use(Facebook, { companionUrl: COMPANION_URL, companionAllowedHosts })
// .use(OneDrive, { companionUrl: COMPANION_URL, companionAllowedHosts })
// .use(Zoom, { companionUrl: COMPANION_URL, companionAllowedHosts })
// .use(Url, { companionUrl: COMPANION_URL, companionAllowedHosts })
// .use(Unsplash, { companionUrl: COMPANION_URL, companionAllowedHosts })
.use(RemoteSources, {
companionUrl: COMPANION_URL,
sources: ['GooglePhotos', 'Box', 'Dropbox', 'Facebook', 'Instagram', 'OneDrive', 'Unsplash', 'Zoom', 'Url'],
companionAllowedHosts,
})
.use(Webcam, {
target: Dashboard,
showVideoSourceDropdown: true,
showRecordingLength: true,
})
.use(Audio, {
target: Dashboard,
showRecordingLength: true,
})
.use(ScreenCapture, { target: Dashboard })
.use(Form, { target: '#upload-form' })
.use(ImageEditor, { target: Dashboard })
.use(ScreenCapture)
.use(ImageEditor)
.use(DropTarget, {
target: document.body,
})
Expand Down Expand Up @@ -185,8 +169,6 @@ export default () => {
uppyDashboard.use(GoldenRetriever, { serviceWorker: true })
}

window.uppy = uppyDashboard

uppyDashboard.on('complete', (result) => {
if (result.failed.length === 0) {
console.log('Upload successful 😀')
Expand All @@ -200,6 +182,30 @@ export default () => {
}
})

return uppyDashboard
}

export default () => {
const restrictions = undefined
// const restrictions = { requiredMetaFields: ['caption'], maxNumberOfFiles: 3 }

const uppy = UppyDashboard({ restrictions })
.use(Dashboard, {
trigger: '#pick-files',
// inline: true,
target: '.foo',
metaFields: [
{ id: 'license', name: 'License', placeholder: 'specify license' },
{ id: 'caption', name: 'Caption', placeholder: 'add caption' },
],
showProgressDetails: true,
proudlyDisplayPoweredByUppy: true,
note: `${JSON.stringify(restrictions)}`,
})
.use(Form, { target: '#upload-form' })

window.uppy = uppy

const modalTrigger = document.querySelector('#pick-files')
if (modalTrigger) modalTrigger.click()
}
36 changes: 36 additions & 0 deletions private/dev/React.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* eslint-disable react/react-in-jsx-scope, import/no-extraneous-dependencies */
// eslint-disable-next-line no-unused-vars
import { createElement as h, useState, useCallback } from 'react';
// eslint-disable-next-line import/no-unresolved
import { createRoot } from 'react-dom/client';

import '@uppy/core/dist/style.css';
import '@uppy/dashboard/dist/style.css';

import { Dashboard } from '@uppy/react';

import { UppyDashboard } from './Dashboard.js'


function App() {
const [uppy] = useState(() => UppyDashboard());

const [i, setI] = useState(0);

// https://github.com/transloadit/uppy/issues/5248
const handleDoneButtonClick = useCallback(() => {
setI(i + 1);
console.log('Done button clicked', i);

Check warning on line 23 in private/dev/React.jsx

View workflow job for this annotation

GitHub Actions / Lint JavaScript/TypeScript

Unexpected console statement
}, [i]);

return (
<div>
<h1>React Uppy</h1>
<Dashboard uppy={uppy} doneButtonHandler={handleDoneButtonClick} />
</div>
);
}

const container = document.getElementById('root');
const root = createRoot(container);
root.render(<App />);
3 changes: 3 additions & 0 deletions private/dev/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
<main class="foo">
<h1>Dashboard is here</h1>

<p><a href="/react.html">React dashboard</a></p>
<p><a href="/dragdrop.html">DragDrop</a></p>

<!-- some inputs in a form to check focus management in Dashboard -->
<form id="upload-form" action="/">
<button type="button" id="pick-files">Pick Files</button><br />
Expand Down
2 changes: 2 additions & 0 deletions private/dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"autoprefixer": "^10.2.6",
"postcss-dir-pseudo-class": "^6.0.0",
"postcss-logical": "^5.0.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"vite": "^5.0.0"
},
"private": true,
Expand Down
14 changes: 14 additions & 0 deletions private/dev/react.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>React</title>
<link rel="icon" type="image/png" href="https://uppy.io/img/logo.svg" />
</head>

<body>
<div id="root"></div>
<script type="module" src="/React.jsx"></script>
</body>
</html>
6 changes: 4 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8084,6 +8084,8 @@ __metadata:
autoprefixer: "npm:^10.2.6"
postcss-dir-pseudo-class: "npm:^6.0.0"
postcss-logical: "npm:^5.0.0"
react: "npm:^18.3.1"
react-dom: "npm:^18.3.1"
vite: "npm:^5.0.0"
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -24866,7 +24868,7 @@ __metadata:
languageName: node
linkType: hard

"react-dom@npm:^18.0.0, react-dom@npm:^18.1.0, react-dom@npm:^18.2.0":
"react-dom@npm:^18.0.0, react-dom@npm:^18.1.0, react-dom@npm:^18.2.0, react-dom@npm:^18.3.1":
version: 18.3.1
resolution: "react-dom@npm:18.3.1"
dependencies:
Expand Down Expand Up @@ -25026,7 +25028,7 @@ __metadata:
languageName: node
linkType: hard

"react@npm:^18.0.0, react@npm:^18.1.0, react@npm:^18.2.0":
"react@npm:^18.0.0, react@npm:^18.1.0, react@npm:^18.2.0, react@npm:^18.3.1":
version: 18.3.1
resolution: "react@npm:18.3.1"
dependencies:
Expand Down