Skip to content

Commit

Permalink
fix map style creation workflow (#688)
Browse files Browse the repository at this point in the history
  • Loading branch information
allyoucanmap authored Dec 21, 2021
1 parent 9645f8b commit 88ddede
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 26 deletions.
42 changes: 21 additions & 21 deletions geonode_mapstore_client/client/js/epics/visualstyleeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
} from '@js/actions/visualstyleeditor';
import { saveDirectContent } from '@js/actions/gnsave';
import tinycolor from 'tinycolor2';
import { isNewResource } from '@js/selectors/resource';
import { parseStyleName, parseMetadata } from '@js/utils/ResourceUtils';

function getBaseCSSStyle({ type, title }) {
Expand Down Expand Up @@ -119,26 +118,27 @@ export const gnRequestDatasetAvailableStyles = (action$, store) =>
.switchMap((action) => {
const state = store.getState();
const styleService = action?.options?.styleService || styleServiceSelector(state);
return Observable.defer(() => getGeoNodeStyles({ layer: action.layer, styleService }))
.switchMap(([styles, update]) => {
const style = action?.options?.style || styles?.[0]?.name;
return Observable.concat(
Observable.of(setControlProperty('visualStyleEditor', 'enabled', true)),
Observable.defer(() => StylesAPI.getStylesInfo({
baseUrl: styleService?.baseUrl,
styles
}))
.switchMap((availableStyles) => {
return Observable.of(
updateNode(action.layer.id, 'layer', { availableStyles }),
updateSettingsParams({ style }, true),
updateAdditionalLayer(action.layer.id, STYLE_OWNER_NAME, 'override', {}),
updateStatus('edit'),
...(update && !isNewResource(state) ? [saveDirectContent()] : [])
);
})
);
});
return Observable.concat(
Observable.of(setControlProperty('visualStyleEditor', 'enabled', true)),
Observable.defer(() => getGeoNodeStyles({ layer: action.layer, styleService }))
.switchMap(([styles]) => {
const style = action?.options?.style || styles?.[0]?.name;
return Observable.concat(
Observable.defer(() => StylesAPI.getStylesInfo({
baseUrl: styleService?.baseUrl,
styles
}))
.switchMap((availableStyles) => {
return Observable.of(
updateNode(action.layer.id, 'layer', { availableStyles }),
updateSettingsParams({ style }, true),
updateAdditionalLayer(action.layer.id, STYLE_OWNER_NAME, 'override', {}),
updateStatus('edit')
);
})
);
})
);
});

export const gnCreateStyle = (action$, store) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function TemplateSelector({

const isMounted = useRef();
const [templates, setTemplates] = useState([]);
const [selectedTemplate, setSelectedTemplate] = useState();

useEffect(() => {
isMounted.current = true;
Expand All @@ -55,6 +56,7 @@ function TemplateSelector({
if (isOpen) {
onStoreTmpCode(code);
} else {
setSelectedTemplate(undefined);
if (tmpCode) {
onSelect(tmpCode);
}
Expand All @@ -78,7 +80,8 @@ function TemplateSelector({
onSelect(styleTemplate);
}

function replaceTemplateMetadata(templateCode) {
function replaceTemplateMetadata({ code: templateCode }, idx) {
setSelectedTemplate(idx);
const styleTitle = selectedStyle?.metadata?.title || selectedStyle?.label || selectedStyle?.title || selectedStyle?.name || '';
getStyleParser(format)
.writeStyle({
Expand Down Expand Up @@ -107,8 +110,8 @@ function TemplateSelector({
return (
<li
key={idx}
className="gn-visual-style-editor-template"
onClick={() => replaceTemplateMetadata(styleTemplate.code)}
className={`gn-visual-style-editor-template${selectedTemplate === idx ? ' selected' : ''}`}
onClick={() => replaceTemplateMetadata(styleTemplate, idx)}
>
<div className="gn-visual-style-editor-template-preview">
{styleTemplate?.preview?.config
Expand All @@ -121,7 +124,7 @@ function TemplateSelector({
})}
</ul>
<div className="gn-visual-style-editor-templates-footer">
<Button size="xs" variant="primary" onClick={handleApply}><Message msgId="gnviewer.applyStyle"/></Button>
<Button size="xs" disabled={selectedTemplate === undefined} variant="primary" onClick={handleApply}><Message msgId="gnviewer.applyStyle"/></Button>
</div>
</div>
}
Expand Down
5 changes: 4 additions & 1 deletion geonode_mapstore_client/client/js/utils/ResourceUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,11 @@ export function toMapStoreMapConfig(resource, baseConfig) {
* @param {Array} entry Array containing layer metadata information
* @returns {Object} metadata object
*/
export const parseMetadata = ({ entry }) => {
export const parseMetadata = ({ entry } = {}) => {
const metadata = {};
if (!entry) {
return metadata;
}
entry.forEach((entryObj) => {
const entryArray = Object.values(entryObj);
if (entryArray.length > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,4 +427,8 @@ describe('Test Resource Utils', () => {

expect(metadataObj).toEqual({key1: 'test', key2: 'test2'});
});
it('should return empty object if entry is not defined', () => {
const metadataObj = parseMetadata();
expect(metadataObj).toEqual({});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
.gn-visual-style-editor-styles {
.border-bottom-color-var(@theme-vars[main-border-color]);
}
.gn-visual-style-editor-template {
&.selected {
.outline-color-var(@theme-vars[focus-color]);
}
}
}

// **************
Expand Down Expand Up @@ -134,6 +139,10 @@
overflow: hidden;
text-align: center;
}
&.selected {
outline-width: 2px;
outline-style: solid;
}
}
}

Expand Down

0 comments on commit 88ddede

Please sign in to comment.