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

Dashboard: Revert LayoutItemContext #83465

Merged
merged 4 commits into from Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 0 additions & 21 deletions packages/grafana-ui/src/components/Layout/LayoutItemContext.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/grafana-ui/src/components/index.ts
Expand Up @@ -267,8 +267,6 @@ export { Divider } from './Divider/Divider';
export { getDragStyles, type DragHandlePosition } from './DragHandle/DragHandle';
export { useSplitter } from './Splitter/useSplitter';

export { LayoutItemContext, type LayoutItemContextProps } from './Layout/LayoutItemContext';

/** @deprecated Please use non-legacy versions of these components */
const LegacyForms = {
SecretFormField,
Expand Down
34 changes: 5 additions & 29 deletions public/app/features/dashboard/dashgrid/DashboardGrid.tsx
@@ -1,12 +1,10 @@
import classNames from 'classnames';
import React, { PureComponent, CSSProperties, useRef, useCallback, useReducer, useMemo } from 'react';
import React, { PureComponent, CSSProperties } from 'react';
import ReactGridLayout, { ItemCallback } from 'react-grid-layout';
import AutoSizer from 'react-virtualized-auto-sizer';
import { Subscription } from 'rxjs';

import { zIndex } from '@grafana/data/src/themes/zIndex';
import { config } from '@grafana/runtime';
import { LayoutItemContext } from '@grafana/ui';
import appEvents from 'app/core/app_events';
import { GRID_CELL_HEIGHT, GRID_CELL_VMARGIN, GRID_COLUMN_COUNT } from 'app/core/constants';
import { contextSrv } from 'app/core/services/context_srv';
Expand Down Expand Up @@ -379,21 +377,6 @@ const GrafanaGridItem = React.forwardRef<HTMLDivElement, GrafanaGridItemProps>((
let width = 100;
let height = 100;

const boostedCount = useRef(0);
const [_, forceUpdate] = useReducer((x) => x + 1, 0);

const boostZIndex = useCallback(() => {
boostedCount.current += 1;
forceUpdate();

return () => {
boostedCount.current -= 1;
forceUpdate();
};
}, [forceUpdate]);

const ctxValue = useMemo(() => ({ boostZIndex }), [boostZIndex]);

const { gridWidth, gridPos, isViewing, windowHeight, windowWidth, descendingOrderIndex, ...divProps } = props;
const style: CSSProperties = props.style ?? {};

Expand Down Expand Up @@ -424,17 +407,10 @@ const GrafanaGridItem = React.forwardRef<HTMLDivElement, GrafanaGridItemProps>((

// props.children[0] is our main children. RGL adds the drag handle at props.children[1]
return (
<LayoutItemContext.Provider value={ctxValue}>
<div
{...divProps}
// .context-menu-open === $zindex-dropdown === 1030 (zIndex.ts)
style={{ ...divProps.style, zIndex: boostedCount.current === 0 ? descendingOrderIndex : zIndex.dropdown }}
ref={ref}
>
{/* Pass width and height to children as render props */}
{[props.children[0](width, height), props.children.slice(1)]}
</div>
</LayoutItemContext.Provider>
<div {...divProps} style={{ ...divProps.style, zIndex: descendingOrderIndex }} ref={ref}>
{/* Pass width and height to children as render props */}
{[props.children[0](width, height), props.children.slice(1)]}
</div>
);
});

Expand Down