1- import React from 'react' ;
1+ import React , { useEffect , useState } from 'react' ;
22import PropTypes from 'prop-types' ;
33import { JSONTree } from 'react-json-tree' ;
44import { Action } from 'redux' ;
55import getItemString from './getItemString' ;
66import getJsonTreeTheme from './getJsonTreeTheme' ;
77import { TabComponentProps } from '../ActionPreview' ;
88
9+ const isFF = navigator . userAgent . indexOf ( 'Firefox' ) !== - 1 ;
10+
911const StateTab : React . FunctionComponent <
1012 TabComponentProps < any , Action < unknown > >
1113> = ( {
@@ -16,18 +18,39 @@ const StateTab: React.FunctionComponent<
1618 labelRenderer,
1719 dataTypeKey,
1820 isWideLayout,
19- } ) => (
20- < JSONTree
21- labelRenderer = { labelRenderer }
22- theme = { getJsonTreeTheme ( base16Theme ) }
23- data = { nextState }
24- getItemString = { ( type , data ) =>
25- getItemString ( styling , type , data , dataTypeKey , isWideLayout )
26- }
27- invertTheme = { invertTheme }
28- hideRoot
29- />
30- ) ;
21+ } ) => {
22+ const [ sortObjectKeys , setSortObjectKeys ] = useState ( false ) ;
23+ const [ disableCollection , setDisableCollection ] = useState ( false ) ;
24+
25+ useEffect ( ( ) => {
26+ if ( ! chrome || ! chrome . storage ) return ;
27+ const storage = isFF
28+ ? chrome . storage . local
29+ : chrome . storage . sync || chrome . storage . local ;
30+ storage . get (
31+ [ 'sortStateTreeAlphabetically' , 'disableStateTreeCollection' ] ,
32+ function ( result ) {
33+ setSortObjectKeys ( ! ! result . sortStateTreeAlphabetically ) ;
34+ setDisableCollection ( ! ! result . disableStateTreeCollection ) ;
35+ }
36+ ) ;
37+ } , [ ] ) ;
38+
39+ return (
40+ < JSONTree
41+ labelRenderer = { labelRenderer }
42+ theme = { getJsonTreeTheme ( base16Theme ) }
43+ data = { nextState }
44+ getItemString = { ( type , data ) =>
45+ getItemString ( styling , type , data , dataTypeKey , isWideLayout )
46+ }
47+ invertTheme = { invertTheme }
48+ hideRoot
49+ sortObjectKeys = { sortObjectKeys }
50+ { ...( disableCollection ? { collectionLimit : 0 } : { } ) }
51+ />
52+ ) ;
53+ } ;
3154
3255StateTab . propTypes = {
3356 nextState : PropTypes . any . isRequired ,
0 commit comments