diff --git a/packages/compass-indexes/src/components/regular-indexes-table/usage-field.spec.tsx b/packages/compass-indexes/src/components/regular-indexes-table/usage-field.spec.tsx
index 375b950391f..2a6fd0ffa8d 100644
--- a/packages/compass-indexes/src/components/regular-indexes-table/usage-field.spec.tsx
+++ b/packages/compass-indexes/src/components/regular-indexes-table/usage-field.spec.tsx
@@ -17,10 +17,15 @@ describe('UsageField', function () {
expect(screen.getByText(renderedText)).to.exist;
});
- it('renders zero when usage is not defined', function () {
- render();
+ it('renders usage unavailable when usage is not defined', function () {
+ render();
+ const renderedText = 'Usage data unavailable';
+ expect(screen.getByText(renderedText)).to.exist;
+ });
- const renderedText = `0`;
+ it('renders zero when usage is zero', function () {
+ render();
+ const renderedText = '0';
expect(screen.getByText(renderedText)).to.exist;
});
@@ -37,6 +42,9 @@ describe('UsageField', function () {
'Either the server does not support the $indexStats command' +
' or the user is not authorized to execute it.'
);
+ expect(getUsageTooltip(0)).to.equal(
+ '0 index hits since index creation or last server restart'
+ );
expect(getUsageTooltip(30)).to.equal(
'30 index hits since index creation or last server restart'
);
diff --git a/packages/compass-indexes/src/components/regular-indexes-table/usage-field.tsx b/packages/compass-indexes/src/components/regular-indexes-table/usage-field.tsx
index 9145e122dea..f6e9706d36b 100644
--- a/packages/compass-indexes/src/components/regular-indexes-table/usage-field.tsx
+++ b/packages/compass-indexes/src/components/regular-indexes-table/usage-field.tsx
@@ -6,7 +6,7 @@ const NO_USAGE_STATS =
' or the user is not authorized to execute it.';
export const getUsageTooltip = (usage?: number): string => {
- return !usage
+ return usage === null || usage === undefined
? NO_USAGE_STATS
: `${usage} index hits since index creation or last server restart`;
};
@@ -27,9 +27,15 @@ const UsageField: React.FunctionComponent = ({
{children}
- {usage || 0}
- {nbsp}
- <>{since ? `(since ${since.toDateString()})` : ''}>
+ {usage === null || usage === undefined ? (
+ 'Usage data unavailable'
+ ) : (
+ <>
+ {usage}
+ {nbsp}
+ {since ? `(since ${since.toDateString()})` : ''}
+ >
+ )}
)}
diff --git a/packages/data-service/src/index-detail-helper.ts b/packages/data-service/src/index-detail-helper.ts
index f77080d76b1..6674319c03d 100644
--- a/packages/data-service/src/index-detail-helper.ts
+++ b/packages/data-service/src/index-detail-helper.ts
@@ -9,7 +9,7 @@ export type IndexInfo = {
export type IndexStats = {
name: string;
- usageCount: number;
+ usageCount?: number;
usageHost?: string;
usageSince?: Date;
};
@@ -124,7 +124,6 @@ export function createIndexDefinition(
): IndexDefinition {
indexStats ??= {
name,
- usageCount: 0,
usageHost: '',
usageSince: new Date(0),
};