From 5636c7d0104d666dfc0068e55c265660118efc04 Mon Sep 17 00:00:00 2001 From: Sudha Eswaran Date: Wed, 6 Nov 2024 15:24:57 -0800 Subject: [PATCH] doc name updated --- src/utilities/database_utils.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/utilities/database_utils.tsx b/src/utilities/database_utils.tsx index 220e493..800ddda 100644 --- a/src/utilities/database_utils.tsx +++ b/src/utilities/database_utils.tsx @@ -342,10 +342,16 @@ export async function exportDocumentAsJSONObject( * @returns {string} The document name appended by the maximum index of a given document name. */ const findMaxDocNameIndex = (names: string[], docName: string): string => { - const baseDocName = docName.replace(/\(\d+\)$/, '') // Remove any existing index from the docName + const baseDocName = docName + .replace(/\(\d+\)$/, '') + .trim() + .replace(/\(\d+\)$/, '') + .trim() // Removing any existing index from the docName // Check if the docName (with or without index) already exists in the list - const nameExists = names.some(name => name.startsWith(baseDocName)) + const nameExists = names.some(name => { + return name === baseDocName || name.startsWith(baseDocName) + }) // If the name exists, find the next available index, otherwise return the name as is let count = 0 @@ -366,7 +372,7 @@ const findMaxDocNameIndex = (names: string[], docName: string): string => { }, 0) // Starts with 0 as the default if no matches are found } - return nameExists ? `${baseDocName} (${count + 1})` : docName + return nameExists ? `${baseDocName} (${count + 1})` : baseDocName } /**