@@ -73,11 +73,13 @@ export const CreateClone = observer((props: Props) => {
7373 }
7474 }
7575
76- const fetchBranchSnapshotsData = async ( branchName : string ) => {
77- const snapshotsRes =
78- ( await stores . main . getSnapshots ( props . instanceId , branchName ) ) ?? [ ]
76+ const fetchBranchSnapshotsData = async ( branchName : string , initialSnapshotId ?: string ) => {
77+ const snapshotsRes = ( await stores . main . getSnapshots ( props . instanceId , branchName ) ) ?? [ ]
7978 setSnapshots ( snapshotsRes )
80- formik . setFieldValue ( 'snapshotId' , snapshotsRes [ 0 ] ?. id )
79+
80+ const selectedSnapshot = snapshotsRes . find ( s => s . id === initialSnapshotId ) || snapshotsRes [ 0 ]
81+
82+ formik . setFieldValue ( 'snapshotId' , selectedSnapshot ?. id )
8183 }
8284
8385 const handleSelectBranch = async (
@@ -93,24 +95,30 @@ export const CreateClone = observer((props: Props) => {
9395
9496 const formik = useForm ( onSubmit )
9597
96- const fetchData = async ( ) => {
98+ const fetchData = async ( initialBranch ?: string , initialSnapshotId ?: string ) => {
9799 try {
98100 setIsLoadingSnapshots ( true )
99101 await stores . main . load ( props . instanceId )
100102
101103 const branches = ( await stores . main . getBranches ( props . instanceId ) ) ?? [ ]
102- const initiallySelectedBranch = branches [ 0 ] ?. name
104+
105+ let initiallySelectedBranch = branches [ 0 ] ?. name ;
106+
107+ if ( initialBranch && branches . find ( ( branch ) => branch . name === initialBranch ) ) {
108+ initiallySelectedBranch = initialBranch ;
109+ }
110+
103111 setBranchesList ( branches . map ( ( branch ) => branch . name ) )
104112 formik . setFieldValue ( 'branch' , initiallySelectedBranch )
105113
106114 if ( props . api . getSnapshots ) {
107- await fetchBranchSnapshotsData ( initiallySelectedBranch )
115+ await fetchBranchSnapshotsData ( initiallySelectedBranch , initialSnapshotId )
108116 } else {
109117 const allSnapshots = stores . main ?. snapshots ?. data ?? [ ]
110118 const sortedSnapshots = allSnapshots . slice ( ) . sort ( compareSnapshotsDesc )
111119 setSnapshots ( sortedSnapshots )
112- const [ firstSnapshot ] = allSnapshots ?? [ ]
113- formik . setFieldValue ( 'snapshotId' , firstSnapshot ?. id )
120+ let selectedSnapshot = allSnapshots . find ( s => s . id === initialSnapshotId ) || allSnapshots [ 0 ]
121+ formik . setFieldValue ( 'snapshotId' , selectedSnapshot ?. id )
114122 }
115123 } catch ( error ) {
116124 console . error ( 'Error fetching data:' , error )
@@ -121,8 +129,13 @@ export const CreateClone = observer((props: Props) => {
121129
122130 // Initial loading data.
123131 useEffect ( ( ) => {
124- fetchData ( )
125- } , [ ] )
132+ const queryString = history . location . search . split ( '?' ) [ 1 ]
133+ const params = new URLSearchParams ( queryString )
134+ const branchId = params . get ( 'branch_id' ) ?? undefined
135+ const snapshotId = params . get ( 'snapshot_id' ) ?? undefined
136+
137+ fetchData ( branchId , snapshotId )
138+ } , [ history . location . search , formik . initialValues ] )
126139
127140 // Redirect when clone is created and stable.
128141 useEffect ( ( ) => {
0 commit comments