From ce628768bbfefa5f50469fc086494e09d03311ac Mon Sep 17 00:00:00 2001 From: Nikhil Nandagopal Date: Wed, 16 Sep 2020 13:41:24 +0530 Subject: [PATCH] Fix/bindings (#554) * changed chart data to behave as an array and not use json stringify to update added a generic logic to flag all objects with internal bindings as dynamic moved unescape to only handle at the time of eval and removed new lines before eval * added a migration for older charts that have their data as strings * flagged column actions as an action trigger to avoid evaluating it * minor fix * fixed chart fields disappearing * added migration on update * added migration to constructor * added a fallback for first time renders * removed migration from did update Co-authored-by: Nikhil Nandagopal --- .../propertyControls/ChartDataControl.tsx | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/app/client/src/components/propertyControls/ChartDataControl.tsx b/app/client/src/components/propertyControls/ChartDataControl.tsx index d6a53ac732..fcd08e00b7 100644 --- a/app/client/src/components/propertyControls/ChartDataControl.tsx +++ b/app/client/src/components/propertyControls/ChartDataControl.tsx @@ -139,11 +139,6 @@ function DataControlComponent(props: RenderComponentProps) { } class ChartDataControl extends BaseControl { - chartData: Array<{ - seriesName: string; - data: string; - }> = []; - getValidations = (message: string, isValid: boolean, len: number) => { const validations: Array<{ isValid: boolean; @@ -173,7 +168,10 @@ class ChartDataControl extends BaseControl { }; componentDidMount() { - const chartData = this.props.propertyValue; + this.migrateChartData(this.props.propertyValue); + } + + migrateChartData(chartData: Array<{ seriesName: string; data: string }>) { // Added a migration script for older chart data that was strings // deprecate after enough charts have moved to the new format if (_.isString(chartData)) { @@ -182,8 +180,8 @@ class ChartDataControl extends BaseControl { seriesName: string; data: string; }> = JSON.parse(chartData); - this.updateProperty("chartData", parsedData); - this.chartData = parsedData; + this.updateProperty(this.props.propertyName, parsedData); + return parsedData; } catch (error) { Sentry.captureException({ message: "Chart Migration Failed", @@ -191,17 +189,17 @@ class ChartDataControl extends BaseControl { }); } } else { - this.chartData = this.props.propertyValue; + return this.props.propertyValue; } } - componentDidUpdate() { - this.chartData = this.props.propertyValue; - } - render() { - const chartData = this.chartData; - const dataLength = this.chartData.length; + const chartData: Array<{ seriesName: string; data: string }> = _.isString( + this.props.propertyValue, + ) + ? [] + : this.props.propertyValue; + const dataLength = chartData.length; const { validationMessage, isValid } = this.props; const validations: Array<{ isValid: boolean; @@ -213,7 +211,7 @@ class ChartDataControl extends BaseControl { ); return ( - {this.chartData.map((data, index) => { + {chartData.map((data, index) => { return (