Skip to content
Open
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
32 changes: 22 additions & 10 deletions src/commands/blueprint/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ const ListBlueprintsUI = ({

// Fetch function for pagination hook
const fetchPage = React.useCallback(
async (params: { limit: number; startingAt?: string }) => {
async (params: {
limit: number;
startingAt?: string;
includeTotalCount?: boolean;
}) => {
const client = getClient();
const pageBlueprints: BlueprintListItem[] = [];

Expand All @@ -127,11 +131,17 @@ const ListBlueprintsUI = ({
if (search.submittedSearchQuery) {
queryParams.search = search.submittedSearchQuery;
}
// Only request total_count on first page (expensive for backend)
if (params.includeTotalCount) {
queryParams.include_total_count = true;
}

// Fetch ONE page only
const page = (await client.blueprints.list(
queryParams,
)) as unknown as BlueprintsCursorIDPage<BlueprintListItem>;
)) as unknown as BlueprintsCursorIDPage<BlueprintListItem> & {
total_count?: number;
};

// Extract data and create defensive copies
if (page.blueprints && Array.isArray(page.blueprints)) {
Expand All @@ -148,7 +158,7 @@ const ListBlueprintsUI = ({
const result = {
items: pageBlueprints,
hasMore: page.has_more || false,
totalCount: pageBlueprints.length,
totalCount: page.total_count,
};

return result;
Expand Down Expand Up @@ -356,7 +366,11 @@ const ListBlueprintsUI = ({
// Calculate pagination info for display
const totalPages = Math.max(1, Math.ceil(totalCount / PAGE_SIZE));
const startIndex = currentPage * PAGE_SIZE;
const endIndex = startIndex + blueprints.length;
const endIndex = Math.min(startIndex + blueprints.length, totalCount);
const showingRange =
endIndex === startIndex + 1
? `${startIndex + 1}`
: `${startIndex + 1}-${endIndex}`;

const executeOperation = async (
blueprintOverride?: BlueprintListItem,
Expand Down Expand Up @@ -883,7 +897,7 @@ const ListBlueprintsUI = ({
data={blueprints}
keyExtractor={(blueprint: BlueprintListItem) => blueprint.id}
selectedIndex={selectedIndex}
title={`blueprints[${hasMore ? `${totalCount}+` : totalCount}]`}
title={`blueprints[${totalCount}]`}
columns={blueprintColumns}
emptyState={
<Text color={colors.textDim}>
Expand All @@ -897,7 +911,7 @@ const ListBlueprintsUI = ({
{!showPopup && (
<Box marginTop={1} paddingX={1}>
<Text color={colors.primary} bold>
{figures.hamburger} {hasMore ? `${totalCount}+` : totalCount}
{figures.hamburger} {totalCount}
</Text>
<Text color={colors.textDim} dimColor>
{" "}
Expand All @@ -915,8 +929,7 @@ const ListBlueprintsUI = ({
</Text>
) : (
<Text color={colors.textDim} dimColor>
Page {currentPage + 1} of{" "}
{hasMore ? `${totalPages}+` : totalPages}
Page {currentPage + 1} of {totalPages}
</Text>
)}
</>
Expand All @@ -926,8 +939,7 @@ const ListBlueprintsUI = ({
•{" "}
</Text>
<Text color={colors.textDim} dimColor>
Showing {startIndex + 1}-{endIndex} of{" "}
{hasMore ? `${totalCount}+` : totalCount}
Showing {showingRange} of {totalCount}
</Text>
{search.submittedSearchQuery && (
<>
Expand Down
30 changes: 20 additions & 10 deletions src/commands/devbox/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ const ListDevboxesUI = ({

// Fetch function for pagination hook
const fetchPage = React.useCallback(
async (params: { limit: number; startingAt?: string }) => {
async (params: {
limit: number;
startingAt?: string;
includeTotalCount?: boolean;
}) => {
const client = getClient();
const pageDevboxes: Devbox[] = [];

Expand All @@ -95,11 +99,15 @@ const ListDevboxesUI = ({
if (search.submittedSearchQuery) {
queryParams.search = search.submittedSearchQuery;
}
// Only request total_count on first page (expensive for backend)
if (params.includeTotalCount) {
queryParams.include_total_count = true;
}

// Fetch ONE page only
const page = (await client.devboxes.list(
queryParams,
)) as unknown as DevboxesCursorIDPage<Devbox>;
)) as unknown as DevboxesCursorIDPage<Devbox> & { total_count?: number };

// Extract data and create defensive copies using JSON serialization
if (page.devboxes && Array.isArray(page.devboxes)) {
Expand All @@ -111,7 +119,7 @@ const ListDevboxesUI = ({
const result = {
items: pageDevboxes,
hasMore: page.has_more || false,
totalCount: pageDevboxes.length,
totalCount: page.total_count,
};

return result;
Expand Down Expand Up @@ -419,7 +427,11 @@ const ListDevboxesUI = ({
// Calculate pagination info for display
const totalPages = Math.max(1, Math.ceil(totalCount / PAGE_SIZE));
const startIndex = currentPage * PAGE_SIZE;
const endIndex = startIndex + devboxes.length;
const endIndex = Math.min(startIndex + devboxes.length, totalCount);
const showingRange =
endIndex === startIndex + 1
? `${startIndex + 1}`
: `${startIndex + 1}-${endIndex}`;

// Filter operations based on devbox status
const hasTunnel = !!(
Expand Down Expand Up @@ -709,7 +721,7 @@ const ListDevboxesUI = ({
data={devboxes}
keyExtractor={(devbox: Devbox) => devbox.id}
selectedIndex={selectedIndex}
title="devboxes"
title={`devboxes[${totalCount}]`}
columns={tableColumns}
emptyState={
<Text color={colors.textDim}>
Expand All @@ -723,7 +735,7 @@ const ListDevboxesUI = ({
{!showPopup && (
<Box marginTop={1} paddingX={1}>
<Text color={colors.primary} bold>
{figures.hamburger} {hasMore ? `${totalCount}+` : totalCount}
{figures.hamburger} {totalCount}
</Text>
<Text color={colors.textDim} dimColor>
{" "}
Expand All @@ -741,8 +753,7 @@ const ListDevboxesUI = ({
</Text>
) : (
<Text color={colors.textDim} dimColor>
Page {currentPage + 1} of{" "}
{hasMore ? `${totalPages}+` : totalPages}
Page {currentPage + 1} of {totalPages}
</Text>
)}
</>
Expand All @@ -752,8 +763,7 @@ const ListDevboxesUI = ({
•{" "}
</Text>
<Text color={colors.textDim} dimColor>
Showing {startIndex + 1}-{endIndex} of{" "}
{hasMore ? `${totalCount}+` : totalCount}
Showing {showingRange} of {totalCount}
</Text>
{search.submittedSearchQuery && (
<>
Expand Down
32 changes: 22 additions & 10 deletions src/commands/gateway-config/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ const ListGatewayConfigsUI = ({

// Fetch function for pagination hook
const fetchPage = React.useCallback(
async (params: { limit: number; startingAt?: string }) => {
async (params: {
limit: number;
startingAt?: string;
includeTotalCount?: boolean;
}) => {
const client = getClient();
const pageConfigs: GatewayConfigListItem[] = [];

Expand All @@ -136,11 +140,17 @@ const ListGatewayConfigsUI = ({
if (search.submittedSearchQuery) {
queryParams.name = search.submittedSearchQuery;
}
// Only request total_count on first page (expensive for backend)
if (params.includeTotalCount) {
queryParams.include_total_count = true;
}

// Fetch ONE page only
const page = (await client.gatewayConfigs.list(
queryParams,
)) as unknown as GatewayConfigsCursorIDPage<GatewayConfigListItem>;
)) as unknown as GatewayConfigsCursorIDPage<GatewayConfigListItem> & {
total_count?: number;
};

// Extract data and create defensive copies
if (page.gateway_configs && Array.isArray(page.gateway_configs)) {
Expand All @@ -163,7 +173,7 @@ const ListGatewayConfigsUI = ({
const result = {
items: pageConfigs,
hasMore: page.has_more || false,
totalCount: pageConfigs.length,
totalCount: page.total_count,
};

return result;
Expand Down Expand Up @@ -304,7 +314,11 @@ const ListGatewayConfigsUI = ({
// Calculate pagination info for display
const totalPages = Math.max(1, Math.ceil(totalCount / PAGE_SIZE));
const startIndex = currentPage * PAGE_SIZE;
const endIndex = startIndex + configs.length;
const endIndex = Math.min(startIndex + configs.length, totalCount);
const showingRange =
endIndex === startIndex + 1
? `${startIndex + 1}`
: `${startIndex + 1}-${endIndex}`;

const executeOperation = async (
config: GatewayConfigListItem,
Expand Down Expand Up @@ -653,7 +667,7 @@ const ListGatewayConfigsUI = ({
data={configs}
keyExtractor={(config: GatewayConfigListItem) => config.id}
selectedIndex={selectedIndex}
title={`gateway_configs[${hasMore ? `${totalCount}+` : totalCount}]`}
title={`gateway_configs[${totalCount}]`}
columns={columns}
emptyState={
<Text color={colors.textDim}>
Expand All @@ -668,7 +682,7 @@ const ListGatewayConfigsUI = ({
{!showPopup && (
<Box marginTop={1} paddingX={1}>
<Text color={colors.primary} bold>
{figures.hamburger} {hasMore ? `${totalCount}+` : totalCount}
{figures.hamburger} {totalCount}
</Text>
<Text color={colors.textDim} dimColor>
{" "}
Expand All @@ -686,8 +700,7 @@ const ListGatewayConfigsUI = ({
</Text>
) : (
<Text color={colors.textDim} dimColor>
Page {currentPage + 1} of{" "}
{hasMore ? `${totalPages}+` : totalPages}
Page {currentPage + 1} of {totalPages}
</Text>
)}
</>
Expand All @@ -697,8 +710,7 @@ const ListGatewayConfigsUI = ({
•{" "}
</Text>
<Text color={colors.textDim} dimColor>
Showing {startIndex + 1}-{endIndex} of{" "}
{hasMore ? `${totalCount}+` : totalCount}
Showing {showingRange} of {totalCount}
</Text>
{search.submittedSearchQuery && (
<>
Expand Down
32 changes: 22 additions & 10 deletions src/commands/mcp-config/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ const ListMcpConfigsUI = ({
const nameWidth = Math.min(80, Math.max(15, remainingWidth));

const fetchPage = React.useCallback(
async (params: { limit: number; startingAt?: string }) => {
async (params: {
limit: number;
startingAt?: string;
includeTotalCount?: boolean;
}) => {
const client = getClient();
const pageConfigs: McpConfigListItem[] = [];

Expand All @@ -116,10 +120,16 @@ const ListMcpConfigsUI = ({
if (search.submittedSearchQuery) {
queryParams.name = search.submittedSearchQuery;
}
// Only request total_count on first page (expensive for backend)
if (params.includeTotalCount) {
queryParams.include_total_count = true;
}

const page = (await client.mcpConfigs.list(
queryParams,
)) as unknown as McpConfigsCursorIDPage<McpConfigListItem>;
)) as unknown as McpConfigsCursorIDPage<McpConfigListItem> & {
total_count?: number;
};

if (page.mcp_configs && Array.isArray(page.mcp_configs)) {
page.mcp_configs.forEach((m: McpConfigListItem) => {
Expand All @@ -139,7 +149,7 @@ const ListMcpConfigsUI = ({
return {
items: pageConfigs,
hasMore: page.has_more || false,
totalCount: pageConfigs.length,
totalCount: page.total_count,
};
},
[search.submittedSearchQuery],
Expand Down Expand Up @@ -266,7 +276,11 @@ const ListMcpConfigsUI = ({

const totalPages = Math.max(1, Math.ceil(totalCount / PAGE_SIZE));
const startIndex = currentPage * PAGE_SIZE;
const endIndex = startIndex + configs.length;
const endIndex = Math.min(startIndex + configs.length, totalCount);
const showingRange =
endIndex === startIndex + 1
? `${startIndex + 1}`
: `${startIndex + 1}-${endIndex}`;

const executeOperation = async (
config: McpConfigListItem,
Expand Down Expand Up @@ -580,7 +594,7 @@ const ListMcpConfigsUI = ({
data={configs}
keyExtractor={(config: McpConfigListItem) => config.id}
selectedIndex={selectedIndex}
title={`mcp_configs[${hasMore ? `${totalCount}+` : totalCount}]`}
title={`mcp_configs[${totalCount}]`}
columns={columns}
emptyState={
<Text color={colors.textDim}>
Expand All @@ -593,7 +607,7 @@ const ListMcpConfigsUI = ({
{!showPopup && (
<Box marginTop={1} paddingX={1}>
<Text color={colors.primary} bold>
{figures.hamburger} {hasMore ? `${totalCount}+` : totalCount}
{figures.hamburger} {totalCount}
</Text>
<Text color={colors.textDim} dimColor>
{" "}
Expand All @@ -611,8 +625,7 @@ const ListMcpConfigsUI = ({
</Text>
) : (
<Text color={colors.textDim} dimColor>
Page {currentPage + 1} of{" "}
{hasMore ? `${totalPages}+` : totalPages}
Page {currentPage + 1} of {totalPages}
</Text>
)}
</>
Expand All @@ -622,8 +635,7 @@ const ListMcpConfigsUI = ({
•{" "}
</Text>
<Text color={colors.textDim} dimColor>
Showing {startIndex + 1}-{endIndex} of{" "}
{hasMore ? `${totalCount}+` : totalCount}
Showing {showingRange} of {totalCount}
</Text>
{search.submittedSearchQuery && (
<>
Expand Down
Loading
Loading