From d59ab5498eab8d2d58c5eb309556ace07d4c7144 Mon Sep 17 00:00:00 2001 From: Murderlon Date: Tue, 7 Jan 2025 15:05:19 +0100 Subject: [PATCH] @uppy/unsplash,@uppy/provider-views: add utmSource option --- packages/@uppy/angular/tsconfig.json | 1 + packages/@uppy/provider-views/src/Browser.tsx | 3 ++ .../@uppy/provider-views/src/Item/index.tsx | 14 +++++- .../src/ProviderView/ProviderView.tsx | 1 + .../SearchProviderView/SearchProviderView.tsx | 43 ++++++++----------- packages/@uppy/svelte/tsconfig.json | 1 + packages/@uppy/unsplash/src/Unsplash.tsx | 3 +- 7 files changed, 38 insertions(+), 28 deletions(-) diff --git a/packages/@uppy/angular/tsconfig.json b/packages/@uppy/angular/tsconfig.json index 9e59d901a7..eae21ced29 100644 --- a/packages/@uppy/angular/tsconfig.json +++ b/packages/@uppy/angular/tsconfig.json @@ -8,6 +8,7 @@ "strict": true, "noImplicitOverride": true, "noPropertyAccessFromIndexSignature": true, + "useUnknownInCatchVariables": false, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, "sourceMap": true, diff --git a/packages/@uppy/provider-views/src/Browser.tsx b/packages/@uppy/provider-views/src/Browser.tsx index 2deffdbe9d..7cecf3d23e 100644 --- a/packages/@uppy/provider-views/src/Browser.tsx +++ b/packages/@uppy/provider-views/src/Browser.tsx @@ -24,6 +24,7 @@ type BrowserProps = { openFolder: ProviderView['openFolder'] noResultsLabel: string virtualList: boolean + utmSource: string } function Browser(props: BrowserProps) { @@ -38,6 +39,7 @@ function Browser(props: BrowserProps) { openFolder, noResultsLabel, virtualList, + utmSource, } = props const [isShiftKeyPressed, setIsShiftKeyPressed] = useState(false) @@ -88,6 +90,7 @@ function Browser(props: BrowserProps) { i18n={i18n} openFolder={openFolder} file={item} + utmSource={utmSource} /> ) diff --git a/packages/@uppy/provider-views/src/Item/index.tsx b/packages/@uppy/provider-views/src/Item/index.tsx index 094bbbf655..b94e84d3cd 100644 --- a/packages/@uppy/provider-views/src/Item/index.tsx +++ b/packages/@uppy/provider-views/src/Item/index.tsx @@ -18,10 +18,19 @@ type ItemProps = { viewType: string showTitles: boolean i18n: I18n + utmSource: string } export default function Item(props: ItemProps): h.JSX.Element { - const { viewType, toggleCheckbox, showTitles, i18n, openFolder, file } = props + const { + viewType, + toggleCheckbox, + showTitles, + i18n, + openFolder, + file, + utmSource, + } = props const restrictionError = file.type === 'folder' ? null : file.restrictionError const isDisabled = !!restrictionError && file.status !== 'checked' @@ -30,6 +39,7 @@ export default function Item(props: ItemProps): h.JSX.Element { file, openFolder, toggleCheckbox, + utmSource, i18n, viewType, @@ -54,7 +64,7 @@ export default function Item(props: ItemProps): h.JSX.Element { return ( { showTitles={opts.showTitles} i18n={this.plugin.uppy.i18n} isLoading={loading} + utmSource="Companion" /> = Pick, K> & Omit - interface Opts { provider: UnknownSearchProviderPlugin['provider'] - viewType: 'list' | 'grid' | 'unsplash' - showTitles: boolean - showFilter: boolean + viewType?: 'list' | 'grid' | 'unsplash' + showTitles?: boolean + showFilter?: boolean + utmSource?: string } -type PassedOpts = Optional< - Opts, - 'viewType' | 'showTitles' | 'showFilter' -> -type DefaultOpts = Omit, 'provider'> -type RenderOpts = Omit< - PassedOpts, - 'provider' -> + +type RenderOpts = Omit, 'provider'> type Res = { items: CompanionFile[] @@ -66,6 +59,13 @@ type Res = { searchedFor: string } +const defaultOptions = { + viewType: 'grid' as const, + showTitles: true, + showFilter: true, + utmSource: 'Companion', +} + /** * SearchProviderView, used for Unsplash and future image search providers. * Extends generic View, shared with regular providers like Google Drive and Instagram. @@ -77,23 +77,15 @@ export default class SearchProviderView { provider: UnknownSearchProviderPlugin['provider'] - opts: Opts + opts: DefinePluginOpts, keyof typeof defaultOptions> isHandlingScroll: boolean = false lastCheckbox: string | null = null - constructor( - plugin: UnknownSearchProviderPlugin, - opts: PassedOpts, - ) { + constructor(plugin: UnknownSearchProviderPlugin, opts: Opts) { this.plugin = plugin this.provider = opts.provider - const defaultOptions: DefaultOpts = { - viewType: 'grid', - showTitles: true, - showFilter: true, - } this.opts = { ...defaultOptions, ...opts } this.setSearchString = this.setSearchString.bind(this) @@ -286,7 +278,7 @@ export default class SearchProviderView { const { isInputMode, searchString, loading, partialTree } = this.plugin.getPluginState() const { i18n } = this.plugin.uppy - const opts: Opts = { ...this.opts, ...viewOptions } + const opts = { ...this.opts, ...viewOptions } if (isInputMode) { return ( @@ -334,6 +326,7 @@ export default class SearchProviderView { isLoading={loading} i18n={i18n} virtualList={false} + utmSource={this.opts.utmSource} /> extends UIPlugin @@ -91,6 +91,7 @@ export default class Unsplash provider: this.provider, viewType: 'unsplash', showFilter: true, + utmSource: this.opts.utmSource, }) const { target } = this.opts