Skip to content

Commit 1ad6654

Browse files
authored
[dashboard] set project wsClass (#18837)
1 parent a5afbd2 commit 1ad6654

File tree

1 file changed

+6
-25
lines changed

1 file changed

+6
-25
lines changed

components/dashboard/src/workspaces/CreateWorkspacePage.tsx

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -128,29 +128,6 @@ export function CreateWorkspacePage() {
128128
}
129129
}, [project, selectedProjectID]);
130130

131-
// Apply project ws class settings
132-
useEffect(() => {
133-
// If URL has a ws class set, we don't override it w/ project settings
134-
if (props.workspaceClass) {
135-
return;
136-
}
137-
138-
if (!project) {
139-
// If no project and user hasn't changed ws class, reset it to default value
140-
// Empty value causes SelectWorkspaceClassComponent to use the default ws class
141-
if (!selectedWsClassIsDirty) {
142-
setSelectedWsClass(defaultWorkspaceClass, false);
143-
}
144-
return;
145-
}
146-
const wsClass = project.settings?.workspaceClasses;
147-
148-
// only set if user hasn't changed the value themselves, and project has a vaue
149-
if (wsClass?.regular && !selectedWsClassIsDirty) {
150-
setSelectedWsClass(wsClass?.regular, false);
151-
}
152-
}, [defaultWorkspaceClass, project, props.workspaceClass, selectedWsClassIsDirty, setSelectedWsClass]);
153-
154131
// In addition to updating state, we want to update the url hash as well
155132
// This allows the contextURL to persist if user changes orgs, or copies/shares url
156133
const handleContextURLChange = useCallback(
@@ -276,6 +253,9 @@ export function CreateWorkspacePage() {
276253

277254
// when workspaceContext is available, we look up if options are remembered
278255
useEffect(() => {
256+
if (!workspaceContext.data || !user || !currentOrg) {
257+
return;
258+
}
279259
const cloneURL = CommitContext.is(workspaceContext.data) && workspaceContext.data.repository.cloneUrl;
280260
if (!cloneURL) {
281261
return undefined;
@@ -299,13 +279,14 @@ export function CreateWorkspacePage() {
299279
setUseLatestIde(defaultLatestIde);
300280
}
301281
if (!selectedWsClassIsDirty) {
302-
setSelectedWsClass(defaultWorkspaceClass, false);
282+
const projectWsClass = project?.settings?.workspaceClasses?.regular;
283+
setSelectedWsClass(projectWsClass || defaultWorkspaceClass, false);
303284
}
304285
}
305286
setOptionsLoaded(true);
306287
// we only update the remembered options when the workspaceContext changes
307288
// eslint-disable-next-line react-hooks/exhaustive-deps
308-
}, [workspaceContext.data, setOptionsLoaded]);
289+
}, [workspaceContext.data, setOptionsLoaded, project]);
309290

310291
// Need a wrapper here so we call createWorkspace w/o any arguments
311292
const onClickCreate = useCallback(() => createWorkspace(), [createWorkspace]);

0 commit comments

Comments
 (0)