@@ -20,28 +20,7 @@ import { i18n, Tab } from "@kui-shell/core"
2020import { Card , CardResponse , Icons , Loading , Markdown } from "@kui-shell/plugin-client-common"
2121import { ButtonProps , Chip , ChipGroup , Grid , GridItem , Progress , Tile , WizardStep } from "@patternfly/react-core"
2222
23- import {
24- Choice ,
25- Choices ,
26- CodeBlockProps ,
27- Status ,
28- Title ,
29- Description ,
30- OrderedGraph ,
31- extractTitle ,
32- extractDescription ,
33- sameGraph ,
34- order ,
35- compile ,
36- validate ,
37- findChoiceFrontier ,
38- wizardify ,
39- Wizard as WizardModel ,
40- ChoiceStep ,
41- isChoiceStep ,
42- TaskStep ,
43- isTaskStep ,
44- } from "madwizard"
23+ import { Graph , CodeBlock , Choices , Wizard as Wiz } from "madwizard"
4524
4625import read from "../read"
4726import Wizard from "./Wizard/KWizard"
@@ -51,37 +30,37 @@ import "@kui-shell/plugin-client-common/web/scss/components/Wizard/Guide.scss"
5130
5231const strings = i18n ( "plugin-client-common" , "code" )
5332
54- export type Props = Choices &
55- Partial < Title > &
56- Partial < Description > & {
33+ export type Props = Choices . Choices &
34+ Partial < CodeBlock . Title > &
35+ Partial < CodeBlock . Description > & {
5736 /** Enclosing Kui Tab */
5837 tab : Tab
5938
6039 /** markdown document id */
6140 uuid : string
6241
6342 /** Raw list of code blocks */
64- blocks : CodeBlockProps [ ]
43+ blocks : CodeBlock . CodeBlockProps [ ]
6544
6645 /** Status of code blocks */
6746 // codeBlockResponses: CodeBlockResponseFn
6847 }
6948
70- type State = Choices & {
49+ type State = Choices . Choices & {
7150 /** Internal error in rendering? */
7251 error ?: unknown
7352
7453 /** Graph of code blocks to be executed */
75- graph : OrderedGraph
54+ graph : Graph . OrderedGraph
7655
7756 /** Choice Frontier */
78- frontier : ReturnType < typeof findChoiceFrontier >
57+ frontier : ReturnType < typeof Graph . findChoiceFrontier >
7958
8059 /** Instance of Wizard model */
81- wizard : WizardModel
60+ wizard : Wiz . Wizard
8261
8362 /** validation status of each wizard step */
84- wizardStepStatus : Status [ ]
63+ wizardStepStatus : Graph . Status [ ]
8564
8665 /** Which of `wizardStepStatus` to display (indexed from 1) */
8766 startAtStep : number
@@ -102,23 +81,23 @@ export default class Guide extends React.PureComponent<Props, State> {
10281 /**
10382 * TODO move to a more common location?
10483 */
105- private static isValidFrontier ( frontier : ReturnType < typeof findChoiceFrontier > ) : boolean {
84+ private static isValidFrontier ( frontier : ReturnType < typeof Graph . findChoiceFrontier > ) : boolean {
10685 return frontier . length > 0 && frontier . every ( ( _ ) => ( _ . prereqs && _ . prereqs . length > 0 ) || ! ! _ . choice )
10786 }
10887
10988 private async init ( props : Props , useTheseChoices ?: State [ "choices" ] ) {
11089 const choices = useTheseChoices || props . choices
111- const newGraph = await compile ( props . blocks , choices , undefined , "sequence" , props . title , props . description )
90+ const newGraph = await Graph . compile ( props . blocks , choices , undefined , "sequence" , props . title , props . description )
11291 choices . onChoice ( this . onChoiceFromAbove )
11392
11493 this . setState ( ( state ) => {
115- const noChangeToGraph = state && sameGraph ( state . graph , newGraph )
94+ const noChangeToGraph = state && Graph . sameGraph ( state . graph , newGraph )
11695
117- const graph = noChangeToGraph ? state . graph : order ( newGraph )
118- const frontier = noChangeToGraph && state && state . frontier ? state . frontier : findChoiceFrontier ( graph )
96+ const graph = noChangeToGraph ? state . graph : Graph . order ( newGraph )
97+ const frontier = noChangeToGraph && state && state . frontier ? state . frontier : Graph . findChoiceFrontier ( graph )
11998
12099 const startAtStep = state ? state . startAtStep : 1
121- const wizard = wizardify ( graph , { previous : state ? state . wizard : undefined } )
100+ const wizard = Wiz . wizardify ( graph , { previous : state ? state . wizard : undefined } )
122101 const wizardStepStatus = noChangeToGraph && state ? state . wizardStepStatus : [ ]
123102
124103 const isRunning = state ? state . isRunning : false
@@ -144,7 +123,7 @@ export default class Guide extends React.PureComponent<Props, State> {
144123 }
145124
146125 /** @return a UI component to visualize the given markdown source */
147- private renderContent ( source : TaskStep [ "step" ] [ "content" ] ) {
126+ private renderContent ( source : Wiz . TaskStep [ "step" ] [ "content" ] ) {
148127 return (
149128 source &&
150129 this . stepContent (
@@ -165,7 +144,7 @@ export default class Guide extends React.PureComponent<Props, State> {
165144 }
166145
167146 /** A choice was made somewhere in the UI */
168- private readonly onChoiceFromAbove = ( { choices } : Choices ) => this . init ( this . props , choices . clone ( ) )
147+ private readonly onChoiceFromAbove = ( { choices } : Choices . Choices ) => this . init ( this . props , choices . clone ( ) )
169148
170149 /**
171150 * A choice was made in *this* UI. The `this.props.choices.set()`
@@ -181,7 +160,7 @@ export default class Guide extends React.PureComponent<Props, State> {
181160 }
182161
183162 /** @return UI that offers the user a choice */
184- private tilesForChoice ( choice : Choice ) {
163+ private tilesForChoice ( choice : Graph . Choice ) {
185164 return this . stepContent (
186165 < Grid hasGutter span = { 4 } >
187166 { choice . choices . map ( ( _ ) => {
@@ -206,7 +185,7 @@ export default class Guide extends React.PureComponent<Props, State> {
206185 )
207186 }
208187
209- private withStatus ( name : WizardStep [ "name" ] , status : Status ) {
188+ private withStatus ( name : WizardStep [ "name" ] , status : Graph . Status ) {
210189 const icon = status && statusToIcon ( status )
211190 if ( icon ) {
212191 return (
@@ -231,7 +210,7 @@ export default class Guide extends React.PureComponent<Props, State> {
231210 }
232211
233212 /** Add React `component` to the given choice step */
234- private choiceUI ( { status, step, graph } : ChoiceStep , isFirstChoice : boolean ) {
213+ private choiceUI ( { status, step, graph } : Wiz . ChoiceStep , isFirstChoice : boolean ) {
235214 return {
236215 status,
237216 graph,
@@ -250,15 +229,15 @@ export default class Guide extends React.PureComponent<Props, State> {
250229 }
251230
252231 /** Add React `component` to the given task execution step */
253- private taskUI ( { status, step, graph } : TaskStep ) {
232+ private taskUI ( { status, step, graph } : Wiz . TaskStep ) {
254233 return {
255234 status,
256235 graph,
257236 step : {
258237 name : step . name === "Missing title" ? < span className = "red-text" > { step . name } </ span > : step . name ,
259238 component : this . renderContent ( step . content ) ,
260239 stepNavItemProps : {
261- children : this . wizardStepDescription ( extractDescription ( graph ) ) ,
240+ children : this . wizardStepDescription ( Graph . extractDescription ( graph ) ) ,
262241 } ,
263242 } ,
264243 }
@@ -268,13 +247,13 @@ export default class Guide extends React.PureComponent<Props, State> {
268247 private wizardSteps ( ) {
269248 let isFirstChoice = true
270249 return this . state . wizard . reduce ( ( uiSteps , _ , idx , A ) => {
271- if ( isChoiceStep ( _ ) ) {
250+ if ( Wiz . isChoiceStep ( _ ) ) {
272251 const ui = this . choiceUI ( _ , isFirstChoice )
273252 isFirstChoice = false
274253 uiSteps . push ( ui )
275- } else if ( isTaskStep ( _ ) ) {
254+ } else if ( Wiz . isTaskStep ( _ ) ) {
276255 const previous = A [ idx - 1 ]
277- if ( ! previous || ! isTaskStep ( previous ) || previous . step . name !== _ . step . name ) {
256+ if ( ! previous || ! Wiz . isTaskStep ( previous ) || previous . step . name !== _ . step . name ) {
278257 // task steps with multiple code blocks... combine them into one ui step
279258 uiSteps . push ( this . taskUI ( _ ) )
280259 }
@@ -287,7 +266,9 @@ export default class Guide extends React.PureComponent<Props, State> {
287266 Promise . all (
288267 steps . map ( async ( _ , idx ) => {
289268 if ( ! this . state . wizardStepStatus [ idx ] || this . state . wizardStepStatus [ idx ] === "blank" ) {
290- const status = await validate ( _ . graph , { validator : ( cmdline : string ) => this . props . tab . REPL . qexec ( cmdline ) } )
269+ const status = await Graph . validate ( _ . graph , {
270+ validator : ( cmdline : string ) => this . props . tab . REPL . qexec ( cmdline ) ,
271+ } )
291272 if ( status !== this . state . wizardStepStatus [ idx ] ) {
292273 this . setState ( ( curState ) => ( {
293274 wizardStepStatus : [
@@ -368,7 +349,7 @@ export default class Guide extends React.PureComponent<Props, State> {
368349 }
369350
370351 private wizardDescription ( ) {
371- const descriptionContent = extractDescription ( this . state . graph )
352+ const descriptionContent = Graph . extractDescription ( this . state . graph )
372353 return descriptionContent && < Markdown nested source = { descriptionContent } />
373354 }
374355
@@ -377,7 +358,7 @@ export default class Guide extends React.PureComponent<Props, State> {
377358 }
378359
379360 private wizardTitle ( ) {
380- return extractTitle ( this . state . graph )
361+ return Graph . extractTitle ( this . state . graph )
381362 // {this.state.isRunning && <span className="small-left-pad">{statusToIcon('in-progress')}</span> }
382363 }
383364
0 commit comments