-
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.
- Loading branch information
1 parent
6549901
commit d54c857
Showing
35 changed files
with
911 additions
and
72 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
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
116 changes: 116 additions & 0 deletions
116
web/client/components/widgets/builder/wizard/CounterWizard.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,116 @@ | ||
/** | ||
* 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 {isNil} = require('lodash'); | ||
const { compose, lifecycle } = require('recompose'); | ||
|
||
const {wizardHandlers} = require('../../../misc/wizard/enhancers'); | ||
const loadingState = require('../../../misc/enhancers/loadingState')(({loading, data}) => loading || !data, {width: 500, height: 200}); | ||
|
||
const wfsChartOptions = require('./common/wfsChartOptions'); | ||
const CounterOptions = wfsChartOptions(require('./common/WPSWidgetOptions')); | ||
const WidgetOptions = require('./common/WidgetOptions'); | ||
|
||
const wpsCounter = require('../../enhancers/wpsCounter'); | ||
const dependenciesToFilter = require('../../enhancers/dependenciesToFilter'); | ||
const emptyChartState = require('../../enhancers/emptyChartState'); | ||
const errorChartState = require('../../enhancers/errorChartState'); | ||
|
||
const isCounterOptionsValid = (options = {}) => options.aggregateFunction && options.aggregationAttribute; | ||
const triggerSetValid = compose( | ||
lifecycle({ | ||
componentWillReceiveProps: ({ valid, data = [], options={}, setValid = () => { }, error } = {}) => { | ||
const isNowValid = !isNil(data[0]) && !error; | ||
if (!!valid !== !!isNowValid && isCounterOptionsValid(options)) { | ||
setValid(isNowValid); | ||
} | ||
} | ||
})); | ||
|
||
const enhanchePreview = compose( | ||
|
||
dependenciesToFilter, | ||
wpsCounter, | ||
triggerSetValid, | ||
loadingState, | ||
errorChartState, | ||
emptyChartState | ||
); | ||
|
||
const sampleProps = { | ||
width: 430, | ||
height: 200 | ||
}; | ||
|
||
const Wizard = wizardHandlers(require('../../../misc/wizard/WizardContainer')); | ||
|
||
|
||
const Counter = require('../../widget/CounterView'); | ||
const Preview = enhanchePreview(Counter); | ||
const CounterPreview = ({ data = {}, layer, dependencies = {}, valid, setValid = () => { } }) => | ||
!isCounterOptionsValid(data.options) | ||
? <Counter | ||
{...sampleProps} | ||
data={[{data: 42}]} | ||
options={data.options} | ||
series={[{dataKey: "data"}]} /> | ||
: <Preview | ||
{...sampleProps} | ||
valid={valid} | ||
dependencies={dependencies} | ||
setValid={setValid} | ||
type={data.type} | ||
legend={data.legend} | ||
layer={data.layer || layer} | ||
filter={data.filter} | ||
geomProp={data.geomProp} | ||
mapSync={data.mapSync} | ||
options={data.options} />; | ||
|
||
const enhanceWizard = compose(lifecycle({ | ||
componentWillReceiveProps: ({data = {}, valid, setValid = () => {}} = {}) => { | ||
if (valid && !isCounterOptionsValid(data.options)) { | ||
setValid(false); | ||
} | ||
}}) | ||
); | ||
module.exports = enhanceWizard(({ onChange = () => { }, onFinish = () => { }, setPage = () => { }, setValid = () => { }, valid, formOptions, data = {}, layer ={}, step=0, types, featureTypeProperties, dependencies}) => | ||
(<Wizard | ||
step={step} | ||
setPage={setPage} | ||
onFinish={onFinish} | ||
isStepValid={n => n === 1 ? isCounterOptionsValid(data.options) : true} hideButtons> | ||
<CounterOptions | ||
dependencies={dependencies} | ||
key="chart-options" | ||
formOptions={formOptions} | ||
featureTypeProperties={featureTypeProperties} | ||
types={types} | ||
data={data} | ||
onChange={onChange} | ||
layer={data.layer || layer} | ||
sampleChart={<CounterPreview | ||
data={data} | ||
valid={valid} | ||
layer={data.layer || layer} | ||
dependencies={dependencies} | ||
setValid={v => setValid(v && isCounterOptionsValid(data.options))} />} | ||
/> | ||
<WidgetOptions | ||
key="widget-options" | ||
data={data} | ||
onChange={onChange} | ||
layer={data.layer || layer} | ||
sampleChart={<CounterPreview | ||
data={data} | ||
valid={valid} | ||
layer={data.layer || layer} | ||
dependencies={dependencies} | ||
setValid={v => setValid(v && isCounterOptionsValid(data.options))} />} | ||
/> | ||
</Wizard>)); |
37 changes: 37 additions & 0 deletions
37
web/client/components/widgets/builder/wizard/__tests__/CounterWizard-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,37 @@ | ||
/* | ||
* Copyright 2017, 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 expect = require('expect'); | ||
const CounterWizard = require('../CounterWizard'); | ||
describe('CounterWizard component', () => { | ||
beforeEach((done) => { | ||
document.body.innerHTML = '<div id="container"></div>'; | ||
setTimeout(done); | ||
}); | ||
afterEach((done) => { | ||
ReactDOM.unmountComponentAtNode(document.getElementById("container")); | ||
document.body.innerHTML = ''; | ||
setTimeout(done); | ||
}); | ||
it('CounterWizard rendering with defaults', () => { | ||
ReactDOM.render(<CounterWizard />, document.getElementById("container")); | ||
const container = document.getElementById('container'); | ||
const el = container.querySelector('.ms-wizard'); | ||
expect(el).toExist(); | ||
expect(container.querySelector('.chart-options-form')).toExist(); | ||
}); | ||
it('CounterWizard rendering widget options', () => { | ||
ReactDOM.render(<CounterWizard step={1}/>, document.getElementById("container")); | ||
const container = document.getElementById('container'); | ||
const el = container.querySelector('.chart-options-form'); | ||
expect(el).toNotExist(); | ||
}); | ||
}); |
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
Oops, something went wrong.