Prechádzať zdrojové kódy

minor code refactor

Torkel Ödegaard 7 rokov pred
rodič
commit
df83c4650d

+ 6 - 2
public/app/features/dashboard/dashgrid/QueriesTab.tsx

@@ -50,17 +50,21 @@ export class QueriesTab extends PureComponent<Props, State> {
 
 
   constructor(props) {
   constructor(props) {
     super(props);
     super(props);
-    const { panel } = props;
 
 
     this.state = {
     this.state = {
-      currentDS: this.datasources.find(datasource => datasource.value === panel.datasource),
       isLoadingHelp: false,
       isLoadingHelp: false,
+      currentDS: this.findCurrentDataSource(),
       helpContent: null,
       helpContent: null,
       isPickerOpen: false,
       isPickerOpen: false,
       isAddingMixed: false,
       isAddingMixed: false,
     };
     };
   }
   }
 
 
+  findCurrentDataSource(): DataSourceSelectItem {
+    const { panel } = this.props;
+    return this.datasources.find(datasource => datasource.value === panel.datasource) || this.datasources[0];
+  }
+
   getAngularQueryComponentScope(): AngularQueryComponentScope {
   getAngularQueryComponentScope(): AngularQueryComponentScope {
     const { panel, dashboard } = this.props;
     const { panel, dashboard } = this.props;
 
 

+ 1 - 1
public/app/features/dashboard/dashgrid/QueryOptions.tsx

@@ -94,7 +94,7 @@ export class QueryOptions extends PureComponent<Props, State> {
 
 
   renderOptions() {
   renderOptions() {
     const { datasource, panel } = this.props;
     const { datasource, panel } = this.props;
-    const queryOptions = datasource && datasource.meta ? datasource.meta.queryOptions : undefined;
+    const { queryOptions } = datasource.meta;
 
 
     if (!queryOptions) {
     if (!queryOptions) {
       return null;
       return null;