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

Merged
merged 20 commits into from
Feb 8, 2025
Merged

Fix changing subject weights #1810

merged 20 commits into from
Feb 8, 2025

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 5d2522f):

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

(expires Tue, 11 Feb 2025 21:40:18 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 4cb3ae61e1e018abfd9841fd3239f5b49ccc034b

@Jonas-Sander
Copy link
Collaborator Author

Jonas-Sander commented Feb 4, 2025

(Just a note for myself)

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?

@Jonas-Sander Jonas-Sander marked this pull request as ready for review February 8, 2025 18:39
Copy link
Member

@nilsreichardt nilsreichardt left a comment

Choose a reason for hiding this comment

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

Thanks for fixing ❤️ I added the bug back then 😭

@Jonas-Sander Jonas-Sander added this pull request to the merge queue Feb 8, 2025
Merged via the queue into main with commit b3239a5 Feb 8, 2025
38 checks passed
@Jonas-Sander Jonas-Sander deleted the test-subject-weights branch February 8, 2025 22:11
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
2 participants