Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions packages/compass-indexes/src/components/indexes/indexes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,22 @@ const containerStyles = css({

const linkTitle = 'Atlas Search.';

const DIMISSED_SEARCH_INDEXES_BANNER_LOCAL_STORAGE_KEY =
'mongodb_compass_dismissedSearchIndexesBanner' as const;

const AtlasIndexesBanner = ({ namespace }: { namespace: string }) => {
const { atlasMetadata } = useConnectionInfo();
if (!atlasMetadata) {
return null;
}
const onClose = () => {
localStorage.setItem(
DIMISSED_SEARCH_INDEXES_BANNER_LOCAL_STORAGE_KEY,
'true'
);
};
return (
<Banner variant="info">
<Banner variant="info" dismissible onClose={onClose}>
<Body weight="medium">Looking for search indexes?</Body>
These indexes can be created and viewed under{' '}
{atlasMetadata ? (
Expand Down Expand Up @@ -141,9 +150,11 @@ export function Indexes({
}
>
<div className={indexesContainersStyles}>
{!isReadonlyView && !enableAtlasSearchIndexes && (
<AtlasIndexesBanner namespace={namespace} />
)}
{!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

{!isReadonlyView && currentIndexesView === 'regular-indexes' && (
<RegularIndexesTable />
)}
Expand Down
16 changes: 14 additions & 2 deletions packages/compass-schema/src/components/compass-schema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ const insightsBadgeStyles = css({
verticalAlign: 'middle',
});

const DISMISSED_PERFORMANCE_ADVISOR_BANNER_LOCAL_STORAGE_KEY =
'mongodb_compass_dismissedPerformanceAdvisorBanner' as const;

const minichartStyles = (darkMode: boolean) => {
const mcBlue0 = palette.blue.light1;
const mcBlue1 = lighten(0.075, mcBlue0);
Expand Down Expand Up @@ -341,8 +344,14 @@ const title = 'Atlas’ Performance Advisor.';
const PerformanceAdvisorBanner = () => {
const connectionInfo = useConnectionInfo();
const track = useTelemetry();
const onClose = () => {
localStorage.setItem(
DISMISSED_PERFORMANCE_ADVISOR_BANNER_LOCAL_STORAGE_KEY,
'true'
);
};
return (
<Banner variant="info">
<Banner variant="info" dismissible onClose={onClose}>
<Body weight="medium">Looking for schema anti-patterns?</Body>
In its place, you may refer to Data Explorer’s performance insights{' '}
<Badge className={insightsBadgeStyles} variant="blue">
Expand Down Expand Up @@ -413,7 +422,10 @@ const Schema: React.FunctionComponent<{
}
>
<div className={contentStyles}>
{enablePerformanceAdvisorBanner && <PerformanceAdvisorBanner />}
{enablePerformanceAdvisorBanner &&
localStorage.getItem(
DISMISSED_PERFORMANCE_ADVISOR_BANNER_LOCAL_STORAGE_KEY
) !== 'true' && <PerformanceAdvisorBanner />}
{analysisState === ANALYSIS_STATE_INITIAL && (
<InitialScreen onApplyClicked={onApplyClicked} />
)}
Expand Down
Loading