Skip to content

Commit 54570ee

Browse files
Pablo Carmonastarpit
authored andcommitted
add job runs to tray menu under profile section
1 parent e682a4c commit 54570ee

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

plugins/plugin-codeflare/src/tray/menus/profiles.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { CreateWindowFunction } from "@kui-shell/core"
2020

2121
import windowOptions from "../window"
2222
import { profileIcon, bootIcon, shutDownIcon } from "../icons"
23+
import { RUNS_ERROR, submenuForRuns, readRunsDir } from "./runs"
2324

2425
/** Handler for booting up a profile */
2526
async function boot(profile: string, createWindow: CreateWindowFunction) {
@@ -40,20 +41,32 @@ async function shutdown(profile: string, createWindow: CreateWindowFunction) {
4041
/** @return a menu for the given profile */
4142
function submenuForOneProfile(
4243
state: Choices.ChoiceState,
43-
createWindow: CreateWindowFunction
44+
createWindow: CreateWindowFunction,
45+
runs: string[]
4446
): MenuItemConstructorOptions {
47+
const isRunsSubMenu =
48+
runs.length && runs[0] !== RUNS_ERROR
49+
? { label: "Runs", submenu: submenuForRuns(createWindow, runs) }
50+
: { label: RUNS_ERROR }
4551
return {
4652
label: state.profile.name,
4753
submenu: [
4854
{ label: "Boot", icon: bootIcon, click: () => boot(state.profile.name, createWindow) },
4955
{ label: "Shutdown", icon: shutDownIcon, click: () => shutdown(state.profile.name, createWindow) },
56+
{ type: "separator" },
57+
isRunsSubMenu,
5058
],
5159
}
5260
}
5361

5462
/** @return a menu for all profiles */
5563
export default async function profilesMenu(createWindow: CreateWindowFunction): Promise<MenuItemConstructorOptions> {
5664
const profiles = await Profiles.list({})
65+
const runs = await readRunsDir()
5766

58-
return { label: "Profiles", icon: profileIcon, submenu: profiles.map((_) => submenuForOneProfile(_, createWindow)) }
67+
return {
68+
label: "Profiles",
69+
icon: profileIcon,
70+
submenu: profiles.map((_) => submenuForOneProfile(_, createWindow, runs)),
71+
}
5972
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { MenuItemConstructorOptions } from "electron"
2+
import { Profiles } from "madwizard"
3+
import { CreateWindowFunction } from "@kui-shell/core"
4+
import { readdir } from "fs/promises"
5+
import { join } from "path"
6+
7+
import windowOptions from "../window"
8+
9+
export const RUNS_ERROR = "No runs found"
10+
11+
/** @return a new Window with a dashboard of the selected job run */
12+
function openRun(runId: string, createWindow: CreateWindowFunction) {
13+
const runsDir = Profiles.guidebookJobDataPath({})
14+
createWindow(
15+
["codeflare", "dashboard", join(runsDir, runId)],
16+
windowOptions({ title: "CodeFlare Dashboard: " + runId })
17+
)
18+
}
19+
20+
/** @return files of the directory of job runs for a given profile */
21+
export async function readRunsDir(): Promise<string[]> {
22+
try {
23+
const runsDir = Profiles.guidebookJobDataPath({})
24+
return await readdir(runsDir)
25+
} catch (err) {
26+
return [RUNS_ERROR]
27+
}
28+
}
29+
30+
/** @return a menu for all runs of a profile */
31+
export function submenuForRuns(createWindow: CreateWindowFunction, runs: string[]): MenuItemConstructorOptions[] {
32+
return runs.map((run) => ({ label: run, click: () => openRun(run, createWindow) }))
33+
}

0 commit comments

Comments
 (0)