Skip to content

Commit

Permalink
Lint and clean
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaetanbrl committed Aug 21, 2024
1 parent e0ee368 commit fdacd45
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 47 deletions.
2 changes: 1 addition & 1 deletion docs/user-guide/attributes-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,4 @@ MapStore [allows to configure](https://mapstore.geosolutionsgroup.com/mapstore/d

Note that this restriction is never active for adminstrators. If active, the user see an icon to the left of the attribute table toolbar :

<img src="../img/attributes-table/restricted_area_icon.png" class="ms-docbutton"/>
<img src="../img/attributes-table/restricted_area_icon.png" class="ms-docbutton"/>
16 changes: 8 additions & 8 deletions web/client/components/data/featuregrid/toolbars/Toolbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,21 @@ const standardButtons = {
onClick={events.switchEditMode}
glyph="pencil" />),
isRestrictedByArea: ({ restrictedArea }) => {
return <Button
return (<Button
id="fg-isRestrictedByArea-button"
keyProp="fg-restrictedarea-button"
className="square-button-md"
bsStyle="warning"
tooltipId="featuregrid.toolbar.restrictedByArea"
disabled
style={isEmpty(restrictedArea) ? {
width: 0,
padding: 0,
borderWidth: 0
} : {}}>
<Glyphicon glyph="1-point-dashed" />
</Button>
},
width: 0,
padding: 0,
borderWidth: 0
} : {}}>
<Glyphicon glyph="1-point-dashed" />
</Button>);
},
filter: ({isFilterActive = false, viewportFilter, disabled, isSearchAllowed, mode, showAdvancedFilterButton = true, events = {}}) => (<TButton
id="search"
keyProp="search"
Expand Down
39 changes: 18 additions & 21 deletions web/client/epics/featuregrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
import requestBuilder from '../utils/ogc/WFST/RequestBuilder';
import { findGeometryProperty } from '../utils/ogc/WFS/base';
import { FEATURE_INFO_CLICK, HIDE_MAPINFO_MARKER, closeIdentify, hideMapinfoMarker } from '../actions/mapInfo';
import { LOGIN_SUCCESS, LOGOUT } from "../actions/security"
import { LOGIN_SUCCESS, LOGOUT } from "../actions/security";

import {
query,
Expand Down Expand Up @@ -113,7 +113,7 @@ import {
launchUpdateFilterFunc,
LAUNCH_UPDATE_FILTER_FUNC, SET_LAYER,
SET_VIEWPORT_FILTER, setViewportFilter,
setRestrictedArea,
setRestrictedArea
} from '../actions/featuregrid';

import {
Expand Down Expand Up @@ -219,7 +219,7 @@ const setupDrawSupport = (state, original) => {
// allow only feature inside restricted area
isValidFeature = booleanIntersects(restrictedArea, ft.geometry);
}
return isValidFeature
return isValidFeature;
});

if (cleanFeatures.length > 0) {
Expand Down Expand Up @@ -502,7 +502,6 @@ export const enableGeometryFilterOnEditMode = (action$, store) =>
action$.ofType(TOGGLE_MODE)
.filter(() => modeSelector(store.getState()) === MODES.EDIT)
.switchMap(() => {
console.log("enableGeometryFilterOnEditMode")
const currentFilter = find(getAttributeFilters(store.getState()), f => f.type === 'geometry') || {};
return currentFilter.value ? Rx.Observable.empty() : Rx.Observable.of(updateFilter({
attribute: findGeometryProperty(describeSelector(store.getState())).name,
Expand Down Expand Up @@ -1300,35 +1299,33 @@ export const resetViewportFilter = (action$, store) =>
: Rx.Observable.empty();
});

export const requestRestrictedArea = (action$, store) =>
export const requestRestrictedArea = (action$, store) =>
action$.ofType(OPEN_FEATURE_GRID, LOGIN_SUCCESS)
.filter(() =>
{
.filter(() => {
return !isAdminUserSelector(store.getState())
&& isLoggedIn(store.getState())
&& !isEmpty(restrictedAreaSrcSelector(store.getState()))}
)
.switchMap((action) => {
&& isLoggedIn(store.getState())
&& !isEmpty(restrictedAreaSrcSelector(store.getState()));
})
.switchMap(() => {
const src = restrictedAreaSrcSelector(store.getState());
if (src.url) {
return Rx.Observable.defer(() => fetch(src?.url).then(r => r?.json?.()))
.switchMap(result => {
return Rx.Observable.of(
setRestrictedArea(rawAsGeoJson(result)),
changePage(0)
)
})
} else {
return Rx.Observable.of(
setRestrictedArea(rawAsGeoJson(src.raw) || {}),
changePage(0)
)
);
});
}
})
return Rx.Observable.of(
setRestrictedArea(rawAsGeoJson(src.raw) || {}),
changePage(0)
);
});

export const resetRestrictedArea = (action$, store) =>
action$.ofType(LOGOUT, CLOSE_FEATURE_GRID)
.filter((a) => !isEmpty(restrictedAreaSrcSelector(store.getState())))
.filter(() => !isEmpty(restrictedAreaSrcSelector(store.getState())))
.switchMap(() => Rx.Observable.of(
setRestrictedArea({})
))
));
4 changes: 2 additions & 2 deletions web/client/reducers/featuregrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import {
UPDATE_EDITORS_OPTIONS,
SET_PAGINATION,
SET_VIEWPORT_FILTER,
SET_RESTRICTED_AREA,
SET_RESTRICTED_AREA
} from '../actions/featuregrid';
import { MAP_CONFIG_LOADED } from '../actions/config';

Expand Down Expand Up @@ -443,7 +443,7 @@ function featuregrid(state = emptyResultsState, action) {
}
case MAP_CONFIG_LOADED: {
return {...state, ...get(action, 'config.featureGrid', {})};
}
}
case SET_RESTRICTED_AREA: {
return { ...state, restrictedArea: { ...state.restrictedArea, geometry: action.area } };
}
Expand Down
12 changes: 6 additions & 6 deletions web/client/selectors/featuregrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,12 @@ export const restrictedAreaFilter = createShallowSelectorCreator(isEqual)(
projectionSelector,
describeSelector,
state => restrictedAreaOperatorSelector(state),
(restrictedArea, spatialField = [], viewportFilter, projection, describeLayer, operator) => {
(restrictedArea, spatialField = [], viewPortFilter, projection, describeLayer, operator) => {
const attribute = findGeometryProperty(describeLayer)?.name;
let existingFilter = [];
// if activate, viewportFilter already get existing filter
if(isEmpty(viewportFilter) && !isEmpty(spatialField)) {
existingFilter = spatialField?.operation ? [spatialField] : spatialField
if (isEmpty(viewPortFilter) && !isEmpty(spatialField)) {
existingFilter = spatialField?.operation ? [spatialField] : spatialField;
}
return !isEmpty(restrictedArea) ? {
spatialField: [
Expand All @@ -275,7 +275,7 @@ export const restrictedAreaFilter = createShallowSelectorCreator(isEqual)(
]
} : {};
}
)
);

/**
* Create spatialField filters array.
Expand All @@ -284,5 +284,5 @@ export const restrictedAreaFilter = createShallowSelectorCreator(isEqual)(
export const additionnalGridFilters = (state) => {
const restrictedArea = restrictedAreaFilter(state)?.spatialField || [];
const viewport = viewportFilter(state)?.spatialField || [];
return {spatialField: [...restrictedArea, ...viewport]}
}
return {spatialField: [...restrictedArea, ...viewport]};
};
20 changes: 11 additions & 9 deletions web/client/utils/FeatureGridUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,34 +396,36 @@ export const supportsFeatureEditing = (layer) => includes(supportedEditLayerType
export const areLayerFeaturesEditable = (layer) => !layer?.disableFeaturesEditing && supportsFeatureEditing(layer);

export const isWKT = (wktString) => {
const reader = new WKT();
let isWKTGeom = false;
try {
const reader = new WKT();
const feature = reader.readFeature(wktString);
if (feature) {
return true;
isWKTGeom = true;
}
} catch (e) {
return false;
isWKTGeom = false;
}
}
return isWKTGeom;
};

export const wktToGeoJson = (wktString) => {
const reader = new WKT();
const feature = reader.readFeature(wktString);
return {
type: feature.getGeometry().getType(),
coordinates: feature.getGeometry().getCoordinates()
}
}
};
};

/**
* Return GeoJSON geometry. Transform WKT to GeoJSON if necessary.
* @param {string} raw - geometry
* @returns
* @returns geometry object
*/
export const rawAsGeoJson = (raw) => {
if(isWKT(raw)) {
if (isWKT(raw)) {
return wktToGeoJson(raw);
}
return raw;
}
};

0 comments on commit fdacd45

Please sign in to comment.