forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution] [Flyout] drive flyout state with url or memory + …
…support back button navigation from timelines (elastic#169661) ## Summary This is a PoC for flyout state (left, right, preview panels) stored entirely in the url without separate syncing mechanism. It is also possible to opt in for in-memory storage. ### This vs current solution: - **browser navigation is supported** - we dont need to sync anything with in-memory state - we can remove useImperativeHandle from expandable flyout package - flyout state can be updated on the individual widget level, without prop drilling - when clicking between alerts, current flyout arrangement is retained - so the tabs you have open etc are still there (no custom code required) - **it is now possible to investigate something in timeline using the flyout action & go back to the flyout view** elastic/security-team#8135 --------- Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
545e472
commit a2a6cd2
Showing
59 changed files
with
722 additions
and
718 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,9 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export const EXPANDABLE_FLYOUT_URL_KEY = 'eventFlyout' as const; |
This file contains 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
98 changes: 98 additions & 0 deletions
98
packages/kbn-expandable-flyout/src/context/memory_state_provider.tsx
This file contains 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,98 @@ | ||
/* | ||
* 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 React, { FC, PropsWithChildren, useCallback, useMemo, useReducer } from 'react'; | ||
import { ActionType } from '../actions'; | ||
import { reducer } from '../reducer'; | ||
import type { ExpandableFlyoutContextValue, FlyoutPanelProps } from '../types'; | ||
import { initialState } from '../reducer'; | ||
import { ExpandableFlyoutContext } from '../context'; | ||
|
||
/** | ||
* In-memory state provider for the expandable flyout, for cases when we don't want changes to be persisted | ||
* in the url. | ||
*/ | ||
export const MemoryStateProvider: FC<PropsWithChildren<{}>> = ({ children }) => { | ||
const [state, dispatch] = useReducer(reducer, initialState); | ||
|
||
const openPanels = useCallback( | ||
({ | ||
right, | ||
left, | ||
preview, | ||
}: { | ||
right?: FlyoutPanelProps; | ||
left?: FlyoutPanelProps; | ||
preview?: FlyoutPanelProps; | ||
}) => dispatch({ type: ActionType.openFlyout, payload: { left, right, preview } }), | ||
[dispatch] | ||
); | ||
|
||
const openRightPanel = useCallback( | ||
(panel: FlyoutPanelProps) => dispatch({ type: ActionType.openRightPanel, payload: panel }), | ||
[] | ||
); | ||
|
||
const openLeftPanel = useCallback( | ||
(panel: FlyoutPanelProps) => dispatch({ type: ActionType.openLeftPanel, payload: panel }), | ||
[] | ||
); | ||
|
||
const openPreviewPanel = useCallback( | ||
(panel: FlyoutPanelProps) => dispatch({ type: ActionType.openPreviewPanel, payload: panel }), | ||
[] | ||
); | ||
|
||
const closeRightPanel = useCallback(() => dispatch({ type: ActionType.closeRightPanel }), []); | ||
|
||
const closeLeftPanel = useCallback(() => dispatch({ type: ActionType.closeLeftPanel }), []); | ||
|
||
const closePreviewPanel = useCallback(() => dispatch({ type: ActionType.closePreviewPanel }), []); | ||
|
||
const previousPreviewPanel = useCallback( | ||
() => dispatch({ type: ActionType.previousPreviewPanel }), | ||
[] | ||
); | ||
|
||
const closePanels = useCallback(() => { | ||
dispatch({ type: ActionType.closeFlyout }); | ||
}, []); | ||
|
||
const contextValue: ExpandableFlyoutContextValue = useMemo( | ||
() => ({ | ||
panels: state, | ||
openFlyout: openPanels, | ||
openRightPanel, | ||
openLeftPanel, | ||
openPreviewPanel, | ||
closeRightPanel, | ||
closeLeftPanel, | ||
closePreviewPanel, | ||
closeFlyout: closePanels, | ||
previousPreviewPanel, | ||
}), | ||
[ | ||
state, | ||
openPanels, | ||
openRightPanel, | ||
openLeftPanel, | ||
openPreviewPanel, | ||
closeRightPanel, | ||
closeLeftPanel, | ||
closePreviewPanel, | ||
closePanels, | ||
previousPreviewPanel, | ||
] | ||
); | ||
|
||
return ( | ||
<ExpandableFlyoutContext.Provider value={contextValue}> | ||
{children} | ||
</ExpandableFlyoutContext.Provider> | ||
); | ||
}; |
Oops, something went wrong.