Skip to content

Commit

Permalink
#8959 Add hide options for service selector of LayerDownload plugin (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
allyoucanmap authored Feb 21, 2023
1 parent ffb1bf2 commit a82f99e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
7 changes: 5 additions & 2 deletions web/client/components/data/download/DownloadDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class DownloadDialog extends React.Component {
formatsLoading: PropTypes.bool,
virtualScroll: PropTypes.bool,
customAttributeSettings: PropTypes.object,
attributes: PropTypes.array
attributes: PropTypes.array,
hideServiceSelector: PropTypes.bool
};

static defaultProps = {
Expand Down Expand Up @@ -82,7 +83,8 @@ class DownloadDialog extends React.Component {
{name: "EPSG:4326", label: "WGS84"}
],
virtualScroll: true,
downloadOptions: {}
downloadOptions: {},
hideServiceSelector: false
};

componentDidUpdate(oldProps) {
Expand Down Expand Up @@ -145,6 +147,7 @@ class DownloadDialog extends React.Component {
virtualScroll={this.props.virtualScroll}
customAttributesSettings={this.props.customAttributeSettings}
attributes={this.props.attributes}
hideServiceSelector={this.props.hideServiceSelector}
/>}
</div>
{!this.props.checkingWPSAvailability && <div role="footer">
Expand Down
8 changes: 5 additions & 3 deletions web/client/components/data/download/DownloadOptions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class DownloadOptions extends React.Component {
layer: PropTypes.object,
formatsLoading: PropTypes.bool,
virtualScroll: PropTypes.bool,
services: PropTypes.arrayOf(PropTypes.object)
services: PropTypes.arrayOf(PropTypes.object),
hideServiceSelector: PropTypes.bool
};

static defaultProps = {
Expand All @@ -60,7 +61,8 @@ class DownloadOptions extends React.Component {
services: [
{ value: "wps", label: "WPS" },
{ value: "wfs", label: "WFS" }
]
],
hideServiceSelector: false
};

constructor(props) {
Expand All @@ -76,7 +78,7 @@ class DownloadOptions extends React.Component {

render() {
return (<form>
{this.props.wpsAvailable && this.props.wfsAvailable &&
{!this.props.hideServiceSelector && this.props.wpsAvailable && this.props.wfsAvailable &&
<>
<label><Message msgId="layerdownload.service" /></label>
<Select
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,20 @@ describe('Test for DownloadDialog component', () => {
expect(dialog).toBeTruthy();
expect(dialog.getElementsByTagName('form')[0]).toBeTruthy();
});
it('should not render service selector with true hideServiceSelector prop', () => {
const selectedLayer = {
type: 'wms',
visibility: true,
id: 'mapstore:states__7',
search: {
url: '/geoserver/wfs'
}
};
ReactDOM.render(<DownloadDialog enabled service="wps" wpsAvailable layer={selectedLayer} hideServiceSelector />, document.getElementById("container"));
const dialog = document.getElementById('mapstore-export');
expect(dialog).toBeTruthy();
expect(dialog.getElementsByTagName('form')[0]).toBeTruthy();
const selectors = dialog.querySelectorAll('.Select');
expect(selectors.length).toBe(2);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,10 @@ describe('Test for DownloadOptions component', () => {
const selectors = form.querySelectorAll('.Select');
expect(selectors.length).toBe(2);
});
it('should not render service selector if hideServiceSelector is true', () => {
ReactDOM.render(<DownloadOptions wpsAvailable wfsAvailable hideServiceSelector service="wps" />, document.getElementById("container"));
const form = document.getElementsByTagName('form')[0];
const selectors = form.querySelectorAll('.Select');
expect(selectors.length).toBe(2);
});
});
6 changes: 4 additions & 2 deletions web/client/plugins/LayerDownload.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ import { createPlugin } from '../utils/PluginsUtils';
* @prop {object[]} srsList An array of name-label objects for the allowed srs available. Use name:'native' to omit srsName param in wfs filter
* @prop {string} defaultSrs Default selected srs
* @prop {string} closeGlyph The icon to use for close the dialog
* @prop {string} defaultSelectedService The service that should be used by default for donwloading. Valid values: "wfs", "wps"
* @prop {string} defaultSelectedService The service that should be used by default for downloading. Valid values: "wfs", "wps"
* @prop {bool} hideServiceSelector hide service selector input from the user interface
* @example
* {
* "name": "LayerDownload",
Expand All @@ -77,7 +78,8 @@ import { createPlugin } from '../utils/PluginsUtils';
* {"name": "EPSG:4326", "label": "WGS84"}
* ],
* "defaultSrs": "native",
* "defaultSelectedService": "wfs"
* "defaultSelectedService": "wfs",
* "hideServiceSelector": true
* }
* }
* // it is possible to support GeoPackage format when the targeted GeoServer uses wps download extensions
Expand Down

0 comments on commit a82f99e

Please sign in to comment.