Skip to content

Commit

Permalink
Use simpler separator for DateRange url param
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieldutra committed Sep 18, 2019
1 parent 6b09a84 commit 0374841
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 14 deletions.
15 changes: 7 additions & 8 deletions client/app/services/parameters/DateRangeParameter.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ class DateRangeParameter extends Parameter {
const prefix = this.urlPrefix;
if (isObject(this.value) && this.value.start && this.value.end) {
return {
[`${prefix}${this.name}`]: null,
[`${prefix}${this.name}.start`]: this.value.start,
[`${prefix}${this.name}.end`]: this.value.end,
[`${prefix}${this.name}`]: `${this.value.start}--${this.value.end}`,
};
}
return super.toUrlParams();
Expand All @@ -146,12 +144,13 @@ class DateRangeParameter extends Parameter {
fromUrlParams(query) {
const prefix = this.urlPrefix;
const key = `${prefix}${this.name}`;
const keyStart = `${prefix}${this.name}.start`;
const keyEnd = `${prefix}${this.name}.end`;
if (has(query, key)) {
this.setValue(query[key]);
} else if (has(query, keyStart) && has(query, keyEnd)) {
this.setValue([query[keyStart], query[keyEnd]]);
const dates = query[key].split('--');
if (dates.length === 2) {
this.setValue(dates);
} else {
this.setValue(query[key]);
}
}
}

Expand Down
2 changes: 0 additions & 2 deletions client/app/services/parameters/EnumParameter.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ class EnumParameter extends Parameter {

return {
[`${prefix}${this.name}`]: !this.isEmpty ? urlParam : null,
[`${prefix}${this.name}.start`]: null,
[`${prefix}${this.name}.end`]: null,
};
}

Expand Down
2 changes: 0 additions & 2 deletions client/app/services/parameters/Parameter.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ class Parameter {
// `null` removes the parameter from the URL in case it exists
return {
[`${prefix}${this.name}`]: !this.isEmpty ? this.value : null,
[`${prefix}${this.name}.start`]: null,
[`${prefix}${this.name}.end`]: null,
};
}

Expand Down
2 changes: 0 additions & 2 deletions client/app/services/parameters/QueryBasedDropdownParameter.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ class QueryBasedDropdownParameter extends Parameter {

return {
[`${prefix}${this.name}`]: !this.isEmpty ? urlParam : null,
[`${prefix}${this.name}.start`]: null,
[`${prefix}${this.name}.end`]: null,
};
}

Expand Down

0 comments on commit 0374841

Please sign in to comment.