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

Commit4c1cdad

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 commit4c1cdad

6 files changed

+54
-32
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 & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -403,22 +403,4 @@ export const WithViewSourceButton: Story = {
403403
},
404404
};
405405

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-
};
406+

‎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+
exportconstWithViewSourceButton: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{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: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
exportconstcreateWorkspaceChecks=(organizationId:string)=>
1+
exportconstcreateWorkspaceChecks=(organizationId:string,templateId?:string)=>
22
({
33
createWorkspaceForAny:{
44
object:{
@@ -8,6 +8,15 @@ export const createWorkspaceChecks = (organizationId: string) =>
88
},
99
action:"create",
1010
},
11+
...(templateId&&{
12+
canUpdateTemplate:{
13+
object:{
14+
resource_type:"template",
15+
resource_id:templateId,
16+
},
17+
action:"update",
18+
},
19+
}),
1120
})asconst;
1221

1322
exporttypeCreateWorkspacePermissions=Record<

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp