From f774c4a076fbfd07b456115ade0265e0c099ea6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 7 Jan 2020 13:05:14 +0100 Subject: [PATCH] Cloudwatch: Fixed crash when switching from cloudwatch data source (#21376) --- .../datasource/cloudwatch/components/QueryEditor.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/public/app/plugins/datasource/cloudwatch/components/QueryEditor.tsx b/public/app/plugins/datasource/cloudwatch/components/QueryEditor.tsx index 644858df061..2935619cb29 100644 --- a/public/app/plugins/datasource/cloudwatch/components/QueryEditor.tsx +++ b/public/app/plugins/datasource/cloudwatch/components/QueryEditor.tsx @@ -28,8 +28,8 @@ const idValidationEvents: ValidationEvents = { export class QueryEditor extends PureComponent { state: State = { regions: [], namespaces: [], metricNames: [], variableOptionGroup: {}, showMeta: false }; - componentWillMount() { - const { query } = this.props; + static getDerivedStateFromProps(props: Props, state: State) { + const { query } = props; if (!query.namespace) { query.namespace = ''; @@ -66,6 +66,8 @@ export class QueryEditor extends PureComponent { if (!query.hasOwnProperty('matchExact')) { query.matchExact = true; } + + return state; } componentDidMount() {