mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
* Performance: Standardize lodash imports to use destructured members Changes lodash imports of the form `import x from 'lodash/x'` to `import { x } from 'lodash'` to reduce bundle size. * Remove unnecessary _ import from Graph component * Enforce lodash import style * Fix remaining lodash imports
66 lines
1.6 KiB
TypeScript
66 lines
1.6 KiB
TypeScript
import React, { Component } from 'react';
|
|
|
|
import { CloudWatchLogsQuery } from '../types';
|
|
import { PanelData } from '@grafana/data';
|
|
import { Icon } from '@grafana/ui';
|
|
import { encodeUrl, AwsUrl } from '../aws_url';
|
|
import { CloudWatchDatasource } from '../datasource';
|
|
|
|
interface Props {
|
|
query: CloudWatchLogsQuery;
|
|
panelData?: PanelData;
|
|
datasource: CloudWatchDatasource;
|
|
}
|
|
|
|
interface State {
|
|
href: string;
|
|
}
|
|
|
|
export default class CloudWatchLink extends Component<Props, State> {
|
|
state: State = { href: '' };
|
|
|
|
async componentDidUpdate(prevProps: Props) {
|
|
const { panelData: panelDataNew } = this.props;
|
|
const { panelData: panelDataOld } = prevProps;
|
|
|
|
if (panelDataOld !== panelDataNew && panelDataNew?.request) {
|
|
const href = this.getExternalLink();
|
|
this.setState({ href });
|
|
}
|
|
}
|
|
|
|
getExternalLink(): string {
|
|
const { query, panelData, datasource } = this.props;
|
|
|
|
const range = panelData?.request?.range;
|
|
|
|
if (!range) {
|
|
return '';
|
|
}
|
|
|
|
const start = range.from.toISOString();
|
|
const end = range.to.toISOString();
|
|
|
|
const urlProps: AwsUrl = {
|
|
end,
|
|
start,
|
|
timeType: 'ABSOLUTE',
|
|
tz: 'UTC',
|
|
editorString: query.expression ?? '',
|
|
isLiveTail: false,
|
|
source: query.logGroupNames ?? [],
|
|
};
|
|
|
|
return encodeUrl(urlProps, datasource.getActualRegion(query.region));
|
|
}
|
|
|
|
render() {
|
|
const { href } = this.state;
|
|
return (
|
|
<a href={href} target="_blank" rel="noopener noreferrer">
|
|
<Icon name="share-alt" /> CloudWatch Logs Insights
|
|
</a>
|
|
);
|
|
}
|
|
}
|