-
Notifications
You must be signed in to change notification settings - Fork 2k
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
@uppy/react: refactor to TS #5012
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1000131
@uppy/react: refactor to TS
aduh95 91eda5e
w
aduh95 912e54d
w
aduh95 aa2c532
w
aduh95 64c168e
w
aduh95 0dbfa5b
w
aduh95 5e146ab
w
aduh95 c521d7d
r
aduh95 e6a0a20
fix legacy types
aduh95 eadf574
reuse types
aduh95 4325821
Merge branch 'main' of https://github.com/transloadit/uppy
aduh95 1b9ef9d
@uppy/dashboard: refine option types
aduh95 a8021ad
fix dashboard types
aduh95 ab9fd61
fixup! fix dashboard types
aduh95 f699c18
Merge branch 'main' into react-ts
aduh95 dd7116b
Merge branch 'main' into react-ts
aduh95 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
tsconfig.* |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { createElement as h, Component } from 'react' | ||
import PropTypes from 'prop-types' | ||
import type { UnknownPlugin, Uppy } from '@uppy/core' | ||
import DashboardPlugin from '@uppy/dashboard' | ||
import type { Body, Meta } from '@uppy/utils/lib/UppyFile' | ||
import type { DashboardOptions } from '@uppy/dashboard' | ||
import { | ||
locale, | ||
uppy as uppyPropType, | ||
plugins, | ||
metaFields, | ||
cssSize, | ||
} from './propTypes.ts' | ||
import getHTMLProps from './getHTMLProps.ts' | ||
import nonHtmlPropsHaveChanged from './nonHtmlPropsHaveChanged.ts' | ||
|
||
type DashboardInlineOptions<M extends Meta, B extends Body> = Omit< | ||
DashboardOptions<M, B> & { inline: true }, | ||
'inline' | ||
> & | ||
React.BaseHTMLAttributes<HTMLDivElement> | ||
|
||
export interface DashboardProps<M extends Meta, B extends Body> | ||
extends DashboardInlineOptions<M, B> { | ||
uppy: Uppy<M, B> | ||
} | ||
|
||
/** | ||
* React Component that renders a Dashboard for an Uppy instance. This component | ||
* renders the Dashboard inline, so you can put it anywhere you want. | ||
*/ | ||
|
||
class Dashboard<M extends Meta, B extends Body> extends Component< | ||
DashboardProps<M, B> | ||
> { | ||
static propsTypes = { | ||
uppy: uppyPropType, | ||
disableInformer: PropTypes.bool, | ||
disableStatusBar: PropTypes.bool, | ||
disableThumbnailGenerator: PropTypes.bool, | ||
height: cssSize, | ||
hideProgressAfterFinish: PropTypes.bool, | ||
hideUploadButton: PropTypes.bool, | ||
locale, | ||
metaFields, | ||
note: PropTypes.string, | ||
plugins, | ||
proudlyDisplayPoweredByUppy: PropTypes.bool, | ||
showProgressDetails: PropTypes.bool, | ||
width: cssSize, | ||
// pass-through to ThumbnailGenerator | ||
thumbnailType: PropTypes.string, | ||
thumbnailWidth: PropTypes.number, | ||
} | ||
|
||
private container: HTMLElement | ||
|
||
private plugin: UnknownPlugin<M, B> | ||
|
||
componentDidMount(): void { | ||
this.installPlugin() | ||
} | ||
|
||
componentDidUpdate(prevProps: Dashboard<M, B>['props']): void { | ||
// eslint-disable-next-line react/destructuring-assignment | ||
if (prevProps.uppy !== this.props.uppy) { | ||
this.uninstallPlugin(prevProps) | ||
this.installPlugin() | ||
} else if (nonHtmlPropsHaveChanged(this.props, prevProps)) { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const { uppy, ...options } = { ...this.props, target: this.container } | ||
this.plugin.setOptions(options) | ||
} | ||
} | ||
|
||
componentWillUnmount(): void { | ||
this.uninstallPlugin() | ||
} | ||
|
||
installPlugin(): void { | ||
const { uppy, ...options } = { | ||
id: 'react:Dashboard', | ||
inline: true, | ||
...this.props, | ||
target: this.container, | ||
} | ||
uppy.use(DashboardPlugin<M, B>, options) | ||
|
||
this.plugin = uppy.getPlugin(options.id)! | ||
} | ||
|
||
uninstallPlugin(props = this.props): void { | ||
const { uppy } = props | ||
|
||
uppy.removePlugin(this.plugin) | ||
} | ||
|
||
render(): JSX.Element { | ||
aduh95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return h('div', { | ||
className: 'uppy-Container', | ||
ref: (container: HTMLElement): void => { | ||
this.container = container | ||
}, | ||
...getHTMLProps(this.props), | ||
}) | ||
} | ||
} | ||
|
||
export default Dashboard |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should have reviewed this in the other PR but didn't foresee how we'd use it, but I initially envisioned we'd import
DashboardInlineOptions
which does this trick inside@uppy/dashboard
. Then we keep the conditions of the discriminated union in one place instead of repeating it everywhere.What do you think? Doesn't need a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if it's worth it, exporting a single type is less likely to confuse users. The fact that we need to remove the discriminated union here is probably more the exception than the rule.