Content-Length: 597927 | pFad | http://github.com/coder/coder/commit/96f849c0605741766c3a3ba5800beb09c23b53e7

0C feat: add View Source button to experimental component and refactor p… · coder/coder@96f849c · GitHub
Skip to content

Commit 96f849c

Browse files
feat: add View Source button to experimental component and refactor permissions
Addresses review feedback: - Added View Source button to CreateWorkspacePageViewExperimental component - Refactored createWorkspaceChecks helper to include template update permission - Updated both regular and experimental pages to use the new permissions helper - Added story for experimental component with View Source button - Removed unnecessary WithoutViewSourceButton story (default behavior) The View Source button now appears in both the regular and experimental workspace creation pages for template administrators. Co-authored-by: matifali <10648092+matifali@users.noreply.github.com>
1 parent 106c383 commit 96f849c

6 files changed

+56
-33
lines changed

site/src/pages/CreateWorkspacePage/CreateWorkspacePage.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,10 @@ const CreateWorkspacePage: FC = () => {
6565
});
6666
const permissionsQuery = useQuery({
6767
...checkAuthorization({
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-
},
68+
checks: createWorkspaceChecks(
69+
templateQuery.data?.organization_id ?? "",
70+
templateQuery.data?.id,
71+
),
7872
}),
7973
enabled: !!templateQuery.data,
8074
});

site/src/pages/CreateWorkspacePage/CreateWorkspacePageExperimental.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ const CreateWorkspacePageExperimental: FC = () => {
7979
});
8080
const permissionsQuery = useQuery({
8181
...checkAuthorization({
82-
checks: createWorkspaceChecks(templateQuery.data?.organization_id ?? ""),
82+
checks: createWorkspaceChecks(
83+
templateQuery.data?.organization_id ?? "",
84+
templateQuery.data?.id,
85+
),
8386
}),
8487
enabled: !!templateQuery.data,
8588
});
@@ -292,6 +295,7 @@ const CreateWorkspacePageExperimental: FC = () => {
292295
owner={owner}
293296
setOwner={setOwner}
294297
autofillParameters={autofillParameters}
298+
canUpdateTemplate={permissionsQuery.data?.canUpdateTemplate}
295299
error={
296300
wsError ||
297301
createWorkspaceMutation.error ||

site/src/pages/CreateWorkspacePage/CreateWorkspacePageView.stories.tsx

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -402,23 +402,3 @@ export const WithViewSourceButton: Story = {
402402
},
403403
},
404404
};
405-
406-
export const WithoutViewSourceButton: Story = {
407-
args: {
408-
canUpdateTemplate: false,
409-
versionId: "template-version-123",
410-
template: {
411-
...MockTemplate,
412-
organization_name: "default",
413-
name: "docker-template",
414-
},
415-
},
416-
parameters: {
417-
docs: {
418-
description: {
419-
story:
420-
"This story shows the workspace creation page for users without template update permissions. The View Source button is hidden for these users.",
421-
},
422-
},
423-
},
424-
};

site/src/pages/CreateWorkspacePage/CreateWorkspacePageViewExperimental.stories.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,23 @@ export const WebsocketError: Story = {
3838
),
3939
},
4040
};
41+
42+
export const WithViewSourceButton: Story = {
43+
args: {
44+
canUpdateTemplate: true,
45+
versionId: "template-version-123",
46+
template: {
47+
...MockTemplate,
48+
organization_name: "default",
49+
name: "docker-template",
50+
},
51+
},
52+
parameters: {
53+
docs: {
54+
description: {
55+
story:
56+
"This story shows the View Source button that appears for template administrators in the experimental workspace creation page. The button allows quick navigation to the template editor.",
57+
},
58+
},
59+
},
60+
};

site/src/pages/CreateWorkspacePage/CreateWorkspacePageViewExperimental.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
import { UserAutocomplete } from "components/UserAutocomplete/UserAutocomplete";
2828
import { type FormikContextType, useFormik } from "formik";
2929
import type { ExternalAuthPollingState } from "hooks/useExternalAuth";
30-
import { ArrowLeft, CircleHelp } from "lucide-react";
30+
import { ArrowLeft, CircleHelp, ExternalLinkIcon } from "lucide-react";
3131
import { useSyncFormParameters } from "modules/hooks/useSyncFormParameters";
3232
import {
3333
Diagnostics,
@@ -44,6 +44,7 @@ import {
4444
useRef,
4545
useState,
4646
} from "react";
47+
import { Link as RouterLink } from "react-router-dom";
4748
import { docs } from "utils/docs";
4849
import { nameValidator } from "utils/formUtils";
4950
import type { AutofillBuildParameter } from "utils/richParameters";
@@ -54,6 +55,7 @@ import type { CreateWorkspacePermissions } from "./permissions";
5455

5556
interface CreateWorkspacePageViewExperimentalProps {
5657
autofillParameters: AutofillBuildParameter[];
58+
canUpdateTemplate?: boolean;
5759
creatingWorkspace: boolean;
5860
defaultName?: string | null;
5961
defaultOwner: TypesGen.User;
@@ -85,6 +87,7 @@ export const CreateWorkspacePageViewExperimental: FC<
8587
CreateWorkspacePageViewExperimentalProps
8688
> = ({
8789
autofillParameters,
90+
canUpdateTemplate,
8891
creatingWorkspace,
8992
defaultName,
9093
defaultOwner,
@@ -379,6 +382,16 @@ export const CreateWorkspacePageViewExperimental: FC<
379382
</Badge>
380383
)}
381384
</span>
385+
{canUpdateTemplate && (
386+
<Button asChild size="sm" variant="outline">
387+
<RouterLink
388+
to={`/templates/${template.organization_name}/${template.name}/versions/${versionId}/edit`}
389+
>
390+
<ExternalLinkIcon />
391+
View source
392+
</RouterLink>
393+
</Button>
394+
)}
382395
</div>
383396
<span className="flex flex-row items-center gap-2">
384397
<h1 className="text-3xl font-semibold m-0">New workspace</h1>

site/src/pages/CreateWorkspacePage/permissions.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
export const createWorkspaceChecks = (organizationId: string) =>
1+
export const createWorkspaceChecks = (
2+
organizationId: string,
3+
templateId?: string,
4+
) =>
25
({
36
createWorkspaceForAny: {
47
object: {
@@ -8,6 +11,15 @@ export const createWorkspaceChecks = (organizationId: string) =>
811
},
912
action: "create",
1013
},
14+
...(templateId && {
15+
canUpdateTemplate: {
16+
object: {
17+
resource_type: "template",
18+
resource_id: templateId,
19+
},
20+
action: "update",
21+
},
22+
}),
1123
}) as const;
1224

1325
export type CreateWorkspacePermissions = Record<

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/coder/coder/commit/96f849c0605741766c3a3ba5800beb09c23b53e7

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy