Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#9706: Allow time range filtering for Attribute Table quick filter #9743

Merged
merged 19 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
7f3c2e7
#9706: handle the advanced filter in attribute table with different o…
mahmoudadel54 Nov 22, 2023
fc0f4c8
#9706: Allow time range filtering for Attribute Table quick filter an…
mahmoudadel54 Nov 23, 2023
5205513
Merge branch 'master' into feature_9706
mahmoudadel54 Nov 23, 2023
7edb767
#9706: fix test failure by remove unused variable
mahmoudadel54 Nov 23, 2023
2bec670
#9706: fix test failure by remove unused action in featuregrid file
mahmoudadel54 Nov 23, 2023
d8d1ae8
#9706: resolve review comments
mahmoudadel54 Dec 1, 2023
70e7e69
#9706: fix test case in AttributeFilter file
mahmoudadel54 Dec 1, 2023
083b971
Merge branch 'master' into feature_9706
mahmoudadel54 Dec 13, 2023
483af18
Merge branch 'master' into feature_9706
mahmoudadel54 Dec 15, 2023
c4f5640
#9706: Allow time range filtering for Attribute Table quick filter
mahmoudadel54 Dec 18, 2023
820517c
Merge branch 'feature_9706' of https://github.com/mahmoudadel54/MapSt…
mahmoudadel54 Dec 18, 2023
322d3d4
#9706: Allow time range filtering for Attribute Table quick filter
mahmoudadel54 Dec 18, 2023
e105916
#9706: resolve reviewer comments [improve UI of pickers]
mahmoudadel54 Jan 14, 2024
2960978
#9706: resolve reviewer comments
mahmoudadel54 Jan 16, 2024
ad64e56
#9706: resolve FE test failure
mahmoudadel54 Jan 16, 2024
ad2ff6f
#9706: resolve reviewer comments
mahmoudadel54 Jan 18, 2024
bd0c36f
#9706: hide input tooltip when user open pickers
mahmoudadel54 Jan 18, 2024
be42c15
Time filter refactor
dsuren1 Jan 22, 2024
170fd7c
unit test
dsuren1 Jan 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class AttributeFilter extends React.PureComponent {
booleanOperators: ["="],
defaultOperators: ["=", ">", "<", ">=", "<=", "<>", "isNull"],
timeDateOperators: ["=", ">", "<", ">=", "<=", "<>", "><", "isNull"],
operator: this.props.isWithinAttrTbl ? "=" : ""
operator: this.props.isWithinAttrTbl ? "=" : "",
isInputValid: true
};
}
getOperator = (type) => {
Expand Down Expand Up @@ -86,12 +87,12 @@ class AttributeFilter extends React.PureComponent {
let isValueExist = this.state?.value ?? this.props.value;
if (['date', 'time', 'date-time'].includes(this.props.type)) isValueExist = this.state?.value ?? this.props.value?.startDate ?? this.props.value;
let isNullOperator = this.state.operator === 'isNull';
return (<div className="rw-widget">
return (<div className={`rw-widget ${this.state.isInputValid ? "" : "show-error"}`}>
<input
disabled={this.props.disabled || isNullOperator}
key={inputKey}
type="text"
className="form-control input-sm"
className={"form-control input-sm"}
placeholder={placeholder}
value={isValueExist}
onChange={this.handleChange}/>
Expand All @@ -108,19 +109,33 @@ class AttributeFilter extends React.PureComponent {
renderOperatorField = () => {
return (
<ComboField
style={{ width: '30%'}}
// dropUp={this.props.dropUp}
style={{ width: '90px'}}
fieldOptions= {this.getOperator(this.props.type)}
fieldName="operator"
fieldRowId={1}
onSelect={(selectedOperator)=>{
// if select the same operator -> don't do anything
if (selectedOperator === this.state.operator) return;
let isValueExist = this.state?.value ?? this.props.value;
if (['date', 'time', 'date-time'].includes(this.props.type)) isValueExist = this.state?.value ?? this.props.value?.startDate ?? this.props.value;
this.setState({ operator: selectedOperator, value: selectedOperator === 'isNull' ? undefined : isValueExist });
let isValueExist; // entered value
if (['date', 'time', 'date-time'].includes(this.props.type)) {
isValueExist = this.state?.value ?? this.props.value?.startDate ?? this.props.value;
} else {
isValueExist = this.state?.value ?? this.props.value;
}
let isNullOperatorSelected = selectedOperator === 'isNull';
let isOperatorChangedFromIsNullAndValueNotExist = this.state.operator === 'isNull' && this.state.operator !== selectedOperator && !isValueExist;
if (isValueExist || isNullOperatorSelected || isOperatorChangedFromIsNullAndValueNotExist ) this.props.onChange({value: isNullOperatorSelected ? null : isValueExist, attribute: this.props.column && this.props.column.key, inputOperator: selectedOperator});
let isOperatorChangedFromRange = this.state.operator === '><';
// set the selected operator + value and reset the value in case of isNull
this.setState({ operator: selectedOperator, value: (isNullOperatorSelected || isOperatorChangedFromRange) ? undefined : isValueExist });
// get flag of being (operator was isNull then changes to other operator)
let isOperatorChangedFromIsNull = this.state.operator === 'isNull' && selectedOperator !== 'isNull';
// apply filter if value exists 'OR' operator = isNull 'OR' (prev operator was isNull and changes --> reset filter)
if (isNullOperatorSelected || isOperatorChangedFromIsNull || isOperatorChangedFromRange) {
// reset data --> operator = isNull 'OR' (prev operator was isNull and changes)
this.props.onChange({value: null, attribute: this.props.column && this.props.column.key, inputOperator: selectedOperator});
} else if (isValueExist) {
// apply filter --> if value exists
this.props.onChange({value: isValueExist, attribute: this.props.column && this.props.column.key, inputOperator: selectedOperator});
}
}}
fieldValue={this.state.operator}
onUpdateField={() => {}}/>
Expand All @@ -129,16 +144,23 @@ class AttributeFilter extends React.PureComponent {
render() {
let inputKey = 'header-filter--' + this.props.column.key;
return (
<div key={inputKey} className={`form-group${(this.props.valid ? "" : " has-error")}`}>
<div key={inputKey} className={`form-group${((this.state.isInputValid && this.props.valid) ? "" : " has-error")}`}>
{this.props.isWithinAttrTbl ? this.renderOperatorField() : null}
{this.renderTooltip(this.renderInput())}
</div>
);
}
handleChange = (e) => {
const value = e.target.value;
this.setState({value});
this.props.onChange({value, attribute: this.props.column && this.props.column.key, inputOperator: this.state.operator});
// todo: validate input based on type
let isValid = true;
const match = /\s*(!==|!=|<>|<=|>=|===|==|=|<|>)?(.*)/.exec(value);
if (match[1]) isValid = false;
if (match[2]) {
if (['integer', 'number'].includes(this.props.type) && isNaN(match[2])) isValid = false;
}
this.setState({value, isInputValid: isValid});
if (isValid) this.props.onChange({value, attribute: this.props.column && this.props.column.key, inputOperator: this.state.operator});
mahmoudadel54 marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@ const EXPRESSION_TESTS = [
[" ", "=", undefined],
["ZZZ", "=", undefined]
];
const testExpression = (spyonChange, spyonValueChange, rawValue, expectedOperator, expectedValue) => {
const testExpression = (spyonChange, spyonValueChange, rawValue, expectedOperator, expectedValue, index) => {
const input = document.getElementsByTagName("input")[0];
input.value = rawValue;
ReactTestUtils.Simulate.change(input);
const args = spyonChange.calls[spyonChange.calls.length - 1].arguments[0];
const valueArgs = spyonValueChange.calls[spyonValueChange.calls.length - 1].arguments[0];
expect(args.value).toBe(expectedValue);
expect(args.operator).toBe(expectedOperator);
expect(valueArgs).toBe(rawValue);
const args = spyonChange.calls[index]?.arguments[0];
const valueArgs = spyonValueChange.calls[index]?.arguments[0];
if (valueArgs) { // in case of invalid number expression it will be undefined
expect(args.value).toBe(expectedValue);
expect(args.operator).toBe(expectedOperator);
expect(valueArgs).toBe(rawValue);
}
};

describe('Test for NumberFilter component', () => {
Expand Down Expand Up @@ -75,7 +77,7 @@ describe('Test for NumberFilter component', () => {
ReactDOM.render(<NumberFilter onChange={actions.onChange} />, document.getElementById("container"));

const input = document.getElementsByTagName("input")[0];
input.value = "> 2";
input.value = "2";
ReactTestUtils.Simulate.change(input);
expect(spyonChange).toHaveBeenCalled();
});
Expand Down Expand Up @@ -115,6 +117,6 @@ describe('Test for NumberFilter component', () => {
const spyonChange = expect.spyOn(actions, 'onChange');
const spyonValueChange = expect.spyOn(actions, 'onValueChange');
ReactDOM.render(<NumberFilter onChange={actions.onChange} onValueChange={actions.onValueChange} />, document.getElementById("container"));
EXPRESSION_TESTS.map( params => testExpression(spyonChange, spyonValueChange, ...params));
EXPRESSION_TESTS.map( (params, index) => testExpression(spyonChange, spyonValueChange, ...params, index));
});
});
Loading
Loading