Explorar o código

update angular state on props update

Torkel Ödegaard %!s(int64=7) %!d(string=hai) anos
pai
achega
74a0c0e618
Modificáronse 1 ficheiros con 18 adicións e 10 borrados
  1. 18 10
      public/app/features/datasources/settings/PluginSettings.tsx

+ 18 - 10
public/app/features/datasources/settings/PluginSettings.tsx

@@ -11,25 +11,33 @@ interface Props {
 export class PluginSettings extends PureComponent<Props> {
   element: any;
   component: AngularComponent;
+  scopeProps: any;
 
-  componentDidMount() {
-    const { dataSource, dataSourceMeta } = this.props;
+  constructor(props) {
+    super(props);
+
+    this.scopeProps = {
+      ctrl: {
+        datasourceMeta: this.props.dataSourceMeta,
+        current: this.props.dataSource,
+      },
+      onModelChanged: this.onModelChanged,
+    };
+  }
 
+  componentDidUpdate() {
+    this.scopeProps.ctrl.current = this.props.dataSource;
+  }
+
+  componentDidMount() {
     if (!this.element) {
       return;
     }
 
     const loader = getAngularLoader();
     const template = '<plugin-component type="datasource-config-ctrl" />';
-    const scopeProps = {
-      ctrl: {
-        datasourceMeta: dataSourceMeta,
-        current: _.cloneDeep(dataSource),
-      },
-      onModelChanged: this.onModelChanged,
-    };
 
-    this.component = loader.load(this.element, scopeProps, template);
+    this.component = loader.load(this.element, this.scopeProps, template);
   }
 
   componentWillUnmount() {