Skip to content

Commit f441f04

Browse files
committed
cp dines
1 parent 60e9c81 commit f441f04

3 files changed

Lines changed: 61 additions & 40 deletions

File tree

src/cli.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,9 @@ const blueprint = program
389389
"./utils/interactiveCommand.js"
390390
);
391391
const { listBlueprints } = await import("./commands/blueprint/list.js");
392-
await runInteractiveCommand(() => listBlueprints({ output: "interactive" }));
392+
await runInteractiveCommand(() =>
393+
listBlueprints({ output: "interactive" }),
394+
);
393395
});
394396

395397
blueprint

src/commands/blueprint/list.tsx

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const ListBlueprintsUI: React.FC<{
4444
);
4545
const [loading, setLoading] = React.useState(false);
4646
const [showCreateDevbox, setShowCreateDevbox] = React.useState(false);
47-
47+
4848
// List view state - moved to top to ensure hooks are called in same order
4949
const [blueprints, setBlueprints] = React.useState<any[]>([]);
5050
const [listError, setListError] = React.useState<Error | null>(null);
@@ -67,25 +67,29 @@ const ListBlueprintsUI: React.FC<{
6767
// Helper function to generate operations based on selected blueprint
6868
const getOperationsForBlueprint = (blueprint: any): Operation[] => {
6969
const operations: Operation[] = [];
70-
70+
7171
// Only show create devbox option if blueprint is successfully built
72-
if (blueprint && (blueprint.status === "build_complete" || blueprint.status === "building_complete")) {
72+
if (
73+
blueprint &&
74+
(blueprint.status === "build_complete" ||
75+
blueprint.status === "building_complete")
76+
) {
7377
operations.push({
7478
key: "create_devbox",
7579
label: "Create Devbox from Blueprint",
7680
color: colors.success,
7781
icon: figures.play,
7882
});
7983
}
80-
84+
8185
// Always show delete option
8286
operations.push({
8387
key: "delete",
8488
label: "Delete Blueprint",
8589
color: colors.error,
8690
icon: figures.cross,
8791
});
88-
92+
8993
return operations;
9094
};
9195

@@ -150,7 +154,6 @@ const ListBlueprintsUI: React.FC<{
150154
return;
151155
}
152156

153-
154157
// Handle create devbox view
155158
if (showCreateDevbox) {
156159
return; // Let DevboxCreatePage handle its own input
@@ -160,13 +163,16 @@ const ListBlueprintsUI: React.FC<{
160163
if (showPopup) {
161164
if (key.upArrow && selectedOperation > 0) {
162165
setSelectedOperation(selectedOperation - 1);
163-
} else if (key.downArrow && selectedOperation < allOperations.length - 1) {
166+
} else if (
167+
key.downArrow &&
168+
selectedOperation < allOperations.length - 1
169+
) {
164170
setSelectedOperation(selectedOperation + 1);
165171
} else if (key.return) {
166172
console.clear();
167173
setShowPopup(false);
168174
const operationKey = allOperations[selectedOperation].key;
169-
175+
170176
if (operationKey === "create_devbox") {
171177
// Go directly to create devbox screen
172178
setSelectedBlueprint(selectedBlueprintItem);
@@ -183,22 +189,27 @@ const ListBlueprintsUI: React.FC<{
183189
setSelectedOperation(0);
184190
} else if (input === "c") {
185191
// Create devbox hotkey - only if blueprint is complete
186-
if (selectedBlueprintItem &&
187-
(selectedBlueprintItem.status === "build_complete" || selectedBlueprintItem.status === "building_complete")) {
192+
if (
193+
selectedBlueprintItem &&
194+
(selectedBlueprintItem.status === "build_complete" ||
195+
selectedBlueprintItem.status === "building_complete")
196+
) {
188197
console.clear();
189198
setShowPopup(false);
190199
setSelectedBlueprint(selectedBlueprintItem);
191200
setShowCreateDevbox(true);
192201
}
193202
} else if (input === "d") {
194203
// Delete hotkey
195-
const deleteIndex = allOperations.findIndex(op => op.key === "delete");
204+
const deleteIndex = allOperations.findIndex(
205+
(op) => op.key === "delete",
206+
);
196207
if (deleteIndex >= 0) {
197-
console.clear();
198-
setShowPopup(false);
199-
setSelectedBlueprint(selectedBlueprintItem);
200-
setExecutingOperation("delete");
201-
executeOperation();
208+
console.clear();
209+
setShowPopup(false);
210+
setSelectedBlueprint(selectedBlueprintItem);
211+
setExecutingOperation("delete");
212+
executeOperation();
202213
}
203214
}
204215
return; // prevent falling through to list nav
@@ -226,7 +237,10 @@ const ListBlueprintsUI: React.FC<{
226237
setSelectedIndex(selectedIndex - 1);
227238
} else if (key.downArrow && selectedIndex < pageBlueprints - 1) {
228239
setSelectedIndex(selectedIndex + 1);
229-
} else if ((input === "n" || key.rightArrow) && currentPage < totalPages - 1) {
240+
} else if (
241+
(input === "n" || key.rightArrow) &&
242+
currentPage < totalPages - 1
243+
) {
230244
setCurrentPage(currentPage + 1);
231245
setSelectedIndex(0);
232246
} else if ((input === "p" || key.leftArrow) && currentPage > 0) {
@@ -271,18 +285,19 @@ const ListBlueprintsUI: React.FC<{
271285

272286
// Ensure selected index is within bounds - place before any returns
273287
React.useEffect(() => {
274-
if (currentBlueprints.length > 0 && selectedIndex >= currentBlueprints.length) {
288+
if (
289+
currentBlueprints.length > 0 &&
290+
selectedIndex >= currentBlueprints.length
291+
) {
275292
setSelectedIndex(Math.max(0, currentBlueprints.length - 1));
276293
}
277294
}, [currentBlueprints.length, selectedIndex]);
278295

279296
const selectedBlueprintItem = currentBlueprints[selectedIndex];
280-
297+
281298
// Generate operations based on selected blueprint status
282299
const allOperations = getOperationsForBlueprint(selectedBlueprintItem);
283300

284-
285-
286301
const executeOperation = async () => {
287302
const client = getClient();
288303
const blueprint = selectedBlueprint;
@@ -311,7 +326,6 @@ const ListBlueprintsUI: React.FC<{
311326
}
312327
};
313328

314-
315329
// Filter operations based on blueprint status
316330
const operations = selectedBlueprint
317331
? allOperations.filter((op) => {
@@ -455,7 +469,6 @@ const ListBlueprintsUI: React.FC<{
455469
);
456470
}
457471

458-
459472
// Loading state
460473
if (loading) {
461474
return (
@@ -471,10 +484,7 @@ const ListBlueprintsUI: React.FC<{
471484
return (
472485
<>
473486
<Breadcrumb items={[{ label: "Blueprints", active: true }]} />
474-
<ErrorMessage
475-
message="Failed to load blueprints"
476-
error={listError}
477-
/>
487+
<ErrorMessage message="Failed to load blueprints" error={listError} />
478488
</>
479489
);
480490
}
@@ -503,7 +513,7 @@ const ListBlueprintsUI: React.FC<{
503513
return (
504514
<>
505515
<Breadcrumb items={[{ label: "Blueprints", active: true }]} />
506-
516+
507517
{/* Table */}
508518
<Table
509519
data={currentBlueprints}
@@ -525,7 +535,7 @@ const ListBlueprintsUI: React.FC<{
525535
<Text
526536
color={isSelected ? "white" : statusColor}
527537
bold={true}
528-
dimColor={false}
538+
dimColor={false}
529539
inverse={isSelected}
530540
wrap="truncate"
531541
>
@@ -572,7 +582,7 @@ const ListBlueprintsUI: React.FC<{
572582
<Text
573583
color={isSelected ? "white" : statusColor}
574584
bold={true}
575-
dimColor={false}
585+
dimColor={false}
576586
inverse={isSelected}
577587
wrap="truncate"
578588
>
@@ -661,7 +671,11 @@ const ListBlueprintsUI: React.FC<{
661671
color: op.color,
662672
icon: op.icon,
663673
shortcut:
664-
op.key === "create_devbox" ? "c" : op.key === "delete" ? "d" : "",
674+
op.key === "create_devbox"
675+
? "c"
676+
: op.key === "delete"
677+
? "d"
678+
: "",
665679
}))}
666680
selectedOperation={selectedOperation}
667681
onClose={() => setShowPopup(false)}

src/components/ResourceActionsMenu.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,17 @@ type DevboxMenuProps = BaseProps & {
3434
type BlueprintMenuProps = BaseProps & {
3535
resourceType: "blueprint";
3636
operations: OperationDef[];
37-
onExecute: (opKey: string, args: { input?: string }) => Promise<string | void>;
37+
onExecute: (
38+
opKey: string,
39+
args: { input?: string },
40+
) => Promise<string | void>;
3841
};
3942

4043
type ResourceActionsMenuProps = DevboxMenuProps | BlueprintMenuProps;
4144

42-
export const ResourceActionsMenu: React.FC<ResourceActionsMenuProps> = (props) => {
45+
export const ResourceActionsMenu: React.FC<ResourceActionsMenuProps> = (
46+
props,
47+
) => {
4348
if (props.resourceType === "devbox") {
4449
const {
4550
resource,
@@ -82,9 +87,9 @@ export const ResourceActionsMenu: React.FC<ResourceActionsMenuProps> = (props) =
8287
const [selectedOperation, setSelectedOperation] = React.useState(
8388
initialOperationIndex,
8489
);
85-
const [executingOperation, setExecutingOperation] = React.useState<string | null>(
86-
initialOperation || null,
87-
);
90+
const [executingOperation, setExecutingOperation] = React.useState<
91+
string | null
92+
>(initialOperation || null);
8893
const [operationInput, setOperationInput] = React.useState("");
8994
const [operationResult, setOperationResult] = React.useState<string | null>(
9095
null,
@@ -197,7 +202,9 @@ export const ResourceActionsMenu: React.FC<ResourceActionsMenuProps> = (props) =
197202
<>
198203
<Breadcrumb items={breadcrumbItems} />
199204
<Box marginTop={1} flexDirection="column">
200-
<Text color={colors.textDim}>{selectedOp.inputPrompt || "Input:"} </Text>
205+
<Text color={colors.textDim}>
206+
{selectedOp.inputPrompt || "Input:"}{" "}
207+
</Text>
201208
<Text> {operationInput}</Text>
202209
<Text color={colors.textDim} dimColor>
203210
Press [Enter] to execute • [q or esc] Cancel
@@ -228,5 +235,3 @@ export const ResourceActionsMenu: React.FC<ResourceActionsMenuProps> = (props) =
228235
</>
229236
);
230237
};
231-
232-

0 commit comments

Comments
 (0)