Skip to content

Commit 24f6c42

Browse files
authored
chore: revert failing commit (#7843)
1 parent 1d5d171 commit 24f6c42

File tree

10 files changed

+20
-59
lines changed

10 files changed

+20
-59
lines changed

packages/sanity/src/core/form/inputs/files/ImageInput/ImageInput.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,10 @@ function BaseImageInputComponent(props: BaseImageInputProps): JSX.Element {
108108
}, [path])
109109

110110
const clearUploadStatus = useCallback(() => {
111-
onChange(unset(['_upload']))
112-
}, [onChange])
111+
if (value?._upload) {
112+
onChange(unset(['_upload']))
113+
}
114+
}, [onChange, value?._upload])
113115
const cancelUpload = useCallback(() => {
114116
if (uploadSubscription.current) {
115117
uploadSubscription.current.unsubscribe()

packages/sanity/src/core/form/inputs/files/ImageInput/ImageInputAssetMenu.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {type Observable} from 'rxjs'
99
import {MenuItem} from '../../../../../ui-components'
1010
import {useTranslation} from '../../../../i18n'
1111
import {ActionsMenu} from '../common/ActionsMenu'
12-
import {SUPPORTED_IMAGE_UPLOAD_TYPES} from '../constants'
1312
import {ImageActionsMenu, ImageActionsMenuWaitPlaceholder} from './ImageActionsMenu'
1413
import {type BaseImageInputProps} from './types'
1514

@@ -55,10 +54,7 @@ function ImageInputAssetMenuComponent(
5554
} = props
5655
const {t} = useTranslation()
5756

58-
const accept = useMemo(
59-
() => get(schemaType, 'options.accept', SUPPORTED_IMAGE_UPLOAD_TYPES.join(',')),
60-
[schemaType],
61-
)
57+
const accept = useMemo(() => get(schemaType, 'options.accept', 'image/*'), [schemaType])
6258
const asset = value?.asset
6359

6460
const showAdvancedEditButton = value && asset && isImageToolEnabled

packages/sanity/src/core/form/inputs/files/ImageInput/ImageInputAssetSource.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {get} from 'lodash'
33
import {memo, useMemo} from 'react'
44

55
import {WithReferencedAsset} from '../../../utils/WithReferencedAsset'
6-
import {SUPPORTED_IMAGE_UPLOAD_TYPES} from '../constants'
76
import {type BaseImageInputProps} from './types'
87

98
function ImageInputAssetSourceComponent(
@@ -21,10 +20,7 @@ function ImageInputAssetSourceComponent(
2120
selectedAssetSource,
2221
value,
2322
} = props
24-
const accept = useMemo(
25-
() => get(schemaType, 'options.accept', SUPPORTED_IMAGE_UPLOAD_TYPES.join(',')),
26-
[schemaType],
27-
)
23+
const accept = useMemo(() => get(schemaType, 'options.accept', 'image/*'), [schemaType])
2824

2925
if (!selectedAssetSource) {
3026
return null

packages/sanity/src/core/form/inputs/files/ImageInput/ImageInputUploadPlaceholder.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {get} from 'lodash'
33
import {memo, useMemo} from 'react'
44

55
import {UploadPlaceholder} from '../common/UploadPlaceholder'
6-
import {SUPPORTED_IMAGE_UPLOAD_TYPES} from '../constants'
76
import {type BaseImageInputProps, type FileInfo} from './types'
87

98
function ImageInputUploadPlaceholderComponent(props: {
@@ -29,10 +28,7 @@ function ImageInputUploadPlaceholderComponent(props: {
2928
() => hoveringFiles.filter((file) => resolveUploader(schemaType, file)),
3029
[hoveringFiles, resolveUploader, schemaType],
3130
)
32-
const accept = useMemo(
33-
() => get(schemaType, 'options.accept', SUPPORTED_IMAGE_UPLOAD_TYPES.join(',')),
34-
[schemaType],
35-
)
31+
const accept = useMemo(() => get(schemaType, 'options.accept', 'image/*'), [schemaType])
3632

3733
const rejectedFilesCount = hoveringFiles.length - acceptedFiles.length
3834

packages/sanity/src/core/form/inputs/files/__workshop__/UploadPlaceholderStory.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ import {Card, Container, Flex} from '@sanity/ui'
22

33
import {Button} from '../../../../../ui-components'
44
import {UploadPlaceholder} from '../common/UploadPlaceholder'
5-
import {SUPPORTED_IMAGE_UPLOAD_TYPES} from '../constants'
65

76
export default function UploadPlaceholderStory() {
87
return (
98
<Flex align="center" height="fill" justify="center" padding={3}>
109
<Container width={1}>
1110
<Card>
1211
<UploadPlaceholder
13-
accept={SUPPORTED_IMAGE_UPLOAD_TYPES.join(',')}
12+
accept="image/*"
1413
acceptedFiles={[{name: 'foo.jpg', type: 'image/jpeg'}]}
1514
browse={<Button text="Browse btn" mode="ghost" />}
1615
directUploads

packages/sanity/src/core/form/inputs/files/constants.ts

-16
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,3 @@
44
* the upload will be marked as stale/interrupted.
55
*/
66
export const STALE_UPLOAD_MS = 1000 * 60 * 2
7-
8-
/**
9-
* The mime types of image formats we support uploading
10-
*
11-
* @internal
12-
*/
13-
export const SUPPORTED_IMAGE_UPLOAD_TYPES = [
14-
'image/bmp',
15-
'image/gif',
16-
'image/jpeg',
17-
'image/png',
18-
'image/svg',
19-
'image/tiff',
20-
'image/webp',
21-
'.psd', // Many different mime types for PSD files, so we just use the extension
22-
]

packages/sanity/src/core/form/studio/inputs/client-adapters/assets.ts

+5-14
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,10 @@ export const uploadImageAsset = (
7373
client: SanityClient,
7474
file: File | Blob,
7575
options?: UploadOptions,
76-
): Observable<UploadEvent> => uploadAsset(client, 'image', file, options)
76+
) => uploadAsset(client, 'image', file, options)
7777

78-
export const uploadFileAsset = (
79-
client: SanityClient,
80-
file: File | Blob,
81-
options?: UploadOptions,
82-
): Observable<UploadEvent> => uploadAsset(client, 'file', file, options)
78+
export const uploadFileAsset = (client: SanityClient, file: File | Blob, options?: UploadOptions) =>
79+
uploadAsset(client, 'file', file, options)
8380

8481
/**
8582
*
@@ -126,17 +123,11 @@ function observeAssetDoc(documentPreviewStore: DocumentPreviewStore, id: string)
126123
)
127124
}
128125

129-
export function observeImageAsset(
130-
documentPreviewStore: DocumentPreviewStore,
131-
id: string,
132-
): Observable<ImageAsset> {
126+
export function observeImageAsset(documentPreviewStore: DocumentPreviewStore, id: string) {
133127
return observeAssetDoc(documentPreviewStore, id) as Observable<ImageAsset>
134128
}
135129

136-
export function observeFileAsset(
137-
documentPreviewStore: DocumentPreviewStore,
138-
id: string,
139-
): Observable<FileAsset> {
130+
export function observeFileAsset(documentPreviewStore: DocumentPreviewStore, id: string) {
140131
return observeAssetDoc(documentPreviewStore, id) as Observable<FileAsset>
141132
}
142133

packages/sanity/src/core/form/studio/uploads/uploadImage.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ export function uploadImage(
2121
options?: UploadOptions,
2222
): Observable<UploadProgressEvent> {
2323
const upload$ = uploadImageAsset(client, file, options).pipe(
24-
filter((event) => !('stage' in event) || event.stage !== 'download'),
24+
filter((event: any) => event.stage !== 'download'),
2525
map((event) => ({
2626
...event,
27-
progress: event.type === 'complete' ? 100 : 2 + (event.percent / 100) * 98,
27+
progress: 2 + (event.percent / 100) * 98,
2828
})),
29+
2930
map((event) => {
3031
if (event.type === 'complete') {
3132
return createUploadEvent([

packages/sanity/src/core/form/studio/uploads/uploaders.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ import {type SanityClient} from '@sanity/client'
22
import {type SchemaType} from '@sanity/types'
33
import {map} from 'rxjs/operators'
44

5-
import {SUPPORTED_IMAGE_UPLOAD_TYPES} from '../../inputs/files/constants'
65
import {set} from '../../patch'
76
import {type Uploader, type UploaderDef, type UploadOptions} from './types'
87
import {uploadFile} from './uploadFile'
98
import {uploadImage} from './uploadImage'
109

1110
const UPLOAD_IMAGE: UploaderDef = {
1211
type: 'image',
13-
accepts: SUPPORTED_IMAGE_UPLOAD_TYPES.join(','),
12+
accepts: 'image/*',
1413
upload: (client: SanityClient, file: File, type?: SchemaType, options?: UploadOptions) =>
1514
uploadImage(client, file, options),
1615
}

packages/sanity/src/core/studio/components/navbar/search/components/filters/filter/inputs/asset/Asset.tsx

+3-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {styled} from 'styled-components'
77

88
import {Button, MenuButton, MenuItem} from '../../../../../../../../../../ui-components'
99
import {type Source} from '../../../../../../../../../config'
10-
import {SUPPORTED_IMAGE_UPLOAD_TYPES} from '../../../../../../../../../form/inputs/files/constants'
1110
import {FileSource, ImageSource} from '../../../../../../../../../form/studio/assetSource'
1211
import {useClient} from '../../../../../../../../../hooks'
1312
import {useTranslation} from '../../../../../../../../../i18n'
@@ -103,15 +102,13 @@ export function SearchFilterAssetInput(type?: AssetType) {
103102

104103
const AssetSourceComponent = selectedAssetSource?.component
105104

105+
const fontSize = fullscreen ? 2 : 1
106+
106107
const buttonText = t(value ? 'search.filter-asset-change' : 'search.filter-asset-select', {
107108
context: type,
108109
})
109110

110-
const accept = get(
111-
type,
112-
'options.accept',
113-
type === 'image' ? SUPPORTED_IMAGE_UPLOAD_TYPES.join(',') : '',
114-
)
111+
const accept = get(type, 'options.accept', type === 'image' ? 'image/*' : '')
115112

116113
return (
117114
<ContainerBox>

0 commit comments

Comments
 (0)