Skip to content

Commit

Permalink
Fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ridoo committed Oct 24, 2023
1 parent e9e4e57 commit e627387
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,8 @@ const parseTabItems = (items) => {
};
const isDefaultTabType = (type) => type === 'tab';

const canShowAttributeTab = ({resource, tab}) => {
return resource?.resource_type === 'dataset' && tab?.type === 'attribute-table'
}

function DetailsInfo({
tabs = [],
resource,
formatHref,
resourceTypesInfo
}) {
Expand Down
191 changes: 96 additions & 95 deletions geonode_mapstore_client/client/js/plugins/ExclusiveLayer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,26 @@ import { createPlugin } from '@mapstore/framework/utils/PluginsUtils';
import { layerSelector, groupSelector } from '../selectors/layersSelectors';
import { updateNode } from '@mapstore/framework/actions/layers';

function ExclusiveLayer(props) {
const layers = props.layers;
const groups = props.groups.filter((group) => group.id !== "Default");
const previousLayersAndGroups = useRef("");
const [ prevVals, updatePrevVals ] = useState(false);
useEffect(() => {
previousLayersAndGroups.current = {
"layers": layers,
"groups": groups,
};
}, [prevVals])

let onGroup = false;
window.onclick = (e) => {
const clickedItem = e.target
if ( clickedItem.className.includes("glyphicon-record") || clickedItem.className.includes("glyphicon-unchecked") ||
clickedItem.className.includes("glyphicon-eye-open") || clickedItem.className.includes("glyphicon-eye-close")) {
onGroup = checkIfClickedOnGroup( clickedItem );
if ( onGroup.clicked && onGroup.open ) {
checkExclusiveGroupsForConsistency( groups, layers, props );
} else {
changeLayerVisibility( props, previousLayersAndGroups, layers );
}
updatePrevVals( !prevVals );
}
}

// if ( previousLayersAndGroups.current.groups && groups.length === previousLayersAndGroups.current.groups.length ) {
if ( previousLayersAndGroups.current.groups && groups ) {
for ( let i=0; i<groups.length; i++ ) {
const oldGroup = previousLayersAndGroups.current.groups.filter((curr_gr) => groups[i].id === curr_gr.id)[0];
if ( oldGroup ) {
//check if a group was changed from non-exclusive to exclusive
if ( groups[i].exclusiveLayer && !oldGroup.exclusiveLayer ) {
const layersInGroup = getLayersInGroup( layers, groups[i].id );
const visibleLayers = countVisibleLayers( layersInGroup );
if ( visibleLayers>1 ) {
layersInGroup.forEach( ( layer ) => {
props.updateLayerVisibility( layer.id, 'layer', { visibility: false } );
})
}
const checkIfClickedOnGroup = (click) =>{
if ( click.parentElement.attributes.class.nodeValue.includes("toc-default-group-head") ) {
if ( click.className.includes("glyphicon-eye-open") ) {
return {
"clicked": true,
"open": true,
}
//check if a layer was moved from one group to another. If so, check if the target group is exclusive and act accordingly
checkIfLayerMoved( groups[i], oldGroup, layers, previousLayersAndGroups.current.layers, props );
} else {
return {
"clicked": true,
"open": false,
}
}
} else {
return {
"clicked": false,
"open": null,
}
}
return (
<div></div>
)
}

const getLayersInGroup = (layers, group) => {
Expand All @@ -70,34 +40,6 @@ const countVisibleLayers = (layers) => {
return visibleLayers;
}

const changeLayerVisibility = (props, previousLayersAndGroups, layers) => {
if ( props && previousLayersAndGroups.current ) {
findLayerThatChangedVisibility( layers, previousLayersAndGroups.current.layers, props );
}
}

const checkIfLayerMoved = ( newGroup, oldGroup, newLayers, oldLayers, props ) => {
if ( ( newGroup.nodes.length - oldGroup.nodes.length ) === 1 ) { //if this is true, newGroup is the group where the layer was moved to.
if ( newGroup.exclusiveLayer ) {
const layersInNewGroup = getLayersInGroup( newLayers, newGroup.id );
const oldLayersInGroup = getLayersInGroup( oldLayers, newGroup.id);
const visibleLayers = countVisibleLayers(layersInNewGroup)
if ( visibleLayers > 1 ) {
for ( let i=0; i<layersInNewGroup.length; i++ ) {
const tmpLyr = oldLayersInGroup.filter((ol)=>ol.id===layersInNewGroup[i].id)[0];
if ( tmpLyr && tmpLyr.visibility ) {
props.updateLayerVisibility( layersInNewGroup[i].id, 'layer', {visibility:false} );
}
if ( tmpLyr === undefined) { //if tmpLayer is undefined, it means that an older 'version' of the layer does not exist, meaning it was just added.
const visible = layersInNewGroup[i].visibility;
props.updateLayerVisibility( layersInNewGroup[i].id, 'layer', {visibility:!visible});
}
}
}
}
}
}

const checkExclusiveGroupsForConsistency = ( groups, layers, props ) => {
if ( groups ) {
groups.forEach( group => {
Expand All @@ -116,6 +58,15 @@ const checkExclusiveGroupsForConsistency = ( groups, layers, props ) => {
}
}

const getCorrespondingGroup = ( props, layer ) => {
const corrGr = head(props.groups.filter((group) => isObject(group) && group.id === layer.group));
if ( corrGr !== undefined ) {
return corrGr;
} else {
return head(props.groups.filter((group) => isObject(group) && group.id === "Default"));
}
}

const findLayerThatChangedVisibility = ( newLayers, oldLayers, props ) => {
let changedLayers=[];
for ( let i = 0; i < newLayers.length; i++ ) {
Expand All @@ -137,34 +88,84 @@ const findLayerThatChangedVisibility = ( newLayers, oldLayers, props ) => {
}
}

const checkIfClickedOnGroup = (click) =>{
if ( click.parentElement.attributes.class.nodeValue.includes("toc-default-group-head") ) {
if ( click.className.includes("glyphicon-eye-open") ) {
return {
"clicked": true,
"open": true,
}
} else {
return {
"clicked": true,
"open": false,
const changeLayerVisibility = (props, previousLayersAndGroups, layers) => {
if ( props && previousLayersAndGroups.current ) {
findLayerThatChangedVisibility( layers, previousLayersAndGroups.current.layers, props );
}
}

const checkIfLayerMoved = ( newGroup, oldGroup, newLayers, oldLayers, props ) => {
if ( ( newGroup.nodes.length - oldGroup.nodes.length ) === 1 ) { //if this is true, newGroup is the group where the layer was moved to.
if ( newGroup.exclusiveLayer ) {
const layersInNewGroup = getLayersInGroup( newLayers, newGroup.id );
const oldLayersInGroup = getLayersInGroup( oldLayers, newGroup.id);
const visibleLayers = countVisibleLayers(layersInNewGroup)
if ( visibleLayers > 1 ) {
for ( let i=0; i<layersInNewGroup.length; i++ ) {
const tmpLyr = oldLayersInGroup.filter((ol)=>ol.id===layersInNewGroup[i].id)[0];
if ( tmpLyr && tmpLyr.visibility ) {
props.updateLayerVisibility( layersInNewGroup[i].id, 'layer', {visibility:false} );
}
if ( tmpLyr === undefined) { //if tmpLayer is undefined, it means that an older 'version' of the layer does not exist, meaning it was just added.
const visible = layersInNewGroup[i].visibility;
props.updateLayerVisibility( layersInNewGroup[i].id, 'layer', {visibility:!visible});
}
}
}
}
} else {
return {
"clicked": false,
"open": null,
}
}
}

const getCorrespondingGroup = ( props, layer ) => {
const corrGr = head(props.groups.filter((group) => isObject(group) && group.id === layer.group));
if ( corrGr !== undefined ) {
return corrGr;
} else {
return head(props.groups.filter((group) => isObject(group) && group.id === "Default"));

function ExclusiveLayer(props) {
const layers = props.layers;
const groups = props.groups.filter((group) => group.id !== "Default");
const previousLayersAndGroups = useRef("");
const [ prevVals, updatePrevVals ] = useState(false);
useEffect(() => {
previousLayersAndGroups.current = {
"layers": layers,
"groups": groups,
};
}, [prevVals])

let onGroup = false;
window.onclick = (e) => {
const clickedItem = e.target
if ( clickedItem.className.includes("glyphicon-record") || clickedItem.className.includes("glyphicon-unchecked") ||
clickedItem.className.includes("glyphicon-eye-open") || clickedItem.className.includes("glyphicon-eye-close")) {
onGroup = checkIfClickedOnGroup( clickedItem );
if ( onGroup.clicked && onGroup.open ) {
checkExclusiveGroupsForConsistency( groups, layers, props );
} else {
changeLayerVisibility( props, previousLayersAndGroups, layers );
}
updatePrevVals( !prevVals );
}
}

if ( previousLayersAndGroups.current.groups && groups ) {
for ( let i=0; i<groups.length; i++ ) {
const oldGroup = previousLayersAndGroups.current.groups.filter((current) => groups[i].id === current.id)[0];
if ( oldGroup ) {
//check if a group was changed from non-exclusive to exclusive
if ( groups[i].exclusiveLayer && !oldGroup.exclusiveLayer ) {
const layersInGroup = getLayersInGroup( layers, groups[i].id );
const visibleLayers = countVisibleLayers( layersInGroup );
if ( visibleLayers>1 ) {
layersInGroup.forEach( ( layer ) => {
props.updateLayerVisibility( layer.id, 'layer', { visibility: false } );
})
}
}
//check if a layer was moved from one group to another. If so, check if the target group is exclusive and act accordingly
checkIfLayerMoved( groups[i], oldGroup, layers, previousLayersAndGroups.current.layers, props );
}
}
}
return (
<div></div>
)
}

const ExclusiveLayerPlugin = connect((state) => ({
Expand Down
10 changes: 4 additions & 6 deletions geonode_mapstore_client/client/js/plugins/TabularPreview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { connect } from 'react-redux';
import { createSelector } from 'reselect';

import { createPlugin } from '@mapstore/framework/utils/PluginsUtils';
import { describeFeatureType, getFeatureSimple } from '@mapstore/framework/api/WFS';
import { getFeatureSimple } from '@mapstore/framework/api/WFS';

import Table from '@js/components/Table';
import resourceReducer from '@js/reducers/gnresource';

function propertyToKey(property, index) {
function propertyToKey(property) {
return `${property}`;
};

Expand All @@ -32,8 +32,6 @@ function rowsFromFeatures(data) {
};




function TableComponent({ owsUrl, typeName }) {
const [header, setHeader] = useState();
const [rows, setRows] = useState();
Expand All @@ -44,8 +42,8 @@ function TableComponent({ owsUrl, typeName }) {
const data = await getFeatureSimple(owsUrl, { typeName });
setHeader(headerFromFeatures(data));
setRows(rowsFromFeatures(data));
} catch(error) {
setError(error)
} catch(e) {
setError(e)
}
}
getFeatures()
Expand Down
19 changes: 8 additions & 11 deletions geonode_mapstore_client/client/js/selectors/layersSelectors.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
import isObject from 'lodash/isObject';

export const layerSelector = (state) => {
const layers = state.layers.flat.filter(layer => filterLayers(layer));
return layers;
};

function filterLayers(layer) {
if (layer.group != 'background') {
return layer;
}
return layer.group !== 'background' ? layer : undefined;
}

export const groupSelector = (state) => {
return returnGroup(state.layers.groups);
}
export const layerSelector = (state) => {
return state.layers.flat.filter(layer => filterLayers(layer));
};

const returnGroup = (groups) => {
if ( Array.isArray(groups) ) {
Expand All @@ -35,6 +28,10 @@ const returnGroup = (groups) => {
}
}

export const groupSelector = (state) => {
return returnGroup(state.layers.groups);
}

export const getStyleeditor = (state) => {
return state.styleeditor;
}

0 comments on commit e627387

Please sign in to comment.