mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
PanelChrome: Allow panel to be dragged if set as draggable from the outside (#61698)
This commit is contained in:
parent
e32cd6d4ff
commit
db51e963de
@ -27,7 +27,8 @@ export interface PanelChromeProps {
|
|||||||
titleItems?: ReactNode[];
|
titleItems?: ReactNode[];
|
||||||
menu?: ReactElement | (() => ReactElement);
|
menu?: ReactElement | (() => ReactElement);
|
||||||
/** dragClass, hoverHeader not yet implemented */
|
/** dragClass, hoverHeader not yet implemented */
|
||||||
// dragClass?: string;
|
dragClass?: string;
|
||||||
|
dragClassCancel?: string;
|
||||||
hoverHeader?: boolean;
|
hoverHeader?: boolean;
|
||||||
loadingState?: LoadingState;
|
loadingState?: LoadingState;
|
||||||
/**
|
/**
|
||||||
@ -69,6 +70,8 @@ export function PanelChrome({
|
|||||||
statusMessage,
|
statusMessage,
|
||||||
statusMessageOnClick,
|
statusMessageOnClick,
|
||||||
leftItems,
|
leftItems,
|
||||||
|
dragClass,
|
||||||
|
dragClassCancel,
|
||||||
}: PanelChromeProps) {
|
}: PanelChromeProps) {
|
||||||
const theme = useTheme2();
|
const theme = useTheme2();
|
||||||
const styles = useStyles2(getStyles);
|
const styles = useStyles2(getStyles);
|
||||||
@ -91,6 +94,7 @@ export function PanelChrome({
|
|||||||
|
|
||||||
const headerStyles: CSSProperties = {
|
const headerStyles: CSSProperties = {
|
||||||
height: headerHeight,
|
height: headerHeight,
|
||||||
|
cursor: dragClass ? 'move' : 'auto',
|
||||||
};
|
};
|
||||||
|
|
||||||
const itemStyles: CSSProperties = {
|
const itemStyles: CSSProperties = {
|
||||||
@ -107,17 +111,17 @@ export function PanelChrome({
|
|||||||
{loadingState === LoadingState.Loading ? <LoadingBar width={'28%'} height={'2px'} /> : null}
|
{loadingState === LoadingState.Loading ? <LoadingBar width={'28%'} height={'2px'} /> : null}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={styles.headerContainer} style={headerStyles} data-testid="header-container">
|
<div className={cx(styles.headerContainer, dragClass)} style={headerStyles} data-testid="header-container">
|
||||||
{title && (
|
{title && (
|
||||||
<h6 title={title} className={styles.title}>
|
<h6 title={title} className={styles.title}>
|
||||||
{title}
|
{title}
|
||||||
</h6>
|
</h6>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<PanelDescription description={description} />
|
<PanelDescription description={description} className={dragClassCancel} />
|
||||||
|
|
||||||
{titleItems.length > 0 && (
|
{titleItems.length > 0 && (
|
||||||
<div className={styles.titleItems} data-testid="title-items-container">
|
<div className={cx(styles.titleItems, dragClassCancel)} data-testid="title-items-container">
|
||||||
{titleItems.map((item) => item)}
|
{titleItems.map((item) => item)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@ -139,7 +143,7 @@ export function PanelChrome({
|
|||||||
icon="ellipsis-v"
|
icon="ellipsis-v"
|
||||||
narrow
|
narrow
|
||||||
data-testid="panel-menu-button"
|
data-testid="panel-menu-button"
|
||||||
className={cx(styles.menuItem, 'menu-icon')}
|
className={cx(styles.menuItem, dragClassCancel, 'menu-icon')}
|
||||||
/>
|
/>
|
||||||
</Dropdown>
|
</Dropdown>
|
||||||
)}
|
)}
|
||||||
@ -148,7 +152,11 @@ export function PanelChrome({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{statusMessage && (
|
{statusMessage && (
|
||||||
<PanelStatus className={styles.errorContainer} message={statusMessage} onClick={statusMessageOnClick} />
|
<PanelStatus
|
||||||
|
className={cx(styles.errorContainer, dragClassCancel)}
|
||||||
|
message={statusMessage}
|
||||||
|
onClick={statusMessageOnClick}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { css } from '@emotion/css';
|
import { css, cx } from '@emotion/css';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { Icon } from '../Icon/Icon';
|
import { Icon } from '../Icon/Icon';
|
||||||
@ -8,9 +8,10 @@ import { TitleItem } from './TitleItem';
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
description: string | (() => string);
|
description: string | (() => string);
|
||||||
|
className?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function PanelDescription({ description }: Props) {
|
export function PanelDescription({ description, className }: Props) {
|
||||||
const styles = getStyles();
|
const styles = getStyles();
|
||||||
|
|
||||||
const getDescriptionContent = (): JSX.Element => {
|
const getDescriptionContent = (): JSX.Element => {
|
||||||
@ -26,7 +27,7 @@ export function PanelDescription({ description }: Props) {
|
|||||||
|
|
||||||
return description !== '' ? (
|
return description !== '' ? (
|
||||||
<Tooltip interactive content={getDescriptionContent}>
|
<Tooltip interactive content={getDescriptionContent}>
|
||||||
<TitleItem className={styles.description}>
|
<TitleItem className={cx(className, styles.description)}>
|
||||||
<Icon name="info-circle" size="lg" title="description" />
|
<Icon name="info-circle" size="lg" title="description" />
|
||||||
</TitleItem>
|
</TitleItem>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
@ -240,6 +240,7 @@ export class DashboardGrid extends PureComponent<Props, State> {
|
|||||||
cols={GRID_COLUMN_COUNT}
|
cols={GRID_COLUMN_COUNT}
|
||||||
rowHeight={GRID_CELL_HEIGHT}
|
rowHeight={GRID_CELL_HEIGHT}
|
||||||
draggableHandle=".grid-drag-handle"
|
draggableHandle=".grid-drag-handle"
|
||||||
|
draggableCancel=".grid-drag-cancel"
|
||||||
layout={this.buildLayout()}
|
layout={this.buildLayout()}
|
||||||
onDragStop={this.onDragStop}
|
onDragStop={this.onDragStop}
|
||||||
onResize={this.onResize}
|
onResize={this.onResize}
|
||||||
|
@ -636,6 +636,8 @@ export class PanelStateWrapper extends PureComponent<Props, State> {
|
|||||||
const title = panel.getDisplayTitle();
|
const title = panel.getDisplayTitle();
|
||||||
const padding: PanelPadding = plugin.noPadding ? 'none' : 'md';
|
const padding: PanelPadding = plugin.noPadding ? 'none' : 'md';
|
||||||
|
|
||||||
|
const dragClass = !(isViewing || isEditing) ? 'grid-drag-handle' : '';
|
||||||
|
|
||||||
const titleItems = [
|
const titleItems = [
|
||||||
<PanelHeaderTitleItems
|
<PanelHeaderTitleItems
|
||||||
key="title-items"
|
key="title-items"
|
||||||
@ -674,6 +676,8 @@ export class PanelStateWrapper extends PureComponent<Props, State> {
|
|||||||
description={!!panel.description ? this.onShowPanelDescription : undefined}
|
description={!!panel.description ? this.onShowPanelDescription : undefined}
|
||||||
titleItems={titleItems}
|
titleItems={titleItems}
|
||||||
menu={menu}
|
menu={menu}
|
||||||
|
dragClass={dragClass}
|
||||||
|
dragClassCancel="grid-drag-cancel"
|
||||||
padding={padding}
|
padding={padding}
|
||||||
>
|
>
|
||||||
{(innerWidth, innerHeight) => (
|
{(innerWidth, innerHeight) => (
|
||||||
|
Loading…
Reference in New Issue
Block a user