From 26371757d8f861f534c4b4f23167d16730c091ac Mon Sep 17 00:00:00 2001 From: Regis Millet Date: Tue, 15 Jun 2021 00:07:53 +0200 Subject: [PATCH] fix(compilation): Fixing the searchModeOn compilation problem (#482) Co-authored-by: Hrusikesh Panda --- src/tree/index.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/tree/index.js b/src/tree/index.js index 95690fca..f9d9bf01 100644 --- a/src/tree/index.js +++ b/src/tree/index.js @@ -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, @@ -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, @@ -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(