Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
faff65c
fix: do not send duplicate upload edit data on request
PatrikKozak Jul 11, 2024
9be0114
Merge branch 'beta' of https://github.com/payloadcms/payload into fix…
PatrikKozak Jul 11, 2024
50a27b5
fix: removes FormQueryParams provider for UploadEditsProvider
PatrikKozak Jul 15, 2024
717ff96
Merge branch 'beta' into fix/beta/uploads-in-drawer
PatrikKozak Jul 15, 2024
71e6ef1
fix: simplifies if statement to remove need for actionEndpoint var
PatrikKozak Jul 15, 2024
0907e99
Merge branch 'fix/beta/uploads-in-drawer' of https://github.com/paylo…
PatrikKozak Jul 15, 2024
0a46385
Merge branch 'beta' of https://github.com/payloadcms/payload into fix…
PatrikKozak Jul 15, 2024
31956dc
fix: adds locale to dep array in default edit view
PatrikKozak Jul 15, 2024
16a017a
Merge branch 'beta' of https://github.com/payloadcms/payload into fix…
PatrikKozak Jul 15, 2024
c33f84b
fix: adds resetUploadEdits to dep array
PatrikKozak Jul 15, 2024
aa674fd
Merge branch 'beta' of https://github.com/payloadcms/payload into fix…
PatrikKozak Jul 15, 2024
f8dd65a
chore: adds updateUploadEdits to dep array in onEditsSave
PatrikKozak Jul 16, 2024
538c271
Merge branch 'beta' of https://github.com/payloadcms/payload into fix…
PatrikKozak Jul 16, 2024
8c4bbe1
chore: fixes focal point cropping
JarrodMFlesch Jul 16, 2024
8dff5d8
chore: adds e2e test for incorrect resized animated image file names
PatrikKozak Jul 17, 2024
a3fd9be
Merge branch 'beta' of https://github.com/payloadcms/payload into fix…
PatrikKozak Jul 17, 2024
7a60357
chore: consolidate resize logic
JarrodMFlesch Jul 17, 2024
6e38be8
chore: stubs out e2e test for focal point issue updates
PatrikKozak Jul 17, 2024
36c85bd
Merge branch 'beta' of https://github.com/payloadcms/payload into fix…
PatrikKozak Jul 18, 2024
1ebc1c6
fix: jarrods negligence
PatrikKozak Jul 18, 2024
a9c69ce
fix: updates focal point e2e test
PatrikKozak Jul 18, 2024
49cb27a
Merge branch 'beta' of https://github.com/payloadcms/payload into fix…
PatrikKozak Jul 18, 2024
2daa52a
chore: update image file name
PatrikKozak Jul 18, 2024
f0dcfb7
Merge branch 'beta' of https://github.com/payloadcms/payload into fix…
PatrikKozak Jul 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions docs/migration-guide/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ import {
useFormInitializing,
useFormModified,
useFormProcessing,
useFormQueryParams,
useFormSubmitted,
useHotkey,
useIntersect,
Expand Down Expand Up @@ -221,7 +220,6 @@ import {
EntityVisibilityProvider,
FieldComponentsProvider,
FieldPropsProvider,
FormQueryParamsProvider,
ListInfoProvider,
ListQueryProvider,
LocaleProvider,
Expand Down
42 changes: 16 additions & 26 deletions packages/next/src/views/Account/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AdminViewProps, ServerSideEditViewProps } from 'payload'

import { DocumentInfoProvider, FormQueryParamsProvider, HydrateClientUser } from '@payloadcms/ui'
import { DocumentInfoProvider, HydrateClientUser } from '@payloadcms/ui'
import { RenderCustomComponent } from '@payloadcms/ui/shared'
import { notFound } from 'next/navigation.js'
import React from 'react'
Expand Down Expand Up @@ -65,7 +65,6 @@ export const Account: React.FC<AdminViewProps> = async ({
return (
<DocumentInfoProvider
AfterFields={<Settings i18n={i18n} languageOptions={languageOptions} />}
action={`${serverURL}${api}/${userSlug}${user?.id ? `/${user.id}` : ''}`}
apiURL={`${serverURL}${api}/${userSlug}${user?.id ? `/${user.id}` : ''}`}
collectionSlug={userSlug}
docPermissions={docPermissions}
Expand All @@ -84,31 +83,22 @@ export const Account: React.FC<AdminViewProps> = async ({
permissions={permissions}
/>
<HydrateClientUser permissions={permissions} user={user} />
<FormQueryParamsProvider
initialParams={{
depth: 0,
'fallback-locale': 'null',
locale: locale?.code,
uploadEdits: undefined,
<RenderCustomComponent
CustomComponent={
typeof CustomAccountComponent === 'function' ? CustomAccountComponent : undefined
}
DefaultComponent={EditView}
componentProps={viewComponentProps}
serverOnlyProps={{
i18n,
locale,
params,
payload,
permissions,
searchParams,
user,
}}
>
<RenderCustomComponent
CustomComponent={
typeof CustomAccountComponent === 'function' ? CustomAccountComponent : undefined
}
DefaultComponent={EditView}
componentProps={viewComponentProps}
serverOnlyProps={{
i18n,
locale,
params,
payload,
permissions,
searchParams,
user,
}}
/>
</FormQueryParamsProvider>
/>
</DocumentInfoProvider>
)
}
Expand Down
67 changes: 21 additions & 46 deletions packages/next/src/views/Document/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
import type {
AdminViewComponent,
AdminViewProps,
EditViewComponent,
ServerSideEditViewProps,
} from 'payload'
import type { AdminViewComponent, AdminViewProps, EditViewComponent } from 'payload'

import {
DocumentInfoProvider,
EditDepthProvider,
FormQueryParamsProvider,
HydrateClientUser,
} from '@payloadcms/ui'
import { DocumentInfoProvider, EditDepthProvider, HydrateClientUser } from '@payloadcms/ui'
import { RenderCustomComponent, isEditing as getIsEditing } from '@payloadcms/ui/shared'
import { notFound, redirect } from 'next/navigation.js'
import React from 'react'
Expand Down Expand Up @@ -65,7 +55,6 @@ export const Document: React.FC<AdminViewProps> = async ({
let ErrorView: AdminViewComponent

let apiURL: string
let action: string

const { data, formState } = await getDocumentData({
id,
Expand All @@ -88,8 +77,6 @@ export const Document: React.FC<AdminViewProps> = async ({
notFound()
}

action = `${serverURL}${apiRoute}/${collectionSlug}${isEditing ? `/${id}` : ''}`

const params = new URLSearchParams()
if (collectionConfig.versions?.drafts) {
params.append('draft', 'true')
Expand Down Expand Up @@ -128,8 +115,6 @@ export const Document: React.FC<AdminViewProps> = async ({
notFound()
}

action = `${serverURL}${apiRoute}/globals/${globalSlug}`

const params = new URLSearchParams({
locale: locale?.code,
})
Expand Down Expand Up @@ -198,7 +183,6 @@ export const Document: React.FC<AdminViewProps> = async ({

return (
<DocumentInfoProvider
action={action}
apiURL={apiURL}
collectionSlug={collectionConfig?.slug}
disableActions={false}
Expand All @@ -225,34 +209,25 @@ export const Document: React.FC<AdminViewProps> = async ({
depth={1}
key={`${collectionSlug || globalSlug}${locale?.code ? `-${locale?.code}` : ''}`}
>
<FormQueryParamsProvider
initialParams={{
depth: 0,
'fallback-locale': 'null',
locale: locale?.code,
uploadEdits: undefined,
}}
>
{ErrorView ? (
<ErrorView initPageResult={initPageResult} searchParams={searchParams} />
) : (
<RenderCustomComponent
CustomComponent={ViewOverride || CustomView}
DefaultComponent={DefaultView}
serverOnlyProps={{
i18n,
initPageResult,
locale,
params,
payload,
permissions,
routeSegments: segments,
searchParams,
user,
}}
/>
)}
</FormQueryParamsProvider>
{ErrorView ? (
<ErrorView initPageResult={initPageResult} searchParams={searchParams} />
) : (
<RenderCustomComponent
CustomComponent={ViewOverride || CustomView}
DefaultComponent={DefaultView}
serverOnlyProps={{
i18n,
initPageResult,
locale,
params,
payload,
permissions,
routeSegments: segments,
searchParams,
user,
}}
/>
)}
</EditDepthProvider>
</DocumentInfoProvider>
)
Expand Down
21 changes: 8 additions & 13 deletions packages/next/src/views/Edit/Default/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
useDocumentEvents,
useDocumentInfo,
useEditDepth,
useFormQueryParams,
useUploadEdits,
} from '@payloadcms/ui'
import { getFormState } from '@payloadcms/ui/shared'
import { useRouter, useSearchParams } from 'next/navigation.js'
Expand Down Expand Up @@ -58,11 +58,13 @@ export const DefaultEditView: React.FC = () => {
const { refreshCookieAsync, user } = useAuth()
const config = useConfig()
const router = useRouter()
const { dispatchFormQueryParams } = useFormQueryParams()
const { getComponentMap, getFieldMap } = useComponentMap()
const params = useSearchParams()
const depth = useEditDepth()
const params = useSearchParams()
const { reportUpdate } = useDocumentEvents()
const { resetUploadEdits } = useUploadEdits()

const locale = params.get('locale')

const {
admin: { user: userSlug },
Expand All @@ -72,8 +74,6 @@ export const DefaultEditView: React.FC = () => {
serverURL,
} = config

const locale = params.get('locale')

const collectionConfig =
collectionSlug && collections.find((collection) => collection.slug === collectionSlug)

Expand Down Expand Up @@ -130,12 +130,7 @@ export const DefaultEditView: React.FC = () => {
const redirectRoute = `${adminRoute}/collections/${collectionSlug}/${json?.doc?.id}${locale ? `?locale=${locale}` : ''}`
router.push(redirectRoute)
} else {
dispatchFormQueryParams({
type: 'SET',
params: {
uploadEdits: null,
},
})
resetUploadEdits()
}
},
[
Expand All @@ -151,9 +146,9 @@ export const DefaultEditView: React.FC = () => {
isEditing,
refreshCookieAsync,
adminRoute,
locale,
router,
dispatchFormQueryParams,
locale,
resetUploadEdits,
],
)

Expand Down
27 changes: 23 additions & 4 deletions packages/payload/src/uploads/cropImage.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
import type { SharpOptions } from 'sharp'

import type { SanitizedConfig } from '../config/types.js'
import type { PayloadRequest } from '../types/index.js'
import type { UploadEdits } from './types.js'

export const percentToPixel = (value, dimension) => {
return Math.floor((parseFloat(value) / 100) * dimension)
}

export async function cropImage({ cropData, dimensions, file, sharp }) {
type CropImageArgs = {
cropData: UploadEdits['crop']
dimensions: { height: number; width: number }
file: PayloadRequest['file']
heightInPixels: number
sharp: SanitizedConfig['sharp']
widthInPixels: number
}
export async function cropImage({
cropData,
dimensions,
file,
heightInPixels,
sharp,
widthInPixels,
}: CropImageArgs) {
try {
const { heightPixels, widthPixels, x, y } = cropData
const { x, y } = cropData

const fileIsAnimatedType = ['image/avif', 'image/gif', 'image/webp'].includes(file.mimetype)

Expand All @@ -15,10 +34,10 @@ export async function cropImage({ cropData, dimensions, file, sharp }) {
if (fileIsAnimatedType) sharpOptions.animated = true

const formattedCropData = {
height: Number(heightPixels),
height: Number(heightInPixels),
left: percentToPixel(x, dimensions.width),
top: percentToPixel(y, dimensions.height),
width: Number(widthPixels),
width: Number(widthInPixels),
}

const cropped = sharp(file.tempFilePath || file.data, sharpOptions).extract(formattedCropData)
Expand Down
9 changes: 8 additions & 1 deletion packages/payload/src/uploads/generateFileData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,14 @@ export const generateFileData = async <T>({
let fileForResize = file

if (cropData && sharp) {
const { data: croppedImage, info } = await cropImage({ cropData, dimensions, file, sharp })
const { data: croppedImage, info } = await cropImage({
cropData,
dimensions,
file,
heightInPixels: uploadEdits.heightInPixels,
sharp,
widthInPixels: uploadEdits.widthInPixels,
})

filesToSave.push({
buffer: croppedImage,
Expand Down
Loading