Skip to content
Merged
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
9 changes: 9 additions & 0 deletions app/client/src/widgets/ChartWidget/widget/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ describe("emptyChartData", () => {
expect(emptyChartData(props)).toEqual(true);
});

it("returns true if each series is null or undefined", () => {
const props = JSON.parse(JSON.stringify(basicEChartProps));
Copy link
Contributor

@jsartisan jsartisan Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you are just following what the previous developer did in this test, but why are we doing stringify and parse the JS object? 🤔 Just curious about it...What's the point?

Copy link
Contributor Author

@rahulbarwal rahulbarwal Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically creating a (deep)clone of the object. We change some nested properties of this object in the test.


props.chartData.seriesID1 = { data: undefined };
props.chartData.seriesID2 = { data: null };

expect(emptyChartData(props)).toEqual(true);
});

it("returns true if no series is present", () => {
const props = JSON.parse(JSON.stringify(basicEChartProps));

Expand Down
5 changes: 4 additions & 1 deletion app/client/src/widgets/ChartWidget/widget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ export const emptyChartData = (props: ChartWidgetProps) => {
const builder = new EChartsDatasetBuilder(props.chartType, props.chartData);

for (const seriesID in builder.filteredChartData) {
if (Object.keys(props.chartData[seriesID].data).length > 0) {
if (
Array.isArray(props.chartData[seriesID].data) &&
props.chartData[seriesID].data.length > 0
) {
return false;
}
}
Expand Down