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

feat: utilize generics in UserPreferencesService #504

Merged
merged 19 commits into from
Nov 28, 2024
Merged

Conversation

danielsiemens
Copy link
Collaborator

@danielsiemens danielsiemens commented Nov 25, 2024

Summary

First off, a big BIG thank you to @gmarques-mParticle for his assistance in making this properly generic. You're the man!

  • Replaces UserPreference with UserPreferencePerScope
  • Thanks to GM, this is now generic by user preference key. This allows different preferences to specify different data structures. This change should not break existing uses in CDP/Analytics, but we will write new unit tests on those platforms to confirm
  • "Why not use localStorage like recently-viewed in nancy?" -> Because we know that we want to add a backend to UPS in 2025, and it makes sense that beyond just a simple toggle we may want to store more complex data types as well. Replacing the optedIn attribute outright would break existing usage patterns, and we don't want users forced to re-opt in!
  • Updates unit tests

Testing Plan

  • Was this tested locally? If not, explain why.
  • {explain how this has been tested, and what, if any, additional testing should be done}

+80% coverage on user-preference related files

Reference Issue (For mParticle employees only. Ignore if you are an outside contributor)

@@ -52,6 +52,7 @@
"@types/multer": "1.4.12",
"@typescript-eslint/eslint-plugin": "6.19.0",
"@vitejs/plugin-react": "4.2.1",
"@vitest/coverage-v8": "1.3.1",
Copy link
Collaborator Author

@danielsiemens danielsiemens Nov 25, 2024

Choose a reason for hiding this comment

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

Added so we can check unit test coverage with vitest. This is a dev dependency

Copy link

github-actions bot commented Nov 25, 2024

PR Preview Action v1.4.8
Preview removed because the pull request was closed.
2024-11-28 21:23 UTC

Copy link
Collaborator

@tibuurcio tibuurcio left a comment

Choose a reason for hiding this comment

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

Summary already goes a bit into the choices made here. From our chats I know you've tried a generics approach before this solution @danielsiemens, do you mind going over that context and some of the challenges you faced? Documenting it for posterity.

@tibuurcio
Copy link
Collaborator

tibuurcio commented Nov 26, 2024

Would also be interesting to state some of the alternatives to the current approach we discussed sync yesterday. Just cause there's a lot of ways to accomplish what we want here and besides the localStorage approach the PR doesn't convey the amount of thought and tradeoff analysis we put into it 😅

If possible I'd state a few options and highlight the one we decided to go with!

@danielsiemens danielsiemens changed the title feat: add data attribute to UserPreference feat: utilize generics in UserPreferencesService Nov 27, 2024
@danielsiemens danielsiemens removed the request for review from gabrielmarquesf November 27, 2024 15:37
Copy link
Collaborator

@tibuurcio tibuurcio left a comment

Choose a reason for hiding this comment

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

Now that I'm thinking of it, will this update require changes in tha platforms implementations once it reaches a new Aquarium version? If yes, then that's technically a breaking change 🥲

This is also a sensitive part of the application, I know we have tests here but usage in the platforms is a bit different. Can we have a feature version released for this and try a POC of it in the platforms just to see how it goes?

We don't usually do proper semver breaking changes in Aquarium currently. Maybe too extreme but would it be worth to duplicate the implementation? Probably not, but just raising the idea.

Either way nice work @danielsiemens and @gmarques-mParticle

@gmarques-mParticle
Copy link
Contributor

Now that I'm thinking of it, will this update require changes in tha platforms implementations once it reaches a new Aquarium version? If yes, then that's technically a breaking change 🥲

This is also a sensitive part of the application, I know we have tests here but usage in the platforms is a bit different. Can we have a feature version released for this and try a POC of it in the platforms just to see how it goes?

We don't usually do proper semver breaking changes in Aquarium currently. Maybe too extreme but would it be worth to duplicate the implementation? Probably not, but just raising the idea.

Either way nice work @danielsiemens and @gmarques-mParticle

I like the idea to duplicate the implementation, so we can have a FF on CDP to validate it in the consumer side

@tibuurcio
Copy link
Collaborator

Now that I'm thinking of it, will this update require changes in tha platforms implementations once it reaches a new Aquarium version? If yes, then that's technically a breaking change 🥲
This is also a sensitive part of the application, I know we have tests here but usage in the platforms is a bit different. Can we have a feature version released for this and try a POC of it in the platforms just to see how it goes?
We don't usually do proper semver breaking changes in Aquarium currently. Maybe too extreme but would it be worth to duplicate the implementation? Probably not, but just raising the idea.
Either way nice work @danielsiemens and @gmarques-mParticle

I like the idea to duplicate the implementation, so we can have a FF on CDP to validate it in the consumer side

hey @gmarques-mParticle, both @danielsiemens and I validated the changes in the platforms locally. Discussion is in the slack thread in PR canvas. I'd like your input again here. We have a separate PR in Nancy to perform the changes to the UPS implementation, so IMO with that plus the unit tests that Dan implemented in Nancy, as well as the Test Plan in the PR, we should be good for keeping only a single implementation.

The important part that worried me is we were able to verify backwards compatibility is maintained between the implementations, both by unit and manual testing.

Given that I'd suggest we do not duplicate...

Copy link
Collaborator

@tibuurcio tibuurcio left a comment

Choose a reason for hiding this comment

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

This has been tested both in Aquarium but also in the platforms and we are good to go. This will also be thouroughfully tested in the platform PR introducing it.

@danielsiemens
Copy link
Collaborator Author

Maintaining two implementations would have a much higher likelihood of causing bugs when we can verify through unit tests that the legacy cookies are still valid and working. I agree with @tibuurcio that we should not have a duplicate implementation.
cc @gmarques-mParticle

@danielsiemens danielsiemens removed the request for review from Seebiscuit November 28, 2024 21:20
@danielsiemens danielsiemens merged commit 4838a86 into main Nov 28, 2024
9 checks passed
mparticle-automation added a commit that referenced this pull request Nov 28, 2024
# [1.36.0](v1.35.0...v1.36.0) (2024-11-28)

### Bug Fixes

* typography component updates ([#497](#497)) ([d32d390](d32d390))

### Features

* add abSplit icon ([#499](#499)) ([8776f1c](8776f1c))
* add notificationSubscriptions icon ([#505](#505)) ([b4976bc](b4976bc))
* utilize generics in UserPreferencesService  ([#504](#504)) ([4838a86](4838a86))
@mparticle-automation
Copy link
Collaborator

🎉 This PR is included in version 1.36.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants