Skip to content

Commit

Permalink
fix: should handle key and path of nested grouped array with nestedIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
pionxzh committed Nov 4, 2023
1 parent c4037a5 commit 47497ad
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/components/DataKeyPair.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,9 @@ export const DataKeyPair: FC<DataKeyPairProps> = (props) => {
inspect,
setInspect,
value,
prevValue
}), [inspect, path, setInspect, value, prevValue])
prevValue,
nestedIndex
}), [inspect, path, setInspect, value, prevValue, nestedIndex])
return (
<Box
className='data-key-pair'
Expand Down
3 changes: 2 additions & 1 deletion src/components/DataTypes/Object.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ const ObjectType: FC<DataItemProps<object>> = (props) => {
if (Array.isArray(value)) {
// unknown[]
if (value.length <= groupArraysAfterLength) {
const elements = value.slice(0, displayLength).map((value, index) => {
const elements = value.slice(0, displayLength).map((value, _index) => {
const index = props.nestedIndex ? (props.nestedIndex * groupArraysAfterLength) + _index : _index
const path = [...props.path, index]
return (
<DataKeyPair
Expand Down
1 change: 1 addition & 0 deletions src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface DataItemProps<ValueType = unknown> {
value: ValueType
prevValue: ValueType | undefined
path: Path
nestedIndex?: number
}

export type EditorProps<ValueType = unknown> = {
Expand Down

0 comments on commit 47497ad

Please sign in to comment.