-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea9e64c
commit 6825a35
Showing
16 changed files
with
218 additions
and
23 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
40 changes: 40 additions & 0 deletions
40
web/client/components/widgets/enhancers/__tests__/dependenciesToMapProp-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,40 @@ | ||
/* | ||
* Copyright 2018, 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. | ||
*/ | ||
const React = require('react'); | ||
const ReactDOM = require('react-dom'); | ||
const {createSink} = require('recompose'); | ||
const expect = require('expect'); | ||
const dependenciesToMapProp = require('../dependenciesToMapProp'); | ||
|
||
describe('dependenciesToMapProp enhancer', () => { | ||
beforeEach((done) => { | ||
document.body.innerHTML = '<div id="container"></div>'; | ||
setTimeout(done); | ||
}); | ||
afterEach((done) => { | ||
ReactDOM.unmountComponentAtNode(document.getElementById("container")); | ||
document.body.innerHTML = ''; | ||
setTimeout(done); | ||
}); | ||
it('dependenciesToMapProp rendering with defaults', (done) => { | ||
const Sink = dependenciesToMapProp('center')(createSink( props => { | ||
expect(props.map.center.x).toBe(1); | ||
expect(props.map.center.y).toBe(1); | ||
done(); | ||
})); | ||
ReactDOM.render(<Sink map={{center: {x: 1, y: 1}}} dependencies={{center: {x: 2, y: 2}}}/>, document.getElementById("container")); | ||
}); | ||
it('dependenciesToMapProp rendering with mapSync', (done) => { | ||
const Sink = dependenciesToMapProp('center')(createSink(props => { | ||
expect(props.map.center.x).toBe(2); | ||
expect(props.map.center.y).toBe(2); | ||
done(); | ||
})); | ||
ReactDOM.render(<Sink mapSync map={{ center: { x: 1, y: 1 } }} dependencies={{ center: { x: 2, y: 2 } }} />, document.getElementById("container")); | ||
}); | ||
}); |
24 changes: 24 additions & 0 deletions
24
web/client/components/widgets/enhancers/dependenciesToMapProp.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,24 @@ | ||
/* | ||
* Copyright 2018, 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. | ||
*/ | ||
const {set} = require('../../../utils/ImmutableUtils'); | ||
const {shallowEqual, branch, withPropsOnChange} = require('recompose'); | ||
/** | ||
* Syncs map center | ||
*/ | ||
module.exports = (prop) => branch( | ||
(({mapSync} = {}) => mapSync), | ||
withPropsOnChange( | ||
({ mapSync, dependencies = {} } = {}, { mapSync: newMapSync, dependencies: newDependencies }) => | ||
newDependencies && shallowEqual(dependencies[prop], newDependencies[prop]) | ||
|| mapSync === newMapSync, | ||
({ map, mapSync, dependencies = {} }) => ({ | ||
mapStateSource: "__dependency_system__", | ||
map: dependencies[prop] && mapSync ? set(prop, dependencies[prop], map) : map | ||
}) | ||
) | ||
); |
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
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
56 changes: 56 additions & 0 deletions
56
web/client/plugins/widgetbuilder/enhancers/connection/mapPositionConnect.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,56 @@ | ||
/* | ||
* Copyright 2018, 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. | ||
*/ | ||
const { withHandlers, withProps, compose } = require('recompose'); | ||
const { omit } = require('lodash'); | ||
|
||
/** | ||
* Provides proper handlers and variables to connect a widget to a map viewport in the toolbar or other builders | ||
* requires: | ||
* - editorData object | ||
* - onChange: function to change widget properties | ||
* - toggleDependencySelector function in case of multiple maps | ||
* | ||
*/ | ||
module.exports = compose( | ||
withProps(({ availableDependencies = [], editorData = {}} = {}) => ({ | ||
availableDependencies: availableDependencies.filter(d => !(editorData.id && d.indexOf(editorData.id) >= 0)) | ||
})), | ||
withProps(({ editorData = {} }) => ({ | ||
canConnect: true, | ||
connected: editorData.mapSync | ||
})), | ||
withHandlers({ | ||
toggleConnection: ({ onChange = () => { }, editorData = {} }) => (widget, id) => { | ||
onChange('mapSync', !editorData.mapSync); | ||
const center = | ||
!editorData.mapSync | ||
? id === 'map' | ||
? 'center' | ||
: `${id}.center` | ||
: undefined; | ||
const zoom = | ||
!editorData.mapSync | ||
? id === 'map' | ||
? 'zoom' | ||
: `${id}.zoom` | ||
: undefined; | ||
const { dependenciesMap = {} } = editorData; | ||
onChange('dependenciesMap', !editorData.mapSync && center && zoom !== undefined | ||
? { ...dependenciesMap, center, zoom } : | ||
omit(dependenciesMap, ['center', 'zoom'])); | ||
|
||
|
||
} | ||
}), | ||
withHandlers({ | ||
toggleConnection: ({ toggleConnection = () => { }, toggleDependencySelector = () => { }, widget, editorData = {} }) => | ||
(available = []) => available.length === 1 || editorData.mapSync | ||
? toggleConnection(widget, available[0]) | ||
: toggleDependencySelector() | ||
}) | ||
); |
36 changes: 36 additions & 0 deletions
36
web/client/plugins/widgetbuilder/enhancers/connection/withConnectButton.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,36 @@ | ||
/* | ||
* Copyright 2018, 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. | ||
*/ | ||
const { withProps, compose } = require('recompose'); | ||
/** | ||
* Returns an enhancer that add `stepButtons` for viewport connection to a wizard toolbar | ||
* @param {function} showCondition parses props to allow visualization of the buttons (if other connect condition are satisfied) | ||
*/ | ||
module.exports = (showCondition = () => true) => compose( | ||
withProps(({ | ||
stepButtons = [], | ||
toggleConnection = () => { }, | ||
availableDependencies = [], | ||
canConnect, | ||
connected, | ||
...props | ||
}) => ({ | ||
stepButtons: [{ | ||
onClick: () => toggleConnection(availableDependencies), | ||
disabled: availableDependencies.length > 1, // TODO: remove when support multi map | ||
visible: showCondition(props) && canConnect && availableDependencies.length > 0, | ||
bsStyle: connected ? "success" : "primary", | ||
glyph: connected ? "plug" : "unplug", | ||
tooltipId: connected | ||
? "widgets.builder.wizard.clearConnection" | ||
: availableDependencies.length === 1 | ||
? "widgets.builder.wizard.connectToTheMap" | ||
: "connection to multiple maps not supported yet" // TODO: "widgets.builder.wizard.connectToAMap" | ||
}, ...stepButtons | ||
] | ||
})) | ||
); |
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