Skip to content

Commit

Permalink
chore: added max depth to model files recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
jeafreezy committed Nov 25, 2024
1 parent b2e440b commit a603e6d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const ModelFilesDialog: React.FC<TrainingAreaDialogProps> = ({
closeDialog={closeDialog}
label={APP_CONTENT.models.modelsDetailsCard.modelFilesDialog.dialogTitle}
>
<p className="text-dark text-body-2base px-2 mb-4">{APP_CONTENT.models.modelsDetailsCard.modelFilesDialog.dialogDescription}</p>
{isOpened && (
<DirectoryTree
trainingId={trainingId}
Expand Down
23 changes: 18 additions & 5 deletions frontend/src/features/models/components/directory-tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,28 +120,41 @@ const DirectoryTree: React.FC<DirectoryTreeProps> = ({

const fetchDirectoryRecursive = async (
currentDirectory: string = "",
currentDepth: number = 0,
maxDepth: number = 2
): Promise<any> => {
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,
size: dir[key]?.size || 0,
length: dir[key]?.len || 0,
},
};
}),
})
)
: [];
: [];

return {
dir: Object.assign({}, ...subdirectories),
Expand Down
1 change: 1 addition & 0 deletions frontend/src/utils/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit a603e6d

Please sign in to comment.