Skip to content

Commit 3e613d4

Browse files
committed
release 2.4.2
1 parent f498d04 commit 3e613d4

File tree

5 files changed

+46
-40
lines changed

5 files changed

+46
-40
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 2.4.2
2+
3+
### Bug Fixes
4+
5+
- [beforeExpandChange was not propagated to the child objects](https://github.com/AnyRoad/react-json-view-lite/pull/52)
6+
17
## 2.4.1
28

39
### Bug Fixes

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-json-view-lite",
3-
"version": "2.4.1",
3+
"version": "2.4.2",
44
"description": "JSON viewer component for React focused on performance for large volume input while still providing few customiziation features",
55
"homepage": "https://github.com/AnyRoad/react-json-view-lite",
66
"author": "AnyRoad",

src/DataRenderer.test.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,25 @@ describe('DataRender', () => {
568568
expect(screen.queryByText('123')).not.toBeInTheDocument();
569569
});
570570

571+
it('should stop expanding for the nested object if beforeExpandChange returned true', () => {
572+
const { container } = render(
573+
<WrappedDataRenderer
574+
value={{ obj: { test: 123 } }}
575+
shouldExpandNode={collapseAllNested}
576+
beforeExpandChange={() => false}
577+
/>
578+
);
579+
expect(screen.queryByText(/obj/)).toBeInTheDocument();
580+
expect(screen.queryByText(/test:/)).not.toBeInTheDocument();
581+
expect(screen.queryByText('123')).not.toBeInTheDocument();
582+
583+
const collapsedContent = container.getElementsByClassName(commonProps.style.collapsedContent);
584+
fireEvent.click(collapsedContent[0]);
585+
expect(screen.getByText(/obj/)).toBeInTheDocument();
586+
expect(screen.queryByText(/test:/)).not.toBeInTheDocument();
587+
expect(screen.queryByText('123')).not.toBeInTheDocument();
588+
});
589+
571590
it('should stop expanding if beforeExpandChange returned false and render with new shouldExpandNode value', () => {
572591
let level = null;
573592
let field = null;

src/stories/JsonView.stories.tsx

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
import React from 'react';
22
import { StoryFn, Meta, StoryObj } from '@storybook/react';
3-
import { useArgs } from '@storybook/preview-api';
43

5-
import {
6-
JsonView,
7-
defaultStyles,
8-
darkStyles,
9-
allExpanded,
10-
collapseAllNested,
11-
NodeExpandingEvent
12-
} from '../index';
4+
import { JsonView, defaultStyles, darkStyles, allExpanded, collapseAllNested } from '../index';
135

146
export default {
157
title: 'Json View',
@@ -133,35 +125,24 @@ ClickOnFieldNameToExpand.args = {
133125
clickToExpandNode: true
134126
};
135127

128+
const tmp = {
129+
a: <a href='https://www.google.com'>Google</a>
130+
};
131+
132+
const JsonViewer: React.FC = () => {
133+
return (
134+
<div>
135+
<JsonView data={tmp} shouldExpandNode={collapseAllNested} />
136+
</div>
137+
);
138+
};
139+
136140
type JsonViewStory = StoryObj<typeof JsonView>;
137141

138142
export const ExpandOnlyFirstLevelWhenClickOnRoot: JsonViewStory = {
139-
args: {
140-
data: jsonData,
141-
style: { ...defaultStyles },
142-
shouldExpandNode: collapseAll,
143-
clickToExpandNode: true
144-
},
145-
argTypes: {},
146-
name: 'Expand only first level on root click (using beforeExpandChange)',
147-
148-
render: function Render(args) {
149-
const [{ shouldExpandNode }, updateArgs] = useArgs();
150-
151-
const beforeExpandChange = (event: NodeExpandingEvent) => {
152-
if (event.level === 0 && event.newExpandValue) {
153-
updateArgs({ shouldExpandNode: (level: number) => level < 1 });
154-
return false;
155-
}
156-
return true;
157-
};
158-
159-
return (
160-
<JsonView
161-
{...args}
162-
beforeExpandChange={beforeExpandChange}
163-
shouldExpandNode={shouldExpandNode}
164-
/>
165-
);
143+
name: 'Bug test',
144+
145+
render: function Render() {
146+
return <JsonViewer />;
166147
}
167148
};

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4120,9 +4120,9 @@ __metadata:
41204120
linkType: hard
41214121

41224122
"caniuse-lite@npm:^1.0.0, caniuse-lite@npm:^1.0.30001109, caniuse-lite@npm:^1.0.30001688":
4123-
version: 1.0.30001702
4124-
resolution: "caniuse-lite@npm:1.0.30001702"
4125-
checksum: ba8e88f0ef09a16f36de805c9491c3047986ab6bb1e0dc66f03067dce5e197be1c98cfaed21867bad851985f775b8d4fa50e7e37537c116a5fe1ae623dfd400c
4123+
version: 1.0.30001731
4124+
resolution: "caniuse-lite@npm:1.0.30001731"
4125+
checksum: ecd2ad779f31011bef657c0104a08a780d9bb38ff8ad7aeeeaf196151be22c492de87f4a9c89a30ea4aa9575c5a39c85bf6bd56e89a4bf8259f54a4fbfc24a0d
41264126
languageName: node
41274127
linkType: hard
41284128

0 commit comments

Comments
 (0)