mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-24 01:18:23 +00:00
Bugfix/chart widget freeze issue (#976)
* fixes chart widget * refactored * removing comments
This commit is contained in:
parent
7931e9b8f7
commit
6b79a3096d
1 changed files with 9 additions and 8 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import React, { useState, useEffect } from 'react';
|
||||
import React, { useState, useEffect, useMemo } from 'react';
|
||||
import { resolveReferences, resolveWidgetFieldValue } from '@/_helpers/utils';
|
||||
|
||||
// Use plotly basic bundle
|
||||
|
|
@ -8,7 +8,6 @@ const Plot = createPlotlyComponent(Plotly);
|
|||
|
||||
export const Chart = function Chart({ id, width, height, component, onComponentClick, currentState, darkMode }) {
|
||||
const [loadingState, setLoadingState] = useState(false);
|
||||
const [chartData, setChartData] = useState([]);
|
||||
|
||||
const widgetVisibility = component.definition.styles?.visibility?.value ?? true;
|
||||
const disabledState = component.definition.styles?.disabledState?.value ?? false;
|
||||
|
|
@ -87,8 +86,8 @@ export const Chart = function Chart({ id, width, height, component, onComponentC
|
|||
|
||||
const data = resolveReferences(dataString, currentState, []);
|
||||
|
||||
useEffect(() => {
|
||||
let rawData = data || [];
|
||||
const computeChartData = (data, dataString) => {
|
||||
let rawData = data;
|
||||
if (typeof rawData === 'string') {
|
||||
try {
|
||||
rawData = JSON.parse(dataString);
|
||||
|
|
@ -122,9 +121,11 @@ export const Chart = function Chart({ id, width, height, component, onComponentC
|
|||
];
|
||||
}
|
||||
|
||||
setChartData(newData);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [data, chartType]);
|
||||
return newData;
|
||||
};
|
||||
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
const memoizedChartData = useMemo(() => computeChartData(data, dataString), [data, dataString]);
|
||||
|
||||
return (
|
||||
<div
|
||||
|
|
@ -143,7 +144,7 @@ export const Chart = function Chart({ id, width, height, component, onComponentC
|
|||
</div>
|
||||
) : (
|
||||
<Plot
|
||||
data={chartData}
|
||||
data={memoizedChartData}
|
||||
layout={layout}
|
||||
config={{
|
||||
displayModeBar: false,
|
||||
|
|
|
|||
Loading…
Reference in a new issue