Public Dashboards: add icon buttons with links to useful information for the user (#51722)

This commit is contained in:
Ezequiel Victorero 2022-07-06 16:34:23 -03:00 committed by GitHub
parent 777f0d532a
commit 10a33be2c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 4 deletions

View File

@ -9,6 +9,7 @@ import { IconName } from '../../types/icon';
import { ComponentSize } from '../../types/size'; import { ComponentSize } from '../../types/size';
import { getPropertiesForButtonSize } from '../Forms/commonStyles'; import { getPropertiesForButtonSize } from '../Forms/commonStyles';
import { Icon } from '../Icon/Icon'; import { Icon } from '../Icon/Icon';
import { PopoverContent, Tooltip, TooltipPlacement } from '../Tooltip';
export type ButtonVariant = 'primary' | 'secondary' | 'destructive'; export type ButtonVariant = 'primary' | 'secondary' | 'destructive';
export const allButtonVariants: ButtonVariant[] = ['primary', 'secondary', 'destructive']; export const allButtonVariants: ButtonVariant[] = ['primary', 'secondary', 'destructive'];
@ -24,6 +25,10 @@ type CommonProps = {
children?: React.ReactNode; children?: React.ReactNode;
fullWidth?: boolean; fullWidth?: boolean;
type?: string; type?: string;
/** Tooltip content to display on hover */
tooltip?: PopoverContent;
/** Position of the tooltip */
tooltipPlacement?: TooltipPlacement;
}; };
export type ButtonProps = CommonProps & ButtonHTMLAttributes<HTMLButtonElement>; export type ButtonProps = CommonProps & ButtonHTMLAttributes<HTMLButtonElement>;
@ -79,6 +84,8 @@ export const LinkButton = React.forwardRef<HTMLAnchorElement, ButtonLinkProps>(
onBlur, onBlur,
onFocus, onFocus,
disabled, disabled,
tooltip,
tooltipPlacement,
...otherProps ...otherProps
}, },
ref ref
@ -103,12 +110,22 @@ export const LinkButton = React.forwardRef<HTMLAnchorElement, ButtonLinkProps>(
className className
); );
return ( const button = (
<a className={linkButtonStyles} {...otherProps} tabIndex={disabled ? -1 : 0} ref={ref}> <a className={linkButtonStyles} {...otherProps} tabIndex={disabled ? -1 : 0} ref={ref}>
{icon && <Icon name={icon} size={size} className={styles.icon} />} {icon && <Icon name={icon} size={size} className={styles.icon} />}
{children && <span className={styles.content}>{children}</span>} {children && <span className={styles.content}>{children}</span>}
</a> </a>
); );
if (tooltip) {
return (
<Tooltip content={tooltip} placement={tooltipPlacement}>
{button}
</Tooltip>
);
}
return button;
} }
); );

View File

@ -2,7 +2,18 @@ import React, { useCallback, useEffect, useState } from 'react';
import { AppEvents } from '@grafana/data'; import { AppEvents } from '@grafana/data';
import { reportInteraction } from '@grafana/runtime/src'; import { reportInteraction } from '@grafana/runtime/src';
import { Alert, Button, Checkbox, ClipboardButton, Field, FieldSet, Icon, Input, Switch } from '@grafana/ui'; import {
Alert,
Button,
Checkbox,
ClipboardButton,
Field,
FieldSet,
Icon,
Input,
LinkButton,
Switch,
} from '@grafana/ui';
import { notifyApp } from 'app/core/actions'; import { notifyApp } from 'app/core/actions';
import { createErrorNotification } from 'app/core/copy/appNotification'; import { createErrorNotification } from 'app/core/copy/appNotification';
import { appEvents } from 'app/core/core'; import { appEvents } from 'app/core/core';
@ -114,17 +125,33 @@ export const SharePublicDashboard = (props: Props) => {
<Checkbox <Checkbox
label="Publishing currently only works with a subset of datasources" label="Publishing currently only works with a subset of datasources"
value={acknowledgements.datasources} value={acknowledgements.datasources}
description="Learn more about public datasources"
onChange={(e) => onAcknowledge('datasources', e.currentTarget.checked)} onChange={(e) => onAcknowledge('datasources', e.currentTarget.checked)}
/> />
<LinkButton
variant="primary"
href="https://grafana.com/docs/grafana/latest/datasources/"
target="_blank"
fill="text"
icon="info-circle"
rel="noopener noreferrer"
tooltip="Learn more about public datasources"
/>
</div> </div>
<br /> <br />
<Checkbox <Checkbox
label="Making your dashboard public will cause queries to run each time the dashboard is viewed which may increase costs" label="Making your dashboard public will cause queries to run each time the dashboard is viewed which may increase costs"
value={acknowledgements.usage} value={acknowledgements.usage}
description="Learn more about query caching"
onChange={(e) => onAcknowledge('usage', e.currentTarget.checked)} onChange={(e) => onAcknowledge('usage', e.currentTarget.checked)}
/> />
<LinkButton
variant="primary"
href="https://grafana.com/docs/grafana/latest/enterprise/query-caching/"
target="_blank"
fill="text"
icon="info-circle"
rel="noopener noreferrer"
tooltip="Learn more about query caching"
/>
<br /> <br />
<br /> <br />
</FieldSet> </FieldSet>