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

[Saved Courses] add collection into firesbase #921

Closed
wants to merge 9 commits into from

Conversation

plumshum
Copy link
Contributor

@plumshum plumshum commented Apr 24, 2024

Summary

This pull request is the first step towards adding collection into Firebase for implementing the Save Courses Feature.

  • add collection to firebase
  • Add firebase function to modify (add, delete, edit) from collections (functionalities that aren't tested yet)
  • Stub functions into frontend components MOVED TO A NEW PR
    - [ ] only for save course modal [Saved Courses] add save modal #912

Remaining TODOs

Depends on #{number of PR}
need to make sure it works with #912

Test Plan

  • Should make some JUnit tests

Notes

Blockers

  • A newly discovered dependency that hasn’t been addressed

Breaking Changes

  • store now has collections , need to update alot of code with semesters
  • Database schema change (anything that changes Firestore collection structure)
  • Other change that could cause problems (Detailed in notes)

@plumshum plumshum self-assigned this Apr 24, 2024
@dti-github-bot
Copy link
Member

dti-github-bot commented Apr 24, 2024

[diff-counting] Significant lines: 147.

Copy link
Contributor

github-actions bot commented Apr 24, 2024

Visit the preview URL for this PR (updated for commit 1d44852):

https://cornelldti-courseplan-dev--pr921-hannah-add-firestore-hmirtull.web.app

(expires Fri, 31 May 2024 22:02:33 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 6d4e0437c4559ed895272bbd63991394f1e0e933

@plumshum plumshum changed the title add collection into firesbase [Saved Courses] add collection into firesbase Apr 24, 2024
@plumshum plumshum marked this pull request as ready for review May 1, 2024 20:53
@plumshum plumshum requested a review from a team as a code owner May 1, 2024 20:53
Copy link
Member

@Destaq Destaq left a comment

Choose a reason for hiding this comment

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

Great work Hannah! And I appreciate that this is still a quasi-draft PR (make sure that you open things appropriately in the future when not fully ready for review), so makes sense that there are some of the console.logs and TODOs. Just please ensure that these are all removed when all the other commits are finished, for the reasons I outlined.

In general, looks fantastic and you did a really good job with TypeScript too. Good to have a chance to start working with Vuex, that's very critical to the web app. In terms of future work, would just encourage you to do some minor refactoring (maybe not now, but at least before the merge request proper) and test that the Firebase writing works. Whenever you need any help finishing stuff up feel free to message or find me.

Also, if it would be possible to update the description for this PR that would be great, I think you may have left some parts of the initial boilerplate intact.

export const editCollections = async (
updater: (oldCollections: readonly Collection[]) => readonly Collection[]
): Promise<void> => {
console.log('edit Collections');
Copy link
Member

Choose a reason for hiding this comment

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

If you don't need this for further debugging, would be great to remove — don't want to unnecessarily clutter the console.

console.log('edit Collections');
const collections = updater(store.state.collections);
store.commit('setCollections', collections);
await updateDoc(doc(semestersCollection, store.state.currentFirebaseUser.email), {
Copy link
Member

Choose a reason for hiding this comment

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

If / when you are testing this on Firebase, you might get a warning about insufficient permissions. Nidhi and I just went through this last week. So a heads up if that does pop up: you need to update the 'rules' for that collection in the Firebase. Happy to help if you're experiencing trouble with that and not 100% sure what to do.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be ok for now -- the semestersCollection already allows for read and write

@@ -56,6 +77,17 @@ export const editPlan = (name: string, updater: (oldPlan: Plan) => Plan): void =
editPlans(oldPlan => oldPlan.map(plan => (plan.name === name ? updater(plan) : plan)));
};

const createCollection = (
name: string,
Copy link
Member

Choose a reason for hiding this comment

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

Would it be possible to abstract this into a local type? Improves a bit on maintainability.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's ok for codebase consistency -- we initialize most of our objects (semester, plan, etc) like that

courses: readonly FirestoreSemesterCourse[]
): {
name: string;
courses: readonly FirestoreSemesterCourse[];
Copy link
Member

Choose a reason for hiding this comment

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

Great use of some advanced TS features, I don't think I've ever used readonly or even properly understand it 😁

@@ -88,6 +120,15 @@ export const semesterEquals = (
season: FirestoreSemesterSeason
): boolean => semester.year === year && semester.season === season;

export const addCollection = async (
name: string,
Copy link
Member

Choose a reason for hiding this comment

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

See above — could abstract this (the first two parameters) and then connect to the optional parameter using the ampersand operator.

gtag?: VueGtag
): void => {
// TODO: 1) add course to collection 2) delete course from semester
// 3) cannot add course to collection if it is already in the collection
Copy link
Member

Choose a reason for hiding this comment

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

I imagine there will be a bit of a lull in development of other features at the beginning of next semester. See that you have a lot of TODOs; if you need any help am always available.


type Collection = {
readonly name: string;
// TODO: add potential more fields
Copy link
Member

Choose a reason for hiding this comment

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

I mentioned earlier about using a local collection type — is this it? Maybe could use this?

Copy link
Collaborator

@elizabeth-tang elizabeth-tang left a comment

Choose a reason for hiding this comment

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

Awesome, it's really coming along Hannah!! I know some of the stuff Simon mentioned are present in the existing codebase so it's ok to leave to later to address. Thanks for working on this!

console.log('edit Collections');
const collections = updater(store.state.collections);
store.commit('setCollections', collections);
await updateDoc(doc(semestersCollection, store.state.currentFirebaseUser.email), {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be ok for now -- the semestersCollection already allows for read and write

await updateDoc(doc(semestersCollection, store.state.currentFirebaseUser.email), {
collections,
});
store.commit('setOrderByNewest', store.state.orderByNewest);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This shouldn't be necessary here since editing collections should not change the ordering of the semesters

@@ -56,6 +77,17 @@ export const editPlan = (name: string, updater: (oldPlan: Plan) => Plan): void =
editPlans(oldPlan => oldPlan.map(plan => (plan.name === name ? updater(plan) : plan)));
};

const createCollection = (
name: string,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's ok for codebase consistency -- we initialize most of our objects (semester, plan, etc) like that

@plumshum plumshum marked this pull request as draft September 19, 2024 20:55
@plumshum plumshum mentioned this pull request Oct 2, 2024
6 tasks
@plumshum plumshum closed this Oct 5, 2024
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