Skip to content

Commit ed5ecf8

Browse files
committed
feat: add functionality to delete report files and update changelog
1 parent b1c0f21 commit ed5ecf8

File tree

5 files changed

+56
-3
lines changed

5 files changed

+56
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ All notable changes to the "magento-log-viewer" extension will be documented in
88

99
## Latest Release
1010

11+
### [1.12.0] - 2025-05-30
12+
13+
- feat: Add functionality to delete report files
14+
1115
### [1.11.0] - 2025-05-29
1216

1317
- feat: improved timestamp formatting for log entries
@@ -21,6 +25,7 @@ All notable changes to the "magento-log-viewer" extension will be documented in
2125
- fix: improve type safety in report handling functions
2226

2327
### [1.10.2] - 2025-05-28
28+
2429
- update: `readme.md` update
2530
- fix: update notification for better performance
2631
- fix: update configuration keys for Magento project selection to correctly save "Is this a Magento project" response

package.json

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "magento-log-viewer",
33
"displayName": "Magento Log Viewer",
44
"description": "A Visual Studio Code extension to view and manage Magento log files.",
5-
"version": "1.11.0",
5+
"version": "1.12.0",
66
"publisher": "MathiasElle",
77
"icon": "resources/logo.png",
88
"repository": {
@@ -52,6 +52,11 @@
5252
"title": "Delete Logfiles",
5353
"icon": "$(trash)"
5454
},
55+
{
56+
"command": "magento-log-viewer.clearAllReportFiles",
57+
"title": "Delete Report Files",
58+
"icon": "$(trash)"
59+
},
5560
{
5661
"command": "magento-log-viewer.refreshLogFiles",
5762
"title": "Refresh Log Files",
@@ -180,7 +185,14 @@
180185
{
181186
"id": "reportFiles",
182187
"name": "Report Files",
183-
"contextualTitle": "Magento Reports"
188+
"contextualTitle": "Magento Reports",
189+
"commands": [
190+
{
191+
"command": "magento-log-viewer.clearAllReportFiles",
192+
"title": "Delete Report Files",
193+
"group": "navigation"
194+
}
195+
]
184196
}
185197
]
186198
},
@@ -200,6 +212,11 @@
200212
"command": "magento-log-viewer.refreshReportFiles",
201213
"when": "view == reportFiles && magentoLogViewer.hasMagentoRoot",
202214
"group": "navigation"
215+
},
216+
{
217+
"command": "magento-log-viewer.clearAllReportFiles",
218+
"when": "view == reportFiles && magentoLogViewer.hasReportFiles",
219+
"group": "navigation"
203220
}
204221
],
205222
"view/item/context": [

src/extension.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as vscode from 'vscode';
2-
import { promptMagentoProjectSelection, showErrorMessage, activateExtension, isValidPath, deleteReportFile } from './helpers';
2+
import { promptMagentoProjectSelection, showErrorMessage, activateExtension, isValidPath, deleteReportFile, clearAllReportFiles } from './helpers';
33
import { LogItem, ReportViewerProvider } from './logViewer';
44
import { showUpdateNotification } from './updateNotifier';
55

@@ -37,7 +37,12 @@ export function activate(context: vscode.ExtensionContext): void {
3737
}
3838
});
3939

40+
const clearAllReportsCommand = vscode.commands.registerCommand('magento-log-viewer.clearAllReportFiles', () => {
41+
clearAllReportFiles(reportViewerProvider, magentoRoot);
42+
});
43+
4044
disposables.push(deleteCommand);
45+
disposables.push(clearAllReportsCommand);
4146
context.subscriptions.push(...disposables);
4247
}
4348
}

src/helpers.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,23 @@ export function deleteReportFile(filePath: string): void {
181181
}
182182
}
183183

184+
// Clears all report files in the Magento report directory.
185+
export function clearAllReportFiles(reportViewerProvider: ReportViewerProvider, magentoRoot: string): void {
186+
vscode.window.showWarningMessage('Are you sure you want to delete all report files?', 'Yes', 'No').then(selection => {
187+
if (selection === 'Yes') {
188+
const reportPath = path.join(magentoRoot, 'var', 'report');
189+
if (pathExists(reportPath)) {
190+
const files = fs.readdirSync(reportPath);
191+
files.forEach(file => fs.unlinkSync(path.join(reportPath, file)));
192+
reportViewerProvider.refresh();
193+
showInformationMessage('All report files have been cleared.');
194+
} else {
195+
showInformationMessage('No report files found to clear.');
196+
}
197+
}
198+
});
199+
}
200+
184201
// Cache for badge updates
185202
let lastUpdateTime = 0;
186203
const BADGE_UPDATE_THROTTLE = 1000; // Maximum one update per second

src/logViewer.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ export class ReportViewerProvider implements vscode.TreeDataProvider<LogItem>, v
257257
const workspaceUri = vscode.workspace.workspaceFolders?.[0]?.uri || null;
258258
const config = vscode.workspace.getConfiguration('magentoLogViewer', workspaceUri);
259259
this.groupByMessage = config.get<boolean>('groupByMessage', true);
260+
this.updateBadge();
260261
}
261262

262263
refresh(): void {
@@ -265,6 +266,14 @@ export class ReportViewerProvider implements vscode.TreeDataProvider<LogItem>, v
265266
return;
266267
}
267268
this._onDidChangeTreeData.fire();
269+
this.updateBadge();
270+
}
271+
272+
private updateBadge(): void {
273+
const reportPath = path.join(this.workspaceRoot, 'var', 'report');
274+
const reportFiles = this.getLogFilesWithoutUpdatingBadge(reportPath);
275+
const hasReports = reportFiles.length > 0;
276+
vscode.commands.executeCommand('setContext', 'magentoLogViewer.hasReportFiles', hasReports);
268277
}
269278

270279
getTreeItem(element: LogItem): vscode.TreeItem {

0 commit comments

Comments
 (0)