Skip to content

Commit

Permalink
Merge branch 'develop' into supernova/239_shipping_methods
Browse files Browse the repository at this point in the history
  • Loading branch information
tjwiebell authored Feb 5, 2020
2 parents 5f34249 + 20c1cc8 commit b033585
Show file tree
Hide file tree
Showing 38 changed files with 245 additions and 194 deletions.
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Thank you for your interest in contributing to the PWA Studio project! Before yo
- [Code of Conduct]
- [Support]

To contribute to this repository, fork the [official repository] and follow the installation instructions in the `README` file.
To contribute to this repository, fork the [official repository] and follow the installation instructions in the `README` file. To get your contribution accepted, you must sign [Adobe's Contributor License Agreement (CLA)](https://opensource.adobe.com/cla.html). You only need to sign the CLA once.

## Pull Requests

Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const testVenia = inPackage => ({
'\\.css$': 'identity-obj-proxy',
'\\.svg$': 'identity-obj-proxy'
},
moduleFileExtensions: ['ee.js', 'ce.js', 'js', 'json', 'jsx', 'node'],
// Reproduce the Webpack resolution config that lets Venia import
// from `src` instead of with relative paths:
modulePaths: [
Expand Down
19 changes: 10 additions & 9 deletions packages/peregrine/lib/talons/SignIn/useSignIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export const useSignIn = props => {
errors.push(getDetailsError);
}

const formRef = useRef(null);
const formApiRef = useRef(null);
const setFormApi = useCallback(api => (formApiRef.current = api), []);

const handleSubmit = useCallback(
async ({ email, password }) => {
Expand Down Expand Up @@ -84,31 +85,31 @@ export const useSignIn = props => {
);

const handleForgotPassword = useCallback(() => {
const { current: form } = formRef;
const { current: formApi } = formApiRef;

if (form) {
setDefaultUsername(form.formApi.getValue('email'));
if (formApi) {
setDefaultUsername(formApi.getValue('email'));
}

showForgotPassword();
}, [setDefaultUsername, showForgotPassword]);

const handleCreateAccount = useCallback(() => {
const { current: form } = formRef;
const { current: formApi } = formApiRef;

if (form) {
setDefaultUsername(form.formApi.getValue('email'));
if (formApi) {
setDefaultUsername(formApi.getValue('email'));
}

showCreateAccount();
}, [setDefaultUsername, showCreateAccount]);

return {
errors,
formRef,
handleCreateAccount,
handleForgotPassword,
handleSubmit,
isBusy: isGettingDetails || isSigningIn
isBusy: isGettingDetails || isSigningIn,
setFormApi
};
};
2 changes: 1 addition & 1 deletion packages/peregrine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@apollo/react-hooks": "~3.1.2",
"@babel/runtime": "~7.4.2",
"apollo-client": "~2.6.4",
"informed": "~2.1.13",
"informed": "~2.11.17",
"react": "~16.9.0",
"react-dom": "~16.9.0",
"react-redux": "~7.1.1",
Expand Down
12 changes: 12 additions & 0 deletions packages/pwa-buildpack/envVarDefinitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@
}
]
},
{
"name": "Magento Store Edition",
"variables": [
{
"name": "MAGENTO_BACKEND_EDITION",
"type": "str",
"desc": "Specify the edition of the magento store (Enterprise Edition or Community Edition). Can be one of CE or EE.",
"example": "CE",
"default": "CE"
}
]
},
{
"name": "Image Optimizing Origin",
"variables": [
Expand Down
5 changes: 4 additions & 1 deletion packages/pwa-buildpack/lib/Utilities/getClientConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ module.exports = async function({
vendorTest += `(${vendor.join('|')})[\\\/]`;
}

const isEE = projectConfig.env.MAGENTO_BACKEND_EDITION === 'EE';

debug('Creating client config');

const config = {
Expand Down Expand Up @@ -116,7 +118,8 @@ module.exports = async function({
resolve: await MagentoResolver.configure({
paths: {
root: context
}
},
isEE
}),
plugins: [
new RootComponentsPlugin({
Expand Down
13 changes: 11 additions & 2 deletions packages/pwa-buildpack/lib/WebpackTools/MagentoResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@ const validateConfig = optionsValidator('MagentoResolver', {
module.exports = {
validateConfig,
async configure(options) {
validateConfig('.configure()', options);
const { isEE, ...restOptions } = options;
const extensions = [
'.wasm',
'.mjs',
isEE ? '.ee.js' : '.ce.js',
'.js',
'.json',
'.graphql'
];
validateConfig('.configure()', restOptions);
return {
alias: {},
modules: [options.paths.root, 'node_modules'],
mainFiles: ['index'],
mainFields: ['esnext', 'es2015', 'module', 'browser', 'main'],
extensions: ['.wasm', '.mjs', '.js', '.json', '.graphql']
extensions
};
}
};
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
const MagentoResolver = require('../MagentoResolver');
test('static configure() produces a webpack resolver config', async () => {

test('static configure() produces a webpack resolver config with .ee.js extension if backend is enterprise edition', async () => {
const extensions = ['.wasm', '.mjs', '.ee.js', '.js', '.json', '.graphql'];
await expect(
MagentoResolver.configure({ paths: { root: 'fakeRoot' } })
MagentoResolver.configure({ paths: { root: 'fakeRoot' }, isEE: true })
).resolves.toEqual({
alias: {},
modules: ['fakeRoot', 'node_modules'],
mainFiles: ['index'],
mainFields: ['esnext', 'es2015', 'module', 'browser', 'main'],
extensions: ['.wasm', '.mjs', '.js', '.json', '.graphql']
extensions
});
});

test('static configure() produces a webpack resolver config with .ce.js extension if backend is not enterprise edition', async () => {
const extensions = ['.wasm', '.mjs', '.ce.js', '.js', '.json', '.graphql'];
await expect(
MagentoResolver.configure({ paths: { root: 'fakeRoot' }, isEE: false })
).resolves.toEqual({
alias: {},
modules: ['fakeRoot', 'node_modules'],
mainFiles: ['index'],
mainFields: ['esnext', 'es2015', 'module', 'browser', 'main'],
extensions
});
});

test('static configure() throws if required paths are missing', async () => {
await expect(
MagentoResolver.configure({ paths: { root: false } })
Expand Down
2 changes: 1 addition & 1 deletion packages/venia-concept/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"graphql-cli-validate-magento-pwa-queries": "~1.2.0",
"graphql-tag": "~2.10.1",
"html-webpack-plugin": "~3.2.0",
"informed": "~2.1.13",
"informed": "~2.11.17",
"lodash.over": "~4.7.0",
"memoize-one": "~5.0.0",
"memory-fs": "~0.4.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ exports[`disables remove button on click 1`] = `
exports[`disables submit button on coupon entry 1`] = `
<form
className="entryForm"
onKeyDown={[Function]}
onReset={[Function]}
onSubmit={[Function]}
>
Expand Down Expand Up @@ -70,6 +71,7 @@ exports[`disables submit button on coupon entry 1`] = `
exports[`renders CouponCode input and submit button 1`] = `
<form
className="entryForm"
onKeyDown={[Function]}
onReset={[Function]}
onSubmit={[Function]}
>
Expand Down Expand Up @@ -122,6 +124,7 @@ exports[`renders CouponCode input and submit button 1`] = `
exports[`renders an error message if an error occurs on code entry 1`] = `
<form
className="entryForm"
onKeyDown={[Function]}
onReset={[Function]}
onSubmit={[Function]}
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,40 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`renders accumulated gift card value 1`] = `null`;
exports[`renders accumulated gift card value 1`] = `
Array [
<span
className="lineItemLabel"
>
Gift Card(s) applied
</span>,
<span
className="price"
>
-
<span>
$2
</span>
</span>,
]
`;

exports[`renders gift card summary line item correctly 1`] = `null`;
exports[`renders gift card summary line item correctly 1`] = `
Array [
<span
className="lineItemLabel"
>
Gift Card(s) applied
</span>,
<span
className="price"
>
-
<span>
$10
</span>
</span>,
]
`;

exports[`renders nothing if gift card data is empty 1`] = `null`;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from 'react';
import { Price } from '@magento/peregrine';

import { mergeClasses } from '../../../classify';

const DEFAULT_AMOUNT = {
currency: 'USD',
value: 0
};

/**
* Reduces applied gift card amounts into a single amount.
*
* @param {Array} cards
*/
const getGiftCards = (cards = []) => {
if (!cards.length) {
return DEFAULT_AMOUNT;
} else {
return {
currency: 'USD',
value: cards.reduce(
(acc, card) => acc + card.applied_balance.value,
0
)
};
}
};

/**
* A component that renders the gift card summary line item.
*
* @param {Object} props.classes
* @param {Object} props.data fragment response data
*/

export default props => {
const classes = mergeClasses({}, props.classes);
const cards = getGiftCards(props.data);

return cards.value ? (
<>
<span className={classes.lineItemLabel}>
{'Gift Card(s) applied'}
</span>
<span className={classes.price}>
{'-'}
<Price value={cards.value} currencyCode={cards.currency} />
</span>
</>
) : null;
};

This file was deleted.

Loading

0 comments on commit b033585

Please sign in to comment.