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

@uppy/dashboard: stylistic changes for plugin options #5384

Merged
merged 3 commits into from
Oct 15, 2024
Merged
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
37 changes: 23 additions & 14 deletions packages/@uppy/dashboard/src/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ interface DashboardMiscOptions<M extends Meta, B extends Body>
thumbnailHeight?: number
thumbnailType?: string
thumbnailWidth?: number
trigger?: string | Element
trigger?: string | Element | null
Copy link
Contributor

Choose a reason for hiding this comment

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

for people who have a strict tsconfig and have set exactOptionalPropertyTypes: true, it's nice to also allow undefined (but this also applies to all other options, so maybe a separate pr when i think about it..)

Suggested change
trigger?: string | Element | null
trigger?: string | Element | null | undefined

Copy link
Member

Choose a reason for hiding this comment

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

imo that's what ? is for, we don't need to add undefined everywhere. Too redundant.

Copy link
Contributor

Choose a reason for hiding this comment

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

that is incorrect when exactOptionalPropertyTypes: true:

  • undefined means that the property exists on the object but has the value undefined, e.g. { prop: undefined } satisfies the type { prop: string | undefined }
  • ? means that the property might not exist at all, e.g.: {} satisfies the type { prop?: string }

And we cannot control whether or not consumers of uppy are using exactOptionalPropertyTypes: true in their tsconfig

waitForThumbnailsBeforeUpload?: boolean
}

Expand All @@ -183,9 +183,6 @@ export type DashboardOptions<
const defaultOptions = {
target: 'body',
metaFields: [],
inline: false as boolean,
width: 750,
height: 550,
thumbnailWidth: 280,
thumbnailType: 'image/jpeg',
waitForThumbnailsBeforeUpload: false,
Expand All @@ -198,32 +195,44 @@ const defaultOptions = {
hidePauseResumeButton: false,
hideProgressAfterFinish: false,
note: null,
closeModalOnClickOutside: false,
closeAfterFinish: false,
singleFileFullScreen: true,
disableStatusBar: false,
disableInformer: false,
disableThumbnailGenerator: false,
disablePageScrollWhenModalOpen: true,
animateOpenClose: true,
fileManagerSelectionType: 'files',
proudlyDisplayPoweredByUppy: true,
showSelectedFiles: true,
showRemoveButtonAfterComplete: false,
browserBackButtonClose: false,
showNativePhotoCameraButton: false,
showNativeVideoCameraButton: false,
theme: 'light',
autoOpen: null,
disabled: false,
disableLocalFiles: false,
nativeCameraFacingMode: '',
onDragLeave: () => {},
onDragOver: () => {},
onDrop: () => {},
plugins: [],

// Dynamic default options, they have to be defined in the constructor (because
// they require access to the `this` keyword), but we still want them to
// appear in the default options so TS knows they'll be defined.
doneButtonHandler: undefined as any,
onRequestCloseModal: null as any,

// defaultModalOptions
inline: false as boolean,
animateOpenClose: true,
browserBackButtonClose: false,
closeAfterFinish: false,
closeModalOnClickOutside: false,
disablePageScrollWhenModalOpen: true,
trigger: null,

// defaultInlineOptions
width: 750,
height: 550,
} satisfies Partial<DashboardOptions<any, any>>

/**
Expand Down Expand Up @@ -828,7 +837,7 @@ export default class Dashboard<M extends Meta, B extends Body> extends UIPlugin<

this.setPluginState({ isDraggingOver: true })

this.opts.onDragOver?.(event)
this.opts.onDragOver(event)
}

private handleDragLeave = (event: DragEvent) => {
Expand All @@ -837,7 +846,7 @@ export default class Dashboard<M extends Meta, B extends Body> extends UIPlugin<

this.setPluginState({ isDraggingOver: false })

this.opts.onDragLeave?.(event)
this.opts.onDragLeave(event)
}

private handleDrop = async (event: DragEvent) => {
Expand Down Expand Up @@ -876,7 +885,7 @@ export default class Dashboard<M extends Meta, B extends Body> extends UIPlugin<
this.addFiles(files)
}

this.opts.onDrop?.(event)
this.opts.onDrop(event)
}

private handleRequestThumbnail = (file: UppyFile<M, B>) => {
Expand Down Expand Up @@ -1264,7 +1273,7 @@ export default class Dashboard<M extends Meta, B extends Body> extends UIPlugin<
}

#addSpecifiedPluginsFromOptions = () => {
const plugins = this.opts.plugins || []
const { plugins } = this.opts

plugins.forEach((pluginID) => {
const plugin = this.uppy.getPlugin(pluginID)
Expand Down Expand Up @@ -1470,7 +1479,7 @@ export default class Dashboard<M extends Meta, B extends Body> extends UIPlugin<
if (thumbnail) this.uppy.removePlugin(thumbnail)
}

const plugins = this.opts.plugins || []
const { plugins } = this.opts
plugins.forEach((pluginID) => {
const plugin = this.uppy.getPlugin(pluginID)
if (plugin) (plugin as any).unmount()
Expand Down
Loading