Skip to content
Open
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
31 changes: 24 additions & 7 deletions packages/compass-crud/src/components/crud-toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import {
useContextMenuGroups,
usePersistedState,
AtlasSkillsBanner,
Tooltip,
} from '@mongodb-js/compass-components';
import type { MenuAction, Signal } from '@mongodb-js/compass-components';
import { ViewSwitcher } from './view-switcher';
import type { DocumentView } from '../stores/crud-store';
import { COUNT_MAX_TIME_MS_CAP, type DocumentView } from '../stores/crud-store';
import { AddDataMenu } from './add-data-menu';
import { usePreference } from 'compass-preferences-model/provider';
import UpdateMenu from './update-data-menu';
Expand Down Expand Up @@ -87,6 +88,12 @@ const loaderContainerStyles = css({
paddingRight: spacing[200],
});

const countUnavailableTextStyles = css({
textDecoration: 'underline',
textDecorationStyle: 'dotted',
textUnderlineOffset: '3px',
});

type ExportDataOption = 'export-query' | 'export-full-collection';
const exportDataActions: MenuAction<ExportDataOption>[] = [
{ action: 'export-query', label: 'Export query results' },
Expand All @@ -109,6 +116,8 @@ const ERROR_CODE_OPERATION_TIMED_OUT = 50;
const INCREASE_MAX_TIME_MS_HINT =
'Operation exceeded time limit. Please try increasing the maxTimeMS for the query in the expanded filter options.';

const COUNT_UNAVAILABLE_TOOLTIP = `The count is not available for this query. This can happen when the count operation fails or exceeds the maxTimeMS of ${COUNT_MAX_TIME_MS_CAP}.`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though we cap maxTimeMS, but if a user has set it to lower value in preferences, should we show that instead? When running count, we call capMaxTimeMSAtPreferenceLimit to get actual value we use.


type ErrorWithPossibleCode = Error & {
code?: {
value: number;
Expand Down Expand Up @@ -198,11 +207,6 @@ const CrudToolbar: React.FunctionComponent<CrudToolbarProps> = ({
SkillsBannerContextEnum.Documents
);

const displayedDocumentCount = useMemo(
() => (loadingCount ? '' : `${count ?? 'N/A'}`),
[loadingCount, count]
);

const onClickRefreshDocuments = useCallback(() => {
track('Query Results Refreshed', {}, connectionInfoRef.current);
refreshDocuments();
Expand Down Expand Up @@ -416,7 +420,20 @@ const CrudToolbar: React.FunctionComponent<CrudToolbarProps> = ({
</Select>
<Body data-testid="crud-document-count-display">
{start} – {end}{' '}
{displayedDocumentCount && `of ${displayedDocumentCount}`}
{!loadingCount && (
<span>
{'of '}
{count ?? (
<Tooltip
trigger={
<span className={countUnavailableTextStyles}>N/A</span>
}
>
<Body>{COUNT_UNAVAILABLE_TOOLTIP}</Body>
</Tooltip>
)}
</span>
)}
</Body>
{loadingCount && (
<div className={loaderContainerStyles}>
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-crud/src/stores/crud-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ const DEFAULT_INITIAL_MAX_TIME_MS = 60000;
* We want to make sure `count` does not hold back the query results for too
* long after docs are returned.
*/
const COUNT_MAX_TIME_MS_CAP = 5000;
export const COUNT_MAX_TIME_MS_CAP = 5000;

/**
* The key we use to persist the user selected maximum documents per page for
Expand Down
Loading