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

Disabling License Banners #19116

Merged
merged 20 commits into from
Feb 14, 2023
Merged

Conversation

Monkeychip
Copy link
Contributor

@Monkeychip Monkeychip commented Feb 10, 2023

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

@Monkeychip Monkeychip added the ui label Feb 10, 2023
@Monkeychip Monkeychip added this to the 1.13.1 milestone Feb 10, 2023
@@ -9,11 +17,24 @@
* @param {string} expiry - RFC3339 date timestamp
*/

import Component from '@glimmer/component';
Copy link
Contributor Author

@Monkeychip Monkeychip Feb 13, 2023

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

@Monkeychip Monkeychip marked this pull request as ready for review February 13, 2023 18:08
Copy link
Contributor

@hashishaw hashishaw left a 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!

// 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 });
Copy link
Contributor

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)

Copy link
Contributor Author

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;

Copy link
Contributor Author

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?

Copy link
Contributor

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)
}

Copy link
Contributor Author

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.

Copy link
Contributor Author

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);
Copy link
Contributor

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?

Copy link
Contributor Author

@Monkeychip Monkeychip Feb 13, 2023

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Great context, thanks!

Copy link
Contributor

@hashishaw hashishaw left a 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 🚀

ui/app/lib/local-storage.js Show resolved Hide resolved
Copy link
Contributor

@hashishaw hashishaw left a 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 🚢

@Monkeychip Monkeychip enabled auto-merge (squash) February 14, 2023 16:48
@Monkeychip Monkeychip merged commit b1179db into main Feb 14, 2023
@Monkeychip Monkeychip deleted the ui/VAULT-13299/allow-disabling-license-banners branch February 14, 2023 17:42
@Monkeychip Monkeychip modified the milestones: 1.13.1, 1.14 Mar 29, 2023
Monkeychip added a commit that referenced this pull request Apr 18, 2023
* 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
@hellobontempo hellobontempo modified the milestones: 1.14, 1.13.2 Apr 18, 2023
Monkeychip added a commit that referenced this pull request Apr 18, 2023
* 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
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.

3 participants