Skip to content

Commit 772d936

Browse files
have compass and de be same, add new incompatible state
1 parent f1ed69c commit 772d936

File tree

4 files changed

+59
-29
lines changed

4 files changed

+59
-29
lines changed

packages/compass-aggregations/src/components/stage-toolbar/stage-operator-select.spec.tsx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe('StageOperatorSelect', () => {
3636
isDisabled: false,
3737
stages: mockStages,
3838
serverVersion: '8.1.0',
39-
isReadonlyView: false,
39+
sourceName: 'sourceName',
4040
collectionStats: {
4141
pipeline: [{ $addFields: { field: 'value' } }],
4242
},
@@ -49,7 +49,7 @@ describe('StageOperatorSelect', () => {
4949
};
5050

5151
it('renders the correct descriptions if not in readonly view', () => {
52-
renderCombobox({ isReadonlyView: false });
52+
renderCombobox({ sourceName: null });
5353
fireEvent.click(screen.getByRole('combobox'));
5454
const listbox = screen.getByRole('listbox');
5555

@@ -62,7 +62,6 @@ describe('StageOperatorSelect', () => {
6262

6363
it('renders the correct descriptions if in readonly view with non queryable pipeline', () => {
6464
renderCombobox({
65-
isReadonlyView: true,
6665
collectionStats: {
6766
pipeline: [
6867
{ $addFields: { field: 'value' } },
@@ -78,13 +77,28 @@ describe('StageOperatorSelect', () => {
7877
.to.exist;
7978
expect(
8079
within(listbox).getByText(
81-
'Atlas only. Only views containing $addFields, $set or $match stages with the $expr operator are compatible with search indexes. searchStage description.'
80+
'Atlas only. Only views containing $match stages with the $expr operator, $addFields, or $set are compatible with search indexes. searchStage description.'
81+
)
82+
).to.exist;
83+
});
84+
85+
it('renders the correct descriptions for $search stage in readonly view with 8.0 version', () => {
86+
renderCombobox({ serverVersion: '8.0.0' });
87+
fireEvent.click(screen.getByRole('combobox'));
88+
const listbox = screen.getByRole('listbox');
89+
90+
expect(within(listbox).getByText('basicStage description.')).to.exist;
91+
expect(within(listbox).getByText('Atlas only. atlasOnlyStage description.'))
92+
.to.exist;
93+
expect(
94+
within(listbox).getByText(
95+
'Atlas only. Requires MongoDB 8.1+ to run on a view. To use a search index on a view on MongoDB 8.0, query the view’s source collection sourceName. searchStage description.'
8296
)
8397
).to.exist;
8498
});
8599

86100
it('renders the correct descriptions for $search stage in readonly view with incompatible version', () => {
87-
renderCombobox({ serverVersion: '7.0.0', isReadonlyView: true });
101+
renderCombobox({ serverVersion: '7.0.0' });
88102
fireEvent.click(screen.getByRole('combobox'));
89103
const listbox = screen.getByRole('listbox');
90104

packages/compass-aggregations/src/components/stage-toolbar/stage-operator-select.tsx

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import React, { useCallback } from 'react';
2-
import {
3-
usePreference,
4-
withPreferences,
5-
} from 'compass-preferences-model/provider';
2+
import { withPreferences } from 'compass-preferences-model/provider';
63
import { connect } from 'react-redux';
74
import { VIEW_PIPELINE_UTILS } from '@mongodb-js/mongodb-constants';
85

@@ -21,10 +18,11 @@ import { filterStageOperators, isSearchStage } from '../../utils/stage';
2118
import { isAtlasOnly } from '../../utils/stage';
2219
import type { ServerEnvironment } from '../../modules/env';
2320
import type { CollectionStats } from '../../modules/collection-stats';
21+
import semver from 'semver';
2422

2523
const inputWidth = spacing[1400] * 3;
2624
// width of options popover
27-
const comboxboxOptionsWidth = spacing[1200] * 10;
25+
const comboxboxOptionsWidth = spacing[1200] * 14;
2826
// left position of options popover wrt input. this aligns it with the start of input
2927
const comboboxOptionsLeft = (comboxboxOptionsWidth - inputWidth) / 2;
3028

@@ -45,7 +43,7 @@ type StageOperatorSelectProps = {
4543
isDisabled: boolean;
4644
stages: Stage[];
4745
serverVersion: string;
48-
isReadonlyView: boolean;
46+
sourceName: string | null;
4947
collectionStats: CollectionStats;
5048
};
5149

@@ -55,29 +53,52 @@ export type Stage = {
5553
description: string;
5654
};
5755

56+
const sourceCollectionSupportsViewIndex = (serverVersion: string) => {
57+
try {
58+
// Check if the serverVersion is 8.0
59+
return (
60+
semver.gte(serverVersion, '8.0.0') && semver.lt(serverVersion, '8.1.0')
61+
);
62+
} catch {
63+
return false;
64+
}
65+
};
66+
5867
export const getStageDescription = (
5968
stage: Stage,
60-
isReadonlyView: boolean,
69+
sourceName: string | null,
70+
serverVersion: string,
6171
versionIncompatibleCompass: boolean,
6272
isPipelineSearchQueryable: boolean
6373
) => {
74+
const isReadonlyView = !!sourceName;
6475
if (isReadonlyView && isSearchStage(stage.name)) {
65-
const minMajorMinorVersion =
76+
const minVersionCompatibility =
6677
VIEW_PIPELINE_UTILS.MIN_VERSION_FOR_VIEW_SEARCH_COMPATIBILITY_COMPASS.split(
6778
'.'
6879
)
6980
.slice(0, 2)
7081
.join('.');
82+
7183
if (versionIncompatibleCompass) {
84+
// If version is <8.1
85+
if (sourceCollectionSupportsViewIndex(serverVersion)) {
86+
// version is 8.0
87+
return (
88+
`Atlas only. Requires MongoDB ${minVersionCompatibility}+ to run on a view. To use a search index on a view on MongoDB 8.0, query the view’s source collection ${sourceName}. ` +
89+
stage.description
90+
);
91+
}
92+
7293
return (
73-
`Atlas only. Requires MongoDB ${minMajorMinorVersion}+ to run on a view. ` +
94+
`Atlas only. Requires MongoDB ${minVersionCompatibility}+ to run on a view. ` +
7495
stage.description
7596
);
7697
}
7798

7899
if (!isPipelineSearchQueryable) {
79100
return (
80-
`Atlas only. Only views containing $addFields, $set or $match stages with the $expr operator are compatible with search indexes. ` +
101+
`Atlas only. Only views containing $match stages with the $expr operator, $addFields, or $set are compatible with search indexes. ` +
81102
stage.description
82103
);
83104
}
@@ -92,17 +113,10 @@ export const StageOperatorSelect = ({
92113
selectedStage,
93114
isDisabled,
94115
serverVersion,
95-
isReadonlyView,
116+
sourceName,
96117
collectionStats,
97118
stages,
98119
}: StageOperatorSelectProps) => {
99-
const enableAtlasSearchIndexes = usePreference('enableAtlasSearchIndexes');
100-
// filter out search stages for data explorer
101-
const filteredStages =
102-
isReadonlyView && !enableAtlasSearchIndexes
103-
? stages.filter((stage) => !isSearchStage(stage.name))
104-
: stages;
105-
106120
const onStageOperatorSelected = useCallback(
107121
(name: string | null) => {
108122
onChange(index, name);
@@ -119,6 +133,7 @@ export const StageOperatorSelect = ({
119133
collectionStats.pipeline as Document[]
120134
)
121135
: true;
136+
const isReadonlyView = !!sourceName;
122137
const disableSearchStage =
123138
isReadonlyView &&
124139
(!pipelineIsSearchQueryable || versionIncompatibleCompass);
@@ -134,15 +149,16 @@ export const StageOperatorSelect = ({
134149
data-testid="stage-operator-combobox"
135150
className={comboboxStyles}
136151
>
137-
{filteredStages.map((stage: Stage, index) => (
152+
{stages.map((stage: Stage, index) => (
138153
<ComboboxOption
139154
data-testid={`combobox-option-stage-${stage.name}`}
140155
key={`combobox-option-stage-${index}`}
141156
value={stage.name}
142157
disabled={isSearchStage(stage.name) && disableSearchStage}
143158
description={getStageDescription(
144159
stage,
145-
isReadonlyView,
160+
sourceName,
161+
serverVersion,
146162
versionIncompatibleCompass,
147163
pipelineIsSearchQueryable
148164
)}
@@ -182,7 +198,7 @@ export default withPreferences(
182198
isDisabled: stage.disabled,
183199
stages: stages,
184200
serverVersion: state.serverVersion,
185-
isReadonlyView: !!state.sourceName,
201+
sourceName: state.sourceName,
186202
collectionStats: state.collectionStats,
187203
};
188204
},

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ const ViewNotSearchCompatibleBanner = ({
106106
</>
107107
)}
108108
This view is incompatible with search indexes. Only views containing
109-
$addFields, $set or $match stages with the $expr operator are compatible
109+
$match stages with the $expr operator, $addFields, or $set are compatible
110110
with search indexes.{' '}
111111
{!hasNoSearchIndexes && 'Edit the view to rebuild search indexes.'}{' '}
112112
<Link

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ function ZeroState({
9494
</Button>
9595
}
9696
>
97-
Search indexes can only be created on views containing $addFields,
98-
$set or $match stages with the $expr operator.
97+
Search indexes can only be created on views containing $match stages
98+
with the $expr operator, $addFields, or $set.
9999
</Tooltip>
100100
}
101101
callToActionLink={

0 commit comments

Comments
 (0)