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

Add support for year-long modules to module planner #2913

Open
wants to merge 28 commits into
base: master
Choose a base branch
from

Conversation

jeffsieu
Copy link

@jeffsieu jeffsieu commented Oct 17, 2020

Context

Resolves #1912

Implementation

Before adding

image

After adding

image

Year long modules are represented as modules in semester 0.

Adding year-long modules

Year-long modules are moved to the year-long module list whenever added from Semester 1 or 2. The year-long semester is hidden unless it is not empty, or being dragged over.

Dragging modules

  • Semester-long modules can only be dragged between regular semesters, exemptions and plan-to-take semesters.
  • Year-long modules can only be dragged between year-long semesters, exemptions and plan-to-take semesters.

Upon dragging, their type (year-long or semester-long) is stored as part of their draggableId, which is then used to update PlannerContainer.state.draggedModuleType. This prompts children PlannerYear components to display their year-long semester containers as drag targets.

Misc

  • "+ Add modules" section removed to avoid clutter. Also avoids the case where non year-long modules are added from the year-long "add modules" section
  • Adds type attribute to Droppable targets to disallow dragging of modules to the lists of the wrong module type.
  • Some test cases are modified to due to the extra "semester".

Represents year long modules as modules in semester
0. Whenever new modules are added, they are checked
for whether they are year long modules. If they are,
they are moved to the year long "semester".
@codecov
Copy link

codecov bot commented Oct 17, 2020

Codecov Report

Merging #2913 (4ce415e) into master (1cc25c8) will increase coverage by 0.16%.
The diff coverage is 43.10%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2913      +/-   ##
==========================================
+ Coverage   55.40%   55.57%   +0.16%     
==========================================
  Files         254      255       +1     
  Lines        5315     5357      +42     
  Branches     1226     1232       +6     
==========================================
+ Hits         2945     2977      +32     
- Misses       2370     2380      +10     
Impacted Files Coverage Δ
website/src/views/planner/AddModule.tsx 0.00% <0.00%> (ø)
...iews/planner/PlannerContainer/PlannerContainer.tsx 0.00% <0.00%> (ø)
website/src/views/planner/PlannerModule.tsx 0.00% <0.00%> (ø)
website/src/views/planner/PlannerModuleSelect.tsx 0.00% <0.00%> (ø)
website/src/views/planner/PlannerSemester.tsx 0.00% <0.00%> (ø)
website/src/views/planner/PlannerYear.tsx 0.00% <0.00%> (ø)
website/src/utils/planner.ts 69.09% <71.42%> (+0.34%) ⬆️
website/src/actions/planner.ts 85.18% <100.00%> (+1.85%) ⬆️
website/src/reducers/planner.ts 90.90% <100.00%> (+2.19%) ⬆️
website/src/selectors/planner.ts 91.56% <100.00%> (+0.10%) ⬆️
... and 18 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1cc25c8...4e02420. Read the comment docs.

@nusmods-deploy-bot
Copy link

nusmods-deploy-bot bot commented Oct 17, 2020

@jeffsieu jeffsieu marked this pull request as draft October 17, 2020 16:51
@jeffsieu jeffsieu marked this pull request as ready for review October 17, 2020 18:51
Copy link
Member

@ZhangYiJiang ZhangYiJiang left a comment

Choose a reason for hiding this comment

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

This looks great! I do think we might want to change the data structure from the scraper to allow us to do this more naturally. Let me know if you need help with that

website/src/utils/planner.ts Outdated Show resolved Hide resolved
website/src/views/planner/PlannerYear.tsx Show resolved Hide resolved
website/src/views/planner/PlannerYear.tsx Outdated Show resolved Hide resolved
website/src/views/planner/PlannerModule.tsx Outdated Show resolved Hide resolved
website/src/utils/modules.ts Outdated Show resolved Hide resolved
website/src/utils/planner.ts Outdated Show resolved Hide resolved
@jeffsieu jeffsieu requested a review from ZhangYiJiang October 24, 2020 08:02
@vercel
Copy link

vercel bot commented Dec 30, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployments, click below or on the icon next to each commit.

nusmods-website – ./website

🔍 Inspect: https://vercel.com/nusmodifications/nusmods-website/f9tn1djmd
✅ Preview: https://nusmods-website-git-fork-jeffsieu-planner-year-long-support.nusmodifications.vercel.app

nusmods-export – ./export

🔍 Inspect: https://vercel.com/nusmodifications/nusmods-export/ckvmvsxzp
✅ Preview: https://nusmods-export-git-fork-jeffsieu-planner-year-long-support.nusmodifications.vercel.app

@jeffsieu
Copy link
Author

@ZhangYiJiang How should I proceed with this PR? I really wish to see these changes be incorporated.

Copy link
Member

@ZhangYiJiang ZhangYiJiang left a comment

Choose a reason for hiding this comment

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

Sorry for not coming back to review this. This looks almost ready - just a few things

  • The reducers and actions that are now unused should be removed
  • Semester 0 should not be a valid global semester value, instead we can add something specifically for the planner
  • Drag and drop ID and module type should be strongly typed instead of just being strings

scrapers/nus-v2/src/tasks/CollateModules.ts Outdated Show resolved Hide resolved
website/src/utils/planner.ts Outdated Show resolved Hide resolved
website/src/views/planner/PlannerYear.tsx Show resolved Hide resolved
@@ -121,7 +121,7 @@ export function PlannerModuleSelectComponent({
} else if (inputValue != null) {
// Otherwise we use the input value - this allows the user to
// enter multiple
onSelect(inputValue);
onSelect(modules.find((module) => module.moduleCode === inputValue) ?? null);
Copy link
Member

Choose a reason for hiding this comment

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

This would break existing functionality where this field allows multiple module codes to be entered at once here

Tip: You can add multiple module at once, eg. copy from your transcript

The logic for validating module code should be on the parent component, not the child.

onSelect did have incorrect typing - ModuleCode should just be string, sorry about that

Copy link
Author

Choose a reason for hiding this comment

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

Actually, how does the adding multiple module codes part work? Since onSelect(inputValue) seems to call this:

onSelectModule = (input: ModuleCode | null) => {
if (input) {
this.props.onAddModule({
type: 'module',
moduleCode: input.trim(),
});
}
this.onCancel();
};

which seems to add only 1 module

Copy link
Member

Choose a reason for hiding this comment

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

It's in this function

onAddModule = (year: string, semester: Semester, module: AddModuleData) => {
. Again the types are wrong and the name is a bit misleading - moduleCode is matched to search for anything that looks like a module code

Copy link
Author

Choose a reason for hiding this comment

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

@ZhangYiJiang I changed the logic so that the module code extraction is done in PlannerModuleSelect, and PlannerContainer.onAddModule now only handles a single module at a time. i.e. AddModuleData's type has also been modified. This decision was made because I needed the yearLong property of every module. And PlannerModuleSelect does have a reference to modules from which I can extract ModuleCondensed instances out of.

website/src/views/planner/PlannerSemester.tsx Outdated Show resolved Hide resolved
PlannerModuleSemester represents a semester in
the module planner. PlannerSemesterModuleType represents
the module type accepted by a PlannerSemester
(semester or year long or both).
@vercel
Copy link

vercel bot commented Jan 1, 2021

@jeffsieu is attempting to deploy a commit to the NUSMods Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Member

@ZhangYiJiang ZhangYiJiang left a comment

Choose a reason for hiding this comment

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

Looking very close! Please revert some of the changes that are outdated, run the linter, and avoid using cast in favor of type guards, and this PR should be good to go

website/src/types/modules.ts Outdated Show resolved Hide resolved
website/src/selectors/planner.test.ts Outdated Show resolved Hide resolved
website/src/utils/planner.ts Outdated Show resolved Hide resolved
website/src/selectors/planner.ts Show resolved Hide resolved
Co-authored-by: Zhang Yi Jiang <[email protected]>
@jeffsieu
Copy link
Author

@ZhangYiJiang Most issues should be resolved. There's currently still a circular dependency between types/planner.ts and types/reducers.ts.... I'm not sure how to resolve this without shifting the type declarations over from a file to the other.

@yangshun
Copy link
Member

yangshun commented Jul 3, 2023

Guys, merge this plox

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.

Improve support for year long modules in module planner
3 participants