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

Commited3d6fa

Browse files
authored
fix(site): preserve file path when building template version (#20481)
Fixes issue where clicking Build in the template editor would alwaysredirect to main.tf instead of keeping the currently open file.Closes#14130<!--If you have used AI to produce some or all of this PR, please ensure youhave read our [AI Contributionguidelines](https://coder.com/docs/about/contributing/AI_CONTRIBUTING)before submitting.-->
1 parentd9c40d6 commited3d6fa

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,39 @@ test("The file is uploaded with the correct content type", async () => {
255255
);
256256
});
257257

258+
test("Preserves the currently open file path when building a template version",async()=>{
259+
constuser=userEvent.setup();
260+
const{ router}=renderWithAuth(<TemplateVersionEditorPage/>,{
261+
route:`/templates/${MockTemplate.name}/versions/${MockTemplateVersion.name}/edit?path=myfile.tf`,
262+
path:"/templates/:template/versions/:version/edit",
263+
extraRoutes:[
264+
{
265+
path:"/templates/:templateId",
266+
element:<div></div>,
267+
},
268+
],
269+
});
270+
271+
consttopbar=awaitscreen.findByTestId("topbar");
272+
273+
constnewTemplateVersion:TemplateVersion={
274+
...MockTemplateVersion,
275+
id:"new-version-id",
276+
name:"new-version",
277+
};
278+
279+
awaittypeOnEditor("new content",user);
280+
awaitbuildTemplateVersion(newTemplateVersion,user,topbar);
281+
282+
// Verify that the path query parameter is preserved in the URL
283+
awaitwaitFor(()=>{
284+
expect(router.state.location.pathname).toBe(
285+
`/templates/${MockTemplate.name}/versions/new-version/edit`,
286+
);
287+
});
288+
expect(router.state.location.search).toBe("?path=myfile.tf");
289+
});
290+
258291
describe.each([
259292
{
260293
testName:"Do not ask when template version has no errors",

‎site/src/pages/TemplateVersionEditorPage/TemplateVersionEditorPage.tsx‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,10 @@ const TemplateVersionEditorPage: FC = () => {
104104
};
105105

106106
constnavigateToVersion=(version:TemplateVersion)=>{
107-
returnnavigate(
108-
`${getLink(linkToTemplate(organizationName,templateName))}/versions/${
109-
version.name
110-
}/edit`,
111-
{replace:true},
112-
);
107+
consturl=`${getLink(linkToTemplate(organizationName,templateName))}/versions/${
108+
version.name
109+
}/edit?${searchParams.toString()}`;
110+
returnnavigate(url,{replace:true});
113111
};
114112

115113
constonBuildEnds=(newVersion:TemplateVersion)=>{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp