Skip to content

Commit 99334d0

Browse files
committed
make it clear that this is for search-related stages only
1 parent 68fc3d6 commit 99334d0

File tree

5 files changed

+26
-10
lines changed

5 files changed

+26
-10
lines changed

packages/compass-aggregations/src/components/focus-mode/focus-mode-stage-preview.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import OutputStagePreview from '../stage-preview/output-stage-preview';
1616
import { AtlasStagePreview } from '../stage-preview/atlas-stage-preview';
1717
import {
1818
isAtlasOnlyStage,
19+
isSearchStage,
1920
isMissingAtlasStageSupport,
2021
isOutputStage,
2122
} from '../../utils/stage';
@@ -24,7 +25,7 @@ import {
2425
expandPreviewDocsForStage,
2526
} from '../../modules/pipeline-builder/stage-editor';
2627
import type { StoreStage } from '../../modules/pipeline-builder/stage-editor';
27-
import AtlasNoResults from '../atlas-no-results';
28+
import SearchNoResults from '../search-no-results';
2829

2930
const containerStyles = css({
3031
display: 'flex',
@@ -150,8 +151,8 @@ export const FocusModePreview = ({
150151
className={documentListStyles}
151152
/>
152153
);
153-
} else if (isAtlasOnlyStage(stageOperator)) {
154-
content = <AtlasNoResults />;
154+
} else if (isSearchStage(stageOperator)) {
155+
content = <SearchNoResults />;
155156
} else {
156157
content = (
157158
<div className={centerStyles}>

packages/compass-aggregations/src/components/pipeline-builder-workspace/pipeline-as-text-workspace/pipeline-preview.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
expandPreviewDocs,
2626
collapsePreviewDocs,
2727
} from '../../../modules/pipeline-builder/text-editor-pipeline';
28-
import AtlasNoResults from '../../atlas-no-results';
28+
import SearchNoResults from '../../search-no-results';
2929

3030
const containerStyles = css({
3131
display: 'flex',
@@ -128,7 +128,7 @@ const PreviewResults = ({
128128

129129
if (previewDocs.length === 0) {
130130
if (atlasOperator) {
131-
return <AtlasNoResults />;
131+
return <SearchNoResults />;
132132
}
133133
return (
134134
<div className={centerStyles}>

packages/compass-aggregations/src/components/atlas-no-results.tsx renamed to packages/compass-aggregations/src/components/search-no-results.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const missingAtlasIndexDarkStyles = css({
2727
color: palette.green.base,
2828
});
2929

30-
export default function AtlasNoResults() {
30+
export default function SearchNoResults() {
3131
const darkMode = useDarkMode();
3232

3333
return (

packages/compass-aggregations/src/components/stage-preview/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { Document } from '@mongodb-js/compass-crud';
1414

1515
import type { RootState } from '../../modules';
1616
import {
17-
isAtlasOnlyStage,
17+
isSearchStage,
1818
isMissingAtlasStageSupport,
1919
isOutputStage,
2020
} from '../../utils/stage';
@@ -25,7 +25,7 @@ import OutputStagePreivew from './output-stage-preview';
2525
import StagePreviewHeader from './stage-preview-header';
2626
import type { StoreStage } from '../../modules/pipeline-builder/stage-editor';
2727

28-
import AtlasNoResults from '../atlas-no-results';
28+
import SearchNoResults from '../search-no-results';
2929

3030
const centeredContent = css({
3131
display: 'flex',
@@ -145,8 +145,8 @@ function StagePreviewBody({
145145
);
146146
}
147147

148-
if (isAtlasOnlyStage(stageOperator ?? '') && documents?.length === 0) {
149-
return <AtlasNoResults />;
148+
if (isSearchStage(stageOperator) && documents?.length === 0) {
149+
return <SearchNoResults />;
150150
}
151151

152152
if (documents && documents.length > 0) {

packages/compass-aggregations/src/utils/stage.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,21 @@ export function isAtlasOnlyStage(
203203
return !!stageOperator && ATLAS_ONLY_OPERATOR_NAMES.has(stageOperator);
204204
}
205205

206+
/*
207+
Atlas Search does not return an error if there is no search index - it just
208+
returns no results. So if the connection has access to Atlas Search and the
209+
aggregation used a search-related stage and got no results we want to display a
210+
different error.
211+
*/
212+
export function isSearchStage(
213+
stageOperator: string | null | undefined
214+
): stageOperator is '$search' | '$searchMeta' | '$vectorSearch' {
215+
if (!stageOperator) {
216+
return false;
217+
}
218+
return ['$search', '$searchMeta', '$vectorSearch'].includes(stageOperator);
219+
}
220+
206221
const STAGE_OPERATORS_MAP = new Map(
207222
STAGE_OPERATORS.map((stage) => [stage.value, stage])
208223
);

0 commit comments

Comments
 (0)