Skip to content

Standardize semester type/season naming convention#546

Merged
benjamin-shen merged 12 commits into
masterfrom
ben/standardize-season-year-terminology
Oct 26, 2021
Merged

Standardize semester type/season naming convention#546
benjamin-shen merged 12 commits into
masterfrom
ben/standardize-season-year-terminology

Conversation

@benjamin-shen

@benjamin-shen benjamin-shen commented Oct 19, 2021

Copy link
Copy Markdown
Collaborator

Summary

We used "semester type" before we were using TypeScript and it worked for a while, but now "type" can be very ambiguous -- meanwhile, "season" has no ambiguity and we've actually been using both terms for a while now. This pull request officially standardizes the naming convention by changing most instances of "semester type" to "semester season".

  • changed FirestoreSemesterType to FirestoreSemesterSeason in user-data.d.ts
  • changed as many instances of "semester type" to "semester season" that I could find and safely remove
  • standardized argument order (year then semester) in global-firestore-data/semesters.ts
  • simplified some functions in global-firestore-data/semesters.ts
  • cleaned up some util functions, clear semester functionality, and toggle semester order functionality

TODO

Test Plan

Verify that all semester-related functionality still works as intended.

Notes

If there are merge conflicts: accept your current changes, change "semester type" to "semester season" where appropriate, verify that the web app builds, and make sure to npm run type-check.

@dti-github-bot

dti-github-bot commented Oct 19, 2021

Copy link
Copy Markdown
Member

[diff-counting] Significant lines: 519.

@github-actions

github-actions Bot commented Oct 19, 2021

Copy link
Copy Markdown
Contributor

Visit the preview URL for this PR (updated for commit 348ee96):

https://cornelldti-courseplan-dev--pr546-ben-standardize-seas-r6ofacz8.web.app

(expires Sun, 31 Oct 2021 01:41:54 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

@willespencer willespencer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Identified a bug - existing semesters will still have the "type" key in Firestore documents, but any new semester will have "season," leading to issues where seasons don't show up on CP. Need either a migration script or need to check for both of these keys in the code.

Comment on lines -35 to +46
v-for="season in seasons"
:key="season[1]"
v-for="s in seasons"
:key="s[1]"
class="selectSemester-dropdown-content-item"
@click="selectSeason(season[1])"
@click="selectSeason(s[1])"
data-cyId="newSemester-seasonItem"
>
<img
:src="season[0]"
:src="s[0]"
class="selectSemester-dropdown-content-season"
:alt="`${season[1]} icon`"
:alt="`${s[1]} icon`"
/>
{{ season[1] }}
{{ s[1] }}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

had to rename since season is now a prop name

Comment on lines -218 to -231
getCurrentSeason(): FirestoreSemesterType {
let currentSeason: FirestoreSemesterType;
const currentMonth = new Date().getMonth();
if (currentMonth === 0) {
currentSeason = 'Winter';
} else if (currentMonth <= 4) {
currentSeason = 'Spring';
} else if (currentMonth <= 7) {
currentSeason = 'Summer';
} else {
currentSeason = 'Fall';
}
return currentSeason;
},

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

duplicate function in @/utilities

Comment thread src/utilities.ts
Comment on lines -17 to -49
export function getCurrentType(): 'WI' | 'SP' | 'SU' | 'FA' {
const currentMonth = new Date().getMonth();
if (currentMonth === 0) return 'WI';
if (currentMonth <= 4) return 'SP';
if (currentMonth <= 7) return 'SU';
return 'FA';
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

unused

@benjamin-shen benjamin-shen marked this pull request as ready for review October 19, 2021 21:20
@benjamin-shen benjamin-shen requested a review from a team as a code owner October 19, 2021 21:20
@hahnbeelee

Copy link
Copy Markdown
Contributor

Just wanted to say - overall looks good to me. I want to check all the season semester functionality in depth but it's getting a little late so ill do it tmrw!

@hahnbeelee hahnbeelee left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@vaishnavi17 's semester population doesn't seem to be working here? (I deleted my firestore data and went through onboarding again)
All other semester functionality seems to be good.
image

@benjamin-shen

benjamin-shen commented Oct 23, 2021

Copy link
Copy Markdown
Collaborator Author

@hahnbeelee thanks for the catch. The bug existed because I hadn't merged Vaish's PR from master, it should be fixed now.

  • merge Vaish's changes
  • merge Toby's changes
  • merge Zach's changes

Then I will push to master!! 😄

Comment on lines -27 to +29
props: {
clearSemType: { type: String, required: true },
clearSemYear: { type: Number, required: true },
},
emits: {
'close-clear-sem': () => true,
'clear-semester': (type: string, year: number) =>
typeof type === 'string' && typeof year === 'number',
'clear-semester': () => true,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

These are redundant props because the <clear-semester> component is a child of the <semester> prop.

I think it was modeled after delete-semester, which does need a season & year passed in to delete the semester (because it is emitted to the grandparent <semester-view>). Instead, clear-semester is more similar to add-course and delete-course, despite what the naming suggests.

Comment on lines -12 to -27
// compare function for FirestoreSemester to determine which comes first by year and type/season
export const compareFirestoreSemesters = (a: FirestoreSemester, b: FirestoreSemester): number => {
if (a.type === b.type && a.year === b.year) {
return 0;
}
if (a.year > b.year) {
return -1;
}
if (a.year < b.year) {
return 1;
}
if (SeasonOrdinal[a.type] < SeasonOrdinal[b.type]) {
return 1;
}
return -1;
};

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We can get rid of this; sortedSemesters() has the same purpose. The only difference is that we don't modify the array directly anymore (think sorted() vs .sort(), which is good to avoid side effects & when working with readonly arrays.

export const toggleOrderByNewest = (): boolean => {
const toggled = !store.state.orderByNewest;
store.commit('setOrderByNewest', toggled);
export const setOrderByNewest = (orderByNewest: boolean): void => {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Changed toggle (which set the negated boolean value) to set (which sets a specific boolean value) to simplify the code in the frontend component and unify the global-firestore-data functions (i.e. setBlah(newValue) or editBlah(updater)). It should have the same functionality.

Lmk if you have a different opinion and I can change this back!

Comment thread src/utilities.ts
return value;
}

export default function getCurrentSeason(): FirestoreSemesterType {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No reason for this to be a default export

@hahnbeelee hahnbeelee left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yerssirrrrrrrrrrrrrrrrrrrrrrrrr. so clean 🙏

@willespencer willespencer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is so great, thanks Ben!! Specifically tested to make sure that nothing breaks when users have the "type" prop in Firestore, and that duplicate semester prevention, re-ordering semesters, and adding courses to a semester from the req bar add modal all work as expected.

My only remaining question is if we want to write a data migration script if the code already works and handles both semester and type for existing users?

If we do choose to write it, maybe we should have a release with this change that handles both types, then run the migration script on prod so users only have season, and finally push another release that does not use type anymore, so there is never a period of time where user data does not match the prod code.

@benjamin-shen benjamin-shen merged commit 2001c50 into master Oct 26, 2021
@benjamin-shen benjamin-shen deleted the ben/standardize-season-year-terminology branch October 26, 2021 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants