11import { Box , Text , useApp , useInput } from "ink"
22import { useState } from "react"
3-
4- type ExpertChoice = {
5- name : string
6- description ?: string
7- }
3+ import { WizardExpertSelector } from "../../src/components/index.js"
4+ import type { ExpertChoice } from "../../src/types/index.js"
85
96type VersionInfo = {
107 key : string
118 version : string
129 tags : string [ ]
1310 status : "available" | "deprecated" | "disabled"
1411}
15-
1612type WizardStep =
1713 | { type : "selectExpert" }
1814 | { type : "loadingVersions" ; expertName : string }
1915 | { type : "selectVersion" ; expertName : string ; versions : VersionInfo [ ] }
2016 | { type : "selectStatus" ; expertKey : string ; currentStatus : string }
2117 | { type : "confirm" ; expertKey : string ; status : string ; currentStatus : string }
2218 | { type : "error" ; message : string }
23-
2419type StatusWizardResult = {
2520 expertKey : string
2621 status : "available" | "deprecated" | "disabled"
2722}
28-
2923type StatusAppProps = {
3024 experts : ExpertChoice [ ]
3125 onFetchVersions : ( expertName : string ) => Promise < VersionInfo [ ] >
3226 onComplete : ( result : StatusWizardResult ) => void
3327 onCancel : ( ) => void
3428}
35-
3629function getAvailableStatusTransitions ( currentStatus : string ) : string [ ] {
3730 switch ( currentStatus ) {
3831 case "available" :
@@ -46,50 +39,6 @@ function getAvailableStatusTransitions(currentStatus: string): string[] {
4639 }
4740}
4841
49- function ExpertSelector ( {
50- experts,
51- onSelect,
52- } : {
53- experts : ExpertChoice [ ]
54- onSelect : ( name : string ) => void
55- } ) {
56- const { exit } = useApp ( )
57- const [ selectedIndex , setSelectedIndex ] = useState ( 0 )
58- useInput ( ( input , key ) => {
59- if ( key . upArrow ) {
60- setSelectedIndex ( ( prev ) => ( prev > 0 ? prev - 1 : experts . length - 1 ) )
61- } else if ( key . downArrow ) {
62- setSelectedIndex ( ( prev ) => ( prev < experts . length - 1 ? prev + 1 : 0 ) )
63- } else if ( key . return ) {
64- const expert = experts [ selectedIndex ]
65- if ( expert ) {
66- onSelect ( expert . name )
67- }
68- } else if ( input === "q" || key . escape ) {
69- exit ( )
70- }
71- } )
72- return (
73- < Box flexDirection = "column" >
74- < Text bold > Select an Expert to change status:</ Text >
75- < Box flexDirection = "column" marginTop = { 1 } >
76- { experts . map ( ( expert , index ) => (
77- < Box key = { expert . name } >
78- < Text color = { index === selectedIndex ? "cyan" : undefined } >
79- { index === selectedIndex ? "❯ " : " " }
80- { expert . name }
81- { expert . description && < Text dimColor > - { expert . description } </ Text > }
82- </ Text >
83- </ Box >
84- ) ) }
85- </ Box >
86- < Box marginTop = { 1 } >
87- < Text dimColor > ↑↓ navigate · enter select · q quit</ Text >
88- </ Box >
89- </ Box >
90- )
91- }
92-
9342function VersionSelector ( {
9443 expertName,
9544 versions,
@@ -368,7 +317,13 @@ export function StatusApp({ experts, onFetchVersions, onComplete, onCancel }: St
368317 }
369318 switch ( step . type ) {
370319 case "selectExpert" :
371- return < ExpertSelector experts = { experts } onSelect = { handleExpertSelect } />
320+ return (
321+ < WizardExpertSelector
322+ title = "Select an Expert to change status:"
323+ experts = { experts }
324+ onSelect = { handleExpertSelect }
325+ />
326+ )
372327 case "loadingVersions" :
373328 return (
374329 < Box >
@@ -417,4 +372,4 @@ export function StatusApp({ experts, onFetchVersions, onComplete, onCancel }: St
417372 }
418373}
419374
420- export type { ExpertChoice , VersionInfo , StatusWizardResult }
375+ export type { VersionInfo , StatusWizardResult }
0 commit comments