Skip to content

Commit

Permalink
@uppy/unsplash,@uppy/provider-views: add utmSource option
Browse files Browse the repository at this point in the history
  • Loading branch information
Murderlon committed Jan 7, 2025
1 parent f3a750d commit 4ef8909
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/@uppy/provider-views/src/Browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type BrowserProps<M extends Meta, B extends Body> = {
openFolder: ProviderView<M, B>['openFolder']
noResultsLabel: string
virtualList: boolean
utmSource: string
}

function Browser<M extends Meta, B extends Body>(props: BrowserProps<M, B>) {
Expand All @@ -38,6 +39,7 @@ function Browser<M extends Meta, B extends Body>(props: BrowserProps<M, B>) {
openFolder,
noResultsLabel,
virtualList,
utmSource,
} = props

const [isShiftKeyPressed, setIsShiftKeyPressed] = useState(false)
Expand Down Expand Up @@ -88,6 +90,7 @@ function Browser<M extends Meta, B extends Body>(props: BrowserProps<M, B>) {
i18n={i18n}
openFolder={openFolder}
file={item}
utmSource={utmSource}
/>
)

Expand Down
14 changes: 12 additions & 2 deletions packages/@uppy/provider-views/src/Item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -30,6 +39,7 @@ export default function Item(props: ItemProps): h.JSX.Element {
file,
openFolder,
toggleCheckbox,
utmSource,

i18n,
viewType,
Expand All @@ -54,7 +64,7 @@ export default function Item(props: ItemProps): h.JSX.Element {
return (
<GridItem {...ourProps}>
<a
href={`${file.data.author!.url}?utm_source=Companion&utm_medium=referral`}
href={`${file.data.author!.url}?utm_source=${utmSource}&utm_medium=referral`}
target="_blank"
rel="noopener noreferrer"
className="uppy-ProviderBrowserItem-author"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ interface Opts<M extends Meta, B extends Body> {
viewType: 'list' | 'grid' | 'unsplash'
showTitles: boolean
showFilter: boolean
utmSource?: string
}
type PassedOpts<M extends Meta, B extends Body> = Optional<
Opts<M, B>,
Expand Down Expand Up @@ -93,6 +94,7 @@ export default class SearchProviderView<M extends Meta, B extends Body> {
viewType: 'grid',
showTitles: true,
showFilter: true,
utmSource: 'Companion',
}
this.opts = { ...defaultOptions, ...opts }

Expand Down Expand Up @@ -334,6 +336,7 @@ export default class SearchProviderView<M extends Meta, B extends Body> {
isLoading={loading}
i18n={i18n}
virtualList={false}
utmSource={this.opts.utmSource}

Check failure on line 339 in packages/@uppy/provider-views/src/SearchProviderView/SearchProviderView.tsx

View workflow job for this annotation

GitHub Actions / Type tests

Type 'string | undefined' is not assignable to type 'string'.

Check failure on line 339 in packages/@uppy/provider-views/src/SearchProviderView/SearchProviderView.tsx

View workflow job for this annotation

GitHub Actions / Browser tests

Type 'string | undefined' is not assignable to type 'string'.
/>

<FooterActions
Expand Down
3 changes: 2 additions & 1 deletion packages/@uppy/unsplash/src/Unsplash.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import locale from './locale.js'
// @ts-ignore We don't want TS to generate types for the package.json
import packageJson from '../package.json'

export type UnsplashOptions = CompanionPluginOptions
export type UnsplashOptions = { utmSource: string } & CompanionPluginOptions

export default class Unsplash<M extends Meta, B extends Body>
extends UIPlugin<UnsplashOptions, M, B, UnknownSearchProviderPluginState>
Expand Down Expand Up @@ -91,6 +91,7 @@ export default class Unsplash<M extends Meta, B extends Body>
provider: this.provider,
viewType: 'unsplash',
showFilter: true,
utmSource: this.opts.utmSource,
})

const { target } = this.opts
Expand Down

0 comments on commit 4ef8909

Please sign in to comment.