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(site): fix react state violation in filetree create/update utils#20483

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
DanielleMaywood merged 4 commits intomainfromdanielle/site/react-state-violation
Oct 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
34 changes: 22 additions & 12 deletionssite/src/utils/filetree.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,18 +10,20 @@ import {
} from "./filetree";

test("createFile() set file into the file tree", () => {
let fileTree: FileTree = {
const fileTree: FileTree = {
"main.tf": "terraform",
images: { "java.Dockerfile": "java dockerfile" },
};
fileTree = createFile(
const updatedFileTree = createFile(
"images/python.Dockerfile",
fileTree,
"python dockerfile",
);
expect((fileTree.images as FileTree)["python.Dockerfile"]).toEqual(
expect((updatedFileTree.images as FileTree)["python.Dockerfile"]).toEqual(
"python dockerfile",
);
// Verify the original FileTree was not modified.
expect((fileTree.images as FileTree)["python.Dockerfile"]).toBeUndefined();
});

test("getFileContent() return the file content from the file tree", () => {
Expand All@@ -35,50 +37,56 @@ test("getFileContent() return the file content from the file tree", () => {
});

test("removeFile() removes a file from a folder", () => {
let fileTree: FileTree = {
const fileTree: FileTree = {
"main.tf": "terraform content",
images: {
"java.Dockerfile": "java dockerfile",
"python.Dockerfile": "python Dockerfile",
},
};
fileTree = removeFile("images/python.Dockerfile", fileTree);
const updatedFileTree = removeFile("images/python.Dockerfile", fileTree);
const expectedFileTree = {
"main.tf": "terraform content",
images: {
"java.Dockerfile": "java dockerfile",
},
};
expect(expectedFileTree).toEqual(fileTree);
expect(updatedFileTree).toEqual(expectedFileTree);
// Verify the original FileTree was not modified.
expect((fileTree.images as FileTree)["python.Dockerfile"]).toEqual(
"python Dockerfile",
);
});

test("removeFile() removes a file from root", () => {
let fileTree: FileTree = {
const fileTree: FileTree = {
"main.tf": "terraform content",
images: {
"java.Dockerfile": "java dockerfile",
"python.Dockerfile": "python Dockerfile",
},
};
fileTree = removeFile("main.tf", fileTree);
const updatedFileTree = removeFile("main.tf", fileTree);
const expectedFileTree = {
images: {
"java.Dockerfile": "java dockerfile",
"python.Dockerfile": "python Dockerfile",
},
};
expect(expectedFileTree).toEqual(fileTree);
expect(updatedFileTree).toEqual(expectedFileTree);
// Verify the original FileTree was not modified.
expect(fileTree["main.tf"]).toEqual("terraform content");
});

test("moveFile() moves a file from in file tree", () => {
let fileTree: FileTree = {
const fileTree: FileTree = {
"main.tf": "terraform content",
images: {
"java.Dockerfile": "java dockerfile",
"python.Dockerfile": "python Dockerfile",
},
};
fileTree = moveFile(
const updatedFileTree = moveFile(
"images/java.Dockerfile",
"other/java.Dockerfile",
fileTree,
Expand All@@ -92,7 +100,9 @@ test("moveFile() moves a file from in file tree", () => {
"java.Dockerfile": "java dockerfile",
},
};
expect(fileTree).toEqual(expectedFileTree);
expect(updatedFileTree).toEqual(expectedFileTree);
// Verify the original FileTree was not modified.
expect(fileTree["main.tf"]).toEqual("terraform content");
});

test("existsFile() returns if there is or not a file", () => {
Expand Down
8 changes: 5 additions & 3 deletionssite/src/utils/filetree.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,7 +20,8 @@ export const createFile = (
throw new Error(pathError);
}

return set(fileTree, path.split("/"), value);
const updatedFileTree = structuredClone(fileTree);
return set(updatedFileTree, path.split("/"), value);
};

export const validatePath = (
Expand All@@ -43,15 +44,16 @@ export const updateFile = (
content: FileTree | string,
fileTree: FileTree,
): FileTree => {
return set(fileTree, path.split("/"), content);
const updatedFileTree = structuredClone(fileTree);
return set(updatedFileTree, path.split("/"), content);
};

export const existsFile = (path: string, fileTree: FileTree) => {
return has(fileTree, path.split("/"));
};

export const removeFile = (path: string, fileTree: FileTree) => {
const updatedFileTree ={ ...fileTree };
const updatedFileTree =structuredClone(fileTree);
unset(updatedFileTree, path.split("/"));
return updatedFileTree;
};
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp