Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

Commit

Permalink
Allow sidebar side to be controlled
Browse files Browse the repository at this point in the history
Summary:
Each time the sidebar closes and re opens it loses its previous side, this is very frustrating.

Given we dont know where / how the sidebar size atom should be scoped, (component level, plugin level local storage) we just expose the resize handler for developer to control this aspect if they want to.

Reviewed By: mweststrate

Differential Revision: D56237144

fbshipit-source-id: fa2fc67e813d722852d57808a23a15f8d5ba7e9e
  • Loading branch information
Luke De Feo authored and facebook-github-bot committed Apr 18, 2024
1 parent 5cb4c0d commit 14b6931
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions desktop/flipper-plugin/src/plugin/FlipperLib.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export interface FlipperLib {
children: any;
width?: number;
minWidth?: number;
onResize?: (width: number, height: number) => void;
}): ReactElement | null;
/**
* @returns
Expand Down
1 change: 1 addition & 0 deletions desktop/flipper-plugin/src/ui/DetailSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type DetailSidebarProps = {
children: any;
width?: number;
minWidth?: number;
onResize?: (width: number, height: number) => void;
};

/* eslint-disable react-hooks/rules-of-hooks */
Expand Down
12 changes: 10 additions & 2 deletions desktop/flipper-plugin/src/ui/MasterDetailWithPowerSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,14 @@ type MasterDetailProps<T> = {
tableManagerRef?: React.RefObject<DataTableManager<T> | undefined>;
}>;
/**
* Default size of the sidebar.
* Size of the sidebar, can be controlled by listening to onResize, otherwise the initial size
*/
sidebarSize?: number;

/**
* Fired when user changes sidebar, allows you to control size of side bar and have it persist at whatever level is appropriate
*/
onResize?: (width: number, height: number) => void;
/**
* If provided, this atom will be used to store selection in.
*/
Expand Down Expand Up @@ -82,6 +87,7 @@ export function MasterDetailWithPowerSearch<T extends object>({
sidebarComponent,
sidebarPosition,
sidebarSize,
onResize,
onSelect,
actionsTop,
extraActions,
Expand Down Expand Up @@ -244,7 +250,9 @@ export function MasterDetailWithPowerSearch<T extends object>({
return (
<Layout.Container grow>
{table}
<DetailSidebar width={sidebarSize}>{sidebar}</DetailSidebar>
<DetailSidebar onResize={onResize} width={sidebarSize}>
{sidebar}
</DetailSidebar>
</Layout.Container>
);
case 'right':
Expand Down
3 changes: 3 additions & 0 deletions desktop/flipper-ui/src/sandy-chrome/DetailSidebarImpl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ export type DetailSidebarProps = {
children: any;
width?: number;
minWidth?: number;
onResize?: (width: number, height: number) => void;
};

/* eslint-disable react-hooks/rules-of-hooks */
export function DetailSidebarImpl({
children,
width,
minWidth,
onResize,
}: DetailSidebarProps) {
const [domNode, setDomNode] = useState(
document.getElementById('detailsSidebar'),
Expand Down Expand Up @@ -70,6 +72,7 @@ export function DetailSidebarImpl({
domNode &&
ReactDOM.createPortal(
<_Sidebar
onResize={onResize}
minWidth={minWidth}
width={width || 300}
position="right"
Expand Down

0 comments on commit 14b6931

Please sign in to comment.