Sfoglia il codice sorgente

Set query empty condition in render function. Also clear query transactions when no valid query is present

Erik Sundell 7 anni fa
parent
commit
4e591653bd

+ 5 - 0
public/app/features/explore/Explore.tsx

@@ -771,6 +771,9 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
   async runQueries(resultType: ResultType, queryOptions: any, resultGetter?: any) {
     const queries = [...this.modifiedQueries];
     if (!hasNonEmptyQuery(queries)) {
+      this.setState({
+        queryTransactions: [],
+      });
       return;
     }
     const { datasource } = this.state;
@@ -837,6 +840,7 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
     const tableLoading = queryTransactions.some(qt => qt.resultType === 'Table' && !qt.done);
     const logsLoading = queryTransactions.some(qt => qt.resultType === 'Logs' && !qt.done);
     const loading = queryTransactions.some(qt => !qt.done);
+    const queryEmpty = queryTransactions.some(qt => qt.resultType === 'Logs' && qt.done && qt.result.length === 0);
 
     return (
       <div className={exploreClass} ref={this.getRef}>
@@ -969,6 +973,7 @@ export class Explore extends React.PureComponent<ExploreProps, ExploreState> {
                           range={range}
                           scanning={scanning}
                           scanRange={scanRange}
+                          queryEmpty={queryEmpty}
                         />
                       </Panel>
                     )}

+ 13 - 2
public/app/features/explore/Logs.tsx

@@ -140,6 +140,7 @@ interface LogsProps {
   range?: RawTimeRange;
   scanning?: boolean;
   scanRange?: RawTimeRange;
+  queryEmpty: boolean;
   onChangeTime?: (range: RawTimeRange) => void;
   onClickLabel?: (label: string, value: string) => void;
   onStartScanning?: () => void;
@@ -239,7 +240,17 @@ export default class Logs extends PureComponent<LogsProps, LogsState> {
   };
 
   render() {
-    const { className = '', data, loading = false, onClickLabel, position, range, scanning, scanRange } = this.props;
+    const {
+      className = '',
+      data,
+      loading = false,
+      onClickLabel,
+      position,
+      range,
+      scanning,
+      scanRange,
+      queryEmpty,
+    } = this.props;
     const { dedup, deferLogs, hiddenLogLevels, renderAll, showLocalTime, showUtc } = this.state;
     let { showLabels } = this.state;
     const hasData = data && data.rows && data.rows.length > 0;
@@ -358,7 +369,7 @@ export default class Logs extends PureComponent<LogsProps, LogsState> {
           {hasData && deferLogs && <span>Rendering {dedupedData.rows.length} rows...</span>}
         </div>
         {!loading &&
-          data.queryEmpty &&
+          queryEmpty &&
           !scanning && (
             <div className="logs-nodata">
               No logs found.