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

Feature/add search panel in state tab #1424

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions extension/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const test = process.env.NODE_ENV === 'test';

module.exports = {
presets: [
['@babel/preset-env', { targets: 'defaults' }],
'@babel/preset-react',
'@babel/preset-typescript',
],
plugins: [...(test ? ['babel-plugin-transform-import-meta'] : [])],
};
7 changes: 0 additions & 7 deletions extension/babel.config.json

This file was deleted.

1 change: 1 addition & 0 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"@types/react": "^18.2.31",
"@types/react-dom": "^18.2.14",
"@types/styled-components": "^5.1.29",
"babel-plugin-transform-import-meta": "^2.2.1",
"chromedriver": "^118.0.1",
"cross-env": "^7.0.3",
"electron": "^27.0.2",
Expand Down
35 changes: 30 additions & 5 deletions packages/react-json-tree/src/ItemRange.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useCallback, useState } from 'react';
import JSONArrow from './JSONArrow';
import type { CircularCache, CommonInternalProps } from './types';
import type { CircularCache, CommonInternalProps, KeyPath } from './types';

interface Props extends CommonInternalProps {
data: unknown;
Expand All @@ -13,12 +13,25 @@ interface Props extends CommonInternalProps {
}

export default function ItemRange(props: Props) {
const { styling, from, to, renderChildNodes, nodeType } = props;
const {
styling,
from,
to,
renderChildNodes,
nodeType,
keyPath,
searchResultPath,
level,
} = props;

const [expanded, setExpanded] = useState<boolean>(false);
const [userExpanded, setUserExpanded] = useState<boolean>(false);
const handleClick = useCallback(() => {
setExpanded(!expanded);
}, [expanded]);
setUserExpanded(!userExpanded);
}, [userExpanded]);

const expanded =
userExpanded ||
containsSearchResult(keyPath, from, to, searchResultPath, level);

return expanded ? (
<div {...styling('itemRange', expanded)}>
Expand All @@ -37,3 +50,15 @@ export default function ItemRange(props: Props) {
</div>
);
}

const containsSearchResult = (
ownKeyPath: KeyPath,
from: number,
to: number,
resultKeyPath: KeyPath,
level: number,
): boolean => {
const searchLevel = level > 1 ? level - 1 : level;
const nextKey = Number(resultKeyPath[searchLevel]);
return !isNaN(nextKey) && nextKey >= from && nextKey <= to;
};
28 changes: 22 additions & 6 deletions packages/react-json-tree/src/JSONNestedNode.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useCallback, useState } from 'react';
import ItemRange from './ItemRange';
import JSONArrow from './JSONArrow';
import getCollectionEntries from './getCollectionEntries';
import JSONNode from './JSONNode';
import ItemRange from './ItemRange';
import type { CircularCache, CommonInternalProps } from './types';
import getCollectionEntries from './getCollectionEntries';
import type { CircularCache, CommonInternalProps, KeyPath } from './types';

/**
* Renders nested values (eg. objects, arrays, lists, etc.)
Expand Down Expand Up @@ -110,17 +110,21 @@ export default function JSONNestedNode(props: Props) {
nodeType,
nodeTypeIndicator,
shouldExpandNodeInitially,
searchResultPath,
styling,
} = props;

const [expanded, setExpanded] = useState<boolean>(
const [userExpanded, setUserExpanded] = useState<boolean>(
// calculate individual node expansion if necessary
isCircular ? false : shouldExpandNodeInitially(keyPath, data, level),
);

const handleClick = useCallback(() => {
if (expandable) setExpanded(!expanded);
}, [expandable, expanded]);
if (expandable) setUserExpanded(!userExpanded);
}, [expandable, userExpanded]);

const expanded =
userExpanded || containsSearchResult(keyPath, searchResultPath, level);

const renderedChildren =
expanded || (hideRoot && level === 0)
Expand Down Expand Up @@ -175,3 +179,15 @@ export default function JSONNestedNode(props: Props) {
</li>
);
}

const containsSearchResult = (
ownKeyPath: KeyPath,
resultKeyPath: KeyPath,
level: number,
): boolean => {
const searchLevel = level > 0 ? level - 1 : level;
const currKey = [...ownKeyPath].reverse()[searchLevel];
return resultKeyPath && currKey !== undefined
? resultKeyPath[searchLevel] === currKey.toString()
: false;
};
18 changes: 11 additions & 7 deletions packages/react-json-tree/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
// port by Daniele Zannotti http://www.github.com/dzannotti <[email protected]>

import React, { useMemo } from 'react';
import type { StylingValue, Theme } from 'react-base16-styling';
import { invertTheme } from 'react-base16-styling';
import JSONNode from './JSONNode';
import createStylingFromTheme from './createStylingFromTheme';
import { invertTheme } from 'react-base16-styling';
import type { StylingValue, Theme } from 'react-base16-styling';
import type {
CommonExternalProps,
GetItemString,
Expand Down Expand Up @@ -41,6 +41,8 @@ export function JSONTree({
labelRenderer = defaultLabelRenderer,
valueRenderer = identity,
shouldExpandNodeInitially = expandRootNode,
isSearchInProgress = false,
searchResultPath = [],
hideRoot = false,
getItemString = defaultItemString,
postprocessValue = identity,
Expand All @@ -64,6 +66,8 @@ export function JSONTree({
labelRenderer={labelRenderer}
valueRenderer={valueRenderer}
shouldExpandNodeInitially={shouldExpandNodeInitially}
searchResultPath={searchResultPath}
isSearchInProgress={isSearchInProgress}
hideRoot={hideRoot}
getItemString={getItemString}
postprocessValue={postprocessValue}
Expand All @@ -75,16 +79,16 @@ export function JSONTree({
}

export type {
CommonExternalProps,
GetItemString,
IsCustomNode,
Key,
KeyPath,
GetItemString,
LabelRenderer,
ValueRenderer,
ShouldExpandNodeInitially,
PostprocessValue,
IsCustomNode,
ShouldExpandNodeInitially,
SortObjectKeys,
Styling,
CommonExternalProps,
ValueRenderer,
} from './types';
export type { StylingValue };
2 changes: 2 additions & 0 deletions packages/react-json-tree/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export interface CommonExternalProps {
labelRenderer: LabelRenderer;
valueRenderer: ValueRenderer;
shouldExpandNodeInitially: ShouldExpandNodeInitially;
searchResultPath: KeyPath;
isSearchInProgress: boolean;
hideRoot: boolean;
getItemString: GetItemString;
postprocessValue: PostprocessValue;
Expand Down
13 changes: 13 additions & 0 deletions packages/redux-devtools-app/babel.config.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const test = process.env.NODE_ENV === 'test';

module.exports = {
presets: [
['@babel/preset-env', { targets: 'defaults', modules: false }],
'@babel/preset-react',
'@babel/preset-typescript',
],
plugins: [
'@babel/plugin-transform-runtime',
...(test ? ['babel-plugin-transform-import-meta'] : []),
],
};
8 changes: 0 additions & 8 deletions packages/redux-devtools-app/babel.config.esm.json

This file was deleted.

13 changes: 13 additions & 0 deletions packages/redux-devtools-app/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const test = process.env.NODE_ENV === 'test';

module.exports = {
presets: [
['@babel/preset-env', { targets: 'defaults' }],
'@babel/preset-react',
'@babel/preset-typescript',
],
plugins: [
'@babel/plugin-transform-runtime',
...(test ? ['babel-plugin-transform-import-meta'] : []),
],
};
8 changes: 0 additions & 8 deletions packages/redux-devtools-app/babel.config.json

This file was deleted.

1 change: 1 addition & 0 deletions packages/redux-devtools-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"@types/webpack-env": "^1.18.3",
"@typescript-eslint/eslint-plugin": "^6.9.0",
"@typescript-eslint/parser": "^6.9.0",
"babel-plugin-transform-import-meta": "^2.2.1",
"babel-loader": "^9.1.3",
"cross-env": "^7.0.3",
"css-loader": "^6.8.1",
Expand Down
43 changes: 22 additions & 21 deletions packages/redux-devtools-app/src/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
import { LiftedAction, LiftedState } from '@redux-devtools/core';
import { SchemeName, ThemeName } from '@redux-devtools/ui';
import { AuthStates, States } from 'socketcluster-client/lib/clientsocket';
import { Action } from 'redux';
import { REHYDRATE } from 'redux-persist';
import { AuthStates, States } from 'socketcluster-client/lib/clientsocket';
import {
CHANGE_SECTION,
CHANGE_STATE_TREE_SETTINGS,
CHANGE_THEME,
SELECT_INSTANCE,
SELECT_MONITOR,
UPDATE_MONITOR_STATE,
CLEAR_NOTIFICATION,
ERROR,
EXPORT,
GET_REPORT_ERROR,
GET_REPORT_REQUEST,
GET_REPORT_SUCCESS,
LIFTED_ACTION,
MONITOR_ACTION,
EXPORT,
TOGGLE_SYNC,
TOGGLE_SLIDER,
REMOVE_INSTANCE,
SELECT_INSTANCE,
SELECT_MONITOR,
SET_PERSIST,
SET_STATE,
SHOW_NOTIFICATION,
TOGGLE_DISPATCHER,
TOGGLE_PERSIST,
GET_REPORT_REQUEST,
SHOW_NOTIFICATION,
CLEAR_NOTIFICATION,
UPDATE_STATE,
TOGGLE_SLIDER,
TOGGLE_SYNC,
UPDATE_MONITOR_STATE,
UPDATE_REPORTS,
REMOVE_INSTANCE,
SET_STATE,
GET_REPORT_ERROR,
GET_REPORT_SUCCESS,
ERROR,
SET_PERSIST,
CHANGE_STATE_TREE_SETTINGS,
UPDATE_STATE,
} from '../constants/actionTypes';
import {
AUTH_ERROR,
Expand All @@ -43,12 +45,9 @@ import {
SUBSCRIBE_SUCCESS,
UNSUBSCRIBE,
} from '../constants/socketActionTypes';
import { Action } from 'redux';
import { Features, State } from '../reducers/instances';
import { MonitorStateMonitorState } from '../reducers/monitor';
import { LiftedAction } from '@redux-devtools/core';
import { Data } from '../reducers/reports';
import { LiftedState } from '@redux-devtools/core';

let monitorReducer: (
monitorProps: unknown,
Expand Down Expand Up @@ -86,6 +85,7 @@ export function changeTheme(data: ChangeThemeData): ChangeThemeAction {
interface ChangeStateTreeSettingsFormData {
readonly sortAlphabetically: boolean;
readonly disableCollection: boolean;
readonly enableSearchPanel: boolean;
}

interface ChangeStateTreeSettingsData {
Expand All @@ -96,6 +96,7 @@ export interface ChangeStateTreeSettingsAction {
readonly type: typeof CHANGE_STATE_TREE_SETTINGS;
readonly sortAlphabetically: boolean;
readonly disableCollection: boolean;
readonly enableSearchPanel: boolean;
}

export function changeStateTreeSettings(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from 'react';
import { connect, ResolveThunks } from 'react-redux';
import { Container, Form } from '@redux-devtools/ui';
import React, { Component } from 'react';
import { ResolveThunks, connect } from 'react-redux';
import { changeStateTreeSettings } from '../../actions';
import { StoreState } from '../../reducers';

Expand All @@ -14,6 +14,7 @@ export class StateTree extends Component<Props> {
const formData = {
sortAlphabetically: stateTree.sortAlphabetically,
disableCollection: stateTree.disableCollection,
enableSearchPanel: stateTree.enableSearchPanel,
};

return (
Expand All @@ -30,6 +31,10 @@ export class StateTree extends Component<Props> {
title: 'Disable collapsing of nodes',
type: 'boolean',
},
enableSearchPanel: {
title: 'Show search panel in State tab',
type: 'boolean',
},
},
}}
formData={formData}
Expand Down
9 changes: 5 additions & 4 deletions packages/redux-devtools-app/src/containers/DevTools.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React, { Component } from 'react';
import { withTheme } from 'styled-components';
import { LiftedAction, LiftedState } from '@redux-devtools/core';
import { ThemeFromProvider } from '@redux-devtools/ui';
import React, { Component } from 'react';
import { Action } from 'redux';
import getMonitor from '../utils/getMonitor';
import { withTheme } from 'styled-components';
import { InitMonitorAction } from '../actions';
import { Features, State } from '../reducers/instances';
import { MonitorStateMonitorState } from '../reducers/monitor';
import { ThemeFromProvider } from '@redux-devtools/ui';
import { StateTreeSettings } from '../reducers/stateTreeSettings';
import getMonitor from '../utils/getMonitor';

interface Props {
monitor: string;
Expand Down Expand Up @@ -118,6 +118,7 @@ class DevTools extends Component<Props> {
disableStateTreeCollection={
this.props.stateTreeSettings.disableCollection
}
enableSearchPanel={this.props.stateTreeSettings.enableSearchPanel}
/>
</div>
);
Expand Down
Loading