Skip to content

Commit 5a9501c

Browse files
use persisted storage
1 parent 5481015 commit 5a9501c

File tree

3 files changed

+42
-44
lines changed

3 files changed

+42
-44
lines changed

packages/compass-indexes/src/components/indexes/indexes.tsx

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
WorkspaceContainer,
88
css,
99
spacing,
10+
usePersistedState,
1011
} from '@mongodb-js/compass-components';
1112

1213
import IndexesToolbar from '../indexes-toolbar/indexes-toolbar';
@@ -49,38 +50,40 @@ const containerStyles = css({
4950

5051
const linkTitle = 'Atlas Search.';
5152

52-
const DIMISSED_SEARCH_INDEXES_BANNER_LOCAL_STORAGE_KEY =
53+
const DISMISSED_SEARCH_INDEXES_BANNER_LOCAL_STORAGE_KEY =
5354
'mongodb_compass_dismissedSearchIndexesBanner' as const;
5455

5556
const AtlasIndexesBanner = ({ namespace }: { namespace: string }) => {
5657
const { atlasMetadata } = useConnectionInfo();
5758
if (!atlasMetadata) {
5859
return null;
5960
}
60-
const onClose = () => {
61-
localStorage.setItem(
62-
DIMISSED_SEARCH_INDEXES_BANNER_LOCAL_STORAGE_KEY,
63-
'true'
64-
);
65-
};
61+
62+
const [dismissed, setDismissed] = usePersistedState(
63+
DISMISSED_SEARCH_INDEXES_BANNER_LOCAL_STORAGE_KEY,
64+
false
65+
);
66+
6667
return (
67-
<Banner variant="info" dismissible onClose={onClose}>
68-
<Body weight="medium">Looking for search indexes?</Body>
69-
These indexes can be created and viewed under{' '}
70-
{atlasMetadata ? (
71-
<Link
72-
href={getAtlasSearchIndexesLink({
73-
clusterName: atlasMetadata.clusterName,
74-
namespace,
75-
})}
76-
hideExternalIcon
77-
>
78-
{linkTitle}
79-
</Link>
80-
) : (
81-
linkTitle
82-
)}
83-
</Banner>
68+
!dismissed && (
69+
<Banner variant="info" dismissible onClose={() => setDismissed(true)}>
70+
<Body weight="medium">Looking for search indexes?</Body>
71+
These indexes can be created and viewed under{' '}
72+
{atlasMetadata ? (
73+
<Link
74+
href={getAtlasSearchIndexesLink({
75+
clusterName: atlasMetadata.clusterName,
76+
namespace,
77+
})}
78+
hideExternalIcon
79+
>
80+
{linkTitle}
81+
</Link>
82+
) : (
83+
linkTitle
84+
)}
85+
</Banner>
86+
)
8487
);
8588
};
8689

@@ -150,11 +153,9 @@ export function Indexes({
150153
}
151154
>
152155
<div className={indexesContainersStyles}>
153-
{!isReadonlyView &&
154-
!enableAtlasSearchIndexes &&
155-
localStorage.getItem(
156-
DIMISSED_SEARCH_INDEXES_BANNER_LOCAL_STORAGE_KEY
157-
) !== 'true' && <AtlasIndexesBanner namespace={namespace} />}
156+
{!isReadonlyView && !enableAtlasSearchIndexes && (
157+
<AtlasIndexesBanner namespace={namespace} />
158+
)}
158159
{!isReadonlyView && currentIndexesView === 'regular-indexes' && (
159160
<RegularIndexesTable />
160161
)}

packages/compass-schema/src/components/compass-schema.tsx

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
spacing,
2323
useDarkMode,
2424
WorkspaceContainer,
25+
usePersistedState,
2526
lighten,
2627
Banner,
2728
Body,
@@ -74,9 +75,6 @@ const insightsBadgeStyles = css({
7475
verticalAlign: 'middle',
7576
});
7677

77-
const DISMISSED_PERFORMANCE_ADVISOR_BANNER_LOCAL_STORAGE_KEY =
78-
'mongodb_compass_dismissedPerformanceAdvisorBanner' as const;
79-
8078
const minichartStyles = (darkMode: boolean) => {
8179
const mcBlue0 = palette.blue.light1;
8280
const mcBlue1 = lighten(0.075, mcBlue0);
@@ -344,14 +342,14 @@ const title = 'Atlas’ Performance Advisor.';
344342
const PerformanceAdvisorBanner = () => {
345343
const connectionInfo = useConnectionInfo();
346344
const track = useTelemetry();
347-
const onClose = () => {
348-
localStorage.setItem(
349-
DISMISSED_PERFORMANCE_ADVISOR_BANNER_LOCAL_STORAGE_KEY,
350-
'true'
351-
);
352-
};
345+
346+
const [dismissed, setDismissed] = usePersistedState(
347+
DISMISSED_SEARCH_INDEXES_BANNER_LOCAL_STORAGE_KEY,
348+
false
349+
);
350+
353351
return (
354-
<Banner variant="info" dismissible onClose={onClose}>
352+
<Banner variant="info" dismissible onClose={() => setDismissed(true)}>
355353
<Body weight="medium">Looking for schema anti-patterns?</Body>
356354
In its place, you may refer to Data Explorer’s performance insights{' '}
357355
<Badge className={insightsBadgeStyles} variant="blue">
@@ -422,10 +420,7 @@ const Schema: React.FunctionComponent<{
422420
}
423421
>
424422
<div className={contentStyles}>
425-
{enablePerformanceAdvisorBanner &&
426-
localStorage.getItem(
427-
DISMISSED_PERFORMANCE_ADVISOR_BANNER_LOCAL_STORAGE_KEY
428-
) !== 'true' && <PerformanceAdvisorBanner />}
423+
{enablePerformanceAdvisorBanner && <PerformanceAdvisorBanner />}
429424
{analysisState === ANALYSIS_STATE_INITIAL && (
430425
<InitialScreen onApplyClicked={onApplyClicked} />
431426
)}

packages/compass-sidebar/src/components/multiple-connections/connections-navigation.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,9 @@ const ConnectionsNavigation: React.FC<ConnectionsNavigationProps> = ({
536536
</div>
537537
<NavigationItemsFilter
538538
placeholder={
539-
isAtlasConnectionStorage ? 'Search clusters' : 'Search connections'
539+
isAtlasConnectionStorage
540+
? 'Search clusterssssss'
541+
: 'Search connections'
540542
}
541543
filter={filter}
542544
onFilterChange={onFilterChange}

0 commit comments

Comments
 (0)