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

[pull] main from mongodb-js:main #372

Merged
merged 14 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion .evergreen/print-compass-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

export MONGODB_DEFAULT_VERSION=6.0.x
export MONGODB_DEFAULT_VERSION=7.0.x

if [[ $OSTYPE == "cygwin" ]]; then
export PLATFORM='win32'
Expand Down
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,4 @@ Vivian Xiao <[email protected]>
admin-token-bot <[email protected]>
Kræn Hansen <[email protected]>
Kræn Hansen <[email protected]>
Ruchitha Rajaghatta <[email protected]>
2 changes: 1 addition & 1 deletion THIRD-PARTY-NOTICES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
The following third-party software is used by and included in **Mongodb Compass**.
This document was automatically generated on Tue Oct 15 2024.
This document was automatically generated on Fri Oct 18 2024.

## List of dependencies

Expand Down
2 changes: 1 addition & 1 deletion docs/tracking-plan.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# Compass Tracking Plan

Generated on Tue, Oct 15, 2024 at 05:11 AM
Generated on Fri, Oct 18, 2024 at 04:41 PM

## Table of Contents

Expand Down
5 changes: 1 addition & 4 deletions packages/atlas-service/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,7 @@ export class CompassAuthService {

await throwIfNotOk(res);

const userInfo = (await res.json()) as AtlasUserInfo;

// TODO: Remove hadcoded `enabledAIFeature: true` when Atlas returns the actual value.
return { ...userInfo, enabledAIFeature: true };
return (await res.json()) as AtlasUserInfo;
})();
return this.currentUser;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/atlas-service/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type AtlasUserInfo = {
lastName: string;
primaryEmail: string;
login: string;
} & { enabledAIFeature: boolean };
};

export type IntrospectInfo = { active: boolean };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,36 @@ describe('FocusModeStagePreview', function () {
const preview = screen.getByTestId('focus-mode-stage-preview');
expect(within(preview).getByText(/no preview documents/i)).to.exist;
});
for (const stageOperator of ['$search', '$searchMeta', '$vectorSearch']) {
it(`renders missing search index text for ${stageOperator}`, async function () {
await renderFocusModePreview({
stageOperator,
documents: [],
});
expect(screen.getByText('No preview documents')).to.exist;
expect(
screen.getByText(
'This may be because your search has no results or your search index does not exist.'
)
).to.exist;
});

it(`does not render missing search index text for ${stageOperator} and documents.length > 0`, async function () {
await renderFocusModePreview({
stageOperator,
documents: [
new HadronDocument({ _id: 12345 }),
new HadronDocument({ _id: 54321 }),
],
});
expect(screen.queryByText('No preview documents')).to.not.exist;
expect(
screen.queryByText(
'This may be because your search has no results or your search index does not exist.'
)
).to.not.exist;
});
}
it('renders $out stage preview', async function () {
await renderFocusModePreview(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import OutputStagePreview from '../stage-preview/output-stage-preview';
import { AtlasStagePreview } from '../stage-preview/atlas-stage-preview';
import {
isAtlasOnlyStage,
isSearchStage,
isMissingAtlasStageSupport,
isOutputStage,
} from '../../utils/stage';
Expand All @@ -24,6 +25,7 @@ import {
expandPreviewDocsForStage,
} from '../../modules/pipeline-builder/stage-editor';
import type { StoreStage } from '../../modules/pipeline-builder/stage-editor';
import SearchNoResults from '../search-no-results';

const containerStyles = css({
display: 'flex',
Expand Down Expand Up @@ -149,6 +151,8 @@ export const FocusModePreview = ({
className={documentListStyles}
/>
);
} else if (isSearchStage(stageOperator)) {
content = <SearchNoResults />;
} else {
content = (
<div className={centerStyles}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ describe('PipelinePreview', function () {
expect(screen.getByText(/No preview documents/)).to.exist;
});

it('renders missing search index text for $search', async function () {
await renderPipelineEditor({
atlasOperator: '$search',
previewDocs: [],
});
expect(screen.getByText('No preview documents')).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 document list', async function () {
await renderPipelineEditor({
previewDocs: [{ _id: 1 }, { _id: 2 }].map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
expandPreviewDocs,
collapsePreviewDocs,
} from '../../../modules/pipeline-builder/text-editor-pipeline';
import SearchNoResults from '../../search-no-results';

const containerStyles = css({
display: 'flex',
Expand Down Expand Up @@ -126,6 +127,9 @@ const PreviewResults = ({
}

if (previewDocs.length === 0) {
if (atlasOperator) {
return <SearchNoResults />;
}
return (
<div className={centerStyles}>
<DocumentIcon />
Expand Down
48 changes: 48 additions & 0 deletions packages/compass-aggregations/src/components/search-no-results.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react';

import {
css,
palette,
spacing,
Body,
useDarkMode,
Subtitle,
} from '@mongodb-js/compass-components';

const centeredContent = css({
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
height: '100%',
padding: spacing[3],
flexDirection: 'column',
textAlign: 'center',
});

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

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

export default function SearchNoResults() {
const darkMode = useDarkMode();

return (
<div className={centeredContent}>
<Subtitle
className={css(
darkMode ? missingAtlasIndexDarkStyles : missingAtlasIndexLightStyles
)}
>
No preview documents
</Subtitle>
<Body>
This may be because your search has no results or your search index does
not exist.
</Body>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe('StagePreview', function () {
stageOperator: '$search',
documents: [],
});
expect(screen.getByText('No results found')).to.exist;
expect(screen.getByText('No preview documents')).to.exist;
expect(
screen.getByText(
'This may be because your search has no results or your search index does not exist.'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ import {
Body,
KeylineCard,
useDarkMode,
Subtitle,
} from '@mongodb-js/compass-components';
import { Document } from '@mongodb-js/compass-crud';

import type { RootState } from '../../modules';
import {
isAtlasOnlyStage,
isSearchStage,
isMissingAtlasStageSupport,
isOutputStage,
} from '../../utils/stage';
Expand All @@ -26,6 +25,8 @@ import OutputStagePreivew from './output-stage-preview';
import StagePreviewHeader from './stage-preview-header';
import type { StoreStage } from '../../modules/pipeline-builder/stage-editor';

import SearchNoResults from '../search-no-results';

const centeredContent = css({
display: 'flex',
alignItems: 'center',
Expand All @@ -52,7 +53,7 @@ const emptyStylesLight = css({
stroke: palette.gray.base,
});

function EmptyIcon() {
function NoPreviewDocuments() {
const darkMode = useDarkMode();

return (
Expand Down Expand Up @@ -97,14 +98,6 @@ 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 @@ -123,9 +116,8 @@ function StagePreviewBody({
shouldRenderStage,
isLoading,
}: StagePreviewProps) {
const darkMode = useDarkMode();
if (!shouldRenderStage) {
return <EmptyIcon />;
return <NoPreviewDocuments />;
}

if (isMissingAtlasOnlyStageSupport) {
Expand Down Expand Up @@ -153,24 +145,8 @@ 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 (isSearchStage(stageOperator) && documents?.length === 0) {
return <SearchNoResults />;
}

if (documents && documents.length > 0) {
Expand All @@ -186,7 +162,7 @@ function StagePreviewBody({
return <div className={documentsStyles}>{docs}</div>;
}

return <EmptyIcon />;
return <NoPreviewDocuments />;
}

const containerStyles = css({
Expand All @@ -208,7 +184,7 @@ export function StagePreview(props: StagePreviewProps) {
if (props.isDisabled) {
return (
<div className={containerStyles}>
<EmptyIcon />
<NoPreviewDocuments />
</div>
);
}
Expand Down
15 changes: 15 additions & 0 deletions packages/compass-aggregations/src/utils/stage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,21 @@ export function isAtlasOnlyStage(
return !!stageOperator && ATLAS_ONLY_OPERATOR_NAMES.has(stageOperator);
}

/*
Atlas Search does not return an error if there is no search index - it just
returns no results. So if the connection has access to Atlas Search and the
aggregation used a search-related stage and got no results we want to display a
different error.
*/
export function isSearchStage(
stageOperator: string | null | undefined
): stageOperator is '$search' | '$searchMeta' | '$vectorSearch' {
if (!stageOperator) {
return false;
}
return ['$search', '$searchMeta', '$vectorSearch'].includes(stageOperator);
}

const STAGE_OPERATORS_MAP = new Map(
STAGE_OPERATORS.map((stage) => [stage.value, stage])
);
Expand Down
2 changes: 2 additions & 0 deletions packages/compass-e2e-tests/helpers/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ export * from './unhide-index';
export * from './hide-visible-modal';
export * from './hide-visible-toasts';
export * from './sidebar-collection';
export * from './read-first-document-content';
export * from './read-stage-operators';
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import chai from 'chai';
const { expect } = chai;

import type { CompassBrowser } from '../helpers/compass-browser';
import * as Selectors from '../helpers/selectors';
import type { CompassBrowser } from '../compass-browser';
import * as Selectors from '../selectors';

export async function getFirstListDocument(browser: CompassBrowser) {
// We check the total from the header area so it is probably good enough to
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CompassBrowser } from '../helpers/compass-browser';
import * as Selectors from '../helpers/selectors';
import type { CompassBrowser } from '../compass-browser';
import * as Selectors from '../selectors';

export async function getStageOperators(
browser: CompassBrowser,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
createNestedDocumentsCollection,
createNumbersCollection,
} from '../helpers/insert-data';
import { getStageOperators } from '../helpers/read-stage-operators';
import { saveAggregationPipeline } from '../helpers/commands/save-aggregation-pipeline';
import { Key } from 'webdriverio';

Expand Down Expand Up @@ -166,7 +165,7 @@ describe('Collection aggregations tab', function () {
});

it('supports the right stages for the environment', async function () {
const options = await getStageOperators(browser, 0);
const options = await browser.getStageOperators(0);

const expectedAggregations = [
'$addFields',
Expand Down
3 changes: 1 addition & 2 deletions packages/compass-e2e-tests/tests/collection-ai-query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import * as Selectors from '../helpers/selectors';
import { createNumbersCollection } from '../helpers/insert-data';
import { startMockAtlasServiceServer } from '../helpers/atlas-service';
import type { MockAtlasServerResponse } from '../helpers/atlas-service';
import { getFirstListDocument } from '../helpers/read-first-document-content';

describe('Collection ai query', function () {
let compass: Compass;
Expand Down Expand Up @@ -147,7 +146,7 @@ describe('Collection ai query', function () {

// Run it and check that the correct documents are shown.
await browser.runFind('Documents', true);
const modifiedResult = await getFirstListDocument(browser);
const modifiedResult = await browser.getFirstListDocument();
expect(modifiedResult.i).to.be.equal('51');
});
});
Expand Down
Loading
Loading