grafana/public/app/features/explore/QueryStatus.tsx
Boyko 1e74037eae
React: refactor away from unsafe lifecycle methods (#21291)
* refactor aliasBy and PopoverCtrl components

* refactor Aggregations component

* refactor MetricSelect component

* refactor UserProvider

* popoverCtr: remove redundant logic

* simplified the MetricsSelect a bit.

* skipping testing of internal component logic.

* changed to componentWillMount.

* changed elapsed time to a functional component.

* rewrote the tests.

* fixed missing test title.

* fixed a tiny issue with elapsed time.

* rename of field.

Co-authored-by: Marcus Andersson <marcus.andersson@grafana.com>
2020-05-18 18:03:29 +02:00

53 lines
1.4 KiB
TypeScript

import React, { PureComponent } from 'react';
import { ElapsedTime } from './ElapsedTime';
import { PanelData, LoadingState } from '@grafana/data';
function formatLatency(value: number) {
return `${(value / 1000).toFixed(1)}s`;
}
interface QueryStatusItemProps {
queryResponse: PanelData;
latency: number;
}
class QueryStatusItem extends PureComponent<QueryStatusItemProps> {
render() {
const { queryResponse, latency } = this.props;
const className =
queryResponse.state === LoadingState.Done || LoadingState.Error
? 'query-transaction'
: 'query-transaction query-transaction--loading';
return (
<div className={className}>
{/* <div className="query-transaction__type">{transaction.resultType}:</div> */}
<div className="query-transaction__duration">
{queryResponse.state === LoadingState.Done || LoadingState.Error ? formatLatency(latency) : <ElapsedTime />}
</div>
</div>
);
}
}
interface QueryStatusProps {
queryResponse: PanelData;
latency: number;
}
export default class QueryStatus extends PureComponent<QueryStatusProps> {
render() {
const { queryResponse, latency } = this.props;
if (queryResponse.state === LoadingState.NotStarted) {
return null;
}
return (
<div className="query-transactions">
<QueryStatusItem queryResponse={queryResponse} latency={latency} />
</div>
);
}
}