mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2025-07-22 22:19:48 +03:00
run prettier
This commit is contained in:
parent
4574eb0c62
commit
a4aac76d5a
|
@ -122,9 +122,12 @@ export default function JSONNestedNode(props: Props) {
|
||||||
? false
|
? false
|
||||||
: (function getDefault() {
|
: (function getDefault() {
|
||||||
switch (shouldExpandNode) {
|
switch (shouldExpandNode) {
|
||||||
case 'expand': return true;
|
case 'expand':
|
||||||
case 'collapse': return false;
|
return true;
|
||||||
default: return shouldExpandNodeInitially(keyPath, data, level);
|
case 'collapse':
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
return shouldExpandNodeInitially(keyPath, data, level);
|
||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
);
|
);
|
||||||
|
@ -134,21 +137,27 @@ export default function JSONNestedNode(props: Props) {
|
||||||
/**
|
/**
|
||||||
* Used the useRef to handle expanded because calling a setState in a recursive implementation
|
* Used the useRef to handle expanded because calling a setState in a recursive implementation
|
||||||
* could lead to a "Maximum update depth exceeded" error */
|
* could lead to a "Maximum update depth exceeded" error */
|
||||||
const expandedRef = useRef<boolean>(defaultExpanded)
|
const expandedRef = useRef<boolean>(defaultExpanded);
|
||||||
|
|
||||||
switch (shouldExpandNode) {
|
switch (shouldExpandNode) {
|
||||||
case 'expand': expandedRef.current = isCircular ? false : true; break;
|
case 'expand':
|
||||||
case 'collapse': expandedRef.current = false; break;
|
expandedRef.current = isCircular ? false : true;
|
||||||
case 'default': expandedRef.current = defaultExpanded; break;
|
break;
|
||||||
|
case 'collapse':
|
||||||
|
expandedRef.current = false;
|
||||||
|
break;
|
||||||
|
case 'default':
|
||||||
|
expandedRef.current = defaultExpanded;
|
||||||
|
break;
|
||||||
default: //Do nothing;
|
default: //Do nothing;
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleClick = useCallback(() => {
|
const handleClick = useCallback(() => {
|
||||||
if (expandable) {
|
if (expandable) {
|
||||||
expandedRef.current = !expandedRef.current
|
expandedRef.current = !expandedRef.current;
|
||||||
setTriggerReRender((e) => !e)
|
setTriggerReRender((e) => !e);
|
||||||
setEnableDefaultButton(true);
|
setEnableDefaultButton(true);
|
||||||
setShouldExpandNode(undefined)
|
setShouldExpandNode(undefined);
|
||||||
}
|
}
|
||||||
}, [expandable, setEnableDefaultButton, setShouldExpandNode]);
|
}, [expandable, setEnableDefaultButton, setShouldExpandNode]);
|
||||||
|
|
||||||
|
@ -169,7 +178,12 @@ export default function JSONNestedNode(props: Props) {
|
||||||
createItemString(data, collectionLimit),
|
createItemString(data, collectionLimit),
|
||||||
keyPath
|
keyPath
|
||||||
);
|
);
|
||||||
const stylingArgs = [keyPath, nodeType, expandedRef.current, expandable] as const;
|
const stylingArgs = [
|
||||||
|
keyPath,
|
||||||
|
nodeType,
|
||||||
|
expandedRef.current,
|
||||||
|
expandable,
|
||||||
|
] as const;
|
||||||
|
|
||||||
return hideRoot ? (
|
return hideRoot ? (
|
||||||
<li {...styling('rootNode', ...stylingArgs)}>
|
<li {...styling('rootNode', ...stylingArgs)}>
|
||||||
|
|
|
@ -24,7 +24,11 @@ interface Props {
|
||||||
|
|
||||||
const ExpandableButtonsContext = createContext<Context>({} as Context);
|
const ExpandableButtonsContext = createContext<Context>({} as Context);
|
||||||
|
|
||||||
function ExpandableButtonsContextProvider({ expandable, children, styling }: Props) {
|
function ExpandableButtonsContextProvider({
|
||||||
|
expandable,
|
||||||
|
children,
|
||||||
|
styling,
|
||||||
|
}: Props) {
|
||||||
const [enableDefaultButton, setEnableDefaultButton] = useState(false);
|
const [enableDefaultButton, setEnableDefaultButton] = useState(false);
|
||||||
const [shouldExpandNode, setShouldExpandNode] = useState();
|
const [shouldExpandNode, setShouldExpandNode] = useState();
|
||||||
|
|
||||||
|
@ -41,7 +45,9 @@ function ExpandableButtonsContextProvider({ expandable, children, styling }: Pro
|
||||||
return (
|
return (
|
||||||
<ExpandableButtonsContext.Provider value={value}>
|
<ExpandableButtonsContext.Provider value={value}>
|
||||||
{children}
|
{children}
|
||||||
{expandable && <ExpandableButtons expandable={expandable} styling={styling} />}
|
{expandable && (
|
||||||
|
<ExpandableButtons expandable={expandable} styling={styling} />
|
||||||
|
)}
|
||||||
</ExpandableButtonsContext.Provider>
|
</ExpandableButtonsContext.Provider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@ describe('JSONTree', () => {
|
||||||
const result = render(<JSONTree data={BASIC_DATA} />);
|
const result = render(<JSONTree data={BASIC_DATA} />);
|
||||||
|
|
||||||
expect(result.type).toBe('ul');
|
expect(result.type).toBe('ul');
|
||||||
expect(result.props.children.type.name).toBe(ExpandableButtonsContextProvider.name);
|
expect(result.props.children.type.name).toBe(
|
||||||
|
ExpandableButtonsContextProvider.name
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user