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

Commit4216e28

Browse files
authored
fix: editor: fallback to default entrypoint (#16757)
Related:#16753 (comment)
1 parent930816f commit4216e28

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import type { MonacoEditorProps } from "./MonacoEditor";
2727
import{Language}from"./PublishTemplateVersionDialog";
2828
importTemplateVersionEditorPage,{
2929
findEntrypointFile,
30+
getActivePath,
3031
}from"./TemplateVersionEditorPage";
3132

3233
const{API}=apiModule;
@@ -413,6 +414,34 @@ function renderEditorPage(queryClient: QueryClient) {
413414
);
414415
}
415416

417+
describe("Get active path",()=>{
418+
it("empty path",()=>{
419+
constft:FileTree={
420+
"main.tf":"foobar",
421+
};
422+
constsearchParams=newURLSearchParams({path:""});
423+
constactivePath=getActivePath(searchParams,ft);
424+
expect(activePath).toBe("main.tf");
425+
});
426+
it("invalid path",()=>{
427+
constft:FileTree={
428+
"main.tf":"foobar",
429+
};
430+
constsearchParams=newURLSearchParams({path:"foobaz"});
431+
constactivePath=getActivePath(searchParams,ft);
432+
expect(activePath).toBe("main.tf");
433+
});
434+
it("valid path",()=>{
435+
constft:FileTree={
436+
"main.tf":"foobar",
437+
"foobar.tf":"foobaz",
438+
};
439+
constsearchParams=newURLSearchParams({path:"foobar.tf"});
440+
constactivePath=getActivePath(searchParams,ft);
441+
expect(activePath).toBe("foobar.tf");
442+
});
443+
});
444+
416445
describe("Find entrypoint",()=>{
417446
it("empty tree",()=>{
418447
constft:FileTree={};

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { type FC, useEffect, useState } from "react";
2020
import{Helmet}from"react-helmet-async";
2121
import{useMutation,useQuery,useQueryClient}from"react-query";
2222
import{useNavigate,useParams,useSearchParams}from"react-router-dom";
23-
import{typeFileTree,traverse}from"utils/filetree";
23+
import{typeFileTree,existsFile,traverse}from"utils/filetree";
2424
import{pageTitle}from"utils/page";
2525
import{TarReader,TarWriter}from"utils/tar";
2626
import{createTemplateVersionFileTree}from"utils/templateVersion";
@@ -88,9 +88,8 @@ export const TemplateVersionEditorPage: FC = () => {
8888
useState<TemplateVersion>();
8989

9090
// File navigation
91-
// It can be undefined when a selected file is deleted
92-
constactivePath:string|undefined=
93-
searchParams.get("path")??findEntrypointFile(fileTree??{});
91+
constactivePath=getActivePath(searchParams,fileTree||{});
92+
9493
constonActivePathChange=(path:string|undefined)=>{
9594
if(path){
9695
searchParams.set("path",path);
@@ -392,4 +391,15 @@ export const findEntrypointFile = (fileTree: FileTree): string | undefined => {
392391
returninitialFile;
393392
};
394393

394+
exportconstgetActivePath=(
395+
searchParams:URLSearchParams,
396+
fileTree:FileTree,
397+
):string|undefined=>{
398+
constselectedPath=searchParams.get("path");
399+
if(selectedPath&&existsFile(selectedPath,fileTree)){
400+
returnselectedPath;
401+
}
402+
returnfindEntrypointFile(fileTree);
403+
};
404+
395405
exportdefaultTemplateVersionEditorPage;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp