-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Fleet] Implement show policies action #217188
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
Merged
nchaulet
merged 5 commits into
elastic:main
from
nchaulet:feature-installed-integrations-policies
Apr 7, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2019735
[Fleet] Implement show policies action
nchaulet 6de92a5
Merge branch 'main' into feature-installed-integrations-policies
elasticmachine 0248d1d
fix after review
nchaulet c62f00a
Merge branch 'feature-installed-integrations-policies' of github.com:…
nchaulet 748da60
Merge branch 'main' into feature-installed-integrations-policies
elasticmachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...rations/sections/epm/screens/installed_integrations/components/package_policies_panel.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| * 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; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import React from 'react'; | ||
|
|
||
| import { EuiFlexGroup, EuiFlexItem, EuiText, useEuiPaddingCSS } from '@elastic/eui'; | ||
|
|
||
| import type { PackageInfo } from '../../../../../../../../common'; | ||
| import { IntegrationsStateContextProvider } from '../../../../../hooks'; | ||
| import type { InstalledPackageUIPackageListItem } from '../types'; | ||
| import { TableIcon } from '../../../../../../../components/package_icon'; | ||
| import { PackagePoliciesPage } from '../../detail/policies'; | ||
| import { useViewPolicies } from '../hooks/use_url_filters'; | ||
|
|
||
| import { ResizablePanel } from './resizable_panel'; | ||
|
|
||
| export const PackagePoliciesPanel: React.FunctionComponent<{ | ||
| installedPackage: InstalledPackageUIPackageListItem; | ||
| }> = ({ installedPackage }) => { | ||
| const { addViewPolicies } = useViewPolicies(); | ||
| const paddingStyles = useEuiPaddingCSS(); | ||
| const cssStyles = [paddingStyles.s]; | ||
|
|
||
| const title = ( | ||
| <EuiFlexGroup gutterSize="s" alignItems="center"> | ||
| <EuiFlexItem grow={false}> | ||
| <TableIcon | ||
| size="m" | ||
| icons={installedPackage.icons} | ||
| packageName={installedPackage.name} | ||
| version={installedPackage.version} | ||
| /> | ||
| </EuiFlexItem> | ||
| <EuiFlexItem grow={false}> | ||
| <EuiText size="s">{installedPackage.title}</EuiText> | ||
| </EuiFlexItem> | ||
| </EuiFlexGroup> | ||
| ); | ||
|
|
||
| const content = ( | ||
| <div css={cssStyles}> | ||
| <IntegrationsStateContextProvider> | ||
| <PackagePoliciesPage embedded={true} packageInfo={installedPackage as any as PackageInfo} /> | ||
| </IntegrationsStateContextProvider> | ||
| </div> | ||
| ); | ||
|
|
||
| return <ResizablePanel title={title} content={content} onClose={() => addViewPolicies('')} />; | ||
| }; |
226 changes: 226 additions & 0 deletions
226
...s/integrations/sections/epm/screens/installed_integrations/components/resizable_panel.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,226 @@ | ||
| /* | ||
| * 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; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import React, { useState, useCallback, useRef, useEffect } from 'react'; | ||
| import { | ||
| EuiButtonIcon, | ||
| EuiFlexGroup, | ||
| EuiFlexItem, | ||
| EuiPortal, | ||
| useEuiPaddingCSS, | ||
| useEuiTheme, | ||
| } from '@elastic/eui'; | ||
| import { EuiResizableButton, EuiPanel, keys } from '@elastic/eui'; | ||
| import { css } from '@emotion/react'; | ||
| import { i18n } from '@kbn/i18n'; | ||
|
|
||
| const getMouseOrTouchY = ( | ||
| e: TouchEvent | MouseEvent | React.MouseEvent | React.TouchEvent | ||
| ): number => { | ||
| const x = (e as TouchEvent).targetTouches | ||
| ? (e as TouchEvent).targetTouches[0].pageY | ||
| : (e as MouseEvent).pageY; | ||
| return -x; | ||
| }; | ||
|
|
||
| export const ResizablePanelComponent: React.FunctionComponent<{ | ||
| topBar: React.ReactNode; | ||
| children: React.ReactNode; | ||
| isCollapsed: boolean; | ||
| }> = ({ children, isCollapsed, topBar }) => { | ||
| const euiTheme = useEuiTheme(); | ||
| const [panelHeight, setPanelHeight] = useState(300); | ||
| const initialPanelHeight = useRef(panelHeight); | ||
| const initialMouseY = useRef(0); | ||
|
|
||
| const normalizeHeight = useCallback( | ||
| (height: number) => { | ||
| const marginTop = parseInt(euiTheme.euiTheme.size.xxxxl, 10); | ||
| // Be sure to not go over top bar | ||
| return Math.min(Math.max(height, 0), window.innerHeight - marginTop * 3); | ||
| }, | ||
| [euiTheme.euiTheme.size.xxxxl] | ||
| ); | ||
|
|
||
| useEffect(() => { | ||
| function onResize() { | ||
| const normalizedHeight = normalizeHeight(panelHeight); | ||
| if (normalizedHeight !== panelHeight) { | ||
| setPanelHeight(normalizedHeight); | ||
| } | ||
| } | ||
| window.addEventListener('resize', onResize); | ||
| return () => { | ||
| window.removeEventListener('resize', onResize); | ||
| }; | ||
| }, [panelHeight, normalizeHeight]); | ||
|
|
||
| const onMouseMove = useCallback( | ||
| (e: MouseEvent | TouchEvent) => { | ||
| const mouseOffset = getMouseOrTouchY(e) - initialMouseY.current; | ||
| const changedPanelHeight = initialPanelHeight.current + mouseOffset; | ||
|
|
||
| setPanelHeight(normalizeHeight(changedPanelHeight)); | ||
| }, | ||
| [normalizeHeight] | ||
| ); | ||
|
|
||
| const onMouseUp = useCallback(() => { | ||
| initialMouseY.current = 0; | ||
|
|
||
| window.removeEventListener('mousemove', onMouseMove); | ||
| window.removeEventListener('mouseup', onMouseUp); | ||
| window.removeEventListener('touchmove', onMouseMove); | ||
| window.removeEventListener('touchend', onMouseUp); | ||
| }, [onMouseMove]); | ||
|
|
||
| const onMouseDown = useCallback( | ||
| (e: React.MouseEvent | React.TouchEvent) => { | ||
| initialMouseY.current = getMouseOrTouchY(e); | ||
| initialPanelHeight.current = panelHeight; | ||
|
|
||
| // Window event listeners instead of React events are used | ||
| // in case the user's mouse leaves the component | ||
| window.addEventListener('mousemove', onMouseMove); | ||
| window.addEventListener('mouseup', onMouseUp); | ||
| window.addEventListener('touchmove', onMouseMove); | ||
| window.addEventListener('touchend', onMouseUp); | ||
| }, | ||
| [panelHeight, onMouseMove, onMouseUp] | ||
| ); | ||
|
|
||
| const onKeyDown = useCallback( | ||
| (e: React.KeyboardEvent) => { | ||
| const KEYBOARD_OFFSET = 10; | ||
|
|
||
| switch (e.key) { | ||
| case keys.ARROW_UP: | ||
| e.preventDefault(); // Safari+VO will screen reader navigate off the button otherwise | ||
| setPanelHeight((currentPanelHeight) => | ||
| normalizeHeight(currentPanelHeight + KEYBOARD_OFFSET) | ||
| ); | ||
| break; | ||
| case keys.ARROW_DOWN: | ||
| e.preventDefault(); // Safari+VO will screen reader navigate off the button otherwise | ||
| setPanelHeight((currentPanelHeight) => | ||
| normalizeHeight(currentPanelHeight - KEYBOARD_OFFSET) | ||
| ); | ||
| } | ||
| }, | ||
| [normalizeHeight] | ||
| ); | ||
|
|
||
| return ( | ||
| <EuiPanel | ||
| css={css` | ||
| position: fixed; | ||
| padding: 0; | ||
| bottom: 0; | ||
| background: ${euiTheme.euiTheme.colors.backgroundBasePlain}; | ||
| `} | ||
| > | ||
| {topBar} | ||
| <EuiResizableButton | ||
| css={css` | ||
| position: absolute; | ||
| top: 0; | ||
| `} | ||
| onMouseDown={onMouseDown} | ||
| onTouchStart={onMouseDown} | ||
| onKeyDown={onKeyDown} | ||
| disabled={isCollapsed} | ||
| /> | ||
| <EuiPanel | ||
| paddingSize="none" | ||
| css={css` | ||
| background: ${euiTheme.euiTheme.colors.backgroundBasePlain}; | ||
| height: ${isCollapsed ? 0 : panelHeight}px; | ||
| overflow: auto; | ||
| `} | ||
| > | ||
| {children} | ||
| </EuiPanel> | ||
| </EuiPanel> | ||
| ); | ||
| }; | ||
|
|
||
| export const ResizablePanel: React.FunctionComponent<{ | ||
| title: React.ReactNode; | ||
| content: React.ReactNode; | ||
| onClose: () => void; | ||
| }> = ({ title, content, onClose }) => { | ||
| const euiTheme = useEuiTheme(); | ||
|
|
||
| const paddingStyles = useEuiPaddingCSS(); | ||
| const cssStyles = [paddingStyles.m]; | ||
|
|
||
| const toggleCollpase = useCallback(() => { | ||
| setIsCollapsed((current) => !current); | ||
| }, []); | ||
|
|
||
| const [isCollapsed, setIsCollapsed] = useState(false); | ||
|
|
||
| const topBar = ( | ||
| <EuiFlexGroup | ||
| css={css` | ||
| background: ${euiTheme.euiTheme.colors.backgroundBaseFormsPrepend}; | ||
| ${cssStyles} | ||
| `} | ||
| responsive={false} | ||
| gutterSize="s" | ||
| > | ||
| <EuiFlexItem>{title}</EuiFlexItem> | ||
| <EuiFlexItem grow={false}> | ||
| <EuiFlexGroup responsive={false} gutterSize="none"> | ||
| <EuiFlexItem grow={false}> | ||
| {isCollapsed ? ( | ||
| <EuiButtonIcon | ||
| key="arrowUp" | ||
| iconType="arrowUp" | ||
| aria-label={i18n.translate( | ||
| 'xpack.fleet.integrationsResizablePanel.collapseButton', | ||
| { defaultMessage: 'Collapse panel' } | ||
| )} | ||
| color="text" | ||
| onClick={toggleCollpase} | ||
| /> | ||
| ) : ( | ||
| <EuiButtonIcon | ||
| key="arrowDown" | ||
| iconType="arrowDown" | ||
| aria-label={i18n.translate( | ||
| 'xpack.fleet.integrationsResizablePanel.collapseButton', | ||
| { defaultMessage: 'Collapse panel' } | ||
| )} | ||
| color="text" | ||
| onClick={toggleCollpase} | ||
| /> | ||
| )} | ||
| </EuiFlexItem> | ||
| <EuiFlexItem grow={false}> | ||
| <EuiButtonIcon | ||
| iconType="cross" | ||
| aria-label={i18n.translate('xpack.fleet.integrationsResizablePanel.closeButton', { | ||
| defaultMessage: 'Close panel', | ||
| })} | ||
| color="text" | ||
| onClick={onClose} | ||
| /> | ||
| </EuiFlexItem> | ||
| </EuiFlexGroup> | ||
| </EuiFlexItem> | ||
| </EuiFlexGroup> | ||
| ); | ||
|
|
||
| return ( | ||
| <EuiPortal> | ||
| <ResizablePanelComponent isCollapsed={isCollapsed} topBar={topBar}> | ||
| {content} | ||
| </ResizablePanelComponent> | ||
| </EuiPortal> | ||
| ); | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heavily inspired from https://eui.elastic.co/#/layout/resizable-container#custom-resize-logic,
I tried two approach: