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

Commit176f747

Browse files
committed
feat: add default workspace name to Template Embed form
1 parent91780db commit176f747

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

‎site/src/pages/TemplatePage/TemplateEmbedPage/TemplateEmbedPage.test.tsx‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import{screen}from"@testing-library/react";
1+
import{screen,within}from"@testing-library/react";
22
importuserEventfrom"@testing-library/user-event";
33
import{API}from"api/api";
44
import{TemplateLayout}from"pages/TemplatePage/TemplateLayout";
@@ -30,6 +30,11 @@ test("Users can fill the parameters and copy the open in coder url", async () =>
3030
awaitwaitForLoaderToBeRemoved();
3131

3232
constuser=userEvent.setup();
33+
constworkspaceName=within(
34+
screen.getByTestId("default-workspace-name"),
35+
).getByRole("textbox");
36+
awaituser.clear(workspaceName);
37+
awaituser.type(workspaceName,"my-first-workspace");
3338
constfirstParameterField=screen.getByLabelText(
3439
parameter1.display_name??parameter1.name,
3540
{exact:false},
@@ -47,6 +52,6 @@ test("Users can fill the parameters and copy the open in coder url", async () =>
4752
constcopyButton=screen.getByRole("button",{name:/copy/i});
4853
awaituserEvent.click(copyButton);
4954
expect(window.navigator.clipboard.writeText).toBeCalledWith(
50-
`[![Open in Coder](http://localhost/open-in-coder.svg)](http://localhost/templates/${MockTemplate.organization_name}/${MockTemplate.name}/workspace?mode=manual&param.first_parameter=firstParameterValue&param.second_parameter=123456)`,
55+
`[![Open in Coder](http://localhost/open-in-coder.svg)](http://localhost/templates/${MockTemplate.organization_name}/${MockTemplate.name}/workspace?mode=manual&param.first_parameter=firstParameterValue&param.second_parameter=123456&name=my-first-workspace)`,
5156
);
5257
});

‎site/src/pages/TemplatePage/TemplateEmbedPage/TemplateEmbedPage.tsx‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Button from "@mui/material/Button";
22
importFormControlLabelfrom"@mui/material/FormControlLabel";
33
importRadiofrom"@mui/material/Radio";
44
importRadioGroupfrom"@mui/material/RadioGroup";
5+
importTextFieldfrom"@mui/material/TextField";
56
import{API}from"api/api";
67
importtype{Template,TemplateVersionParameter}from"api/typesGenerated";
78
import{FormSection,VerticalForm}from"components/Form/Form";
@@ -13,9 +14,11 @@ import { useTemplateLayoutContext } from "pages/TemplatePage/TemplateLayout";
1314
import{typeFC,useEffect,useState}from"react";
1415
import{Helmet}from"react-helmet-async";
1516
import{useQuery}from"react-query";
17+
import{nameValidator}from"utils/formUtils";
1618
import{pageTitle}from"utils/page";
1719
import{getInitialRichParameterValues}from"utils/richParameters";
1820
import{paramsUsedToCreateWorkspace}from"utils/workspace";
21+
import{ValidationError}from"yup";
1922

2023
typeButtonValues=Record<string,string>;
2124

@@ -89,6 +92,17 @@ export const TemplateEmbedPageView: FC<TemplateEmbedPageViewProps> = ({
8992
}
9093
},[buttonValues,templateParameters]);
9194

95+
const[workspaceNameError,setWorkspaceNameError]=useState("");
96+
constworkspaceNameValidator=nameValidator("Workspace name");
97+
constvalidateWorkspaceName=(workspaceName:string)=>{
98+
try{
99+
workspaceName&&workspaceNameValidator.validateSync(workspaceName);
100+
setWorkspaceNameError("");
101+
}catch(e){
102+
setWorkspaceNameError(einstanceofValidationError ?e.message :"");
103+
}
104+
};
105+
92106
return(
93107
<>
94108
<Helmet>
@@ -126,6 +140,26 @@ export const TemplateEmbedPageView: FC<TemplateEmbedPageViewProps> = ({
126140
</RadioGroup>
127141
</FormSection>
128142

143+
<FormSection
144+
title="Workspace name"
145+
description="Default name for the new workspace"
146+
>
147+
<TextField
148+
data-testid="default-workspace-name"
149+
defaultValue={buttonValues.name}
150+
fullWidth
151+
onChange={(event)=>{
152+
validateWorkspaceName(event.target.value);
153+
setButtonValues((buttonValues)=>({
154+
...buttonValues,
155+
name:event.target.value,
156+
}));
157+
}}
158+
error={workspaceNameError!==""}
159+
helperText={workspaceNameError}
160+
/>
161+
</FormSection>
162+
129163
{templateParameters.length>0&&(
130164
<div
131165
css={{display:"flex",flexDirection:"column",gap:36}}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp