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

Hide Columns #624

Merged
merged 28 commits into from
Aug 21, 2023
Merged

Hide Columns #624

merged 28 commits into from
Aug 21, 2023

Conversation

KevinWu098
Copy link
Member

@KevinWu098 KevinWu098 commented Jun 13, 2023

Summary

Columns can now be shown/hidden through a dropdown menu in the Course Render Pane

Demo Hide Column feature

Columns

  • Columns can now be hidden by deselecting them in a new Dropdown Menu housed in CoursePaneButtonRow
    • Active columns are stored and emitted in RightPaneStore.ts

Removing ConditionalWrapper

  • ConditionalWrapper.tsx has been removed in favor of plain conditional rendering logic.
  • Just use conditional rendering logic instead of a goofy component. JSX is already a pain to read, there's no need to obscure component logic even more.

Removing colorAndDelete

  • The property colorAndDelete, used in SectionTableBody (and related files) has been removed in favor of more reasonably calculating the proper value for addedCourse in sectionTableBody.tsx

Previously, sectionTableBody.tsx would always pass colorAndDelete as false, but then immediately recalculate it with the addedCourse state when it rendered:

const SectionTableBody = withStyles(styles)((props: SectionTableBodyProps) => {
    const { classes, section, courseDetails, term, 
      colorAndDelete /*ALWAYS false in courseRenderPane*/, 
      allowHighlight, scheduleNames } = props;

    const [addedCourse, setAddedCourse] = useState(colorAndDelete);

{...}

    // Immediately resets addedCourse
    useEffect(() => {
        const updateHighlight = () => {
            const doAdd = AppStore.getAddedSectionCodes().has(`${section.sectionCode} ${term}`);
            setAddedCourse(doAdd);
        };

The new callback doesn't immediately setAddedCourse, so instead we should just set the default useState to:

const [addedCourse, setAddedCourse] = useState(
        AppStore.getAddedSectionCodes().has(`${section.sectionCode} ${term}`)
    );

Doing so eliminates the need for the colorAndDelete prop!

Index.ts changes

  • The way the app is rendered has been changed in index.tsx to an async function

Refactor scheduleConflict

  • Refactored and added new helper functions into calendarizeHelpers.ts to assist in calculating scheduleConflicts
  • Utilize useMemo and useCallback to more correctly manage state

Test Plan

  • Columns should correctly be derendered when they're deselected in the Menu
  • Make sure it functions well on all devices

Issues

Zotcourse parity a la #440

@KevinWu098 KevinWu098 added the enhancement Improvements to the user experience label Jun 13, 2023
@KevinWu098 KevinWu098 marked this pull request as ready for review June 13, 2023 10:05
@github-actions github-actions bot requested a review from MinhxNguyen7 June 13, 2023 10:06
Copy link
Member

@MinhxNguyen7 MinhxNguyen7 left a comment

Choose a reason for hiding this comment

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

Sorry for taking so long to review. I missed the notification.

Great feature and works well. There are only some code quality issues.

My main issue is that there's so much separate state management and duplication going on. It's difficult to parse logic that should be relatively straightforward. Instead of having slightly different and separate states, try to put it all in one place, have named types, and translate it at the very end when you use it if really necessary.

Also, remember to merge. (I know it's my fault that there's a commit on main)

@KevinWu098 KevinWu098 requested a review from MinhxNguyen7 June 30, 2023 16:49
* refactor: completed column filtering

* style: use eye icon for columns

* fix: use react `createRoot`, fix ui errors

* style: small margin and padding
@ap0nia ap0nia self-requested a review August 15, 2023 18:27
@ap0nia ap0nia dismissed MinhxNguyen7’s stale review August 15, 2023 18:27

I'll review it

Copy link
Collaborator

@ap0nia ap0nia left a comment

Choose a reason for hiding this comment

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

I think the changes look fine. I'll wait for the preview deployment to finish before merging.

@EricPedley
Copy link
Member

Bumping this PR, seems like all that's left is to fix some merge conflicts

@ap0nia
Copy link
Collaborator

ap0nia commented Aug 19, 2023

wait, stop

@ap0nia
Copy link
Collaborator

ap0nia commented Aug 19, 2023

What are you doing, don't do this

  useEffect(() => {
        const updateHighlight = useCallback(() => {
          setAddedCourse(AppStore.getAddedSectionCodes().has(`${section.sectionCode} ${term}`));
        }, [setAddedCourse, AppStore.getAddedSectionCodes]);

        const checkAndDisplayScheduleConflict = () => {
            if (AppStore.getCourseEventsInCalendar().length < 1) {
                setScheduleConflict(false);
                return;
            }

@ap0nia
Copy link
Collaborator

ap0nia commented Aug 19, 2023

Don't invoke hooks inside of other hooks

@KevinWu098
Copy link
Member Author

💀 I did a whoopsie

@ap0nia
Copy link
Collaborator

ap0nia commented Aug 19, 2023

Ok, fine, give me a bit to fix it

@ap0nia ap0nia self-requested a review August 20, 2023 00:02
@KevinWu098
Copy link
Member Author

KevinWu098 commented Aug 20, 2023

Sorry 'bout all that nonsense, hopefully this latest commit should resolve the issues, but I'll test on the staging instance // read over the code again right now!

@ap0nia
Copy link
Collaborator

ap0nia commented Aug 20, 2023

Ok no like. The entire strategy for figuring out conflicts is just wrong. There shouldn't even be a useEffect + useState. The entire logic should be a single useMemo

Copy link
Collaborator

@ap0nia ap0nia left a comment

Choose a reason for hiding this comment

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

Ok, code is fixed. I have to go so I can't immediately verify the behavior live. Somebody else please review 🙏

TLDR:
Please don't write bad code. And if you don't know React, try consulting somebody that does before approving React code.

@ap0nia ap0nia requested a review from EricPedley August 20, 2023 00:44
@KevinWu098
Copy link
Member Author

KevinWu098 commented Aug 21, 2023

Deployed staging instance to https://staging-624.antalmanac.com

I'll eventually move this into the original PR body, but for now, this is why I removed colorAndDelete:

Previously, sectionTableBody.tsx would always pass colorAndDelete as false, but then immediately recalculate it with the addedCourse state when it rendered:

const SectionTableBody = withStyles(styles)((props: SectionTableBodyProps) => {
    const { classes, section, courseDetails, term, 
      colorAndDelete /*ALWAYS false in courseRenderPane*/, 
      allowHighlight, scheduleNames } = props;

    const [addedCourse, setAddedCourse] = useState(colorAndDelete);

{...}

    // Immediately resets addedCourse
    useEffect(() => {
        const updateHighlight = () => {
            const doAdd = AppStore.getAddedSectionCodes().has(`${section.sectionCode} ${term}`);
            setAddedCourse(doAdd);
        };

The new callback doesn't immediately setAddedCourse, so instead we should just set the default useState to:

const [addedCourse, setAddedCourse] = useState(
        AppStore.getAddedSectionCodes().has(`${section.sectionCode} ${term}`)
    );

Doing so eliminates the need for the colorAndDelete prop!

@KevinWu098 KevinWu098 requested a review from ap0nia August 21, 2023 08:11
Copy link
Collaborator

@ap0nia ap0nia left a comment

Choose a reason for hiding this comment

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

Ok good enough, if it breaks prod I'll fix it later. 🚀

@ap0nia ap0nia merged commit 8a954df into main Aug 21, 2023
@ap0nia ap0nia deleted the columnFilter branch August 21, 2023 09:27
@MinhxNguyen7 MinhxNguyen7 mentioned this pull request Aug 22, 2023
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvements to the user experience
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants