Dashboard: Disable image renderer link for unsaved dashboards (#41249)

This commit is contained in:
Josh Hunt 2021-11-03 11:17:16 +00:00 committed by GitHub
parent f8d75726e7
commit 9fc5193ecd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 7 deletions

View File

@ -7,6 +7,7 @@ import { initTemplateSrv } from '../../../../../test/helpers/initTemplateSrv';
import { variableAdapters } from '../../../variables/adapters';
import { createQueryVariableAdapter } from '../../../variables/query/adapter';
import { PanelModel } from '../../state';
import { getDefaultTimeRange } from '@grafana/data';
jest.mock('app/features/dashboard/services/TimeSrv', () => ({
getTimeSrv: () => ({
@ -76,6 +77,7 @@ function shareLinkScenario(description: string, scenarioFn: (ctx: ScenarioContex
mount: (propOverrides?: any) => {
const props: any = {
panel: undefined,
dashboard: { time: getDefaultTimeRange() },
};
Object.assign(props, propOverrides);

View File

@ -81,10 +81,11 @@ export class ShareLink extends PureComponent<Props, State> {
};
render() {
const { panel } = this.props;
const isRelativeTime = this.props.dashboard ? this.props.dashboard.time.to === 'now' : false;
const { panel, dashboard } = this.props;
const isRelativeTime = dashboard ? dashboard.time.to === 'now' : false;
const { useCurrentTimeRange, useShortUrl, selectedTheme, shareUrl, imageUrl } = this.state;
const selectors = e2eSelectors.pages.SharePanelModal;
const isDashboardSaved = Boolean(dashboard.id);
return (
<>
@ -122,13 +123,25 @@ export class ShareLink extends PureComponent<Props, State> {
/>
</Field>
</FieldSet>
{panel && config.rendererAvailable && (
<div className="gf-form">
<a href={imageUrl} target="_blank" rel="noreferrer" aria-label={selectors.linkToRenderedImage}>
<Icon name="camera" /> Direct link rendered image
</a>
</div>
<>
{isDashboardSaved && (
<div className="gf-form">
<a href={imageUrl} target="_blank" rel="noreferrer" aria-label={selectors.linkToRenderedImage}>
<Icon name="camera" /> Direct link rendered image
</a>
</div>
)}
{!isDashboardSaved && (
<Alert severity="info" title="Dashboard is not saved" bottomSpacing={0}>
To render a panel image, you must save the dashboard first.
</Alert>
)}
</>
)}
{panel && !config.rendererAvailable && (
<Alert severity="info" title="Image renderer plugin not installed" bottomSpacing={0}>
<>To render a panel image, you must install the </>