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 attributes filter to PCP #560

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 0 additions & 11 deletions Pipfile

This file was deleted.

64 changes: 38 additions & 26 deletions frontend/plan/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export const COURSE_SEARCH_ERROR = "COURSE_SEARCH_ERROR";
export const COURSE_SEARCH_LOADING = "COURSE_SEARCH_LOADING";
export const COURSE_SEARCH_SUCCESS = "COURSE_SEARCH_SUCCESS";

export const LOAD_REQUIREMENTS = "LOAD_REQUIREMENTS";
export const ADD_SCHOOL_REQ = "ADD_SCHOOL_REQ";
export const REM_SCHOOL_REQ = "REM_SCHOOL_REQ";
export const LOAD_ATTRIBUTES = "LOAD_ATTRIBUTES";
export const ADD_SCHOOL_ATTR = "ADD_SCHOOL_ATTR";
export const REM_SCHOOL_ATTR = "REM_SCHOOL_ATTR";
export const UPDATE_SEARCH_TEXT = "UPDATE_SEARCH_TEXT";

export const UPDATE_RANGE_FILTER = "UPDATE_RANGE_FILTER";
Expand Down Expand Up @@ -188,8 +188,8 @@ export const checkForDefaultSchedules = (schedulesFromBackend) => (
}
};

export const loadRequirements = () => (dispatch) =>
doAPIRequest("/base/current/requirements/").then(
export const loadAttributes = () => (dispatch) =>
doAPIRequest("/base/attributes/").then(
(response) =>
response.json().then(
(data) => {
Expand All @@ -198,16 +198,28 @@ export const loadRequirements = () => (dispatch) =>
SEAS: [],
WH: [],
NURS: [],
LPS: [],
DSGN: [],
GSE: [],
LAW: [],
MED: [],
VET: [],
MODE: [],
};
const selObj = {};
const selAttrs = {};
data.forEach((element) => {
obj[element.school].push(element);
selObj[element.id] = 0;
const school =
element.school === "NUR" ? "NURS" : element.school;
if (obj[school] === undefined) {
return;
}
obj[school].push(element);
selAttrs[element.code] = 0;
});
dispatch({
type: LOAD_REQUIREMENTS,
type: LOAD_ATTRIBUTES,
obj,
selObj,
selObj: selAttrs,
});
},
(error) => {
Expand All @@ -224,19 +236,19 @@ export const loadRequirements = () => (dispatch) =>
function buildCourseSearchUrl(filterData) {
let queryString = `/base/current/search/courses/?search=${filterData.searchString}`;

// Requirements filter
const reqs = [];
if (filterData.selectedReq) {
for (const key of Object.keys(filterData.selectedReq)) {
if (filterData.selectedReq[key]) {
reqs.push(key);
// Course attribute filter (e.g., filter by Wharton CCP requirements)
const attributes = [];
if (filterData.selectedAttrs) {
for (const code of Object.keys(filterData.selectedAttrs)) {
if (filterData.selectedAttrs[code]) {
attributes.push(code);
}
}

if (reqs.length > 0) {
queryString += `&requirements=${reqs[0]}`;
for (let i = 1; i < reqs.length; i += 1) {
queryString += `,${reqs[i]}`;
if (attributes.length > 0) {
queryString += `&attributes=${attributes[0]}`;
for (let i = 1; i < attributes.length; i += 1) {
queryString += `*${attributes[i]}`;
}
}
}
Expand Down Expand Up @@ -398,17 +410,17 @@ export function sectionInfoSearchError(error) {
};
}

export function addSchoolReq(reqID) {
export function addSchoolAttr(attrCode) {
return {
type: ADD_SCHOOL_REQ,
reqID,
type: ADD_SCHOOL_ATTR,
attrCode,
};
}

export function remSchoolReq(reqID) {
export function remSchoolAttr(attrCode) {
return {
type: REM_SCHOOL_REQ,
reqID,
type: REM_SCHOOL_ATTR,
attrCode,
};
}

Expand Down
6 changes: 3 additions & 3 deletions frontend/plan/components/analytics.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ReactGA from "react-ga";
import {
ADD_SCHOOL_REQ,
REM_SCHOOL_REQ,
ADD_SCHOOL_ATTR,
REM_SCHOOL_ATTR,
UPDATE_SEARCH_TEXT,
UPDATE_RANGE_FILTER,
CHANGE_MY_SCHEDULE,
Expand Down Expand Up @@ -30,7 +30,7 @@ export const logException = (description = "", fatal = false) => {
}
};

const filterActions = [ADD_SCHOOL_REQ, REM_SCHOOL_REQ, UPDATE_RANGE_FILTER];
const filterActions = [ADD_SCHOOL_ATTR, REM_SCHOOL_ATTR, UPDATE_RANGE_FILTER];
const schedActions = [
CHANGE_MY_SCHEDULE,
RENAME_SCHEDULE,
Expand Down
Loading
Loading