From f0cd61efccf70bdab6413ea658215fa22c4992cd Mon Sep 17 00:00:00 2001 From: Wannes Vereecken Date: Tue, 7 Jan 2025 09:26:27 +0100 Subject: [PATCH] Fixed bug where editing a duplicated panel might affect the original --- src/QueryEditor.tsx | 51 +++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/src/QueryEditor.tsx b/src/QueryEditor.tsx index e6bf564..68f6209 100644 --- a/src/QueryEditor.tsx +++ b/src/QueryEditor.tsx @@ -124,11 +124,12 @@ export class QueryEditor extends Component { onChangeAssetMeasurementQuery(assetMeasurementQuery: AssetMeasurementQuery): void { const { onChange, query } = this.props - query.queryType = 'AssetMeasurementQuery' - query.query = assetMeasurementQuery - query.tabIndex = TabIndex.Assets - query.historianInfo = this.historianInfo - onChange(query) + const updatedQuery = JSON.parse(JSON.stringify(query)) as Query + updatedQuery.queryType = 'AssetMeasurementQuery' + updatedQuery.query = assetMeasurementQuery + updatedQuery.tabIndex = TabIndex.Assets + updatedQuery.historianInfo = this.historianInfo + onChange(updatedQuery) this.onRunQuery(this.props) this.setState({ ...this.state, @@ -138,11 +139,12 @@ export class QueryEditor extends Component { onChangeMeasurementQuery(measurementQuery: MeasurementQuery): void { const { onChange, query } = this.props - query.queryType = 'MeasurementQuery' - query.query = measurementQuery - query.tabIndex = TabIndex.Measurements - query.historianInfo = this.historianInfo - onChange(query) + const updatedQuery = JSON.parse(JSON.stringify(query)) as Query + updatedQuery.queryType = 'MeasurementQuery' + updatedQuery.query = measurementQuery + updatedQuery.tabIndex = TabIndex.Measurements + updatedQuery.historianInfo = this.historianInfo + onChange(updatedQuery) this.onRunQuery(this.props) this.setState({ ...this.state, @@ -152,11 +154,12 @@ export class QueryEditor extends Component { onChangeRawQuery(rawQuery: RawQuery): void { const { onChange, query } = this.props - query.queryType = 'RawQuery' - query.query = rawQuery - query.tabIndex = TabIndex.RawQuery - query.historianInfo = this.historianInfo - onChange(query) + const updatedQuery = JSON.parse(JSON.stringify(query)) as Query + updatedQuery.queryType = 'RawQuery' + updatedQuery.query = rawQuery + updatedQuery.tabIndex = TabIndex.RawQuery + updatedQuery.historianInfo = this.historianInfo + onChange(updatedQuery) this.onRunQuery(this.props) this.setState({ ...this.state, @@ -166,11 +169,12 @@ export class QueryEditor extends Component { onChangeEventQuery(eventQuery: EventQuery): void { const { onChange, query } = this.props - query.queryType = 'EventQuery' - query.query = eventQuery - query.tabIndex = TabIndex.Events - query.historianInfo = this.historianInfo - onChange(query) + const updatedQuery = JSON.parse(JSON.stringify(query)) as Query + updatedQuery.queryType = 'EventQuery' + updatedQuery.query = eventQuery + updatedQuery.tabIndex = TabIndex.Events + updatedQuery.historianInfo = this.historianInfo + onChange(updatedQuery) this.onRunQuery(this.props) this.setState({ ...this.state, @@ -180,9 +184,10 @@ export class QueryEditor extends Component { onChangeSeriesLimit(value: number): void { const { onChange, query } = this.props - query.seriesLimit = value - query.historianInfo = this.historianInfo - onChange(query) + const updatedQuery = JSON.parse(JSON.stringify(query)) as Query + updatedQuery.seriesLimit = value + updatedQuery.historianInfo = this.historianInfo + onChange(updatedQuery) this.onRunQuery(this.props) }