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

fix: editor: fallback to default entrypoint#16757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mtojek merged 1 commit intomainfrom16360-fix-2
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,6 +27,7 @@ import type { MonacoEditorProps } from "./MonacoEditor";
import { Language } from "./PublishTemplateVersionDialog";
import TemplateVersionEditorPage, {
findEntrypointFile,
getActivePath,
} from "./TemplateVersionEditorPage";

const { API } = apiModule;
Expand DownExpand Up@@ -413,6 +414,34 @@ function renderEditorPage(queryClient: QueryClient) {
);
}

describe("Get active path", () => {
it("empty path", () => {
const ft: FileTree = {
"main.tf": "foobar",
};
const searchParams = new URLSearchParams({ path: "" });
const activePath = getActivePath(searchParams, ft);
expect(activePath).toBe("main.tf");
});
it("invalid path", () => {
const ft: FileTree = {
"main.tf": "foobar",
};
const searchParams = new URLSearchParams({ path: "foobaz" });
const activePath = getActivePath(searchParams, ft);
expect(activePath).toBe("main.tf");
});
it("valid path", () => {
const ft: FileTree = {
"main.tf": "foobar",
"foobar.tf": "foobaz",
};
const searchParams = new URLSearchParams({ path: "foobar.tf" });
const activePath = getActivePath(searchParams, ft);
expect(activePath).toBe("foobar.tf");
});
});

describe("Find entrypoint", () => {
it("empty tree", () => {
const ft: FileTree = {};
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,7 +20,7 @@ import { type FC, useEffect, useState } from "react";
import { Helmet } from "react-helmet-async";
import { useMutation, useQuery, useQueryClient } from "react-query";
import { useNavigate, useParams, useSearchParams } from "react-router-dom";
import { type FileTree, traverse } from "utils/filetree";
import { type FileTree,existsFile,traverse } from "utils/filetree";
import { pageTitle } from "utils/page";
import { TarReader, TarWriter } from "utils/tar";
import { createTemplateVersionFileTree } from "utils/templateVersion";
Expand DownExpand Up@@ -88,9 +88,8 @@ export const TemplateVersionEditorPage: FC = () => {
useState<TemplateVersion>();

// File navigation
// It can be undefined when a selected file is deleted
const activePath: string | undefined =
searchParams.get("path") ?? findEntrypointFile(fileTree ?? {});
const activePath = getActivePath(searchParams, fileTree || {});

const onActivePathChange = (path: string | undefined) => {
if (path) {
searchParams.set("path", path);
Expand DownExpand Up@@ -392,4 +391,15 @@ export const findEntrypointFile = (fileTree: FileTree): string | undefined => {
return initialFile;
};

export const getActivePath = (
searchParams: URLSearchParams,
fileTree: FileTree,
): string | undefined => {
const selectedPath = searchParams.get("path");
if (selectedPath && existsFile(selectedPath, fileTree)) {
return selectedPath;
}
return findEntrypointFile(fileTree);
};

export default TemplateVersionEditorPage;
Loading

[8]ページ先頭

©2009-2025 Movatter.jp