Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VizPanelRenderer: Emit SetPanelAttention event #716

Merged
merged 9 commits into from
May 30, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import { GrafanaTheme2 } from '@grafana/data';
export function SceneGridLayoutRenderer({ model }: SceneComponentProps<SceneGridLayout>) {
const { children, isLazy, isDraggable, isResizable } = model.useState();

// Attention to handle keyboard and hover shortcuts
const [attention, setAttention] = React.useState<string | undefined>();

validateChildrenSize(children);

return (
Expand Down Expand Up @@ -66,6 +69,8 @@ export function SceneGridLayoutRenderer({ model }: SceneComponentProps<SceneGrid
index={index}
isLazy={isLazy}
totalCount={layout.length}
hasAttention={attention === gridItem.i}
setAttention={() => setAttention(gridItem.i)}
/>
))}
</ReactGridLayout>
Expand All @@ -82,10 +87,25 @@ interface GridItemWrapperProps extends React.HTMLAttributes<HTMLDivElement> {
index: number;
totalCount: number;
isLazy?: boolean;
hasAttention: boolean;
setAttention: () => void;
}

const GridItemWrapper = React.forwardRef<HTMLDivElement, GridItemWrapperProps>((props, ref) => {
const { grid, layoutItem, index, totalCount, isLazy, style, onLoad, onChange, children, ...divProps } = props;
const {
grid,
layoutItem,
index,
totalCount,
isLazy,
style,
onLoad,
onChange,
children,
hasAttention,
setAttention,
...divProps
} = props;
const sceneChild = grid.getSceneLayoutChild(layoutItem.i)!;
const className = sceneChild.getClassName?.();

Expand All @@ -97,6 +117,9 @@ const GridItemWrapper = React.forwardRef<HTMLDivElement, GridItemWrapperProps>((
{...divProps}
key={sceneChild.state.key!}
data-griditem-key={sceneChild.state.key}
data-attention={hasAttention}
onFocus={() => !hasAttention && setAttention()}
onMouseMove={() => !hasAttention && setAttention()}
className={cx(className, props.className)}
style={style}
ref={ref}
Expand All @@ -113,6 +136,9 @@ const GridItemWrapper = React.forwardRef<HTMLDivElement, GridItemWrapperProps>((
ref={ref}
key={sceneChild.state.key}
data-griditem-key={sceneChild.state.key}
data-attention={hasAttention}
onFocus={() => !hasAttention && setAttention()}
onMouseMove={() => !hasAttention && setAttention()}
className={cx(className, props.className)}
style={style}
>
Expand Down