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

[PWA-893] My Account: Order History - Remove @client directive #2786

Merged
merged 23 commits into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
fbd6689
Remove client directive and work through errors from using live data
tjwiebell Oct 16, 2020
c4e4b3d
Fixup region display so its not rendering ids
tjwiebell Oct 16, 2020
eb62267
Fix payment method display and remove extra comma in addresses
tjwiebell Oct 16, 2020
cf1750f
Merge remote-tracking branch 'origin/develop' into tommy/orders-remov…
tjwiebell Oct 19, 2020
c1e4000
Additional tweaks from UX feedback
tjwiebell Oct 19, 2020
63c515b
Fixup failing tests
tjwiebell Oct 20, 2020
75ab886
Fix couple tests failing after gql move
tjwiebell Oct 20, 2020
77cd793
Fix bug where tracking information doesn't exist for shipped order
tjwiebell Oct 20, 2020
f10bdcf
Updated Intl FormattedMessage component mock. (#2792)
revanth0212 Oct 20, 2020
a9e3194
- Adjust item grid based on UX feedback
tjwiebell Oct 21, 2020
d8025cf
Merge branch 'develop' into tommy/orders-remove-mock
tjwiebell Oct 22, 2020
2943abf
Fixup failing tests
tjwiebell Oct 22, 2020
299b560
Merge branch 'develop' into tommy/orders-remove-mock
tjwiebell Nov 3, 2020
6d3da3c
Address PR feedback
tjwiebell Nov 3, 2020
bb4d380
Cover new context with tests
tjwiebell Nov 3, 2020
115c3ac
Merge remote-tracking branch 'origin/develop' into tommy/orders-remov…
tjwiebell Nov 3, 2020
1c1a478
Address QA feedback
tjwiebell Nov 5, 2020
5ccd567
Fixup tests and hide incomplete features
tjwiebell Nov 5, 2020
5604e84
Address additional edges found in QA
tjwiebell Nov 9, 2020
41d2595
Merge branch 'develop' into tommy/orders-remove-mock
tjwiebell Nov 10, 2020
b8eb620
Dependently render discount row
tjwiebell Nov 10, 2020
af521e9
Update snaps with new mock
tjwiebell Nov 10, 2020
a1a069b
Allow empty string as quantity value to support backspace
tjwiebell Nov 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,23 @@ jest.mock('react-router-dom', () => {
};
});

jest.mock('@apollo/client', () => ({
useQuery: jest.fn().mockReturnValue({
data: {
customer: {
orders: {
items: ['order1', 'order2']
jest.mock('@apollo/client', () => {
const apolloClient = jest.requireActual('@apollo/client');

return {
...apolloClient,
useQuery: jest.fn().mockReturnValue({
data: {
customer: {
orders: {
items: ['order1', 'order2']
}
}
}
},
loading: false
})
}));
},
loading: false
})
};
});

jest.mock('@magento/peregrine/lib/context/app', () => {
const state = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ import { useQuery } from '@apollo/client';
import createTestInstance from '../../../util/createTestInstance';
import { useOrderRow } from '../useOrderRow';

jest.mock('@apollo/client', () => ({
useQuery: jest.fn()
}));
jest.mock('@apollo/client', () => {
const apolloClient = jest.requireActual('@apollo/client');

return {
...apolloClient,
useQuery: jest.fn()
};
});

const log = jest.fn();
const Component = props => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { gql } from '@apollo/client';

export const GET_CUSTOMER_ORDERS = gql`
query GetCustomerOrders {
customer {
id
orders {
items {
billing_address {
city
country_code
firstname
lastname
postcode
region
street
telephone
}
id
invoices {
id
}
items {
id
product_name
product_sale_price {
currency
value
}
product_sku
product_url_key
selected_options {
label
value
}
quantity_ordered
}
number
order_date
payment_methods {
name
type
additional_data {
name
value
}
}
shipments {
id
tracking {
carrier
number
}
}
shipping_address {
city
country_code
firstname
lastname
postcode
region
street
telephone
}
shipping_method
status
total {
discounts {
amount {
currency
value
}
}
grand_total {
currency
value
}
subtotal {
currency
value
}
total_shipping {
currency
value
}
total_tax {
currency
value
}
}
}
}
}
}
`;

export default {
getCustomerOrdersQuery: GET_CUSTOMER_ORDERS
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { gql } from '@apollo/client';

export const GET_PRODUCT_THUMBNAILS_BY_SKU = gql`
query GetProductThumbnailsBySku($skus: [String!]!) {
products(filter: { sku: { in: $skus } }) {
export const GET_PRODUCT_THUMBNAILS_BY_URL_KEY = gql`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had to change this over to query by URL Key, since the product_sku returned by orders was variant skus which will return no results from the backend. Issue was escalated to GraphQL team, and they will be adding new fields in 2.4.2 so we shouldn't need to make a secondary query to get this data.

Copy link
Contributor

Choose a reason for hiding this comment

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

which will return no results from the backend.

Is this because of our sample data or is it by design of the API?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is by design; configurable variants all have Visibility = Not Visible Individually, so GraphQL is correct in not returning them. Couple JIRA tickets were created to address this though; this one so we don't even need to do a second query for images, and this one so parent sku is returned (which is also a blocker to doing re-orders).

query GetProductThumbnailsByURLKey($urlKeys: [String!]!) {
products(filter: { url_key: { in: $urlKeys } }) {
items {
id
sku
Expand All @@ -18,7 +18,5 @@ export const GET_PRODUCT_THUMBNAILS_BY_SKU = gql`
`;

export default {
queries: {
getProductThumbnailsQuery: GET_PRODUCT_THUMBNAILS_BY_SKU
}
getProductThumbnailsQuery: GET_PRODUCT_THUMBNAILS_BY_URL_KEY
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import { useQuery } from '@apollo/client';

import { useAppContext } from '../../context/app';
import { useUserContext } from '../../context/user';
import { useTypePolicies } from '../../hooks/useTypePolicies';
import DEFAULT_OPERATIONS from './orderHistoryPage.gql';

export const useOrderHistoryPage = props => {
const { queries, types } = props;
const { getCustomerOrdersQuery } = queries;

useTypePolicies(types);
export const useOrderHistoryPage = (props = {}) => {
const { operations = DEFAULT_OPERATIONS } = props;
const { getCustomerOrdersQuery } = operations;

const [
,
Expand Down
12 changes: 7 additions & 5 deletions packages/peregrine/lib/talons/OrderHistoryPage/useOrderRow.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { useCallback, useState, useMemo } from 'react';
import { useQuery } from '@apollo/client';

import DEFAULT_OPERATIONS from './orderRow.gql';

/**
* @function
*
Expand All @@ -11,18 +13,18 @@ import { useQuery } from '@apollo/client';
* @returns {OrderRowTalonProps}
*/
export const useOrderRow = props => {
const { items, queries } = props;
const { getProductThumbnailsQuery } = queries;
const { items, operations = DEFAULT_OPERATIONS } = props;
const { getProductThumbnailsQuery } = operations;

const skus = useMemo(() => {
return items.map(item => item.product_sku).sort();
const urlKeys = useMemo(() => {
return items.map(item => item.product_url_key).sort();
}, [items]);

const { data, loading } = useQuery(getProductThumbnailsQuery, {
fetchPolicy: 'cache-and-network',
nextFetchPolicy: 'cache-first',
variables: {
skus
urlKeys
}
});
const imagesData = useMemo(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/venia-ui/__mocks__/react-intl.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ const intl = reactIntl.createIntl({

module.exports = {
...reactIntl,
FormattedMessage: jest.fn(({ defaultMessage }) => defaultMessage),
FormattedMessage: jest.fn(({ defaultMessage, id }) => defaultMessage || id),
useIntl: jest.fn(() => intl)
};
3 changes: 2 additions & 1 deletion packages/venia-ui/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -336,5 +336,6 @@
"wishlistPage.disabledMessage": "Sorry, this feature has been disabled.",
"wishlistPage.fetchErrorMessage": "Something went wrong. Please refresh and try again.",
"wishlistPage.headingText": "Favorites Lists",
"wishlistPage.wishlistDisabledMessage": "The wishlist is not currently available."
"wishlistPage.wishlistDisabledMessage": "The wishlist is not currently available.",
"orderDetails.waitingOnTracking": "Waiting for tracking information"
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,14 @@ exports[`should render properly 1`] = `
</div>
<div>
<span>
Gooseton
</span>
<span>
Jr
Gooseton Jr
</span>
</div>
<div>
2134, Apt 123, Goose Drive
</div>
<div>
Austin, TX, 78451
</div>
<div>
USA
Austin, TX 78451 USA
</div>
</div>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`should render properly 1`] = `
<div>
<div
componentName="Link Component"
to="/carina-cardigan.html"
to="carina-cardigan.html"
>
<div
className="undefined undefined"
Expand All @@ -23,14 +23,23 @@ exports[`should render properly 1`] = `
onError={[Function]}
onLoad={[Function]}
sizes="50px"
srcSet=""
src="https://www.venia.com/product1-thumbnail.jpg?auto=webp&format=pjpg&width=50&height=62.5&fit=cover"
srcSet="https://www.venia.com/product1-thumbnail.jpg?auto=webp&format=pjpg&width=40&height=50&fit=cover 40w,
https://www.venia.com/product1-thumbnail.jpg?auto=webp&format=pjpg&width=80&height=100&fit=cover 80w,
https://www.venia.com/product1-thumbnail.jpg?auto=webp&format=pjpg&width=160&height=200&fit=cover 160w,
https://www.venia.com/product1-thumbnail.jpg?auto=webp&format=pjpg&width=320&height=400&fit=cover 320w,
https://www.venia.com/product1-thumbnail.jpg?auto=webp&format=pjpg&width=640&height=800&fit=cover 640w,
https://www.venia.com/product1-thumbnail.jpg?auto=webp&format=pjpg&width=960&height=1200&fit=cover 960w,
https://www.venia.com/product1-thumbnail.jpg?auto=webp&format=pjpg&width=1280&height=1600&fit=cover 1280w,
https://www.venia.com/product1-thumbnail.jpg?auto=webp&format=pjpg&width=1600&height=2000&fit=cover 1600w,
https://www.venia.com/product1-thumbnail.jpg?auto=webp&format=pjpg&width=2560&height=3200&fit=cover 2560w"
width={50}
/>
</div>
</div>
<div
componentName="Link Component"
to="/carina-cardigan.html"
to="carina-cardigan.html"
>
Product 1
</div>
Expand All @@ -45,30 +54,29 @@ exports[`should render properly 1`] = `
</div>
</dl>
<span>
<div
componentName="Formatted Message Component"
id="orderDetails.quantity"
values={
Object {
"quantity": 3,
}
}
/>
</span>
<span>
$100.00
orderDetails.quantity
</span>
<div>
<span>
$
</span>
<span>
100
</span>
<span>
.
</span>
<span>
00
</span>
</div>
<button
disabled={false}
onClick={[Function]}
type="button"
>
<span>
<div
componentName="Formatted Message Component"
defaultMessage="Buy Again"
id="orderDetails.buyAgain"
/>
Buy Again
</span>
</button>
<button
Expand All @@ -77,11 +85,7 @@ exports[`should render properly 1`] = `
type="button"
>
<span>
<div
componentName="Formatted Message Component"
defaultMessage="Return This"
id="orderDetails.returnThis"
/>
Return This
</span>
</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ exports[`should render properly 1`] = `
product_name="Product 3"
product_sale_price="$100.00"
product_sku="VA03"
product_url_key="valeria-two-layer-tank"
quantity_ordered={1}
selected_options={
Array [
Expand All @@ -32,6 +33,7 @@ exports[`should render properly 1`] = `
product_name="Product 4"
product_sale_price="$100.00"
product_sku="VP08"
product_url_key="chloe-silk-shell"
quantity_ordered={1}
selected_options={
Array [
Expand All @@ -56,6 +58,7 @@ exports[`should render properly 1`] = `
product_name="Product 5"
product_sale_price="$100.00"
product_sku="VSW09"
product_url_key="helena-cardigan"
quantity_ordered={1}
selected_options={
Array [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,7 @@ exports[`should render properly 1`] = `
</svg>
</span>
<span>
<div
componentName="Formatted Message Component"
defaultMessage="Print Receipt"
id="orderDetails.printLabel"
/>
Print Receipt
</span>
</span>
</button>
Expand Down
Loading