-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Introduce inheritance to the Parameter structure #4049
Merged
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
c81f46e
Start draft for new Parameter structure
gabrieldutra 20a2f83
Add the rest of the methods
gabrieldutra 5c7e745
EnumParameter
gabrieldutra a05d4b2
QueryBasedDropdownParameter
gabrieldutra 3c52dcb
DateParameter
gabrieldutra db009df
DateRangeParameter
gabrieldutra 8cccf8b
Update Parameter usage on code
gabrieldutra a1a3421
Merge dynamicValue into normalizedValue
gabrieldutra 6b98f3d
Merge branch 'master' into parameters-structure
gabrieldutra 622240d
Add updateLocals and omit unwanted props
gabrieldutra 5dcacbe
Allow null NumberParameter and omit parentQueryId
gabrieldutra f7a382b
Merge branch 'master' into parameters-structure
gabrieldutra 3279e88
Rename parameter getValue to getExecutionValue
gabrieldutra c4c0418
Update $$value to normalizedValue + omit on save
gabrieldutra bd09b34
Merge branch 'master' into parameters-structure
gabrieldutra a6df8b3
Add a few comments
gabrieldutra 8e0a684
Remove ngModel property from Parameter
gabrieldutra 6b09a84
Use value directly in DateRangeParameter
gabrieldutra 0374841
Use simpler separator for DateRange url param
gabrieldutra 0e5782e
Add backward compatibility
gabrieldutra 3718047
Merge branch 'master' into parameters-structure
gabrieldutra b63b584
Merge branch 'master' into parameters-structure
gabrieldutra da7255e
Use normalizeValue null value for isEmpty
gabrieldutra 927783d
Start creating jest tests
gabrieldutra 3a3c08f
Add more tests
gabrieldutra b970fb0
Merge branch 'master' into parameters-structure
gabrieldutra 567536d
Merge branch 'master' into parameters-structure
gabrieldutra d269a38
Normalize null value for multi mode in Enum
gabrieldutra 82c1104
Use saved value for param isEmpty
gabrieldutra 56268b3
Merge branch 'master' into parameters-structure
arikfr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { toNumber } from 'lodash'; | ||
import { Parameter } from '.'; | ||
|
||
class NumberParameter extends Parameter { | ||
constructor(parameter, parentQueryId) { | ||
super(parameter, parentQueryId); | ||
this.setValue(parameter.value); | ||
} | ||
|
||
getValue() { | ||
const value = toNumber(this.value); | ||
return !isNaN(value) ? value : null; | ||
} | ||
} | ||
|
||
export default NumberParameter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { isNull, isObject, isFunction, has } from 'lodash'; | ||
import { TextParameter, NumberParameter } from '.'; | ||
|
||
class Parameter { | ||
constructor(parameter, parentQueryId) { | ||
this.title = parameter.title; | ||
this.name = parameter.name; | ||
this.type = parameter.type; | ||
this.global = parameter.global; // backward compatibility in Widget service | ||
this.parentQueryId = parentQueryId; | ||
|
||
// Used for meta-parameters (i.e. dashboard-level params) | ||
this.locals = []; | ||
|
||
// Used for URL serialization | ||
Object.defineProperty(this, 'urlPrefix', { | ||
configurable: true, | ||
enumerable: false, // don't save it | ||
writable: true, | ||
value: 'p_', | ||
}); | ||
} | ||
|
||
static create(param) { | ||
switch (param.type) { | ||
case 'text': | ||
return new TextParameter(param); | ||
case 'number': | ||
return new NumberParameter(param); | ||
default: | ||
return null; | ||
} | ||
} | ||
ranbena marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
static getValue(param, extra = {}) { | ||
if (!isObject(param) || !isFunction(param.getValue)) { | ||
return null; | ||
} | ||
|
||
return param.getValue(extra); | ||
} | ||
|
||
static setValue(param, value) { | ||
if (!isObject(param) || !isFunction(param.setValue)) { | ||
return null; | ||
} | ||
|
||
return param.setValue(value); | ||
} | ||
|
||
get isEmpty() { | ||
return isNull(this.getValue()); | ||
} | ||
|
||
clone() { | ||
return Parameter.create(this); | ||
} | ||
|
||
toUrlParams() { | ||
const prefix = this.urlPrefix; | ||
return { | ||
[`${prefix}${this.name}`]: !this.isEmpty ? this.value : null, | ||
[`${prefix}${this.name}.start`]: null, | ||
[`${prefix}${this.name}.end`]: null, | ||
}; | ||
} | ||
|
||
fromUrlParams(query) { | ||
const prefix = this.urlPrefix; | ||
const key = `${prefix}${this.name}`; | ||
if (has(query, key)) { | ||
this.setValue(query[key]); | ||
} | ||
} | ||
} | ||
|
||
export default Parameter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { toString, isEmpty } from 'lodash'; | ||
import { Parameter } from '.'; | ||
|
||
class TextParameter extends Parameter { | ||
constructor(parameter, parentQueryId) { | ||
super(parameter, parentQueryId); | ||
this.setValue(parameter.value); | ||
} | ||
|
||
getValue() { | ||
const value = toString(this.value); | ||
return !isEmpty(value) ? value : null; | ||
} | ||
} | ||
gabrieldutra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggesting addition: isEmptyValue(value) {
return !trim(value);
} |
||
export default TextParameter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { default as Parameter } from './Parameter'; | ||
export { default as TextParameter } from './TextParameter'; | ||
export { default as NumberParameter } from './NumberParameter'; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As Cypress pointed out, this doesn't work with inheritance 🙂