Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix changing subject weights #1810

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft

Fix changing subject weights #1810

wants to merge 17 commits into from

Conversation

Jonas-Sander
Copy link
Collaborator

@Jonas-Sander Jonas-Sander commented Feb 4, 2025

Fixes #1803

@github-actions github-actions bot added testing feature: grades Users can add their grades to Sharezone. labels Feb 4, 2025
Copy link

github-actions bot commented Feb 4, 2025

Visit the preview URL for this PR (updated for commit 705ca92):

https://sharezone-test--pr1810-test-subject-weights-hdzacmrr.web.app

(expires Fri, 07 Feb 2025 16:36:34 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 4cb3ae61e1e018abfd9841fd3239f5b49ccc034b

@Jonas-Sander
Copy link
Collaborator Author

Inside the private grade logic a class called NonNegativeWeight is used.

class NonNegativeWeight extends Weight {
  factory NonNegativeWeight.fromWeight(Weight weight) =>
      NonNegativeWeight.factor(weight.asFactor);
  NonNegativeWeight.factor(num factor) : super.factor(factor) {
    if (factor < 0) {
      throw ArgumentError('Weight must be non-negative');
    }
  }
  NonNegativeWeight.percent(num percent) : super.percent(percent) {
    if (percent < 0) {
      throw ArgumentError('Weight must be non-negative');
    }
  }
}

Inside subject_settings_page_controller.dart we used the following code:

  late IMap<GradeTypeId, Weight> _weights;
  // ...
   SubjectSettingsPageController({
      required this.subRef,
      required this.gradesService,
    }) {
    //...
    _weights = _getTerm()!.gradeTypeWeightings;
    //...
  }

This threw the following error:

  type 'Weight' is not a subtype of type 'NonNegativeWeight' of 'value'
  package:fast_immutable_collections/src/imap/imap.dart 822:27                                       IMap.add
  package:sharezone/grades/pages/subject_settings_page/subject_settings_page_controller.dart 142:25  SubjectSettingsPageController.setGradeWeight

This is unexpected for the consuming code of the grades logic.
I need to create a fix so that the consuming code does not break.
Probably it should never see NonNegativeWeight - maybe make it a completely different class?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: grades Users can add their grades to Sharezone. testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding a new grade type to weights of a subject will delete the other weights and change final grade type
1 participant