@@ -40,6 +40,7 @@ import Scalar from '../../../Content/Scalar'
40
40
import { MutabilityContext , MutabilityState , MutabilityStateOffline } from '../../../Client/MutabilityContext'
41
41
42
42
import Tooltip from '../../../spi/Tooltip'
43
+ import { SupportedIcon } from '../../../spi/Icons'
43
44
import TwoFaceIcon from '../../../spi/Icons/TwoFaceIcon'
44
45
45
46
import { emitGetCodeBlockReadiness , onCodeBlockReadiness , offCodeBlockReadiness } from './CodeBlockEvents'
@@ -561,31 +562,70 @@ export default class CodeBlock<T1, T2, T3> extends StreamingConsumer<Props<T1, T
561
562
}
562
563
}
563
564
564
- type RunProps = Pick < Props , 'optional' > &
565
- Pick < State , 'execution' | 'ready' > & {
566
- onRun : ( ) => void | Promise < void >
565
+ abstract class ActionButton < Props > extends React . PureComponent < Props > {
566
+ protected abstract get icon ( ) : SupportedIcon
567
+ protected abstract get onClick ( ) : ( ) => void
568
+ protected abstract get tooltip ( ) : string
569
+ protected abstract get className ( ) : string
570
+
571
+ protected classNameOf ( cls : string ) {
572
+ return `kui--block-action ${ cls } `
567
573
}
568
574
569
- class Cleanup extends React . PureComponent < { onCleanup : ( ) => void } > {
570
575
public render ( ) {
571
576
return (
572
- < Tooltip content = "Clean up the effects of this code block" position = "bottom-end" >
573
- < TwoFaceIcon
574
- a = "Trash"
575
- b = "Checkmark"
576
- delay = { 4000 }
577
- onClick = { this . props . onCleanup }
578
- classNameB = "green-text"
579
- className = "kui--block-action kui--block-action-cleanup"
580
- />
577
+ < Tooltip content = { this . tooltip } position = "bottom-end" >
578
+ < div className = "flex-layout" >
579
+ < TwoFaceIcon
580
+ a = { this . icon }
581
+ b = "Checkmark"
582
+ delay = { 4000 }
583
+ onClick = { this . onClick }
584
+ classNameB = "green-text"
585
+ className = { this . className }
586
+ />
587
+ </ div >
581
588
</ Tooltip >
582
589
)
583
590
}
584
591
}
585
592
586
- class Run extends React . PureComponent < RunProps > {
587
- public render ( ) {
588
- const tooltip = strings (
593
+ /** The Code Block Trash button */
594
+ class Cleanup extends ActionButton < { onCleanup : ( ) => void } > {
595
+ private readonly _className = this . classNameOf ( 'kui--block-action-cleanup' )
596
+
597
+ protected get className ( ) {
598
+ return this . _className
599
+ }
600
+
601
+ protected get tooltip ( ) {
602
+ return 'Clean up the effects of this code block'
603
+ }
604
+
605
+ protected get icon ( ) : SupportedIcon {
606
+ return 'Trash'
607
+ }
608
+
609
+ protected get onClick ( ) {
610
+ return this . props . onCleanup
611
+ }
612
+ }
613
+
614
+ type RunProps = Pick < Props , 'optional' > &
615
+ Pick < State , 'execution' | 'ready' > & {
616
+ onRun : ( ) => void | Promise < void >
617
+ }
618
+
619
+ /** The Code Block Run button */
620
+ class Run extends ActionButton < RunProps > {
621
+ private readonly _className = this . classNameOf ( 'kui--block-action-run' )
622
+
623
+ protected get className ( ) {
624
+ return this . _className
625
+ }
626
+
627
+ protected get tooltip ( ) {
628
+ return strings (
589
629
! this . props . ready && this . props . execution !== 'done' && this . props . execution !== 'error'
590
630
? 'Execute with caution! The pre-requisites for this code block have not yet been satisfied.'
591
631
: this . props . execution === 'done'
@@ -594,17 +634,13 @@ class Run extends React.PureComponent<RunProps> {
594
634
? 'Execution of this command is optional'
595
635
: 'Execute this command'
596
636
)
597
- return (
598
- < Tooltip content = { tooltip } position = "bottom-end" >
599
- < TwoFaceIcon
600
- a = "Play"
601
- b = "Checkmark"
602
- delay = { 4000 }
603
- onClick = { this . props . onRun }
604
- classNameB = "green-text"
605
- className = "kui--block-action kui--block-action-run"
606
- />
607
- </ Tooltip >
608
- )
637
+ }
638
+
639
+ protected get icon ( ) : SupportedIcon {
640
+ return 'Play'
641
+ }
642
+
643
+ protected get onClick ( ) {
644
+ return this . props . onRun
609
645
}
610
646
}
0 commit comments