-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Disabling License Banners #19116
Disabling License Banners #19116
Conversation
@@ -9,11 +17,24 @@ | |||
* @param {string} expiry - RFC3339 date timestamp | |||
*/ | |||
|
|||
import Component from '@glimmer/component'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved the imports above documentation to match the component template
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good start! I think this will be much easier to read (and eliminate extra dependencies) if we organize the dismissals by key rather than the object value. Let me know if you have any questions or want to pair on this!
ui/app/components/license-banners.js
Outdated
// If nothing is saved in localStorage or the user has updated their Vault version, do not dismiss any of the banners. | ||
const localStorageLicenseBannerObject = localStorage.getItem('licenseBanner'); | ||
if (!localStorageLicenseBannerObject || localStorageLicenseBannerObject.version !== this.currentVersion) { | ||
localStorage.setItem('licenseBanner', { dismissType: '', version: this.currentVersion }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the logic here could be simplified by storing the dismissal at a variable key, rather than storing an object that has to be parsed and reasoned about. So for example, if I'm on version 1.12.2, this component would check for a value (any value, really) at licenseBanner-warning-1.12.2
The get and set calls would be able to use a key variable that is calculated based on the version:
const warningBannerKey = `licenseBanner-warning-${this.currentVersion}`
const dismissedWarning = localStorage.getItem(warningBannerKey)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea. Let me know what you think of the changes. Not exactly your suggestion, but a similar concept.
|
||
@tracked warningDismissed; | ||
@tracked expiredDismissed; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thought about this approach, is that localStorage will continue to store past version dismissals. Thinking through this, there really isn't a way for me to get the previous version so I'd have to do some string finding to remove a past version's (dismiss-license-banner-${this.currentVersion}
). Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true. We could have a helper in the localStorage lib which goes through each of the localStorage values and matches on the first part of the string, then removes the matching ones
const relevantKeys = Object.keys(localStorage).filter(str => str.startsWith("dismiss-license-banner")
relevantKeys.forEach(key => {
localStorage.removeItem(key)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea. I'll add that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a method to lib/local-storage. Let me know what you think. (see row 51 here and the new method on local-storage.js).
@action | ||
dismissBanner(dismissAction) { | ||
// updates localStorage and then updates the template by calling updateDismissType | ||
localStorage.setItem(`dismiss-license-banner-${this.currentVersion}`, dismissAction); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm understanding this correctly, if I've previously dismissed a warning and I come back and dismiss an expired, we will replace the localStorage value so that the warning will be able to show up again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. The key here is that both will never show up at the same time. So let's say you dismissed a warning, but then you let your license expire, the expired license will show. If we dismiss that, then next time a warning should display it will.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great context, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! I have one more request 🙏
Can we add a few test scenarios covering the new local-storage method, including it behaves correctly when:
- nothing in localstorage
- extra things in localstorage (those should not be removed)
- keeping a specified key that would otherwise be removed
Once that's done let's ship it 🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approval for once tests are in 🚢
* work in progress: got the expired banner set with license check * wip: got the logic for both banners, need to test and write tests * add notes * prep for test writing * test coverage * add changelog * clean up * clarify dismissTypes and conditionals * updates * update comment * update comment * address pr comments * update test * small naming change * small naming changes * clean localStorage * comment clean up * another comment clean up * remove meep * add test coverage for new method in localStorage
* work in progress: got the expired banner set with license check * wip: got the logic for both banners, need to test and write tests * add notes * prep for test writing * test coverage * add changelog * clean up * clarify dismissTypes and conditionals * updates * update comment * update comment * address pr comments * update test * small naming change * small naming changes * clean localStorage * comment clean up * another comment clean up * remove meep * add test coverage for new method in localStorage
This PR allows the
licenseBanners
to be dismissed and records those preferences in localStorage. Once a banner is dismissed, it will not show again unless a user clears their localStorage, or the vault version changes.license.mov