-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[Chore] Refactored map control and decoupled action components #1552
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -283,4 +283,4 @@ | |
"volta": { | ||
"node": "12.19.0" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react'; | ||
import {Layer} from 'layers'; | ||
import {MapControls} from 'reducers/ui-state-updaters'; | ||
|
||
export type LayerSelectorPanelProps = { | ||
onMapToggleLayer: (layerId: string) => void; | ||
onToggleMapControl: (control: string) => void; | ||
layers: ReadonlyArray<Layer>; | ||
layersToRender: {[key: string]: boolean}; | ||
isSplit: boolean; | ||
mapControls: MapControls; | ||
readOnly: boolean; | ||
}; | ||
|
||
export type LayerSelectorPanelComponent = React.FunctionComponent<LayerSelectorPanelProps>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import React, {useCallback, useMemo} from 'react'; | ||
import {MapControlButton} from 'components/common/styled-components'; | ||
import {Layers} from '../common/icons'; | ||
import MapLayerSelector from '../common/map-layer-selector'; | ||
import MapControlTooltipFactory from './map-control-tooltip'; | ||
import MapControlPanelFactory from './map-control-panel'; | ||
|
||
LayerSelectorPanelFactory.deps = [MapControlTooltipFactory, MapControlPanelFactory]; | ||
|
||
function LayerSelectorPanelFactory(MapControlTooltip, MapControlPanel) { | ||
/** @type {import('./layer-selector-panel').LayerSelectorPanelComponent} */ | ||
const LayerSelectorPanel = ({ | ||
onMapToggleLayer, | ||
onToggleMapControl, | ||
layers, | ||
layersToRender, | ||
isSplit, | ||
mapControls, | ||
readOnly | ||
}) => { | ||
const visibleLayers = mapControls?.visibleLayers || {}; | ||
const {active: isActive, show, disableClose} = visibleLayers; | ||
|
||
const legendLayers = useMemo( | ||
() => | ||
layers | ||
.filter(({config}) => config.isVisible) | ||
.map(({id, config}) => ({ | ||
id, | ||
name: config.label, | ||
// layer | ||
isVisible: layersToRender[id] | ||
})), | ||
[layers, layersToRender] | ||
); | ||
|
||
const isVisible = useMemo(() => isSplit && show && readOnly !== true, [ | ||
isSplit, | ||
show, | ||
readOnly | ||
]); | ||
|
||
const onToggleMenuPanel = useCallback( | ||
event => { | ||
event.preventDefault(); | ||
onToggleMapControl('visibleLayers'); | ||
}, | ||
[onToggleMapControl] | ||
); | ||
|
||
return isVisible ? ( | ||
(!isActive ? ( | ||
<MapControlButton | ||
key={1} | ||
onClick={onToggleMenuPanel} | ||
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={onToggleMenuPanel} | ||
disableClose={disableClose} | ||
> | ||
<MapLayerSelector layers={legendLayers} onMapToggleLayer={onMapToggleLayer} /> | ||
</MapControlPanel> | ||
)) | ||
) : null; | ||
}; | ||
|
||
LayerSelectorPanel.displayName = 'LayerSelectorPanel'; | ||
|
||
return React.memo(LayerSelectorPanel); | ||
} | ||
|
||
export default LayerSelectorPanelFactory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react'; | ||
import {MapControls} from '../../reducers'; | ||
|
||
export type LocalePanelProps = { | ||
availableLocales: ReadnlyArray<string>; | ||
onSetLocale: (locale: string) => void; | ||
locale: string; | ||
onToggleMenuPanel: () => void; | ||
mapControls: MapControls; | ||
}; | ||
|
||
export type LocalePanelComponent = React.FunctionComponent<LocalePanelProps>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React, {useCallback} from 'react'; | ||
import ToolbarItem from 'components/common/toolbar-item'; | ||
import {MapControlButton} from 'components/common/styled-components'; | ||
import MapControlTooltipFactory from './map-control-tooltip'; | ||
import MapControlPanelFactory from './map-control-panel'; | ||
import MapControlToolbarFactory from './map-control-toolbar'; | ||
|
||
LocalePanelFactory.deps = [ | ||
MapControlTooltipFactory, | ||
MapControlPanelFactory, | ||
MapControlToolbarFactory | ||
]; | ||
|
||
function LocalePanelFactory(MapControlTooltip, MapControlPanel, MapControlToolbar) { | ||
/** @type {import('./locale-panel').LocalePanelComponent} */ | ||
const LocalePanel = React.memo( | ||
({availableLocales, onToggleMenuPanel, onSetLocale, locale: currentLocal, mapControls}) => { | ||
const {active: isActive, disableClose} = mapControls.mapLocale || {}; | ||
|
||
const onClickItem = useCallback( | ||
locale => { | ||
onSetLocale(locale); | ||
}, | ||
[onSetLocale] | ||
); | ||
|
||
const onClickButton = useCallback( | ||
e => { | ||
e.preventDefault(); | ||
onToggleMenuPanel(); | ||
}, | ||
[onToggleMenuPanel] | ||
); | ||
const getLabel = useCallback(locale => `toolbar.${locale}`, []); | ||
|
||
if (!mapControls.mapLocale) { | ||
return null; | ||
} | ||
return ( | ||
<div style={{position: 'relative'}}> | ||
{isActive ? ( | ||
<MapControlToolbar show={isActive}> | ||
{availableLocales.map(locale => ( | ||
<ToolbarItem | ||
key={locale} | ||
onClick={() => onClickItem(locale)} | ||
label={getLabel(locale)} | ||
active={currentLocal === locale} | ||
/> | ||
))} | ||
</MapControlToolbar> | ||
) : null} | ||
<MapControlButton | ||
onClick={onClickButton} | ||
active={isActive} | ||
data-tip | ||
data-for="locale" | ||
disableClose={disableClose} | ||
> | ||
{currentLocal.toUpperCase()} | ||
<MapControlTooltip id="locale" message="tooltip.selectLocale" /> | ||
</MapControlButton> | ||
</div> | ||
); | ||
} | ||
); | ||
|
||
LocalePanel.displayName = 'LocalePanel'; | ||
|
||
return LocalePanel; | ||
} | ||
|
||
export default LocalePanelFactory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react'; | ||
|
||
export type MapControlPanelProps = { | ||
children: Element; | ||
header?: string; | ||
scale?: number; | ||
onClick: () => void; | ||
isExport?: boolean; | ||
logoComponent?: Element; | ||
}; | ||
|
||
export type MapControlPanelComponent = React.FunctionComponent<MapControlPanelProps>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import {FormattedMessage} from 'localization'; | ||
import {IconRoundSmall} from 'components/common/styled-components'; | ||
import {Close} from 'components/common/icons'; | ||
|
||
const StyledMapControlPanel = styled.div` | ||
background-color: ${props => props.theme.mapPanelBackgroundColor}; | ||
flex-grow: 1; | ||
z-index: 1; | ||
p { | ||
margin-bottom: 0; | ||
} | ||
`; | ||
|
||
const StyledMapControlPanelContent = styled.div.attrs({ | ||
className: 'map-control__panel-content' | ||
})` | ||
${props => props.theme.dropdownScrollBar}; | ||
max-height: 500px; | ||
min-height: 100px; | ||
min-width: ${props => props.theme.mapControl.width}px; | ||
overflow: auto; | ||
`; | ||
|
||
const StyledMapControlPanelHeader = styled.div.attrs({ | ||
className: 'map-control__panel-header' | ||
})` | ||
display: flex; | ||
justify-content: space-between; | ||
background-color: ${props => props.theme.mapPanelHeaderBackgroundColor}; | ||
height: 32px; | ||
padding: 6px 12px; | ||
font-size: 11px; | ||
color: ${props => props.theme.titleTextColor}; | ||
position: relative; | ||
|
||
button { | ||
width: 18px; | ||
height: 18px; | ||
} | ||
`; | ||
|
||
function MapControlPanelFactory() { | ||
/** @type {import('./map-control-panel').MapControlPanelComponent} */ | ||
const MapControlPanel = React.memo( | ||
({children, header, onClick, scale = 1, isExport, logoComponent}) => ( | ||
<StyledMapControlPanel | ||
style={{ | ||
transform: `scale(${scale})`, | ||
marginBottom: '8px' | ||
}} | ||
> | ||
<StyledMapControlPanelHeader> | ||
{isExport && logoComponent ? ( | ||
logoComponent | ||
) : header ? ( | ||
<span style={{verticalAlign: 'middle'}}> | ||
<FormattedMessage id={header} /> | ||
</span> | ||
) : null} | ||
{isExport ? null : ( | ||
<IconRoundSmall className="close-map-control-item" onClick={onClick}> | ||
<Close height="16px" /> | ||
</IconRoundSmall> | ||
)} | ||
</StyledMapControlPanelHeader> | ||
<StyledMapControlPanelContent>{children}</StyledMapControlPanelContent> | ||
</StyledMapControlPanel> | ||
) | ||
); | ||
|
||
MapControlPanel.displayName = 'MapControlPanel'; | ||
|
||
return MapControlPanel; | ||
} | ||
|
||
export default MapControlPanelFactory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import styled from 'styled-components'; | ||
import VerticalToolbar from '../common/vertical-toolbar'; | ||
|
||
function MapControlToolbar() { | ||
const StyledToolbar = styled(VerticalToolbar)` | ||
position: absolute; | ||
right: 32px; | ||
`; | ||
|
||
return StyledToolbar; | ||
} | ||
|
||
export default MapControlToolbar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import React from 'react'; | ||
|
||
export type MapControlTooltipProps = { | ||
id: string; | ||
message: string; | ||
}; | ||
|
||
export type MapControlTooltipComponent = React.FunctionComponent<MapControlTooltipProps>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react'; | ||
import {Tooltip} from '..'; | ||
import {FormattedMessage} from 'localization'; | ||
|
||
function MapControlTooltipFactory() { | ||
/** @type {import('./map-control-tooltip').MapControlTooltipComponent} */ | ||
const MapControlTooltip = React.memo(({id, message}) => ( | ||
<Tooltip id={id} place="left" effect="solid"> | ||
<span> | ||
<FormattedMessage id={message} /> | ||
</span> | ||
</Tooltip> | ||
)); | ||
|
||
MapControlTooltip.displayName = 'MapControlTooltip'; | ||
|
||
return MapControlTooltip; | ||
} | ||
|
||
export default MapControlTooltipFactory; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: if you use
React.FunctionComponent
orReact.Component
you don't need to define children as part of its props