chore: mirror changes from PR #3276 (#3284)

This commit is contained in:
Jarrod Flesch
2023-09-07 11:06:57 -04:00
committed by GitHub
parent 1092ae6f98
commit abd983f421
4 changed files with 18 additions and 6 deletions

View File

@@ -265,6 +265,20 @@ export const addFieldStatePromise = async ({
break
}
case 'relationship':
case 'upload': {
const relationshipValue =
valueWithDefault && typeof valueWithDefault === 'object' && 'id' in valueWithDefault
? valueWithDefault.id
: valueWithDefault
fieldState.value = relationshipValue
fieldState.initialValue = relationshipValue
state[`${path}${field.name}`] = fieldState
break
}
default: {
fieldState.value = valueWithDefault
fieldState.initialValue = valueWithDefault

View File

@@ -105,7 +105,7 @@ const GlobalView: React.FC<IndexProps> = (props) => {
CustomComponent={CustomEdit}
DefaultComponent={DefaultGlobal}
componentProps={{
action: `${serverURL}${api}/globals/${slug}?locale=${locale}&depth=0&fallback-locale=null`,
action: `${serverURL}${api}/globals/${slug}?locale=${locale}&fallback-locale=null`,
apiURL: `${serverURL}${api}/globals/${slug}?locale=${locale}${
global.versions?.drafts ? '&draft=true' : ''
}`,

View File

@@ -112,7 +112,7 @@ const EditView: React.FC<IndexProps> = (props) => {
}`
const action = `${serverURL}${api}/${slug}${
isEditing ? `/${id}` : ''
}?locale=${locale}&depth=0&fallback-locale=null`
}?locale=${locale}&fallback-locale=null`
const hasSavePermission =
(isEditing && docPermissions?.update?.permission) ||
(!isEditing && (docPermissions as CollectionPermission)?.create?.permission)

View File

@@ -2,8 +2,6 @@
import type { CollectionConfig } from '../../../../packages/payload/src/collections/config/types'
import type { PayloadRequest } from '../../../../packages/payload/src/types'
import payload from '../../../../packages/payload/src'
export const contextHooksSlug = 'context-hooks'
const ContextHooks: CollectionConfig = {
slug: contextHooksSlug,
@@ -47,12 +45,12 @@ const ContextHooks: CollectionConfig = {
},
],
afterChange: [
async ({ context, doc }) => {
async ({ context, doc, req }) => {
if (context.triggerAfterChange === false) {
// Make sure we don't trigger afterChange again and again in an infinite loop
return
}
await payload.update({
await req.payload.update({
collection: contextHooksSlug,
id: doc.id,
data: {