Skip to content

Commit 3f55afa

Browse files
author
Kent Kwee
committed
feature(redux-devtools-inspector-monitor): add option to sort state tree alphabetically and/or disable collections
1 parent cc5d7b7 commit 3f55afa

File tree

8 files changed

+98
-26
lines changed

8 files changed

+98
-26
lines changed

.changeset/plenty-gifts-watch.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'remotedev-redux-devtools-extension': minor
3+
'@redux-devtools/inspector-monitor': minor
4+
---
5+
6+
Option to sort State Tree keys alphabetically
7+
Option to disable collapsing of object keys

extension/src/options/Options.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import AllowToRunGroup from './AllowToRunGroup';
55
import MiscellaneousGroup from './MiscellaneousGroup';
66
import ContextMenuGroup from './ContextMenuGroup';
77
import { Options } from './syncOptions';
8+
import JsonTree from './StateTree';
89

910
export interface OptionsProps {
1011
readonly options: Options;
@@ -18,6 +19,7 @@ export default (props: OptionsProps) => (
1819
<div>
1920
<EditorGroup {...props} />
2021
<FilterGroup {...props} />
22+
<JsonTree {...props} />
2123
<AllowToRunGroup {...props} />
2224
<MiscellaneousGroup {...props} />
2325
<ContextMenuGroup {...props} />

extension/src/options/StateTree.tsx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React from 'react';
2+
import { OptionsProps } from './Options';
3+
4+
export default ({ options, saveOption }: OptionsProps) => {
5+
return (
6+
<fieldset className="option-group">
7+
<legend className="option-group__title">State Tree</legend>
8+
9+
<div className="option option_type_checkbox">
10+
<input
11+
className="option__element"
12+
id="sortStateTreeAlphabetically"
13+
type="checkbox"
14+
checked={options.sortStateTreeAlphabetically}
15+
onChange={(e) =>
16+
saveOption('sortStateTreeAlphabetically', e.target.checked)
17+
}
18+
/>
19+
<label className="option__label" htmlFor="sortStateTreeAlphabetically">
20+
Sort State Tree alphabetically
21+
</label>
22+
<div className="option__hint">
23+
Property keys are sorted alphabetically
24+
</div>
25+
</div>
26+
27+
<div className="option option_type_checkbox">
28+
<input
29+
className="option__element"
30+
id="disableStateTreeCollection"
31+
type="checkbox"
32+
checked={options.disableStateTreeCollection}
33+
onChange={(e) =>
34+
saveOption('disableStateTreeCollection', e.target.checked)
35+
}
36+
/>
37+
<label className="option__label" htmlFor="disableStateTreeCollection">
38+
Disable State Tree Collection
39+
</label>
40+
<div className="option__hint">Prevents collapsing of object keys</div>
41+
</div>
42+
</fieldset>
43+
);
44+
};

extension/src/options/syncOptions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export interface Options {
1212
readonly inject: boolean;
1313
readonly urls: string;
1414
readonly showContextMenus: boolean;
15+
readonly sortStateTreeAlphabetically: boolean;
16+
readonly disableStateTreeCollection: boolean;
1517
}
1618

1719
interface OldOrNewOptions {
@@ -32,6 +34,8 @@ interface OldOrNewOptions {
3234
readonly inject: boolean;
3335
readonly urls: string;
3436
readonly showContextMenus: boolean;
37+
readonly sortStateTreeAlphabetically: boolean;
38+
readonly disableStateTreeCollection: boolean;
3539
}
3640

3741
let options: Options | undefined;

packages/redux-devtools-inspector-monitor/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"@types/dragula": "^3.7.1",
4040
"@types/lodash": "^4.14.186",
4141
"@types/prop-types": "^15.7.5",
42+
"@types/chrome": "^0.0.198",
4243
"dateformat": "^4.6.3",
4344
"hex-rgba": "^1.0.2",
4445
"immutable": "^4.1.0",

packages/redux-devtools-inspector-monitor/src/tabs/StateTab.tsx

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import React from 'react';
1+
import React, { useEffect, useState } from 'react';
22
import PropTypes from 'prop-types';
33
import { JSONTree } from 'react-json-tree';
44
import { Action } from 'redux';
55
import getItemString from './getItemString';
66
import getJsonTreeTheme from './getJsonTreeTheme';
77
import { TabComponentProps } from '../ActionPreview';
88

9+
const isFF = navigator.userAgent.indexOf('Firefox') !== -1;
10+
911
const 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

3255
StateTab.propTypes = {
3356
nextState: PropTypes.any.isRequired,

packages/redux-devtools-inspector-monitor/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"extends": "../../tsconfig.react.base.json",
33
"compilerOptions": {
44
"outDir": "lib/types",
5-
"resolveJsonModule": true
5+
"resolveJsonModule": true,
6+
"types": ["chrome"]
67
},
78
"include": ["src"]
89
}

pnpm-lock.yaml

Lines changed: 2 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)