Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#6758 Fixed default custom editors and FeatureEditor config in context #6836

Merged
merged 3 commits into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion web/client/plugins/FeatureEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 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 React, {useEffect} from 'react';
import {connect} from 'react-redux';
import {createSelector, createStructuredSelector} from 'reselect';
import {bindActionCreators} from 'redux';
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 (JSON.stringify(newOptions) !== JSON.stringify(oldOptions) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why stringify and not !isEqual or deepEqual from lodash?

Copy link
Member Author

@offtherailz offtherailz May 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll replace it with a deepEqual maybe be more robust and predictable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok :)

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