mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
24bd557485
Remove rootFolder from EditorContext GitOrigin-RevId: 827b046046265ad2418eb91d5a69eae02aa8b5a4
37 lines
765 B
JavaScript
37 lines
765 B
JavaScript
export function countFiles(fileTreeData) {
|
|
if (!fileTreeData) {
|
|
return 0
|
|
}
|
|
|
|
const files = filesInFolder(fileTreeData)
|
|
|
|
// count all the non-deleted entities
|
|
const value = files.filter(item => !item.deleted).length
|
|
|
|
const limit = window.ExposedSettings.maxEntitiesPerProject
|
|
const status = fileCountStatus(value, limit, Math.ceil(limit / 20))
|
|
|
|
return { value, status, limit }
|
|
}
|
|
|
|
function filesInFolder({ docs, folders, fileRefs }) {
|
|
const files = [...docs, ...fileRefs]
|
|
|
|
for (const folder of folders) {
|
|
files.push(...filesInFolder(folder))
|
|
}
|
|
|
|
return files
|
|
}
|
|
|
|
function fileCountStatus(value, limit, range) {
|
|
if (value >= limit) {
|
|
return 'error'
|
|
}
|
|
|
|
if (value >= limit - range) {
|
|
return 'warning'
|
|
}
|
|
|
|
return 'success'
|
|
}
|