From a603e6d750c1fea3157d725ab31818ef9c5ae1ba Mon Sep 17 00:00:00 2001 From: jeafreezy Date: Mon, 25 Nov 2024 11:19:58 +0100 Subject: [PATCH] chore: added max depth to model files recursion --- .../components/dialogs/model-files-dialog.tsx | 1 + .../models/components/directory-tree.tsx | 23 +++++++++++++++---- frontend/src/utils/content.ts | 1 + 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/frontend/src/features/models/components/dialogs/model-files-dialog.tsx b/frontend/src/features/models/components/dialogs/model-files-dialog.tsx index 65c4277c..4a2de107 100644 --- a/frontend/src/features/models/components/dialogs/model-files-dialog.tsx +++ b/frontend/src/features/models/components/dialogs/model-files-dialog.tsx @@ -20,6 +20,7 @@ const ModelFilesDialog: React.FC = ({ closeDialog={closeDialog} label={APP_CONTENT.models.modelsDetailsCard.modelFilesDialog.dialogTitle} > +

{APP_CONTENT.models.modelsDetailsCard.modelFilesDialog.dialogDescription}

{isOpened && ( = ({ const fetchDirectoryRecursive = async ( currentDirectory: string = "", + currentDepth: number = 0, + maxDepth: number = 2 ): Promise => { + if (currentDepth >= maxDepth) { + + return {}; + } + const data = await fetchDirectoryData(currentDirectory); if (!data) return {}; const { dir, file } = data; - const subdirectories = dir - ? await Promise.all( + + const subdirectories = + dir && currentDepth < maxDepth + ? await Promise.all( Object.keys(dir).map(async (key: string) => { const fullPath = currentDirectory ? `${currentDirectory}/${key}` : key; - const subDirData = await fetchDirectoryRecursive(fullPath); + const subDirData = await fetchDirectoryRecursive( + fullPath, + currentDepth + 1, + maxDepth + ); return { [key]: { ...subDirData, @@ -139,9 +152,9 @@ const DirectoryTree: React.FC = ({ length: dir[key]?.len || 0, }, }; - }), + }) ) - : []; + : []; return { dir: Object.assign({}, ...subdirectories), diff --git a/frontend/src/utils/content.ts b/frontend/src/utils/content.ts index 40444821..e179c44e 100644 --- a/frontend/src/utils/content.ts +++ b/frontend/src/utils/content.ts @@ -506,6 +506,7 @@ export const APP_CONTENT = { modelFilesDialog: { rootDirectory: "Root Directory", dialogTitle: "Model Files", + dialogDescription: "Click to download each file...", error: "Error loading directories.", }, trainingInfoDialog: {