Skip to content

Commit

Permalink
fix: allow index usageCount to be 0 and display 'data unavailable' me…
Browse files Browse the repository at this point in the history
…ssage if user cannot view stats COMPASS-7290 (#4930)
  • Loading branch information
flatypus authored Oct 2, 2023
1 parent 69151f1 commit 15d1ce3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ describe('UsageField', function () {
expect(screen.getByText(renderedText)).to.exist;
});

it('renders zero when usage is not defined', function () {
render(<UsageField usage={0} />);
it('renders usage unavailable when usage is not defined', function () {
render(<UsageField />);
const renderedText = 'Usage data unavailable';
expect(screen.getByText(renderedText)).to.exist;
});

const renderedText = `0`;
it('renders zero when usage is zero', function () {
render(<UsageField usage={0} />);
const renderedText = '0';
expect(screen.getByText(renderedText)).to.exist;
});

Expand All @@ -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'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
};
Expand All @@ -27,9 +27,15 @@ const UsageField: React.FunctionComponent<UsageFieldProps> = ({
<span {...props}>
{children}
<Body>
{usage || 0}
{nbsp}
<>{since ? `(since ${since.toDateString()})` : ''}</>
{usage === null || usage === undefined ? (
'Usage data unavailable'
) : (
<>
{usage}
{nbsp}
{since ? `(since ${since.toDateString()})` : ''}
</>
)}
</Body>
</span>
)}
Expand Down
3 changes: 1 addition & 2 deletions packages/data-service/src/index-detail-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type IndexInfo = {

export type IndexStats = {
name: string;
usageCount: number;
usageCount?: number;
usageHost?: string;
usageSince?: Date;
};
Expand Down Expand Up @@ -124,7 +124,6 @@ export function createIndexDefinition(
): IndexDefinition {
indexStats ??= {
name,
usageCount: 0,
usageHost: '',
usageSince: new Date(0),
};
Expand Down

0 comments on commit 15d1ce3

Please sign in to comment.