Skip to content
Snippets Groups Projects
Commit 0d98de44 authored by esikkala's avatar esikkala
Browse files

Update changeNodeAtPath

parent 18e71bce
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,7 @@ import PropTypes from 'prop-types' ...@@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
import intl from 'react-intl-universal' import intl from 'react-intl-universal'
import { withStyles } from '@material-ui/core/styles' import { withStyles } from '@material-ui/core/styles'
import { has } from 'lodash' import { has } from 'lodash'
import SortableTree, { changeNodeAtPath, getNodeAtPath } from 'react-sortable-tree' import SortableTree, { changeNodeAtPath } from 'react-sortable-tree'
import FileExplorerTheme from 'react-sortable-tree-theme-file-explorer' import FileExplorerTheme from 'react-sortable-tree-theme-file-explorer'
import Checkbox from '@material-ui/core/Checkbox' import Checkbox from '@material-ui/core/Checkbox'
import FormControlLabel from '@material-ui/core/FormControlLabel' import FormControlLabel from '@material-ui/core/FormControlLabel'
...@@ -95,37 +95,37 @@ class HierarchicalFacet extends Component { ...@@ -95,37 +95,37 @@ class HierarchicalFacet extends Component {
serverFScomponentDidUpdate = prevProps => { serverFScomponentDidUpdate = prevProps => {
// update component state if the user modified this facet // update component state if the user modified this facet
if (prevProps.facetUpdateID !== this.props.facetUpdateID) { if (prevProps.facetUpdateID !== this.props.facetUpdateID) {
// When removing, node may be already removed by the SPARQL query, check for those
if (!this.props.facet.useConjuction && this.props.updatedFacet === this.props.facetID) { if (!this.props.facet.useConjuction && this.props.updatedFacet === this.props.facetID) {
if (has(this.props.updatedFilter, 'path') &&
!this.props.updatedFilter.added &&
!getNodeAtPath(this.props.updatedFilter.path)
) { return }
if (has(this.props.updatedFilter, 'path')) { if (has(this.props.updatedFilter, 'path')) {
const treeObj = this.props.updatedFilter const treeObj = this.props.updatedFilter
const newTreeData = changeNodeAtPath({ try {
treeData: this.state.treeData, const newTreeData = changeNodeAtPath({
getNodeKey: ({ treeIndex }) => treeIndex, treeData: this.state.treeData,
path: treeObj.path, getNodeKey: ({ treeIndex }) => treeIndex,
newNode: () => { path: treeObj.path,
const oldNode = treeObj.node newNode: () => {
if (has(oldNode, 'children')) { const oldNode = treeObj.node
return { if (has(oldNode, 'children')) {
...oldNode, return {
selected: treeObj.added ? 'true' : 'false', ...oldNode,
// select also children by default if 'selectAlsoSubconcepts' is not defined selected: treeObj.added ? 'true' : 'false',
...((!Object.prototype.hasOwnProperty.call(this.props.facet, 'selectAlsoSubconcepts') || this.props.facet.selectAlsoSubconcepts) && // select also children by default if 'selectAlsoSubconcepts' is not defined
{ children: this.recursiveSelect(oldNode.children, treeObj.added) }) ...((!Object.prototype.hasOwnProperty.call(this.props.facet, 'selectAlsoSubconcepts') || this.props.facet.selectAlsoSubconcepts) &&
} { children: this.recursiveSelect(oldNode.children, treeObj.added) })
} else { }
return { } else {
...oldNode, return {
selected: treeObj.added ? 'true' : 'false' ...oldNode,
selected: treeObj.added ? 'true' : 'false'
}
} }
} }
} })
}) this.setState({ treeData: newTreeData })
this.setState({ treeData: newTreeData }) } catch (err) {
// console.log(err)
// Ignore the error -- the null return will be explanation enough
}
} }
} else { // else fetch new values, because some other facet was updated } else { // else fetch new values, because some other facet was updated
// console.log(`fetching new values for ${this.props.facetID}`) // console.log(`fetching new values for ${this.props.facetID}`)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment