Skip to content

Commit

Permalink
force set value from field param
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaetanbrl committed Aug 30, 2024
1 parent 03efa6a commit 209d1eb
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 8 deletions.
8 changes: 8 additions & 0 deletions web/client/actions/featuregrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const LOAD_MORE_FEATURES = "LOAD_MORE_FEATURES";
export const GRID_QUERY_RESULT = 'FEATUREGRID:QUERY_RESULT';
export const SET_TIME_SYNC = "FEATUREGRID:SET_TIME_SYNC";
export const SET_PAGINATION = "FEATUREGRID:SET_PAGINATION";
export const GRID_ROW_UPDATE = "FEATUREGRID:GRID_ROW_UPDATE";

export function toggleShowAgain() {
return {
Expand Down Expand Up @@ -262,6 +263,13 @@ export function featureModified(features, updated) {
updated
};
}
export function gridRowUpdate(features, updated) {
return {
type: GRID_ROW_UPDATE,
features,
updated
};
}
export function createNewFeatures(features) {
return {
type: CREATE_NEW_FEATURE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class CellRenderer extends React.Component {
const isValid = isProperty ? this.context.isValid(this.props.rowData.get(this.props.column.key), this.props.column.key) : true;
const className = (isModified ? ['modified'] : [])
.concat(isValid ? [] : ['invalid']).join(" ");
console.log(this.props);
return <Cell {...this.props} ref="cell" className={className}/>;
}
}
Expand Down
18 changes: 16 additions & 2 deletions web/client/epics/featuregrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ import {
setPagination,
launchUpdateFilterFunc,
LAUNCH_UPDATE_FILTER_FUNC, SET_LAYER,
SET_VIEWPORT_FILTER, setViewportFilter
SET_VIEWPORT_FILTER, setViewportFilter,
GRID_ROW_UPDATE,
featureModified
} from '../actions/featuregrid';

import {
Expand Down Expand Up @@ -144,7 +146,8 @@ import {
getAttributeFilters,
selectedLayerSelector,
multiSelect,
paginationSelector, isViewportFilterActive, viewportFilter
paginationSelector, isViewportFilterActive, viewportFilter,
getLayerById
} from '../selectors/featuregrid';

import { error, warning } from '../actions/notifications';
Expand All @@ -169,6 +172,7 @@ import {dockPanelsSelector} from "../selectors/maplayout";
import {shutdownToolOnAnotherToolDrawing} from "../utils/ControlUtils";
import {mapTypeSelector} from "../selectors/maptype";
import { MapLibraries } from '../utils/MapTypeUtils';
import { userSelector } from '../selectors/security';

const setupDrawSupport = (state, original) => {
const defaultFeatureProj = getDefaultFeatureProjection();
Expand Down Expand Up @@ -902,6 +906,16 @@ export const onFeatureGridCreateNewFeature = (action$) => action$.ofType(CREATE_
.switchMap( () => {
return Rx.Observable.of(drawSupportReset());
});

export const handleFeatureChanges = (action$, store) => action$.ofType(CREATE_NEW_FEATURE, GRID_ROW_UPDATE)
.flatMap(({features, updated}) => {
const layer = getLayerById(store.getState(), selectedLayerIdSelector(store.getState()));
// force value from fields
layer.fields.filter(f => f.value && f.source).forEach(f => {
updated[f.name] = f.value;
});
return Rx.Observable.of(featureModified(features, updated));
});
/**
* control highlight support on view mode.
* @memberof epics.featuregrid
Expand Down
6 changes: 3 additions & 3 deletions web/client/plugins/featuregrid/gridEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import {
sort,
selectFeatures,
deselectFeatures,
featureModified,
updateFilter,
activateTemporaryChanges
activateTemporaryChanges,
gridRowUpdate
} from '../../actions/featuregrid';

const range = (start, end) => Array.from({length: (end + 1 - start)}, (v, k) => k + start);
Expand All @@ -17,7 +17,7 @@ export default {
let features = range(fromRow, toRow).map(r => rowGetter(r)).filter(f =>
Object.keys(updated || {}).filter(k => f.properties[k] !== updated[k]).length > 0
);
return featureModified(features, updated);
return gridRowUpdate(features, updated);
},
onRowsToggled: (rows, rowGetter) => selectFeatures(rows.map(r => rowGetter(r.rowIdx)), false),
onRowsSelected: (rows, rowGetter) => selectFeatures(rows.map(r => rowGetter(r.rowIdx)), true),
Expand Down
18 changes: 16 additions & 2 deletions web/client/plugins/tocitemssettings/tabs/Fields.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,32 @@ import LayerFields, {hasFields} from '../../../components/TOC/fragments/LayerFie
import {connect} from 'react-redux';
import { createStructuredSelector } from 'reselect';
import { currentLocaleSelector } from '../../../selectors/locale';
import { userSelector } from '../../../selectors/security';
import { find, get } from 'lodash';

export {hasFields};


export default connect(createStructuredSelector({
currentLocale: currentLocaleSelector
currentLocale: currentLocaleSelector,
userInfos: userSelector
}), {
updateLayerProperties: changeLayerProperties
}
)(({element = {}, updateLayerProperties = () => {}, ...props}) => {
)(({element = {}, updateLayerProperties = () => {}, userInfos, ...props}) => {
const layer = element;
const updateFields = (fields) => {
// insert fields value from selected user prop source
fields?.forEach?.((field) => {
if(field.source) {
field.value = get(userInfos,field.source) || find(userInfos.attribute, ["name", field.source])?.value
field.editable = false;
} else if(!field.source && field.value) {
field.value = null;
field.editable = null;
}
})
// update state
updateLayerProperties(layer.id, {fields});
};
return <LayerFields {...props} layer={layer} updateFields={updateFields}/>;
Expand Down

0 comments on commit 209d1eb

Please sign in to comment.