Skip to content

Commit ffa46f9

Browse files
authored
Fix #2903. Add support to hide spatial and cross layer filter (#2904)
1 parent 6165bb3 commit ffa46f9

4 files changed

Lines changed: 69 additions & 12 deletions

File tree

web/client/components/data/query/QueryBuilder.jsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ class QueryBuilder extends React.Component {
6363
autocompleteEnabled: PropTypes.bool,
6464
emptyFilterWarning: PropTypes.bool,
6565
header: PropTypes.node,
66-
zoom: PropTypes.number
66+
zoom: PropTypes.number,
67+
toolsOptions: PropTypes.object
6768
};
6869

6970
static defaultProps = {
@@ -127,7 +128,8 @@ class QueryBuilder extends React.Component {
127128
onQuery: () => {},
128129
onReset: () => {},
129130
onChangeDrawingStatus: () => {}
130-
}
131+
},
132+
toolsOptions: {}
131133
};
132134

133135
render() {
@@ -174,23 +176,23 @@ class QueryBuilder extends React.Component {
174176
addButtonIcon={this.props.addButtonIcon}
175177
attributePanelExpanded={this.props.attributePanelExpanded}
176178
actions={this.props.attributeFilterActions}/>
177-
<SpatialFilter
179+
{this.props.toolsOptions.hideSpatialFilter ? null : <SpatialFilter
178180
useMapProjection={this.props.useMapProjection}
179181
spatialField={this.props.spatialField}
180182
spatialOperations={this.props.spatialOperations}
181183
spatialMethodOptions={this.props.spatialMethodOptions}
182184
spatialPanelExpanded={this.props.spatialPanelExpanded}
183185
showDetailsPanel={this.props.showDetailsPanel}
184186
actions={this.props.spatialFilterActions}
185-
zoom={this.props.zoom}/>
186-
<CrossLayerFilter
187+
zoom={this.props.zoom}/>}
188+
{this.props.toolsOptions.hideCrossLayer ? null : <CrossLayerFilter
187189
spatialOperations={this.props.spatialOperations}
188190
crossLayerExpanded={this.props.crossLayerExpanded}
189191
searchUrl={this.props.searchUrl}
190192
featureTypeName={this.props.featureTypeName}
191193
{...this.props.crossLayerFilterOptions}
192194
{...this.props.crossLayerFilterActions}
193-
/>
195+
/>}
194196
</BorderLayout>
195197
: <div style={{margin: "0 auto", width: "60px"}}><Spinner spinnerName="three-bounce" overrideSpinnerClassName="spinner"/></div>;
196198
}

web/client/components/data/query/__tests__/QueryBuilder-test.jsx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,51 @@ describe('QueryBuilder', () => {
141141
const queryButton = document.getElementById('query-toolbar-query');
142142
expect(queryButton).toExist();
143143
expect(queryButton.getAttribute("disabled")).toBe('');
144+
// check presence of attribute, spatial and cross layer filter
145+
expect(document.querySelectorAll('.mapstore-switch-panel').length).toBe(3);
146+
});
147+
it('tool options', () => {
148+
const groupLevels = 5;
149+
150+
const groupFields = [];
151+
152+
const filterFields = [{
153+
rowId: 100,
154+
groupId: 1,
155+
attribute: "",
156+
operator: null,
157+
value: null,
158+
exception: null
159+
}];
160+
161+
const attributes = [{
162+
id: "Attribute",
163+
type: "list",
164+
values: [
165+
"attribute1",
166+
"attribute2",
167+
"attribute3",
168+
"attribute4",
169+
"attribute5"
170+
]
171+
}];
172+
173+
const querybuilder = ReactDOM.render(
174+
<QueryBuilder
175+
toolsOptions={{
176+
hideCrossLayer: true,
177+
hideSpatialFilter: true
178+
}}
179+
filterFields={filterFields}
180+
attributes={attributes}
181+
groupFields={groupFields}
182+
groupLevels={groupLevels}
183+
/>,
184+
document.getElementById("container")
185+
);
186+
expect(querybuilder).toExist();
187+
// only attribute filter should be shown
188+
expect(document.querySelectorAll('.mapstore-switch-panel').length).toBe(1);
144189
});
145190

146191
it('creates the QueryBuilder component in error state', () => {

web/client/localConfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,10 @@
518518
}, {
519519
"name": "QueryPanel",
520520
"cfg": {
521+
"toolsOptions": {
522+
"hideCrossLayer": true,
523+
"hideSpatialFilter": true
524+
},
521525
"containerPosition": "columns"
522526
}
523527
}, "Dashboard", "Notifications"],

web/client/plugins/QueryPanel.jsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ class QueryPanel extends React.Component {
204204
activateSettingsTool: PropTypes.bool,
205205
visibilityCheckType: PropTypes.string,
206206
settingsOptions: PropTypes.object,
207-
layout: PropTypes.object
207+
layout: PropTypes.object,
208+
toolsOptions: PropTypes.object
208209
};
209210

210211
static defaultProps = {
@@ -226,7 +227,8 @@ class QueryPanel extends React.Component {
226227
visibilityCheckType: "checkbox",
227228
settingsOptions: {},
228229
querypanelEnabled: false,
229-
layout: {}
230+
layout: {},
231+
toolsOptions: {}
230232
};
231233

232234
componentWillReceiveProps(newProps) {
@@ -275,6 +277,7 @@ class QueryPanel extends React.Component {
275277
header={<QueryPanelHeader onToggleQuery={this.props.onToggleQuery} />}
276278
spatialOperations={this.props.spatialOperations}
277279
spatialMethodOptions={this.props.spatialMethodOptions}
280+
toolsOptions={this.props.toolsOptions}
278281
featureTypeErrorText={<Message msgId="layerProperties.featureTypeError"/>}/>
279282
</div>);
280283
};
@@ -301,15 +304,18 @@ class QueryPanel extends React.Component {
301304
* - blacklist {string[]} a list of banned words excluded from the wfs search
302305
* - maxFeatures {number} the maximum features fetched per request
303306
* - predicate {string} the cql predicate
304-
* - queriableAttributes {string[]} list of attributes to query on.
305-
* - typeName {string} the workspace + layer name on geosever
307+
* - querableAttributes {string[]} list of attributes to query on.
308+
* - typeName {string} the workspace + layer name on geoserver
306309
* - valueField {string} the attribute from features properties used as value/label in the autocomplete list
307310
* - srsName {string} The projection of the requested features fetched via wfs
308311
*
309312
* @prop {object[]} cfg.spatialOperations: The list of geometric operations use to create the spatial filter.<br/>
313+
* @prop {boolean} cfg.toolsOptions.hideCrossLayer force cross layer to hide
314+
* @prop {boolean} cfg.toolsOptions.hideCrossLayer force cross layer filter panel to hide (when is not used or not usable)
315+
* @prop {boolean} cfg.toolsOptions.hideSpatialFilter force spatial filter panel to hide (when is not used or not usable)
310316
*
311317
* @example
312-
* // This example configure a layer with polyogns geometry as spatial filter method
318+
* // This example configure a layer with polygons geometry as spatial filter method
313319
* "spatialOperations": [
314320
* {"id": "INTERSECTS", "name": "queryform.spatialfilter.operations.intersects"},
315321
* {"id": "BBOX", "name": "queryform.spatialfilter.operations.bbox"},
@@ -339,7 +345,7 @@ class QueryPanel extends React.Component {
339345
* "queriableAttributes": ["ATTRIBUTE_X"],
340346
* "typeName": "workspace:typeName",
341347
* "valueField": "ATTRIBUTE_Y",
342-
* "srsName": "ESPG:3857"
348+
* "srsName": "EPSG:3857"
343349
* },
344350
* "customItemClassName": "customItemClassName"
345351
* }

0 commit comments

Comments
 (0)