-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
97 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,58 @@ | ||
import { | ||
GetMajorsResponse, | ||
GetSupportedMajorsResponse, | ||
OptionObject, | ||
majorNameComparator, | ||
majorOptionObjectComparator, | ||
} from "@graduate/common"; | ||
|
||
export const extractSupportedMajorYears = ( | ||
supportedMajorsData?: GetSupportedMajorsResponse | ||
) => { | ||
return Object.keys(supportedMajorsData?.supportedMajors ?? {}); | ||
}; | ||
|
||
/** | ||
* Returns a list of the supported majors names as strings for the given catalog year. | ||
* | ||
* @param catalogYear Catalog year to search for | ||
* @param supportedMajorsData Supported major data to extract from | ||
* @returns A list of the supported major names for the | ||
* given catalog year | ||
*/ | ||
export const extractSupportedMajorNames = ( | ||
catalogYear?: number, | ||
supportedMajorsData?: GetSupportedMajorsResponse | ||
): string[] => { | ||
if (!catalogYear) { | ||
return []; | ||
} | ||
return Object.keys( | ||
supportedMajorsData?.supportedMajors[catalogYear] ?? {} | ||
).sort(majorNameComparator); | ||
const majorMap = supportedMajorsData?.supportedMajors[catalogYear]; | ||
return Object.keys(majorMap ?? {}).sort(majorNameComparator); | ||
}; | ||
|
||
export const extractMajorYears = (majorsData?: GetMajorsResponse) => { | ||
return Object.keys(majorsData?.majors ?? {}); | ||
}; | ||
export const extractMajorNames = ( | ||
/** | ||
* Returns a list of option objects for supported majors (label, value) for the | ||
* given catalog year. | ||
* | ||
* @param catalogYear Catalog year to search for | ||
* @param supportedMajorsData Supported major data to extract from | ||
* @returns A list of the supported major option objects for | ||
* the given catalog year | ||
*/ | ||
export const extractSupportedMajorOptions = ( | ||
catalogYear?: number, | ||
majorsData?: GetMajorsResponse | ||
): string[] => { | ||
supportedMajorsData?: GetSupportedMajorsResponse | ||
): OptionObject[] => { | ||
if (!catalogYear) { | ||
return []; | ||
} | ||
// extract the name to information mapping for the given year | ||
let majorMap = majorsData?.majors[catalogYear]; | ||
const majorMap = supportedMajorsData?.supportedMajors[catalogYear]; | ||
return Object.keys(majorMap ?? {}) | ||
.map( | ||
(majorName) => | ||
majorName + (majorMap?.[majorName].metadata.verified ? "" : " [BETA]") | ||
) | ||
.sort(majorNameComparator); | ||
.map((majorName) => { | ||
return { | ||
label: majorName + (majorMap?.[majorName].verified ? "" : " [BETA]"), | ||
value: majorName, | ||
}; | ||
}) | ||
.sort(majorOptionObjectComparator); | ||
}; |