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

Tech Story: [M3-8281] - Introduce Mock Service Worker v2 #10610

Merged
merged 86 commits into from
Aug 30, 2024

Conversation

abailly-akamai
Copy link
Contributor

@abailly-akamai abailly-akamai commented Jun 25, 2024

Description 📝

🔧 This PR implements the first iteration of MSW tooling V2.

🙏 I apologize for throwing 5000+ lines at you all. But hey, we may all benefit from this in the near future. It was already a bit too late to break it down when inherited then it grew some more. Apart for a few files, it is very contained code, and not bundled with our production application. To that effect it can be imperfect (and it is) and is very subjected to iteration and contributions.

👀 Please read the whole PR description before reviewing to manage certain expectations - especially regarding:

  • the completeness of the new feature
  • the contributions needed to grow it).

As we are reducing our reliance on ALPHA (lower env getting deprecated), development in Cloud Manager needs a better way of emulating what developing against a real API feels like. Our previous MSW tooling, while very helpful, is very static and lacks model relationships among other things (aka, update this volume which should update this linode).
This is a problem when moving forward with a feature we only can assume the behavior of, especially with the reactivity that comes with react-query.

While big and fairly complex, this contribution only builds the foundation for a full suite of tools aimed to facilitate local development for existing and new features. It features current best practices for building upon it by providing both simple and complex examples on how to mock our features.

Warning

This is (and will remain for a while) very much a work in progress! There will be bugs, which is acceptable considering this is a non-public facing development tool. I encourage contributions and engagement for the team who will end up benefiting greatly from fine tuning this suite. However, it needs to be used in order to grow, and for that reason can't be nursed forever, and needs to be merged as an in-progress suite. As such I also encourage contributions as feedback!

What it does:

  • revamp the dev tools
  • implements MOCK presets and CRUD-like mocking
  • implements few convenient presets (API state, accounts, regions)
  • implements few handlers partially (linodes, volumes, placement groups)
  • sets up persistent mock data via indexedDB
  • implements basic sorting and paginating mock data
  • implements a seeding system for quick testing and emulating large accounts
  • implements a custom API response time handler
  • implements CRUD event tooling
  • updates documentation

What is next

  • implements more handlers for various content types as needed (we want to eventually deprecate legacy handlers)
  • implement seeding for more content types
  • improve reliability, stability and code quality
  • team contribution!!

Note

While pushing forward a new approach, legacy MSW tooling is available as a baseline preset. We do want to write any new handlers in the new CRUD mode, but we can still use old tooling as "read-only", at least until the new suite is mature and well rounded.

CREDITS for @jdamore-linode for the initial effort and pushing for a brave new world 🤟

Preview 📷

Screenshot 2024-08-07 at 21 26 59

How to test 🧪

Best way is to play with the tool and read along the documentation!

💡 I plan to pick and choose what feedback can be implemented as this point, since the PR is already large. Important bugs will be addressed, feature requests will be captured for subsequent tickets.

Important

Besides new tooling bugs, these are the two items we want to be confident about:

  • not breaking existing MSW tools
  • not introducing any issue bleeding to the production environment
  • documentation. while far from exhaustive (this will need a lot of iteration), it needs to be accurate in its initial rendition

As an Author I have considered 🤔

Check all that apply

  • 👀 Doing a self review
  • ❔ Our contribution guidelines
  • 🤏 Splitting feature into small PRs
  • ➕ Adding a changeset
  • 🧪 Providing/Improving test coverage
  • 🔐 Removing all sensitive information from the code and PR description
  • 🚩 Using a feature flag to protect the release
  • 👣 Providing comprehensive reproduction steps
  • 📑 Providing or updating our documentation
  • 🕛 Scheduling a pair reviewing session
  • 📱 Providing mobile support
  • ♿ Providing accessibility support

@abailly-akamai abailly-akamai self-assigned this Jun 27, 2024
@abailly-akamai abailly-akamai force-pushed the M3-8281 branch 3 times, most recently from e464335 to c0ee5b6 Compare July 5, 2024 16:41
@abailly-akamai abailly-akamai added Help Wanted Teamwork makes the dream work! and removed Help Wanted Teamwork makes the dream work! labels Aug 7, 2024
@abailly-akamai abailly-akamai changed the title poc: [M3-8281] - MSW Presets change: [M3-8281] - MSW V2 Aug 7, 2024
@@ -1,6 +1,7 @@
import { COUNTRY_CODE_TO_CONTINENT_CODE } from './constants';

export type Capabilities =
| 'Backups'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

An interesting omission which @jdamore-linode added initially. Def returned by the /regions endpoint. Not adding a changeset for it since it's not very impacting.

</div>
<div className="dev-tools__tool__footer">
<div className="dev-tools__button-list">
<button onClick={resetFlags}>Reset to LD DEV Defaults</button>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mostly things moving around

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree with switching Grids to divs -- no need for fancy themed components in devtools

</button>
</div>
</div>
</div>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a pretty large file, which could be broken down further (already exported some components, constants, types and methods)

],
regions: [...initialContext.regions, ...(seedContext?.regions || [])],
volumes: [...initialContext.volumes, ...(seedContext?.volumes || [])],
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This could be certainly be improved and that's on my list. In general this file is dense, complex and lacking optimization which I plan to work on and test. Out of scope for this first rendition as this isn't client facing code.

if (container) {
const root = handleRoot(container);
root.render(<Main />);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

See handleRoot() definition. This fix is to circumvent HMR issues while developing Dev Tools. It should be non-impacting but need to point out the change in self review since it touches our APP entry point and needs to be looked at accordingly.

@abailly-akamai abailly-akamai marked this pull request as ready for review August 7, 2024 15:52
@abailly-akamai abailly-akamai requested a review from a team as a code owner August 7, 2024 15:52
@abailly-akamai abailly-akamai requested review from bnussman-akamai and carrillo-erik and removed request for a team August 7, 2024 15:52
@abailly-akamai abailly-akamai changed the title change: [M3-8281] - MSW V2 tech-story: [M3-8281] - Introduce Mock Service Worker v2 Aug 7, 2024
@abailly-akamai abailly-akamai changed the title tech-story: [M3-8281] - Introduce Mock Service Worker v2 Tech Story: [M3-8281] - Introduce Mock Service Worker v2 Aug 7, 2024
@abailly-akamai
Copy link
Contributor Author

one very small thing with the CRUD preset when deleting Linodes - there was a very long delay for the Linode to disappear from the page in comparison with volumes/placement groups. Assuming this is because we first have to wait for the msw db to 'shut down' the Linode - is there a way to shorten the delay, or is that not in scope for this PR?

@coliu-akamai it is because we simulate a shut down + corresponding eventing so yeah it takes extra time. may be worth adjusting this later on

@abailly-akamai abailly-akamai merged commit 518a901 into linode:develop Aug 30, 2024
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants