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

Commit7e6cb66

Browse files
authored
feat(site): allow creating a workspace without connecting optional external auth providers (#12251)
1 parentb8a5323 commit7e6cb66

File tree

5 files changed

+117
-29
lines changed

5 files changed

+117
-29
lines changed

‎site/src/pages/CreateWorkspacePage/CreateWorkspacePage.test.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -233,19 +233,6 @@ describe("CreateWorkspacePage", () => {
233233
);
234234
});
235235

236-
it("external auth errors if unauthenticated",async()=>{
237-
jest
238-
.spyOn(API,"getTemplateVersionExternalAuth")
239-
.mockResolvedValueOnce([MockTemplateVersionExternalAuthGithub]);
240-
241-
renderCreateWorkspacePage();
242-
awaitwaitForLoaderToBeRemoved();
243-
244-
awaitscreen.findByText(
245-
"To create a workspace using the selected template, please ensure you are authenticated with all the external providers listed below.",
246-
);
247-
});
248-
249236
it("auto create a workspace if uses mode=auto",async()=>{
250237
constparam="first_parameter";
251238
constparamValue="It works!";
@@ -312,7 +299,7 @@ describe("CreateWorkspacePage", () => {
312299
route:`/templates/${MockWorkspace.name}/workspace?${params.toString()}`,
313300
});
314301

315-
constwarningMessage=awaitscreen.findByRole("alert");
302+
constwarningMessage=awaitscreen.findByTestId("duplication-warning");
316303
constnameInput=awaitscreen.findByRole("textbox",{
317304
name:"Workspace Name",
318305
});

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

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,80 @@ export const ExternalAuth: Story = {
126126
authenticate_url:"",
127127
display_icon:"/icon/gitlab.svg",
128128
display_name:"GitLab",
129+
optional:true,
130+
},
131+
],
132+
},
133+
};
134+
135+
exportconstExternalAuthError:Story={
136+
args:{
137+
error:true,
138+
externalAuth:[
139+
{
140+
id:"github",
141+
type:"github",
142+
authenticated:false,
143+
authenticate_url:"",
144+
display_icon:"/icon/github.svg",
145+
display_name:"GitHub",
146+
},
147+
{
148+
id:"gitlab",
149+
type:"gitlab",
150+
authenticated:false,
151+
authenticate_url:"",
152+
display_icon:"/icon/gitlab.svg",
153+
display_name:"GitLab",
154+
optional:true,
155+
},
156+
],
157+
},
158+
};
159+
160+
exportconstExternalAuthAllRequiredConnected:Story={
161+
args:{
162+
externalAuth:[
163+
{
164+
id:"github",
165+
type:"github",
166+
authenticated:true,
167+
authenticate_url:"",
168+
display_icon:"/icon/github.svg",
169+
display_name:"GitHub",
170+
},
171+
{
172+
id:"gitlab",
173+
type:"gitlab",
174+
authenticated:false,
175+
authenticate_url:"",
176+
display_icon:"/icon/gitlab.svg",
177+
display_name:"GitLab",
178+
optional:true,
179+
},
180+
],
181+
},
182+
};
183+
184+
exportconstExternalAuthAllConnected:Story={
185+
args:{
186+
externalAuth:[
187+
{
188+
id:"github",
189+
type:"github",
190+
authenticated:true,
191+
authenticate_url:"",
192+
display_icon:"/icon/github.svg",
193+
display_name:"GitHub",
194+
},
195+
{
196+
id:"gitlab",
197+
type:"gitlab",
198+
authenticated:true,
199+
authenticate_url:"",
200+
display_icon:"/icon/gitlab.svg",
201+
display_name:"GitLab",
202+
optional:true,
129203
},
130204
],
131205
},

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
147147
);
148148
},[autofillParameters]);
149149

150+
consthasAllRequiredExternalAuth=externalAuth.every(
151+
(auth)=>auth.optional||auth.authenticated,
152+
);
153+
150154
return(
151155
<Marginssize="medium">
152156
<PageHeaderactions={<ButtononClick={onCancel}>Cancel</Button>}>
@@ -179,7 +183,7 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
179183
{Boolean(error)&&<ErrorAlerterror={error}/>}
180184

181185
{mode==="duplicate"&&(
182-
<Alertseverity="info"dismissible>
186+
<Alertseverity="info"dismissibledata-testid="duplication-warning">
183187
{Language.duplicationWarning}
184188
</Alert>
185189
)}
@@ -248,21 +252,19 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
248252
{externalAuth&&externalAuth.length>0&&(
249253
<FormSection
250254
title="External Authentication"
251-
description="This templaterequires authentication toexternal services."
255+
description="This templateusesexternal services for authentication."
252256
>
253257
<FormFields>
254-
{requiresExternalAuth&&(
255-
// This should really be a `notice` but `severity` is a MUI prop, and we'd need
256-
// to basically make our own `Alert` component.
257-
<Alertseverity="info">
258-
To create a workspace using the selected template, please
259-
ensure you are authenticated with all the external providers
260-
listed below.
258+
{Boolean(error)&&!hasAllRequiredExternalAuth&&(
259+
<Alertseverity="error">
260+
To create a workspace using this template, please connect to
261+
all required external authentication providers listed below.
261262
</Alert>
262263
)}
263264
{externalAuth.map((auth)=>(
264265
<ExternalAuthButton
265266
key={auth.id}
267+
error={error}
266268
auth={auth}
267269
isLoading={externalAuthPollingState==="polling"}
268270
onStartPolling={startPollingExternalAuth}
@@ -313,6 +315,7 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
313315
<FormFooter
314316
onCancel={onCancel}
315317
isLoading={creatingWorkspace}
318+
submitDisabled={!hasAllRequiredExternalAuth}
316319
submitLabel="Create Workspace"
317320
/>
318321
</HorizontalForm>

‎site/src/pages/CreateWorkspacePage/ExternalAuthButton.stories.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const MockExternalAuth: TemplateVersionExternalAuth = {
1212
};
1313

1414
constmeta:Meta<typeofExternalAuthButton>={
15-
title:"pages/CreateWorkspacePage/ExternalAuth",
15+
title:"pages/CreateWorkspacePage/ExternalAuthButton",
1616
component:ExternalAuthButton,
1717
};
1818

@@ -25,6 +25,15 @@ export const Github: Story = {
2525
},
2626
};
2727

28+
exportconstGithubOptional:Story={
29+
args:{
30+
auth:{
31+
...MockExternalAuth,
32+
optional:true,
33+
},
34+
},
35+
};
36+
2837
exportconstGithubWithRetry:Story={
2938
args:{
3039
auth:MockExternalAuth,
@@ -48,6 +57,7 @@ export const Gitlab: Story = {
4857
display_icon:"/icon/gitlab.svg",
4958
display_name:"GitLab",
5059
authenticated:false,
60+
optional:true,
5161
},
5262
},
5363
};
@@ -70,6 +80,7 @@ export const AzureDevOps: Story = {
7080
display_icon:"/icon/azure-devops.svg",
7181
display_name:"Azure DevOps",
7282
authenticated:false,
83+
optional:true,
7384
},
7485
},
7586
};
@@ -92,6 +103,7 @@ export const Bitbucket: Story = {
92103
display_icon:"/icon/bitbucket.svg",
93104
display_name:"Bitbucket",
94105
authenticated:false,
106+
optional:true,
95107
},
96108
},
97109
};

‎site/src/pages/CreateWorkspacePage/ExternalAuthButton.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
importReplayIconfrom"@mui/icons-material/Replay";
22
importButtonfrom"@mui/material/Button";
33
importTooltipfrom"@mui/material/Tooltip";
4-
import{typeFC}from"react";
54
importLoadingButtonfrom"@mui/lab/LoadingButton";
65
import{visuallyHidden}from"@mui/utils";
6+
import{typeFC}from"react";
7+
importtype{TemplateVersionExternalAuth}from"api/typesGenerated";
78
import{ExternalImage}from"components/ExternalImage/ExternalImage";
8-
import{TemplateVersionExternalAuth}from"api/typesGenerated";
9+
import{Pill}from"components/Pill/Pill";
910

1011
exportinterfaceExternalAuthButtonProps{
1112
auth:TemplateVersionExternalAuth;
1213
displayRetry:boolean;
1314
isLoading:boolean;
1415
onStartPolling:()=>void;
16+
error?:unknown;
1517
}
1618

1719
exportconstExternalAuthButton:FC<ExternalAuthButtonProps>=({
1820
auth,
1921
displayRetry,
2022
isLoading,
2123
onStartPolling,
24+
error,
2225
})=>{
2326
return(
2427
<>
@@ -48,9 +51,18 @@ export const ExternalAuthButton: FC<ExternalAuthButtonProps> = ({
4851
onStartPolling();
4952
}}
5053
>
51-
{auth.authenticated
52-
?`Authenticated with${auth.display_name}`
53-
:`Login with${auth.display_name}`}
54+
{auth.authenticated ?(
55+
`Authenticated with${auth.display_name}`
56+
) :(
57+
<>
58+
Login with{auth.display_name}
59+
{!auth.optional&&(
60+
<Pilltype={error ?"error" :"info"}css={{marginLeft:12}}>
61+
Required
62+
</Pill>
63+
)}
64+
</>
65+
)}
5466
</LoadingButton>
5567

5668
{displayRetry&&(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp