Skip to content

Commit e442c2f

Browse files
committed
feat: add functionality to retrieve report items from directory and handle empty states
1 parent fd5db01 commit e442c2f

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/helpers.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,33 @@ export function getIconForReport(filePath: string): vscode.ThemeIcon {
288288
return new vscode.ThemeIcon('file');
289289
}
290290
}
291+
292+
export function getReportItems(dir: string): LogItem[] {
293+
if (!pathExists(dir)) {
294+
return [];
295+
}
296+
297+
const items: LogItem[] = [];
298+
const files = fs.readdirSync(dir);
299+
300+
files.forEach(file => {
301+
const filePath = path.join(dir, file);
302+
if (fs.lstatSync(filePath).isDirectory()) {
303+
const subItems = getReportItems(filePath);
304+
if (subItems.length > 0) {
305+
items.push(...subItems);
306+
}
307+
} else if (fs.lstatSync(filePath).isFile()) {
308+
const title = parseReportTitle(filePath);
309+
const reportFile = new LogItem(title, vscode.TreeItemCollapsibleState.None, {
310+
command: 'magento-log-viewer.openFile',
311+
title: 'Open Report File',
312+
arguments: [filePath]
313+
});
314+
reportFile.iconPath = getIconForReport(filePath);
315+
items.push(reportFile);
316+
}
317+
});
318+
319+
return items;
320+
}

src/logViewer.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ export class ReportViewerProvider implements vscode.TreeDataProvider<LogItem>, v
230230
} else {
231231
const reportPath = path.join(this.workspaceRoot, 'var', 'report');
232232
const reportItems = this.getLogItems(reportPath, 'Reports');
233+
if (reportItems.length === 0) {
234+
return Promise.resolve([new LogItem('No report files found', vscode.TreeItemCollapsibleState.None)]);
235+
}
233236
return Promise.resolve(reportItems);
234237
}
235238
}

0 commit comments

Comments
 (0)