Skip to content
This repository has been archived by the owner on Jun 7, 2022. It is now read-only.

Migrated "import" store to "wp.data" #4982

Merged
merged 28 commits into from
Sep 1, 2020
Merged

Migrated "import" store to "wp.data" #4982

merged 28 commits into from
Sep 1, 2020

Conversation

octaedro
Copy link
Contributor

@octaedro octaedro commented Aug 13, 2020

Fixes #3382

This PR migrates the import store to wp.data.

Also added error handling.

Screenshots

screenshot-one wordpress test-2020 08 13-11_40_08

Detailed test instructions:

  • Go to WooCommerce | Analytics | Settings (URL: /wp-admin/admin.php?page=wc-admin&path=/analytics/settings)
  • If you need to add orders to test you should turn WC-Admin off, add a new order and turn it on again.
  • The count of customers and orders and refunds available to import should be visible.
  • Verify no HTTP/JS errors occur.
  • Press Start.
  • Everything should work normally.

Re-import data

  • After the process finishes, it should show the button Re-import data. Press it.
  • Start the process again.
  • Refresh the browser.
  • The button Stop should be visible until the importation finishes.

Be careful when you press Delete Previously Imported Data. It could show a false positive since it's a process that runs under the hood

Changelog Note:

Dev: migrate import store to wp.data (don't include this in plugin changelog)

@octaedro octaedro self-assigned this Aug 13, 2020
@octaedro octaedro added this to In Progress PRs (for automation purposes) in Isotope via automation Aug 13, 2020
@octaedro octaedro force-pushed the add/3382 branch 2 times, most recently from 4871e9f to 13d20d8 Compare August 19, 2020 13:04
@octaedro octaedro requested a review from a team August 22, 2020 19:54
Copy link
Collaborator

@psealock psealock left a comment

Choose a reason for hiding this comment

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

Looking good @octaedro, this is quite the refactor!

I noted a few things, and found some items in testing but I'm not sure if they how they relate to these changes:

I had more orders than the total, which led to an odd UI
Screen Shot 2020-08-24 at 9 45 42 AM

Here is a shot of the API response showing the same thing.
Screen Shot 2020-08-24 at 9 59 15 AM

It also showed is_importing: false and the UI said "Finalizing" with the spinner showing, but it remained that way for a long time and continued to poll the server until I refreshed the page. I would have expected it to stop and show some kind of indication of success.

"Delete Previously Imported Data" didn't really do anything until I refreshed the page some time later. I don't know if thats a different issue.

I also got this warning:

Property setImportFinished returned from dispatchMap in useDispatchWithMap must be a function.`

Finally, when the button received the disabled prop the UI doesn't reflect that, so it can be misleading to the user because the button looks enabled. This obviously is a separate issue to tackle later. Issue here: #5046

noteTypes: 'info,warning,marketing,survey',
};

export const TIMEOUT = 3 * SECOND;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should use the constants found in packages/data/src/constants.js.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea! The constants were moved in the commit 2b79e38

* Internal dependencies
*/
import { formatParams } from './utils';
import { recordEvent } from '../../../lib/tracks';
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you rebase, this code is now at import { recordEvent } from '@woocommerce/tracks';

...imports.operations.read( resourceNames ),
...items.operations.read( resourceNames ),
];
return [ ...items.operations.read( resourceNames ) ];
},
update( resourceNames, data ) {
return [ ...items.operations.update( resourceNames, data ) ];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Items have now been removed, so this whole file can be removed after a rebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would removing the file client/wc-api/wc-api-spec.js generate some problems here?

@psealock psealock added needs: author feedback The issue/PR needs a response from any of the parties involved in the issue. and removed [Status] Needs Review labels Aug 23, 2020
Fernando Marichal added 17 commits August 26, 2020 11:53
This commit migrates the "import" store to "wp.data"

# Conflicts:
#	client/analytics/settings/historical-data/layout.js
#	packages/data/src/index.js

# Conflicts:
#	packages/data/src/index.js

# Conflicts:
#	packages/data/src/index.js
This commit adds error handling to the apiFetch
This commit removes old import store files and "wc-api-spec" import references

# Conflicts:
#	client/wc-api/wc-api-spec.js

# Conflicts:
#	client/wc-api/wc-api-spec.js
# Conflicts:
#	client/analytics/settings/historical-data/index.js
# Conflicts:
#	client/analytics/settings/historical-data/index.js
# Conflicts:
#	client/analytics/settings/historical-data/index.js
# Conflicts:
#	client/analytics/settings/historical-data/index.js
@octaedro
Copy link
Contributor Author

Thank you @psealock for your review. I answered the questions you asked below.
Could you give this PR another look?

I had more orders than the total, which led to an odd UI
Screen Shot 2020-08-24 at 9 45 42 AM

I couldn't replicate this issue. I tried with 20 orders and 20 customers and everything worked ok.

 It also showed is_importing: false and the UI said "Finalizing" with the spinner showing

This is a preexisting issue, I solved it in the commit d736c7f

but it remained that way for a long time and continued to poll the server until I refreshed the page.

Weird, this process usually takes a lot of time but I never experienced something like that. Did refreshing the page fix the problem for you?

I would have expected it to stop and show some kind of indication of success.

The current behavior is inherited from the old version. When the importation process finishes the user will see Status: All historical data imported and only the buttons Re-import data and Delete Previously Imported Data should be visible.

 "Delete Previously Imported Data" didn't really do anything until I refreshed the page some time later. I don't know if thats a different issue.

This is also inherited. It's working but it doesn't tell the user what is going on in the API side.

 I also got this warning:
Property setImportFinished returned from dispatchMap in useDispatchWithMap must be a function.

Solved in the commit bee9f92

 Finally, when the button received the disabled prop the UI doesn't reflect that, so it can be misleading to the user because the button looks enabled. This obviously is a separate issue to tackle later. Issue here: #5046

I solved this problem in the commit aada1d3

@octaedro octaedro added [Status] Needs Review and removed needs: author feedback The issue/PR needs a response from any of the parties involved in the issue. labels Aug 28, 2020

class HistoricalData extends Component {
constructor() {
super( ...arguments );

this.dateFormat = __( 'MM/DD/YYYY', 'woocommerce-admin' );
this.intervalId = -1;
this.lastImportStopTimestamp = 0;
this.cacheNeedsClearning = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

typo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good eyes @becdetat! I corrected it in the commit 2637750

lastImportStartTimestamp

const isError = Boolean(
getImportError( lastImportStartTimestamp ) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

is this a || a?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch! This was fixed in the commit e417088

! isStatusLoading &&
inProgress &&
inProgress &&
! cacheNeedsClearning &&
Copy link
Contributor

Choose a reason for hiding this comment

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

same typo as above

Copy link
Contributor

@becdetat becdetat left a comment

Choose a reason for hiding this comment

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

Everything looked fine in the first step until it seemed to get stuck when almost completed importing orders and refunds. When I refreshed the page everything was zero-ed out but the re-import data button wasn't present so I couldn't test the second step.

Assuming that this is just a quirk with my setup (I have thousands of customers and orders) this looks fine.

Copy link
Collaborator

@psealock psealock left a comment

Choose a reason for hiding this comment

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

Changes look good @octaedro ! Nice work. I left a comment about the CSS for disabled button, otherwise looking good.

Would removing the file client/wc-api/wc-api-spec.js generate some problems here?

yes probably. I deleted the entire client/wc-api folder to see what would happen. Theres a lot of conflicts with code still using parts of wc-api. Once this is merged, I think it would good to address those in a follow up.

@@ -112,4 +112,7 @@
.woocommerce-settings-historical-data__actions {
align-items: center;
display: flex;
button:disabled {
opacity: 0.5 !important;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This works great, but I think should be removed because its a problem across all wc-admin. Issue to track here: #5046

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you @psealock, got it!
This was removed in the commit b481d41

Copy link
Collaborator

@psealock psealock left a comment

Choose a reason for hiding this comment

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

That last comment was meant to be an approval 🎉

@psealock psealock added needs: author feedback The issue/PR needs a response from any of the parties involved in the issue. and removed [Status] Needs Review labels Sep 1, 2020
@octaedro
Copy link
Contributor Author

octaedro commented Sep 1, 2020

As all the suggested changes were addressed I'll proceed to merge this PR.

@octaedro octaedro added [Status] Ready to Merge and removed needs: author feedback The issue/PR needs a response from any of the parties involved in the issue. labels Sep 1, 2020
@octaedro octaedro merged commit 917ce3c into main Sep 1, 2020
Isotope automation moved this from In Progress PRs (for automation purposes) to Done Cycle 4 Sep 1, 2020
@octaedro octaedro deleted the add/3382 branch September 1, 2020 13:21
@timmyc timmyc added this to the 1.6 milestone Sep 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Isotope
  
Done Cycle 4
Development

Successfully merging this pull request may close these issues.

Data Layer: Migrate imports store to wp.data
4 participants