From 38a143004f9b0cb07444a2fbe8abcd82bb4f0416 Mon Sep 17 00:00:00 2001 From: vipinpaul Date: Fri, 6 Sep 2024 11:46:58 +0530 Subject: [PATCH] Renaming the title to scope management and fixing the edge case --- .../ProjectManagement/ProjectManagement.js | 2 +- .../scope-management/ScopeManagement.jsx | 10 ++++---- .../utils/readProjectScope.js | 24 ++++++++++++------- .../src/components/Projects/ProjectRow.js | 2 +- .../CreateProject/AdvancedSettingsDropdown.js | 3 ++- 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/renderer/src/components/ProjectManagement/ProjectManagement.js b/renderer/src/components/ProjectManagement/ProjectManagement.js index 54d8cc5a..51cb6059 100644 --- a/renderer/src/components/ProjectManagement/ProjectManagement.js +++ b/renderer/src/components/ProjectManagement/ProjectManagement.js @@ -116,7 +116,7 @@ export default function ProjectMangement(props) {
- Project Management + Scope Management : {project?.name}
diff --git a/renderer/src/components/ProjectManagement/scope-management/ScopeManagement.jsx b/renderer/src/components/ProjectManagement/scope-management/ScopeManagement.jsx index 87961a39..a1768c31 100644 --- a/renderer/src/components/ProjectManagement/scope-management/ScopeManagement.jsx +++ b/renderer/src/components/ProjectManagement/scope-management/ScopeManagement.jsx @@ -189,7 +189,7 @@ function ScopeManagement({
- {backendScope && bookList?.slice(0, 39)?.map((book) => { + {bookList?.slice(0, 39)?.map((book) => { const isScope = book?.key?.toUpperCase() in currentScope; return ( ); })} @@ -207,7 +207,7 @@ function ScopeManagement({
- {backendScope && bookList?.slice(39)?.map((book) => { + {bookList?.slice(39)?.map((book) => { const isScope = book?.key?.toUpperCase() in currentScope; return ( ); })} @@ -270,7 +270,7 @@ function ScopeManagement({
{chapterList?.map(({ key, name }) => { const isInScope = selectedChaptersSet.has(key); - const disable = backendScope[bookId.toUpperCase()]?.includes(key); + const disable = backendScope && backendScope[bookId.toUpperCase()]?.includes(key); return ( handleChapterSelection(e, name)} diff --git a/renderer/src/components/ProjectManagement/utils/readProjectScope.js b/renderer/src/components/ProjectManagement/utils/readProjectScope.js index ca1a6e79..a86cce73 100644 --- a/renderer/src/components/ProjectManagement/utils/readProjectScope.js +++ b/renderer/src/components/ProjectManagement/utils/readProjectScope.js @@ -11,26 +11,32 @@ const getDirectories = (readdirSync, source) => readdirSync(source, { withFileTy .map((dirent) => dirent.name); // This function returns the Object of books & chapters which has atleast 1 audio file in it. -export const getScope = (project) => { +export const getScope = async (project) => { const path = require('path'); const scope = {}; const { readdirSync } = window.require('fs'); const fs = window.require('fs'); const list = getDirectories(readdirSync, project); - list.forEach((book) => { + + list.forEach(async (book) => { const chapters = getDirectories(readdirSync, path.join(project, book)); const chapterFilter = []; - chapters.forEach((chapter) => { + let flag = false; + await Promise.all(chapters.map(async (chapter) => { + // for (const chapter of chapters) { // Finding non empty directories/chapters - isDirEmpty(path.join(project, book, chapter), fs).then((value) => { + await isDirEmpty(path.join(project, book, chapter), fs).then((value) => { if (value === true) { - chapterFilter.push(chapter); + flag = true; + return chapterFilter.push(chapter); } }); - }); - scope[book] = chapterFilter; + })); + if (flag === true) { + scope[book] = chapterFilter; + } }); - return scope; +return scope; }; export const readProjectScope = async (projectName) => { try { @@ -48,7 +54,7 @@ export const readProjectScope = async (projectName) => { if (metadataFile) { logger.debug('readProjectScope.js', `read metadata file successfully - ${projectName}`); const project = path.join(file, projectName, 'audio', 'ingredients'); - const backendScope = getScope(project); + const backendScope = await getScope(project); const json = await JSON.parse(metadataFile); return { metadata: json, scope: backendScope }; } diff --git a/renderer/src/components/Projects/ProjectRow.js b/renderer/src/components/Projects/ProjectRow.js index 1dbbe727..5b86b8fd 100644 --- a/renderer/src/components/Projects/ProjectRow.js +++ b/renderer/src/components/Projects/ProjectRow.js @@ -245,7 +245,7 @@ const ProjectRow = ({ } group rounded-md items-center w-full px-2 py-2 text-sm ${project.isArchived ? 'hidden' : 'flex'}`} onClick={() => manageProject(project)} > - Manage Project + Scope Management )} diff --git a/renderer/src/components/ProjectsPage/CreateProject/AdvancedSettingsDropdown.js b/renderer/src/components/ProjectsPage/CreateProject/AdvancedSettingsDropdown.js index fe82639c..4d2a2f9f 100644 --- a/renderer/src/components/ProjectsPage/CreateProject/AdvancedSettingsDropdown.js +++ b/renderer/src/components/ProjectsPage/CreateProject/AdvancedSettingsDropdown.js @@ -260,7 +260,8 @@ export default function AdvancedSettingsDropdown({ call, project, projectType })
- + {projectType === 'Audio' + && NOTE: Choose the book and chapter from the SCOPE MANAGEMENT option on the project listing page.} {/*
*/}
{/*