Skip to content

Commit

Permalink
[Chore] SidePanel panels are now passed through only through props or…
Browse files Browse the repository at this point in the history
… default ones (#1339)

* SidePanel panels are now passed through only through props or default props. 
* Removed CustomPanels default panels reference from SidePanel

Signed-off-by: Giuseppe Macri <macri.giuseppe@gmail.com>
  • Loading branch information
heshan0131 committed Dec 3, 2020
1 parent f802f39 commit 5642ca8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
15 changes: 6 additions & 9 deletions src/components/side-panel.js
Expand Up @@ -96,7 +96,6 @@ export default function SidePanelFactory(
MapManager,
CustomPanels
) {
const customPanels = get(CustomPanels, ['defaultProps', 'panels']) || [];
const getCustomPanelProps = get(CustomPanels, ['defaultProps', 'getProps']) || (() => ({}));

class SidePanel extends PureComponent {
Expand Down Expand Up @@ -188,12 +187,12 @@ export default function SidePanelFactory(
visStateActions,
mapStyleActions,
uiStateActions,
availableProviders
availableProviders,
panels
} = this.props;

const {activeSidePanel} = uiState;
const isOpen = Boolean(activeSidePanel);
const panels = [...this.props.panels, ...customPanels];

const layerManagerActions = {
addLayer: visStateActions.addLayer,
Expand Down Expand Up @@ -304,12 +303,10 @@ export default function SidePanelFactory(
{activeSidePanel === 'map' && (
<MapManager {...mapManagerActions} mapStyle={this.props.mapStyle} />
)}
{(customPanels || []).find(p => p.id === activeSidePanel) ? (
<CustomPanels
{...getCustomPanelProps(this.props)}
activeSidePanel={activeSidePanel}
/>
) : null}
<CustomPanels
{...getCustomPanelProps(this.props)}
activeSidePanel={activeSidePanel}
/>
</div>
</SidePanelContent>
</Sidebar>
Expand Down
38 changes: 25 additions & 13 deletions test/browser/components/side-panel/side-panel-test.js
Expand Up @@ -198,18 +198,6 @@ test('Components -> SidePanel -> render custom panel', t => {
};

MyPanels.defaultProps = {
panels: [
{
id: 'rocket',
label: 'Rocket',
iconComponent: RocketIcon
},
{
id: 'chart',
label: 'Chart',
iconComponent: ChartIcon
}
],
getProps: props => ({
layers: props.layers
})
Expand All @@ -219,9 +207,33 @@ test('Components -> SidePanel -> render custom panel', t => {
return MyPanels;
}

function CustomSidePanelFactory(...deps) {
const CustomSidePanel = SidePanelFactory(...deps);
CustomSidePanel.defaultProps = {
...CustomSidePanel.defaultProps,
panels: [
...CustomSidePanel.defaultProps.panels,
{
id: 'rocket',
label: 'Rocket',
iconComponent: RocketIcon
},
{
id: 'chart',
label: 'Chart',
iconComponent: ChartIcon
}
]
};
return CustomSidePanel;
}

CustomSidePanelFactory.deps = SidePanelFactory.deps;

let wrapper;

const CustomSidePanel = appInjector
.provide(SidePanelFactory, CustomSidePanelFactory)
.provide(CustomPanelsFactory, CustomSidePanelsFactory)
.get(SidePanelFactory);

Expand All @@ -239,7 +251,7 @@ test('Components -> SidePanel -> render custom panel', t => {
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
// // mount CustomSidePanel with 1 of the custom panel
const uiState = {...defaultProps.uiState, activeSidePanel: 'rocket'};
t.doesNotThrow(() => {
wrapper = mountWithTheme(
Expand Down

0 comments on commit 5642ca8

Please sign in to comment.