Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d3a5460
reduce redundancy in transcript
Jun 5, 2024
c99ace9
edited code by Amos
Jun 6, 2024
2c16131
using array to store job_title data instead of using variavble
Jun 7, 2024
76e7c0f
sorting experience elements by alphabetical order and end date
Jun 10, 2024
6d7cf86
Sorting experience elements by alphabetical order and end date. Delet…
Jun 10, 2024
5936f8c
Complete the code to job titles and end date.
Jun 11, 2024
7b16a93
Delete console.log
Jun 11, 2024
e9ae5c9
Apply suggestions from code review
yushinj Jun 12, 2024
4ea5b62
Merge branch 'develop' into s24-remove-redundancy-transcript
amos-cha Jun 12, 2024
8b4083c
Alppy suggestions from code review and improve legibility of transcripts
Jun 12, 2024
e74e80c
Merge branch 's24-remove-redundancy-transcript' of https://github.com…
Jun 12, 2024
06b2b18
Merge branch 'develop' into s24-remove-redundancy-transcript
amos-cha Jun 13, 2024
1b9fb91
Apply suggestions from code review
yushinj Jun 13, 2024
189c110
apply suggestion from code reivew except groupedExperience
Jun 14, 2024
df1143d
Merge branch 'develop' into s24-remove-redundancy-transcript
Jun 25, 2024
1ac3f23
Create grouped experience by Job_Title and sort them by the lastes en…
Jul 2, 2024
0af2330
ignore
Jul 8, 2024
b20f130
ignore
Jul 9, 2024
2e60437
display grouped and sorted transcript
Jul 11, 2024
c8fabde
delete unsed code and add comment
Jul 11, 2024
ad4d617
add comments
Jul 12, 2024
fcd8079
fix some errors
Jul 12, 2024
67a68cc
fix some errors
Jul 12, 2024
cf20b05
update ts
Jul 12, 2024
a21c1b3
Update package.json
yushinj Jul 12, 2024
ac6ce86
restore unrelated changes
Jul 12, 2024
53c4711
Merge branch 's24-remove-redundancy-transcript' of https://github.com…
Jul 12, 2024
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
13 changes: 10 additions & 3 deletions src/services/transcript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,13 @@ 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);
});
Copy link
Member

Choose a reason for hiding this comment

The 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?)


return groupedMembershipHistory;
};
Expand Down Expand Up @@ -141,3 +145,6 @@ const transcriptService = {
};

export default transcriptService;

const getName = (experience: MembershipHistory | StudentEmployment) =>
'Sessions' in experience ? experience.ActivityCode : experience.Job_Title;
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,29 @@
}
}

.experience_transcript_activities_empty_titles {
display: grid;
grid-template-columns: 5% 70% 25%;
grid-template-rows: auto auto;
justify-items: stretch;
position: relative;
top: -20px;

.organization_role {
grid-column: 2;
grid-row: 1;
text-align: left;
}

.date {
grid-column: 3;
grid-row: 1;
text-align: left;
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not ideal to duplicate the whole styles, just to add the position: relative and top: -20px. It would be better to keep those in a separate class and simply apply both classes when needed:

Suggested change
.experience_transcript_activities_empty_titles {
display: grid;
grid-template-columns: 5% 70% 25%;
grid-template-rows: auto auto;
justify-items: stretch;
position: relative;
top: -20px;
.organization_role {
grid-column: 2;
grid-row: 1;
text-align: left;
}
.date {
grid-column: 3;
grid-row: 1;
text-align: left;
}
}
.empty_title {
position: relative;
top: -20px;
}

@media print {
.experience_transcript_activities {
grid-row-gap: 0px;
grid-row-gap: 20px;
}
}
37 changes: 30 additions & 7 deletions src/views/CoCurricularTranscript/Components/Experience/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
import { format } from 'date-fns';
import { StudentEmployment } from 'services/transcript';
import styles from './Experience.module.css';
import { Dispatch, SetStateAction } from 'react';

type Props = {
Experience: StudentEmployment;
previousTitles: string[];
setPreviousTitles: Dispatch<SetStateAction<string[]>>;
};

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, previousTitles, setPreviousTitles }: Props) => {
const jobTitles = newJobTitle(Experience, previousTitles, setPreviousTitles);
const experienceTranscript =
jobTitles === ''
? styles.experience_transcript_activities_empty_titles
: styles.experience_transcript_activities;
return (
<div className={experienceTranscript}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const experienceTranscript =
jobTitles === ''
? styles.experience_transcript_activities_empty_titles
: styles.experience_transcript_activities;
return (
<div className={experienceTranscript}>
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) {
Expand All @@ -35,4 +43,19 @@ const formatDuration = ({ Job_Start_Date, Job_End_Date }: StudentEmployment) =>
}
};

const newJobTitle = (
{ Job_Department_Name, Job_Title }: StudentEmployment,
previousTitles: string[],
setPreviousTitles: Dispatch<SetStateAction<string[]>>,
) => {
if (!previousTitles.includes(Job_Title)) {
previousTitles.push(Job_Title);
setPreviousTitles(previousTitles);
return Job_Department_Name === Job_Title.split(':')[0]
? Job_Title
: `${Job_Department_Name}, ${Job_Title}`;
}
return '';
};

Copy link
Contributor

Choose a reason for hiding this comment

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

There is another way to do this, which in my opinion is both easier and more maintainable.

Basically, you can use Object.groupBy to group the experiences by Job_Title, and display the title once per group of jobs with the same title.

The grouping is as simple as:

const grouped_experiences = Object.groupBy(experiences, (experience) => experience.Job_Title);

Copy link
Contributor

Choose a reason for hiding this comment

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

To give a more complete example, here's a simplified experiences array:

const jobs = [
    {title: 'Dishwasher', start: new Date('2016-08-20'), end: new Date('2017-05-15')},
    {title: 'RA', start: new Date('2017-08-01'), end: new Date('2018-05-25')},
    {title: 'RA', start: new Date('2018-08-02'), end: new Date('2019-05-10')}
];

and we can group it like so:

const jobsByTitle = Object.groupBy(jobs, job => job.title);

we can convert that object to an array of objects, where each object in the array has a Job_Title property which is the title of all the jobs in that group, and a jobs property which is the array containing all the jobs in that group:

const jobGroups = Object.entries(jobsByTitle).map(([title, jobs]) => ({Job_Title: title, jobs}))

then we can render those job groups:

const Experience = ({Job_Title, jobs}) => {
return (
    <div className={styles.experience_transcript_activities}>
        <div className={styles.organization_role}>{Job_Title}</div>
        {jobs.map((job) => (
           <div>{formatDuration(job)}</div>
        )}
    </div>
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your suggestion. Can you explain why using group is easier and more maintainable? This code takes an array of information one by one from the ordered list. If I use group, it need an extra function to extract data from the group and a function that is similar to the upper code to display one title per group and to ignore job titles in the group, which is more complicate.

Copy link
Contributor

Choose a reason for hiding this comment

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

Because your current code is using React's useState hook to keep track of whether a certain title has been seen yet or not, you have to update state (and thus re-render the entire transcript) once for each experience. If you instead group experiences by job title before passing the data to React (i.e. within services/transcript.ts), you will already have all the data calculated and won't have to re-render any extra times.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your answer! I tried to group experiences within services/transcript.ts (line 51-78), but the type of data will be changed from groupedMembershipHistory to array if I group by job title. Is there better way to group experience or improve the code without groupBy?

export default Experience;
8 changes: 8 additions & 0 deletions src/views/CoCurricularTranscript/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const SectionTitle: { [Key in keyof TranscriptItems]: string } = {
};

const CoCurricularTranscript = () => {
const [previousTitles, setPreviousTitles] = useState<string[]>([]);
const [loading, setLoading] = useState(true);
const [transcriptItems, setTranscriptItems] = useState<TranscriptItems | undefined>();
const isAuthenticated = useIsAuthenticated();
Expand All @@ -32,6 +33,11 @@ const CoCurricularTranscript = () => {
return;
}
setLoading(true);
/**
* When you return the transcript from other page, the job titles will be lost
* Fixing bug by setting PreviousTitles to empty array when the transcript is loaded
*/
setPreviousTitles([]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
setPreviousTitles([]);
setPreviousTitles([]);

make a comment about this bugging out BECAUSE of the default transcript item. or else this looks confusing

const transcriptItems = await transcriptService.getItems(profile.AD_Username);
setTranscriptItems(transcriptItems);
} else {
Expand Down Expand Up @@ -78,6 +84,8 @@ const CoCurricularTranscript = () => {
) : (
<Experience
Experience={activity}
previousTitles={previousTitles}
setPreviousTitles={setPreviousTitles}
key={activity.Job_Title + activity.Job_Start_Date}
/>
),
Expand Down