浏览代码

redux: improved state handling

Torkel Ödegaard 7 年之前
父节点
当前提交
42aaa2b907
共有 1 个文件被更改,包括 10 次插入4 次删除
  1. 10 4
      public/app/features/alerting/AlertRuleList.tsx

+ 10 - 4
public/app/features/alerting/AlertRuleList.tsx

@@ -41,14 +41,20 @@ export class AlertRuleList extends PureComponent<Props, State> {
   }
 
   componentDidMount() {
-    this.fetchRules(this.getStateFilter());
+    console.log('did mount');
+    this.fetchRules();
+  }
+
+  componentDidUpdate(prevProps: Props) {
+    if (prevProps.stateFilter !== this.props.stateFilter) {
+      this.fetchRules();
+    }
   }
 
   onStateFilterChanged = evt => {
     this.props.updateLocation({
       query: { state: evt.target.value },
     });
-    this.fetchRules(evt.target.value);
   };
 
   getStateFilter(): string {
@@ -59,8 +65,8 @@ export class AlertRuleList extends PureComponent<Props, State> {
     return 'all';
   }
 
-  async fetchRules(stateFilter: string) {
-    await this.props.getAlertRulesAsync({ state: stateFilter });
+  async fetchRules() {
+    await this.props.getAlertRulesAsync({ state: this.getStateFilter() });
   }
 
   onOpenHowTo = () => {