mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2025-07-22 14:09:46 +03:00
add collapse/expand all feature for react-json-tree
This commit is contained in:
parent
58a8135b08
commit
5961ae4cba
|
@ -1,4 +1,4 @@
|
|||
import React, { useCallback, useState } from 'react';
|
||||
import React, { useCallback, useEffect, useState } from 'react';
|
||||
import JSONArrow from './JSONArrow';
|
||||
import getCollectionEntries from './getCollectionEntries';
|
||||
import JSONNode from './JSONNode';
|
||||
|
@ -110,6 +110,7 @@ export default function JSONNestedNode(props: Props) {
|
|||
nodeType,
|
||||
nodeTypeIndicator,
|
||||
shouldExpandNodeInitially,
|
||||
shouldExpandNode,
|
||||
styling,
|
||||
} = props;
|
||||
|
||||
|
@ -118,6 +119,15 @@ export default function JSONNestedNode(props: Props) {
|
|||
isCircular ? false : shouldExpandNodeInitially(keyPath, data, level)
|
||||
);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if(shouldExpandNode === undefined){
|
||||
return
|
||||
}
|
||||
|
||||
setExpanded(shouldExpandNode);
|
||||
}, [shouldExpandNode])
|
||||
|
||||
const handleClick = useCallback(() => {
|
||||
if (expandable) setExpanded(!expanded);
|
||||
}, [expandable, expanded]);
|
||||
|
|
|
@ -41,6 +41,7 @@ export function JSONTree({
|
|||
labelRenderer = defaultLabelRenderer,
|
||||
valueRenderer = identity,
|
||||
shouldExpandNodeInitially = expandRootNode,
|
||||
shouldExpandNode,
|
||||
hideRoot = false,
|
||||
getItemString = defaultItemString,
|
||||
postprocessValue = identity,
|
||||
|
@ -64,6 +65,7 @@ export function JSONTree({
|
|||
labelRenderer={labelRenderer}
|
||||
valueRenderer={valueRenderer}
|
||||
shouldExpandNodeInitially={shouldExpandNodeInitially}
|
||||
shouldExpandNode={shouldExpandNode}
|
||||
hideRoot={hideRoot}
|
||||
getItemString={getItemString}
|
||||
postprocessValue={postprocessValue}
|
||||
|
|
|
@ -47,6 +47,7 @@ export interface CommonExternalProps {
|
|||
labelRenderer: LabelRenderer;
|
||||
valueRenderer: ValueRenderer;
|
||||
shouldExpandNodeInitially: ShouldExpandNodeInitially;
|
||||
shouldExpandNode: boolean | undefined;
|
||||
hideRoot: boolean;
|
||||
getItemString: GetItemString;
|
||||
postprocessValue: PostprocessValue;
|
||||
|
|
Loading…
Reference in New Issue
Block a user