Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaca0211

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 experimentalworkspace creation pages for template administrators.Co-authored-by: matifali <10648092+matifali@users.noreply.github.com>
1 parent106c383 commitaca0211

6 files changed

+60
-35
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
constpermissionsQuery=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
constpermissionsQuery=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: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const meta: Meta<typeof CreateWorkspacePageView> = {
2828
mode:"form",
2929
permissions:{
3030
createWorkspaceForAny:true,
31+
canUpdateTemplate:false,
3132
},
3233
onCancel:action("onCancel"),
3334
},
@@ -402,23 +403,3 @@ export const WithViewSourceButton: Story = {
402403
},
403404
},
404405
};
405-
406-
exportconstWithoutViewSourceButton: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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const meta: Meta<typeof CreateWorkspacePageViewExperimental> = {
2020
parameters:[],
2121
permissions:{
2222
createWorkspaceForAny:true,
23+
canUpdateTemplate:false,
2324
},
2425
presets:[],
2526
sendMessage:()=>{},
@@ -38,3 +39,23 @@ export const WebsocketError: Story = {
3839
),
3940
},
4041
};
42+
43+
exportconstWithViewSourceButton:Story={
44+
args:{
45+
canUpdateTemplate:true,
46+
versionId:"template-version-123",
47+
template:{
48+
...MockTemplate,
49+
organization_name:"default",
50+
name:"docker-template",
51+
},
52+
},
53+
parameters:{
54+
docs:{
55+
description:{
56+
story:
57+
"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.",
58+
},
59+
},
60+
},
61+
};

‎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{typeFormikContextType,useFormik}from"formik";
2929
importtype{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{LinkasRouterLink}from"react-router-dom";
4748
import{docs}from"utils/docs";
4849
import{nameValidator}from"utils/formUtils";
4950
importtype{AutofillBuildParameter}from"utils/richParameters";
@@ -54,6 +55,7 @@ import type { CreateWorkspacePermissions } from "./permissions";
5455

5556
interfaceCreateWorkspacePageViewExperimentalProps{
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+
<ButtonasChildsize="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
<spanclassName="flex flex-row items-center gap-2">
384397
<h1className="text-3xl font-semibold m-0">New workspace</h1>

‎site/src/pages/CreateWorkspacePage/permissions.ts‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1-
exportconstcreateWorkspaceChecks=(organizationId:string)=>
1+
exportconstcreateWorkspaceChecks=(
2+
organizationId:string,
3+
templateId?:string,
4+
)=>
25
({
36
createWorkspaceForAny:{
47
object:{
5-
resource_type:"workspace",
8+
resource_type:"workspace"asconst,
69
organization_id:organizationId,
710
owner_id:"*",
811
},
9-
action:"create",
12+
action:"create"asconst,
1013
},
14+
...(templateId&&{
15+
canUpdateTemplate:{
16+
object:{
17+
resource_type:"template"asconst,
18+
resource_id:templateId,
19+
},
20+
action:"update"asconst,
21+
},
22+
}),
1123
})asconst;
1224

1325
exporttypeCreateWorkspacePermissions=Record<

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp