From 93215ab434fa538b7472be7c7884bd8a0d407230 Mon Sep 17 00:00:00 2001 From: Heliozoa Date: Thu, 7 Nov 2024 11:46:08 +0200 Subject: [PATCH] Add button to go to course details in open exercise warning --- shared/lib.ts | 2 +- src/actions/webview.ts | 1 - src/actions/workspace.ts | 19 ++++++++++++++++--- src/init/commands.ts | 1 - src/panels/TmcPanel.ts | 3 +-- webview-ui/src/components/Card.svelte | 2 ++ webview-ui/src/panels/CourseDetails.svelte | 8 +++++++- 7 files changed, 27 insertions(+), 9 deletions(-) diff --git a/shared/lib.ts b/shared/lib.ts index 30a5b80c..0c1a32b7 100644 --- a/shared/lib.ts +++ b/shared/lib.ts @@ -78,7 +78,7 @@ export type CourseDetailsPanel = { exerciseGroups?: Array; updateableExercises?: Array; disabled?: boolean; - exerciseStatuses: Record; + exerciseStatuses?: Record; }; export type SelectOrganizationPanel = { diff --git a/src/actions/webview.ts b/src/actions/webview.ts index 5a3f64c0..4a1a9897 100644 --- a/src/actions/webview.ts +++ b/src/actions/webview.ts @@ -156,7 +156,6 @@ export async function displayLocalCourseDetails( type: "CourseDetails", id: randomPanelId(), courseId: course.id, - exerciseStatuses: {}, }; TmcPanel.renderMain(context.extensionUri, context, actionContext, panel); diff --git a/src/actions/workspace.ts b/src/actions/workspace.ts index 09e2e496..f009b7a4 100644 --- a/src/actions/workspace.ts +++ b/src/actions/workspace.ts @@ -4,11 +4,13 @@ * ------------------------------------------------------------------------------------------------- */ +import * as vscode from "vscode"; + import { compact } from "lodash"; import { Ok, Result } from "ts-results"; import { ExerciseStatus } from "../api/workspaceManager"; -import { TmcPanel } from "../panels/TmcPanel"; -import { ExtensionToWebview } from "../shared/shared"; +import { randomPanelId, TmcPanel } from "../panels/TmcPanel"; +import { CourseDetailsPanel, ExtensionToWebview } from "../shared/shared"; import { Logger } from "../utilities"; import * as systeminformation from "systeminformation"; import { ActionContext } from "./types"; @@ -18,6 +20,7 @@ import { ActionContext } from "./types"; * @param exerciseIdsToOpen Array of exercise IDs */ export async function openExercises( + context: vscode.ExtensionContext, actionContext: ActionContext, exerciseIdsToOpen: number[], courseName: string, @@ -52,7 +55,6 @@ export async function openExercises( // check open exercise count and warn if it's too high const under8GbRam = (await systeminformation.mem()).available < 9_000_000_000; - dialog.warningNotification(`${(await systeminformation.mem()).available}`); const weakThreshold = 50; const strongThreshold = 100; const warningThreshold = under8GbRam ? weakThreshold : strongThreshold; @@ -62,6 +64,17 @@ export async function openExercises( if (openExercises.length > warningThreshold) { dialog.warningNotification( `You have over ${warningThreshold} exercises open, which may cause performance issues. You can close completed exercises from the TMC extension menu in the sidebar.`, + [ + "Open course details", + (): void => { + const panel: CourseDetailsPanel = { + id: randomPanelId(), + type: "CourseDetails", + courseId: course.id, + }; + TmcPanel.renderMain(context.extensionUri, context, actionContext, panel); + }, + ], ); } diff --git a/src/init/commands.ts b/src/init/commands.ts index 1a1f8ee0..55cb23b8 100644 --- a/src/init/commands.ts +++ b/src/init/commands.ts @@ -74,7 +74,6 @@ export function registerCommands( id: randomPanelId(), type: "CourseDetails", courseId, - exerciseStatuses: {}, }); } }), diff --git a/src/panels/TmcPanel.ts b/src/panels/TmcPanel.ts index 5d5c74db..e5d8dd02 100644 --- a/src/panels/TmcPanel.ts +++ b/src/panels/TmcPanel.ts @@ -497,7 +497,6 @@ export class TmcPanel { id: randomPanelId(), type: "CourseDetails", courseId: message.courseId, - exerciseStatuses: {}, }, webview, ); @@ -616,6 +615,7 @@ export class TmcPanel { // now, actually open the exercises const result = await openExercises( + extensionContext, actionContext, message.ids, message.courseName, @@ -655,7 +655,6 @@ export class TmcPanel { id: randomPanelId(), type: "CourseDetails", courseId: courseId, - exerciseStatuses: {}, }, webview, ); diff --git a/webview-ui/src/components/Card.svelte b/webview-ui/src/components/Card.svelte index 289d9076..ab4e20e1 100644 --- a/webview-ui/src/components/Card.svelte +++ b/webview-ui/src/components/Card.svelte @@ -1,3 +1,5 @@ + +
diff --git a/webview-ui/src/panels/CourseDetails.svelte b/webview-ui/src/panels/CourseDetails.svelte index 570cab0a..25d5b0f0 100644 --- a/webview-ui/src/panels/CourseDetails.svelte +++ b/webview-ui/src/panels/CourseDetails.svelte @@ -43,6 +43,9 @@ break; } case "exerciseStatusChange": { + if (panel.exerciseStatuses === undefined) { + panel.exerciseStatuses = {}; + } panel.exerciseStatuses[message.exerciseId] = message.status; savePanelState(panel); break; @@ -58,6 +61,9 @@ break; } case "exerciseStatusChange": { + if (panel.exerciseStatuses === undefined) { + panel.exerciseStatuses = {}; + } panel.exerciseStatuses[message.exerciseId] = message.status; savePanelState(panel); break; @@ -237,7 +243,7 @@
panel.course && downloadExercises(panel.course, exercises)}