Skip to content

[dashboard] give start workspace button focus #16826

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
Mar 13, 2023
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion components/dashboard/src/components/RepositoryFinder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ interface RepositoryFinderProps {
}

function stripOffProtocol(url: string): string {
if (!url.startsWith("http")) {
return url;
}
return url.substring(url.indexOf("//") + 2);
}

Expand Down Expand Up @@ -105,7 +108,7 @@ function displayContextUrl(contextUrl?: string) {
if (!contextUrl) {
return undefined;
}
return contextUrl.substring(contextUrl.indexOf("//") + 2);
return stripOffProtocol(contextUrl);
}

function loadSearchData(): string[] {
Expand Down
5 changes: 5 additions & 0 deletions components/dashboard/src/start/start-workspace-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,9 @@ export namespace StartWorkspaceOptions {
}
return params.toString();
}

export function parseContextUrl(locationHash: string): string {
let result = locationHash.replace(/^[#/]+/, "").trim();
return result;
}
}
30 changes: 22 additions & 8 deletions components/dashboard/src/workspaces/CreateWorkspacePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ export function CreateWorkspacePage() {
);
const [selectedWsClass, setSelectedWsClass] = useState<string | undefined>(props.workspaceClass);
const [errorWsClass, setErrorWsClass] = useState<string | undefined>(undefined);
const [repo, setRepo] = useState<string | undefined>(location.hash.substring(1));
const workspaceContext = useWorkspaceContext(repo);
const [contextURL, setContextURL] = useState<string | undefined>(
StartWorkspaceOptions.parseContextUrl(location.hash),
);
const workspaceContext = useWorkspaceContext(contextURL);
const isLoading = workspaceContext.isLoading || projects.isLoading;
const project = useMemo(() => {
if (!workspaceContext.data || !projects.data) {
Expand Down Expand Up @@ -108,28 +110,28 @@ export function CreateWorkspacePage() {
useLatestVersion: useLatestIde,
};
}
if (!repo) {
if (!contextURL) {
return;
}

try {
const result = await createWorkspaceMutation.mutateAsync({
contextUrl: repo,
contextUrl: contextURL,
organizationId: currentOrg?.id,
...opts,
});
if (result.workspaceURL) {
window.location.href = result.workspaceURL;
} else if (result.createdWorkspaceId) {
history.push(`/start/${result.createdWorkspaceId}`);
history.push(`/start/#${result.createdWorkspaceId}`);
} else if (result.existingWorkspaces && result.existingWorkspaces.length > 0) {
setExistingWorkspaces(result.existingWorkspaces);
}
} catch (error) {
console.log(error);
}
},
[createWorkspaceMutation, history, repo, selectedIde, selectedWsClass, currentOrg?.id, useLatestIde],
[createWorkspaceMutation, history, contextURL, selectedIde, selectedWsClass, currentOrg?.id, useLatestIde],
);

// Need a wrapper here so we call createWorkspace w/o any arguments
Expand All @@ -155,7 +157,12 @@ export function CreateWorkspacePage() {
</div>
<div className="-mx-6 px-6 mt-6 w-full">
<div className="pt-3">
<RepositoryFinder setSelection={setRepo} initialValue={repo} />
{workspaceContext.error && (
<div className="text-red-500 text-sm">
{workspaceContext.error.message} URL was: {contextURL}
</div>
)}
<RepositoryFinder setSelection={setContextURL} initialValue={contextURL} />
</div>
<div className="pt-3">
{errorIde && <div className="text-red-500 text-sm">{errorIde}</div>}
Expand All @@ -178,8 +185,15 @@ export function CreateWorkspacePage() {
<div className="w-full flex justify-end mt-6 space-x-2 px-6">
<Button
onClick={onClickCreate}
autoFocus={true}
loading={isStarting || isLoading}
disabled={!repo || repo.length === 0 || !!errorIde || !!errorWsClass}
disabled={
!contextURL ||
contextURL.length === 0 ||
!!errorIde ||
!!errorWsClass ||
!!workspaceContext.error
}
>
{isLoading ? "Loading ..." : isStarting ? "Creating Workspace ..." : "New Workspace"}
</Button>
Expand Down