Skip to content

fix: Add fetching and caching of unknown grade weight and set TeltMee…#93

Open
Tureluurtje wants to merge 1 commit intoQkeleQ10:mainfrom
Tureluurtje:fix-unknown-grade-weight
Open

fix: Add fetching and caching of unknown grade weight and set TeltMee…#93
Tureluurtje wants to merge 1 commit intoQkeleQ10:mainfrom
Tureluurtje:fix-unknown-grade-weight

Conversation

@Tureluurtje
Copy link
Copy Markdown

… to false for grades with weight being 0

Copilot AI review requested due to automatic review settings March 23, 2026 17:31
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the grade statistics pane to ensure grades with column weight 0 are excluded (TeltMee = false), including cases where the weight is initially unknown by fetching and caching grade-column info from the API.

Changes:

  • Added a year getter plus in-memory caching for gradesColumnInfo lookups.
  • Introduced #applyColumnWeightToGrade() to fetch missing column weights and set TeltMee = false when weight is 0.
  • Integrated the new weight application step into toggleGrade() (plus substantial formatting changes).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +50 to +56
const existingWeight = Number(grade.CijferKolom.Weging);
if (!Number.isNaN(existingWeight) && existingWeight === 0) {
grade.TeltMee = false;
return;
}

if (grade.CijferKolom.Weging != null) return;
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Number(null) evaluates to 0, so when CijferKolom.Weging is null (unknown) this branch will incorrectly treat it as weight 0 and set grade.TeltMee = false. Guard the “weight is 0” logic with a non-null/undefined check (e.g., only consider it 0 when Weging != null), and apply the same guard after merging gradeColumnInfo to avoid null being interpreted as 0 there too.

Copilot uses AI. Check for mistakes.
Comment on lines +411 to 421
await this.#applyColumnWeightToGrade(grade);

if (
(this.selectedGrades.some((g) => g.id === grade.CijferId) ||
force === false) &&
force !== true
) {
this.selectedGrades = this.selectedGrades.filter(
(g) => g.id !== grade.CijferId,
);
} else {
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toggleGrade awaits #applyColumnWeightToGrade before determining whether this call is actually removing an already-selected grade. This can add unnecessary latency (and potentially network calls) to deselection/removal flows; consider checking the remove-condition first and only fetching column info when the grade is being added/validated.

Suggested change
await this.#applyColumnWeightToGrade(grade);
if (
(this.selectedGrades.some((g) => g.id === grade.CijferId) ||
force === false) &&
force !== true
) {
this.selectedGrades = this.selectedGrades.filter(
(g) => g.id !== grade.CijferId,
);
} else {
const isSelected = this.selectedGrades.some(
(g) => g.id === grade.CijferId,
);
const shouldRemove =
(isSelected || force === false) && force !== true;
if (shouldRemove) {
this.selectedGrades = this.selectedGrades.filter(
(g) => g.id !== grade.CijferId,
);
} else {
await this.#applyColumnWeightToGrade(grade);

Copilot uses AI. Check for mistakes.
Comment on lines +66 to +74
if (!this.#gradeColumnInfoCache.has(cacheKey)) {
this.#gradeColumnInfoCache.set(
cacheKey,
magisterApi.gradesColumnInfo(year, columnId).catch(() => {
this.#gradeColumnInfoFailed.add(cacheKey);
return null;
}),
);
}
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because #applyColumnWeightToGrade can call magisterApi.gradesColumnInfo, and toggleGrade() is invoked for every grade during the pane’s first redraw() initialization, opening this pane may now result in many column-info requests (one per unique column with unknown weight). This can be slow and may risk API rate limiting; consider adding throttling/backoff (see the delays used when fetching column info in grades/backup.js) or deferring these lookups until the user explicitly selects grades.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants