-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Added actions, reducers & selectors to fetch the locations from the WooCommerce host. #15032
Conversation
* @return {Array} The locations tree, as retrieved from the server. It can also be the string "LOADING" | ||
* if the locations are currently being fetched, or a "falsy" value if that haven't been fetched at all. | ||
*/ | ||
export const getRawLocations = ( state, siteId = getSelectedSiteId( state ) ) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you need the Raw here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this being used somewhere else? From this PR it is not evident why it is being exported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, it doesn't need to be exported. Fixed.
@DanReyLop This PR needs a rebase |
], | ||
}, | ||
{ | ||
code: "AM", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor but this should be NA
and North America
.
}, | ||
], | ||
}, | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NA
and North America
|
||
const locations = [ | ||
{ | ||
code: 'AM', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NA
and North America
expect( hasStates( loadedState, 'SA' ) ).to.be.false; | ||
} ); | ||
|
||
it( 'should return true if the countri has states', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: country
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good to me. The main thing is replacing AM
/America
in the docs and tests with NA
and North America
which match what would be returned.
🤦♂️ fixed. It was just for an example, but I should have looked at the real values anyway :) |
@DanReyLop This PR needs a rebase |
@belcherj @justinshreve Can I please get another quick 👀? I've fixed the comments you had. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved - your latest change LGTM.
Fixes #14266
This PR adds logic to fetch locations data from the WooCommerce server. It uses the new
v3/data/continents
endpoint (from here). Since each continent already is returned with all the info for all its countries, and every country is returned with all the info for all its states, there's no need to hit any other endpoint.The data is stored as it comes from the server, but I've added a few selectors to "query" it. Since there are quite a few countries in the world, maybe I've been too negligent with performance. When this is hooked to an actual UI, I'll measure and if needed optimize the data structures or add memoizing to the selectors.
There is no way to test it in the UI, so just run the tests.