Fixed path not being updated in nodes
This commit is contained in:
parent
ec987385c8
commit
a62b1e1c94
|
@ -1,6 +1,7 @@
|
|||
import { createElement as h, PureComponent } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import initial from 'lodash/initial'
|
||||
import isEqual from 'lodash/isEqual'
|
||||
import naturalSort from 'javascript-natural-sort'
|
||||
|
||||
import FloatingMenu from './menu/FloatingMenu'
|
||||
|
@ -41,12 +42,22 @@ export default class JSONNode extends PureComponent {
|
|||
menu: null, // can contain object {anchor, root}
|
||||
appendMenu: null, // can contain object {anchor, root}
|
||||
hover: null,
|
||||
path: this.props.parentPath
|
||||
? this.props.parentPath.concat('index' in this.props ? this.props.index : this.props.prop)
|
||||
: []
|
||||
path: null // initialized via getDerivedStateFromProps
|
||||
}
|
||||
}
|
||||
|
||||
static getDerivedStateFromProps(props, state) {
|
||||
const path = props.parentPath
|
||||
? props.parentPath.concat('index' in props ? props.index : props.prop)
|
||||
: []
|
||||
|
||||
// only update the path in the state if there is actually something changed,
|
||||
// else we get unnecessary re-rendering of all nodes
|
||||
return isEqual(path, state.path)
|
||||
? null
|
||||
: { path }
|
||||
}
|
||||
|
||||
componentWillUnmount () {
|
||||
if (hoveredNode === this) {
|
||||
hoveredNode = null
|
||||
|
|
|
@ -956,8 +956,6 @@ export default class TreeMode extends PureComponent {
|
|||
throw new TypeError('Array with patch actions expected')
|
||||
}
|
||||
|
||||
console.log('patch', operations) // TODO: cleanup
|
||||
|
||||
const jsonResult = immutableJSONPatch(this.state.json, operations)
|
||||
const esonResult = immutableESONPatch(this.state.eson, operations)
|
||||
|
||||
|
|
Loading…
Reference in New Issue