Skip to content
This repository was archived by the owner on Jul 12, 2024. It is now read-only.

Add wc-api and "Fresh Data"#833

Merged
coderkevin merged 4 commits intomasterfrom
add/wc-api-fresh-data
Nov 29, 2018
Merged

Add wc-api and "Fresh Data"#833
coderkevin merged 4 commits intomasterfrom
add/wc-api-fresh-data

Conversation

@coderkevin
Copy link
Copy Markdown
Contributor

@coderkevin coderkevin commented Nov 13, 2018

This adds a wc-api module as a @wordpress/data generic store, which is based on Fresh Data

Note: This PR contains a workaround that will no longer be necessary after the following Gutenberg PR is merged: WordPress/gutenberg#11460

This leverages the general purpose fresh-data framework to create a woocommerce-specific api implementation. The first use of this is in the orders fetching for the orders table in the analytics report. The goal was to have minimal changes to the application code but still gain the advantages of sharing data across components and automatic re-fetching of data.

Detailed test instructions:

  1. npm install
  2. npm start
  3. Visit http://localhost/wp-admin/admin.php?page=wc-admin#/analytics/orders and ensure that the orders table populates properly at the bottom.
  4. Create a new order, and it should show up in the table automatically within 5 minutes.

For additional debugging information, type localStorage.setItem( 'debug', 'fresh-data:*' ); to see the updating and scheduling of data fetches.

@allendav
Copy link
Copy Markdown
Contributor

allendav commented Nov 15, 2018

Maybe as part of this, maybe separate - it would be nice to have an example where we use fresh data to detect that a new instance of a resource is available (e.g. a new order) and fetch it (e.g. to auto update a table bound to orders.)

Create a new order, and it should show up in the table [analytics - orders] automatically within 5 minutes.

Or maybe this already works without user intervention?

Copy link
Copy Markdown
Contributor

@allendav allendav left a comment

Choose a reason for hiding this comment

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

I'll take another crack at running this today, but in the meantime I wanted to get these pending comments posted.

@psealock
Copy link
Copy Markdown
Contributor

psealock commented Nov 21, 2018

hey @coderkevin, on a fresh clone of fresh-data, I npm install and get the following error on npm run build:

lerna ERR! npm run build stderr:
events.js:167
      throw er; // Unhandled 'error' event
      ^

Error: spawn babel ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:229:19)
    at onErrorNT (internal/child_process.js:406:16)
    at process._tickCallback (internal/process/next_tick.js:63:19)
    at Function.Module.runMain (internal/modules/cjs/loader.js:746:11)
    at startup (internal/bootstrap/node.js:240:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:564:3)
Emitted 'error' event at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:235:12)
    at onErrorNT (internal/child_process.js:406:16)
    [... lines matching original stack trace ...]
    at bootstrapNodeJSCore (internal/bootstrap/node.js:564:3)

are some modules missing from devDependencies?

This PR adds fresh-data with a WooCommerce API spec to fulfill order
information. It then replaces the existing selectors for the orders
table with the new selectors as a proof-of-concept.
@coderkevin coderkevin force-pushed the add/wc-api-fresh-data branch from d6aefc5 to 0b63da3 Compare November 27, 2018 20:11
This adds temporary code for a `withSelect` function outside of
`@wordpress/data` until the context PR is merged:

WordPress/gutenberg#11460
@coderkevin
Copy link
Copy Markdown
Contributor Author

This PR uses the updated fresh-data version and has a workaround for @wordpress/data.
It no longer needs either of those dependencies to be built to test. I've revised the testing instructions and it's ready for review again. Thanks!

Copy link
Copy Markdown
Collaborator

@emdashcodes emdashcodes left a comment

Choose a reason for hiding this comment

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

This is building and testing well for me. I added a new order in another tab and it showed up pretty quickly. Nice work 👍

@coderkevin coderkevin merged commit 3dbcbf7 into master Nov 29, 2018
@coderkevin coderkevin deleted the add/wc-api-fresh-data branch November 29, 2018 15:57
@timmyc
Copy link
Copy Markdown
Contributor

timmyc commented Nov 29, 2018

Super happy to see this land @coderkevin - way to push it through!

@coderkevin
Copy link
Copy Markdown
Contributor Author

Thanks! Now the rest of the work can begin. 😄

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants