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

fix(compass-web): make banners dismissible COMPASS-8976 #6764

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

djechlin-mongodb
Copy link
Contributor

Description

Checklist

Motivation and Context

  • Bugfix
  • New feature
  • Dependency update
  • Misc

Open Questions

Dependents

Types of changes

  • Backport Needed
  • Patch (non-breaking change which fixes an issue)
  • Minor (non-breaking change which adds functionality)
  • Major (fix or feature that would cause existing functionality to change)

@djechlin-mongodb djechlin-mongodb added the no release notes Fix or feature not for release notes label Mar 1, 2025
@github-actions github-actions bot added the fix label Mar 1, 2025
Comment on lines 153 to 157
{!isReadonlyView &&
!enableAtlasSearchIndexes &&
localStorage.getItem(
DIMISSED_SEARCH_INDEXES_BANNER_LOCAL_STORAGE_KEY
) !== 'true' && <AtlasIndexesBanner namespace={namespace} />}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't know if you tried this locally yet, but this is currently not really working until you somehow trigger a component re-render (like navigating back and forth) because this is not wired to the component state, so when the onClick happens, nothing is triggering the component re-render and the banner stays on the screen. What you'd want is a corresponding UI state here that would be in sync with localStorage. Wrapped in a custom hook just to easier demostrate the encapsulated example:

function useDismissedState(key: string) {
  const [dismissed, setDismissed] = useState<'true' | null>(() => localStorage.getItem(key))
  const onDismissed = useCallback(() => {
    localStorage.setItem(key, 'true')
    setDismissed('true')
  }, [])
  return [dismissed === 'true', onDismissed]
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thans for catching this. I would have noticed this design mistake... eventually haha.

I'm also asking #leafygreen-ui if I can upstream this to their Banner. Your point actually stands though, I was about to send them bad sample code repeating this mistake. I think it's a good feature, I think I have time to get it in leafygreen and get it in our code, and it's somewhat lower effort if I don't have to replicate tests and stuff in two places. I could centralize to our own component which is fine, just a lot of overhead for a glorified wrapper.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I have a feeling they'd be reluctant to accept something like this, but it's worth asking! Also I kinda forgot about this, but we do have usePersistedState hook in compass-components (used exactly once 😆) that basically does what I wrote above already, so you can probably use it too here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, done with usePersistedState

@djechlin-mongodb djechlin-mongodb force-pushed the COMPASS-8976-dimissible-banners branch from 5a9501c to c4acb5c Compare March 5, 2025 02:43
@djechlin-mongodb djechlin-mongodb force-pushed the COMPASS-8976-dimissible-banners branch from c4acb5c to 02578e8 Compare March 5, 2025 02:44
@djechlin-mongodb djechlin-mongodb marked this pull request as ready for review March 6, 2025 04:34
@djechlin-mongodb djechlin-mongodb changed the title fix(compass-web) make banners dismissible COMPASS-8976 fix(compass-web): make banners dismissible COMPASS-8976 Mar 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix no release notes Fix or feature not for release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants