Skip to content

Commit f0c11ed

Browse files
authored
fix(indexes): add namespace to the URL params for Atlas Search link COMPASS-8917 (#6707)
* fix(indexes): add namespace to the URL params for Atlas Search link * chore(indexes): remove unused dep
1 parent 3dd51f0 commit f0c11ed

File tree

5 files changed

+47
-17
lines changed

5 files changed

+47
-17
lines changed

package-lock.json

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-indexes/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@
7676
"@mongodb-js/compass-logging": "^1.6.0",
7777
"@mongodb-js/compass-telemetry": "^1.4.0",
7878
"@mongodb-js/compass-workspaces": "^0.31.0",
79-
"@mongodb-js/connection-storage": "^0.26.0",
8079
"@mongodb-js/mongodb-constants": "^0.10.0",
8180
"@mongodb-js/shell-bson-parser": "^1.2.0",
8281
"bson": "^6.10.1",

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,24 @@ const containerStyles = css({
4848
});
4949

5050
const linkTitle = 'Atlas Search.';
51-
const AtlasIndexesBanner = () => {
51+
52+
const AtlasIndexesBanner = ({ namespace }: { namespace: string }) => {
5253
const { atlasMetadata } = useConnectionInfo();
54+
if (!atlasMetadata) {
55+
return null;
56+
}
5357
return (
5458
<Banner variant="info">
5559
<Body weight="medium">Looking for search indexes?</Body>
5660
These indexes can be created and viewed under{' '}
5761
{atlasMetadata ? (
58-
<Link href={getAtlasSearchIndexesLink(atlasMetadata)} hideExternalIcon>
62+
<Link
63+
href={getAtlasSearchIndexesLink({
64+
clusterName: atlasMetadata.clusterName,
65+
namespace,
66+
})}
67+
hideExternalIcon
68+
>
5969
{linkTitle}
6070
</Link>
6171
) : (
@@ -66,6 +76,7 @@ const AtlasIndexesBanner = () => {
6676
};
6777

6878
type IndexesProps = {
79+
namespace: string;
6980
isReadonlyView?: boolean;
7081
regularIndexes: Pick<RegularIndexesState, 'indexes' | 'error' | 'status'>;
7182
searchIndexes: Pick<SearchIndexesState, 'indexes' | 'error' | 'status'>;
@@ -88,6 +99,7 @@ const indexesContainersStyles = css({
8899
});
89100

90101
export function Indexes({
102+
namespace,
91103
isReadonlyView,
92104
regularIndexes,
93105
searchIndexes,
@@ -130,7 +142,7 @@ export function Indexes({
130142
>
131143
<div className={indexesContainersStyles}>
132144
{!isReadonlyView && !enableAtlasSearchIndexes && (
133-
<AtlasIndexesBanner />
145+
<AtlasIndexesBanner namespace={namespace} />
134146
)}
135147
{!isReadonlyView && currentIndexesView === 'regular-indexes' && (
136148
<RegularIndexesTable />
@@ -148,11 +160,13 @@ export function Indexes({
148160
}
149161

150162
const mapState = ({
163+
namespace,
151164
isReadonlyView,
152165
regularIndexes,
153166
searchIndexes,
154167
indexView,
155168
}: RootState) => ({
169+
namespace,
156170
isReadonlyView,
157171
regularIndexes,
158172
searchIndexes,

packages/compass-indexes/src/utils/atlas-search-indexes-link.spec.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@ import { getAtlasSearchIndexesLink } from './atlas-search-indexes-link';
33

44
describe('getAtlasSearchIndexesLink', function () {
55
it('returns the correct link with clusterName', function () {
6-
expect(getAtlasSearchIndexesLink({ clusterName: 'abc' })).to.equal(
7-
'#/clusters/atlasSearch/abc'
8-
);
9-
expect(getAtlasSearchIndexesLink({ clusterName: '' })).to.equal(
10-
'#/clusters/atlasSearch/'
11-
);
6+
expect(
7+
getAtlasSearchIndexesLink({ clusterName: 'abc', namespace: 'foo.bar' })
8+
).to.equal('#/clusters/atlasSearch/abc?database=foo&collectionName=bar');
129
});
1310

1411
it('encodes the clusterName', function () {
15-
expect(getAtlasSearchIndexesLink({ clusterName: 'a b c' })).to.equal(
16-
'#/clusters/atlasSearch/a%20b%20c'
12+
expect(
13+
getAtlasSearchIndexesLink({
14+
clusterName: 'a b c',
15+
namespace: 'b u z.a@b@c',
16+
})
17+
).to.equal(
18+
'#/clusters/atlasSearch/a%20b%20c?database=b%20u%20z&collectionName=a%40b%40c'
1719
);
1820
});
1921
});
Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
1-
import type { AtlasClusterMetadata } from '@mongodb-js/connection-storage/renderer';
1+
import toNS from 'mongodb-ns';
22

3+
/**
4+
* List to Atlas search indexes page. Supports certain query params that can be
5+
* part of hash url: https://github.com/10gen/mms/blob/ba8025a4be58591cea0299ab500d2cf06e187f95/client/packages/project/nds/clusters/components/AtlasSearch/routeUtil.ts#L20-L30
6+
*/
37
export function getAtlasSearchIndexesLink({
48
clusterName,
5-
}: Pick<AtlasClusterMetadata, 'clusterName'>) {
6-
return `#/clusters/atlasSearch/${encodeURIComponent(clusterName)}`;
9+
namespace,
10+
}: {
11+
clusterName: string;
12+
namespace: string;
13+
}) {
14+
const { database, collection } = toNS(namespace);
15+
// Atlas Search URL params are parsed from hash, they are not real search
16+
// params on a URL, appended at the end of hash part
17+
let url = `#/clusters/atlasSearch/${encodeURIComponent(clusterName)}`;
18+
if (database && collection) {
19+
url +=
20+
`?database=${encodeURIComponent(database)}` +
21+
`&collectionName=${encodeURIComponent(collection)}`;
22+
}
23+
return url;
724
}

0 commit comments

Comments
 (0)