Skip to content

Commit

Permalink
#9901 - Disable the operator dropdown in Edit mode (#9903)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsuren1 committed Jan 23, 2024
1 parent 2985e23 commit a6f588a
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class AttributeFilter extends React.PureComponent {
const placeholder = getMessageById(this.context.messages, this.props.placeholderMsgId) || "Search";
let inputKey = 'header-filter-' + this.props.column.key;
let isValueExist = this.state?.value ?? this.props.value;
if (['date', 'time', 'date-time'].includes(this.props.type) && this.props.isWithinAttrTbl) isValueExist = this.state?.value ?? this.props.value?.startDate ?? this.props.value;
if (this.isDateTimeField() && this.props.isWithinAttrTbl) isValueExist = this.state?.value ?? this.props.value?.startDate ?? this.props.value;
let isNullOperator = this.state.operator === 'isNull';
return (<div className={`rw-widget ${this.state.isInputValid ? "" : "show-error"}`}>
<input
Expand All @@ -109,15 +109,16 @@ class AttributeFilter extends React.PureComponent {
renderOperatorField = () => {
return (
<ComboField
style={{ width: '90px'}}
style={{ width: 90 }}
fieldOptions= {this.getOperator(this.props.type)}
fieldName="operator"
fieldRowId={1}
disabled={this.props.disabled}
onSelect={(selectedOperator)=>{
// if select the same operator -> don't do anything
if (selectedOperator === this.state.operator) return;
let isValueExist; // entered value
if (['date', 'time', 'date-time'].includes(this.props.type)) {
if (this.isDateTimeField()) {
isValueExist = this.state?.value ?? this.props.value?.startDate ?? this.props.value;
} else {
isValueExist = this.state?.value ?? this.props.value;
Expand Down Expand Up @@ -147,11 +148,14 @@ class AttributeFilter extends React.PureComponent {
<div key={inputKey} className={`form-group${((this.state.isInputValid && this.props.valid) ? "" : " has-error")}`}>
{this.props.isWithinAttrTbl ? <>
{this.renderOperatorField()}
{['time', 'date', 'date-time'].includes(this.props.type) ? this.renderInput() : this.renderTooltip(this.renderInput())}
{this.isDateTimeField() ? this.renderInput() : this.renderTooltip(this.renderInput())}
</> : this.renderTooltip(this.renderInput())}
</div>
);
}
isDateTimeField = () => {
return ['date', 'time', 'date-time'].includes(this.props.type);
}
handleChange = (e) => {
const value = e.target.value;
// todo: validate input based on type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ describe('Test for AttributeFilter component', () => {
const operatorDropdownListEl = ReactTestUtils.findRenderedDOMComponentWithClass(cmp, 'rw-dropdownlist');
expect(operatorDropdownListEl).toExist();
});
it('test disable operator dropdown', () => {
const cmp = ReactDOM.render(<AttributeFilter disabled isWithinAttrTbl={"true"} value={"TEST"}/>, document.getElementById("container"));
const el = document.getElementsByClassName("form-control input-sm")[0];
expect(el).toExist();
const input = ReactTestUtils.findRenderedDOMComponentWithTag(cmp, "input");
expect(input.value).toBe("TEST");
expect(input.disabled).toBe(true);
});
it('test rendering without operator DD', () => {
const cmp = ReactDOM.render(<AttributeFilter isWithinAttrTbl={false} value={"TEST"}/>, document.getElementById("container"));
const el = document.getElementsByClassName("form-control input-sm")[0];
Expand Down
28 changes: 14 additions & 14 deletions web/client/components/data/featuregrid/filterRenderers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,39 @@ import NumberFilter from './NumberFilter';
import StringFilter from './StringFilter';

const types = {
"defaultFilter": (props) => withProps(() =>{
"defaultFilter": (props) => withProps(({disabled, tooltipMsgId: editTooltipMsgId}) =>{
let placeholderMsgId = props.isWithinAttrTbl ? "featuregrid.attributeFilter.placeholders.default" : '';
let tooltipMsgId = props.isWithinAttrTbl ? "featuregrid.attributeFilter.tooltips.default" : "";
let tooltipMsgId = props.isWithinAttrTbl ? disabled ? editTooltipMsgId : "featuregrid.attributeFilter.tooltips.default" : "";
return { type: props.type, isWithinAttrTbl: props.isWithinAttrTbl || false, placeholderMsgId, tooltipMsgId };
})(DefaultFilter),
"string": (props) => withProps(() =>{
"string": (props) => withProps(({disabled, tooltipMsgId: editTooltipMsgId}) =>{
let placeholderMsgId = props.isWithinAttrTbl ? "featuregrid.attributeFilter.placeholders.string" : '';
let tooltipMsgId = props.isWithinAttrTbl ? "featuregrid.attributeFilter.tooltips.string" : "";
let tooltipMsgId = props.isWithinAttrTbl ? disabled ? editTooltipMsgId : "featuregrid.attributeFilter.tooltips.string" : "";
return { type: 'string', isWithinAttrTbl: props.isWithinAttrTbl || false, placeholderMsgId, tooltipMsgId };
})(StringFilter),
"number": (props) => withProps(() =>{
"number": (props) => withProps(({disabled, tooltipMsgId: editTooltipMsgId}) =>{
let placeholderMsgId = props.isWithinAttrTbl ? "featuregrid.attributeFilter.placeholders.number" : '';
let tooltipMsgId = props.isWithinAttrTbl ? "featuregrid.attributeFilter.tooltips.number" : "";
let tooltipMsgId = props.isWithinAttrTbl ? disabled ? editTooltipMsgId : "featuregrid.attributeFilter.tooltips.number" : "";
return { type: 'number', isWithinAttrTbl: props.isWithinAttrTbl || false, placeholderMsgId, tooltipMsgId };
})(NumberFilter),
"int": (props) => withProps(() =>{
"int": (props) => withProps(({disabled, tooltipMsgId: editTooltipMsgId}) =>{
let placeholderMsgId = props.isWithinAttrTbl ? "featuregrid.attributeFilter.placeholders.number" : '';
let tooltipMsgId = props.isWithinAttrTbl ? "featuregrid.attributeFilter.tooltips.number" : "";
let tooltipMsgId = props.isWithinAttrTbl ? disabled ? editTooltipMsgId : "featuregrid.attributeFilter.tooltips.number" : "";
return { type: 'integer', isWithinAttrTbl: props.isWithinAttrTbl || false, placeholderMsgId, tooltipMsgId };
})(NumberFilter),
"date": (props) => withProps(() =>{
"date": (props) => withProps(({disabled, tooltipMsgId: editTooltipMsgId}) =>{
let placeholderMsgId = props.isWithinAttrTbl ? "featuregrid.attributeFilter.placeholders.date" : '';
let tooltipMsgId = props.isWithinAttrTbl ? "featuregrid.attributeFilter.tooltips.date" : "";
let tooltipMsgId = props.isWithinAttrTbl ? disabled ? editTooltipMsgId : "featuregrid.attributeFilter.tooltips.date" : "";
return { type: "date", isWithinAttrTbl: props.isWithinAttrTbl || false, placeholderMsgId, tooltipMsgId };
})(DateTimeFilter),
"time": (props) => withProps(() =>{
"time": (props) => withProps(({disabled, tooltipMsgId: editTooltipMsgId}) =>{
let placeholderMsgId = props.isWithinAttrTbl ? "featuregrid.attributeFilter.placeholders.date" : '';
let tooltipMsgId = props.isWithinAttrTbl ? "featuregrid.attributeFilter.tooltips.date" : "";
let tooltipMsgId = props.isWithinAttrTbl ? disabled ? editTooltipMsgId : "featuregrid.attributeFilter.tooltips.date" : "";
return { type: "time", isWithinAttrTbl: props.isWithinAttrTbl || false, placeholderMsgId, tooltipMsgId };
})(DateTimeFilter),
"date-time": (props) => withProps(() =>{
"date-time": (props) => withProps(({disabled, tooltipMsgId: editTooltipMsgId}) =>{
let placeholderMsgId = props.isWithinAttrTbl ? "featuregrid.attributeFilter.placeholders.date" : '';
let tooltipMsgId = props.isWithinAttrTbl ? "featuregrid.attributeFilter.tooltips.date" : "";
let tooltipMsgId = props.isWithinAttrTbl ? disabled ? editTooltipMsgId : "featuregrid.attributeFilter.tooltips.date" : "";
return { type: "date-time", isWithinAttrTbl: props.isWithinAttrTbl || false, placeholderMsgId, tooltipMsgId };
})(DateTimeFilter),
"geometry": () => GeometryFilter
Expand Down
19 changes: 11 additions & 8 deletions web/client/components/misc/datetimepicker/DateTimePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ class DateTimePicker extends Component {
toolTip: PropTypes.string,
tabIndex: PropTypes.string,
options: PropTypes.object,
isWithinAttrTbl: PropTypes.bool
isWithinAttrTbl: PropTypes.bool,
disabled: PropTypes.bool
}
static contextTypes = {
messages: PropTypes.object,
Expand Down Expand Up @@ -154,7 +155,7 @@ class DateTimePicker extends Component {
let inputV = this.props.isWithinAttrTbl ? `${inputValue}` : `${operator}${inputValue}`;
let isNullOperator = this.props.operator === 'isNull';
if (isNullOperator) inputV = '';
const inputEl = <input type="text" id="rw_1_input" role="combobox" onBlur={this.handleInputBlur} placeholder={placeholder} aria-expanded={calendarVisible || timeVisible} aria-haspopup="true" aria-busy="false" aria-owns="rw_1_cal rw_1_time_listbox" tabIndex={tabIndex} autoComplete="off" value={inputV} className={`rw-input ${className ? className : ''}`} onChange={this.handleValueChange} disabled={isNullOperator} />;
const inputEl = <input type="text" disabled={this.props.disabled || isNullOperator} id="rw_1_input" role="combobox" onBlur={this.handleInputBlur} placeholder={placeholder} aria-expanded={calendarVisible || timeVisible} aria-haspopup="true" aria-busy="false" aria-owns="rw_1_cal rw_1_time_listbox" tabIndex={tabIndex} autoComplete="off" value={inputV} className={`rw-input ${className ? className : ''}`} onChange={this.handleValueChange} />;
if (toolTip) {
return (<OverlayTrigger placement="top" overlay={<Tooltip id="tooltip">{toolTip}</Tooltip>}>
{inputEl}
Expand Down Expand Up @@ -196,15 +197,15 @@ class DateTimePicker extends Component {
</div>
}
>
<button tabIndex="-1" title="Select Date" type="button" aria-disabled="false" aria-label="Select Date" className="rw-btn-calendar rw-btn">
<button disabled={this.props.disabled} tabIndex="-1" title="Select Date" type="button" aria-disabled="false" aria-label="Select Date" className="rw-btn-calendar rw-btn">
<Glyphicon glyph={'date-time'} />
</button>
</Popover>
</span>
</div>);
} else if (type === 'time') {
return (
<div tabIndex="-1" onBlur={this.handleWidgetBlur} onKeyDown={this.handleKeyDown} className={`rw-datetimepicker rw-widget ${calendar && time ? 'rw-has-both' : ''} ${!calendar && !time ? 'rw-has-neither' : ''} ${type === 'time' ? 'time-type' : ''} ${focused ? 'rw-state-focus' : ''}`}>
<div tabIndex="-1" onBlur={this.handleWidgetBlur} onKeyDown={this.handleKeyDown} onFocus={this.handleWidgetFocus} className={`rw-datetimepicker rw-widget ${calendar && time ? 'rw-has-both' : ''} ${!calendar && !time ? 'rw-has-neither' : ''} ${type === 'time' ? 'time-type' : ''} ${focused ? 'rw-state-focus' : ''}`}>
{this.renderInput(inputValue, operator, timeVisible ? '' : toolTip, timePlaceholderMsgId, tabIndex, calendarVisible, timeVisible)}
<span className="rw-select">
<Popover
Expand All @@ -222,7 +223,7 @@ class DateTimePicker extends Component {
</div>
}
>
<button tabIndex="-1" title="Select Time" type="button" aria-disabled="false" aria-label="Select Time" className="rw-btn-time rw-btn" >
<button disabled={this.props.disabled} tabIndex="-1" title="Select Time" type="button" aria-disabled="false" aria-label="Select Time" className="rw-btn-time rw-btn" >
<span aria-hidden="true" className="rw-i rw-i-clock-o"></span>
</button>
</Popover>
Expand Down Expand Up @@ -253,7 +254,7 @@ class DateTimePicker extends Component {
</div>
}
>
<button tabIndex="-1" title="Select Date" type="button" aria-disabled="false" aria-label="Select Date" className="rw-btn-calendar rw-btn" >
<button disabled={this.props.disabled} tabIndex="-1" title="Select Date" type="button" aria-disabled="false" aria-label="Select Date" className="rw-btn-calendar rw-btn" >
<span aria-hidden="true" className="rw-i rw-i-calendar"></span>
</button>
</Popover>
Expand All @@ -269,8 +270,10 @@ class DateTimePicker extends Component {
ignoreBlur = false;

handleWidgetFocus = () => {
this.setState({ focused: true });
this.ignoreBlur = false;
if (!this.props.disabled) {
this.setState({ focused: true });
this.ignoreBlur = false;
}
}

handleWidgetBlur = (type) => {
Expand Down
19 changes: 11 additions & 8 deletions web/client/components/misc/datetimepicker/RangedDateTimePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ class DateTimePickerWithRange extends Component {
culture: PropTypes.string,
toolTip: PropTypes.string,
tabIndex: PropTypes.string,
options: PropTypes.object
options: PropTypes.object,
disabled: PropTypes.disabled
}

static defaultProps = {
Expand Down Expand Up @@ -123,7 +124,7 @@ class DateTimePickerWithRange extends Component {

renderInput = (inputValue, operator, toolTip, placeholder, tabIndex, calendarVisible, timeVisible, style = {}, className) => {
let inputV = this.props.isWithinAttrTbl ? `${inputValue}` : `${operator}${inputValue}`;
const inputEl = <input style={style} type="text" id="rw_1_input" disabled={'true'} role="combobox" placeholder={placeholder} aria-expanded={calendarVisible || timeVisible} aria-haspopup="true" aria-busy="false" aria-owns="rw_1_cal rw_1_time_listbox" tabIndex={tabIndex} autoComplete="off" value={inputV} className={`rw-input ${this.state.isInputNotValid ? 'has-error' : ''} ${className ? className : ''}`} onChange={this.handleValueChange} />;
const inputEl = <input style={style} disabled={this.props.disabled || true} type="text" id="rw_1_input" role="combobox" placeholder={placeholder} aria-expanded={calendarVisible || timeVisible} aria-haspopup="true" aria-busy="false" aria-owns="rw_1_cal rw_1_time_listbox" tabIndex={tabIndex} autoComplete="off" value={inputV} className={`rw-input ${this.state.isInputNotValid ? 'has-error' : ''} ${className ? className : ''}`} onChange={this.handleValueChange} />;
if (toolTip) {
return (<OverlayTrigger placement="top" overlay={<Tooltip id="tooltip">{toolTip}</Tooltip>}>
{inputEl}
Expand Down Expand Up @@ -196,7 +197,7 @@ class DateTimePickerWithRange extends Component {
</div>
}
>
<button tabIndex="-1" title="Select Date" type="button" aria-disabled="false" aria-label="Select Date" className="rw-btn-calendar rw-btn" onClick={this.toggleHandler}>
<button disabled={this.props.disabled} tabIndex="-1" title="Select Date" type="button" aria-disabled={this.props.disabled} aria-label="Select Date" className="rw-btn-calendar rw-btn" onClick={this.toggleHandler}>
<span aria-hidden="true" className="rw-i rw-i-clock-o"></span>
</button>
</Popover>
Expand Down Expand Up @@ -271,7 +272,7 @@ class DateTimePickerWithRange extends Component {
</div>
}
>
<button tabIndex="-1" title="Select Date" type="button" aria-disabled="false" aria-label="Select Date" className="rw-btn-calendar rw-btn" onClick={this.toggleHandler}>
<button disabled={this.props.disabled} tabIndex="-1" title="Select Date" type="button" aria-disabled={this.props.disabled} aria-label="Select Date" className="rw-btn-calendar rw-btn" onClick={this.toggleHandler}>
<span aria-hidden="true" className="rw-i rw-i-calendar"></span>
</button>
</Popover>
Expand Down Expand Up @@ -371,7 +372,7 @@ class DateTimePickerWithRange extends Component {
</div>
}
>
<button tabIndex="-1" title="Select Date" type="button" aria-disabled="false" aria-label="Select Date" className="rw-btn-calendar rw-btn" onClick={this.toggleHandler}>
<button disabled={this.props.disabled} tabIndex="-1" title="Select Date" type="button" aria-disabled={this.props.disabled} aria-label="Select Date" className="rw-btn-calendar rw-btn" onClick={this.toggleHandler}>
<Glyphicon glyph={'date-time'} />
</button>
</Popover>
Expand All @@ -392,8 +393,10 @@ class DateTimePickerWithRange extends Component {
ignoreBlur = false;

handleWidgetFocus = () => {
this.setState({ focused: true });
this.ignoreBlur = false;
if (!this.props.disabled) {
this.setState({ focused: true });
this.ignoreBlur = false;
}
}

handleWidgetBlur = (type) => {
Expand All @@ -402,7 +405,7 @@ class DateTimePickerWithRange extends Component {
}
if (type === 'date') {
this.calendarRef.click();
} else if (type === 'dat-time') {
} else if (type === 'date-time') {
this.dateTimeRef.click();
}
this.setState({ openRangeContainer: '', focused: false });
Expand Down
4 changes: 4 additions & 0 deletions web/client/themes/default/less/featuregrid.less
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
.feature-grid-drag-handle-show{
div.form-group{
display:flex;
margin-top: -4px;
div.rw-dropdownlist.rw-widget{
min-width:fit-content;
}
Expand All @@ -105,6 +106,9 @@
div.rw-widget div.rw-input{
padding-right: 0.5rem;
}
div.rw-widget .form-control{
border: none;
}
.range-time-input div.rw-calendar-popup.rw-popup-container{
left: -2.5rem;
overflow-x:hidden;
Expand Down
12 changes: 12 additions & 0 deletions web/client/themes/default/less/react-data-grid.less
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@
.color-var(@theme-vars[main-color]);
.background-color-var(@theme-vars[main-bg]);
}
.feature-grid-container {
.ms2-border-layout-body {
.react-grid-HeaderRow {
.react-grid-HeaderCell {
.rw-datetimepicker.rw-widget input:disabled,
.rw-datetimepicker.rw-widget .rw-select button:disabled {
.background-color-var(@theme-vars[disabled-bg], true);
}
}
}
}
}
}

// **************
Expand Down

0 comments on commit a6f588a

Please sign in to comment.