Skip to content

Commit

Permalink
fix: fix regression with onSelect not passing an array
Browse files Browse the repository at this point in the history
  • Loading branch information
robinpyon committed May 5, 2022
1 parent 8de8996 commit dae8628
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
ToastProvider
} from '@sanity/ui'
import {AssetSourceComponentProps} from '@sanity/types'
import React, {FC, forwardRef, MouseEvent, Ref} from 'react'
import React, {forwardRef, MouseEvent, Ref} from 'react'
import {ThemeProvider as LegacyThemeProvider} from 'theme-ui'
import Browser from './components/Browser'
import ReduxProvider from './components/ReduxProvider'
Expand All @@ -20,7 +20,7 @@ import theme from './styled/theme'

type Props = AssetSourceComponentProps

const AssetBrowser: FC<Props> = forwardRef((props: Props, ref: Ref<HTMLDivElement>) => {
const AssetBrowser = forwardRef((props: Props, ref: Ref<HTMLDivElement>) => {
const {onClose, onSelect} = props

// Close on escape key press
Expand All @@ -40,6 +40,7 @@ const AssetBrowser: FC<Props> = forwardRef((props: Props, ref: Ref<HTMLDivElemen
<LegacyThemeProvider theme={theme}>
<PortalProvider element={document.body}>
<ToastProvider zOffset={Z_INDEX_TOAST_PROVIDER}>
{/* @ts-expect-error */}
<AssetBrowserDispatchProvider onSelect={onSelect}>
<GlobalStyle />

Expand Down
10 changes: 6 additions & 4 deletions src/components/CardAsset/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,12 @@ const CardAsset = (props: Props) => {
e.stopPropagation()

if (onSelect) {
onSelect({
kind: 'assetDocumentId',
value: asset._id
})
onSelect([
{
kind: 'assetDocumentId',
value: asset._id
}
])
} else if (shiftPressed.current) {
if (picked) {
dispatch(assetsActions.pick({assetId: asset._id, picked: !picked}))
Expand Down
10 changes: 6 additions & 4 deletions src/components/TableRowAsset/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,12 @@ const TableRowAsset = (props: Props) => {
e.stopPropagation()

if (onSelect) {
onSelect({
kind: 'assetDocumentId',
value: asset._id
})
onSelect([
{
kind: 'assetDocumentId',
value: asset._id
}
])
} else if (shiftPressed.current) {
if (picked) {
dispatch(assetsActions.pick({assetId: asset._id, picked: !picked}))
Expand Down
4 changes: 2 additions & 2 deletions src/contexts/AssetSourceDispatchContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import React, {ReactNode, createContext, useContext} from 'react'
import type {AssetFromSource} from '@sanity/types'

type ContextProps = {
onSelect?: (assetFromSource: AssetFromSource) => void
onSelect?: (assetFromSource: AssetFromSource[]) => void
}

type Props = {
children: ReactNode
onSelect?: (assetFromSource: AssetFromSource) => void
onSelect?: (assetFromSource: AssetFromSource[]) => void
}

const AssetSourceDispatchContext = createContext<ContextProps | undefined>(undefined)
Expand Down

0 comments on commit dae8628

Please sign in to comment.