Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

[Feat] Allow adding custom side panel tabs

Shan He182e3cf6f7f0
diff --git a/examples/replace-component/src/app.js b/examples/replace-component/src/app.js
index 48ce0c54d..d31d0cb24 100644
--- a/examples/replace-component/src/app.js
+++ b/examples/replace-component/src/app.js
@@ -33,12 +33,14 @@ import {
SidebarFactory,
PanelHeaderFactory,
PanelToggleFactory,
+ CustomPanelsFactory,
injectComponents
} from 'kepler.gl/components';
import CustomPanelHeaderFactory from './components/panel-header';
import CustomSidebarFactory from './components/side-bar';
import CustomPanelToggleFactory from './components/panel-toggle';
+import CustomSidePanelFactory from './components/custom-panel';
const StyledMapConfigDisplay = styled.div`
position: absolute;
@@ -58,7 +60,8 @@ const StyledMapConfigDisplay = styled.div`
const KeplerGl = injectComponents([
[SidebarFactory, CustomSidebarFactory],
[PanelHeaderFactory, CustomPanelHeaderFactory],
- [PanelToggleFactory, CustomPanelToggleFactory]
+ [PanelToggleFactory, CustomPanelToggleFactory],
+ [CustomPanelsFactory, CustomSidePanelFactory]
]);
class App extends Component {
diff --git a/examples/replace-component/src/components/custom-panel.js b/examples/replace-component/src/components/custom-panel.js
new file mode 100644
index 000000000..97ccb8b0e
--- /dev/null
+++ b/examples/replace-component/src/components/custom-panel.js
@@ -0,0 +1,56 @@
+// Copyright (c) 2020 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+import React from 'react';
+import {Icons} from 'kepler.gl/components';
+
+function CustomSidePanelsFactory() {
+ const CustomPanels = props => {
+ if (props.activeSidePanel === 'rocket') {
+ return <div className="rocket-panel">Rocket</div>;
+ } else if (props.activeSidePanel === 'chart') {
+ return <div className="rocket-panel">Charts?</div>;
+ }
+
+ return null;
+ };
+
+ CustomPanels.defaultProps = {
+ panels: [
+ {
+ id: 'rocket',
+ label: 'Rocket',
+ iconComponent: Icons.Rocket
+ },
+ {
+ id: 'chart',
+ label: 'Chart',
+ iconComponent: Icons.LineChart
+ }
+ ],
+ getProps: props => ({
+ layers: props.layers
+ })
+ };
+
+ return CustomPanels;
+}
+
+export default CustomSidePanelsFactory;
diff --git a/src/components/common/logo.js b/src/components/common/logo.js
index 04a6274fc..b39cb752f 100644
--- a/src/components/common/logo.js
+++ b/src/components/common/logo.js
@@ -66,7 +66,7 @@ const LogoSvg = () => (
</svg>
);
-const KeplerGlLogo = ({appName = KEPLER_GL_NAME, version = KEPLER_GL_VERSION}) => (
+const KeplerGlLogo = ({appName, version}) => (
<LogoWrapper className="side-panel-logo">
<LogoSvgWrapper>
<LogoSvg />
@@ -80,9 +80,16 @@ const KeplerGlLogo = ({appName = KEPLER_GL_NAME, version = KEPLER_GL_VERSION}) =
</LogoWrapper>
);
-KeplerGlLogo.defaultProps = {
+KeplerGlLogo.propTypes = {
appName: PropTypes.string,
- version: PropTypes.string
+ version: PropTypes.string,
+ appWebsite: PropTypes.string
+};
+
+KeplerGlLogo.defaultProps = {
+ appName: KEPLER_GL_NAME,
+ version: KEPLER_GL_VERSION,
+ appWebsite: KEPLER_GL_WEBSITE
};
export default KeplerGlLogo;
diff --git a/src/components/index.js b/src/components/index.js
index ffdf1051a..f443fb4e2 100644
--- a/src/components/index.js
+++ b/src/components/index.js
@@ -61,6 +61,7 @@ export {default as TooltipConfigFactory} from './side-panel/interaction-panel/to
export {default as MapManagerFactory} from './side-panel/map-manager';
export {default as LayerGroupSelectorFactory} from './side-panel/map-style-panel/map-layer-selector';
export {default as MapStyleSelectorFactory} from './side-panel/map-style-panel/map-style-selector';
+export {default as CustomPanelsFactory} from './side-panel/custom-panel';
// // map container factories
export {default as MapPopoverFactory} from './map/map-popover';
diff --git a/src/components/kepler-gl.js b/src/components/kepler-gl.js
index 4a2fac488..1ba4513df 100644
--- a/src/components/kepler-gl.js
+++ b/src/components/kepler-gl.js
@@ -208,6 +208,7 @@ function KeplerGlFactory(
id,
appName,
version,
+ appWebsite,
onSaveMap,
onViewStateChange,
width,
@@ -256,6 +257,7 @@ function KeplerGlFactory(
const sideFields = {
appName,
version,
+ appWebsite,
datasets,
filters,
layers,
@@ -265,7 +267,6 @@ function KeplerGlFactory(
mapStyle,
layerBlending,
onSaveMap,
- // onSaveToStorage,
uiState,
mapStyleActions,
visStateActions,
diff --git a/src/components/side-panel.js b/src/components/side-panel.js
index 4d434d18d..8d884866f 100644
--- a/src/components/side-panel.js
+++ b/src/components/side-panel.js
@@ -21,6 +21,7 @@
import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
+import get from 'lodash.get';
import SidebarFactory from './side-panel/side-bar';
import PanelHeaderFactory from './side-panel/panel-header';
@@ -29,6 +30,7 @@ import FilterManagerFactory from './side-panel/filter-manager';
import InteractionManagerFactory from './side-panel/interaction-manager';
import MapManagerFactory from './side-panel/map-manager';
import PanelToggleFactory from './side-panel/panel-toggle';
+import CustomPanelsFactory from './side-panel/custom-panel';
import {
ADD_DATA_ID,
@@ -39,7 +41,7 @@ import {
EXPORT_MAP_ID,
SAVE_MAP_ID,
SHARE_MAP_ID,
- PANELS
+ SIDEBAR_PANELS
} from 'constants/default-settings';
const SidePanelContent = styled.div`
@@ -66,7 +68,8 @@ SidePanelFactory.deps = [
LayerManagerFactory,
FilterManagerFactory,
InteractionManagerFactory,
- MapManagerFactory
+ MapManagerFactory,
+ CustomPanelsFactory
];
/**
@@ -81,9 +84,14 @@ export default function SidePanelFactory(
LayerManager,
FilterManager,
InteractionManager,
- MapManager
+ MapManager,
+ CustomPanels
) {
- return class SidePanel extends PureComponent {
+ const customPanels = get(CustomPanels, ['defaultProps', 'panels']) || [];
+ const getCustomPanelProps =
+ get(CustomPanels, ['defaultProps', 'getProps']) || (() => ({}));
+
+ class SidePanel extends PureComponent {
static propTypes = {
filters: PropTypes.arrayOf(PropTypes.any).isRequired,
interactionConfig: PropTypes.object.isRequired,
@@ -95,8 +103,19 @@ export default function SidePanelFactory(
datasets: PropTypes.object.isRequired,
visStateActions: PropTypes.object.isRequired,
mapStyleActions: PropTypes.object.isRequired,
- availableProviders: PropTypes.object
+ availableProviders: PropTypes.object,
+ panels: PropTypes.arrayOf(PropTypes.object)
+ };
+
+ static defaultProps = {
+ panels: SIDEBAR_PANELS,
+ uiState: {},
+ visStateActions: {},
+ mapStyleActions: {},
+ uiStateActions: {},
+ availableProviders: {}
};
+
/* component private functions */
_onOpenOrClose = () => {
this.props.uiStateActions.toggleSidePanel(
@@ -123,19 +142,25 @@ export default function SidePanelFactory(
this.props.uiStateActions.openDeleteModal(key);
};
- _onClickExportImage = () => this.props.uiStateActions.toggleModal(EXPORT_IMAGE_ID);
+ _onClickExportImage = () =>
+ this.props.uiStateActions.toggleModal(EXPORT_IMAGE_ID);
- _onClickExportData = () => this.props.uiStateActions.toggleModal(EXPORT_DATA_ID);
+ _onClickExportData = () =>
+ this.props.uiStateActions.toggleModal(EXPORT_DATA_ID);
- _onClickExportMap = () => this.props.uiStateActions.toggleModal(EXPORT_MAP_ID);
+ _onClickExportMap = () =>
+ this.props.uiStateActions.toggleModal(EXPORT_MAP_ID);
- _onClickSaveToStorage = () => this.props.uiStateActions.toggleModal(SAVE_MAP_ID);
+ _onClickSaveToStorage = () =>
+ this.props.uiStateActions.toggleModal(SAVE_MAP_ID);
- _onClickShareMap = () => this.props.uiStateActions.toggleModal(SHARE_MAP_ID);
+ _onClickShareMap = () =>
+ this.props.uiStateActions.toggleModal(SHARE_MAP_ID);
render() {
const {
appName,
+ appWebsite,
version,
datasets,
filters,
@@ -148,11 +173,12 @@ export default function SidePanelFactory(
visStateActions,
mapStyleActions,
uiStateActions,
- availableProviders = {}
+ availableProviders
} = this.props;
const {activeSidePanel} = uiState;
const isOpen = Boolean(activeSidePanel);
+ const panels = [...this.props.panels, ...customPanels];
const layerManagerActions = {
addLayer: visStateActions.addLayer,
@@ -207,6 +233,7 @@ export default function SidePanelFactory(
<PanelHeader
appName={appName}
version={version}
+ appWebsite={appWebsite}
visibleDropdown={uiState.visibleDropdown}
showExportDropdown={uiStateActions.showExportDropdown}
hideExportDropdown={uiStateActions.hideExportDropdown}
@@ -214,18 +241,24 @@ export default function SidePanelFactory(
onExportData={this._onClickExportData}
onExportMap={this._onClickExportMap}
onSaveMap={this.props.onSaveMap}
- onSaveToStorage={availableProviders.hasStorage ? this._onClickSaveToStorage : null}
- onShareMap={availableProviders.hasShare ? this._onClickShareMap : null}
+ onSaveToStorage={
+ availableProviders.hasStorage
+ ? this._onClickSaveToStorage
+ : null
+ }
+ onShareMap={
+ availableProviders.hasShare ? this._onClickShareMap : null
+ }
/>
<PanelToggle
- panels={PANELS}
+ panels={panels}
activePanel={activeSidePanel}
togglePanel={uiStateActions.toggleSidePanel}
/>
<SidePanelContent className="side-panel__content">
<div>
<PanelTitle className="side-panel__content__title">
- {(PANELS.find(({id}) => id === activeSidePanel) || {}).label}
+ {(panels.find(({id}) => id === activeSidePanel) || {}).label}
</PanelTitle>
{activeSidePanel === 'layer' && (
<LayerManager
@@ -259,6 +292,12 @@ export default function SidePanelFactory(
mapStyle={this.props.mapStyle}
/>
)}
+ {customPanels.length && customPanels.find(p => p.id === activeSidePanel) && (
+ <CustomPanels
+ {...getCustomPanelProps(this.props)}
+ activeSidePanel={activeSidePanel}
+ />
+ )}
</div>
</SidePanelContent>
</Sidebar>
@@ -266,4 +305,6 @@ export default function SidePanelFactory(
);
}
};
+
+ return SidePanel;
}
diff --git a/src/components/side-panel/custom-panel.js b/src/components/side-panel/custom-panel.js
new file mode 100644
index 000000000..5c22c3d54
--- /dev/null
+++ b/src/components/side-panel/custom-panel.js
@@ -0,0 +1,50 @@
+// Copyright (c) 2020 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+import React from 'react';
+
+// This is a dummy component that can be replaced to inject more side panel sub panels into the side bar
+function CustomPanelsFactory() {
+ const CustomPanels = props => {
+ return <div />;
+ };
+
+ CustomPanels.defaultProps = {
+ // provide a list of additional panels
+ panels: [
+ // {
+ // id: 'rocket',
+ // label: 'Rocket',
+ // iconComponent: Icons.Rocket
+ // },
+ // {
+ // id: 'chart',
+ // label: 'Chart',
+ // iconComponent: Icons.LineChart
+ // }
+ ],
+ // prop selector from side panel props
+ getProps: sidePanelProps => ({})
+ };
+
+ return CustomPanels;
+}
+
+export default CustomPanelsFactory;
diff --git a/src/components/side-panel/panel-header.js b/src/components/side-panel/panel-header.js
index 333df7ac2..bfa832d55 100644
--- a/src/components/side-panel/panel-header.js
+++ b/src/components/side-panel/panel-header.js
@@ -100,7 +100,6 @@ const StyledToolbar = styled(Toolbar)`
export const PanelAction = ({item, onClick}) => (
<StyledPanelAction
- className="side-panel__panel-header__action"
data-tip
data-for={`${item.id}-action`}
onClick={onClick}
diff --git a/src/constants/default-settings.js b/src/constants/default-settings.js
index 2a30007ce..5ebd09078 100644
--- a/src/constants/default-settings.js
+++ b/src/constants/default-settings.js
@@ -146,7 +146,7 @@ export const THEME = keyMirror({
dark: null
});
-export const PANELS = [
+export const SIDEBAR_PANELS = [
{
id: 'layer',
label: 'Layers',
@@ -169,6 +169,9 @@ export const PANELS = [
}
];
+// backward compatibility
+export const PANELS = SIDEBAR_PANELS;
+
// MAP STYLES
export const DEFAULT_LAYER_GROUPS = [
diff --git a/src/constants/index.js b/src/constants/index.js
index 8cffa1207..96980b4b1 100644
--- a/src/constants/index.js
+++ b/src/constants/index.js
@@ -53,6 +53,7 @@ export {
LAYER_TYPES,
MAX_DEFAULT_TOOLTIPS,
PANELS,
+ SIDEBAR_PANELS,
SCALE_TYPES,
THEME,
TRIP_ARC_FIELDS,
diff --git a/test/browser/components/side-panel/index.js b/test/browser/components/side-panel/index.js
index b8e278c73..62b65af6e 100644
--- a/test/browser/components/side-panel/index.js
+++ b/test/browser/components/side-panel/index.js
@@ -20,3 +20,4 @@
import './color-selector-test';
import './save-export-dropdown-test';
+import './side-panel-test';
diff --git a/test/browser/components/side-panel/side-panel-test.js b/test/browser/components/side-panel/side-panel-test.js
new file mode 100644
index 000000000..534d40269
--- /dev/null
+++ b/test/browser/components/side-panel/side-panel-test.js
@@ -0,0 +1,424 @@
+// Copyright (c) 2020 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+import React from 'react';
+import test from 'tape';
+import {mount} from 'enzyme';
+import sinon from 'sinon';
+import SidePanelFactory from 'components/side-panel';
+import SidebarFactory from 'components/side-panel/side-bar';
+import PanelHeaderFactory from 'components/side-panel/panel-header';
+import LayerManagerFactory from 'components/side-panel/layer-manager';
+import FilterManagerFactory from 'components/side-panel/filter-manager';
+import InteractionManagerFactory from 'components/side-panel/interaction-manager';
+import MapManagerFactory from 'components/side-panel/map-manager';
+import PanelToggleFactory from 'components/side-panel/panel-toggle';
+import CustomPanelsFactory from 'components/side-panel/custom-panel';
+import {SaveExportDropdownFactory} from 'components/side-panel/panel-header';
+import ToolbarItem from 'components/common/toolbar-item';
+
+import * as VisStateActions from 'actions/vis-state-actions';
+import * as MapStateActions from 'actions/map-state-actions';
+import * as MapStyleActions from 'actions/map-style-actions';
+import * as UIStateActions from 'actions/ui-state-actions';
+import * as ProviderActions from 'actions/provider-actions';
+
+import {appInjector} from 'components/container';
+import {mountWithTheme} from 'test/helpers/component-utils';
+
+// components
+const SidePanel = appInjector.get(SidePanelFactory);
+const Sidebar = appInjector.get(SidebarFactory);
+const PanelHeader = appInjector.get(PanelHeaderFactory);
+const LayerManager = appInjector.get(LayerManagerFactory);
+const FilterManager = appInjector.get(FilterManagerFactory);
+const InteractionManager = appInjector.get(InteractionManagerFactory);
+const MapManager = appInjector.get(MapManagerFactory);
+const PanelToggle = appInjector.get(PanelToggleFactory);
+const CustomPanels = appInjector.get(CustomPanelsFactory);
+const SaveExportDropdown = appInjector.get(SaveExportDropdownFactory);
+
+// mock state
+import {InitialState} from 'test/helpers/mock-state';
+
+// Constants
+import {
+ ADD_DATA_ID,
+ ADD_MAP_STYLE_ID,
+ DATA_TABLE_ID,
+ EXPORT_IMAGE_ID,
+ EXPORT_DATA_ID,
+ EXPORT_MAP_ID,
+ SAVE_MAP_ID,
+ SHARE_MAP_ID,
+ SIDEBAR_PANELS
+} from 'constants/default-settings';
+
+// default props from initial state
+const defaultProps = {
+ datasets: InitialState.visState.datasets,
+ filters: InitialState.visState.filters,
+ layerBlending: InitialState.visState.layerBlending,
+ layerClasses: InitialState.visState.layerClasses,
+ layerOrder: InitialState.visState.layerOrder,
+ interactionConfig: InitialState.visState.interactionConfig,
+ layers: InitialState.visState.layers,
+ mapStyle: InitialState.mapStyle,
+ uiState: InitialState.uiState,
+ width: 300,
+ uiStateActions: UIStateActions,
+ visStateActions: VisStateActions,
+ mapStyleActions: MapStyleActions,
+ availableProviders: {}
+};
+
+test('Components -> SidePanel.mount -> no prop', t => {
+ // mount
+ let wrapper;
+ t.doesNotThrow(() => {
+ wrapper = mountWithTheme(<SidePanel {...defaultProps} />);
+ }, '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');
+
+ t.end();
+});
+
+test('Components -> SidePanel -> toggle panel', t => {
+ const toggleSidePanel = sinon.spy();
+ const uiStateActions = {
+ ...UIStateActions,
+ toggleSidePanel
+ };
+
+ let wrapper;
+ // mount
+ t.doesNotThrow(() => {
+ wrapper = mountWithTheme(
+ <SidePanel {...defaultProps} uiStateActions={uiStateActions} />
+ );
+ }, 'SidePanel should not fail');
+
+ t.ok(wrapper.find(PanelToggle).length === 1, 'should render PanelToggle');
+
+ t.equal(
+ wrapper.find('.side-panel__tab').length,
+ 4,
+ 'should render 4 panel tabs'
+ );
+ const layerTab = wrapper.find('.side-panel__tab').at(0);
+
+ // click layer tab
+ layerTab.simulate('click');
+ t.ok(
+ toggleSidePanel.calledWith('layer'),
+ 'should call toggleSidePanel with layer'
+ );
+ t.end();
+});
+
+test('Components -> SidePanel -> render panel', t => {
+
+ let wrapper;
+ let uiState = {
+ ...defaultProps.uiState,
+ activeSidePanel: 'layer'
+ }
+ // mount LayerManager
+ t.doesNotThrow(() => {
+ wrapper = mountWithTheme(
+ <SidePanel {...defaultProps} uiState={uiState} />
+ );
+ }, 'SidePanel should not fail');
+
+ t.ok(wrapper.find(LayerManager).length === 1, 'should render LayerManager');
+
+ // mount FilterManager
+ uiState = {
+ ...defaultProps.uiState,
+ activeSidePanel: 'filter'
+ }
+ t.doesNotThrow(() => {
+ wrapper = mountWithTheme(
+ <SidePanel {...defaultProps} uiState={uiState} />
+ );
+ }, 'SidePanel should not fail');
+ t.ok(wrapper.find(FilterManager).length === 1, 'should render FilterManager');
+
+ // mount InteractionManager
+ uiState = {
+ ...defaultProps.uiState,
+ activeSidePanel: 'interaction'
+ }
+ t.doesNotThrow(() => {
+ wrapper = mountWithTheme(
+ <SidePanel {...defaultProps} uiState={uiState} />
+ );
+ }, 'SidePanel should not fail');
+ t.ok(wrapper.find(InteractionManager).length === 1, 'should render InteractionManager');
+
+ // mount MapManager
+ uiState = {
+ ...defaultProps.uiState,
+ activeSidePanel: 'map'
+ }
+ t.doesNotThrow(() => {
+ wrapper = mountWithTheme(
+ <SidePanel {...defaultProps} uiState={uiState} />
+ );
+ }, 'SidePanel should not fail');
+ t.ok(wrapper.find(MapManager).length === 1, 'should render MapManager');
+
+ t.end();
+});
+
+test('Components -> SidePanel -> render custom panel', t => {
+ const RocketIcon = () => <div id="rocket-icon"/>;
+ const ChartIcon = () => <div id="chart-icon"/>
+
+ const MyPanels = props => {
+ if (props.activeSidePanel === 'rocket') {
+ return <div className="rocket-panel">Rocket</div>;
+ } else if (props.activeSidePanel === 'chart') {
+ return <div className="chart-panel">Charts?</div>;
+ }
+
+ return null;
+ };
+
+ MyPanels.defaultProps = {
+ panels: [
+ {
+ id: 'rocket',
+ label: 'Rocket',
+ iconComponent: RocketIcon
+ },
+ {
+ id: 'chart',
+ label: 'Chart',
+ iconComponent: ChartIcon
+ }
+ ],
+ getProps: props => ({
+ layers: props.layers
+ })
+ };
+
+ function CustomSidePanelsFactory() {
+ return MyPanels;
+ }
+
+ let wrapper;
+
+ const CustomSidePanel = appInjector
+ .provide(CustomPanelsFactory, CustomSidePanelsFactory)
+ .get(SidePanelFactory);
+
+ // mount CustomSidePanel
+ t.doesNotThrow(() => {
+ wrapper = mountWithTheme(
+ <CustomSidePanel {...defaultProps} />
+ );
+ }, 'SidePanel should not fail');
+
+ t.equal(
+ wrapper.find('.side-panel__tab').length,
+ 6,
+ 'should render 6 panel tabs'
+ );
+
+ t.equal(wrapper.find(RocketIcon).length, 1, 'should render RocketIcon');
+ t.equal(wrapper.find(ChartIcon).length, 1, 'should render RocketIcon');
+
+ // mount CustomSidePanel with 1 of the custom panel
+ const uiState = {...defaultProps.uiState, activeSidePanel: 'rocket'};
+ t.doesNotThrow(() => {
+ wrapper = mountWithTheme(
+ <CustomSidePanel {...defaultProps} uiState={uiState}/>
+ );
+ }, 'SidePanel should not fail when mount with custom side panel activated');
+ t.equal(
+ wrapper.find(MyPanels).length,
+ 1,
+ 'should render MyPanels'
+ );
+ t.end();
+});
+
+test('Components -> SidePanel -> PanelHeader', t => {
+ const showExportDropdown = sinon.spy();
+ const uiStateActions = {
+ ...UIStateActions,
+ showExportDropdown
+ };
+
+ let wrapper;
+ // mount
+ t.doesNotThrow(() => {
+ wrapper = mountWithTheme(
+ <SidePanel {...defaultProps} uiStateActions={uiStateActions} />
+ );
+ }, 'SidePanel should not fail');
+
+ t.ok(wrapper.find(PanelHeader).length === 1, 'should render PanelHeader');
+
+ const header = wrapper.find(PanelHeader);
+
+ // action item
+ t.equal(
+ header.find('.side-panel__panel-header__action').length,
+ 1,
+ 'should render 1 header action item'
+ );
+
+ // Share
+ t.equal(
+ header
+ .find('.side-panel__panel-header__action')
+ .at(0)
+ .find('p')
+ .text(),
+ 'Share',
+ 'should only render Save action'
+ );
+
+ header
+ .find('.side-panel__panel-header__action')
+ .at(0)
+ .simulate('click');
+
+ t.ok(
+ showExportDropdown.calledWith('save'),
+ 'should call toggleSidePanel with share'
+ );
+
+ // mound with exportDropdown
+ const uiState = {
+ ...defaultProps.uiState,
+ visibleDropdown: 'save'
+ };
+ t.doesNotThrow(() => {
+ wrapper = mountWithTheme(
+ <SidePanel
+ {...defaultProps}
+ uiState={uiState}
+ uiStateActions={uiStateActions}
+ />
+ );
+ }, 'SidePanel should not fail');
+
+ t.end();
+});
+
+test('Components -> SidePanel -> PanelHeader -> ExportDropDown', t => {
+ const toggleModal = sinon.spy();
+ const uiStateActions = {
+ ...UIStateActions,
+ toggleModal
+ };
+
+ // mound with exportDropdown
+ const uiState = {
+ ...defaultProps.uiState,
+ visibleDropdown: 'save'
+ };
+
+ let wrapper;
+ // mount
+ t.doesNotThrow(() => {
+ wrapper = mountWithTheme(
+ <SidePanel
+ {...defaultProps}
+ uiState={uiState}
+ uiStateActions={uiStateActions}
+ />
+ );
+ }, 'SidePanel should not fail');
+
+ t.ok(
+ wrapper.find(SaveExportDropdown).length === 1,
+ 'should render SaveExportDropdown'
+ );
+ t.equal(wrapper.find(ToolbarItem).length, 3, 'should render 3 ToolbarItem');
+
+ // export image
+ t.equal(
+ wrapper
+ .find(ToolbarItem)
+ .at(0)
+ .find('.toolbar-item__title')
+ .text(),
+ 'Export Image',
+ 'Should render Export Image'
+ );
+ wrapper
+ .find(ToolbarItem)
+ .at(0)
+ .find('.toolbar-item')
+ .simulate('click');
+ t.ok(
+ toggleModal.calledWith(EXPORT_IMAGE_ID),
+ 'Should call toggleModal with EXPORT_IMAGE_ID'
+ );
+
+ // export data
+ t.equal(
+ wrapper
+ .find(ToolbarItem)
+ .at(1)
+ .find('.toolbar-item__title')
+ .text(),
+ 'Export Data',
+ 'Should render Export Data'
+ );
+ wrapper
+ .find(ToolbarItem)
+ .at(1)
+ .find('.toolbar-item')
+ .simulate('click');
+ t.ok(
+ toggleModal.calledWith(EXPORT_DATA_ID),
+ 'Should call toggleModal with EXPORT_DATA_ID'
+ );
+
+ // export map
+ t.equal(
+ wrapper
+ .find(ToolbarItem)
+ .at(2)
+ .find('.toolbar-item__title')
+ .text(),
+ 'Export Map',
+ 'Should render Export Map'
+ );
+ wrapper
+ .find(ToolbarItem)
+ .at(2)
+ .find('.toolbar-item')
+ .simulate('click');
+ t.ok(
+ toggleModal.calledWith(EXPORT_MAP_ID),
+ 'Should call toggleModal with EXPORT_MAP_ID'
+ );
+
+ t.end();
+});