@@ -2,6 +2,7 @@ import "./stages.scss";
22
33import { useCallback , useState } from "react" ;
44import {
5+ ReactZoomPanPinchContextState ,
56 TransformComponent ,
67 TransformWrapper ,
78 useControls ,
@@ -14,6 +15,8 @@ import { PipelineGraph } from "../../../../pipeline-graph-view/pipeline-graph/ma
1415import { StageInfo } from "../../../../pipeline-graph-view/pipeline-graph/main/PipelineGraphModel.tsx" ;
1516import { StageViewPosition } from "../providers/user-preference-provider.tsx" ;
1617
18+ const MAX_SCALE = 3 ;
19+
1720export default function Stages ( {
1821 stages,
1922 selectedStage,
@@ -31,18 +34,18 @@ export default function Stages({
3134 [ onStageSelect ] ,
3235 ) ;
3336
37+ const [ initialScale , setInitialScale ] = useState ( 1 ) ;
38+ const [ minScale , setMinScale ] = useState ( 0.75 ) ;
39+
3440 return (
3541 < div
3642 className = { classNames ( "pgv-stages-graph" , {
3743 "pgv-stages-graph--left" : stageViewPosition === StageViewPosition . LEFT ,
3844 "pgv-stages-graph--dialog" : isExpanded ,
45+ "pvg-stages-graph--spacing-top" : onRunPage ,
46+ "pvg-stages-graph--spacing-right" : ! onRunPage && ! isExpanded ,
3947 } ) }
4048 >
41- { ! onRunPage && (
42- < div className = { "pgv-stages-graph__controls pgv-stages-graph__heading" } >
43- Graph
44- </ div >
45- ) }
4649 { onRunPage && (
4750 < a
4851 className = { "pgv-stages-graph__controls pgv-stages-graph__heading" }
@@ -99,16 +102,19 @@ export default function Stages({
99102 </ Tooltip >
100103 </ div >
101104 < TransformWrapper
102- minScale = { 0.75 }
103- maxScale = { 3 }
105+ initialScale = { initialScale }
106+ minScale = { minScale }
107+ maxScale = { MAX_SCALE }
104108 wheel = { { activationKeys : isExpanded ? [ ] : [ "Control" ] } }
105109 >
106- < ZoomControls />
110+ < ZoomControls initialScale = { initialScale } minScale = { minScale } />
107111
108112 < TransformComponent wrapperStyle = { { width : "100%" , height : "100%" } } >
109113 < PipelineGraph
110114 stages = { stages }
111115 selectedStage = { selectedStage }
116+ setInitialScale = { setInitialScale }
117+ setMinScale = { setMinScale }
112118 { ...( onStageSelect && { onStageSelect : handleStageSelect } ) }
113119 />
114120 </ TransformComponent >
@@ -125,33 +131,27 @@ interface StagesProps {
125131 onRunPage ?: boolean ;
126132}
127133
128- function ZoomControls ( ) {
129- const { zoomIn, zoomOut, resetTransform } = useControls ( ) ;
130- const [ buttonState , setButtonState ] = useState ( {
131- zoomIn : false ,
132- zoomOut : false ,
133- reset : true ,
134- } ) ;
135-
136- useTransformEffect ( ( { state, instance } ) => {
137- const cantZoomIn = state . scale >= instance . props . maxScale ! ;
138- const cantZoomOut = state . scale <= instance . props . minScale ! ;
139- const cantReset = state . scale === 1 ;
134+ interface ZoomControlsProps {
135+ initialScale : number ;
136+ minScale : number ;
137+ }
140138
141- setButtonState ( {
142- zoomIn : cantZoomIn ,
143- zoomOut : cantZoomOut ,
144- reset : cantReset ,
145- } ) ;
146- } ) ;
139+ function ZoomControls ( { initialScale, minScale } : ZoomControlsProps ) {
140+ const { zoomIn, zoomOut, centerView } = useControls ( ) ;
141+ const [ scale , setScale ] = useState ( initialScale ) ;
142+ const handleTransformEffect = useCallback (
143+ ( ref : ReactZoomPanPinchContextState ) => setScale ( ref . state . scale ) ,
144+ [ ] ,
145+ ) ;
146+ useTransformEffect ( handleTransformEffect ) ;
147147
148148 return (
149149 < div className = "pgv-stages-graph__controls pgw-zoom-controls" >
150150 < Tooltip content = { "Zoom in" } >
151151 < button
152152 className = { "jenkins-button jenkins-button--tertiary" }
153153 onClick = { ( ) => zoomIn ( ) }
154- disabled = { buttonState . zoomIn }
154+ disabled = { scale >= MAX_SCALE }
155155 >
156156 < svg xmlns = "http://www.w3.org/2000/svg" viewBox = "0 0 512 512" >
157157 < path
@@ -169,7 +169,7 @@ function ZoomControls() {
169169 < button
170170 className = { "jenkins-button jenkins-button--tertiary" }
171171 onClick = { ( ) => zoomOut ( ) }
172- disabled = { buttonState . zoomOut }
172+ disabled = { scale <= minScale }
173173 >
174174 < svg xmlns = "http://www.w3.org/2000/svg" viewBox = "0 0 512 512" >
175175 < path
@@ -186,8 +186,8 @@ function ZoomControls() {
186186 < Tooltip content = { "Reset" } >
187187 < button
188188 className = { "jenkins-button jenkins-button--tertiary" }
189- onClick = { ( ) => resetTransform ( ) }
190- disabled = { buttonState . reset }
189+ onClick = { ( ) => centerView ( initialScale ) }
190+ disabled = { scale === initialScale }
191191 >
192192 < svg className = "ionicon" viewBox = "0 0 512 512" >
193193 < path
0 commit comments