diff --git a/public/app/features/explore/RawPrometheus/RawPrometheusContainer.test.tsx b/public/app/features/explore/RawPrometheus/RawPrometheusContainer.test.tsx index a310592e37a..bdc901630ba 100644 --- a/public/app/features/explore/RawPrometheus/RawPrometheusContainer.test.tsx +++ b/public/app/features/explore/RawPrometheus/RawPrometheusContainer.test.tsx @@ -1,7 +1,8 @@ import { fireEvent, render, screen, within } from '@testing-library/react'; import React from 'react'; -import { FieldType, getDefaultTimeRange, InternalTimeZones, toDataFrame } from '@grafana/data'; +import { FieldType, getDefaultTimeRange, InternalTimeZones, toDataFrame, LoadingState } from '@grafana/data'; +import { getTemplateSrv } from 'app/features/templating/template_srv'; import { TABLE_RESULTS_STYLE } from 'app/types'; import { RawPrometheusContainer } from './RawPrometheusContainer'; @@ -53,7 +54,7 @@ const dataFrame = toDataFrame({ const defaultProps = { exploreId: 'left', - loading: false, + loading: LoadingState.NotStarted, width: 800, onCellFilterAdded: jest.fn(), tableResult: [dataFrame], @@ -65,6 +66,10 @@ const defaultProps = { }; describe('RawPrometheusContainer', () => { + beforeAll(() => { + getTemplateSrv(); + }); + it('should render component for prometheus', () => { render(); diff --git a/public/app/features/explore/RawPrometheus/RawPrometheusContainer.tsx b/public/app/features/explore/RawPrometheus/RawPrometheusContainer.tsx index 9bcfacab161..3cf40901475 100644 --- a/public/app/features/explore/RawPrometheus/RawPrometheusContainer.tsx +++ b/public/app/features/explore/RawPrometheus/RawPrometheusContainer.tsx @@ -4,7 +4,7 @@ import { connect, ConnectedProps } from 'react-redux'; import { applyFieldOverrides, DataFrame, SelectableValue, SplitOpen, TimeZone } from '@grafana/data'; import { getTemplateSrv, reportInteraction } from '@grafana/runtime'; -import { Collapse, RadioButtonGroup, Table, AdHocFilterItem } from '@grafana/ui'; +import { RadioButtonGroup, Table, AdHocFilterItem, PanelChrome } from '@grafana/ui'; import { config } from 'app/core/config'; import { PANEL_BORDER } from 'app/core/constants'; import { StoreState, TABLE_RESULTS_STYLE } from 'app/types'; @@ -12,7 +12,6 @@ import { ExploreItemState, TABLE_RESULTS_STYLES, TableResultsStyle } from 'app/t import { MetaInfoText } from '../MetaInfoText'; import RawListContainer from '../PrometheusListView/RawListContainer'; -import { selectIsWaitingForData } from '../state/query'; import { exploreDataLinkPostProcessorFactory } from '../utils/links'; interface RawPrometheusContainerProps { @@ -32,11 +31,10 @@ interface PrometheusContainerState { function mapStateToProps(state: StoreState, { exploreId }: RawPrometheusContainerProps) { const explore = state.explore; const item: ExploreItemState = explore.panes[exploreId]!; - const { tableResult, rawPrometheusResult, range } = item; - const loadingInState = selectIsWaitingForData(exploreId)(state); + const { tableResult, rawPrometheusResult, range, queryResponse } = item; const rawPrometheusFrame: DataFrame[] = rawPrometheusResult ? [rawPrometheusResult] : []; const result = (tableResult?.length ?? 0) > 0 && rawPrometheusResult ? tableResult : rawPrometheusFrame; - const loading = result && result.length > 0 ? false : loadingInState; + const loading = queryResponse.state; return { loading, tableResult: result, range }; } @@ -86,7 +84,6 @@ export class RawPrometheusContainer extends PureComponent - {this.state.resultsStyle === TABLE_RESULTS_STYLE.raw ? 'Raw' : 'Table'} { const props = { @@ -133,13 +130,14 @@ export class RawPrometheusContainer extends PureComponent !!frame && frame.length !== 0 ); + const title = this.state.resultsStyle === TABLE_RESULTS_STYLE.raw ? 'Raw' : 'Table'; const label = this.state?.resultsStyle !== undefined ? this.renderLabel() : 'Table'; // Render table as default if resultsStyle is not set. const renderTable = !this.state?.resultsStyle || this.state?.resultsStyle === TABLE_RESULTS_STYLE.table; return ( - + {frames?.length && ( <> {renderTable && ( @@ -155,7 +153,7 @@ export class RawPrometheusContainer extends PureComponent )} {!frames?.length && } - + ); } }