Skip to content

Commit 6e4e29d

Browse files
authored
fix: just hide the total count rather than displaying N/A VSCODE-765 (#1276)
1 parent c7a609b commit 6e4e29d

2 files changed

Lines changed: 120 additions & 25 deletions

File tree

src/test/suite/views/data-browsing-app/preview-page.test.tsx

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,72 @@ describe('PreviewApp test suite', function () {
382382
expect(screen.getByText('1-10 of 50')).to.exist;
383383
});
384384

385+
it('should omit total count when count is unavailable', function () {
386+
renderWithProvider(<PreviewApp />);
387+
388+
const documents = Array.from({ length: 10 }, (_, i) => ({
389+
_id: String(i + 1),
390+
name: `Doc${i + 1}`,
391+
}));
392+
393+
act(() => {
394+
window.dispatchEvent(
395+
new MessageEvent('message', {
396+
data: {
397+
command: PreviewMessageType.loadPage,
398+
documents,
399+
},
400+
}),
401+
);
402+
window.dispatchEvent(
403+
new MessageEvent('message', {
404+
data: {
405+
command: PreviewMessageType.updateTotalCount,
406+
totalCount: null,
407+
},
408+
}),
409+
);
410+
});
411+
412+
const paginationText = screen.getByText('1-10');
413+
expect(paginationText).to.exist;
414+
expect(paginationText.textContent).to.equal('1-10');
415+
expect(screen.queryByText('1-10 of N/A')).to.be.null;
416+
});
417+
418+
it('should display count error when total count retrieval fails', function () {
419+
renderWithProvider(<PreviewApp />);
420+
421+
const documents = Array.from({ length: 10 }, (_, i) => ({
422+
_id: String(i + 1),
423+
name: `Doc${i + 1}`,
424+
}));
425+
const errorMessage = 'Count request failed';
426+
427+
act(() => {
428+
window.dispatchEvent(
429+
new MessageEvent('message', {
430+
data: {
431+
command: PreviewMessageType.loadPage,
432+
documents,
433+
},
434+
}),
435+
);
436+
window.dispatchEvent(
437+
new MessageEvent('message', {
438+
data: {
439+
command: PreviewMessageType.updateTotalCountError,
440+
error: errorMessage,
441+
},
442+
}),
443+
);
444+
});
445+
446+
const countError = screen.getByText('Error');
447+
expect(countError).to.exist;
448+
expect(countError.getAttribute('title')).to.equal(errorMessage);
449+
});
450+
385451
it('should not navigate when pagination buttons clicked while loading', function () {
386452
renderWithProvider(<PreviewApp />);
387453

src/views/data-browsing-app/preview-page.tsx

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,53 @@ const insertDocumentButtonStyles = css({
152152
},
153153
});
154154

155+
const Pagination: React.FC<{
156+
startItem: number;
157+
endItem: number;
158+
totalCountForQuery: number | null;
159+
hasReceivedCount: boolean;
160+
getTotalCountError: string | null;
161+
}> = ({
162+
startItem,
163+
endItem,
164+
totalCountForQuery,
165+
hasReceivedCount,
166+
getTotalCountError,
167+
}) => {
168+
// If for some reason we couldn't determine the count, don't mention the total
169+
// at all. If the count is still loading or there's an error, then we'll
170+
// display a loading indicator or the error in place of the total.
171+
if (hasReceivedCount && !getTotalCountError && totalCountForQuery === null) {
172+
return (
173+
<span className={paginationInfoStyles}>
174+
{startItem}-{endItem}
175+
</span>
176+
);
177+
}
178+
179+
return (
180+
<span className={paginationInfoStyles}>
181+
{startItem}-{endItem} of{' '}
182+
{!hasReceivedCount ? (
183+
<VscodeProgressRing
184+
style={{
185+
width: 14,
186+
height: 14,
187+
display: 'inline-block',
188+
verticalAlign: 'middle',
189+
}}
190+
/>
191+
) : getTotalCountError ? (
192+
<span className={countErrorStyles} title={getTotalCountError}>
193+
Error
194+
</span>
195+
) : (
196+
totalCountForQuery
197+
)}
198+
</span>
199+
);
200+
};
201+
155202
const PreviewApp: React.FC = () => {
156203
const dispatch = useAppDispatch();
157204

@@ -297,31 +344,13 @@ const PreviewApp: React.FC = () => {
297344
</VscodeSingleSelect>
298345

299346
{/* Pagination info */}
300-
<span className={paginationInfoStyles}>
301-
{startItem}-{endItem} of{' '}
302-
{!hasReceivedCount ? (
303-
<VscodeProgressRing
304-
style={{
305-
width: 14,
306-
height: 14,
307-
display: 'inline-block',
308-
verticalAlign: 'middle',
309-
}}
310-
/>
311-
) : getTotalCountError ? (
312-
<span className={countErrorStyles} title={getTotalCountError}>
313-
Error
314-
</span>
315-
) : viewType === 'cursor' ? (
316-
<span title="We don't know the total count">N/A</span>
317-
) : totalCountForQuery === null ? (
318-
<span title="We don't run a count for time series and views">
319-
N/A
320-
</span>
321-
) : (
322-
totalCountForQuery
323-
)}
324-
</span>
347+
<Pagination
348+
startItem={startItem}
349+
endItem={endItem}
350+
totalCountForQuery={totalCountForQuery}
351+
hasReceivedCount={hasReceivedCount}
352+
getTotalCountError={getTotalCountError}
353+
/>
325354

326355
{/* Page navigation arrows */}
327356
<div className={paginationArrowsStyles}>

0 commit comments

Comments
 (0)