Skip to content

Commit

Permalink
nav poc
Browse files Browse the repository at this point in the history
  • Loading branch information
christineweng committed Oct 24, 2024
1 parent a2a43e7 commit f5fb866
Show file tree
Hide file tree
Showing 35 changed files with 595 additions and 72 deletions.
6 changes: 5 additions & 1 deletion packages/kbn-expandable-flyout/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ 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';
export {
type FlyoutPanels as ExpandableFlyoutState,
type FlyoutHistoryProps,
} from './src/store/state';

export { ExpandableFlyoutProvider } from './src/provider';
export { withExpandableFlyoutProvider } from './src/with_provider';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
openPreviewPanelAction,
openRightPanelAction,
previousPreviewPanelAction,
goBackAction,
} from '../store/actions';
import { useDispatch } from '../store/redux';
import { FlyoutPanelProps, type ExpandableFlyoutApi } from '../types';
Expand Down Expand Up @@ -87,6 +88,13 @@ export const useExpandableFlyoutApi = () => {
}, [dispatch, id, history]);

const closePanels = useCallback(() => dispatch(closePanelsAction({ id })), [dispatch, id]);
const goBack = useCallback(() => {
if (id === REDUX_ID_FOR_MEMORY_STORAGE) {
dispatch(goBackAction({ id }));
} else {
history.goBack();
}
}, [dispatch, id, history]);

const api: ExpandableFlyoutApi = useMemo(
() => ({
Expand All @@ -99,6 +107,7 @@ export const useExpandableFlyoutApi = () => {
closePreviewPanel,
closeFlyout: closePanels,
previousPreviewPanel,
goBack,
}),
[
openPanels,
Expand All @@ -110,6 +119,7 @@ export const useExpandableFlyoutApi = () => {
closePreviewPanel,
closePanels,
previousPreviewPanel,
goBack,
]
);

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: [],
},
},
},
Expand Down Expand Up @@ -139,6 +140,7 @@ export const Left: Story<void> = () => {
id: 'left',
},
preview: undefined,
history: [],
},
},
},
Expand Down Expand Up @@ -171,6 +173,7 @@ export const Preview: Story<void> = () => {
id: 'preview1',
},
],
history: [],
},
},
},
Expand Down Expand Up @@ -206,6 +209,7 @@ export const MultiplePreviews: Story<void> = () => {
id: 'preview2',
},
],
history: [],
},
},
},
Expand All @@ -232,6 +236,7 @@ export const CollapsedPushMode: Story<void> = () => {
},
left: undefined,
preview: undefined,
history: [],
},
},
},
Expand Down Expand Up @@ -260,6 +265,7 @@ export const ExpandedPushMode: Story<void> = () => {
id: 'left',
},
preview: undefined,
history: [],
},
},
},
Expand Down Expand Up @@ -288,6 +294,7 @@ export const DisableTypeSelection: Story<void> = () => {
id: 'left',
},
preview: undefined,
history: [],
},
},
},
Expand Down Expand Up @@ -318,6 +325,7 @@ export const ResetWidths: Story<void> = () => {
id: 'left',
},
preview: undefined,
history: [],
},
},
},
Expand All @@ -343,6 +351,7 @@ export const DisableResizeWidthSelection: Story<void> = () => {
id: 'left',
},
preview: undefined,
history: [],
},
},
},
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: [],
},
},
},
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: [],
},
},
needsSync: true,
Expand Down Expand Up @@ -93,6 +94,7 @@ describe('UrlSynchronizer', () => {
right: { id: 'key1' },
left: { id: 'key2' },
preview: undefined,
history: [],
},
},
needsSync: true,
Expand Down
8 changes: 8 additions & 0 deletions packages/kbn-expandable-flyout/src/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export enum ActionType {
changeUserSectionWidths = 'change_user_section_widths',

resetAllUserWidths = 'reset_all_user_widths',
goBack = 'goBack',
}

export const openPanelsAction = createAction<{
Expand Down Expand Up @@ -197,3 +198,10 @@ export const changeUserSectionWidthsAction = createAction<{
}>(ActionType.changeUserSectionWidths);

export const resetAllUserChangedWidthsAction = createAction(ActionType.resetAllUserWidths);

export const goBackAction = createAction<{
/**
* Unique identifier for the flyout (either the urlKey or 'memory')
*/
id: string;
}>(ActionType.goBack);
Loading

0 comments on commit f5fb866

Please sign in to comment.