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

[fix] hide side panel close button when data preview is open #2174

Merged
merged 1 commit into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/actions/src/action-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export const ActionTypes = {
TOGGLE_MODAL: `${ACTION_PREFIX}TOGGLE_MODAL`,
SHOW_EXPORT_DROPDOWN: `${ACTION_PREFIX}SHOW_EXPORT_DROPDOWN`,
HIDE_EXPORT_DROPDOWN: `${ACTION_PREFIX}HIDE_EXPORT_DROPDOWN`,
TOGGLE_SIDE_PANEL_CLOSE_BUTTON: `${ACTION_PREFIX}TOGGLE_SIDE_PANEL_CLOSE_BUTTON`,
OPEN_DELETE_MODAL: `${ACTION_PREFIX}OPEN_DELETE_MODAL`,
TOGGLE_MAP_CONTROL: `${ACTION_PREFIX}TOGGLE_MAP_CONTROL`,
SET_MAP_CONTROL_VISIBILITY: `${ACTION_PREFIX}SET_MAP_CONTROL_VISIBILITY`,
Expand Down
20 changes: 20 additions & 0 deletions src/actions/src/ui-state-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,26 @@ export const hideExportDropdown: () => {
type: typeof ActionTypes.HIDE_EXPORT_DROPDOWN;
} = createAction(ActionTypes.HIDE_EXPORT_DROPDOWN);

/** TOGGLE_SIDE_PANEL_CLOSE_BUTTON*/
export type ToggleSidePanelCloseButtonUpdaterAction = {
payload: {
show: boolean;
};
};

/**
* Toggle side panel close button
* @memberof uiStateActions
* @param show - if side panel button visible
* @public
*/
export const toggleSidePanelCloseButton: (
show: boolean
) => Merge<
ToggleSidePanelCloseButtonUpdaterAction,
{type: typeof ActionTypes.TOGGLE_SIDE_PANEL_CLOSE_BUTTON}
> = createAction(ActionTypes.TOGGLE_SIDE_PANEL_CLOSE_BUTTON, show => ({payload: {show}}));

/** TOGGLE_MAP_CONTROL */
export type ToggleMapControlUpdaterAction = {
payload: {
Expand Down
8 changes: 7 additions & 1 deletion src/components/src/side-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,13 @@ export default function SidePanelFactory(
const PanelComponent = currentPanel?.component;

return (
<Sidebar width={width} isOpen={isOpen} minifiedWidth={0} onOpenOrClose={_onOpenOrClose}>
<Sidebar
width={width}
isOpen={isOpen}
shouldShowCollapseButton={uiState.isSidePanelCloseButtonVisible}
minifiedWidth={0}
onOpenOrClose={_onOpenOrClose}
>
<PanelHeader
appName={appName}
version={version}
Expand Down
10 changes: 7 additions & 3 deletions src/components/src/side-panel/side-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type SideBarProps = {
isOpen: boolean;
minifiedWidth: number;
onOpenOrClose: (arg: {isOpen: boolean}) => void;
shouldShowCollapseButton?: boolean | null;
};

const StyledSidePanelContainer = styled.div<{width: number}>`
Expand Down Expand Up @@ -108,15 +109,16 @@ function SidebarFactory(CollapseButton: ReturnType<typeof CollapseButtonFactory>
width: 300,
minifiedWidth: 0,
isOpen: true,
onOpenOrClose: function noop() {}
onOpenOrClose: function noop() {},
shouldShowCollapseButton: true
};

_onOpenOrClose = () => {
this.props.onOpenOrClose({isOpen: !this.props.isOpen});
};

render() {
const {isOpen, minifiedWidth, width} = this.props;
const {isOpen, minifiedWidth, width, shouldShowCollapseButton} = this.props;
const horizontalOffset = isOpen ? 0 : minifiedWidth - width;

return (
Expand All @@ -129,7 +131,9 @@ function SidebarFactory(CollapseButton: ReturnType<typeof CollapseButtonFactory>
{isOpen ? (
<SideBarInner className="side-bar__inner">{this.props.children}</SideBarInner>
) : null}
<CollapseButton isOpen={isOpen} onClick={this._onOpenOrClose} />
{shouldShowCollapseButton ? (
<CollapseButton isOpen={isOpen} onClick={this._onOpenOrClose} />
) : null}
</SideBarContainer>
</StyledSidePanelContainer>
);
Expand Down
17 changes: 16 additions & 1 deletion src/reducers/src/ui-state-updaters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export const DEFAULT_EXPORT_MAP: ExportMap = {
* @property notifications Default: `[]`
* @property notifications Default: `[]`
* @property loadFiles
* @property isSidePanelCloseButtonVisible Default: `true`
* @public
*/
export const INITIAL_UI_STATE: UiState = {
Expand All @@ -263,7 +264,8 @@ export const INITIAL_UI_STATE: UiState = {
// Locale of the UI
locale: LOCALE_CODES.en,
layerPanelListView: 'list',
filterPanelListView: 'list'
filterPanelListView: 'list',
isSidePanelCloseButtonVisible: true
};

/* Updaters */
Expand Down Expand Up @@ -348,6 +350,19 @@ export const hideExportDropdownUpdater = (state: UiState): UiState => ({
visibleDropdown: null
});

/**
* Toggle side panel close button on top left of the side panel
* @memberof uiStateUpdaters
* @public
*/
export const toggleSidePanelCloseButtonUpdater = (
state: UiState,
{payload: {show}}: UIStateActions.ToggleSidePanelCloseButtonUpdaterAction
): UiState => ({
...state,
isSidePanelCloseButtonVisible: show
});

/**
* Toggle active map control panel
* @memberof uiStateUpdaters
Expand Down
1 change: 1 addition & 0 deletions src/reducers/src/ui-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const actionHandler = {
[ActionTypes.TOGGLE_MODAL]: uiStateUpdaters.toggleModalUpdater,
[ActionTypes.SHOW_EXPORT_DROPDOWN]: uiStateUpdaters.showExportDropdownUpdater,
[ActionTypes.HIDE_EXPORT_DROPDOWN]: uiStateUpdaters.hideExportDropdownUpdater,
[ActionTypes.TOGGLE_SIDE_PANEL_CLOSE_BUTTON]: uiStateUpdaters.toggleSidePanelCloseButtonUpdater,
[ActionTypes.OPEN_DELETE_MODAL]: uiStateUpdaters.openDeleteModalUpdater,
[ActionTypes.TOGGLE_MAP_CONTROL]: uiStateUpdaters.toggleMapControlUpdater,
[ActionTypes.SET_MAP_CONTROL_VISIBILITY]: uiStateUpdaters.setMapControlVisibilityUpdater,
Expand Down
2 changes: 2 additions & 0 deletions src/types/reducers.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ export type UiState = {
layerPanelListView: PanelListView;
// view filters by list or dataset
filterPanelListView: PanelListView;
// side panel close button visibility
isSidePanelCloseButtonVisible: boolean | null;
};

/** Width of viewport */
Expand Down
32 changes: 32 additions & 0 deletions test/browser/components/side-panel/side-panel-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import sinon from 'sinon';
import {
SidePanelFactory,
SidebarFactory,
CollapseButtonFactory,
PanelHeaderFactory,
SaveExportDropdownFactory,
LayerManagerFactory,
Expand All @@ -43,6 +44,7 @@ import {IntlWrapper, mountWithTheme} from 'test/helpers/component-utils';
// components
const SidePanel = appInjector.get(SidePanelFactory);
const Sidebar = appInjector.get(SidebarFactory);
const SidebarCloseButton = appInjector.get(CollapseButtonFactory);
const PanelHeader = appInjector.get(PanelHeaderFactory);
const LayerManager = appInjector.get(LayerManagerFactory);
const FilterManager = appInjector.get(FilterManagerFactory);
Expand Down Expand Up @@ -91,6 +93,36 @@ test('Components -> SidePanel.mount -> no prop', t => {
t.ok(wrapper.find(PanelToggle).length === 1, 'should render PanelToggle');
t.ok(wrapper.find(Sidebar).length === 1, 'should render Sidebar');

// side bar close button
t.ok(wrapper.find(SidebarCloseButton).length === 1, 'should render SideBarCollapseButton');

t.end();
});

test('Components -> SidePanel.mount -> hide CollapseButton', t => {
// mount
let wrapper;

const uiState = {
...defaultProps.uiState,
isSidePanelCloseButtonVisible: false
};

t.doesNotThrow(() => {
wrapper = mountWithTheme(
<IntlWrapper>
<SidePanel {...defaultProps} uiState={uiState} />
</IntlWrapper>
);
}, 'SidePanel should not fail without props');

t.ok(wrapper.find(PanelHeader).length === 1, 'should render PanelHeader');
t.ok(wrapper.find(PanelToggle).length === 1, 'should render PanelToggle');
t.ok(wrapper.find(Sidebar).length === 1, 'should render Sidebar');

// side bar close button
t.ok(wrapper.find(SidebarCloseButton).length === 0, 'should not render SideBarCollapseButton');

t.end();
});

Expand Down
23 changes: 23 additions & 0 deletions test/node/reducers/ui-state-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import test from 'tape';
import {
toggleSidePanel,
toggleModal,
toggleSidePanelCloseButton,
openDeleteModal,
setExportImageSetting,
toggleMapControl,
Expand Down Expand Up @@ -117,6 +118,28 @@ test('#uiStateReducer -> TOGGLE_SIDE_PANEL', t => {
t.end();
});

test('#uiStateReducer -> TOGGLE_SIDE_PANEL_CLOSE_BUTTON', t => {
const newReducer = reducer(INITIAL_UI_STATE, toggleSidePanelCloseButton(false));

const expectedState = {
...INITIAL_UI_STATE,
isSidePanelCloseButtonVisible: false
};

t.deepEqual(newReducer, expectedState, 'should hide side panel close button');

const nextState2 = reducer(expectedState, toggleSidePanelCloseButton(true));

const expectedNextState2 = {
...expectedState,
isSidePanelCloseButtonVisible: true
};

t.deepEqual(nextState2, expectedNextState2, 'should show side panel close button');

t.end();
});

test('#uiStateReducer -> OPEN_DELETE_MODAL', t => {
const newReducer = reducer(INITIAL_UI_STATE, openDeleteModal('chai'));

Expand Down