Skip to content

Commit

Permalink
doc name updated
Browse files Browse the repository at this point in the history
  • Loading branch information
sudhacheran committed Nov 6, 2024
1 parent ceadcff commit 5636c7d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/utilities/database_utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

/**
Expand Down

0 comments on commit 5636c7d

Please sign in to comment.