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

790 allow plans with no concentration #803

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
932274f
v1
liamcarvajal Jan 28, 2025
f7abdce
undecided validation works and is a selectable major TODO: make red t…
23langloisj Jan 30, 2025
ca8f727
added massive ahh red warning signaling you have an undecided concent…
23langloisj Jan 31, 2025
f8508b0
editing plan also has undecided as an option now
23langloisj Jan 31, 2025
9b02be2
bcrypt version update
KobeZ123 Jan 31, 2025
08092ed
good colors for missing concentration dropdown warning
23langloisj Jan 31, 2025
e9f3394
removed console logs added comments
23langloisj Feb 2, 2025
febd2cd
missing concentration message appears conditionally and abstracted co…
23langloisj Feb 2, 2025
740892d
Merge pull request #802 from sandboxnu/bcrypt-update
KobeZ123 Feb 2, 2025
8cd6018
addressing comments
liamcarvajal Feb 2, 2025
388de8e
remove comment
liamcarvajal Feb 2, 2025
8ac9630
another constant
liamcarvajal Feb 2, 2025
499a68d
more constants
liamcarvajal Feb 2, 2025
f6e43d3
added constants for undecided strings
23langloisj Feb 4, 2025
99012a6
removed undecided string everywhere and replaced with cosntants
23langloisj Feb 4, 2025
e2fe2e3
i think constants are set properly now
23langloisj Feb 5, 2025
d8f0363
fix
23langloisj Feb 5, 2025
f56972f
coop in last year, not just year 4
liamcarvajal Feb 6, 2025
4eae90f
fix
liamcarvajal Feb 6, 2025
365cee7
Merge pull request #799 from sandboxnu/lc/791
liamcarvajal Feb 9, 2025
5b7febb
changed undecided to undecided_string for clarity
23langloisj Feb 17, 2025
25176b9
Range update (fixed infinite loading) (#805)
denniwang Feb 18, 2025
00df6a3
undecided validation works and is a selectable major TODO: make red t…
23langloisj Jan 30, 2025
381cc90
added massive ahh red warning signaling you have an undecided concent…
23langloisj Jan 31, 2025
7c51eb0
editing plan also has undecided as an option now
23langloisj Jan 31, 2025
aa76a95
good colors for missing concentration dropdown warning
23langloisj Jan 31, 2025
60ba70b
removed console logs added comments
23langloisj Feb 2, 2025
8c59fc0
missing concentration message appears conditionally and abstracted co…
23langloisj Feb 2, 2025
ac10bcc
resolving merge conflict
23langloisj Feb 18, 2025
8afd28e
removed undecided string everywhere and replaced with cosntants
23langloisj Feb 4, 2025
4152b28
i think constants are set properly now
23langloisj Feb 5, 2025
f335de4
fix
23langloisj Feb 5, 2025
d318858
changed undecided to undecided_string for clarity
23langloisj Feb 17, 2025
e195a16
resolve merge plz
23langloisj Feb 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@nestjs/passport": "^8.1.0",
"@nestjs/platform-express": "^9.0.5",
"@nestjs/typeorm": "^8.0.2",
"bcrypt": "5.0.0",
"bcrypt": "5.1.1",
"class-transformer": "^0.5.1",
"class-validator": "^0.13.2",
"cookie-parser": "^1.4.6",
Expand Down
2 changes: 2 additions & 0 deletions packages/api/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
*/
export const COOKIE_DOMAIN =
process.env.NODE_ENV === "production" ? "graduatenu.com" : "localhost";

export const UNDECIDED = "Undecided";
9 changes: 4 additions & 5 deletions packages/api/src/major/major.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
SupportedMajorsForYear,
SupportedMajors,
SupportedConcentrations,
UNDECIDED_STRING,
} from "@graduate/common";
import { Injectable, Logger } from "@nestjs/common";
import { formatServiceCtx } from "../utils";
Expand Down Expand Up @@ -120,9 +121,9 @@ export class MajorService {
return false;
}

const isValidConcentrationName = concentrations.some(
(c) => c === concentrationName
);
const isValidConcentrationName =
concentrations.includes(concentrationName) ||
concentrationName === UNDECIDED_STRING;

if (!isValidConcentrationName) {
this.logger.debug(
Expand All @@ -134,10 +135,8 @@ export class MajorService {
},
MajorService.formatMajorServiceCtx("isValidConcentrationForMajor")
);

return false;
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@
],
"concentrations": {
"minOptions": 1,

"concentrationOptions": [
{
"type": "SECTION",
Expand Down
2 changes: 2 additions & 0 deletions packages/common/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ export const wrongPasswordError = "Incorrect Password";
export const forgotPasswordTokenExpiredError = "Token expired";
export const unableToSendEmail = "Unable to send email";
export const emailAlreadyConfirmed = "Email already confirmed";
export const UNDECIDED_STRING = "Undecided";
export const UNDECIDED_CONCENTRATION = "Concentration Undecided";
71 changes: 71 additions & 0 deletions packages/common/src/major2-validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
Err,
Ok,
} from "./types";
import { UNDECIDED_STRING } from "./constants";
import { assertUnreachable, courseToString } from "./course-utils";

/**
Expand Down Expand Up @@ -193,13 +194,20 @@ interface CourseValidationTracker {

// do we have enough courses to take all classes in both solutions?
hasEnoughCoursesForBoth(s1: Solution, s2: Solution): boolean;

setNecessaryCourses(courses: Set<string>): void;

getNecessaryCourses(): Set<string>;
}

// exported for testing
export class Major2ValidationTracker implements CourseValidationTracker {
// maps courseString => [course instance, # of times taken]
private currentCourses: Map<string, [ScheduleCourse2<unknown>, number]>;

//list of degree-required courses that we should not consider in the range validator
private necessaryCourses: Set<string> = new Set();

constructor(courses: ScheduleCourse2<unknown>[]) {
this.currentCourses = new Map();
for (const c of courses) {
Expand Down Expand Up @@ -260,6 +268,14 @@ export class Major2ValidationTracker implements CourseValidationTracker {
return true;
}

setNecessaryCourses(courses: Set<string>) {
this.necessaryCourses = courses;
}

getNecessaryCourses() {
return this.necessaryCourses;
}

// Maps the # of each course required in the given solution
private static createTakenMap(s: Solution): Map<string, number> {
const map = new Map();
Expand Down Expand Up @@ -295,6 +311,10 @@ export function validateMajor2(
}

const majorReqs = [...major.requirementSections, ...concentrationReq];

const requiredCourses: Set<string> = new Set();
tracker.setNecessaryCourses(getNecessaryCourses(majorReqs, requiredCourses));

// create a big AND requirement of all the sections and selected concentrations
const requirementsResult = validateRequirement(
{
Expand Down Expand Up @@ -323,6 +343,51 @@ export function validateMajor2(
});
}

/**
* Crawls through the requirements, producing a list of necessary courses. This
* is used to filter out courses that cannot be used for the range.
*/
export function getNecessaryCourses(
requirements: Requirement2[],
requiredCourses: Set<string>
): Set<string> {
const tracker = new Major2ValidationTracker([]);

for (const req of requirements) {
crawlRequirement(req, tracker, requiredCourses);
}
return requiredCourses;
}

/** Crawls through the requirements, producing a list of necessary courses. */
function crawlRequirement(
req: Requirement2,
tracker: CourseValidationTracker,
requiredCourses: Set<string>
): void {
switch (req.type) {
// base cases, a course is added to the list of necessary courses
case "COURSE":
requiredCourses.add(courseToString(req));
break;
// inductive case, we crawl through the children of an AND requirement
case "AND":
req.courses.forEach((r) => crawlRequirement(r, tracker, requiredCourses));
break;
// inductive case, we crawl through the children of a whole section
case "SECTION":
req.requirements.forEach((r) =>
crawlRequirement(r, tracker, requiredCourses)
);
case "XOM":
case "OR":
case "RANGE":
break;
default:
return assertUnreachable(req);
}
}

/**
* Produces the selected input concentrations to be included in major validation.
*
Expand All @@ -338,6 +403,10 @@ export function getConcentrationsRequirement(
if (concentrationsRequirement.concentrationOptions.length === 0) {
return [];
}
// Allow undecided concentrations
if (inputConcentrations === UNDECIDED_STRING) {
return [];
}
const concentrationRequirements = [];
for (const c of selectedConcentrations) {
const found = concentrationsRequirement.concentrationOptions.find(
Expand Down Expand Up @@ -443,6 +512,8 @@ function validateRangeRequirement(
): Result<Array<Solution>, MajorValidationError> {
// get the eligible courses (Filter out exceptions)
const exceptions = new Set(r.exceptions.map(courseToString));
tracker.getNecessaryCourses().forEach((course) => exceptions.add(course));

const courses = tracker
.getAll(r.subject, r.idRangeStart, r.idRangeEnd)
.filter((c) => !exceptions.has(courseToString(c)));
Expand Down
25 changes: 18 additions & 7 deletions packages/common/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import type { OptionObject } from "./types";

const UNDECIDED_OPTION: OptionObject = {
label: "Undecided",
value: "Undecided",
};

/** Does the given password satisfy our minimum criteria for strength? */
export const isStrongPassword = (password: string): boolean => {
const containsLettersAndNumbersRegex = /^(?=.*[a-zA-Z])(?=.*[0-9])/;
Expand Down Expand Up @@ -36,14 +41,20 @@ export const majorOptionObjectComparator = (
/**
* Converts a list of strings or numbers into a list of option objects for the
* Select component.
*
Copy link
Contributor

Choose a reason for hiding this comment

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

Good comms!

* IncludeUndecided: optional parameter specifying whether to include\
* "Undecided" as an option
*/
export const convertToOptionObjects = (
options: (string | number)[]
options: (string | number)[],
includeUndecided = false
): OptionObject[] => {
return options.map((option) => {
return {
label: option,
value: option,
};
});
const optionObjects = options.map((option) => ({
label: option,
value: option,
}));
if (includeUndecided) {
optionObjects.unshift(UNDECIDED_OPTION);
}
return optionObjects;
};
2 changes: 1 addition & 1 deletion packages/common/test/major2-validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
IOrCourse2,
IRequiredCourse,
IXofManyCourse,
Major2,
type Major2,
Requirement2,
ScheduleCourse2,
Section,
Expand Down
3 changes: 2 additions & 1 deletion packages/frontend/components/Plan/AddPlanModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ export const AddPlanModal: React.FC<AddPlanModalProps> = ({
name="concentration"
placeholder="Select a Concentration"
options={convertToOptionObjects(
majorConcentrations.concentrations
majorConcentrations.concentrations,
true
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you ever pass in false? Both times when you use convertToOptionObjects its true

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are other places in the codebase where it's used without a second param so it just defaults to false elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • In the same files
options={convertToOptionObjects(
                        extractSupportedMajorYears(supportedMajorsData)
                      )}

should default to false

)}
control={control}
rules={{
Expand Down
3 changes: 2 additions & 1 deletion packages/frontend/components/Plan/EditPlanModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ export const EditPlanModal: React.FC<EditPlanModalProps> = ({ plan }) => {
name="concentration"
placeholder="Select a Concentration"
options={convertToOptionObjects(
majorConcentrations.concentrations
majorConcentrations.concentrations,
true
)}
control={control}
rules={{
Expand Down
70 changes: 70 additions & 0 deletions packages/frontend/components/Plan/ErrorModalError.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { ChevronDownIcon, ChevronUpIcon, WarningIcon } from "@chakra-ui/icons";
import { Box, Flex, Text, Collapse } from "@chakra-ui/react";
import { useState } from "react";

interface ErrorModalErrorProps {
title: string;
message: string;
}

export const ErrorModalError: React.FC<ErrorModalErrorProps> = ({
title,
message,
}) => {
const [opened, setOpened] = useState(false);

return (
<Box
border="1px solid"
borderColor="primary.red.main"
borderRadius="lg"
backgroundColor="#FAE8E7"
transition="background-color 0.25s ease"
_hover={{ backgroundColor: "#F9DAD8" }}
>
<Flex
onClick={() => setOpened(!opened)}
direction="row"
justifyContent="space-between"
alignItems="flex-start"
height="45px"
color="black"
fontWeight="bold"
p="sm"
position="sticky"
top="0px"
zIndex={1}
>
<Flex direction="row" height="100%" columnGap="sm">
<Flex direction="row" height="100%" alignItems="center" gap="1">
<WarningIcon
color="primary.red.main"
width="2rem"
alignSelf="center"
alignItems="center"
justifySelf="center"
transition="background 0.15s ease"
/>
<Text color="black" mt="0" fontSize="sm">
{title}
</Text>
</Flex>
</Flex>

<Flex ml="xs" alignItems="center" justifyItems="center">
{opened ? (
<ChevronUpIcon boxSize="25px" color="primary.red.main" />
) : (
<ChevronDownIcon boxSize="25px" color="primary.red.main" />
)}
</Flex>
</Flex>

<Collapse in={opened} animateOpacity>
<Box px="sm" py="xs" borderRadius="lg" backgroundColor="transparent">
<Text fontSize="sm">{message}</Text>
</Box>
</Collapse>
</Box>
);
};
Loading