Skip to content

[dashboard] set project wsClass #18837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 6 additions & 25 deletions components/dashboard/src/workspaces/CreateWorkspacePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,29 +128,6 @@ export function CreateWorkspacePage() {
}
}, [project, selectedProjectID]);

// Apply project ws class settings
useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice that we're able to remove this useEffect πŸ˜„

// If URL has a ws class set, we don't override it w/ project settings
if (props.workspaceClass) {
return;
}

if (!project) {
// If no project and user hasn't changed ws class, reset it to default value
// Empty value causes SelectWorkspaceClassComponent to use the default ws class
if (!selectedWsClassIsDirty) {
setSelectedWsClass(defaultWorkspaceClass, false);
}
return;
}
const wsClass = project.settings?.workspaceClasses;

// only set if user hasn't changed the value themselves, and project has a vaue
if (wsClass?.regular && !selectedWsClassIsDirty) {
setSelectedWsClass(wsClass?.regular, false);
}
}, [defaultWorkspaceClass, project, props.workspaceClass, selectedWsClassIsDirty, setSelectedWsClass]);

// In addition to updating state, we want to update the url hash as well
// This allows the contextURL to persist if user changes orgs, or copies/shares url
const handleContextURLChange = useCallback(
Expand Down Expand Up @@ -276,6 +253,9 @@ export function CreateWorkspacePage() {

// when workspaceContext is available, we look up if options are remembered
useEffect(() => {
if (!workspaceContext.data || !user || !currentOrg) {
return;
}
const cloneURL = CommitContext.is(workspaceContext.data) && workspaceContext.data.repository.cloneUrl;
if (!cloneURL) {
return undefined;
Expand All @@ -299,13 +279,14 @@ export function CreateWorkspacePage() {
setUseLatestIde(defaultLatestIde);
}
if (!selectedWsClassIsDirty) {
setSelectedWsClass(defaultWorkspaceClass, false);
const projectWsClass = project?.settings?.workspaceClasses?.regular;
setSelectedWsClass(projectWsClass || defaultWorkspaceClass, false);
}
}
setOptionsLoaded(true);
// we only update the remembered options when the workspaceContext changes
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [workspaceContext.data, setOptionsLoaded]);
}, [workspaceContext.data, setOptionsLoaded, project]);

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