-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add query activity log * Revert the log to show newest first * Remove copy notifications and add data storage * Change emojies to svg icons * Remove the latency emoji
- Loading branch information
1 parent
73f515f
commit da3f5a4
Showing
6 changed files
with
121 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import * as vscode from 'vscode'; | ||
import * as path from 'path'; | ||
|
||
export default class ActivityLogTreeProvider implements vscode.TreeDataProvider<ActivityLogNode> { | ||
|
||
private _onDidChangeTreeData: vscode.EventEmitter<ActivityLogNode | undefined | null | void> = new vscode.EventEmitter<ActivityLogNode | undefined | null | void>(); | ||
readonly onDidChangeTreeData: vscode.Event<ActivityLogNode | undefined | null | void> = this._onDidChangeTreeData.event; | ||
|
||
private logs: ActivityLog[] = []; | ||
|
||
constructor(private context: vscode.ExtensionContext) { | ||
this.logs = this.context.globalState.get('activityLogs') || []; | ||
} | ||
|
||
addLog(log: ActivityLog) { | ||
this.logs.push(log); | ||
|
||
// Remove the oldest log if we have more than 100 | ||
if (this.logs.length > 100) { | ||
this.logs.shift(); | ||
} | ||
|
||
this.context.globalState.update('activityLogs', this.logs); | ||
this._onDidChangeTreeData.fire(); | ||
} | ||
|
||
getTreeItem(element: ActivityLogNode): vscode.TreeItem { | ||
return element; | ||
} | ||
|
||
getChildren(element?: ActivityLogNode): Thenable<ActivityLogNode[]> { | ||
if (!element) { | ||
// Revert the logs to show the newest ones at the top | ||
return Promise.resolve(this.logs.slice().reverse().map(log => new ActivityLogNode(log))); | ||
} | ||
return Promise.resolve([]); | ||
} | ||
} | ||
|
||
interface ActivityLog { | ||
status: "success" | "failure"; | ||
latency: number; | ||
sql: string; | ||
} | ||
|
||
class ActivityLogItem extends vscode.TreeItem { | ||
constructor(public readonly log: ActivityLog) { | ||
// Shorten the displayed query if it's too long | ||
const shortSQL = log.sql.length > 50 ? log.sql.substring(0, 50) + "..." : log.sql; | ||
|
||
super(shortSQL, vscode.TreeItemCollapsibleState.None); | ||
|
||
// Set iconPath based on the status | ||
const iconName = log.status === "success" ? "success_icon.svg" : "error_icon.svg"; | ||
this.iconPath = vscode.Uri.file(path.join(__dirname, '..', 'resources', iconName)); | ||
|
||
// Set the description to the query latency | ||
this.description = `${log.latency}ms`; | ||
|
||
this.tooltip = `${log.sql} | Latency: ${log.latency}ms`; | ||
this.contextValue = 'activityLogItem'; | ||
|
||
// Copy SQL command to clipboard | ||
this.command = { | ||
command: 'extension.copySQL', | ||
title: 'Copy SQL', | ||
arguments: [log.sql] | ||
}; | ||
} | ||
} | ||
|
||
class ActivityLogNode extends ActivityLogItem {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import AuthProvider from "./auth"; | ||
import ResultsProvider from "./results"; | ||
import DatabaseTreeProvider from "./schema"; | ||
import ActivityLogTreeProvider from "./activity"; | ||
|
||
export { | ||
AuthProvider, | ||
ResultsProvider, | ||
DatabaseTreeProvider, | ||
}; | ||
ActivityLogTreeProvider, | ||
}; |