overleaf/services/web/frontend/js/features/file-tree/util/is-name-unique-in-folder.js
Hugh O'Brien be51810be5 Merge pull request #3410 from overleaf/hb-validate-new-folder
React File Tree - Validate new folder names and renames

GitOrigin-RevId: f040eb08e2daefb3dfd639e18aaef95d7123d727
2020-12-10 03:04:38 +00:00

13 lines
436 B
JavaScript

import { findInTree } from '../util/find-in-tree'
export function isNameUniqueInFolder(tree, parentFolderId, name) {
if (tree._id !== parentFolderId) {
tree = findInTree(tree, parentFolderId).entity
}
if (tree.docs.some(entity => entity.name === name)) return false
if (tree.fileRefs.some(entity => entity.name === name)) return false
if (tree.folders.some(entity => entity.name === name)) return false
return true
}