-
Notifications
You must be signed in to change notification settings - Fork 20
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
Alleop - reviews and ratings to have separate from 1 to 5 starts #64
base: master
Are you sure you want to change the base?
Conversation
merge vtex into mine
Hi! I'm VTEX IO CI/CD Bot and I'll be helping you to publish your app! 🤖 Please select which version do you want to release:
And then you just need to merge your PR when you are ready! There is no need to create a release commit/tag.
|
Beep boop 🤖 I noticed you didn't make any changes at the
In order to keep track, I'll create an issue if you decide now is not a good time
|
import TotalReviewsByProductId4 from '../graphql/totalReviewsByProductId4.graphql' | ||
import TotalReviewsByProductId3 from '../graphql/totalReviewsByProductId3.graphql' | ||
import TotalReviewsByProductId2 from '../graphql/totalReviewsByProductId2.graphql' | ||
import TotalReviewsByProductId1 from '../graphql/totalReviewsByProductId1.graphql' |
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.
These data are not being used in this component. No need to change this file.
total4: 0, | ||
total3: 0, | ||
total2: 0, | ||
total1: 0, |
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.
These data are not being used in this component. No need to change this file.
@@ -0,0 +1,3 @@ | |||
query TotalReviewsByProductId1($productId: String!) { |
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.
No need to create new queries, just add a new field ratingHistogram
in ReviewsResult.
@@ -0,0 +1,3 @@ | |||
query TotalReviewsByProductId2($productId: String!) { |
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.
Same
@@ -0,0 +1,3 @@ | |||
query TotalReviewsByProductId5($productId: String!) { |
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.
Same
total2: number | ||
total1: number | ||
} | ||
|
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 remove all of these changes until this point.
@@ -508,29 +697,88 @@ function Reviews() { | |||
<FormattedMessage id="store/reviews.list.summary.loading" /> | |||
) : !state.total ? null : ( | |||
<Fragment> | |||
<div className={`${handles.starsContainer} t-heading-4`}> | |||
<Stars rating={state.average} /> | |||
<div> |
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.
Show only if a setting is turned on, otherwise this will be a breaking change.
|
||
FieldAsync<IntGraphType>( | ||
"totalReviewsByProductId4", | ||
arguments: new QueryArguments( | ||
new QueryArgument<NonNullGraphType<StringGraphType>> { Name = "productId", Description = "Product Id" } | ||
), | ||
resolve: async context => | ||
{ | ||
int count = 0; | ||
var searchResult = await productReviewService.GetReviewsByProductId(context.GetArgument<string>("productId")); | ||
|
||
if (searchResult != null && searchResult.Count > 0) | ||
{ | ||
for (int i = 0; i < searchResult.Count; i++) | ||
{ | ||
if (searchResult[i].Rating == 4) | ||
{ | ||
count++; | ||
} | ||
} | ||
} | ||
|
||
return count; | ||
} | ||
); | ||
|
||
FieldAsync<IntGraphType>( | ||
"totalReviewsByProductId3", | ||
arguments: new QueryArguments( | ||
new QueryArgument<NonNullGraphType<StringGraphType>> { Name = "productId", Description = "Product Id" } | ||
), | ||
resolve: async context => | ||
{ | ||
int count = 0; | ||
var searchResult = await productReviewService.GetReviewsByProductId(context.GetArgument<string>("productId")); | ||
|
||
if (searchResult != null && searchResult.Count > 0) | ||
{ | ||
for (int i = 0; i < searchResult.Count; i++) | ||
{ | ||
if (searchResult[i].Rating == 3) | ||
{ | ||
count++; | ||
} | ||
} | ||
} | ||
|
||
return count; | ||
} | ||
); | ||
|
||
FieldAsync<IntGraphType>( | ||
"totalReviewsByProductId2", | ||
arguments: new QueryArguments( | ||
new QueryArgument<NonNullGraphType<StringGraphType>> { Name = "productId", Description = "Product Id" } | ||
), | ||
resolve: async context => | ||
{ | ||
int count = 0; | ||
var searchResult = await productReviewService.GetReviewsByProductId(context.GetArgument<string>("productId")); | ||
|
||
if (searchResult != null && searchResult.Count > 0) | ||
{ | ||
for (int i = 0; i < searchResult.Count; i++) | ||
{ | ||
if (searchResult[i].Rating == 2) | ||
{ | ||
count++; | ||
} | ||
} | ||
} | ||
|
||
return count; | ||
} | ||
); | ||
|
||
FieldAsync<IntGraphType>( | ||
"totalReviewsByProductId1", | ||
arguments: new QueryArguments( | ||
new QueryArgument<NonNullGraphType<StringGraphType>> { Name = "productId", Description = "Product Id" } | ||
), | ||
resolve: async context => | ||
{ | ||
int count = 1; | ||
var searchResult = await productReviewService.GetReviewsByProductId(context.GetArgument<string>("productId")); | ||
|
||
if (searchResult != null && searchResult.Count > 0) | ||
{ | ||
for (int i = 0; i < searchResult.Count; i++) | ||
{ | ||
if (searchResult[i].Rating == 1) | ||
{ | ||
count++; | ||
} | ||
} | ||
} | ||
|
||
return count; | ||
} | ||
); |
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.
FieldAsync<IntGraphType>( | |
"totalReviewsByProductId5", | |
arguments: new QueryArguments( | |
new QueryArgument<NonNullGraphType<StringGraphType>> { Name = "productId", Description = "Product Id" } | |
), | |
resolve: async context => | |
{ | |
int count = 0; | |
var searchResult = await productReviewService.GetReviewsByProductId(context.GetArgument<string>("productId")); | |
if (searchResult != null && searchResult.Count > 0) | |
{ | |
for (int i = 0; i < searchResult.Count; i++) { | |
if (searchResult[i].Rating == 5) | |
{ | |
count++; | |
} | |
} | |
} | |
return count; | |
} | |
); | |
FieldAsync<IntGraphType>( | |
"totalReviewsByProductId4", | |
arguments: new QueryArguments( | |
new QueryArgument<NonNullGraphType<StringGraphType>> { Name = "productId", Description = "Product Id" } | |
), | |
resolve: async context => | |
{ | |
int count = 0; | |
var searchResult = await productReviewService.GetReviewsByProductId(context.GetArgument<string>("productId")); | |
if (searchResult != null && searchResult.Count > 0) | |
{ | |
for (int i = 0; i < searchResult.Count; i++) | |
{ | |
if (searchResult[i].Rating == 4) | |
{ | |
count++; | |
} | |
} | |
} | |
return count; | |
} | |
); | |
FieldAsync<IntGraphType>( | |
"totalReviewsByProductId3", | |
arguments: new QueryArguments( | |
new QueryArgument<NonNullGraphType<StringGraphType>> { Name = "productId", Description = "Product Id" } | |
), | |
resolve: async context => | |
{ | |
int count = 0; | |
var searchResult = await productReviewService.GetReviewsByProductId(context.GetArgument<string>("productId")); | |
if (searchResult != null && searchResult.Count > 0) | |
{ | |
for (int i = 0; i < searchResult.Count; i++) | |
{ | |
if (searchResult[i].Rating == 3) | |
{ | |
count++; | |
} | |
} | |
} | |
return count; | |
} | |
); | |
FieldAsync<IntGraphType>( | |
"totalReviewsByProductId2", | |
arguments: new QueryArguments( | |
new QueryArgument<NonNullGraphType<StringGraphType>> { Name = "productId", Description = "Product Id" } | |
), | |
resolve: async context => | |
{ | |
int count = 0; | |
var searchResult = await productReviewService.GetReviewsByProductId(context.GetArgument<string>("productId")); | |
if (searchResult != null && searchResult.Count > 0) | |
{ | |
for (int i = 0; i < searchResult.Count; i++) | |
{ | |
if (searchResult[i].Rating == 2) | |
{ | |
count++; | |
} | |
} | |
} | |
return count; | |
} | |
); | |
FieldAsync<IntGraphType>( | |
"totalReviewsByProductId1", | |
arguments: new QueryArguments( | |
new QueryArgument<NonNullGraphType<StringGraphType>> { Name = "productId", Description = "Product Id" } | |
), | |
resolve: async context => | |
{ | |
int count = 1; | |
var searchResult = await productReviewService.GetReviewsByProductId(context.GetArgument<string>("productId")); | |
if (searchResult != null && searchResult.Count > 0) | |
{ | |
for (int i = 0; i < searchResult.Count; i++) | |
{ | |
if (searchResult[i].Rating == 1) | |
{ | |
count++; | |
} | |
} | |
} | |
return count; | |
} | |
); |
Can remove those resolvers
totalReviewsByProductId5(productId: String!): Int @cacheControl(scope: PRIVATE) | ||
totalReviewsByProductId4(productId: String!): Int @cacheControl(scope: PRIVATE) | ||
totalReviewsByProductId3(productId: String!): Int @cacheControl(scope: PRIVATE) | ||
totalReviewsByProductId2(productId: String!): Int @cacheControl(scope: PRIVATE) | ||
totalReviewsByProductId1(productId: String!): Int @cacheControl(scope: PRIVATE) |
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.
We can remove those queries and just add the new field totals
to ReviewsResult
totalReviewsByProductId5(productId: String!): Int @cacheControl(scope: PRIVATE) | |
totalReviewsByProductId4(productId: String!): Int @cacheControl(scope: PRIVATE) | |
totalReviewsByProductId3(productId: String!): Int @cacheControl(scope: PRIVATE) | |
totalReviewsByProductId2(productId: String!): Int @cacheControl(scope: PRIVATE) | |
totalReviewsByProductId1(productId: String!): Int @cacheControl(scope: PRIVATE) |
Thanks for the PR! Left some comments! |
What problem is this solving?
In our project the client needs to show a breakdown from 1 to 5 the available stars and total.
How to test it?
https://alleop1--alleop.myvtex.com/silikonova-kupa-za-pukanki-kinghoff-kh-1258-p75504/p?__bindingAddress=alleop.bg/
Screenshots or example usage:
OLD DESIGN https://i.imgur.com/4sqAZ6B.png
NEW DESIGN https://i.imgur.com/uUSAKRt.png
Describe alternatives you've considered, if any.
I have no idea :)
Related to / Depends on
How does this PR make you feel? 🔗
![](put .gif link here - can be found under "advanced" on giphy)