Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use jsoneditor instead of react-json-tree #1608

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/redux-devtools-inspector-monitor/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
"typescript": "~5.3.3",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1"
"webpack-dev-server": "^4.15.1",
"css-loader": "^6.8.1",
"style-loader": "^3.3.3"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ const config: webpack.Configuration = {
},
},
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
],
},
resolve: {
Expand Down
3 changes: 2 additions & 1 deletion packages/redux-devtools-inspector-monitor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"lodash.debounce": "^4.0.8",
"react-base16-styling": "^0.9.1",
"react-json-tree": "^0.18.0",
"redux-devtools-themes": "^1.0.0"
"redux-devtools-themes": "^1.0.0",
"vanilla-jsoneditor": "^0.21.4"
},
"devDependencies": {
"@babel/cli": "^7.23.4",
Expand Down
25 changes: 11 additions & 14 deletions packages/redux-devtools-inspector-monitor/src/tabs/StateTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Action } from 'redux';
import getItemString from './getItemString';
import getJsonTreeTheme from './getJsonTreeTheme';
import { TabComponentProps } from '../ActionPreview';
import { VanillaJSONEditor } from './VanillaJSONEditor';

const StateTab: React.FunctionComponent<
TabComponentProps<any, Action<string>>
Expand All @@ -16,19 +17,15 @@ const StateTab: React.FunctionComponent<
isWideLayout,
sortStateTreeAlphabetically,
disableStateTreeCollection,
}) => (
<JSONTree
labelRenderer={labelRenderer}
theme={getJsonTreeTheme(base16Theme)}
data={nextState}
getItemString={(type, data) =>
getItemString(type, data, dataTypeKey, isWideLayout)
}
invertTheme={invertTheme}
hideRoot
sortObjectKeys={sortStateTreeAlphabetically}
{...(disableStateTreeCollection ? { collectionLimit: 0 } : {})}
/>
);
}) => {
return (
<VanillaJSONEditor
content={{
json: nextState
}}
readOnly={true}
/>
);
}

export default StateTab;
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React, { useEffect, useRef } from "react";
import 'vanilla-jsoneditor/themes/jse-theme-dark.css'

import { JSONEditor } from "vanilla-jsoneditor";

export const VanillaJSONEditor = (props: any) => {
const refContainer = useRef(null);
const refEditor = useRef(null);

useEffect(() => {
// create editor
console.log("create editor", refContainer.current);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
refEditor.current = new JSONEditor({
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
target: refContainer.current,
props: {}
});

return () => {
// destroy editor
if (refEditor.current) {
console.log("destroy editor");
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
refEditor.current.destroy();
refEditor.current = null;
}
};
}, []);

// update props
useEffect(() => {
if (refEditor.current) {
console.log("update props", props);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
refEditor.current.updateProps(props);
}
}, [props]);

return <div style={{height: '100%'}} className="jse-theme-dark" ref={refContainer}></div>;
}
Loading
Loading