Skip to content

Commit

Permalink
force set value from field param, linter
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaetanbrl committed Oct 29, 2024
1 parent 069070d commit 8939de4
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 13 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
1 change: 0 additions & 1 deletion web/client/components/misc/AutocompleteCombobox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ const addStateHandlers = compose(
withStateHandlers((props) => ({
delayDebounce: 0,
performFetch: false,
disabled: false,
open: false,
openOnFocus: props.openOnFocus,
disabled: props.disabled,
Expand Down
17 changes: 15 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 Down Expand Up @@ -902,6 +905,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
5 changes: 1 addition & 4 deletions web/client/utils/FeatureGridUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,6 @@ export const featureTypeToGridColumns = (
getAttributeFields(describe).filter(e => !(columnSettings[e.name] && columnSettings[e.name].hide)).map((desc) => {
const option = options.find(o => o.name === desc.name);
const field = fields.find(f => f.name === desc.name);
if(field && field.name === "id_emprise") {
field.editable = false;
}
let columnProp = {
sortable,
key: desc.name,
Expand All @@ -147,7 +144,7 @@ export const featureTypeToGridColumns = (
headerRenderer: getHeaderRenderer(),
showTitleTooltip: !!option?.description,
resizable,
editable: field.editable === false ? false : editable,
editable: field?.editable === false ? false : editable,
filterable,
editor: getEditor(desc, field),
formatter: getFormatter(desc, field),
Expand Down

0 comments on commit 8939de4

Please sign in to comment.