|
| 1 | +/** |
| 2 | + * DetailedInfoView - Full-screen scrollable detail view for resources. |
| 3 | + * |
| 4 | + * Extracted from ResourceDetailPage to reduce component size. |
| 5 | + * Displays all resource information in a scrollable, bordered container. |
| 6 | + */ |
| 7 | +import React from "react"; |
| 8 | +import { Box, Text } from "ink"; |
| 9 | +import figures from "figures"; |
| 10 | +import { Header } from "./Header.js"; |
| 11 | +import { StatusBadge } from "./StatusBadge.js"; |
| 12 | +import { Breadcrumb } from "./Breadcrumb.js"; |
| 13 | +import { colors } from "../utils/theme.js"; |
| 14 | + |
| 15 | +interface DetailedInfoViewProps { |
| 16 | + /** Lines of React elements to display */ |
| 17 | + detailLines: React.ReactElement[]; |
| 18 | + /** Current scroll offset */ |
| 19 | + scrollOffset: number; |
| 20 | + /** Maximum visible lines */ |
| 21 | + viewportHeight: number; |
| 22 | + /** Display name of the resource */ |
| 23 | + displayName: string; |
| 24 | + /** Resource ID */ |
| 25 | + resourceId: string; |
| 26 | + /** Resource status string */ |
| 27 | + status: string; |
| 28 | + /** Resource type for breadcrumbs (e.g. "Devboxes") */ |
| 29 | + resourceType: string; |
| 30 | + /** Optional breadcrumb prefix items */ |
| 31 | + breadcrumbPrefix?: Array<{ label: string; active?: boolean }>; |
| 32 | +} |
| 33 | + |
| 34 | +export function DetailedInfoView({ |
| 35 | + detailLines, |
| 36 | + scrollOffset, |
| 37 | + viewportHeight, |
| 38 | + displayName, |
| 39 | + resourceId, |
| 40 | + status, |
| 41 | + resourceType, |
| 42 | + breadcrumbPrefix = [], |
| 43 | +}: DetailedInfoViewProps) { |
| 44 | + const maxScroll = Math.max(0, detailLines.length - viewportHeight); |
| 45 | + const actualScroll = Math.min(scrollOffset, maxScroll); |
| 46 | + const visibleLines = detailLines.slice( |
| 47 | + actualScroll, |
| 48 | + actualScroll + viewportHeight, |
| 49 | + ); |
| 50 | + const hasMore = actualScroll + viewportHeight < detailLines.length; |
| 51 | + const hasLess = actualScroll > 0; |
| 52 | + |
| 53 | + return ( |
| 54 | + <> |
| 55 | + <Breadcrumb |
| 56 | + items={[ |
| 57 | + ...breadcrumbPrefix, |
| 58 | + { label: resourceType }, |
| 59 | + { label: displayName }, |
| 60 | + { label: "Full Details", active: true }, |
| 61 | + ]} |
| 62 | + /> |
| 63 | + <Header title={`${displayName} - Complete Information`} /> |
| 64 | + <Box flexDirection="column" marginBottom={1}> |
| 65 | + <Box marginBottom={1}> |
| 66 | + <StatusBadge status={status} /> |
| 67 | + <Text> </Text> |
| 68 | + <Text color={colors.idColor}>{resourceId}</Text> |
| 69 | + </Box> |
| 70 | + </Box> |
| 71 | + |
| 72 | + <Box |
| 73 | + flexDirection="column" |
| 74 | + marginTop={1} |
| 75 | + marginBottom={1} |
| 76 | + borderStyle="round" |
| 77 | + borderColor={colors.border} |
| 78 | + paddingX={2} |
| 79 | + paddingY={1} |
| 80 | + > |
| 81 | + <Box flexDirection="column">{visibleLines}</Box> |
| 82 | + </Box> |
| 83 | + |
| 84 | + <Box marginTop={1}> |
| 85 | + <Text color={colors.textDim} dimColor> |
| 86 | + {figures.arrowUp} |
| 87 | + {figures.arrowDown} Scroll • Line {actualScroll + 1}- |
| 88 | + {Math.min(actualScroll + viewportHeight, detailLines.length)} of{" "} |
| 89 | + {detailLines.length} |
| 90 | + </Text> |
| 91 | + {hasLess && <Text color={colors.primary}> {figures.arrowUp}</Text>} |
| 92 | + {hasMore && <Text color={colors.primary}> {figures.arrowDown}</Text>} |
| 93 | + <Text color={colors.textDim} dimColor> |
| 94 | + {" "} |
| 95 | + • [q or esc] Back to Details |
| 96 | + </Text> |
| 97 | + </Box> |
| 98 | + </> |
| 99 | + ); |
| 100 | +} |
0 commit comments