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

Alleop - reviews and ratings to have separate from 1 to 5 starts #64

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

dmitriyzhuk
Copy link

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)

@dmitriyzhuk dmitriyzhuk requested review from a team as code owners March 12, 2021 12:17
@vtex-io-ci-cd
Copy link

vtex-io-ci-cd bot commented Mar 12, 2021

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:

  • Patch (backwards-compatible bug fixes)

  • Minor (backwards-compatible functionality)

  • Major (incompatible API changes)

And then you just need to merge your PR when you are ready! There is no need to create a release commit/tag.

  • No thanks, I would rather do it manually 😞

@vtex-io-docs-bot
Copy link

Beep boop 🤖

I noticed you didn't make any changes at the docs/ folder

  • There's nothing new to document 🤔
  • I'll do it later 😞

In order to keep track, I'll create an issue if you decide now is not a good time

  • I just updated 🎉🎉

import TotalReviewsByProductId4 from '../graphql/totalReviewsByProductId4.graphql'
import TotalReviewsByProductId3 from '../graphql/totalReviewsByProductId3.graphql'
import TotalReviewsByProductId2 from '../graphql/totalReviewsByProductId2.graphql'
import TotalReviewsByProductId1 from '../graphql/totalReviewsByProductId1.graphql'
Copy link
Contributor

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

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!) {
Copy link
Contributor

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!) {
Copy link
Contributor

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!) {
Copy link
Contributor

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
}

Copy link
Contributor

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

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.

Comment on lines +197 to +319

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Comment on lines +83 to +87
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)
Copy link
Contributor

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

Suggested change
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)

@klzns
Copy link
Contributor

klzns commented Mar 12, 2021

Thanks for the PR! Left some comments!

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