Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(aggregations): update search stage preview #4839

Merged
merged 2 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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