From 8939de460a8b0d3c9dde75d57bc12f4ef38bf346 Mon Sep 17 00:00:00 2001 From: gaetanbrl Date: Thu, 29 Aug 2024 17:20:56 +0200 Subject: [PATCH] force set value from field param, linter --- web/client/actions/featuregrid.js | 8 ++++++++ .../featuregrid/renderers/CellRenderer.jsx | 1 - .../components/misc/AutocompleteCombobox.jsx | 1 - web/client/epics/featuregrid.js | 17 +++++++++++++++-- web/client/plugins/featuregrid/gridEvents.js | 6 +++--- .../plugins/tocitemssettings/tabs/Fields.jsx | 18 ++++++++++++++++-- web/client/utils/FeatureGridUtils.js | 5 +---- 7 files changed, 43 insertions(+), 13 deletions(-) diff --git a/web/client/actions/featuregrid.js b/web/client/actions/featuregrid.js index ec62c14b6c..6eb7bddcd2 100644 --- a/web/client/actions/featuregrid.js +++ b/web/client/actions/featuregrid.js @@ -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 { @@ -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, diff --git a/web/client/components/data/featuregrid/renderers/CellRenderer.jsx b/web/client/components/data/featuregrid/renderers/CellRenderer.jsx index d517942656..d8157f745c 100644 --- a/web/client/components/data/featuregrid/renderers/CellRenderer.jsx +++ b/web/client/components/data/featuregrid/renderers/CellRenderer.jsx @@ -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 ; } } diff --git a/web/client/components/misc/AutocompleteCombobox.jsx b/web/client/components/misc/AutocompleteCombobox.jsx index eeaefc23bc..d6fa9608f9 100644 --- a/web/client/components/misc/AutocompleteCombobox.jsx +++ b/web/client/components/misc/AutocompleteCombobox.jsx @@ -61,7 +61,6 @@ const addStateHandlers = compose( withStateHandlers((props) => ({ delayDebounce: 0, performFetch: false, - disabled: false, open: false, openOnFocus: props.openOnFocus, disabled: props.disabled, diff --git a/web/client/epics/featuregrid.js b/web/client/epics/featuregrid.js index 16b9a27a94..f7b0f79483 100644 --- a/web/client/epics/featuregrid.js +++ b/web/client/epics/featuregrid.js @@ -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 { @@ -144,7 +146,8 @@ import { getAttributeFilters, selectedLayerSelector, multiSelect, - paginationSelector, isViewportFilterActive, viewportFilter + paginationSelector, isViewportFilterActive, viewportFilter, + getLayerById } from '../selectors/featuregrid'; import { error, warning } from '../actions/notifications'; @@ -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 diff --git a/web/client/plugins/featuregrid/gridEvents.js b/web/client/plugins/featuregrid/gridEvents.js index b4ae578953..0d5a9b3f2c 100644 --- a/web/client/plugins/featuregrid/gridEvents.js +++ b/web/client/plugins/featuregrid/gridEvents.js @@ -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); @@ -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), diff --git a/web/client/plugins/tocitemssettings/tabs/Fields.jsx b/web/client/plugins/tocitemssettings/tabs/Fields.jsx index 0a7c02ef95..1e4ecf578b 100644 --- a/web/client/plugins/tocitemssettings/tabs/Fields.jsx +++ b/web/client/plugins/tocitemssettings/tabs/Fields.jsx @@ -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 ; diff --git a/web/client/utils/FeatureGridUtils.js b/web/client/utils/FeatureGridUtils.js index 0af95d50ec..c8bd40eaf7 100644 --- a/web/client/utils/FeatureGridUtils.js +++ b/web/client/utils/FeatureGridUtils.js @@ -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, @@ -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),