fix: removes nested array field configs from array value (#3549)

* fix: array controls 'addBelow' was adding above
This commit is contained in:
Jarrod Flesch
2023-10-10 15:55:00 -04:00
committed by GitHub
parent a42e84bbb2
commit af892ecb0e
11 changed files with 95 additions and 38 deletions

View File

@@ -10,8 +10,6 @@ export const AddCustomBlocks: React.FC = () => {
const { addFieldRow, replaceFieldRow } = useForm()
const { value } = useField({ path: 'customBlocks' })
const nextIndex = Array.isArray(value) ? value.length : 0
return (
<div className={baseClass}>
<div className={`${baseClass}__blocks-grid`}>
@@ -21,7 +19,6 @@ export const AddCustomBlocks: React.FC = () => {
addFieldRow({
data: { block1Title: 'Block 1: Prefilled Title', blockType: 'block-1' },
path: 'customBlocks',
rowIndex: nextIndex,
})
}
type="button"
@@ -35,7 +32,6 @@ export const AddCustomBlocks: React.FC = () => {
addFieldRow({
data: { block2Title: 'Block 2: Prefilled Title', blockType: 'block-2' },
path: 'customBlocks',
rowIndex: nextIndex,
})
}
type="button"
@@ -51,12 +47,12 @@ export const AddCustomBlocks: React.FC = () => {
replaceFieldRow({
data: { block1Title: 'REPLACED BLOCK', blockType: 'block-1' },
path: 'customBlocks',
rowIndex: nextIndex - 1,
rowIndex: (Array.isArray(value) ? value.length : 0) - 1,
})
}
type="button"
>
Replace Block {nextIndex}
Replace Block {Array.isArray(value) ? value.length : 0}
</button>
</div>
</div>

View File

@@ -1,8 +1,7 @@
import type { CollectionConfig } from '../../../../packages/payload/src/collections/config/types'
import { CollapsibleLabelComponent } from './LabelComponent'
export const collapsibleFieldsSlug = 'collapsible-fields'
import { collapsibleFieldsSlug } from './shared'
const CollapsibleFields: CollectionConfig = {
slug: collapsibleFieldsSlug,

View File

@@ -0,0 +1 @@
export const collapsibleFieldsSlug = 'collapsible-fields'

View File

@@ -9,7 +9,7 @@ import wait from '../../packages/payload/src/utilities/wait'
import { saveDocAndAssert, saveDocHotkeyAndAssert } from '../helpers'
import { AdminUrlUtil } from '../helpers/adminUrlUtil'
import { initPayloadE2E } from '../helpers/configHelpers'
import { collapsibleFieldsSlug } from './collections/Collapsible'
import { collapsibleFieldsSlug } from './collections/Collapsible/shared'
import { jsonDoc } from './collections/JSON'
import { numberDoc } from './collections/Number'
import { pointFieldsSlug } from './collections/Point'