Skip to content

Commit 3d7a084

Browse files
authored
[dashboard] give start workspace button focus (#16826)
1 parent f4a06b8 commit 3d7a084

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

components/dashboard/src/components/RepositoryFinder.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ interface RepositoryFinderProps {
1919
}
2020

2121
function stripOffProtocol(url: string): string {
22+
if (!url.startsWith("http")) {
23+
return url;
24+
}
2225
return url.substring(url.indexOf("//") + 2);
2326
}
2427

@@ -105,7 +108,7 @@ function displayContextUrl(contextUrl?: string) {
105108
if (!contextUrl) {
106109
return undefined;
107110
}
108-
return contextUrl.substring(contextUrl.indexOf("//") + 2);
111+
return stripOffProtocol(contextUrl);
109112
}
110113

111114
function loadSearchData(): string[] {

components/dashboard/src/start/start-workspace-options.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,9 @@ export namespace StartWorkspaceOptions {
4949
}
5050
return params.toString();
5151
}
52+
53+
export function parseContextUrl(locationHash: string): string {
54+
let result = locationHash.replace(/^[#/]+/, "").trim();
55+
return result;
56+
}
5257
}

components/dashboard/src/workspaces/CreateWorkspacePage.tsx

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ export function CreateWorkspacePage() {
6161
);
6262
const [selectedWsClass, setSelectedWsClass] = useState<string | undefined>(props.workspaceClass);
6363
const [errorWsClass, setErrorWsClass] = useState<string | undefined>(undefined);
64-
const [repo, setRepo] = useState<string | undefined>(location.hash.substring(1));
65-
const workspaceContext = useWorkspaceContext(repo);
64+
const [contextURL, setContextURL] = useState<string | undefined>(
65+
StartWorkspaceOptions.parseContextUrl(location.hash),
66+
);
67+
const workspaceContext = useWorkspaceContext(contextURL);
6668
const isLoading = workspaceContext.isLoading || projects.isLoading;
6769
const project = useMemo(() => {
6870
if (!workspaceContext.data || !projects.data) {
@@ -108,28 +110,28 @@ export function CreateWorkspacePage() {
108110
useLatestVersion: useLatestIde,
109111
};
110112
}
111-
if (!repo) {
113+
if (!contextURL) {
112114
return;
113115
}
114116

115117
try {
116118
const result = await createWorkspaceMutation.mutateAsync({
117-
contextUrl: repo,
119+
contextUrl: contextURL,
118120
organizationId: currentOrg?.id,
119121
...opts,
120122
});
121123
if (result.workspaceURL) {
122124
window.location.href = result.workspaceURL;
123125
} else if (result.createdWorkspaceId) {
124-
history.push(`/start/${result.createdWorkspaceId}`);
126+
history.push(`/start/#${result.createdWorkspaceId}`);
125127
} else if (result.existingWorkspaces && result.existingWorkspaces.length > 0) {
126128
setExistingWorkspaces(result.existingWorkspaces);
127129
}
128130
} catch (error) {
129131
console.log(error);
130132
}
131133
},
132-
[createWorkspaceMutation, history, repo, selectedIde, selectedWsClass, currentOrg?.id, useLatestIde],
134+
[createWorkspaceMutation, history, contextURL, selectedIde, selectedWsClass, currentOrg?.id, useLatestIde],
133135
);
134136

135137
// Need a wrapper here so we call createWorkspace w/o any arguments
@@ -155,7 +157,12 @@ export function CreateWorkspacePage() {
155157
</div>
156158
<div className="-mx-6 px-6 mt-6 w-full">
157159
<div className="pt-3">
158-
<RepositoryFinder setSelection={setRepo} initialValue={repo} />
160+
{workspaceContext.error && (
161+
<div className="text-red-500 text-sm">
162+
{workspaceContext.error.message} URL was: {contextURL}
163+
</div>
164+
)}
165+
<RepositoryFinder setSelection={setContextURL} initialValue={contextURL} />
159166
</div>
160167
<div className="pt-3">
161168
{errorIde && <div className="text-red-500 text-sm">{errorIde}</div>}
@@ -178,8 +185,15 @@ export function CreateWorkspacePage() {
178185
<div className="w-full flex justify-end mt-6 space-x-2 px-6">
179186
<Button
180187
onClick={onClickCreate}
188+
autoFocus={true}
181189
loading={isStarting || isLoading}
182-
disabled={!repo || repo.length === 0 || !!errorIde || !!errorWsClass}
190+
disabled={
191+
!contextURL ||
192+
contextURL.length === 0 ||
193+
!!errorIde ||
194+
!!errorWsClass ||
195+
!!workspaceContext.error
196+
}
183197
>
184198
{isLoading ? "Loading ..." : isStarting ? "Creating Workspace ..." : "New Workspace"}
185199
</Button>

0 commit comments

Comments
 (0)