Skip to content

Commit 331baaa

Browse files
committed
fix: show nav hints on empty pages, extract hint builders to reduce complexity
- Dashboard: buildHint now shows -c prev/-c next even when results are empty - Trace/span: empty-page branches now show -c prev when hasPrev is true - Extract buildNavHint helper in trace/list.ts to stay under complexity limit
1 parent 613bada commit 331baaa

File tree

4 files changed

+63
-41
lines changed

4 files changed

+63
-41
lines changed

src/commands/dashboard/list.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,23 +337,26 @@ function buildHint(
337337
result: DashboardListResult,
338338
orgSlug: string
339339
): string | undefined {
340-
if (result.dashboards.length === 0) {
341-
return;
342-
}
343340
const filterArg = result.titleFilter ? ` '${result.titleFilter}'` : "";
344341
const navParts: string[] = [];
345342
if (result.hasMore) {
346343
navParts.push(
347-
`Next page: sentry dashboard list ${orgSlug}/${filterArg} -c next`
344+
`Next: sentry dashboard list ${orgSlug}/${filterArg} -c next`
348345
);
349346
}
350347
if (result.hasPrev) {
351348
navParts.push(
352-
`Prev page: sentry dashboard list ${orgSlug}/${filterArg} -c prev`
349+
`Prev: sentry dashboard list ${orgSlug}/${filterArg} -c prev`
353350
);
354351
}
355352
const nav = navParts.length > 0 ? ` ${navParts.join(" | ")}` : "";
356353
const url = buildDashboardsListUrl(orgSlug);
354+
355+
if (result.dashboards.length === 0) {
356+
// Empty results — show nav hint if prev/next exist, otherwise nothing
357+
return nav ? `No dashboards found.${nav}` : undefined;
358+
}
359+
357360
return `Showing ${result.dashboards.length} dashboard(s).${nav}\nDashboards: ${url}`;
358361
}
359362

src/commands/span/list.ts

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -319,20 +319,23 @@ async function handleTraceMode(
319319
const flatSpans = spanItems.map(spanListItemToFlatSpan);
320320
const hasMore = !!nextCursor;
321321

322+
const navParts: string[] = [];
323+
if (hasPrev) {
324+
navParts.push(`Prev: ${tracePrevPageHint(org, project, traceId, flags)}`);
325+
}
326+
if (hasMore) {
327+
navParts.push(`Next: ${traceNextPageHint(org, project, traceId, flags)}`);
328+
}
329+
const nav = navParts.join(" | ");
330+
322331
let hint: string | undefined;
323-
if (flatSpans.length === 0 && hasMore) {
324-
hint = `Try the next page: ${traceNextPageHint(org, project, traceId, flags)}`;
332+
if (flatSpans.length === 0 && nav) {
333+
hint = `No spans on this page. ${nav}`;
325334
} else if (flatSpans.length > 0) {
326335
const countText = `Showing ${flatSpans.length} span${flatSpans.length === 1 ? "" : "s"}.`;
327-
if (hasMore && hasPrev) {
328-
hint = `${countText} Prev: ${tracePrevPageHint(org, project, traceId, flags)} | Next: ${traceNextPageHint(org, project, traceId, flags)}`;
329-
} else if (hasMore) {
330-
hint = `${countText} Next page: ${traceNextPageHint(org, project, traceId, flags)}`;
331-
} else if (hasPrev) {
332-
hint = `${countText} Prev: ${tracePrevPageHint(org, project, traceId, flags)}`;
333-
} else {
334-
hint = `${countText} Use 'sentry span view ${traceId} <span-id>' to view span details.`;
335-
}
336+
hint = nav
337+
? `${countText} ${nav}`
338+
: `${countText} Use 'sentry span view ${traceId} <span-id>' to view span details.`;
336339
}
337340

338341
return {
@@ -394,20 +397,23 @@ async function handleProjectMode(
394397
const flatSpans = spanItems.map(spanListItemToFlatSpan);
395398
const hasMore = !!nextCursor;
396399

400+
const navParts2: string[] = [];
401+
if (hasPrev) {
402+
navParts2.push(`Prev: ${projectPrevPageHint(org, project, flags)}`);
403+
}
404+
if (hasMore) {
405+
navParts2.push(`Next: ${projectNextPageHint(org, project, flags)}`);
406+
}
407+
const nav2 = navParts2.join(" | ");
408+
397409
let hint: string | undefined;
398-
if (flatSpans.length === 0 && hasMore) {
399-
hint = `Try the next page: ${projectNextPageHint(org, project, flags)}`;
410+
if (flatSpans.length === 0 && nav2) {
411+
hint = `No spans on this page. ${nav2}`;
400412
} else if (flatSpans.length > 0) {
401413
const countText = `Showing ${flatSpans.length} span${flatSpans.length === 1 ? "" : "s"}.`;
402-
if (hasMore && hasPrev) {
403-
hint = `${countText} Prev: ${projectPrevPageHint(org, project, flags)} | Next: ${projectNextPageHint(org, project, flags)}`;
404-
} else if (hasMore) {
405-
hint = `${countText} Next page: ${projectNextPageHint(org, project, flags)}`;
406-
} else if (hasPrev) {
407-
hint = `${countText} Prev: ${projectPrevPageHint(org, project, flags)}`;
408-
} else {
409-
hint = `${countText} Use 'sentry span view <trace-id> <span-id>' to view span details.`;
410-
}
414+
hint = nav2
415+
? `${countText} ${nav2}`
416+
: `${countText} Use 'sentry span view <trace-id> <span-id>' to view span details.`;
411417
}
412418

413419
return {

src/commands/trace/list.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,24 @@ function prevPageHint(
117117
return appendTraceFlags(`sentry trace list ${org}/${project} -c prev`, flags);
118118
}
119119

120+
/** Build a combined nav hint string from prev/next hints. */
121+
function buildNavHint(opts: {
122+
hasMore: boolean;
123+
hasPrev: boolean;
124+
org: string;
125+
project: string;
126+
flags: Pick<ListFlags, "sort" | "query" | "period">;
127+
}): string {
128+
const parts: string[] = [];
129+
if (opts.hasPrev) {
130+
parts.push(`Prev: ${prevPageHint(opts.org, opts.project, opts.flags)}`);
131+
}
132+
if (opts.hasMore) {
133+
parts.push(`Next: ${nextPageHint(opts.org, opts.project, opts.flags)}`);
134+
}
135+
return parts.join(" | ");
136+
}
137+
120138
/**
121139
* Parse --limit flag, delegating range validation to shared utility.
122140
*/
@@ -293,20 +311,15 @@ export const listCommand = buildListCommand("trace", {
293311
const hasMore = !!nextCursor;
294312

295313
// Build footer hint based on result state
314+
const nav = buildNavHint({ hasMore, hasPrev, org, project, flags });
296315
let hint: string | undefined;
297-
if (traces.length === 0 && hasMore) {
298-
hint = `Try the next page: ${nextPageHint(org, project, flags)}`;
316+
if (traces.length === 0 && nav) {
317+
hint = `No traces on this page. ${nav}`;
299318
} else if (traces.length > 0) {
300319
const countText = `Showing ${traces.length} trace${traces.length === 1 ? "" : "s"}.`;
301-
if (hasMore && hasPrev) {
302-
hint = `${countText} Prev: ${prevPageHint(org, project, flags)} | Next: ${nextPageHint(org, project, flags)}`;
303-
} else if (hasMore) {
304-
hint = `${countText} Next page: ${nextPageHint(org, project, flags)}`;
305-
} else if (hasPrev) {
306-
hint = `${countText} Prev: ${prevPageHint(org, project, flags)}`;
307-
} else {
308-
hint = `${countText} Use 'sentry trace view <TRACE_ID>' to view the full span tree.`;
309-
}
320+
hint = nav
321+
? `${countText} ${nav}`
322+
: `${countText} Use 'sentry trace view <TRACE_ID>' to view the full span tree.`;
310323
}
311324

312325
yield new CommandOutput({

test/commands/trace/list.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ describe("listCommand.func", () => {
378378
);
379379

380380
const output = stdoutWrite.mock.calls.map((c) => c[0]).join("");
381-
expect(output).toContain("Next page:");
381+
expect(output).toContain("Next:");
382382
expect(output).toContain("-c next");
383383
});
384384

@@ -394,7 +394,7 @@ describe("listCommand.func", () => {
394394
);
395395

396396
const output = stdoutWrite.mock.calls.map((c) => c[0]).join("");
397-
expect(output).not.toContain("Next page:");
397+
expect(output).not.toContain("Next:");
398398
expect(output).toContain("sentry trace view");
399399
});
400400

@@ -482,7 +482,7 @@ describe("listCommand.func", () => {
482482
);
483483

484484
const output = stdoutWrite.mock.calls.map((c) => c[0]).join("");
485-
expect(output).toContain("Next page:");
485+
expect(output).toContain("Next:");
486486
expect(output).toContain("-c next");
487487
expect(output).toContain("--sort duration");
488488
});

0 commit comments

Comments
 (0)