Skip to content
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

Shipping Rates Pre-Fetch #385

Merged
merged 100 commits into from
Mar 30, 2019
Merged

Shipping Rates Pre-Fetch #385

merged 100 commits into from
Mar 30, 2019

Conversation

walmat
Copy link
Owner

@walmat walmat commented Mar 14, 2019


name: Shipping Rates Pre-Fetch
about: This PR implements a way to fetch and store shipping rates for sites using a certain profile.


Changes

  • Moved around a couple things:
    • Captcha buttons to <Navbar />
    • Delays to tasks "bulk actions" area
  • Added shipping manager sub-component in the Settings page that can be used to fetch shipping rates for the selected site using a billing profile (on a specified product, of course)
    • These rates are shown when you load in a profile inside of the Profiles page (or a No shipping rates message if none exist)

TODO

  • Attach and iron out actions/middleware/reducers for the shipping manager component
    • Action redux thunk chain
    • Middleware validation
    • Reducer logic
  • Fix state logic for shipping rates component
    • Show fetched rates based on selectedSite
    • Show rate in the disabled input based on the name of rate selected
  • Unit tests for shipping manager, shipping rates, and the moved components
  • Increase code coverage to >95% (if possible)

Screen Shot 2019-03-22 at 2 42 19 AM

Checks

  • CI passes
  • Coverage (<2%∆)
  • Manual Checks
    • From a non-fresh app state:
    • test that migration to 0.2.1 happens without errors
      • able to navigate to the 3 pages properly with no errors
      • able to edit all fields with errors mapping shown (if exists)
    • able to create tasks, save/update/remove profiles, edit monitor/error delays.
    • able to open captcha windows / close captcha windows
    • able to fetch rates properly
    • tasks work:
      • with prefetch rate
      • without prefetch rate
    • copying profiles doesn't copy shipping rates
    • removing profiles removes them from Create Tasks && Shipping Manager
    • From a fresh app state:
    • test that migration to 0.2.1 happens without errors
      • able to navigate to the 3 pages properly with no errors
      • able to edit all fields with errors mapping shown (if exists)
    • able to create tasks, save/update/remove profiles, edit monitor/error delays.
    • able to open captcha windows / close captcha windows
    • able to fetch rates properly
    • tasks work:
      • with prefetch rate
      • without prefetch rate
    • copying profiles doesn't copy shipping rates
    • removing profiles removes them from Create Tasks && Shipping Manager

fixes #381
fixes #295
fixes #343
fixes #89

@walmat walmat added type:enhancement New feature or request tag:help wanted Extra attention is needed area:frontend Related to Nebula's Frontend Electron app area:task-runner Related to Nebula's Task Runner package priority:urgent Issues that need to be solved right away labels Mar 14, 2019
@walmat walmat added this to the Beta 7 Release milestone Mar 14, 2019
@walmat walmat requested a review from pr1sm March 14, 2019 03:49
Copy link
Collaborator

@pr1sm pr1sm left a comment

Choose a reason for hiding this comment

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

First pass done, mostly #nitpick/small changes

Nice work overall!

packages/frontend/src/profiles/paymentFields.jsx Outdated Show resolved Hide resolved
packages/frontend/src/profiles/profiles.scss Outdated Show resolved Hide resolved
packages/frontend/src/profiles/shippingRates.jsx Outdated Show resolved Hide resolved
packages/frontend/src/profiles/shippingRates.jsx Outdated Show resolved Hide resolved
packages/frontend/src/profiles/shippingRates.jsx Outdated Show resolved Hide resolved
packages/frontend/src/tasks/tasks.jsx Outdated Show resolved Hide resolved
packages/frontend/src/utils/definitions/profiles/rates.js Outdated Show resolved Hide resolved
packages/task-runner/src/shopify/classes/parsers/parser.js Outdated Show resolved Hide resolved
Copy link
Owner Author

@walmat walmat left a comment

Choose a reason for hiding this comment

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

quick follow up

Copy link
Collaborator

@pr1sm pr1sm left a comment

Choose a reason for hiding this comment

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

another pass, just a few more #nitpick changes

packages/frontend/src/profiles/profiles.jsx Outdated Show resolved Hide resolved
packages/frontend/src/profiles/shippingRates.jsx Outdated Show resolved Hide resolved
packages/frontend/src/profiles/shippingRates.jsx Outdated Show resolved Hide resolved
packages/frontend/src/profiles/shippingRates.jsx Outdated Show resolved Hide resolved
packages/frontend/src/profiles/shippingRates.jsx Outdated Show resolved Hide resolved
@walmat
Copy link
Owner Author

walmat commented Mar 20, 2019

I think this needs to be rabased onto b1.0.0-beta.7 as soon as possible. I think the major rebase will include me having to move all my definitions > migrators/ and then write the migration pattern for it as well. Can you assist with this if you get time @pr1sm? Sorry to bug you while you're away..

Done!

Copy link
Collaborator

@pr1sm pr1sm 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 looking pretty good -- nice progress on the unit tests! Just finished another pass with some more comments.

Copy link
Collaborator

@pr1sm pr1sm left a comment

Choose a reason for hiding this comment

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

Just a quick comment on the status deregistering, otherwise this looks good!

@walmat walmat marked this pull request as ready for review March 28, 2019 04:48
@walmat
Copy link
Owner Author

walmat commented Mar 28, 2019

Not sure if this covers #89 as well, or if you want to leave that open until we get the server stuff implemented.

@walmat
Copy link
Owner Author

walmat commented Mar 29, 2019

Okay I think the only thing that is "left" is the notification manager. I've fixed the graceful shutdown and added some error proofing in the task runner side of things. Let me know what else you think should be lumped into this! @pr1sm

@walmat walmat requested a review from pr1sm March 29, 2019 17:11
@pr1sm pr1sm dismissed their stale review March 29, 2019 19:39

old review

Matthew Wall and others added 3 commits March 29, 2019 16:35
This commit updates the preload script to add a
cancellation feature the shipping rates runner.
This cancellation allows the srr to be stopped
in the task manager if it is no longer needed.
This commit updates the preload script to notify the caller
of the stop shipping request whether or not the cleanup
shipping action should be dispatched. The settings actions
are updated to handle this and cleanup the shipping redux
state accordingly.
Copy link
Collaborator

@pr1sm pr1sm left a comment

Choose a reason for hiding this comment

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

Just one small comment, otherwise I think this is good! Great job on increasing test coverage!

pr1sm and others added 2 commits March 29, 2019 16:58
The constructor for the Shipping Rates Runner has been
updated to explicitly reference parameters. This should
prevent initialization bugs where too many/too few
parameters are passed and the type parameter gets
misplaced in the parameter list.
Copy link
Collaborator

@pr1sm pr1sm left a comment

Choose a reason for hiding this comment

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

Code looks good and Manual Checks pass! Nice job 🥇

@walmat
Copy link
Owner Author

walmat commented Mar 30, 2019

Code looks good and Manual Checks pass! Nice job 🥇

Ready for merge? 😳

@pr1sm
Copy link
Collaborator

pr1sm commented Mar 30, 2019

Yep

@walmat
Copy link
Owner Author

walmat commented Mar 30, 2019

merging...

@walmat walmat merged commit 8848d32 into b1.0.0-beta.7 Mar 30, 2019
@walmat walmat deleted the issue_381 branch March 30, 2019 00:26
pr1sm pushed a commit that referenced this pull request Mar 30, 2019
* start on shipping manager refactor

* added action/reducers

* more state changes + UI updates

* progress on shipping rates

* state progress

* small state changes

* small changes to settings actions

* small changes

* pr changes

* pr changes

* Update packages/frontend/src/state/reducers/profiles/profileReducer.js

* Update packages/frontend/src/state/reducers/profiles/profileReducer.js

* rm unnecessary error state declaration

* filter names and rate input autofilled based on selection done

* small fixes

* Update packages/frontend/src/profiles/shippingRates.jsx

Co-Authored-By: walmat <matthew.wallt@gmail.com>

* Update packages/frontend/src/profiles/shippingRates.jsx

Co-Authored-By: walmat <matthew.wallt@gmail.com>

* pr changes

* some layout changes + delete/clear buttons

* added delete rate action, needs work still

* fixed delete rate action/reducer

* rm unnecessary id field

* attach settings middleware for other fields

* added webhook regex and errors map

* fixed product validator error mapping

* Store the selected shipping rate

This commit updates the checkout class to keep track of the selected shipping rate. This will be used by a subclass of the Task Runner to fetch the cheapest shipping rate.

* Refactor Run Loop to a single function

This commit updates the task runner to use a single function in the start method to handle all loop logic. This will allow subclasses to override the default behavior if needed.

* Add Shipping Rates Runner

This commit adds a new type of runner that looks for shipping rates from a specific site. This allows the rates to be "pre-fetched" and then used in actual task runs.

The ShippingRatesRunner is only supported on api checkout methods at this time. Attempting to create the shipping rates runner for a frontend checkout site will cause it to throw an error.

The run loop has been modified to stop if the super implementation errors out, or if the shipping rates have been received.

Further, all messages emitted from this runner will be attached with a special type flag. This will allow the frontend to tell that this runner is not a normal runner.

* Fix lint

This commit fixes a lint caused by an unused variable.

* small css tweaks with cursor:pointer

* Generalize Runner Type Tag

This commit updates the TaskRunner to add a type property. A set of constants has been defined for further use if needed.

Now, payloads emitted from the runner will include it's type. This prevents the need for the ShippingRatesRunner to inject it in using a method override.

Finally, a special "done" flag is emitted when the task runner stops. This will allow the frontend to easily determine when the runner has stopped.

* progress on settings middleware

* separated middleware, added more action chains for fetching shipping rates

* fixed rates proptypes

* small naming fix

* Update Naming

This commit updates the naming of the runner type to be more consistent with the rest of the package. Instead of ShippingRate, the name is now ShippingRates.

* Add Support for Starting the ShippingRatesRunner

This commit updates the managers, as well as the runner scripts to create an instances of the ShippingRatesRunner based on an incoming type. This allows TaskManagers to start ShippingRatesRunners.

The change is backwards compatible and passing no specific type will by default spawn a TaskRunner. This means that the current usage in the Frontend is unaffected.

* Move Runners to a Separate Folder

This commit restructures the task-runner source code structure to group runners together in a separate folder. This keeps the top level clean if/when more runners are added.

* Export Task Runner Types

This commit updates the exported object of the task-runner package so the frontend can reference the specific type it wants to spawn by variable instead of by value.

* Fix Run Loop Bug

This commit fixes a typo where the run loop was not invoked.

* Update Task Status when emitting message

This commit updates the emit task event to update the contexts end status with the message. This allows custom messages to be reused when reaching an end-runner state (aborted, errored, finished).

When handling captchas, the context status is cleared to show the generic end state message.

* Switch to use end runner states instead of generic Stopped

This commit updates the task-runner sub processes to use a distinct end-runner state (Aborted, Errored, Finished) instead of using the generic Stopped event. This provides more context to the specific end state, but also allows the "done" payload to be properly emitted in all cases.

* Fixes to existing test failures

* test progress, broke some others in the progress...

* settings actions tests

* added shipping manager component tests

* pulled in srr changes

* rm unnecessary comments

* some test fixes

* split out shipping reducer

* small change

* revert init state for rates

* added migration pattern

* added random size default in preload

* revert type parameter

* fixed a lot of tests..

* test fixes, code coverage increase

* fix lint, fix scss

* fix lint

* task list reducer test coverage increase

* shipping rates component tests

* test coverage improvements

* increase test coverage

* more code coverage increased

* bug fixes with srr

* rm unused file

* test fix

* added profile reducer

* fixed test

* small code coverage increased

* small bug fix with copy task

* pr changes, test updates

* Update packages/frontend/src/state/migrators/v0.2.0/index.js

Co-Authored-By: walmat <matthew.wallt@gmail.com>

* lint fix

* filtered out shipping rate runner status messages

* task event registration handler split into multiple handlers

* added selectedProfile and currentProfile reducer fixes, and implemented task runner using the shipping rate

* test fix progress

* lint fix

* fix deregister function

* migration changes

* prevented srr from handling restocks

* Add Setup and Cleanup actions for Shipping Rates

This commit adds private setup/cleanup actions for
fetching shipping rates so the reducer can correctly
enable/disable the shipping rates button when there
is a run in progress

* Add Shipping Status Flag

This commit updates the shipping manager definitions
to add a status flag that will be updated by the setup and
cleanup settings actions.

A migrator (v0.2.1) was added to initialize the status flag
if it wasn't previously set. Tests were added for the migrator.

* Update Settings Reducer to handle actions

This commit updates the settings reducer to handle the
setup/cleanup shipping actions. Tests have been added
to ensure proper function.

* Disable Fetch Shipping Rates Button when in progress

This commit updates the shipping manager component to
disable/reenable the fetch button when the shipping manager
is running. This should prevent multiple runs of the shipping
manager from happening.

Tests were added to ensure the component renders properly.

* styling updates, code coverage, and render bug fixes

* bug fix w/ srr skipping fetching rates step

* added price field in

* srr caching rates bug fixed

* rm debug statements

* fixed shipping site username/password resetting bug

* fixed invalid proptype error

* fixed graceful shutdown of srr

* added some more code coverage

* on stop srr

* Implement Cancel feature for SRR

This commit updates the preload script to add a
cancellation feature the shipping rates runner.
This cancellation allows the srr to be stopped
in the task manager if it is no longer needed.

* Update Stop Shipping to Cleanup Shipping State

This commit updates the preload script to notify the caller
of the stop shipping request whether or not the cleanup
shipping action should be dispatched. The settings actions
are updated to handle this and cleanup the shipping redux
state accordingly.

* Address PR Comment

The constructor for the Shipping Rates Runner has been
updated to explicitly reference parameters. This should
prevent initialization bugs where too many/too few
parameters are passed and the type parameter gets
misplaced in the parameter list.

* code coverage increased
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:frontend Related to Nebula's Frontend Electron app area:task-runner Related to Nebula's Task Runner package priority:urgent Issues that need to be solved right away tag:help wanted Extra attention is needed type:enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants