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

PXD-1514 fix(explorer): use sqon to calculate actual number of selected items #346

Merged
merged 3 commits into from
Aug 17, 2018

Conversation

qingyashu
Copy link
Contributor

@qingyashu qingyashu commented Aug 16, 2018

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.

@qingyashu qingyashu requested a review from abgeorge7 August 16, 2018 19:56
Copy link
Contributor

@abgeorge7 abgeorge7 left a 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.

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;
Copy link
Contributor

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?

Copy link
Contributor Author

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)

return sqonValues;
};

const getSQONCount = (sqon, field) => {
Copy link
Contributor

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

Copy link
Contributor Author

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

label,
value: field.buckets.length,
value: Math.min(field.buckets.length, sqonCount),
Copy link
Contributor

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?

Copy link
Contributor Author

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.

});

const getCharts = (data, arrangerConfig) => {
const getSQONValues = (sqon, field) => {
if (!sqon || !sqon.content) return undefined;
Copy link
Contributor

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?

Copy link
Contributor Author

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?


it('return selecetd values from SQON as expected', () => {
expect(helper.getSQONValues(selectWhiteSqon, 'ethnicity')).toEqual(selectWhiteSqonValues);
});
Copy link
Contributor

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;
Copy link
Contributor

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

Copy link
Contributor Author

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)...

@qingyashu
Copy link
Contributor Author

More test cases added~ Please have a check again~ Thanks! @abgeorge7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants