Add history view, rework to use history status, remove old classes
Signed-off-by: Sanjula Ganepola <sanjulagane@gmail.com>
This commit is contained in:
46
src/views/history/history.ts
Normal file
46
src/views/history/history.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { ThemeColor, ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode";
|
||||
import { History, HistoryStatus } from "../../act";
|
||||
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
|
||||
|
||||
export default class HistoryTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
|
||||
static contextValue = 'githubLocalActions.history';
|
||||
history: History;
|
||||
|
||||
constructor(history: History) {
|
||||
super(history.name, TreeItemCollapsibleState.None);
|
||||
this.history = history;
|
||||
|
||||
let totalDuration: string | undefined;
|
||||
if (history.start) {
|
||||
const start = new Date(history.start).getTime();
|
||||
const end = history.end ? new Date(history.end).getTime() : new Date().getTime();
|
||||
totalDuration = `${((end - start) / 1000).toFixed(0).toString()}s`;
|
||||
this.description = totalDuration;
|
||||
}
|
||||
|
||||
this.contextValue = `${HistoryTreeItem.contextValue}_${history.status}`;
|
||||
switch (history.status) {
|
||||
case HistoryStatus.Running:
|
||||
this.iconPath = new ThemeIcon('loading~spin');
|
||||
break;
|
||||
case HistoryStatus.Success:
|
||||
this.iconPath = new ThemeIcon('pass', new ThemeColor('GitHubLocalActions.green'));
|
||||
break;
|
||||
case HistoryStatus.Failed:
|
||||
this.iconPath = new ThemeIcon('error', new ThemeColor('GitHubLocalActions.red'));
|
||||
break;
|
||||
case HistoryStatus.Cancelled:
|
||||
this.iconPath = new ThemeIcon('circle-slash', new ThemeColor('GitHubLocalActions.yellow'));
|
||||
break;
|
||||
}
|
||||
this.tooltip = `Name: ${history.name}\n` +
|
||||
`Status: ${history.status}\n` +
|
||||
`Started: ${history.start ? history.start : 'N/A'}\n` +
|
||||
`Ended: ${history.end ? history.end : 'N/A'}\n` +
|
||||
(totalDuration ? `Total Duration: ${totalDuration}\n` : ``);
|
||||
}
|
||||
|
||||
async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user