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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

@uppy/provider-views: migrate to TS #4919

Merged
merged 21 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
1 change: 1 addition & 0 deletions packages/@uppy/provider-views/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tsconfig.*
6 changes: 3 additions & 3 deletions packages/@uppy/provider-views/src/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ const Breadcrumb = (props: BreadcrumbProps) => {
)
}

type BreadcrumpsProps<M extends Meta, B extends Body> = {
type BreadcrumbsProps<M extends Meta, B extends Body> = {
getFolder: ProviderView<M, B>['getFolder']
title: string
breadcrumbsIcon: JSX.Element
breadcrumbs: UnknownProviderPluginState['breadcrumbs']
}

export default function Breadcrumps<M extends Meta, B extends Body>(
props: BreadcrumpsProps<M, B>,
export default function Breadcrumbs<M extends Meta, B extends Body>(
props: BreadcrumbsProps<M, B>,
): JSX.Element {
const { getFolder, title, breadcrumbsIcon, breadcrumbs } = props

Expand Down
4 changes: 2 additions & 2 deletions packages/@uppy/provider-views/src/Browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type ListItemProps<M extends Meta, B extends Body> = {
viewType: string
isChecked: (file: any) => boolean
toggleCheckbox: (event: Event, file: CompanionFile) => void
recordShiftKeyPress: (event: KeyboardEvent) => void
recordShiftKeyPress: (event: KeyboardEvent | MouseEvent) => void
showTitles: boolean
i18n: I18n
validateRestrictions: Uppy<M, B>['validateRestrictions']
Expand Down Expand Up @@ -100,7 +100,7 @@ type BrowserProps<M extends Meta, B extends Body> = {
showBreadcrumbs: boolean
isChecked: (file: any) => boolean
toggleCheckbox: (event: Event, file: CompanionFile) => void
recordShiftKeyPress: (event: KeyboardEvent) => void
recordShiftKeyPress: (event: KeyboardEvent | MouseEvent) => void
handleScroll: (event: Event) => Promise<void>
showTitles: boolean
i18n: I18n
Expand Down
3 changes: 1 addition & 2 deletions packages/@uppy/provider-views/src/Item/components/ListLi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type ListItemProps<M extends Meta, B extends Body> = {
isCheckboxDisabled: boolean
isChecked: boolean
toggleCheckbox: (event: Event) => void
recordShiftKeyPress: (event: KeyboardEvent) => void
recordShiftKeyPress: (event: KeyboardEvent | MouseEvent) => void
type: string
id: string
itemIconEl: any
Expand Down Expand Up @@ -58,7 +58,6 @@ export default function ListItem<M extends Meta, B extends Body>(
className={`uppy-u-reset uppy-ProviderBrowserItem-checkbox ${isChecked ? 'uppy-ProviderBrowserItem-checkbox--is-checked' : ''}`}
onChange={toggleCheckbox}
onKeyDown={recordShiftKeyPress}
// @ts-expect-error this is fine onMouseDown too
onMouseDown={recordShiftKeyPress}
// for the <label/>
name="listitem"
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/provider-views/src/Item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type ItemProps<M extends Meta, B extends Body> = {
id: string
title: string
toggleCheckbox: (event: Event) => void
recordShiftKeyPress: (event: KeyboardEvent) => void
recordShiftKeyPress: (event: KeyboardEvent | MouseEvent) => void
handleFolderClick?: () => void
restrictionError?: RestrictionError<M, B> | null
isCheckboxDisabled: boolean
Expand Down
12 changes: 2 additions & 10 deletions packages/@uppy/provider-views/src/ProviderView/AuthView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function DefaultForm<M extends Meta, B extends Body>({
const onSubmit = useCallback(
(e: Event) => {
e.preventDefault()
onAuth(undefined)
onAuth()
},
[onAuth],
)
Expand Down Expand Up @@ -117,20 +117,12 @@ export default function AuthView<M extends Meta, B extends Body>(
renderForm = defaultRenderForm,
} = props

const pluginNameComponent = (
<span className="uppy-Provider-authTitleName">
{pluginName}
<br />
</span>
)
return (
<div className="uppy-Provider-auth">
<div className="uppy-Provider-authIcon">{pluginIcon()}</div>
<div className="uppy-Provider-authTitle">
{i18n('authenticateWithTitle', {
// @ts-expect-error how it possible to pass `Element` to `i18n`?
// It seems like like that shouldn't work.
pluginName: pluginNameComponent,
pluginName,
})}
</div>

Expand Down
6 changes: 3 additions & 3 deletions packages/@uppy/provider-views/src/ProviderView/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable react/destructuring-assignment */
import { h, Fragment } from 'preact'
import { h } from 'preact'
Murderlon marked this conversation as resolved.
Show resolved Hide resolved
import type { I18n } from '@uppy/utils/lib/Translator'
import type { Body, Meta } from '@uppy/utils/lib/UppyFile'
import type { UnknownProviderPluginState } from '@uppy/core/lib/Uppy.ts'
Expand All @@ -22,7 +22,7 @@ export default function Header<M extends Meta, B extends Body>(
props: HeaderProps<M, B>,
): JSX.Element {
return (
<Fragment>
<>
{props.showBreadcrumbs && (
<Breadcrumbs
getFolder={props.getFolder}
Expand All @@ -32,6 +32,6 @@ export default function Header<M extends Meta, B extends Body>(
/>
)}
<User logout={props.logout} username={props.username} i18n={props.i18n} />
</Fragment>
</>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ export default class ProviderView<M extends Meta, B extends Body> extends View<
this.plugin.setPluginState({ filterInput: '' })
}

async handleAuth(authFormData: unknown): Promise<void> {
async handleAuth(authFormData?: unknown): Promise<void> {
try {
await this.#withAbort(async (signal) => {
this.setLoading(true)
Expand Down
6 changes: 3 additions & 3 deletions packages/@uppy/provider-views/src/ProviderView/User.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { h, Fragment } from 'preact'
import { h } from 'preact'

Murderlon marked this conversation as resolved.
Show resolved Hide resolved
type UserProps = {
i18n: (phrase: string) => string
Expand All @@ -12,7 +12,7 @@ export default function User({
username,
}: UserProps): JSX.Element {
return (
<Fragment>
<>
<span className="uppy-ProviderBrowser-user" key="username">
{username}
</span>
Expand All @@ -24,6 +24,6 @@ export default function User({
>
{i18n('logOut')}
</button>
</Fragment>
</>
)
}
6 changes: 3 additions & 3 deletions packages/@uppy/provider-views/src/SearchFilterInput.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable react/require-default-props */
import { h, Fragment } from 'preact'
import { h } from 'preact'
Murderlon marked this conversation as resolved.
Show resolved Hide resolved
import { useEffect, useState, useCallback } from 'preact/hooks'
import { nanoid } from 'nanoid/non-secure'

Expand Down Expand Up @@ -72,7 +72,7 @@ export default function SearchFilterInput(props: Props): JSX.Element {
}, [form, validateAndSearch])

return (
<Fragment>
<>
<input
className={`uppy-u-reset ${inputClassName}`}
aduh95 marked this conversation as resolved.
Show resolved Hide resolved
type="search"
Expand Down Expand Up @@ -122,6 +122,6 @@ export default function SearchFilterInput(props: Props): JSX.Element {
{buttonLabel}
</button>
)}
</Fragment>
</>
)
}
8 changes: 5 additions & 3 deletions packages/@uppy/provider-views/src/View.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,10 @@ export default class View<

uppy.log(error.toString())

// @ts-expect-error AuthError lives in @uppy/companion-client
if (error.isAuthError || error.cause?.name === 'AbortError') {
if (
(error as any).isAuthError ||
(error.cause as Error)?.name === 'AbortError'
) {
// authError just means we're not authenticated, don't show to user
// AbortError means the user has clicked "cancel" on an operation
return
Expand Down Expand Up @@ -213,7 +215,7 @@ export default class View<
})
}

recordShiftKeyPress = (e: KeyboardEvent): void => {
recordShiftKeyPress = (e: KeyboardEvent | MouseEvent): void => {
this.isShiftKeyPressed = e.shiftKey
}

Expand Down
1 change: 0 additions & 1 deletion packages/@uppy/utils/src/UppyFile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { CompanionFile } from './CompanionFile'
import type { FileProgress } from './FileProgress'

export type Meta = Record<string, unknown>
Expand Down