Skip to content

Commit ff4fc2f

Browse files
feat: add View Source button for template administrators in workspace creation
Adds a View Source button to the workspace creation page that allows template administrators to quickly navigate to the template editor. The button: - Only appears for users with template update permissions - Links directly to the template version editor - Uses the ExternalLinkIcon for consistency with other source viewing features - Is positioned next to the Cancel button in the page header This addresses user friction where template admins expect to be able to edit templates directly from the workspace creation flow. Co-authored-by: matifali <10648092+matifali@users.noreply.github.com>
1 parent 4ac6be6 commit ff4fc2f

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

site/src/pages/CreateWorkspacePage/CreateWorkspacePage.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,16 @@ const CreateWorkspacePage: FC = () => {
6565
});
6666
const permissionsQuery = useQuery({
6767
...checkAuthorization({
68-
checks: createWorkspaceChecks(templateQuery.data?.organization_id ?? ""),
68+
checks: {
69+
...createWorkspaceChecks(templateQuery.data?.organization_id ?? ""),
70+
canUpdateTemplate: {
71+
object: {
72+
resource_type: "template",
73+
resource_id: templateQuery.data?.id ?? "",
74+
},
75+
action: "update",
76+
},
77+
},
6978
}),
7079
enabled: !!templateQuery.data,
7180
});
@@ -208,6 +217,7 @@ const CreateWorkspacePage: FC = () => {
208217
startPollingExternalAuth={startPollingExternalAuth}
209218
hasAllRequiredExternalAuth={hasAllRequiredExternalAuth}
210219
permissions={permissionsQuery.data as CreateWorkspacePermissions}
220+
canUpdateTemplate={permissionsQuery.data?.canUpdateTemplate}
211221
parameters={realizedParameters as TemplateVersionParameter[]}
212222
presets={templateVersionPresetsQuery.data ?? []}
213223
creatingWorkspace={createWorkspaceMutation.isPending}

site/src/pages/CreateWorkspacePage/CreateWorkspacePageView.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ import { UserAutocomplete } from "components/UserAutocomplete/UserAutocomplete";
2828
import { type FormikContextType, useFormik } from "formik";
2929
import type { ExternalAuthPollingState } from "hooks/useExternalAuth";
3030
import { generateWorkspaceName } from "modules/workspaces/generateWorkspaceName";
31+
import { ExternalLinkIcon } from "lucide-react";
3132
import { type FC, useCallback, useEffect, useMemo, useState } from "react";
33+
import { Link } from "react-router-dom";
3234
import {
3335
getFormHelpers,
3436
nameValidator,
@@ -67,6 +69,7 @@ interface CreateWorkspacePageViewProps {
6769
presets: TypesGen.Preset[];
6870
permissions: CreateWorkspacePermissions;
6971
creatingWorkspace: boolean;
72+
canUpdateTemplate?: boolean;
7073
onCancel: () => void;
7174
onSubmit: (
7275
req: TypesGen.CreateWorkspaceRequest,
@@ -92,6 +95,7 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
9295
presets = [],
9396
permissions,
9497
creatingWorkspace,
98+
canUpdateTemplate,
9599
onSubmit,
96100
onCancel,
97101
}) => {
@@ -218,9 +222,19 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
218222
<Margins size="medium">
219223
<PageHeader
220224
actions={
221-
<Button size="sm" variant="outline" onClick={onCancel}>
222-
Cancel
223-
</Button>
225+
<Stack direction="row" spacing={2}>
226+
{canUpdateTemplate && (
227+
<Button asChild size="sm" variant="outline">
228+
<Link to={`/templates/${template.organization_name}/${template.name}/versions/${versionId}/edit`}>
229+
<ExternalLinkIcon />
230+
View source
231+
</Link>
232+
</Button>
233+
)}
234+
<Button size="sm" variant="outline" onClick={onCancel}>
235+
Cancel
236+
</Button>
237+
</Stack>
224238
}
225239
>
226240
<Stack direction="row">

0 commit comments

Comments
 (0)