Skip to content

Commit b1ae749

Browse files
authored
fix(ui): render preview sizes button when adjustments are disabled but image sizes are defined (#12999)
### What? The "Preview Sizes" button in the file upload UI was not showing up if: - `crop` and `focalPoint` were both `false` - No `customUploadActions` were provided - But image sizes were configured ### Why? This happened because `UploadActions` wasn’t rendered at all unless adjustments or custom actions were present. ### How? Update the conditional in `StaticFileDetails` to also render `UploadActions` when: - `hasImageSizes` is `true` and the document has a `filename` Fixes #12832
1 parent 3f30a2e commit b1ae749

File tree

6 files changed

+228
-6
lines changed

6 files changed

+228
-6
lines changed

packages/ui/src/elements/FileDetails/StaticFileDetails/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export const StaticFileDetails: React.FC<StaticFileDetailsProps> = (props) => {
6363
width={width as number}
6464
/>
6565

66-
{(enableAdjustments || customUploadActions) && (
66+
{(enableAdjustments || (hasImageSizes && doc.filename) || customUploadActions) && (
6767
<UploadActions
6868
customActions={customUploadActions}
6969
enableAdjustments={Boolean(enableAdjustments)}

packages/ui/src/elements/Upload/index.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,16 @@ export const Upload_v4: React.FC<UploadProps_v4> = (props) => {
304304
setUploadStatus('failed')
305305
}
306306
}, [
307+
api,
308+
collectionSlug,
307309
fileUrl,
308-
uploadConfig,
309-
setUploadStatus,
310310
handleFileChange,
311-
useServerSideFetch,
312-
collectionSlug,
313311
id,
314312
serverURL,
315-
api,
313+
setUploadStatus,
314+
uploadConfig,
315+
uploadControlFileName,
316+
useServerSideFetch,
316317
])
317318

318319
useEffect(() => {

test/uploads/config.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
enlargeSlug,
2424
focalNoSizesSlug,
2525
hideFileInputOnCreateSlug,
26+
imageSizesOnlySlug,
2627
listViewPreviewSlug,
2728
mediaSlug,
2829
mediaWithoutCacheTagsSlug,
@@ -296,6 +297,26 @@ export default buildConfigWithDefaults({
296297
staticDir: path.resolve(dirname, './focal-only'),
297298
},
298299
},
300+
{
301+
slug: imageSizesOnlySlug,
302+
fields: [],
303+
upload: {
304+
crop: false,
305+
focalPoint: false,
306+
imageSizes: [
307+
{
308+
name: 'sizeOne',
309+
height: 300,
310+
width: 400,
311+
},
312+
{
313+
name: 'sizeTwo',
314+
height: 400,
315+
width: 300,
316+
},
317+
],
318+
},
319+
},
299320
{
300321
slug: focalNoSizesSlug,
301322
fields: [],

test/uploads/e2e.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
customUploadFieldSlug,
3434
focalOnlySlug,
3535
hideFileInputOnCreateSlug,
36+
imageSizesOnlySlug,
3637
listViewPreviewSlug,
3738
mediaSlug,
3839
mediaWithoutCacheTagsSlug,
@@ -64,6 +65,7 @@ let adminThumbnailWithSearchQueriesURL: AdminUrlUtil
6465
let listViewPreviewURL: AdminUrlUtil
6566
let mediaWithoutCacheTagsSlugURL: AdminUrlUtil
6667
let focalOnlyURL: AdminUrlUtil
68+
let imageSizesOnlyURL: AdminUrlUtil
6769
let withMetadataURL: AdminUrlUtil
6870
let withoutMetadataURL: AdminUrlUtil
6971
let withOnlyJPEGMetadataURL: AdminUrlUtil
@@ -103,6 +105,7 @@ describe('Uploads', () => {
103105
listViewPreviewURL = new AdminUrlUtil(serverURL, listViewPreviewSlug)
104106
mediaWithoutCacheTagsSlugURL = new AdminUrlUtil(serverURL, mediaWithoutCacheTagsSlug)
105107
focalOnlyURL = new AdminUrlUtil(serverURL, focalOnlySlug)
108+
imageSizesOnlyURL = new AdminUrlUtil(serverURL, imageSizesOnlySlug)
106109
withMetadataURL = new AdminUrlUtil(serverURL, withMetadataSlug)
107110
withoutMetadataURL = new AdminUrlUtil(serverURL, withoutMetadataSlug)
108111
withOnlyJPEGMetadataURL = new AdminUrlUtil(serverURL, withOnlyJPEGMetadataSlug)
@@ -872,6 +875,23 @@ describe('Uploads', () => {
872875
expect(href).not.toMatch(/-\d+x\d+\.png$/)
873876
})
874877

878+
test('should show preview button if image sizes are defined but crop and focal point are not', async () => {
879+
await page.goto(imageSizesOnlyURL.create)
880+
881+
const fileChooserPromise = page.waitForEvent('filechooser')
882+
await page.getByText('Select a file').click()
883+
const fileChooser = await fileChooserPromise
884+
await wait(1000)
885+
await fileChooser.setFiles(path.join(dirname, 'test-image.jpg'))
886+
887+
await page.waitForSelector('button#action-save')
888+
await page.locator('button#action-save').click()
889+
await expect(page.locator('.payload-toast-container')).toContainText('successfully')
890+
await wait(1000) // Wait for the save
891+
892+
await expect(page.locator('.file-field__previewSizes')).toBeVisible()
893+
})
894+
875895
describe('bulk uploads', () => {
876896
test('should bulk upload multiple files', async () => {
877897
// Navigate to the upload creation page

test/uploads/payload-types.ts

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,12 @@ export interface Config {
7878
'with-only-jpeg-meta-data': WithOnlyJpegMetaDatum;
7979
'crop-only': CropOnly;
8080
'focal-only': FocalOnly;
81+
'image-sizes-only': ImageSizesOnly;
8182
'focal-no-sizes': FocalNoSize;
8283
media: Media;
8384
'allow-list-media': AllowListMedia;
85+
'skip-safe-fetch-media': SkipSafeFetchMedia;
86+
'skip-allow-list-safe-fetch-media': SkipAllowListSafeFetchMedia;
8487
'animated-type-media': AnimatedTypeMedia;
8588
enlarge: Enlarge;
8689
'without-enlarge': WithoutEnlarge;
@@ -126,9 +129,12 @@ export interface Config {
126129
'with-only-jpeg-meta-data': WithOnlyJpegMetaDataSelect<false> | WithOnlyJpegMetaDataSelect<true>;
127130
'crop-only': CropOnlySelect<false> | CropOnlySelect<true>;
128131
'focal-only': FocalOnlySelect<false> | FocalOnlySelect<true>;
132+
'image-sizes-only': ImageSizesOnlySelect<false> | ImageSizesOnlySelect<true>;
129133
'focal-no-sizes': FocalNoSizesSelect<false> | FocalNoSizesSelect<true>;
130134
media: MediaSelect<false> | MediaSelect<true>;
131135
'allow-list-media': AllowListMediaSelect<false> | AllowListMediaSelect<true>;
136+
'skip-safe-fetch-media': SkipSafeFetchMediaSelect<false> | SkipSafeFetchMediaSelect<true>;
137+
'skip-allow-list-safe-fetch-media': SkipAllowListSafeFetchMediaSelect<false> | SkipAllowListSafeFetchMediaSelect<true>;
132138
'animated-type-media': AnimatedTypeMediaSelect<false> | AnimatedTypeMediaSelect<true>;
133139
enlarge: EnlargeSelect<false> | EnlargeSelect<true>;
134140
'without-enlarge': WithoutEnlargeSelect<false> | WithoutEnlargeSelect<true>;
@@ -720,6 +726,42 @@ export interface FocalOnly {
720726
};
721727
};
722728
}
729+
/**
730+
* This interface was referenced by `Config`'s JSON-Schema
731+
* via the `definition` "image-sizes-only".
732+
*/
733+
export interface ImageSizesOnly {
734+
id: string;
735+
updatedAt: string;
736+
createdAt: string;
737+
url?: string | null;
738+
thumbnailURL?: string | null;
739+
filename?: string | null;
740+
mimeType?: string | null;
741+
filesize?: number | null;
742+
width?: number | null;
743+
height?: number | null;
744+
focalX?: number | null;
745+
focalY?: number | null;
746+
sizes?: {
747+
sizeOne?: {
748+
url?: string | null;
749+
width?: number | null;
750+
height?: number | null;
751+
mimeType?: string | null;
752+
filesize?: number | null;
753+
filename?: string | null;
754+
};
755+
sizeTwo?: {
756+
url?: string | null;
757+
width?: number | null;
758+
height?: number | null;
759+
mimeType?: string | null;
760+
filesize?: number | null;
761+
filename?: string | null;
762+
};
763+
};
764+
}
723765
/**
724766
* This interface was referenced by `Config`'s JSON-Schema
725767
* via the `definition` "focal-no-sizes".
@@ -756,6 +798,42 @@ export interface AllowListMedia {
756798
focalX?: number | null;
757799
focalY?: number | null;
758800
}
801+
/**
802+
* This interface was referenced by `Config`'s JSON-Schema
803+
* via the `definition` "skip-safe-fetch-media".
804+
*/
805+
export interface SkipSafeFetchMedia {
806+
id: string;
807+
updatedAt: string;
808+
createdAt: string;
809+
url?: string | null;
810+
thumbnailURL?: string | null;
811+
filename?: string | null;
812+
mimeType?: string | null;
813+
filesize?: number | null;
814+
width?: number | null;
815+
height?: number | null;
816+
focalX?: number | null;
817+
focalY?: number | null;
818+
}
819+
/**
820+
* This interface was referenced by `Config`'s JSON-Schema
821+
* via the `definition` "skip-allow-list-safe-fetch-media".
822+
*/
823+
export interface SkipAllowListSafeFetchMedia {
824+
id: string;
825+
updatedAt: string;
826+
createdAt: string;
827+
url?: string | null;
828+
thumbnailURL?: string | null;
829+
filename?: string | null;
830+
mimeType?: string | null;
831+
filesize?: number | null;
832+
width?: number | null;
833+
height?: number | null;
834+
focalX?: number | null;
835+
focalY?: number | null;
836+
}
759837
/**
760838
* This interface was referenced by `Config`'s JSON-Schema
761839
* via the `definition` "animated-type-media".
@@ -1402,6 +1480,13 @@ export interface User {
14021480
hash?: string | null;
14031481
loginAttempts?: number | null;
14041482
lockUntil?: string | null;
1483+
sessions?:
1484+
| {
1485+
id: string;
1486+
createdAt?: string | null;
1487+
expiresAt: string;
1488+
}[]
1489+
| null;
14051490
password?: string | null;
14061491
}
14071492
/**
@@ -1455,6 +1540,10 @@ export interface PayloadLockedDocument {
14551540
relationTo: 'focal-only';
14561541
value: string | FocalOnly;
14571542
} | null)
1543+
| ({
1544+
relationTo: 'image-sizes-only';
1545+
value: string | ImageSizesOnly;
1546+
} | null)
14581547
| ({
14591548
relationTo: 'focal-no-sizes';
14601549
value: string | FocalNoSize;
@@ -1467,6 +1556,14 @@ export interface PayloadLockedDocument {
14671556
relationTo: 'allow-list-media';
14681557
value: string | AllowListMedia;
14691558
} | null)
1559+
| ({
1560+
relationTo: 'skip-safe-fetch-media';
1561+
value: string | SkipSafeFetchMedia;
1562+
} | null)
1563+
| ({
1564+
relationTo: 'skip-allow-list-safe-fetch-media';
1565+
value: string | SkipAllowListSafeFetchMedia;
1566+
} | null)
14701567
| ({
14711568
relationTo: 'animated-type-media';
14721569
value: string | AnimatedTypeMedia;
@@ -1997,6 +2094,47 @@ export interface FocalOnlySelect<T extends boolean = true> {
19972094
};
19982095
};
19992096
}
2097+
/**
2098+
* This interface was referenced by `Config`'s JSON-Schema
2099+
* via the `definition` "image-sizes-only_select".
2100+
*/
2101+
export interface ImageSizesOnlySelect<T extends boolean = true> {
2102+
updatedAt?: T;
2103+
createdAt?: T;
2104+
url?: T;
2105+
thumbnailURL?: T;
2106+
filename?: T;
2107+
mimeType?: T;
2108+
filesize?: T;
2109+
width?: T;
2110+
height?: T;
2111+
focalX?: T;
2112+
focalY?: T;
2113+
sizes?:
2114+
| T
2115+
| {
2116+
sizeOne?:
2117+
| T
2118+
| {
2119+
url?: T;
2120+
width?: T;
2121+
height?: T;
2122+
mimeType?: T;
2123+
filesize?: T;
2124+
filename?: T;
2125+
};
2126+
sizeTwo?:
2127+
| T
2128+
| {
2129+
url?: T;
2130+
width?: T;
2131+
height?: T;
2132+
mimeType?: T;
2133+
filesize?: T;
2134+
filename?: T;
2135+
};
2136+
};
2137+
}
20002138
/**
20012139
* This interface was referenced by `Config`'s JSON-Schema
20022140
* via the `definition` "focal-no-sizes_select".
@@ -2212,6 +2350,40 @@ export interface AllowListMediaSelect<T extends boolean = true> {
22122350
focalX?: T;
22132351
focalY?: T;
22142352
}
2353+
/**
2354+
* This interface was referenced by `Config`'s JSON-Schema
2355+
* via the `definition` "skip-safe-fetch-media_select".
2356+
*/
2357+
export interface SkipSafeFetchMediaSelect<T extends boolean = true> {
2358+
updatedAt?: T;
2359+
createdAt?: T;
2360+
url?: T;
2361+
thumbnailURL?: T;
2362+
filename?: T;
2363+
mimeType?: T;
2364+
filesize?: T;
2365+
width?: T;
2366+
height?: T;
2367+
focalX?: T;
2368+
focalY?: T;
2369+
}
2370+
/**
2371+
* This interface was referenced by `Config`'s JSON-Schema
2372+
* via the `definition` "skip-allow-list-safe-fetch-media_select".
2373+
*/
2374+
export interface SkipAllowListSafeFetchMediaSelect<T extends boolean = true> {
2375+
updatedAt?: T;
2376+
createdAt?: T;
2377+
url?: T;
2378+
thumbnailURL?: T;
2379+
filename?: T;
2380+
mimeType?: T;
2381+
filesize?: T;
2382+
width?: T;
2383+
height?: T;
2384+
focalX?: T;
2385+
focalY?: T;
2386+
}
22152387
/**
22162388
* This interface was referenced by `Config`'s JSON-Schema
22172389
* via the `definition` "animated-type-media_select".
@@ -2907,6 +3079,13 @@ export interface UsersSelect<T extends boolean = true> {
29073079
hash?: T;
29083080
loginAttempts?: T;
29093081
lockUntil?: T;
3082+
sessions?:
3083+
| T
3084+
| {
3085+
id?: T;
3086+
createdAt?: T;
3087+
expiresAt?: T;
3088+
};
29103089
}
29113090
/**
29123091
* This interface was referenced by `Config`'s JSON-Schema

test/uploads/shared.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const enlargeSlug = 'enlarge'
66
export const withoutEnlargeSlug = 'without-enlarge'
77
export const focalNoSizesSlug = 'focal-no-sizes'
88
export const focalOnlySlug = 'focal-only'
9+
export const imageSizesOnlySlug = 'image-sizes-only'
910
export const reduceSlug = 'reduce'
1011
export const relationPreviewSlug = 'relation-preview'
1112
export const mediaWithRelationPreviewSlug = 'media-with-relation-preview'

0 commit comments

Comments
 (0)