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

fix: class item conflict indicator correct severity #330

Merged

Conversation

tomaspalma
Copy link
Member

It changes the logic inside ClassItem so that in cases like the one described in #313 the triangle shows red instead of yellow.

@tomaspalma tomaspalma self-assigned this Oct 17, 2024
@tomaspalma tomaspalma requested a review from a team October 17, 2024 23:18
Copy link

netlify bot commented Oct 17, 2024

Deploy Preview for tts-fe-preview ready!

Name Link
🔨 Latest commit 5c26622
🔍 Latest deploy log https://app.netlify.com/sites/tts-fe-preview/deploys/6728f2ee1d7e2500081249e2
😎 Deploy Preview https://deploy-preview-330--tts-fe-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@tomaspalma tomaspalma force-pushed the fix/conflict-triangle-not-showing-correct-severity branch 3 times, most recently from 69d57b1 to b7f7dae Compare October 18, 2024 08:56
Comment on lines +80 to +92
const classesConflictSeverity = (first: ClassInfo, second: ClassInfo): number => {
let maxSeverity = 0;

for (const slot of first.slots) {
for (const otherSlot of second.slots) {
if (schedulesConflict(slot, otherSlot)) {
maxSeverity = Math.max(maxSeverity, conflictsSeverity(slot, otherSlot));
}
}
}

return maxSeverity;
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const classesConflictSeverity = (first: ClassInfo, second: ClassInfo): number => {
let maxSeverity = 0;
for (const slot of first.slots) {
for (const otherSlot of second.slots) {
if (schedulesConflict(slot, otherSlot)) {
maxSeverity = Math.max(maxSeverity, conflictsSeverity(slot, otherSlot));
}
}
}
return maxSeverity;
}
const classesConflictSeverity = (first: ClassInfo, second: ClassInfo): number =>
first.slots.flatMap(slot =>
second.slots
.filter(otherSlot => schedulesConflict(slot, otherSlot))
.map(otherSlot => conflictsSeverity(slot, otherSlot))
).reduce((maxSeverity, severity) => Math.max(maxSeverity, severity), 0);

Because who needs friends when you have pure functions?

Copy link
Member Author

@tomaspalma tomaspalma Oct 18, 2024

Choose a reason for hiding this comment

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

I understand that the code you presented using a more functional paradigm has less lines but it becomes less readable and harder to debug because if we wanted to console log something inside one of the functions it would be a lot harder.

It is also harder because the majority of the people doesn't know well the workings of reduce.

Copy link
Member

Choose a reason for hiding this comment

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

That's why we should have PFL in the first year, ahaha

@tomaspalma tomaspalma force-pushed the fix/conflict-triangle-not-showing-correct-severity branch from b7f7dae to 5c26622 Compare November 4, 2024 16:14
@tomaspalma tomaspalma merged commit 3ca1d9f into develop Nov 4, 2024
5 checks passed
@tomaspalma tomaspalma deleted the fix/conflict-triangle-not-showing-correct-severity branch November 4, 2024 16:19
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.

2 participants