-
Notifications
You must be signed in to change notification settings - Fork 44
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
PXD-1514 fix(explorer): use sqon to calculate actual number of selected items #346
Conversation
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.
The charts behave like I would expect - awesome! Just had some questions on the sqon
and things like that.
src/components/charts/helper.js
Outdated
if (!sqon || !sqon.content) return undefined; | ||
const sqonItems = sqon.content.filter(item => item.content.field === field); | ||
if (!sqonItems || sqonItems.length !== 1) return undefined; | ||
const sqonValues = sqonItems[0].content.value; |
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.
whats does grabbing the first index give us?
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.
It seems arranger use sqon
for filtering queries, sqon.content
stores all selected fields, and since this function only need one specific field, the sqonItems
should be always in length of 1 or zero: 1 means there are some values selected on this field, and zero means no values selected on this field (which means every values should be counted for this field in the visualizations)
src/components/charts/helper.js
Outdated
return sqonValues; | ||
}; | ||
|
||
const getSQONCount = (sqon, field) => { |
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.
this function is pretty much the same as the one above it, I don't think we need two
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.
getSQONCount
gets the count of selected values for given field
, and getSQONValues
gets the selected values for given field
src/components/charts/helper.js
Outdated
label, | ||
value: field.buckets.length, | ||
value: Math.min(field.buckets.length, sqonCount), |
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.
does grabbing the min of these two always give us the value we want?
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.
When there are no selected values in a given field
, this means all values should be counted, so here I think it would be easy to understand that we let sqonCount = Inifinity
. That's why here I use Math.min
. I can change it to a if...else
statement if you want.
src/components/charts/helper.js
Outdated
}); | ||
|
||
const getCharts = (data, arrangerConfig) => { | ||
const getSQONValues = (sqon, field) => { | ||
if (!sqon || !sqon.content) return undefined; |
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.
can we return something other than undefined
?
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.
Sure. We could discuss about return value for sqon=null
case. Do you think null
would be better?
src/components/charts/helper.test.js
Outdated
|
||
it('return selecetd values from SQON as expected', () => { | ||
expect(helper.getSQONValues(selectWhiteSqon, 'ethnicity')).toEqual(selectWhiteSqonValues); | ||
}); |
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.
I think we need some more tests. what if there is a filter with no values selected? does it return the length of the buckets or the sqon count? things like that.
* If no value selected, return null | ||
*/ | ||
const getSQONValues = (sqon, field) => { | ||
if (!sqon || !sqon.content) return null; |
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.
you could also return an empty array right? that might be easier so you wouldn't have to check for null values, but I'll leave that up to you, just a suggestion
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.
Thanks. I think returning an empty array will just be similar to returning null
so I still want to keep it 😛
sqonValues === null || sqonValues.includes(bucket.key)....
=>
sqonValues.length === 0 ? || sqonValues.includes(bucket.key)...
More test cases added~ Please have a check again~ Thanks! @abgeorge7 |
Current counts and charts in visualizations only shows bucket numbers in the filters, but we want the visualization result shows actual number of selected items in the filters. To solve this, we use
sqon
to calculate the correct numbers.