Skip to content

Commit 51ab01e

Browse files
committed
fix: merge stats change to branch
2 parents 73b2bd1 + e09d426 commit 51ab01e

File tree

9 files changed

+89
-209
lines changed

9 files changed

+89
-209
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ describe('IndexesToolbar Component', function () {
4444
onCreateSearchIndexClick={() => {}}
4545
namespace=""
4646
showAtlasSearchLink={false}
47+
serverVersion={'8.0.11'}
4748
{...props}
4849
/>
4950
</PreferencesProvider>

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

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
SegmentedControlOption,
2222
} from '@mongodb-js/compass-components';
2323
import { useConnectionInfo } from '@mongodb-js/compass-connections/provider';
24+
import semver from 'semver';
2425

2526
import type { RootState } from '../../modules';
2627
import { createSearchIndexOpened } from '../../modules/search-indexes';
@@ -53,6 +54,19 @@ const createIndexButtonContainerStyles = css({
5354
width: 'fit-content',
5455
});
5556

57+
const MIN_SEARCH_INDEX_MANAGEMENT_SERVER_VERSION = '6.0.7';
58+
59+
const serverSupportsSearchIndexManagement = (serverVersion: string) => {
60+
try {
61+
return semver.gte(
62+
serverVersion,
63+
MIN_SEARCH_INDEX_MANAGEMENT_SERVER_VERSION
64+
);
65+
} catch {
66+
return false;
67+
}
68+
};
69+
5670
type IndexesToolbarProps = {
5771
namespace: string;
5872
indexView: IndexView;
@@ -62,6 +76,7 @@ type IndexesToolbarProps = {
6276
isRefreshing: boolean;
6377
onRefreshIndexes: () => void;
6478
onIndexViewChanged: (newView: IndexView) => void;
79+
serverVersion: string;
6580
// connected:
6681
isReadonlyView: boolean;
6782
isWritable: boolean;
@@ -88,6 +103,7 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
88103
isSearchIndexesSupported,
89104
onRefreshIndexes,
90105
onIndexViewChanged,
106+
serverVersion,
91107
readOnly, // preferences readOnly.
92108
}) => {
93109
const isSearchManagementActive = usePreference('enableAtlasSearchIndexes');
@@ -188,16 +204,27 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
188204
</SegmentedControlOption>
189205
}
190206
>
191-
<p>
192-
Atlas Search index management in Compass is only available
193-
for Atlas local deployments and clusters running MongoDB
194-
6.0.7 or newer.
195-
</p>
196-
<p>
197-
For clusters running an earlier version of MongoDB, you
198-
can manage your Atlas Search indexes from the Atlas web
199-
Ul, with the CLI, or with the Administration API.
200-
</p>
207+
{serverSupportsSearchIndexManagement(serverVersion) ? (
208+
<p>
209+
Unable to fetch search indexes. This can occur when your
210+
cluster does not support search indexes or the request
211+
to list search indexes failed.
212+
</p>
213+
) : (
214+
<>
215+
<p>
216+
Atlas Search index management in Compass is only
217+
available for Atlas local deployments and clusters
218+
running MongoDB 6.0.7 or newer.
219+
</p>
220+
<p>
221+
For clusters running an earlier version of MongoDB,
222+
you can manage your Atlas Search indexes from the
223+
Atlas web Ul, with the CLI, or with the Administration
224+
API.
225+
</p>
226+
</>
227+
)}
201228
</Tooltip>
202229
)}
203230
{isSearchIndexesSupported && (

packages/compass-preferences-model/src/user-storage.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,4 @@ export class UserStorageImpl implements UserStorage {
7878
await this.userData.write(user.id, user);
7979
return this.getUser(user.id);
8080
}
81-
82-
private getFileName(id: string) {
83-
return `${id}.json`;
84-
}
8581
}

packages/compass-saved-aggregations-queries/src/index.spec.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,11 @@ describe('AggregationsAndQueriesAndUpdatemanyList', function () {
227227
queryStorageLoadAllStub = sandbox
228228
.stub(queryStorage, 'loadAll')
229229
.resolves(queries.map((item) => item.query));
230-
sandbox
231-
.stub(pipelineStorage, 'loadAll')
232-
.resolves(pipelines.map((item) => item.aggregation));
230+
sandbox.stub(pipelineStorage, 'loadAll').resolves(
231+
pipelines.map((item) => {
232+
return { ...item.aggregation, lastModified: new Date() };
233+
})
234+
);
233235

234236
renderPlugin();
235237

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export type { Stats, ReadAllResult, ReadAllWithStatsResult } from './user-data';
1+
export type { ReadAllResult } from './user-data';
22
export { type IUserData, FileUserData, AtlasUserData } from './user-data';
33
export { z } from 'zod';

packages/compass-user-data/src/user-data.spec.ts

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import fs from 'fs/promises';
2-
import { Stats } from 'fs';
32
import os from 'os';
43
import path from 'path';
54
import { expect } from 'chai';
@@ -119,39 +118,6 @@ describe('user-data', function () {
119118
expect(result.data).to.have.lengthOf(0);
120119
expect(result.errors).to.have.lengthOf(2);
121120
});
122-
123-
it('returns file stats', async function () {
124-
await Promise.all(
125-
[
126-
['data1.json', JSON.stringify({ name: 'VSCode' })],
127-
['data2.json', JSON.stringify({ name: 'Mongosh' })],
128-
].map(([filepath, data]) => writeFileToStorage(filepath, data))
129-
);
130-
131-
const { data } = await getUserData().readAllWithStats({
132-
ignoreErrors: true,
133-
});
134-
135-
{
136-
const vscodeData = data.find((x) => x[0].name === 'VSCode');
137-
expect(vscodeData?.[0]).to.deep.equal({
138-
name: 'VSCode',
139-
hasDarkMode: true,
140-
hasWebSupport: false,
141-
});
142-
expect(vscodeData?.[1]).to.be.instanceOf(Stats);
143-
}
144-
145-
{
146-
const mongoshData = data.find((x) => x[0].name === 'Mongosh');
147-
expect(mongoshData?.[0]).to.deep.equal({
148-
name: 'Mongosh',
149-
hasDarkMode: true,
150-
hasWebSupport: false,
151-
});
152-
expect(mongoshData?.[1]).to.be.instanceOf(Stats);
153-
}
154-
});
155121
});
156122

157123
context('UserData.readOne', function () {
@@ -296,27 +262,6 @@ describe('user-data', function () {
296262
company: 'MongoDB',
297263
});
298264
});
299-
300-
it('return file stats', async function () {
301-
await writeFileToStorage(
302-
'data.json',
303-
JSON.stringify({
304-
name: 'Mongosh',
305-
company: 'MongoDB',
306-
})
307-
);
308-
309-
const [data, stats] = await getUserData().readOneWithStats('data', {
310-
ignoreErrors: false,
311-
});
312-
313-
expect(data).to.deep.equal({
314-
name: 'Mongosh',
315-
hasDarkMode: true,
316-
hasWebSupport: false,
317-
});
318-
expect(stats).to.be.instanceOf(Stats);
319-
});
320265
});
321266

322267
context('UserData.write', function () {

0 commit comments

Comments
 (0)