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

website: Switch between LTR and RTL prereq tree directions #3842

Conversation

zehata
Copy link
Contributor

@zehata zehata commented Oct 23, 2024

Context

Fixes #3202 Prerequisite tree right-to-left progression is confusing

Implementation

This PR extends PR #3840's implementation and adds a toggle for the user to choose whether they prefer the prerequisite to appear on the left or the right. Setting defaults to prerequisites on the left, which is the requested specifications for #3202. Please note that this branch diverges from the branch in PR #3840 and cannot both be merged.

While Issue #3203 specifications does not ask for ability to toggle, some users like myself may have already gotten used to prerequisites on the right. However, I do agree that the prerequisites on the right seems to be more intuitive.

I also took the chance to fix some confusing naming in the code, like the trees having class names that were opposite of what they contained. The fix for the truncation bug in PR #3840 is also carried over.

Credits to @sciffany for copywriting and initial implementation, to @li-kai for implementation feedback and to @alvynben for implementation and test cases.

UI tests

Settings toggle:

image

Single prerequisite/dependents:

Left
image

Right, i.e. original layout (unchanged)
image

Complex prerequisite/dependents with uneven layers and uneven letters in module codes

Left
image

Prefixed prerequisites

image

Side effect fixes:

This also fixes misaligned module trees as a side effect
image

Other Information

Any questions you may have

Is there a tele group specific for development?

Letting us know that you're new to this (so we know how much to help out)

Again, been almost 3 years since I touched any web dev. Sorry in advance if I had missed out anything.

Copy link

vercel bot commented Oct 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nusmods-export ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 16, 2024 10:53am

Copy link

vercel bot commented Oct 23, 2024

@zehata is attempting to deploy a commit to the modsbot's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

codecov bot commented Oct 23, 2024

Codecov Report

Attention: Patch coverage is 95.45455% with 1 line in your changes missing coverage. Please review.

Project coverage is 54.81%. Comparing base (988c6fd) to head (e7d61a7).
Report is 26 commits behind head on master.

Files with missing lines Patch % Lines
website/src/views/settings/SettingsContainer.tsx 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3842      +/-   ##
==========================================
+ Coverage   54.52%   54.81%   +0.28%     
==========================================
  Files         274      276       +2     
  Lines        6076     6132      +56     
  Branches     1455     1470      +15     
==========================================
+ Hits         3313     3361      +48     
- Misses       2763     2771       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@zehata
Copy link
Contributor Author

zehata commented Oct 23, 2024

I have noted the codecov report and will work on those. However, it should not impact the implementation.
Fixed by 9be978c and bd7c8aa

@zehata zehata changed the title Zehata/website module page/3202/toggleable left to right prerequisites trees Toggleable left to right prerequisites trees Oct 24, 2024
@zehata
Copy link
Contributor Author

zehata commented Oct 26, 2024

bd7c8aa is technically outside the scope of this PR, but if it makes codecov happy then so be it.

@ravern
Copy link
Member

ravern commented Oct 30, 2024

Hi @zehata, thank you for your contribution!

I think that for backwards compatibility, we would definitely want the toggle. Can I check that means you intend for #3842 to be reviewed and to eventually just close #3840?

Let me know here and I'll review accordingly.

@zehata
Copy link
Contributor Author

zehata commented Oct 30, 2024

I think that for backwards compatibility, we would definitely want the toggle. Can I check that means you intend for #3842 to be reviewed and to eventually just close #3840?

@ravern yup! I think it would be nice to give the user a choice

Copy link
Member

@zwliew zwliew left a comment

Choose a reason for hiding this comment

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

Great job on this! Just some minor review comments and this should be good to go :)

I understand that it's been a while since you submitted the change -- would you like to continue working on this PR? If not, I could make the requested changes and merge it for you.

@@ -40,6 +41,7 @@ const defaultSettingsState: SettingsState = {
moduleTableOrder: 'exam',
beta: false,
loadDisqusManually: false,
prereqTreeOnLeft: true,
Copy link
Member

Choose a reason for hiding this comment

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

Can we retain the original behaviour and set this to false? I don't think it's a great idea to change the default.

@@ -92,3 +92,11 @@ export function setLoadDisqusManually(status: boolean) {
payload: status,
};
}

export const TOGGLE_PREREQ_TREE_DIRECTION = 'TOGGLE_PREREQ_TREE_DIRECTION' as const;
export function togglePreReqTreeDirection(status: boolean) {
Copy link
Member

Choose a reason for hiding this comment

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

Could you rename status to something more informative like isOnLeft? It might also be better to rename togglePreReqTreeDirection to setPreReqTreeOnLeft

<>{reverse ? [...children].reverse() : children}</>
);

export default ConditionalReverse;
Copy link
Member

Choose a reason for hiding this comment

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

Let's memoize this component with React.memo


getModuleCondensed: (moduleCode: ModuleCode) => ModuleCondensed | undefined;
};

interface TreeDisplay {
layer: number;
node: PrereqTree;
isPrereq?: boolean;
prereqTreeOnLeft?: boolean;
Copy link
Member

@zwliew zwliew Dec 4, 2024

Choose a reason for hiding this comment

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

Could you give prereqTreeOnLeft a default value (i.e. false) where necessary instead of leaving it as undefined? I personally don't like having unnecessarily-possibly-undefined values.

@@ -83,39 +85,45 @@ const unwrapLayer = (node: PrereqTree) => {
const Branch: React.FC<{
nodes: PrereqTree[];
layer: number;
prereqTreeOnLeft?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

Same comment as above above giving prereqTreeOnLeft a default value.

@zwliew zwliew self-assigned this Dec 4, 2024
@zwliew zwliew changed the title Toggleable left to right prerequisites trees website: Switch between LTR and RTL prereq tree directions Dec 16, 2024
Copy link
Member

@zwliew zwliew left a comment

Choose a reason for hiding this comment

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

I went ahead and made the requested changes. Thanks for your contribution! Also appreciate you adding the tests

@zwliew zwliew merged commit 65aa3cb into nusmodifications:master Dec 16, 2024
5 of 6 checks passed
@zehata
Copy link
Contributor Author

zehata commented Dec 16, 2024

@zwliew MB, sorry about that, I was not paying attention to the PR because I thought it was exam seasons 😅

GH also didn't ping me on your comments, so I would have to sort out my notifs.

@zwliew
Copy link
Member

zwliew commented Dec 16, 2024

@zwliew MB, sorry about that, I was not paying attention to the PR because I thought it was exam seasons 😅

GH also didn't ping me on your comments, so I would have to sort out my notifs.

It's all good!

@zwliew
Copy link
Member

zwliew commented Dec 16, 2024

@zehata Oh also -- do join the NUSMods Telegram group that's listed on TeleNUS if you'd like to discuss development in the future :)

@zehata
Copy link
Contributor Author

zehata commented Dec 16, 2024

@zehata Oh also -- do join the NUSMods Telegram group that's listed on TeleNUS if you'd like to discuss development in the future :)

Thanks! I have already joined haha

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.

Prerequisite tree right-to-left progression is confusing
3 participants