forked from GeoNode/geonode-mapstore-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add edit button to list of styles (GeoNode#672)
- Loading branch information
stefano bovio
authored
Dec 16, 2021
1 parent
606fedf
commit 665ca6e
Showing
7 changed files
with
150 additions
and
40 deletions.
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
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
94 changes: 94 additions & 0 deletions
94
geonode_mapstore_client/client/js/plugins/layersettings/GeoNodeStyleSelector.jsx
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,94 @@ | ||
/* | ||
* Copyright 2021, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { FormGroup, ControlLabel } from 'react-bootstrap'; | ||
import Message from '@mapstore/framework/components/I18N/Message'; | ||
import Select from 'react-select'; | ||
|
||
import { cleanStyles } from '@js/utils/ResourceUtils'; | ||
|
||
function getStyleOptions(layer) { | ||
const mapLayerStyles = (layer?.extendedParams?.mapLayer?.extra_params?.styles || []) | ||
.map((style) => ({ ...style, canEdit: true })); | ||
const datasetStyles = layer?.extendedParams?.mapLayer?.dataset?.styles || []; | ||
const defaultStyle = layer?.extendedParams?.mapLayer?.dataset?.default_style; | ||
const availableStyles = layer?.availableStyles || []; | ||
return cleanStyles([ | ||
...(defaultStyle ? [defaultStyle] : []), | ||
...datasetStyles, | ||
...mapLayerStyles, | ||
...availableStyles | ||
]).map(({ name, title, canEdit }) => ({ | ||
value: name, | ||
label: title, | ||
canEdit | ||
})); | ||
} | ||
|
||
function OptionLabel({ | ||
canEdit, | ||
label, | ||
style, | ||
value, | ||
buttons = [] | ||
}) { | ||
return ( | ||
<div style={{ display: 'flex', width: '100%', alignItems: 'center', ...style }}> | ||
<div style={{ overflow: 'hidden', textOverflow: 'ellipsis' }}>{label}</div> | ||
{buttons.map(({ Component, name }) => | ||
<Component | ||
key={name} | ||
status="LAYER" | ||
btnProps={{ | ||
variant: 'default', | ||
className: '', | ||
size: '' | ||
}} | ||
hide={!canEdit} | ||
selectedStyle={value} | ||
/> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
function GeoNodeStyleSelector({ | ||
node, | ||
onChange, | ||
buttons | ||
}) { | ||
|
||
const options = getStyleOptions(node); | ||
const currentStyle = options.find(({ value }) => value === node.style) || { }; | ||
|
||
if (!node?.extendedParams?.mapLayer) { | ||
return null; | ||
} | ||
|
||
return ( | ||
|
||
<FormGroup> | ||
<ControlLabel><Message msgId="gnviewer.style" /></ControlLabel> | ||
<Select | ||
key="style-selector" | ||
clearable={false} | ||
options={options.map(({ value, label, canEdit }) => ({ | ||
value, | ||
label: <OptionLabel value={value} label={label} canEdit={canEdit} buttons={buttons}/> | ||
}))} | ||
value={{ | ||
value: node.style, | ||
label: <OptionLabel {...currentStyle} style={{ width: 'calc(100% - 16px)' }} buttons={buttons}/> | ||
}} | ||
onChange={({ value }) => onChange({ style: value })}/> | ||
</FormGroup> | ||
); | ||
} | ||
|
||
export default GeoNodeStyleSelector; |
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
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