Skip to content

Commit

Permalink
geosolutions-it#6758 Fixed default custom editors and FeatureEditor c…
Browse files Browse the repository at this point in the history
…onfig in context (geosolutions-it#6836)
  • Loading branch information
offtherailz authored and agpenton committed Jul 8, 2021
1 parent 03b5c38 commit 9bdfc00
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
12 changes: 11 additions & 1 deletion web/client/plugins/FeatureEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React from 'react';
import {connect} from 'react-redux';
import {createSelector, createStructuredSelector} from 'reselect';
import {bindActionCreators} from 'redux';
import { get, pick } from 'lodash';
import { get, pick, isEqual } from 'lodash';
import {compose, lifecycle} from 'recompose';
import ReactDock from 'react-dock';

Expand Down Expand Up @@ -269,6 +269,16 @@ const EditorPlugin = compose(
componentDidMount() {
// only the passed properties will be picked
this.props.onMount(pick(this.props, ['showFilteredObject', 'showTimeSync', 'timeSync', 'customEditorsOptions']));
},
// TODO: fix this in contexts
// due to multiple renders of plugins in contexts (one with default props, then with context props)
// the options have to be updated when change.
componentDidUpdate(oldProps) {
const newOptions = pick(this.props, ['showFilteredObject', 'showTimeSync', 'timeSync', 'customEditorsOptions']);
const oldOptions = pick(oldProps, ['showFilteredObject', 'showTimeSync', 'timeSync', 'customEditorsOptions']);
if (!isEqual(newOptions, oldOptions) ) {
this.props.onMount(newOptions);
}
}
}),
connect(selector,
Expand Down
3 changes: 2 additions & 1 deletion web/client/utils/featuregrid/EditorRegistry.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

const find = require('lodash/find');
const assign = require('object-assign');
let Editors = assign({}, require('../../components/data/featuregrid/editors/customEditors'));
let Editors = assign({}, require('../../components/data/featuregrid/editors/customEditors').default);

const isPresent = (editorName) => {
return Object.keys(Editors).indexOf(editorName) !== -1;
Expand All @@ -35,6 +35,7 @@ const getEditor = (type, name, props) => {
};
module.exports = {
get: () => Editors,
set: (e) => {Editors = e;},
register: ({name, editors}) => {
if (!!editors) {
Editors[name] = editors;
Expand Down
28 changes: 19 additions & 9 deletions web/client/utils/featuregrid/__tests__/EditorRegistry-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
const ReactDOM = require('react-dom');
const React = require('react');
const expect = require('expect');
const DropDownEditor = require('../../../components/data/featuregrid/editors/DropDownEditor');
import ReactDOM from 'react-dom';
import React from 'react';
import expect from 'expect';
import DropDownEditor from '../../../components/data/featuregrid/editors/DropDownEditor';

const assign = require('object-assign');
const {
import assign from 'object-assign';
import {
register,
clean,
get,
set,
getCustomEditor,
remove
} = require('../EditorRegistry');
} from '../EditorRegistry';
const attribute = "STATE_NAME";
const url = "https://demo.geo-solutions.it/geoserver/wfs";
const typeName = "topp:states";
Expand All @@ -31,22 +32,31 @@ const rules = [{
"forceSelection": true
}
}];
const Editor = require('../../../components/data/featuregrid/editors/AttributeEditor');
const NumberEditor = require('../../../components/data/featuregrid/editors/NumberEditor');
import Editor from '../../../components/data/featuregrid/editors/AttributeEditor';
import NumberEditor from '../../../components/data/featuregrid/editors/NumberEditor';
const testEditors = {
"defaultEditor": (props) => <Editor {...props}/>,
"string": (props) => <DropDownEditor dataType="string" {...props}/>,
"int": (props) => <NumberEditor dataType="int" inputProps={{step: 1, type: "number"}} {...props}/>,
"number": (props) => <NumberEditor dataType="number" inputProps={{step: 1, type: "number"}} {...props}/>
};
describe('EditorRegistry tests ', () => {
let original;
beforeEach(() => {
original = get();
document.body.innerHTML = '<div id="container"></div>';
clean();
});
afterEach(() => {
ReactDOM.unmountComponentAtNode(document.getElementById("container"));
document.body.innerHTML = '';
set(original);
});
it('check custom editors by default', () => {
["DropDownEditor", "NumberEditor", "FormatEditor"].map((v) => {
expect(original[v]).toBeTruthy();
expect(Object.keys(original[v].length > 0)).toBeTruthy();
});
});
it('clean', () => {
let Editors = get();
Expand Down

0 comments on commit 9bdfc00

Please sign in to comment.