Commit Graph

1339 Commits

Author SHA1 Message Date
Mike Jolley e6dfe243f9 Switch out usage from withComponentId to tree-shaken withInstanceId (https://github.com/woocommerce/woocommerce-blocks/pull/1923) 2020-03-10 14:40:30 +00:00
Darren Ethier 2aa2093dfb Add contexts for checkout (https://github.com/woocommerce/woocommerce-blocks/pull/1915)
- restructures `@woocommerce/base-context` imports so it pulls from `index.js` in the `base/context` folder. That way tree-shaking will be used if possible. This also helps with organizing the folder structure a bit better for the new contexts.
- Fixes all the various imports through the code due to the above change.
- Adds `CheckoutContextProvider`, `useCheckoutContext` and related files.
- Adds `PaymentMethodDataProvider`, `usePaymentMethodDataContext` and related files.
- Adds `ShippingMethodDataProvider`, `useShippingMethodDataContext` and related files.
- Adds typedefs used for the various context interfaces.
2020-03-10 09:39:21 -04:00
Seghir Nadir 5ca0593fbd Default to the first state when selecting a country with states (https://github.com/woocommerce/woocommerce-blocks/pull/1919)
* default to the first state

* Update assets/js/base/components/state-input/state-input.js

Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com>

Co-authored-by: Albert Juhé Lluveras <aljullu@gmail.com>
2020-03-10 13:27:58 +01:00
Darren Ethier 0cacf5e0da Disallow selecting quantity of stock past what's available. (https://github.com/woocommerce/woocommerce-blocks/pull/1905)
- `useStoreCartItemQuantity` now receives the cartItem instead of the `cartItemKey` as an argument. I didn't notice in previous reviews how it's used in the context where we already have a cartItem so implementing this reduces complexity and makes the hook more precise for it's purpose.
- Add `backorders_allowed` to the CartItem schema for the API. This allows for client to have correct logic for maximum quantity when this value is true.
- Implement the above in the `CartLineItemRow` so that quantity picker is limited by the amount of stock remaining if that is available (`lowStockRemaining`) and the `backorders_allowed` is false.
- maximum quantity is currently hardcoded to a (filtered) value of `99` when other conditions don't apply (see related issue in woocommerce/woocommerce-blocks#1913)
2020-03-10 07:43:57 -04:00
Albert Juhé Lluveras 2f58d86fa6 Update build-plugin-zip.sh intro text (https://github.com/woocommerce/woocommerce-blocks/pull/1922) 2020-03-10 11:35:17 +00:00
Mike Jolley 514642395a Prevent wp.components loading on frontend (https://github.com/woocommerce/woocommerce-blocks/pull/1918)
* Avoid importing @wordpress/components in icon library

* Avoid @wordpress/compose and @wordpress/components in `base`

* Move hocs used on frontend to base

* Revert "Move hocs used on frontend to base"

This reverts commit bf09016fdc2fc1bea2f465018fecc76945f69d5e.
2020-03-10 11:20:40 +00:00
Seghir Nadir 952638a3ed Link shipping form fields to shipping rates to load them. (https://github.com/woocommerce/woocommerce-blocks/pull/1890)
* add plukedAddress util function in order to use it for shallowEqual

* refactor useShipping so it accepts and returns the address

* refactor fields

* fix test and return shippingRates to hook

* remove unneeded shippingAddress from ShippingRatesControl

* move keys logic to hook

* refactor tests again

* increase cart size
2020-03-10 11:55:19 +01:00
Albert Juhé Lluveras f14fc54faf Refactor 'Hide shipping costs' Cart attribute logic (https://github.com/woocommerce/woocommerce-blocks/pull/1909)
* Use kebab-case for Cart block attributes

* Simplify Cart edit function

* Refactor showShippingCosts logic

* Update snapshots
2020-03-10 10:09:34 +01:00
Rua Haszard 12f942948e mobile layout fixes for cart totals (https://github.com/woocommerce/woocommerce-blocks/pull/1898)
* tidy cart totals layout on mobile:
- totals column is full width
- reset container (card) borders and padding

* increase specificity of mobile cart styles to ensure skeleton hides after load

* use "not loading" && "not skeleton" approach for more readable mobile style selector
2020-03-10 10:16:03 +13:00
Darren Ethier b6c0ce4299 bump up budget for checkout-frontend.js script (https://github.com/woocommerce/woocommerce-blocks/pull/1912) 2020-03-09 15:14:48 -04:00
Mike Jolley 38890b3ff9 Add "or continue below" separator to checkout block (https://github.com/woocommerce/woocommerce-blocks/pull/1906)
* Update express checkout component to match coding standards doc

* Improve express checkout spacing/styling

* Add continue rule
2020-03-09 15:49:01 +00:00
Mike Jolley 168ce52935 Include address fields in the AddressForm component (https://github.com/woocommerce/woocommerce-blocks/pull/1892)
* Move default address fields to blocks; normalise address i18n

* Use optionalLabel and other props from addressFields

* Fix apartment field display

* Country address fields

* Fix default field order

* Update for countries with no states

* Add type defs
2020-03-09 14:23:16 +00:00
Darren Ethier 02b3f2fccc add defaults for cart data totals object (https://github.com/woocommerce/woocommerce-blocks/pull/1896) 2020-03-09 08:52:25 -04:00
renovate[bot] 5475985912 Lock file maintenance (https://github.com/woocommerce/woocommerce-blocks/pull/1897)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2020-03-09 12:30:35 +00:00
Darren Ethier 89ab1579b0 Followup for useStoreCartItem work (change hook name and improve typedefs) (https://github.com/woocommerce/woocommerce-blocks/pull/1900)
* add typedefs for CartItem

* remove cartItem from StoreCartItem typedef

* Implement new typedef and fix defaults as well as returned object.

Now that `cartItem` is only used internally, the default set on the state only has to be the properties required internally in the hook.

* add typedefs for shared settings and implement typedef comments.

* change hook name
2020-03-09 08:24:56 -04:00
Albert Juhé Lluveras b7da7ad198 Make Shipping packages collapsible in Cart page (https://github.com/woocommerce/woocommerce-blocks/pull/1867)
* Make Shipping packages collapsible in Cart page

* Fix Cart block radio controls not looking properly in the editor

* Simplify CSS
2020-03-09 12:28:26 +01:00
Rua Haszard 76f5ed5030 improve responsiveness when setting cart item quantities (https://github.com/woocommerce/woocommerce-blocks/pull/1864)
* rework the quantity change generator action so the UI updates quick:
- work in progress - still need to figure out how to debounce API call
- add new action for updating quantity for an item
- don't set cart item as pending while quantity is updating
  - this leaves QuantitySelector enabled so user can click more/less
- use receiveCartItemQuantity to update quantity in UI before sending request

* debounce line item quantity first cut:
- use local state for quantity, so ui allows multiple clicks up/down
- debounce store updates (and server/API call)

* correct comment on cart item quantity reducer

* remove recieveCartItemQuantity - no longer needed

* remove delegation for deleted RECEIVE_CART_ITEM_QUANTITY

* only update quantity in component sideffect if it has changed:
- reduces unnecessary renders

* factor out debounced quantity update into cartItem hook (hat tip @senadir)

* use quantity from store, instead of passing in to hook +
+ fix latent bug in useStoreCartItem - the cartItem value is now object:
  - was previously single-item array
  - (note no client code is using this at present)

* tidy/refactor cart item hook - separate dispatch from select

* remove dud reset of item pending flag (came back in rebase)

* add quantity to StoreCartItem hook return value typedef

* fix js error when adding cart block in editor – cartItem not found

* fix typedef

* fix logic for debouncing

* don’t update quantity on server unnecessarily

Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
2020-03-09 15:09:47 +13:00
Darren Ethier be5dfbd565 Update plugin zip build script with additional options. (https://github.com/woocommerce/woocommerce-blocks/pull/1893)
* update plugin build script to allow for development builds

* add new npm scripts to package.json

- running dev build without watch
- building a plugin zip for dev build.

* tweak script to have zip only build

* update docs to include new build options

* improve command docs
2020-03-08 21:59:31 -04:00
Seghir Nadir e769516758 better default to array and use length as condition (https://github.com/woocommerce/woocommerce-blocks/pull/1891) 2020-03-06 15:40:07 +00:00
Albert Juhé Lluveras 427a229591 Split Full Cart sidebar totals into several components (https://github.com/woocommerce/woocommerce-blocks/pull/1885) 2020-03-06 12:27:54 +00:00
Mike Jolley 1942491822 Checkout Block: Add Legal links (https://github.com/woocommerce/woocommerce-blocks/pull/1881)
* Create policy component

* Create page constants

* Add toggle options

* Update assets/js/base/components/checkout/policies/style.scss

Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com>

* Update assets/css/editor.scss

Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com>

* Feedback

* update snapshot

Co-authored-by: Albert Juhé Lluveras <aljullu@gmail.com>
2020-03-06 12:20:17 +00:00
Mike Jolley 000858d8f1 Update `reserved stock` class to handle concurrent requests (https://github.com/woocommerce/woocommerce-blocks/pull/1778)
* Add expires column to table

* Use core class if it exists.

* Add Exception class

* Update for currcurrency

* Update tests to handle exception

* Add back legacy stock handling

* Update comments
2020-03-06 11:44:20 +00:00
Mike Jolley 0a722b1708 Cart and checkout error boundaries (https://github.com/woocommerce/woocommerce-blocks/pull/1853)
* Add error boundries

Revert block error move

webpack config

fix path

* type in config

* change text allowed type

* Pass error boundary props to renderfrontend

* Editor error boundaries

* Add errorMessagePrefix

* merge rules

* Remove <disabled>

* Update reload page link
2020-03-06 11:43:40 +00:00
Albert Juhé Lluveras 20da4900c2 Add styling to checkboxes (https://github.com/woocommerce/woocommerce-blocks/pull/1880)
* Add styling to checkboxes

* Add resets for some themes

* Simplify props
2020-03-06 11:26:03 +01:00
Seghir Nadir 2c8388f0a8 Update and select shipping rates dynamically (https://github.com/woocommerce/woocommerce-blocks/pull/1794)
* add select shipping endpoint to router

* add select shipping method

* add selected rates to cart

* better select rates

* move schema function to seperate function

* move validation to Cart Controller

* fix wrong session key

* Update shipping/cart endpoints (https://github.com/woocommerce/woocommerce-blocks/pull/1833)

* Items should not have keys in API response

* Include package ID in response (this is just a basic index)

* /cart/select-shipping-rate/package_id

* Add package_id to package array

* Update responses and add shipping-rates to main cart endpoint

* update-shipping endpoint

* Add querying selected shipping rate to the store (https://github.com/woocommerce/woocommerce-blocks/pull/1829)

* add selecting shipping to store

* directly call useSelectShippingRate

* refactor cart keys transformation to reducer

* remove selecting first result and accept selecting

* move update shipping to new endpoint

* pass selected rates down

* select shipping right directly and fix editor issues

* fix some broken prop types

* key -> package id

* Update and fix cart/shipping-rate tests

* fix case for when rates are set

* Update useShippingRates test

* add args to rest endpoint

* move selecting shipping rate logic to hook

* fix some naming issues

* update propTypes

* update action call

* fully watch cart state

* address review issues

* fix prop type issues

* fix issue with rates not loading in checkout

* remove extra package for shipping

* move ShippingCalculatorOptions to outside

Co-authored-by: Mike Jolley <mike.jolley@me.com>
Co-authored-by: Albert Juhé Lluveras <aljullu@gmail.com>
2020-03-05 20:54:05 +01:00
Rua Haszard 5a26d2708e ensure cart totals update when items are removed or quantity changed (https://github.com/woocommerce/woocommerce-blocks/pull/1840)
* ensure cart totals update when items are removed (prototype):
- return complete cart object from DELETE cart/items/:key
- use receiveCart on client to update whole cart including total

* move API endpoint for removing cart items to cart controller:
- returns full cart schema so should be part of cart controller
- is now a POST request with param - not strict REST
- fix up client action to use new API

* move API test for removing cart items (API has moved)

* use correct path for remove API in tests (doh!)

* add extra API test for remove_cart_item with bad key => 404 (experiment)

* experiment: delete test_remove_cart_item, does test_remove_bad_cart_item work?

* reinstate test_remove_cart_item with single valid request

* remove unnecessary newline

* tidy comments in PHP api tests, rerun travis?

* remove test_remove_cart_item which may be causing problems

* reinstate troublesome remove cart item api test (experiment):
- see if this works now travis issue is resolved

* whitespace

* show correct total when changing cart item quantity:
- move update cart item quantity API to cart controller
  - & return full cart response
- update js action to new API route & receive full cart response

* simplify test_remove_cart_item API test - now just tests a valid remove succeeds

* remove test_update_item (API has moved) +
+ experimentally remove test_remove_bad_cart_item
  - testing if cart remove tests interact with each other

* fix tests (🤞) - pass params in body, not as query params

* reinstate test for re-deleting same item

* update API docs - update/delete cart item have moved to /cart

* add response data checks to new cart API tests:
- extra protection against expected 404 "false positives"

* reinstate API test for changing cart item quantity

* fix remove cart item body tests - MIA items return error code, not cart

* fix test - quantity param is int not string

* attempt fix 404ing test_update_item:
- only allow POST, remove trailing `/`
- align array equals for good measure :)

* fix action for update-item - method=POST, now takes body params

* fix response body asserts in test_update_item

* reinstate update_item and delete_item on CartItems controller

* typos + examples in new cart items API docs

* reorder previous cart item docs to minimise diff/churn

* reinstate tabs in docs response example
2020-03-06 08:11:39 +13:00
Mike Jolley 52feba4f85 Add skeleton markup to the cart block (https://github.com/woocommerce/woocommerce-blocks/pull/1866)
* Add skeleton markup

* Add shipping title to skeleton and match styling/spacing

* Combine skeleton and loading styles
2020-03-05 14:15:28 +00:00
Mike Jolley dd54ce1136 Checkout form options to control field visibility (https://github.com/woocommerce/woocommerce-blocks/pull/1868)
* Fix background overlap of feedback box

* TS notices

* Add company name toggle

* Implement new attributes and toggles in editor

* Handle field config in address component

* Remove other hoc rule from tsconfig

* map -> forEach

* Remove return from forEach

* Export and extend field config

* Fix optional text for all field types

* unit text

* Update snapshot
2020-03-05 13:06:47 +00:00
Mike Jolley 401f50a607 Tidy cart items mobile layout (https://github.com/woocommerce/woocommerce-blocks/pull/1875)
* add a smaller min-width for cart column on smaller screens

* ensure full price is inline on mobile (when visible)

* ensure line item totals are bottom aligned even if quantity cell is huge

* revert price vertical alignment - in design they are aligned with quantity digit
2020-03-05 13:05:42 +00:00
Mike Jolley c4c31bd926 make product name display block to push stock badge on to its own line (https://github.com/woocommerce/woocommerce-blocks/pull/1874) 2020-03-05 12:56:57 +00:00
Mike Jolley c093ad78b4 fix missing key (https://github.com/woocommerce/woocommerce-blocks/pull/1877) 2020-03-05 12:31:03 +00:00
Seghir Nadir f872a3b605 Fix broken e2e test for Checkout block (https://github.com/woocommerce/woocommerce-blocks/pull/1869)
* fix broken e2e test - update snapshot for checkout block:
- new `use-shipping-as-billing` data attr

* add package.json script for updating e2e test snapshots
2020-03-05 10:00:39 +01:00
Albert Juhé Lluveras 2544ffd7d1 Option to 'use shipping address for billing': add attribute and make it work in the frontend (https://github.com/woocommerce/woocommerce-blocks/pull/1857)
* Create useShippingAsBilling attribute

* Fix missing prop

* Refactor FormStep so stepNumber is generated by CSS instead of being passed as a prop

* Add billing address form

* Add text before controls

* Remove old @todo comment
2020-03-04 15:13:38 +00:00
Albert Juhé Lluveras e2f769eedf Do not allow focus on Country and State input hidden fields (https://github.com/woocommerce/woocommerce-blocks/pull/1842) 2020-03-04 14:35:18 +00:00
Rua Haszard 1b69ff666e Add basic tests for Cart & Checkout blocks - snapshot, can only add one instance (https://github.com/woocommerce/woocommerce-blocks/pull/1809)
* basic e2e tests for cart block:
- can add block, confirm editor markup matches snapshot
- can only insert one cart block

* add basic tests for checkout block:
- can add & matches snapshot
- can only add one block

* confirm single-cart test works, by allowing multiple cart blocks :)

* Revert "confirm single-cart test works, by allowing multiple cart blocks :)"

This reverts commit aae10046f37bc53bf11d8d2e1deb626d53654f71.
2020-03-04 14:32:31 +00:00
renovate[bot] ed09515edc Update babel monorepo to v7.8.6 (https://github.com/woocommerce/woocommerce-blocks/pull/1859)
Co-authored-by: WhiteSource Renovate <renovatebot@gmail.com>
2020-03-04 13:01:11 +00:00
renovate[bot] bb36890373 Update dependency config to v3.3.0 (https://github.com/woocommerce/woocommerce-blocks/pull/1860)
Co-authored-by: WhiteSource Renovate <renovatebot@gmail.com>
2020-03-04 13:00:56 +00:00
renovate[bot] 0985e04494 Update dependency eslint-plugin-jest to v23.8.1 (https://github.com/woocommerce/woocommerce-blocks/pull/1861)
Co-authored-by: WhiteSource Renovate <renovatebot@gmail.com>
2020-03-04 13:00:39 +00:00
renovate[bot] fcf3d63d13 Update dependency react-number-format to v4.4.1 (https://github.com/woocommerce/woocommerce-blocks/pull/1862)
Co-authored-by: WhiteSource Renovate <renovatebot@gmail.com>
2020-03-04 13:00:29 +00:00
renovate[bot] de34bc63a3 Update dependency react-test-renderer to v16.13.0 (https://github.com/woocommerce/woocommerce-blocks/pull/1863)
Co-authored-by: WhiteSource Renovate <renovatebot@gmail.com>
2020-03-04 12:59:53 +00:00
renovate[bot] b06286d887 Pin dependency @wordpress/notices to 2.0.0 (https://github.com/woocommerce/woocommerce-blocks/pull/1858)
Co-authored-by: WhiteSource Renovate <renovatebot@gmail.com>
2020-03-04 12:59:39 +00:00
Mike Jolley ea19fad14e Add useStoreCartApiHydration HOC (https://github.com/woocommerce/woocommerce-blocks/pull/1845)
* Add useStoreCartApiHydration hoc

* comment

* indenting

Co-authored-by: Seghir Nadir <nadir.seghir@gmail.com>
2020-03-04 12:40:03 +00:00
Darren Ethier 3d98db9583 add changelog from 2.5.14 2020-03-04 07:29:14 -05:00
Mike Jolley 25a2367338 Cleanup draft orders (https://github.com/woocommerce/woocommerce-blocks/pull/1855)
* On init, create cron events

* Cleanup query + unit test

* Replace cron with AS
2020-03-04 11:08:23 +00:00
Darren Ethier a602a69d4d Fix failing travis e2e tests (environment caused) (https://github.com/woocommerce/woocommerce-blocks/pull/1856)
* refresh package-lock.json

* huh, not installing from package-lock after all.. give this a try
2020-03-03 11:08:53 -05:00
Darren Ethier b8ea4aa747 add extra block classname escaping (https://github.com/woocommerce/woocommerce-blocks/pull/1854) 2020-03-03 07:57:56 -05:00
Albert Juhé Lluveras 3702098ecf Suggest using `git cherry-pick` instead of `hub am -3` in release docs (https://github.com/woocommerce/woocommerce-blocks/pull/1844)
* Suggest using `git cherry-pick` instead of `hub am -3` in release docs

* Suggest using hub cherry-pick instead of git cherry-pick
2020-03-03 12:38:50 +00:00
Albert Juhé Lluveras e97ffd2821 Hide package name when there is only one (https://github.com/woocommerce/woocommerce-blocks/pull/1852) 2020-03-03 12:38:21 +00:00
Albert Juhé Lluveras 81c09d180b Create AddressForm component and change its fields dynamically based on country (https://github.com/woocommerce/woocommerce-blocks/pull/1847) 2020-03-03 11:46:53 +01:00
Mike Jolley d3a9dc3d6b Create Context Provider for Notices w/ Notices API (https://github.com/woocommerce/woocommerce-blocks/pull/1843)
* Working on store provider

* Working on store provider

* Reducer implementation

* Implement core/notices

* Add notices to store coupon hook with context

* Improve store notice text and styling

* Improve JS side API for notices

* Wrap functions with context additon

* Update test to []

* Implement props feedback and useInstanceId

* Update assets/js/base/context/store-notices-context.js

Co-Authored-By: Darren Ethier <darren@roughsmootheng.in>

* Update assets/js/base/context/store-notices-context.js

Co-Authored-By: Darren Ethier <darren@roughsmootheng.in>

* remove instance id

Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
2020-03-03 10:26:02 +00:00