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

[Security Solution][Expandable flyout] Introducing Flyout history in document flyout #184970

Merged
merged 5 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/kbn-expandable-flyout/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ To control (or mutate) flyout's layout, you can utilize [useExpandableFlyoutApi]

> The expandable flyout propagates the `onClose` callback from the EuiFlyout component. As we recommend having a single instance of the flyout in your application, it's up to the application's code to dispatch the event (through Redux, window events, observable, prop drilling...).
When calling `openFlyout`, the right panel state is automatically appended in the `history` slice in the redux context. To access the flyout's history, you can use the [useExpandableFlyoutHistory](https://github.com/elastic/kibana/blob/main/packages/kbn-expandable-flyout/src/hooks/use_expandable_flyout_history.ts) hook.

## Usage

To use the expandable flyout in your plugin, first you need wrap your code with the [context provider](https://github.com/elastic/kibana/blob/main/packages/kbn-expandable-flyout/src/context.tsx) at a high enough level as follows:
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-expandable-flyout/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export { ExpandableFlyout } from './src';

export { useExpandableFlyoutApi } from './src/hooks/use_expandable_flyout_api';
export { useExpandableFlyoutState } from './src/hooks/use_expandable_flyout_state';
export { useExpandableFlyoutHistory } from './src/hooks/use_expandable_flyout_history';

export { type FlyoutPanels as ExpandableFlyoutState } from './src/store/state';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe('Container', () => {
},
left: undefined,
preview: undefined,
history: [{ id: 'key' }],
},
},
},
Expand Down Expand Up @@ -85,6 +86,7 @@ describe('Container', () => {
id: 'key',
},
preview: undefined,
history: [],
},
},
},
Expand Down Expand Up @@ -112,6 +114,7 @@ describe('Container', () => {
id: 'key',
},
],
history: [],
},
},
},
Expand All @@ -137,6 +140,7 @@ describe('Container', () => {
},
left: undefined,
preview: undefined,
history: [],
},
},
},
Expand All @@ -163,6 +167,7 @@ describe('Container', () => {
},
left: undefined,
preview: undefined,
history: [],
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('PreviewSection', () => {
id: 'key',
},
],
history: [],
},
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { REDUX_ID_FOR_MEMORY_STORAGE } from '../constants';
import { useExpandableFlyoutContext } from '../context';
import { selectHistoryById, useSelector } from '../store/redux';

/**
* This hook allows you to access the flyout state, read open right, left and preview panels.
*/
export const useExpandableFlyoutHistory = () => {
const { urlKey } = useExpandableFlyoutContext();
// if no urlKey is provided, we are in memory storage mode and use the reserved word 'memory'
const id = urlKey || REDUX_ID_FOR_MEMORY_STORAGE;
return useSelector(selectHistoryById(id));
};
9 changes: 9 additions & 0 deletions packages/kbn-expandable-flyout/src/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export const Right: Story<void> = () => {
},
left: undefined,
preview: undefined,
history: [{ id: 'right' }],
},
},
},
Expand Down Expand Up @@ -139,6 +140,7 @@ export const Left: Story<void> = () => {
id: 'left',
},
preview: undefined,
history: [{ id: 'right' }],
},
},
},
Expand Down Expand Up @@ -171,6 +173,7 @@ export const Preview: Story<void> = () => {
id: 'preview1',
},
],
history: [{ id: 'right' }],
},
},
},
Expand Down Expand Up @@ -206,6 +209,7 @@ export const MultiplePreviews: Story<void> = () => {
id: 'preview2',
},
],
history: [{ id: 'right' }],
},
},
},
Expand All @@ -232,6 +236,7 @@ export const CollapsedPushMode: Story<void> = () => {
},
left: undefined,
preview: undefined,
history: [{ id: 'right' }],
},
},
},
Expand Down Expand Up @@ -260,6 +265,7 @@ export const ExpandedPushMode: Story<void> = () => {
id: 'left',
},
preview: undefined,
history: [{ id: 'right' }],
},
},
},
Expand Down Expand Up @@ -288,6 +294,7 @@ export const DisableTypeSelection: Story<void> = () => {
id: 'left',
},
preview: undefined,
history: [{ id: 'right' }],
},
},
},
Expand Down Expand Up @@ -318,6 +325,7 @@ export const ResetWidths: Story<void> = () => {
id: 'left',
},
preview: undefined,
history: [{ id: 'right' }],
},
},
},
Expand All @@ -343,6 +351,7 @@ export const DisableResizeWidthSelection: Story<void> = () => {
id: 'left',
},
preview: undefined,
history: [{ id: 'right' }],
},
},
},
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-expandable-flyout/src/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('ExpandableFlyout', () => {
},
left: undefined,
preview: undefined,
history: [{ id: 'key' }],
},
},
},
Expand Down
2 changes: 2 additions & 0 deletions packages/kbn-expandable-flyout/src/provider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('UrlSynchronizer', () => {
right: { id: 'key1' },
left: { id: 'key11' },
preview: undefined,
history: [{ id: 'key1' }],
},
},
needsSync: true,
Expand Down Expand Up @@ -93,6 +94,7 @@ describe('UrlSynchronizer', () => {
right: { id: 'key1' },
left: { id: 'key2' },
preview: undefined,
history: [{ id: 'key1' }],
},
},
needsSync: true,
Expand Down
Loading