Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 54 additions & 21 deletions src/commands/blueprint/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Operation } from "../../components/OperationsMenu.js";
import { ActionsPopup } from "../../components/ActionsPopup.js";
import { formatTimeAgo } from "../../components/ResourceListView.js";
import { SearchBar } from "../../components/SearchBar.js";
import { output, outputError } from "../../utils/output.js";
import { output, outputError, parseLimit } from "../../utils/output.js";
import { getBlueprintUrl } from "../../utils/url.js";
import { colors } from "../../utils/theme.js";
import { getStatusDisplay } from "../../components/StatusBadge.js";
Expand Down Expand Up @@ -148,7 +148,7 @@ const ListBlueprintsUI = ({
const result = {
items: pageBlueprints,
hasMore: page.has_more || false,
totalCount: page.total_count || pageBlueprints.length,
totalCount: pageBlueprints.length,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats the effect of taking this || branch only - doesn't this affect how the UI shows the number of total results?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be no effect

};

return result;
Expand Down Expand Up @@ -179,7 +179,7 @@ const ListBlueprintsUI = ({
!executingOperation &&
!showDeleteConfirm &&
!search.searchMode,
deps: [PAGE_SIZE, search.submittedSearchQuery],
deps: [search.submittedSearchQuery],
});

// Memoize columns array
Expand Down Expand Up @@ -624,10 +624,18 @@ const ListBlueprintsUI = ({
bindings: {
up: () => {
if (selectedIndex > 0) setSelectedIndex(selectedIndex - 1);
else if (!loading && !navigating && hasPrev) {
prevPage();
setSelectedIndex(blueprints.length - 1);
}
},
down: () => {
if (selectedIndex < blueprints.length - 1)
setSelectedIndex(selectedIndex + 1);
else if (!loading && !navigating && hasMore) {
nextPage();
setSelectedIndex(0);
}
},
n: goToNextPage,
right: goToNextPage,
Expand Down Expand Up @@ -875,7 +883,7 @@ const ListBlueprintsUI = ({
data={blueprints}
keyExtractor={(blueprint: BlueprintListItem) => blueprint.id}
selectedIndex={selectedIndex}
title={`blueprints[${totalCount}]`}
title={`blueprints[${hasMore ? `${totalCount}+` : totalCount}]`}
columns={blueprintColumns}
emptyState={
<Text color={colors.textDim}>
Expand All @@ -889,7 +897,7 @@ const ListBlueprintsUI = ({
{!showPopup && (
<Box marginTop={1} paddingX={1}>
<Text color={colors.primary} bold>
{figures.hamburger} {totalCount}
{figures.hamburger} {hasMore ? `${totalCount}+` : totalCount}
</Text>
<Text color={colors.textDim} dimColor>
{" "}
Expand All @@ -907,7 +915,8 @@ const ListBlueprintsUI = ({
</Text>
) : (
<Text color={colors.textDim} dimColor>
Page {currentPage + 1} of {totalPages}
Page {currentPage + 1} of{" "}
{hasMore ? `${totalPages}+` : totalPages}
</Text>
)}
</>
Expand All @@ -917,7 +926,8 @@ const ListBlueprintsUI = ({
•{" "}
</Text>
<Text color={colors.textDim} dimColor>
Showing {startIndex + 1}-{endIndex} of {totalCount}
Showing {startIndex + 1}-{endIndex} of{" "}
{hasMore ? `${totalCount}+` : totalCount}
</Text>
{search.submittedSearchQuery && (
<>
Expand Down Expand Up @@ -982,6 +992,7 @@ const ListBlueprintsUI = ({

interface ListBlueprintsOptions {
name?: string;
limit?: string;
output?: string;
}

Expand All @@ -992,23 +1003,45 @@ export async function listBlueprints(options: ListBlueprintsOptions = {}) {
try {
const client = getClient();

// Build query params
const queryParams: Record<string, unknown> = {
limit: DEFAULT_PAGE_SIZE,
};
if (options.name) {
queryParams.name = options.name;
}
const maxResults = parseLimit(options.limit);
const allBlueprints: unknown[] = [];
let startingAfter: string | undefined;

// Fetch blueprints
const page = (await client.blueprints.list(
queryParams,
)) as BlueprintsCursorIDPage<{ id: string }>;
do {
const remaining = maxResults - allBlueprints.length;
// Build query params
const queryParams: Record<string, unknown> = {
limit: Math.min(DEFAULT_PAGE_SIZE, remaining),
};
if (options.name) {
queryParams.name = options.name;
}
if (startingAfter) {
queryParams.starting_after = startingAfter;
}

// Extract blueprints array
const blueprints = page.blueprints || [];
// Fetch one page
const page = (await client.blueprints.list(
queryParams,
)) as BlueprintsCursorIDPage<{ id: string }>;

const pageBlueprints = page.blueprints || [];
allBlueprints.push(...pageBlueprints);

if (
page.has_more &&
pageBlueprints.length > 0 &&
allBlueprints.length < maxResults
) {
startingAfter = (
pageBlueprints[pageBlueprints.length - 1] as { id: string }
).id;
} else {
startingAfter = undefined;
}
} while (startingAfter !== undefined);

output(blueprints, { format: options.output, defaultFormat: "json" });
output(allBlueprints, { format: options.output, defaultFormat: "json" });
} catch (error) {
outputError("Failed to list blueprints", error);
}
Expand Down
72 changes: 52 additions & 20 deletions src/commands/devbox/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { Column } from "../../components/Table.js";
import { Table, createTextColumn } from "../../components/Table.js";
import { formatTimeAgo } from "../../components/ResourceListView.js";
import { SearchBar } from "../../components/SearchBar.js";
import { output, outputError } from "../../utils/output.js";
import { output, outputError, parseLimit } from "../../utils/output.js";
import { DevboxDetailPage } from "../../components/DevboxDetailPage.js";
import { DevboxCreatePage } from "../../components/DevboxCreatePage.js";
import { ResourceActionsMenu } from "../../components/ResourceActionsMenu.js";
Expand Down Expand Up @@ -117,7 +117,7 @@ const ListDevboxesUI = ({
const result = {
items: pageDevboxes,
hasMore: page.has_more || false,
totalCount: page.total_count || pageDevboxes.length,
totalCount: pageDevboxes.length,
};

return result;
Expand Down Expand Up @@ -148,7 +148,7 @@ const ListDevboxesUI = ({
!showActions &&
!showPopup &&
!search.searchMode,
deps: [status, search.submittedSearchQuery, PAGE_SIZE],
deps: [status, search.submittedSearchQuery],
});

// Sync devboxes to store for detail screen
Expand Down Expand Up @@ -559,10 +559,18 @@ const ListDevboxesUI = ({
bindings: {
up: () => {
if (selectedIndex > 0) setSelectedIndex(selectedIndex - 1);
else if (!loading && !navigating && hasPrev) {
prevPage();
setSelectedIndex(devboxes.length - 1);
}
},
down: () => {
if (selectedIndex < devboxes.length - 1)
setSelectedIndex(selectedIndex + 1);
else if (!loading && !navigating && hasMore) {
nextPage();
setSelectedIndex(0);
}
},
n: goToNextPage,
right: goToNextPage,
Expand Down Expand Up @@ -712,7 +720,7 @@ const ListDevboxesUI = ({
{!showPopup && (
<Box marginTop={1} paddingX={1}>
<Text color={colors.primary} bold>
{figures.hamburger} {totalCount}
{figures.hamburger} {hasMore ? `${totalCount}+` : totalCount}
</Text>
<Text color={colors.textDim} dimColor>
{" "}
Expand All @@ -730,7 +738,8 @@ const ListDevboxesUI = ({
</Text>
) : (
<Text color={colors.textDim} dimColor>
Page {currentPage + 1} of {totalPages}
Page {currentPage + 1} of{" "}
{hasMore ? `${totalPages}+` : totalPages}
</Text>
)}
</>
Expand All @@ -740,7 +749,8 @@ const ListDevboxesUI = ({
•{" "}
</Text>
<Text color={colors.textDim} dimColor>
Showing {startIndex + 1}-{endIndex} of {totalCount}
Showing {startIndex + 1}-{endIndex} of{" "}
{hasMore ? `${totalCount}+` : totalCount}
</Text>
{search.submittedSearchQuery && (
<>
Expand Down Expand Up @@ -796,23 +806,45 @@ export async function listDevboxes(options: ListOptions) {
try {
const client = getClient();

// Build query params
const queryParams: Record<string, unknown> = {
limit: options.limit ? parseInt(options.limit, 10) : DEFAULT_PAGE_SIZE,
};
if (options.status) {
queryParams.status = options.status;
}
const maxResults = parseLimit(options.limit);
const allDevboxes: unknown[] = [];
let startingAfter: string | undefined;

// Fetch devboxes
const page = (await client.devboxes.list(
queryParams,
)) as DevboxesCursorIDPage<{ id: string }>;
do {
const remaining = maxResults - allDevboxes.length;
// Build query params
const queryParams: Record<string, unknown> = {
limit: Math.min(DEFAULT_PAGE_SIZE, remaining),
};
if (options.status) {
queryParams.status = options.status;
}
if (startingAfter) {
queryParams.starting_after = startingAfter;
}

// Extract devboxes array
const devboxes = page.devboxes || [];
// Fetch one page
const page = (await client.devboxes.list(
queryParams,
)) as DevboxesCursorIDPage<{ id: string }>;

const pageDevboxes = page.devboxes || [];
allDevboxes.push(...pageDevboxes);

if (
page.has_more &&
pageDevboxes.length > 0 &&
allDevboxes.length < maxResults
) {
startingAfter = (
pageDevboxes[pageDevboxes.length - 1] as { id: string }
).id;
} else {
startingAfter = undefined;
}
} while (startingAfter !== undefined);

output(devboxes, { format: options.output, defaultFormat: "json" });
output(allDevboxes, { format: options.output, defaultFormat: "json" });
} catch (error) {
outputError("Failed to list devboxes", error);
}
Expand Down
Loading
Loading