Skip to content

fix: reduce side effect logic#2580

Open
duidae wants to merge 3 commits into
instructure:masterfrom
duidae:fix/fix_side_effect_loop
Open

fix: reduce side effect logic#2580
duidae wants to merge 3 commits into
instructure:masterfrom
duidae:fix/fix_side_effect_loop

Conversation

@duidae

@duidae duidae commented Jan 29, 2026

Copy link
Copy Markdown
  1. filter() should be a pure function, adding extra logic inside filter() could lead to unexpected behavior/bug, so did a small refinement to it
  2. minor codebase refinement
    thanks!

@dustin-cowles

Copy link
Copy Markdown
Contributor

Looks good to me, if you can get the conflicts resolved I can submit it to the owning team for review.

@duidae duidae force-pushed the fix/fix_side_effect_loop branch from 83de3f3 to 28ea30f Compare March 13, 2026 02:41
@duidae

duidae commented Mar 13, 2026

Copy link
Copy Markdown
Author

@dustin-cowles conflicts are fixed, please have a look & thanks! 🙂

@CLAassistant

CLAassistant commented Apr 23, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors course-list processing in the Inbox UI to avoid side effects during array filtering and does a small cleanup to reduce magic-string usage around the “All Courses” option.

Changes:

  • Refactor course separation logic to use a single reduce pass instead of mutating an external array inside filter().
  • Introduce constants in CourseSelect to avoid repeated string literals for the “allCourses” group key and “all_courses” id comparisons.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
ui/features/inbox/react/containers/MessageListActionContainer.tsx Replaces side-effectful filter + external mutation with reduce to split concluded vs non-concluded courses.
ui/features/inbox/react/components/CourseSelect/CourseSelect.tsx Adds constants for the “All Courses” key/id to reduce magic strings and improve consistency.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +71 to +81
const { concludedCourses, moreCourses } = uniqueCourses.reduce(
(acc, course) => {
if (course.concluded === true) {
acc.concludedCourses.push(course)
} else {
acc.moreCourses.push(course)
}
return acc
},
{ concludedCourses: [], moreCourses: [] }
)

Copilot AI Apr 24, 2026

Copy link

Choose a reason for hiding this comment

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

The reduce accumulator initializer uses empty array literals ({ concludedCourses: [], moreCourses: [] }). Under this repo’s strict TS settings, those often infer as never[], which makes the subsequent .push(course) lines type-error. Add an explicit accumulator type (or cast the empty arrays to the appropriate element type) so push is type-safe and avoids implicit never[] inference.

Copilot uses AI. Check for mistakes.
if (key === 'allCourses') {
// if provided, allCourses should always be present
if (key === ALL_COURSES_KEY) {
// if provided, ALL_COURSES_KEY should always be present

Copilot AI Apr 24, 2026

Copy link

Choose a reason for hiding this comment

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

The inline comment refers to the constant name (ALL_COURSES_KEY) rather than the actual option group (allCourses), which is a bit unclear to readers. Consider rewording it to describe the behavior (e.g., that the “All Courses” group should always be included when present) without referencing the internal constant name.

Suggested change
// if provided, ALL_COURSES_KEY should always be present
// Always include the "All Courses" group when it is provided.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants