Skip to content

Commit

Permalink
fix(compilation): Fixing the searchModeOn compilation problem (#482)
Browse files Browse the repository at this point in the history
Co-authored-by: Hrusikesh Panda <mrchief@users.noreply.github.com>
  • Loading branch information
Kulgar and mrchief authored Jun 14, 2021
1 parent d22f809 commit 2637175
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/tree/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,6 @@ import React, { Component } from 'react'
import TreeNode from '../tree-node'
import { findIndex } from '../utils'

const shouldRenderNode = (node, searchModeOn, data) => {
if (searchModeOn || node.expanded) return true

const parent = node._parent && data.get(node._parent)
// if it has a parent, then check parent's state.
// otherwise root nodes are always rendered
return !parent || parent.expanded
}

class Tree extends Component {
static propTypes = {
data: PropTypes.object,
Expand Down Expand Up @@ -68,6 +59,17 @@ class Tree extends Component {
}
}

shouldRenderNode = (node, props) => {
const { data, searchModeOn } = props
const { expanded, _parent } = node
if (searchModeOn || expanded) return true

const parent = _parent && data.get(_parent)
// if it has a parent, then check parent's state.
// otherwise root nodes are always rendered
return !parent || parent.expanded
}

getNodes = props => {
const {
data,
Expand All @@ -86,7 +88,7 @@ class Tree extends Component {
} = props
const items = []
data.forEach(node => {
if (shouldRenderNode(node, searchModeOn, data)) {
if (this.shouldRenderNode(node, props)) {
items.push(
<TreeNode
keepTreeOnSearch={keepTreeOnSearch}
Expand Down

0 comments on commit 2637175

Please sign in to comment.