Skip to content

Commit

Permalink
[kbn-grid-layout] EUI Visual Refresh Integration (elastic#204445)
Browse files Browse the repository at this point in the history
## Summary

Related to elastic#203132.
Closes [elastic#204592](elastic#204592).

This replaces all references to euiThemeVars in favor of the useEuiTheme
hook in the `kbn-grid-layout` package.

### Checklist

Check the PR satisfies following conditions.

Reviewers should verify this PR satisfies this list as well.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

### Identify risks

Does this PR introduce any risks? For example, consider risks like hard
to test bugs, performance regression, potential of data loss.

Describe the risk, its severity, and mitigation for each identified
risk. Invite stakeholders and evaluate how to proceed before merging.

- [ ] [See some risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
- [ ] ...

(cherry picked from commit 2b9104c)

# Conflicts:
#	packages/kbn-grid-layout/grid/grid_panel/drag_handle.tsx
#	packages/kbn-grid-layout/grid/grid_panel/resize_handle.tsx
#	packages/kbn-grid-layout/grid/grid_row/grid_row.tsx
#	src/platform/packages/private/kbn-grid-layout/grid/drag_preview.tsx
#	src/platform/packages/private/kbn-grid-layout/grid/use_grid_layout_state.ts
  • Loading branch information
cqliu1 committed Jan 28, 2025
1 parent 13bf14e commit 1d75dfe
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import React, { useEffect, useRef } from 'react';
import { combineLatest, skip } from 'rxjs';

import { transparentize, useEuiTheme } from '@elastic/eui';
import { css } from '@emotion/react';

import { GridLayoutStateManager } from './types';
Expand All @@ -22,6 +23,7 @@ export const DragPreview = ({
gridLayoutStateManager: GridLayoutStateManager;
}) => {
const dragPreviewRef = useRef<HTMLDivElement | null>(null);
const { euiTheme } = useEuiTheme();

useEffect(
() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import React, { forwardRef, useEffect, useMemo, useState } from 'react';
import { combineLatest, skip } from 'rxjs';

import { useEuiTheme } from '@elastic/eui';
import { css } from '@emotion/react';
import { euiThemeVars } from '@kbn/ui-theme';

import { GridLayoutStateManager } from '../types';
import { DragHandle, DragHandleApi } from './drag_handle';
Expand All @@ -30,6 +30,7 @@ export interface GridPanelProps {
export const GridPanel = forwardRef<HTMLDivElement, GridPanelProps>(
({ panelId, rowIndex, renderPanelContents, gridLayoutStateManager }, panelRef) => {
const [dragHandleApi, setDragHandleApi] = useState<DragHandleApi | null>(null);
const { euiTheme } = useEuiTheme();

/** Set initial styles based on state at mount to prevent styles from "blipping" */
const initialStyles = useMemo(() => {
Expand Down Expand Up @@ -74,7 +75,7 @@ export const GridPanel = forwardRef<HTMLDivElement, GridPanelProps>(
const { position: draggingPosition } = activePanel;
const runtimeSettings = gridLayoutStateManager.runtimeSettings$.getValue();

ref.style.zIndex = `${euiThemeVars.euiZModal}`;
ref.style.zIndex = `${euiTheme.levels.modal}`;
if (currentInteractionEvent?.type === 'resize') {
// if the current panel is being resized, ensure it is not shrunk past the size of a single cell
ref.style.width = `${Math.max(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { cloneDeep, pick } from 'lodash';
import { useEffect, useMemo, useRef } from 'react';
import { BehaviorSubject, combineLatest, debounceTime, distinctUntilChanged } from 'rxjs';
import useResizeObserver, { type ObservedSize } from 'use-resize-observer/polyfilled';

import { useEuiTheme } from '@elastic/eui';
import {
ActivePanel,
GridAccessMode,
Expand Down Expand Up @@ -43,6 +43,7 @@ export const useGridLayoutState = ({
} => {
const rowRefs = useRef<Array<HTMLDivElement | null>>([]);
const panelRefs = useRef<Array<{ [id: string]: HTMLDivElement | null }>>([]);
const { euiTheme } = useEuiTheme();

const expandedPanelId$ = useMemo(
() => new BehaviorSubject<string | undefined>(expandedPanelId),
Expand Down Expand Up @@ -107,7 +108,9 @@ export const useGridLayoutState = ({
runtimeSettings$,
interactionEvent$,
expandedPanelId$,
isMobileView$: new BehaviorSubject<boolean>(shouldShowMobileView(accessMode)),
isMobileView$: new BehaviorSubject<boolean>(
shouldShowMobileView(accessMode, euiTheme.breakpoint.m)
),
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Expand All @@ -131,7 +134,8 @@ export const useGridLayoutState = ({
...currentRuntimeSettings,
columnPixelWidth,
});
const isMobileView = shouldShowMobileView(currentAccessMode);
const isMobileView = shouldShowMobileView(currentAccessMode, euiTheme.breakpoint.m);

if (isMobileView !== gridLayoutStateManager.isMobileView$.getValue()) {
gridLayoutStateManager.isMobileView$.next(isMobileView);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { euiThemeVars } from '@kbn/ui-theme';
import { GridAccessMode } from '../types';

const getViewportWidth = () =>
window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;

export const shouldShowMobileView = (accessMode: GridAccessMode) =>
accessMode === 'VIEW' && getViewportWidth() < parseFloat(euiThemeVars.euiBreakpoints.m);
export const shouldShowMobileView = (accessMode: GridAccessMode, breakpoint: number) =>
accessMode === 'VIEW' && getViewportWidth() < breakpoint;
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"target/**/*"
],
"kbn_references": [
"@kbn/ui-theme",
"@kbn/i18n",
]
}

0 comments on commit 1d75dfe

Please sign in to comment.