Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
fix: Fix page path check using full path with folders during duplication (#2958)
Oleg Isonen2c5f8029d2a5
diff --git a/apps/builder/app/builder/features/sidebar-left/panels/pages/page-utils.test.ts b/apps/builder/app/builder/features/sidebar-left/panels/pages/page-utils.test.tsindex 5a56e2d9db..775ff99eb5 100644--- a/apps/builder/app/builder/features/sidebar-left/panels/pages/page-utils.test.ts+++ b/apps/builder/app/builder/features/sidebar-left/panels/pages/page-utils.test.ts@@ -531,7 +531,7 @@ describe("duplicate page", () => {expect($pages.get()?.pages[0]).toEqual({id: expect.not.stringMatching("pageId"),name: "My Name (1)",- path: "/copy-1",+ path: "/1",title: `"My Title"`,meta: {},rootInstanceId: expect.not.stringMatching("body"),@@ -554,7 +554,7 @@ describe("duplicate page", () => {);});- test("non-home page preserving old path with prefix", () => {+ test("non-home page preserving old path and name with suffix", () => {$instances.set(toMap([{ type: "instance", id: "body", component: "Body", children: [] }]));@@ -570,7 +570,7 @@ describe("duplicate page", () => {pages: [{id: "pageId",- name: "My Name",+ name: "My Name (1)",path: "/my-path",title: `"My Title"`,meta: {},@@ -580,10 +580,53 @@ describe("duplicate page", () => {folders: [],});duplicatePage("pageId");+ expect($pages.get()?.pages[1]).toEqual({+ id: expect.not.stringMatching("pageId"),+ name: "My Name (2)",+ path: "/my-path-1",+ title: `"My Title"`,+ meta: {},+ rootInstanceId: expect.not.stringMatching("body"),+ });+ });++ test("check full page path when duplicating inside a folder", () => {+ $instances.set(+ toMap([{ type: "instance", id: "body", component: "Body", children: [] }])+ );+ $pages.set({+ homePage: {+ id: "homeId",+ name: "Home",+ path: "/",+ title: `"Home"`,+ meta: {},+ rootInstanceId: "home",+ },+ pages: [+ {+ id: "pageId",+ name: "My Name",+ path: "/my-path",+ title: `"My Title"`,+ meta: {},+ rootInstanceId: "body",+ },+ ],+ folders: [+ {+ id: "folderId",+ name: "Folder",+ slug: "folder",+ children: ["pageId"],+ },+ ],+ });+ duplicatePage("pageId");expect($pages.get()?.pages[1]).toEqual({id: expect.not.stringMatching("pageId"),name: "My Name (1)",- path: "/copy-1/my-path",+ path: "/my-path-1",title: `"My Title"`,meta: {},rootInstanceId: expect.not.stringMatching("body"),@@ -634,7 +677,7 @@ describe("duplicate page", () => {expect($pages.get()?.pages[0]).toEqual({id: expect.not.stringMatching("pageId"),name: "My Name (1)",- path: "/copy-1",+ path: "/1",title: `"Title: " + ${newVariableName}`,meta: {description: `"Description: " + ${newVariableName}`,@@ -684,7 +727,7 @@ describe("duplicate page", () => {expect($pages.get()?.pages[0]).toEqual({id: expect.not.stringMatching("pageId"),name: "My Name (1)",- path: "/copy-1",+ path: "/1",title: `"My Title"`,meta: {},rootInstanceId: expect.not.stringMatching("body"),diff --git a/apps/builder/app/builder/features/sidebar-left/panels/pages/page-utils.ts b/apps/builder/app/builder/features/sidebar-left/panels/pages/page-utils.tsindex e1f4fbf18b..1dede277aa 100644--- a/apps/builder/app/builder/features/sidebar-left/panels/pages/page-utils.ts+++ b/apps/builder/app/builder/features/sidebar-left/panels/pages/page-utils.ts@@ -335,22 +335,18 @@ export const $pageRootScope = computed(});-const deduplicatePath = (pages: undefined | Pages, path: string) => {- if (pages === undefined) {- return path;- }- const matchedPage = findPageByIdOrPath(path, pages);+const deduplicatePath = (pages: Pages, page: Page) => {+ const fullPath = getPagePath(page.id, pages);+ const matchedPage = findPageByIdOrPath(fullPath, pages);+if (matchedPage === undefined) {- return path;- }- if (path === "/") {- path = "";+ return page.path;}let counter = 1;- while (findPageByIdOrPath(`/copy-${counter}${path}`, pages) !== undefined) {+ while (findPageByIdOrPath(`${fullPath}-${counter}`, pages) !== undefined) {counter += 1;}- return `/copy-${counter}${path}`;+ return page.path === "/" ? `/${counter}` : `${page.path}-${counter}`;};const replaceDataSources = (@@ -409,7 +405,7 @@ export const duplicatePage = (pageId: Page["id"]) => {rootInstanceId: newRootInstanceId,pathParamsDataSourceId: newPathParamsDataSourceId,name: newName,- path: deduplicatePath(pages, page.path),+ path: deduplicatePath(pages, page),title: replaceDataSources(page.title, newDataSourceIds),meta: {...page.meta,