Skip to content

Commit

Permalink
disabled no editable field
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaetanbrl committed Oct 29, 2024
1 parent 8e2d443 commit 069070d
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class AutocompleteEditor extends AttributeEditor {
autocompleteStreamFactory: PropTypes.func,
url: PropTypes.string,
typeName: PropTypes.string,
value: PropTypes.string
value: PropTypes.string,
disabled: PropTypes.bool
};
static defaultProps = {
isValid: () => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class DateTimeEditor extends AttributeEditor {
calendar: PropTypes.bool,
time: PropTypes.bool,
onChange: PropTypes.func,
onBlur: PropTypes.func
onBlur: PropTypes.func,
disabled: PropTypes.bool
};

static contextTypes = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class DropDownEditor extends AttributeEditor {
filter: PropTypes.string,
values: PropTypes.array,
labels: PropTypes.array,
emptyValue: PropTypes.string
emptyValue: PropTypes.string,
disabled: PropTypes.bool
};
static defaultProps = {
isValid: () => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export default class FormatEditor extends React.Component {
dataType: PropTypes.string,
column: PropTypes.object,
formatRegex: PropTypes.string,
onTemporaryChanges: PropTypes.func
onTemporaryChanges: PropTypes.func,
disabled: PropTypes.bool
};

static defaultProps = {
Expand Down Expand Up @@ -61,6 +62,7 @@ export default class FormatEditor extends React.Component {
render() {
return (<input
{...this.props.inputProps}
disabled={this.props?.disabled}
style={!this.state.validated || this.state.isValid ? {} : {
borderColor: 'red'
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export default class NumberEditor extends React.Component {
minValue: PropTypes.number,
maxValue: PropTypes.number,
column: PropTypes.object,
onTemporaryChanges: PropTypes.func
onTemporaryChanges: PropTypes.func,
disabled: PropTypes.bool
};

static defaultProps = {
Expand Down Expand Up @@ -80,6 +81,7 @@ export default class NumberEditor extends React.Component {
render() {
return (<IntlNumberFormControl
{...this.props.inputProps}
disabled={this.props?.disabled}
style={!this.state.validated || this.state.isValid ? {} : {
borderColor: 'red'
}}
Expand Down
8 changes: 5 additions & 3 deletions web/client/components/data/featuregrid/enhancers/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,13 @@ const featuresToGrid = compose(
options: props.options?.propertyName
}, {
getHeaderRenderer,
getEditor: (desc) => {
getEditor: (desc, field) => {
const generalProps = {
onTemporaryChanges: props.gridEvents && props.gridEvents.onTemporaryChanges,
autocompleteEnabled: props.autocompleteEnabled,
url: props.url,
typeName: props.typeName
typeName: props.typeName,
disabled: field && field?.editable === false
};
const regexProps = {attribute: desc.name, url: props.url, typeName: props.typeName};
const rules = props.customEditorsOptions && props.customEditorsOptions.rules || [];
Expand All @@ -169,7 +170,8 @@ const featuresToGrid = compose(
if (!isNil(editor)) {
return editor;
}
return props.editors(desc.localType, generalProps);
const typeEditor = props.editors(desc.localType, generalProps);
return typeEditor;
},
getFilterRenderer: getFilterRendererFunc,
getFormatter: (desc) => getFormatter(desc, (props.fields ?? []).find(f => f.name === desc.name)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ 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
9 changes: 6 additions & 3 deletions web/client/components/misc/AutocompleteCombobox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,33 @@ const streamEnhancer = mapPropsStream(props$ => {
busy: data.busy,
dropUp: props.dropUp,
attribute: props.column && props.column.key,
changeAttribute: props.changeAttribute
changeAttribute: props.changeAttribute,
disabled: props.disabled
}));
});

// component enhanced with props from stream, and local state
const PagedComboboxEnhanced = streamEnhancer(
({ open, toggle, select, focus, change, value, valuesCount,
loadNextPage, loadPrevPage, maxFeatures, currentPage,
busy, data, loading = false, dropUp = false, attribute, changeAttribute}) => {
busy, data, loading = false, dropUp = false, attribute, changeAttribute, disabled = false}) => {
const numberOfPages = Math.ceil(valuesCount / maxFeatures);
return (<PagedCombobox
pagination={{firstPage: currentPage === 1, lastPage: currentPage === numberOfPages, paginated: true, loadPrevPage, loadNextPage}}
busy={busy} dropUp={dropUp} data={data} attribute={attribute} open={open}
onFocus={focus} onToggle={toggle} onChange={change} onSelect={select} onChangeAttribute={changeAttribute}
selectedValue={value} loading={loading}/>);
selectedValue={value} loading={loading} disabled={disabled}/>);
});

// state enhancer for local props
const addStateHandlers = compose(
withStateHandlers((props) => ({
delayDebounce: 0,
performFetch: false,
disabled: false,
open: false,
openOnFocus: props.openOnFocus,
disabled: props.disabled,
currentPage: 1,
maxFeatures: 5,
url: props.url,
Expand Down
3 changes: 2 additions & 1 deletion web/client/components/misc/combobox/ControlledCombobox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import PagedCombobox from './PagedCombobox';
// state enhancer for local props
import addState from './addState';

const ControlledCombobox = addState(({ toggle, select, focus, change, value, busy, data, loading = false, filter, open }) => {
const ControlledCombobox = addState(({ toggle, select, focus, change, value, busy, data, loading = false, filter, open, disabled }) => {
return (<PagedCombobox
pagination={{paginated: false}}
onFocus={focus}
Expand All @@ -27,6 +27,7 @@ const ControlledCombobox = addState(({ toggle, select, focus, change, value, bus
open={open}
loading={loading}
filter={filter}
disabled={disabled}
/>);
});

Expand Down
5 changes: 4 additions & 1 deletion web/client/utils/FeatureGridUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ 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 @@ -144,7 +147,7 @@ export const featureTypeToGridColumns = (
headerRenderer: getHeaderRenderer(),
showTitleTooltip: !!option?.description,
resizable,
editable,
editable: field.editable === false ? false : editable,
filterable,
editor: getEditor(desc, field),
formatter: getFormatter(desc, field),
Expand Down

0 comments on commit 069070d

Please sign in to comment.