From 09280166c736ae8315ac761cc03a3cbf94c036e1 Mon Sep 17 00:00:00 2001 From: Dean Date: Tue, 26 Sep 2023 15:15:30 +0100 Subject: [PATCH 1/2] Added comment updates to reflect new naming behaviour --- packages/builder/src/helpers/duplicate.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/builder/src/helpers/duplicate.js b/packages/builder/src/helpers/duplicate.js index e84a600138..1547fcd4d1 100644 --- a/packages/builder/src/helpers/duplicate.js +++ b/packages/builder/src/helpers/duplicate.js @@ -3,16 +3,17 @@ * e.g. * name all names result * ------ ----------- -------- - * ("foo") ["foo"] "foo (1)" - * ("foo") ["foo", "foo (1)"] "foo (2)" - * ("foo (1)") ["foo", "foo (1)"] "foo (2)" - * ("foo") ["foo", "foo (2)"] "foo (1)" + * ("foo") ["foo"] "foo 1" + * ("foo") ["foo", "foo 1"] "foo 2" + * ("foo 1") ["foo", "foo 1"] "foo 2" + * ("foo") ["foo", "foo 2"] "foo 1" * * Repl */ export const duplicateName = (name, allNames) => { - const baseName = name.split(" (")[0] - const isDuplicate = new RegExp(`${baseName}\\s\\((\\d+)\\)$`) + const duplicatePattern = new RegExp(`\\s(\\d+)$`) + const baseName = name.split(duplicatePattern)[0] + const isDuplicate = new RegExp(`${baseName}\\s(\\d+)$`) // get the sequence from matched names const sequence = [] @@ -28,7 +29,6 @@ export const duplicateName = (name, allNames) => { return false }) sequence.sort((a, b) => a - b) - // get the next number in the sequence let number if (sequence.length === 0) { @@ -46,5 +46,5 @@ export const duplicateName = (name, allNames) => { } } - return `${baseName} (${number})` + return `${baseName} ${number}` } From e73ddef040847f45df09a607e3e251562c56908b Mon Sep 17 00:00:00 2001 From: Dean Date: Tue, 26 Sep 2023 15:29:40 +0100 Subject: [PATCH 2/2] Updated UI tests --- .../builder/src/helpers/tests/duplicate.test.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/builder/src/helpers/tests/duplicate.test.js b/packages/builder/src/helpers/tests/duplicate.test.js index a571054e0c..400abed0aa 100644 --- a/packages/builder/src/helpers/tests/duplicate.test.js +++ b/packages/builder/src/helpers/tests/duplicate.test.js @@ -9,34 +9,34 @@ describe("duplicate", () => { const duplicate = duplicateName(name, names) - expect(duplicate).toBe("foo (1)") + expect(duplicate).toBe("foo 1") }) it("with multiple existing", async () => { - const names = ["foo", "foo (1)", "foo (2)"] + const names = ["foo", "foo 1", "foo 2"] const name = "foo" const duplicate = duplicateName(name, names) - expect(duplicate).toBe("foo (3)") + expect(duplicate).toBe("foo 3") }) it("with mixed multiple existing", async () => { - const names = ["foo", "foo (1)", "foo (2)", "bar", "bar (1)", "bar (2)"] + const names = ["foo", "foo 1", "foo 2", "bar", "bar 1", "bar 2"] const name = "foo" const duplicate = duplicateName(name, names) - expect(duplicate).toBe("foo (3)") + expect(duplicate).toBe("foo 3") }) it("with incomplete sequence", async () => { - const names = ["foo", "foo (2)", "foo (3)"] + const names = ["foo", "foo 2", "foo 3"] const name = "foo" const duplicate = duplicateName(name, names) - expect(duplicate).toBe("foo (1)") + expect(duplicate).toBe("foo 1") }) }) })