Skip to content

Commit

Permalink
[Enhancement] add disableClose to map control (#1529)
Browse files Browse the repository at this point in the history
Signed-off-by: Shan He <heshan0131@gmail.com>
  • Loading branch information
heshan0131 committed Jul 18, 2021
1 parent c6e5b8a commit 01e9396
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 27 deletions.
62 changes: 37 additions & 25 deletions src/components/map/map-control.js
Expand Up @@ -125,29 +125,34 @@ const MapLegendTooltip = ({id, message}) => (
);

/** @type {import('./map-control').LayerSelectorPanelComponent} */
const LayerSelectorPanel = React.memo(({items, onMapToggleLayer, isActive, toggleMenuPanel}) =>
!isActive ? (
(<MapControlButton
key={1}
onClick={e => {
e.preventDefault();
toggleMenuPanel();
}}
className="map-control-button toggle-layer"
data-tip
data-for="toggle-layer"
>
<Layers height="22px" />
<MapControlTooltip
id="toggle-layer"
message={isActive ? 'tooltip.hideLayerPanel' : 'tooltip.showLayerPanel'}
/>
</MapControlButton>)
) : (
(<MapControlPanel header="header.visibleLayers" onClick={toggleMenuPanel}>
<MapLayerSelector layers={items} onMapToggleLayer={onMapToggleLayer} />
</MapControlPanel>)
)
const LayerSelectorPanel = React.memo(
({items, onMapToggleLayer, isActive, toggleMenuPanel, disableClose}) =>
!isActive ? (
(<MapControlButton
key={1}
onClick={e => {
e.preventDefault();
toggleMenuPanel();
}}
className="map-control-button toggle-layer"
data-tip
data-for="toggle-layer"
>
<Layers height="22px" />
<MapControlTooltip
id="toggle-layer"
message={isActive ? 'tooltip.hideLayerPanel' : 'tooltip.showLayerPanel'}
/>
</MapControlButton>)
) : (
(<MapControlPanel
header="header.visibleLayers"
onClick={toggleMenuPanel}
disableClose={disableClose}
>
<MapLayerSelector layers={items} onMapToggleLayer={onMapToggleLayer} />
</MapControlPanel>)
)
);

LayerSelectorPanel.displayName = 'LayerSelectorPanel';
Expand Down Expand Up @@ -372,7 +377,7 @@ export function MapDrawPanelFactory() {

/** @type {import('./map-control').LocalePanelComponent} */
const LocalePanel = React.memo(
({availableLocales, isActive, onToggleMenuPanel, onSetLocale, activeLocale}) => {
({availableLocales, isActive, onToggleMenuPanel, onSetLocale, activeLocale, disableClose}) => {
const onClickItem = useCallback(
locale => {
onSetLocale(locale);
Expand Down Expand Up @@ -403,7 +408,13 @@ const LocalePanel = React.memo(
))}
</StyledToolbar>
) : null}
<MapControlButton onClick={onClickButton} active={isActive} data-tip data-for="locale">
<MapControlButton
onClick={onClickButton}
active={isActive}
data-tip
data-for="locale"
disableClose={disableClose}
>
{activeLocale.toUpperCase()}
<MapControlTooltip id="locale" message="tooltip.selectLocale" />
</MapControlButton>
Expand Down Expand Up @@ -522,6 +533,7 @@ function MapControlFactory(MapDrawPanel, Toggle3dButton, SplitMapButton, MapLege
onMapToggleLayer={onMapToggleLayer}
isActive={visibleLayers.active}
toggleMenuPanel={() => onToggleMapControl('visibleLayers')}
disableClose={visibleLayers.disableClose}
/>
</ActionPanel>
) : null}
Expand Down
3 changes: 2 additions & 1 deletion src/reducers/ui-state-updaters.d.ts
Expand Up @@ -44,7 +44,8 @@ export type ExportMap = {
export type MapControl = {
show: boolean;
active: boolean;
activeMapIndex: number;
disableClose?: boolean;
activeMapIndex?: number;
};
export type MapControls = {
visibleLayers: MapControl;
Expand Down
1 change: 1 addition & 0 deletions src/reducers/ui-state-updaters.js
Expand Up @@ -81,6 +81,7 @@ const uiStateUpdaters = null;
const DEFAULT_MAP_CONTROLS_FEATURES = {
show: true,
active: false,
disableClose: false,
// defines which map index users are interacting with (through map controls)
activeMapIndex: 0
};
Expand Down
2 changes: 1 addition & 1 deletion test/node/reducers/ui-state-test.js
Expand Up @@ -169,7 +169,7 @@ test('#uiStateReducer -> TOGGLE_MAP_CONTROL', t => {
mapControls: {
...INITIAL_UI_STATE.mapControls,
mapLegend: {
show: INITIAL_UI_STATE.mapControls.mapLegend.show,
...INITIAL_UI_STATE.mapControls.mapLegend,
active: !INITIAL_UI_STATE.mapControls.mapLegend.active,
activeMapIndex: 0
}
Expand Down

0 comments on commit 01e9396

Please sign in to comment.