@@ -29,7 +29,6 @@ import { checkAuthorization } from "api/queries/authCheck";
29
29
import { CreateWSPermissions , createWorkspaceChecks } from "./permissions" ;
30
30
import { paramsUsedToCreateWorkspace } from "utils/workspace" ;
31
31
import { useEffectEvent } from "hooks/hookPolyfills" ;
32
- import { workspaceBuildParameters } from "api/queries/workspaceBuilds" ;
33
32
34
33
export const createWorkspaceModes = [ "form" , "auto" , "duplicate" ] as const ;
35
34
export type CreateWorkspaceMode = ( typeof createWorkspaceModes ) [ number ] ;
@@ -264,64 +263,3 @@ function getDefaultName(mode: CreateWorkspaceMode, params: URLSearchParams) {
264
263
265
264
return paramsName ?? "" ;
266
265
}
267
-
268
- function getDuplicationUrlParams (
269
- workspaceParams : readonly WorkspaceBuildParameter [ ] ,
270
- workspace : Workspace ,
271
- ) : URLSearchParams {
272
- // Record type makes sure that every property key added starts with "param.";
273
- // page is also set up to parse params with this prefix for auto mode
274
- const consolidatedParams : Record < `param.${string } `, string > = { } ;
275
-
276
- for ( const p of workspaceParams ) {
277
- consolidatedParams [ `param.${ p . name } ` ] = p . value ;
278
- }
279
-
280
- return new URLSearchParams ( {
281
- ...consolidatedParams ,
282
- mode : "duplicate" satisfies CreateWorkspaceMode ,
283
- name : workspace . name ,
284
- version : workspace . template_active_version_id ,
285
- } ) ;
286
- }
287
-
288
- /**
289
- * Takes a workspace, and returns out a function that will navigate the user to
290
- * the 'Create Workspace' page, pre-filling the form with as much information
291
- * about the workspace as possible.
292
- */
293
- // Meant to be consumed by components outside of this file
294
- export function useWorkspaceDuplication ( workspace : Workspace ) {
295
- const navigate = useNavigate ( ) ;
296
- const buildParametersQuery = useQuery (
297
- workspaceBuildParameters ( workspace . latest_build . id ) ,
298
- ) ;
299
-
300
- // Not using useEffectEvent for this, because useEffect isn't really an
301
- // intended use case for this custom hook
302
- const duplicateWorkspace = useCallback ( ( ) => {
303
- const buildParams = buildParametersQuery . data ;
304
- if ( buildParams === undefined ) {
305
- return ;
306
- }
307
-
308
- const newUrlParams = getDuplicationUrlParams ( buildParams , workspace ) ;
309
-
310
- // Necessary for giving modals/popups time to flush their state changes and
311
- // close the popup before actually navigating. MUI does provide the
312
- // disablePortal prop, which also side-steps this issue, but you have to
313
- // remember to put it on any component that calls this function. Better to
314
- // code defensively and have some redundancy in case someone forgets
315
- void Promise . resolve ( ) . then ( ( ) => {
316
- navigate ( {
317
- pathname : `/templates/${ workspace . template_name } /workspace` ,
318
- search : newUrlParams . toString ( ) ,
319
- } ) ;
320
- } ) ;
321
- } , [ navigate , workspace , buildParametersQuery . data ] ) ;
322
-
323
- return {
324
- duplicateWorkspace,
325
- duplicationReady : buildParametersQuery . isSuccess ,
326
- } as const ;
327
- }
0 commit comments