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>