Skip to content

Commit

Permalink
geosolutions-it#10487: Custom Tile Grids settings for WMS service are…
Browse files Browse the repository at this point in the history
… not retained when adding a Background layer from Catalog

Description:
- handle showing custom tile grid settings for wms service in adding background layer.
- add unit test for the changes
  • Loading branch information
mahmoudadel54 committed Jul 24, 2024
1 parent 0b28a76 commit 99158eb
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 21 deletions.
58 changes: 37 additions & 21 deletions web/client/components/TOC/fragments/settings/WMSCacheOptions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,14 @@ const infoText = {
* @prop {object} layer layer configuration
* @prop {boolean} disableTileGrids disable tile grids toolbar
* @prop {function} onChange callback triggered after changing the form
* @prop {string} owner the owner component name like: 'background-dialog'
*/
function WMSCacheOptions({
layer = {},
projection,
onChange,
disableTileGrids
disableTileGrids,
owner = ""
}) {

const [tileGridLoading, setTileGridLoading] = useState(false);
Expand Down Expand Up @@ -266,8 +268,41 @@ function WMSCacheOptions({
.finally(() => setTimeout(() => setTileGridLoading(false), 500));
};

const handleGetTileGridSettings = () => {
const newTileGridStrategy = layer.tileGridStrategy !== 'custom'
? 'custom'

Check failure on line 273 in web/client/components/TOC/fragments/settings/WMSCacheOptions.jsx

View workflow job for this annotation

GitHub Actions / test-front-end

Expected indentation of 12 spaces but found 8
: undefined;

Check failure on line 274 in web/client/components/TOC/fragments/settings/WMSCacheOptions.jsx

View workflow job for this annotation

GitHub Actions / test-front-end

Expected indentation of 12 spaces but found 8
const promise = newTileGridStrategy === 'custom'
&& ((layer?.tileGrids?.length || 0) === 0 || !layer?.tileGridCacheSupport)
? onTileMatrixSetsFetch(layer)
: Promise.resolve(undefined);
return promise.then(({ tileGrids, tileGridCacheSupport } = {}) => {
const hasTileGrids = (tileGrids?.length || 0) > 0;
const tileGridStrategy = hasTileGrids
? newTileGridStrategy
: undefined;
let tileChangedData = {
tileGridCacheSupport,
tileGridStrategy,
tileGrids
};
if (owner === 'background-dialog' && newTileGridStrategy === 'custom') {
tileChangedData = {
...tileChangedData, tiled: true, tileGridStrategy: 'custom'
}

Check failure on line 292 in web/client/components/TOC/fragments/settings/WMSCacheOptions.jsx

View workflow job for this annotation

GitHub Actions / test-front-end

Missing semicolon
}
handleOnChange(tileChangedData);
});
};

const InfoText = infoText[layer.tileGridStrategy] || infoText.standard;

// fetching grid data in case background layers
React.useEffect(() => {
if (layer.remoteTileGrids && owner === 'background-dialog') {
handleGetTileGridSettings();
}
}, [])

Check failure on line 305 in web/client/components/TOC/fragments/settings/WMSCacheOptions.jsx

View workflow job for this annotation

GitHub Actions / test-front-end

Missing semicolon
return (
<div className="ms-wms-cache-options">
<div className="ms-wms-cache-options-content">
Expand Down Expand Up @@ -320,26 +355,7 @@ function WMSCacheOptions({
glyph={layer.tileGridStrategy === 'custom' ? 'grid-custom' : 'grid-regular'}
bsStyle={layer.tileGridStrategy === 'custom' ? 'success' : 'primary'}
className="square-button-md"
onClick={() => {
const newTileGridStrategy = layer.tileGridStrategy !== 'custom'
? 'custom'
: undefined;
const promise = newTileGridStrategy === 'custom'
&& ((layer?.tileGrids?.length || 0) === 0 || !layer?.tileGridCacheSupport)
? onTileMatrixSetsFetch(layer)
: Promise.resolve(undefined);
return promise.then(({ tileGrids, tileGridCacheSupport } = {}) => {
const hasTileGrids = (tileGrids?.length || 0) > 0;
const tileGridStrategy = hasTileGrids
? newTileGridStrategy
: undefined;
handleOnChange({
tileGridCacheSupport,
tileGridStrategy,
tileGrids
});
});
}}
onClick={handleGetTileGridSettings}
/>
</div>}
</div>
Expand Down
1 change: 1 addition & 0 deletions web/client/components/background/BackgroundDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ export default class BackgroundDialog extends React.Component {
projection={this.props.projection}
onChange={value => this.setState(value)}
disableTileGrids={this.props.disableTileGrids}
owner={"background-dialog"}
/>
</FormGroup>}
<Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import * as TestUtils from 'react-dom/test-utils';
import expect from 'expect';
import BackgroundDialog from '../BackgroundDialog';

import axios from '../../../libs/ajax';
import MockAdapter from 'axios-mock-adapter';
let mockAxios;

describe('test BackgroundDialog', () => {
beforeEach((done) => {
document.body.innerHTML = '<div id="container"></div>';
Expand Down Expand Up @@ -83,4 +87,36 @@ describe('test BackgroundDialog', () => {
const wmsCacheOptionsToolbar = document.querySelector('.ms-wms-cache-options-toolbar');
expect(wmsCacheOptionsToolbar).toBeTruthy();
});
it('should render with WMS cache options with remoteTileGrids = true', (done) => {
mockAxios = new MockAdapter(axios);
mockAxios.onGet().reply(200, {
tileMatrixSets: [],
tileMatrixSetLinks: [],
tileGrids: [],
styles: [],
formats: []
});
ReactDOM.render(<BackgroundDialog
layer={{
type: 'wms',
url: '/geoserver/wms',
name: 'workspace:name',
remoteTileGrids: true
}}
/>,
document.getElementById("container"));
setTimeout(() => {
const modalNode = document.querySelector('#ms-resizable-modal');
expect(modalNode).toBeTruthy();
const wmsCacheOptionsContent = document.querySelector('.ms-wms-cache-options-content');
expect(wmsCacheOptionsContent).toBeTruthy();
const wmsCacheOptionsToolbar = document.querySelector('.ms-wms-cache-options-toolbar');
expect(wmsCacheOptionsToolbar).toBeTruthy();
const wmsCacheCustomGridOption = document.querySelector('.ms-wms-cache-options-toolbar button.active span.glyphicon-grid-custom');
expect(wmsCacheCustomGridOption).toBeTruthy();
const wmsCacheRefreshOption = document.querySelector('.ms-wms-cache-options-toolbar .glyphicon-refresh');
expect(wmsCacheRefreshOption).toBeTruthy();
done();
}, 1000);
});
});

0 comments on commit 99158eb

Please sign in to comment.