-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#9567: handle functionality of zoom to record in table widgets
- Loading branch information
1 parent
2e09d7f
commit 90ba37c
Showing
10 changed files
with
157 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
web/client/components/widgets/enhancers/__tests__/dependenciesToZoomTo-test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright 2020, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import {createSink} from 'recompose'; | ||
import expect from 'expect'; | ||
import axios from 'axios'; | ||
import MockAdapter from 'axios-mock-adapter'; | ||
|
||
import dependenciesToZoomTo from '../dependenciesToZoomTo'; | ||
|
||
import MapUtils from '../../../../utils/MapUtils'; | ||
|
||
|
||
describe('widgets dependenciesToZoomTo enhancer', () => { | ||
let mockAxios; | ||
const widgetsProps = [{ | ||
id: "123", | ||
widgetType: "table", | ||
dependencies: { | ||
extentObj: { | ||
extent: [-10, 0, 0, -10], | ||
crs: "EPSG:3426", | ||
maxZoom: 21 | ||
} | ||
}, | ||
geomProp: "the_geom", | ||
mapSync: true | ||
}, | ||
{ | ||
id: "123Map", | ||
widgetType: "map", | ||
maps: [{}], | ||
mapSync: true | ||
}]; | ||
beforeEach((done) => { | ||
mockAxios = new MockAdapter(axios); | ||
document.body.innerHTML = '<div id="container"></div>'; | ||
setTimeout(done); | ||
}); | ||
afterEach((done) => { | ||
mockAxios.restore(); | ||
ReactDOM.unmountComponentAtNode(document.getElementById("container")); | ||
document.body.innerHTML = ''; | ||
setTimeout(done); | ||
}); | ||
it('dependenciesToZoomTo default', (done) => { | ||
const Sink = dependenciesToZoomTo(createSink( props => { | ||
expect(props).toExist(); | ||
expect(props).toEqual({ widgets: widgetsProps }); | ||
done(); | ||
})); | ||
ReactDOM.render(<Sink widgets={widgetsProps} />, document.getElementById("container")); | ||
}); | ||
|
||
it('dependenciesToZoomTo triggering zoom to extent', (done) => { | ||
let hookRegisterProps = MapUtils.createRegisterHooks(); | ||
const Sink = dependenciesToZoomTo(createSink(({ | ||
hookRegister = hookRegisterProps, widgets = widgetsProps | ||
}) => { | ||
expect(hookRegister).toExist(); | ||
const hook = hookRegister.getHook(MapUtils.ZOOM_TO_EXTENT_HOOK); | ||
expect(hook).toExist(); | ||
expect(widgets).toExist(); | ||
expect(widgets).toEqual(widgetsProps); | ||
done(); | ||
})); | ||
hookRegisterProps.registerHook(MapUtils.ZOOM_TO_EXTENT_HOOK, {hookName: MapUtils.ZOOM_TO_EXTENT_HOOK}); | ||
ReactDOM.render(<Sink hookRegister={hookRegisterProps} widgets={widgetsProps} updateProperty={(path) => { | ||
expect(path).toBe("dependencies.extentObj"); | ||
done(); | ||
}}/>, document.getElementById("container")); | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
web/client/components/widgets/enhancers/dependenciesToZoomTo.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React, { useEffect, memo } from 'react'; | ||
|
||
const dependenciesToZoomTo = (WrappedCompoennet)=>{ | ||
function DependenciesToZoomTo(props) { | ||
let tblWidgetWithExtentObj = props.widgets.find(i=>i?.dependencies?.extentObj); | ||
const extentObj = tblWidgetWithExtentObj?.dependencies?.extentObj; | ||
useEffect(()=>{ | ||
if ( extentObj && extentObj ) { | ||
const hook = props?.hookRegister?.getHook("ZOOM_TO_EXTENT_HOOK"); | ||
if (hook) { | ||
// trigger "internal" zoom to extent | ||
hook(extentObj.extent, { | ||
crs: extentObj.crs, maxZoom: extentObj.maxZoom | ||
}); | ||
// removeextentObj from state | ||
props?.updateProperty(tblWidgetWithExtentObj.id, `dependencies.extentObj`, undefined); | ||
} | ||
} | ||
|
||
}, [extentObj?.extent?.join(",")]); | ||
return <WrappedCompoennet { ...props } />; | ||
} | ||
return memo(DependenciesToZoomTo); | ||
}; | ||
export default dependenciesToZoomTo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters