-
Notifications
You must be signed in to change notification settings - Fork 14
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
reduce redundancy in transcript #2280
base: develop
Are you sure you want to change the base?
Changes from 19 commits
d3a5460
c99ace9
2c16131
76e7c0f
6d7cf86
5936f8c
7b16a93
e9ae5c9
4ea5b62
8b4083c
e74e80c
06b2b18
1b9fb91
189c110
df1143d
1ac3f23
0af2330
b20f130
2e60437
c8fabde
ad4d617
fcd8079
67a68cc
cf20b05
a21c1b3
ac6ce86
53c4711
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -18,6 +18,12 @@ export type TranscriptItems = { | |||||||||
activities: MembershipHistory[]; | ||||||||||
}; | ||||||||||
|
||||||||||
export type Groupexperience = { | ||||||||||
Job_Title: string; | ||||||||||
job: StudentEmployment[] | undefined; | ||||||||||
latestDate?: string; | ||||||||||
}; | ||||||||||
|
||||||||||
const getItems = (username: string) => | ||||||||||
Promise.all([ | ||||||||||
userService.getMembershipHistory(username), | ||||||||||
|
@@ -50,7 +56,7 @@ const getItems = (username: string) => | |||||||||
const categorizeItems = async (memberships: MembershipHistory[], jobs: StudentEmployment[]) => { | ||||||||||
const groupedMembershipHistory: TranscriptItems = { | ||||||||||
honors: [] as MembershipHistory[], | ||||||||||
experiences: jobs as (MembershipHistory | StudentEmployment)[], | ||||||||||
experiences: jobs as StudentEmployment[], | ||||||||||
service: [] as MembershipHistory[], | ||||||||||
activities: [] as MembershipHistory[], | ||||||||||
}; | ||||||||||
|
@@ -70,10 +76,71 @@ const categorizeItems = async (memberships: MembershipHistory[], jobs: StudentEm | |||||||||
|
||||||||||
groupedMembershipHistory.activities = memberships; | ||||||||||
|
||||||||||
groupedMembershipHistory.experiences.sort( | ||||||||||
(a, b) => getExperienceEndDate(b) - getExperienceEndDate(a), | ||||||||||
// Sort experiences by experience name then by end date | ||||||||||
groupedMembershipHistory.experiences.sort((a, b) => { | ||||||||||
const nameComparison = getName(a).localeCompare(getName(b)); | ||||||||||
return nameComparison !== 0 | ||||||||||
? nameComparison | ||||||||||
: getExperienceEndDate(b) - getExperienceEndDate(a); | ||||||||||
}); | ||||||||||
|
||||||||||
//groupedMembershipHistory.experiences = jobs; | ||||||||||
|
||||||||||
let GroupByTitle = Object.entries(Object.groupBy(jobs, (job) => job.Job_Title)).map( | ||||||||||
([title, job]) => ({ | ||||||||||
Job_Title: title, | ||||||||||
job, | ||||||||||
latestDate: '', | ||||||||||
}), | ||||||||||
); | ||||||||||
|
||||||||||
// This code is has a lot of ? and ! opeators because typescript can't analyze the | ||||||||||
// loop to recognize that the array indexing is safe. | ||||||||||
for (let i = 0; i < GroupByTitle.length; i++) { | ||||||||||
let maxDate: string = ''; | ||||||||||
let tempJob = GroupByTitle?.[i].job; | ||||||||||
let numJobs = tempJob!.length; | ||||||||||
for (let j = 0; j < numJobs; j++) { | ||||||||||
let tempVal = GroupByTitle[i]; | ||||||||||
let value = tempVal!.job?.[j].Job_End_Date; | ||||||||||
if (maxDate! < value!) { | ||||||||||
maxDate = value!; | ||||||||||
} | ||||||||||
} | ||||||||||
GroupByTitle[i].latestDate = maxDate; | ||||||||||
} | ||||||||||
|
||||||||||
// Sorting the grouped job by the latest end date | ||||||||||
GroupByTitle.sort((a, b) => { | ||||||||||
return getLatestEndDate(b)! - getLatestEndDate(a)!; | ||||||||||
}); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Return this new GroupByTitle in groupedMembershipHistory, NOT the de-grouped version below. (Why do all the work to combine each job into one entry with multiple times, and then not use it?) |
||||||||||
|
||||||||||
console.log(GroupByTitle); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
remove console logs |
||||||||||
|
||||||||||
let test = []; | ||||||||||
for (let i = 0; i < GroupByTitle.length; i++) { | ||||||||||
let tempJob = GroupByTitle?.[i].job; | ||||||||||
let numJobs = tempJob!.length; | ||||||||||
for (let j = 0; j < numJobs; j++) { | ||||||||||
let tempVal = GroupByTitle[i]; | ||||||||||
let value = tempVal!.job?.[j]; | ||||||||||
if (j > 0) { | ||||||||||
value!.Job_Title = ''; | ||||||||||
} | ||||||||||
if (value) { | ||||||||||
test.push(value); | ||||||||||
} | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
for (let i = 0; i < test.length; i++) { | ||||||||||
jobs[i] = test[i]; | ||||||||||
} | ||||||||||
Comment on lines
+133
to
+151
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be deleted. |
||||||||||
|
||||||||||
//console.log('jobs'); | ||||||||||
//console.log(jobs); | ||||||||||
//console.log('groupedMembershipHistory'); | ||||||||||
//console.log(groupedMembershipHistory); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Remove unused consolelogs |
||||||||||
return groupedMembershipHistory; | ||||||||||
}; | ||||||||||
|
||||||||||
|
@@ -141,3 +208,14 @@ const transcriptService = { | |||||||||
}; | ||||||||||
|
||||||||||
export default transcriptService; | ||||||||||
|
||||||||||
const getName = (experience: MembershipHistory | StudentEmployment) => | ||||||||||
'Sessions' in experience ? experience.ActivityCode : experience.Job_Title; | ||||||||||
|
||||||||||
const getLatestEndDate = (GroupByTitle: Groupexperience) => { | ||||||||||
const date = GroupByTitle.latestDate; | ||||||||||
|
||||||||||
if (date) { | ||||||||||
return Date.parse(date); | ||||||||||
} | ||||||||||
}; |
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -6,14 +6,21 @@ type Props = { | |||||||||||||||||
Experience: StudentEmployment; | ||||||||||||||||||
}; | ||||||||||||||||||
|
||||||||||||||||||
const Experience = ({ Experience }: Props) => ( | ||||||||||||||||||
<div className={styles.experience_transcript_activities}> | ||||||||||||||||||
<div className={styles.organization_role}> | ||||||||||||||||||
{Experience.Job_Department_Name}, {Experience.Job_Title} | ||||||||||||||||||
const Experience = ({ Experience }: Props) => { | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this could be simpler if you passed in the grouped jobs. |
||||||||||||||||||
const jobTitles = newJobTitle(Experience); | ||||||||||||||||||
return ( | ||||||||||||||||||
<div | ||||||||||||||||||
className={ | ||||||||||||||||||
jobTitles === '' | ||||||||||||||||||
? `${styles.experience_transcript_activities} ${styles.empty_title}` | ||||||||||||||||||
: styles.experience_transcript_activities | ||||||||||||||||||
} | ||||||||||||||||||
> | ||||||||||||||||||
<div className={styles.organization_role}>{jobTitles}</div> | ||||||||||||||||||
<div className={styles.date}> {formatDuration(Experience)} </div> | ||||||||||||||||||
</div> | ||||||||||||||||||
<div className={styles.date}> {formatDuration(Experience)} </div> | ||||||||||||||||||
</div> | ||||||||||||||||||
); | ||||||||||||||||||
); | ||||||||||||||||||
}; | ||||||||||||||||||
|
||||||||||||||||||
const formatDuration = ({ Job_Start_Date, Job_End_Date }: StudentEmployment) => { | ||||||||||||||||||
if (!Job_Start_Date) { | ||||||||||||||||||
|
@@ -35,4 +42,11 @@ const formatDuration = ({ Job_Start_Date, Job_End_Date }: StudentEmployment) => | |||||||||||||||||
} | ||||||||||||||||||
}; | ||||||||||||||||||
|
||||||||||||||||||
const newJobTitle = ({ Job_Department_Name, Job_Title }: StudentEmployment) => { | ||||||||||||||||||
if (Job_Title === '') { | ||||||||||||||||||
return ''; | ||||||||||||||||||
} | ||||||||||||||||||
return Job_Title === '' ? Job_Title : `${Job_Department_Name}, ${Job_Title}`; | ||||||||||||||||||
Comment on lines
+46
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
that top part and the first half of the ternary are logically identical. Is there a reason both are included? |
||||||||||||||||||
}; | ||||||||||||||||||
|
||||||||||||||||||
export default Experience; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove unused code