Skip to content

Commit 2f9436f

Browse files
committed
feat(crud): add tooltip for N/A count
1 parent 4086459 commit 2f9436f

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

packages/compass-crud/src/components/crud-toolbar.tsx

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ import {
2121
useContextMenuGroups,
2222
usePersistedState,
2323
AtlasSkillsBanner,
24+
Tooltip,
2425
} from '@mongodb-js/compass-components';
2526
import type { MenuAction, Signal } from '@mongodb-js/compass-components';
2627
import { ViewSwitcher } from './view-switcher';
27-
import type { DocumentView } from '../stores/crud-store';
28+
import { COUNT_MAX_TIME_MS_CAP, type DocumentView } from '../stores/crud-store';
2829
import { AddDataMenu } from './add-data-menu';
2930
import { usePreference } from 'compass-preferences-model/provider';
3031
import UpdateMenu from './update-data-menu';
@@ -87,6 +88,12 @@ const loaderContainerStyles = css({
8788
paddingRight: spacing[200],
8889
});
8990

91+
const countUnavailableTextStyles = css({
92+
textDecoration: 'underline',
93+
textDecorationStyle: 'dotted',
94+
textUnderlineOffset: '3px',
95+
});
96+
9097
type ExportDataOption = 'export-query' | 'export-full-collection';
9198
const exportDataActions: MenuAction<ExportDataOption>[] = [
9299
{ action: 'export-query', label: 'Export query results' },
@@ -109,6 +116,8 @@ const ERROR_CODE_OPERATION_TIMED_OUT = 50;
109116
const INCREASE_MAX_TIME_MS_HINT =
110117
'Operation exceeded time limit. Please try increasing the maxTimeMS for the query in the expanded filter options.';
111118

119+
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}.`;
120+
112121
type ErrorWithPossibleCode = Error & {
113122
code?: {
114123
value: number;
@@ -198,11 +207,6 @@ const CrudToolbar: React.FunctionComponent<CrudToolbarProps> = ({
198207
SkillsBannerContextEnum.Documents
199208
);
200209

201-
const displayedDocumentCount = useMemo(
202-
() => (loadingCount ? '' : `${count ?? 'N/A'}`),
203-
[loadingCount, count]
204-
);
205-
206210
const onClickRefreshDocuments = useCallback(() => {
207211
track('Query Results Refreshed', {}, connectionInfoRef.current);
208212
refreshDocuments();
@@ -416,7 +420,20 @@ const CrudToolbar: React.FunctionComponent<CrudToolbarProps> = ({
416420
</Select>
417421
<Body data-testid="crud-document-count-display">
418422
{start}{end}{' '}
419-
{displayedDocumentCount && `of ${displayedDocumentCount}`}
423+
{!loadingCount && (
424+
<span>
425+
{'of '}
426+
{count ?? (
427+
<Tooltip
428+
trigger={
429+
<span className={countUnavailableTextStyles}>N/A</span>
430+
}
431+
>
432+
<Body>{COUNT_UNAVAILABLE_TOOLTIP}</Body>
433+
</Tooltip>
434+
)}
435+
</span>
436+
)}
420437
</Body>
421438
{loadingCount && (
422439
<div className={loaderContainerStyles}>

packages/compass-crud/src/stores/crud-store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ const DEFAULT_INITIAL_MAX_TIME_MS = 60000;
253253
* We want to make sure `count` does not hold back the query results for too
254254
* long after docs are returned.
255255
*/
256-
const COUNT_MAX_TIME_MS_CAP = 5000;
256+
export const COUNT_MAX_TIME_MS_CAP = 5000;
257257

258258
/**
259259
* The key we use to persist the user selected maximum documents per page for

0 commit comments

Comments
 (0)