Skip to content

Commit

Permalink
chore(aggregations): update search stage preview COMPASS-7169 (#4839)
Browse files Browse the repository at this point in the history
  • Loading branch information
mabaasit authored Sep 13, 2023
1 parent c44e579 commit dfe4b81
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import type { ComponentProps } from 'react';
import type { Document } from 'mongodb';
import { render, screen } from '@testing-library/react';
import { render, screen, cleanup } from '@testing-library/react';
import { expect } from 'chai';
import { Provider } from 'react-redux';

Expand Down Expand Up @@ -40,6 +40,7 @@ const renderStagePreview = (
};

describe('StagePreview', function () {
afterEach(cleanup);
it('renders empty content when stage is disabled', function () {
renderStagePreview({
isDisabled: true,
Expand Down Expand Up @@ -105,4 +106,26 @@ describe('StagePreview', function () {
const docs = screen.getAllByTestId('readonly-document');
expect(docs).to.have.length(2);
});
it('renders missing search index text for $search', function () {
renderStagePreview({
shouldRenderStage: true,
stageOperator: '$search',
documents: [],
});
expect(screen.getByText('No results found')).to.exist;
expect(
screen.getByText(
'This may be because your search has no results or your search index does not exist.'
)
).to.exist;
});
it('renders $search preview docs', function () {
renderStagePreview({
shouldRenderStage: true,
stageOperator: '$search',
documents: [{ _id: 1 }, { _id: 2 }],
});
const docs = screen.getAllByTestId('readonly-document');
expect(docs).to.have.length(2);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ import {
Body,
KeylineCard,
useDarkMode,
Subtitle,
} from '@mongodb-js/compass-components';
import { Document } from '@mongodb-js/compass-crud';

import type { RootState } from '../../modules';
import { isMissingAtlasStageSupport, isOutputStage } from '../../utils/stage';
import {
isAtlasOnlyStage,
isMissingAtlasStageSupport,
isOutputStage,
} from '../../utils/stage';

import LoadingOverlay from '../loading-overlay';
import { AtlasStagePreview } from './atlas-stage-preview';
Expand All @@ -27,6 +32,7 @@ const centeredContent = css({
justifyContent: 'center',
height: '100%',
padding: spacing[3],
flexDirection: 'column',
});

const emptyStyles = css({
Expand Down Expand Up @@ -91,6 +97,14 @@ const documentStyles = css({
padding: 0,
});

const missingAtlasIndexLightStyles = css({
color: palette.green.dark2,
});

const missingAtlasIndexDarkStyles = css({
color: palette.green.base,
});

type StagePreviewProps = {
index: number;
isLoading: boolean;
Expand All @@ -109,6 +123,7 @@ function StagePreviewBody({
shouldRenderStage,
isLoading,
}: StagePreviewProps) {
const darkMode = useDarkMode();
if (!shouldRenderStage) {
return <EmptyIcon />;
}
Expand Down Expand Up @@ -138,6 +153,26 @@ function StagePreviewBody({
);
}

if (isAtlasOnlyStage(stageOperator ?? '') && documents?.length === 0) {
return (
<div className={centeredContent}>
<Subtitle
className={css(
darkMode
? missingAtlasIndexDarkStyles
: missingAtlasIndexLightStyles
)}
>
No results found
</Subtitle>
<Body>
This may be because your search has no results or your search index
does not exist.
</Body>
</div>
);
}

if (documents && documents.length > 0) {
const docs = documents.map((doc, i) => {
return (
Expand Down

0 comments on commit dfe4b81

Please sign in to comment.