mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[8.13] [Unified Data Table] Update full screen handling to fix z-index issues in Kibana (#178788) (#179019)
# Backport This will backport the following commits from `main` to `8.13`: - [[Unified Data Table] Update full screen handling to fix z-index issues in Kibana (#178788)](https://github.com/elastic/kibana/pull/178788) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Davis McPhee","email":"davis.mcphee@elastic.co"},"sourceCommit":{"committedDate":"2024-03-20T02:07:47Z","message":"[Unified Data Table] Update full screen handling to fix z-index issues in Kibana (#178788)\n\n## Summary\r\n\r\nThis PR updates Unified Data Table to toggle a class on the body for\r\nfull screen mode instead of relying on `euiDataGrid__restrictBody` which\r\ncauses z-index issues elsewhere in Kibana, for example in Security\r\nAlerts:\r\n\r\n\r\n3b4b3515
-43f5-46dd-a194-316d76d497b9\r\n\r\n### Checklist\r\n\r\n- [ ] Any text added follows [EUI's writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\r\nsentence case text and includes [i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n- [ ]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas added for features that require explanation or tutorials\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n- [ ] [Flaky Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is usable by keyboard only (learn more\r\nabout [keyboard accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI touched in this PR does not create any new axe failures\r\n(run axe in browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n- [ ] If a plugin configuration key changed, check if it needs to be\r\nallowlisted in the cloud and added to the [docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n- [ ] This renders correctly on smaller devices using a responsive\r\nlayout. (You can test this [in your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n- [x] This was checked for [cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for breaking API changes and was [labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\nCo-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>","sha":"20990773c92a7446e30a55d9e895fb16dcbc70e9","branchLabelMapping":{"^v8.14.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:DataDiscovery","backport:prev-minor","Feature:UnifiedDataTable","v8.14.0"],"title":"[Unified Data Table] Update full screen handling to fix z-index issues in Kibana","number":178788,"url":"https://github.com/elastic/kibana/pull/178788","mergeCommit":{"message":"[Unified Data Table] Update full screen handling to fix z-index issues in Kibana (#178788)\n\n## Summary\r\n\r\nThis PR updates Unified Data Table to toggle a class on the body for\r\nfull screen mode instead of relying on `euiDataGrid__restrictBody` which\r\ncauses z-index issues elsewhere in Kibana, for example in Security\r\nAlerts:\r\n\r\n\r\n3b4b3515
-43f5-46dd-a194-316d76d497b9\r\n\r\n### Checklist\r\n\r\n- [ ] Any text added follows [EUI's writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\r\nsentence case text and includes [i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n- [ ]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas added for features that require explanation or tutorials\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n- [ ] [Flaky Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is usable by keyboard only (learn more\r\nabout [keyboard accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI touched in this PR does not create any new axe failures\r\n(run axe in browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n- [ ] If a plugin configuration key changed, check if it needs to be\r\nallowlisted in the cloud and added to the [docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n- [ ] This renders correctly on smaller devices using a responsive\r\nlayout. (You can test this [in your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n- [x] This was checked for [cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for breaking API changes and was [labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\nCo-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>","sha":"20990773c92a7446e30a55d9e895fb16dcbc70e9"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.14.0","branchLabelMappingKey":"^v8.14.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/178788","number":178788,"mergeCommit":{"message":"[Unified Data Table] Update full screen handling to fix z-index issues in Kibana (#178788)\n\n## Summary\r\n\r\nThis PR updates Unified Data Table to toggle a class on the body for\r\nfull screen mode instead of relying on `euiDataGrid__restrictBody` which\r\ncauses z-index issues elsewhere in Kibana, for example in Security\r\nAlerts:\r\n\r\n\r\n3b4b3515
-43f5-46dd-a194-316d76d497b9\r\n\r\n### Checklist\r\n\r\n- [ ] Any text added follows [EUI's writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\r\nsentence case text and includes [i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n- [ ]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas added for features that require explanation or tutorials\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n- [ ] [Flaky Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is usable by keyboard only (learn more\r\nabout [keyboard accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI touched in this PR does not create any new axe failures\r\n(run axe in browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n- [ ] If a plugin configuration key changed, check if it needs to be\r\nallowlisted in the cloud and added to the [docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n- [ ] This renders correctly on smaller devices using a responsive\r\nlayout. (You can test this [in your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n- [x] This was checked for [cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for breaking API changes and was [labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\nCo-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>","sha":"20990773c92a7446e30a55d9e895fb16dcbc70e9"}}]}] BACKPORT--> Co-authored-by: Davis McPhee <davis.mcphee@elastic.co>
This commit is contained in:
parent
5814aa95db
commit
24e7c9ab38
4 changed files with 108 additions and 1 deletions
|
@ -172,7 +172,7 @@
|
|||
}
|
||||
|
||||
// Ensure full screen data grids are not covered by elements with a z-index
|
||||
.euiDataGrid__restrictBody *:not(
|
||||
.unifiedDataTable__fullScreen *:not(
|
||||
.euiDataGrid--fullScreen,
|
||||
.euiDataGrid--fullScreen *,
|
||||
[data-euiportal='true'],
|
||||
|
|
|
@ -78,6 +78,7 @@ import {
|
|||
import { UnifiedDataTableFooter } from './data_table_footer';
|
||||
import { UnifiedDataTableAdditionalDisplaySettings } from './data_table_additional_display_settings';
|
||||
import { useRowHeight } from '../hooks/use_row_height';
|
||||
import { useFullScreenWatcher } from '../hooks/use_full_screen_watcher';
|
||||
|
||||
export interface UnifiedDataTableRenderCustomToolbarProps {
|
||||
toolbarProps: EuiDataGridCustomToolbarProps;
|
||||
|
@ -927,6 +928,8 @@ export const UnifiedDataTable = ({
|
|||
rowLineHeight: rowLineHeightOverride,
|
||||
});
|
||||
|
||||
const { dataGridId, setDataGridWrapper } = useFullScreenWatcher();
|
||||
|
||||
const isRenderComplete = loadingState !== DataLoadingState.loading;
|
||||
|
||||
if (!rowCount && loadingState === DataLoadingState.loading) {
|
||||
|
@ -967,6 +970,7 @@ export const UnifiedDataTable = ({
|
|||
<UnifiedDataTableContext.Provider value={unifiedDataTableContextValue}>
|
||||
<span className="unifiedDataTable__inner">
|
||||
<div
|
||||
ref={setDataGridWrapper}
|
||||
data-test-subj="discoverDocTable"
|
||||
data-render-complete={isRenderComplete}
|
||||
data-shared-item=""
|
||||
|
@ -976,6 +980,7 @@ export const UnifiedDataTable = ({
|
|||
className={classnames(className, 'unifiedDataTable__table')}
|
||||
>
|
||||
<EuiDataGridMemoized
|
||||
id={dataGridId}
|
||||
aria-describedby={randomId}
|
||||
aria-labelledby={ariaLabelledBy}
|
||||
columns={euiGridColumns}
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { act, renderHook } from '@testing-library/react-hooks';
|
||||
import {
|
||||
EUI_DATA_GRID_FULL_SCREEN_CLASS,
|
||||
UNIFIED_DATA_TABLE_FULL_SCREEN_CLASS,
|
||||
useFullScreenWatcher,
|
||||
} from './use_full_screen_watcher';
|
||||
|
||||
describe('useFullScreenWatcher', () => {
|
||||
it(`should add and remove ${UNIFIED_DATA_TABLE_FULL_SCREEN_CLASS} class from the body when toggling full screen`, async () => {
|
||||
const { result } = renderHook(() => useFullScreenWatcher());
|
||||
const dataGridWrapper = document.createElement('div');
|
||||
document.body.appendChild(dataGridWrapper);
|
||||
act(() => {
|
||||
result.current.setDataGridWrapper(dataGridWrapper);
|
||||
});
|
||||
const dataGrid = document.createElement('div');
|
||||
dataGrid.id = result.current.dataGridId;
|
||||
dataGridWrapper.appendChild(dataGrid);
|
||||
await nextTick();
|
||||
expect(document.body).not.toHaveClass(UNIFIED_DATA_TABLE_FULL_SCREEN_CLASS);
|
||||
dataGrid.classList.add(EUI_DATA_GRID_FULL_SCREEN_CLASS);
|
||||
await nextTick();
|
||||
expect(document.body).toHaveClass(UNIFIED_DATA_TABLE_FULL_SCREEN_CLASS);
|
||||
dataGrid.classList.remove(EUI_DATA_GRID_FULL_SCREEN_CLASS);
|
||||
await nextTick();
|
||||
expect(document.body).not.toHaveClass(UNIFIED_DATA_TABLE_FULL_SCREEN_CLASS);
|
||||
});
|
||||
});
|
||||
|
||||
const nextTick = () => {
|
||||
return act(() => {
|
||||
return new Promise((resolve) =>
|
||||
requestAnimationFrame(() => {
|
||||
resolve();
|
||||
})
|
||||
);
|
||||
});
|
||||
};
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { useGeneratedHtmlId, useMutationObserver } from '@elastic/eui';
|
||||
import { useCallback, useState } from 'react';
|
||||
|
||||
export const useFullScreenWatcher = () => {
|
||||
const dataGridId = useGeneratedHtmlId({ prefix: 'unifiedDataTable' });
|
||||
const [dataGridWrapper, setDataGridWrapper] = useState<HTMLElement | null>(null);
|
||||
const [dataGrid, setDataGrid] = useState<HTMLElement | null>(null);
|
||||
|
||||
const checkForDataGrid = useCallback<MutationCallback>(
|
||||
(_, observer) => {
|
||||
const foundDataGrid = document.getElementById(dataGridId);
|
||||
|
||||
if (foundDataGrid) {
|
||||
setDataGrid(foundDataGrid);
|
||||
observer.disconnect();
|
||||
}
|
||||
},
|
||||
[dataGridId]
|
||||
);
|
||||
|
||||
const watchForFullScreen = useCallback<MutationCallback>(() => {
|
||||
if (dataGrid) {
|
||||
toggleFullScreen(dataGrid);
|
||||
}
|
||||
}, [dataGrid]);
|
||||
|
||||
useMutationObserver(dataGridWrapper, checkForDataGrid, { childList: true, subtree: true });
|
||||
|
||||
useMutationObserver(dataGrid, watchForFullScreen, {
|
||||
attributes: true,
|
||||
attributeFilter: ['class'],
|
||||
});
|
||||
|
||||
return { dataGridId, setDataGridWrapper };
|
||||
};
|
||||
|
||||
export const EUI_DATA_GRID_FULL_SCREEN_CLASS = 'euiDataGrid--fullScreen';
|
||||
export const UNIFIED_DATA_TABLE_FULL_SCREEN_CLASS = 'unifiedDataTable__fullScreen';
|
||||
|
||||
const toggleFullScreen = (dataGrid: HTMLElement) => {
|
||||
const fullScreenClass = dataGrid.classList.contains(EUI_DATA_GRID_FULL_SCREEN_CLASS);
|
||||
|
||||
if (fullScreenClass) {
|
||||
document.body.classList.add(UNIFIED_DATA_TABLE_FULL_SCREEN_CLASS);
|
||||
} else {
|
||||
document.body.classList.remove(UNIFIED_DATA_TABLE_FULL_SCREEN_CLASS);
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue