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

feat: Add a featured sort option for CatalogItems and paginate #4980

Merged
merged 92 commits into from
Mar 19, 2019

Conversation

machikoyasuda
Copy link
Contributor

@machikoyasuda machikoyasuda commented Feb 11, 2019

closes #4983
closes #5004

Currently, the catalogItems query returns a tag's products in order by newest products first. Now that the operator tag management tool is finished and deployed, a developer should be able to query for a tag's catalogItems in the order set in a tag. This ticket modifies the query to add a featured as a sorting option, and also makes featured the default option.

Technical specs

  • adds a featured to CatalogItemSortByField
  • adds a catalogItemsAggregate() method to the catalogItems() resolver that returns catalogItems in the order of its tag's featuredProductIds, passed through to getPaginatedAggregateResponse
  • fixes getPaginatedAggregateResponse() and applyPaginationToMongoAggregation() to so that catalogItems and productsByTagId queries paginate correctly
  • adds integration specs ✨ for catalogItems query
  • adds integration specs ✨ for productsByTagId query

Test cases:

  • Test tag with fewer than 20 products
  • Test tag with more than 20 products, on first page
  • Test tag with more than 20 products, on middle pages
  • Test tag with more than 20 products, on last page
  • Test tag with more than 20 products, going back to first page using after
  • Test tag with 0 featuredProductIds
  • Test on StarterKit
  • Test on Admin

Testing

After this ticket is merged, reactioncommerce/example-storefront#498 can be tested and merged to display the products in the Starter-Kit with this query with the featured sorting option. This Starter Kit PR can also be used to test both the front-end and back-end:

  1. Log in as Admin
  2. Go to http://localhost:3000/operator/tags/
  3. Choose a tag to edit http://localhost:3000/operator/tags/edit/cmVhY3Rpb24vdGFnOnJwakN2VEJHamhCaTJ4ZHJv
  4. Make the last product show up first by adding 0 to the Priority column. Save.
  5. View the tag on http://localhost:4000/tag/shop

Test on GraphQL with a query variable: "slugOrId": "shop".

First, confirm a Tag's featuredProductIds with this query for a tag,

query getTagId($slugOrId: String!) {
  tag(slugOrId:$slugOrId) {
    _id
    name
    featuredProductIds
    displayTitle
    slug
  }
}

You should get something like:

{
  "data": {
    "tag": {
      "_id": "cmVhY3Rpb24vdGFnOnJwakN2VEJHamhCaTJ4ZHJv",
      "name": "Shop",
      "featuredProductIds": [
        "J4FquyjPnvTyw6kQA",
        "BCTMZ6HTxFSppJESk",
        "i7mbZ62dcwtnN8chF"
      ],
      "displayTitle": "Test Display Title",
      "slug": "shop"
    }
  }
}

Then, pass featured into the catalogItems query:

query catalogItems($shopIds: [ID]!, $tagIds: [ID]) {
  catalogItems(shopIds: $shopIds, tagIds:$tagIds, sortBy:featured) {
    totalCount
    pageInfo {
      hasNextPage
      hasPreviousPage
    }
    nodes {
      ... on CatalogItemProduct {
        product {
          title
          slug
        }
      }
    }
  }
}

This query should return the products in order of featuredProductIds.

Example

  1. Featured Croakies and One by Optic to the 0 and 1 spots in Admin:

screen shot 2019-02-14 at 12 33 57 pm

  1. Sorted by featured-desc in Starter Kit:

screen shot 2019-02-14 at 12 33 43 pm

@machikoyasuda machikoyasuda force-pushed the feat-machikoyasuda-reaction-sort-tlp branch from 41f6e50 to 93ed66d Compare February 11, 2019 20:11
@machikoyasuda machikoyasuda added this to the 🏔 Torreys milestone Feb 11, 2019
@machikoyasuda machikoyasuda changed the title feat: WIP - Add a featured sort options feat: WIP - Add a featured sort option Feb 12, 2019
@machikoyasuda machikoyasuda force-pushed the feat-machikoyasuda-reaction-sort-tlp branch from b31f120 to 7bfcdba Compare February 13, 2019 00:48
@machikoyasuda machikoyasuda changed the title feat: WIP - Add a featured sort option feat: Add a featured sort option Feb 13, 2019
@machikoyasuda machikoyasuda changed the title feat: Add a featured sort option feat: Add a featured sort option for CatalogItems Feb 13, 2019
@machikoyasuda machikoyasuda force-pushed the feat-machikoyasuda-reaction-sort-tlp branch 2 times, most recently from d68e007 to 2071e12 Compare February 13, 2019 01:06
@machikoyasuda machikoyasuda changed the title feat: Add a featured sort option for CatalogItems feat: WIP - Add a featured sort option for CatalogItems Feb 13, 2019
@machikoyasuda machikoyasuda force-pushed the feat-machikoyasuda-reaction-sort-tlp branch from 7dca82f to 38a7bc8 Compare February 13, 2019 07:54
@machikoyasuda machikoyasuda changed the title feat: WIP - Add a featured sort option for CatalogItems feat: Add a featured sort option for CatalogItems Feb 13, 2019
@machikoyasuda machikoyasuda force-pushed the feat-machikoyasuda-reaction-sort-tlp branch 3 times, most recently from 8791555 to e6029e9 Compare February 14, 2019 00:37
Copy link
Member

@mikemurray mikemurray left a comment

Choose a reason for hiding this comment

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

admin panel mis-represents order of items. The catalogItems query updates need to be readapted for the admin panel, either in this PR or in another.

image

Signed-off-by: Machiko Yasuda <[email protected]>
…ts by featuredProductIds list.

Signed-off-by: Machiko Yasuda <[email protected]>
Signed-off-by: Machiko Yasuda <[email protected]>
Signed-off-by: Machiko Yasuda <[email protected]>
Signed-off-by: Machiko Yasuda <[email protected]>
Signed-off-by: Machiko Yasuda <[email protected]>
Signed-off-by: Machiko Yasuda <[email protected]>
Signed-off-by: Machiko Yasuda <[email protected]>
@machikoyasuda machikoyasuda requested review from mikemurray and aldeed and removed request for aldeed March 12, 2019 23:23
@machikoyasuda machikoyasuda removed the request for review from mikemurray March 14, 2019 21:36
@machikoyasuda machikoyasuda requested review from mikemurray and rosshadden and removed request for mikemurray March 18, 2019 20:56
Copy link
Contributor

@rosshadden rosshadden left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Member

@mikemurray mikemurray left a comment

Choose a reason for hiding this comment

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

  • Products pagination in tag admin works
  • Query results for catalogItems are in correct order and seem to paginate correctly

Soooo... lgtm 👍

@machikoyasuda
Copy link
Contributor Author

Thank youuuu @rosshadden + @mikemurray + @aldeed !

@machikoyasuda machikoyasuda merged commit 2d842c8 into develop Mar 19, 2019
@machikoyasuda machikoyasuda deleted the feat-machikoyasuda-reaction-sort-tlp branch March 19, 2019 01:35
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.

4 participants