Skip to content

Commit

Permalink
feat(AppLayout): Add Split Panel drawer support (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
jessieweiyi authored Sep 24, 2021
1 parent e9c6463 commit 0c2ab95
Show file tree
Hide file tree
Showing 9 changed files with 630 additions and 83 deletions.
35 changes: 33 additions & 2 deletions src/layouts/AppLayout/AppLayout.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

### Open/Close Help Panel

You can invoke the openHelpPanel method available from the AppLayoutContext from your component (must be descendants of AppLayout component) to trigger open of the help panel programmatically.
Expand Down Expand Up @@ -56,6 +57,8 @@ import AppLayout, { Notification, useAppLayoutContext } from 'aws-northstar/layo
import Box from 'aws-northstar/layouts/Box';
import Header from 'aws-northstar/components/Header';
import SideNavigation, { SideNavigationItemType } from 'aws-northstar/components/SideNavigation';
import ColumnLayout, { Column } from 'aws-northstar/layouts/ColumnLayout';
import KeyValuePair from 'aws-northstar/components/KeyValuePair';
import Badge from 'aws-northstar/components/Badge';
import BreadcrumbGroup from 'aws-northstar/components/BreadcrumbGroup';
import HelpPanel from 'aws-northstar/components/HelpPanel';
Expand Down Expand Up @@ -108,6 +111,28 @@ const helpPanel = (
<Heading variant="h5">h5 section header</Heading>
</HelpPanel>
);
const splitPanel = (<ColumnLayout>
<Column key="column1">
<Stack>
<KeyValuePair label="Distribution Id" value="SLCCSMWOHOFUY0"></KeyValuePair>
<KeyValuePair label="Domain name" value="bbb.cloudfront.net"></KeyValuePair>
</Stack>
</Column>
<Column key="column2">
<Stack>
<KeyValuePair label="Price class" value="Use only US, Canada, Europe, and Asia"></KeyValuePair>
<KeyValuePair label="CNAMEs"></KeyValuePair>
</Stack>
</Column>
<Column key="column3">
<Stack>
<KeyValuePair label="SSL certificate" value="Default CloudFront SSL certificate"></KeyValuePair>
<KeyValuePair label="Custom SSL client support"></KeyValuePair>
<KeyValuePair label="Logging" value="Off"></KeyValuePair>
</Stack>
</Column>
</ColumnLayout>);

const breadcrumbGroup = (
<BreadcrumbGroup
items={[
Expand Down Expand Up @@ -158,8 +183,9 @@ const defaultNotifications = [

const MainContent = () => {
const { openHelpPanel,
openSplitPanel,
addNotification,
dismissNotifications } = useAppLayoutContext();
dismissNotifications } = useAppLayoutContext();

const [ notificationId, setNotificationId ] = useState();

Expand All @@ -182,11 +208,15 @@ const MainContent = () => {
dismissNotifications();
}, [dismissNotifications]);

return (<Box bgcolor="grey.300" width="100%" height="1000px">
return (<Box bgcolor="grey.300" width="100%" height="800px">
<Stack>
Main Content
<Button onClick={() => openHelpPanel()}>Open Help Panel</Button>
<Button onClick={() => openHelpPanel(false)}>Close Help Panel</Button>
<Button onClick={() => {
openSplitPanel();
}}>Open Split Panel</Button>
<Button onClick={() => openSplitPanel(false)}>Close Split Panel</Button>
<Button onClick={handleAddClick}>Add New Notification</Button>
<Button onClick={handleRemoveLastClick}>Remove Last Added Notification</Button>
<Button onClick={handleRemoveAll}>Remove All notifications</Button>
Expand All @@ -205,6 +235,7 @@ const handleDismiss = (id) => {
header={header}
navigation={navigation}
helpPanel={helpPanel}
splitPanel={splitPanel}
breadcrumbs={breadcrumbGroup}
notifications={notifications.map(n => ({ ...n, onDismiss: () => handleDismiss(n.id) }))}
>
Expand Down
24 changes: 11 additions & 13 deletions src/layouts/AppLayout/components/Sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ import Close from '@material-ui/icons/Close';
import IconButton from '@material-ui/core/IconButton';

const useStyles = makeStyles<Theme, SidebarProps>((theme) => ({
hide: {
display: 'none',
},
drawer: {
height: '100%',
flexShrink: 0,
Expand Down Expand Up @@ -59,14 +56,11 @@ const useStyles = makeStyles<Theme, SidebarProps>((theme) => ({
},
},
sidebar: {
display: 'none',
[theme.breakpoints.up('sm')]: {
display: 'flex',
borderRadius: 0,
backgroundColor: theme.palette.background.paper,
borderRight: `1px solid ${theme.palette.grey['200']}`,
minWidth: '50px',
},
display: 'flex',
borderRadius: 0,
backgroundColor: theme.palette.background.paper,
borderRight: `1px solid ${theme.palette.grey['200']}`,
minWidth: '50px',
},
}));

Expand All @@ -78,6 +72,7 @@ export enum SidebarType {
export interface SidebarProps {
sidebarWidth: number;
isSidebarOpen: string;
displayIcon: boolean;
setIsSidebarOpen: (open: string) => void;
type: SidebarType;
renderIcon: (rootClasses: string) => ReactNode;
Expand All @@ -96,7 +91,10 @@ const Sidebar: FunctionComponent<SidebarProps> = (props) => {

return (
<>
{props.type === SidebarType.SIDE_NAVIGATION && !isOpen && props.renderIcon(classes.sidebar)}
{props.displayIcon &&
props.type === SidebarType.SIDE_NAVIGATION &&
!isOpen &&
props.renderIcon(classes.sidebar)}
<Drawer
className={classes.drawer}
variant="persistent"
Expand All @@ -116,7 +114,7 @@ const Sidebar: FunctionComponent<SidebarProps> = (props) => {
</div>
{props.children}
</Drawer>
{props.type === SidebarType.HELP_PANEL && !isOpen && props.renderIcon(classes.sidebar)}
{props.displayIcon && props.type === SidebarType.HELP_PANEL && !isOpen && props.renderIcon(classes.sidebar)}
</>
);
};
Expand Down
99 changes: 99 additions & 0 deletions src/layouts/AppLayout/components/SplitPanel/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/** *******************************************************************************************************************
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License").
You may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. *
******************************************************************************************************************** */
import React from 'react';
import { render, cleanup, fireEvent, act } from '@testing-library/react';
import SplitPanel from '.';

const mockSetIsSplitPanelOpen = jest.fn();

describe('SplitPanel', () => {
beforeEach(() => {
jest.clearAllMocks();
cleanup();
});

it('renders the Split Panel', () => {
const { getByText, getByTestId } = render(
<SplitPanel fullMode isSplitPanelOpen={true} setIsSplitPanelOpen={mockSetIsSplitPanelOpen}>
SplitPanel
</SplitPanel>
);

expect(getByText('SplitPanel')).toBeVisible();
expect(getByTestId('close-split-panel')).toBeVisible();
expect(getByTestId('toggle-expand-split-panel')).toBeVisible();
expect(getByTestId('resize-split-panel')).toBeVisible();
});

it('renders the Split Panel in mobile view', () => {
const { getByText, getByTestId, queryByTestId } = render(
<SplitPanel fullMode={false} isSplitPanelOpen={true} setIsSplitPanelOpen={mockSetIsSplitPanelOpen}>
SplitPanel
</SplitPanel>
);

expect(getByText('SplitPanel')).toBeVisible();
expect(getByTestId('close-split-panel')).toBeVisible();
expect(queryByTestId('toggle-expand-split-panel')).toBeNull();
expect(queryByTestId('resize-split-panel')).toBeNull();
});

it('should not render the Split Panel node when the isSplitPanelOpen is false', () => {
const { queryByText } = render(
<SplitPanel fullMode isSplitPanelOpen={false} setIsSplitPanelOpen={mockSetIsSplitPanelOpen}>
SplitPanel
</SplitPanel>
);

expect(queryByText('SplitPanel')).toBeNull();
});

it('should toggle the split panel when users click the FullscreenExit/Fullscreen button', () => {
const { getByText, getByTestId, queryByText } = render(
<SplitPanel fullMode isSplitPanelOpen={true} setIsSplitPanelOpen={mockSetIsSplitPanelOpen}>
SplitPanel
</SplitPanel>
);

expect(getByText('SplitPanel')).toBeVisible();

act(() => {
fireEvent.click(getByTestId('toggle-expand-split-panel'));
});

expect(queryByText('SplitPanel')).toBeNull();

act(() => {
fireEvent.click(getByTestId('toggle-expand-split-panel'));
});

expect(getByText('SplitPanel')).toBeVisible();
});

it('should trigger the setIsSplitPanelOpen when users click the close button', () => {
const { getByTestId } = render(
<SplitPanel fullMode isSplitPanelOpen={true} setIsSplitPanelOpen={mockSetIsSplitPanelOpen}>
SplitPanel
</SplitPanel>
);

act(() => {
fireEvent.click(getByTestId('close-split-panel'));
});

expect(mockSetIsSplitPanelOpen).toHaveBeenCalledWith(false);
});
});
Loading

0 comments on commit 0c2ab95

Please sign in to comment.