Skip to content

Conversation

@irenekim21
Copy link
Contributor

@irenekim21 irenekim21 commented Jan 19, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Improved sort-order persistence by synchronizing the UI selection with the page URL and local storage so user preferences remain consistent across navigations and sessions.
  • Tests

    • Cleaned up test imports to remove duplication and streamline test files.

✏️ Tip: You can customize this high-level summary in your review settings.

@linear
Copy link

linear bot commented Jan 19, 2026

@irenekim21 irenekim21 requested a review from edmonday January 19, 2026 01:34
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 19, 2026

Walkthrough

Initializes and syncs JourneyList sortOrder from URL query (sortBy) or localStorage, adds a handler to update state, push a shallow route change, and persist to localStorage; replaces direct setter passed to JourneyListView.

Changes

Cohort / File(s) Summary
Sort Order Synchronization
apps/journeys-admin/src/components/JourneyList/JourneyList.tsx
Adds effect to read sortBy from URL or localStorage and set sortOrder; introduces handleSetSortOrder to update state, perform a shallow router push with the new query param, and persist to localStorage; replaces direct setter passed to JourneyListView.
Test import cleanup
apps/journeys-admin/src/components/Editor/Slider/.../VideoListItem/VideoListItem.spec.tsx
Removes duplicate import and consolidates VideoBlockSource import placement; no behavior changes.

Sequence Diagram(s)

sequenceDiagram
    participant Browser
    participant JourneyList
    participant Router
    participant LocalStorage
    participant JourneyListView

    Browser->>JourneyList: Mount component (URL query?)
    JourneyList->>LocalStorage: read stored sortOrder
    alt URL has sortBy
        JourneyList->>JourneyList: set sortOrder from URL
    else stored value only
        JourneyList->>Router: shallow push with sortBy (persist URL)
        Router-->>Browser: update URL (shallow)
    end
    JourneyList->>LocalStorage: persist current sortOrder
    JourneyList->>JourneyListView: pass sortOrder and handleSetSortOrder
    JourneyListView->>JourneyList: user changes sortOrder (via handler)
    JourneyList->>Router: shallow push updated sortBy
    JourneyList->>LocalStorage: persist updated sortOrder
    Router-->>Browser: update URL (shallow)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • edmonday
🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'feat: sort journeys in order' is vague and doesn't clearly convey the main change, which is persisting sort order selection across sessions via URL and localStorage. Consider a more specific title like 'feat: persist journey sort order in URL and localStorage' to better reflect that the change is about remembering user's sort selection.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch irenekim/nes-465-sort-by-order-should-remember-last-selection-and-not-switch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@irenekim21 irenekim21 requested a review from jianwei1 January 19, 2026 01:34
@irenekim21 irenekim21 self-assigned this Jan 19, 2026
@nx-cloud
Copy link

nx-cloud bot commented Jan 19, 2026

🤖 Nx Cloud AI Fix Eligible

An automatically generated fix could have helped fix failing tasks for this run, but Self-healing CI is disabled for this workspace. Visit workspace settings to enable it and get automatic fixes in future runs.

To disable these notifications, a workspace admin can disable them in workspace settings.


View your CI Pipeline Execution ↗ for commit 3ee92e2

Command Status Duration Result
nx run-many --target=deploy --projects=journeys... ❌ Failed 1m 7s View ↗

☁️ Nx Cloud last updated this comment at 2026-01-22 01:24:13 UTC

@github-actions github-actions bot requested a deployment to Preview - journeys-admin January 19, 2026 01:37 Pending
@github-actions github-actions bot temporarily deployed to Preview - journeys-admin January 19, 2026 01:39 Inactive
@github-actions
Copy link
Contributor

github-actions bot commented Jan 19, 2026

The latest updates on your projects.

Name Status Preview Updated (UTC)
journeys-admin ✅ Ready journeys-admin preview Thu Jan 22 11:11:05 NZDT 2026

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@apps/journeys-admin/src/components/JourneyList/JourneyList.tsx`:
- Around line 45-65: The current useEffect uses router.query.sortBy with "||"
which allows an invalid value or string[] to override localStorage; change the
logic in the useEffect to first validate router.query.sortBy is a single string
and a member of SortOrder before using it, otherwise fall back to the
localStorage value from localStorage.getItem('journeyListSortBy'); then call
setSortOrder only with a validated SortOrder value, and only write to
localStorage or call router.replace when the validated source (query or storage)
is used; reference router.query.sortBy, SortOrder, setSortOrder,
localStorage.getItem('journeyListSortBy'), and router.replace to locate and
update the logic.
🧹 Nitpick comments (1)
apps/journeys-admin/src/components/JourneyList/JourneyList.tsx (1)

67-83: Avoid mimicking functional-updater semantics if you don’t implement them.

handleSetSortOrder accepts a functional updater but evaluates it against the render-time sortOrder, which can be stale if multiple updates are queued. If JourneyListView never uses the function form, consider simplifying the signature; otherwise, move the router/localStorage sync to a useEffect driven by sortOrder and pass the updater through untouched.

Comment on lines +45 to +65
useEffect(() => {
if (!router.isReady) return
const sortByFromQuery = router.query.sortBy as string
const sortByFromStorage =
typeof window !== 'undefined'
? localStorage.getItem('journeyListSortBy')
: null
const sortBy = sortByFromQuery || sortByFromStorage
if (sortBy && Object.values(SortOrder).includes(sortBy as SortOrder)) {
setSortOrder((prev) => (prev !== sortBy ? (sortBy as SortOrder) : prev))
if (sortByFromQuery && typeof window !== 'undefined') {
localStorage.setItem('journeyListSortBy', sortByFromQuery)
} else if (sortByFromStorage && !sortByFromQuery) {
void router.replace(
{ query: { ...router.query, sortBy: sortByFromStorage } },
undefined,
{ shallow: true }
)
}
}
}, [router.isReady, router.query.sortBy, router])
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Validate the query param before it overrides stored sort.

sortByFromQuery can be a string[] or an invalid value. Because it’s used with ||, an invalid query string (or array) blocks a valid localStorage fallback, leaving sortOrder unset. Consider validating the query first, and only falling back to storage when the query is absent/invalid.

🛠️ Suggested fix
-    const sortByFromQuery = router.query.sortBy as string
+    const rawSortBy = router.query.sortBy
+    const sortByFromQuery = Array.isArray(rawSortBy) ? rawSortBy[0] : rawSortBy
     const sortByFromStorage =
       typeof window !== 'undefined'
         ? localStorage.getItem('journeyListSortBy')
         : null
-    const sortBy = sortByFromQuery || sortByFromStorage
-    if (sortBy && Object.values(SortOrder).includes(sortBy as SortOrder)) {
-      setSortOrder((prev) => (prev !== sortBy ? (sortBy as SortOrder) : prev))
+    const isValidSort = (value?: string | null): value is SortOrder =>
+      !!value && Object.values(SortOrder).includes(value as SortOrder)
+    const sortBy = isValidSort(sortByFromQuery)
+      ? sortByFromQuery
+      : isValidSort(sortByFromStorage)
+        ? sortByFromStorage
+        : undefined
+    if (sortBy) {
+      setSortOrder((prev) => (prev !== sortBy ? sortBy : prev))
       if (sortByFromQuery && typeof window !== 'undefined') {
         localStorage.setItem('journeyListSortBy', sortByFromQuery)
       } else if (sortByFromStorage && !sortByFromQuery) {
🤖 Prompt for AI Agents
In `@apps/journeys-admin/src/components/JourneyList/JourneyList.tsx` around lines
45 - 65, The current useEffect uses router.query.sortBy with "||" which allows
an invalid value or string[] to override localStorage; change the logic in the
useEffect to first validate router.query.sortBy is a single string and a member
of SortOrder before using it, otherwise fall back to the localStorage value from
localStorage.getItem('journeyListSortBy'); then call setSortOrder only with a
validated SortOrder value, and only write to localStorage or call router.replace
when the validated source (query or storage) is used; reference
router.query.sortBy, SortOrder, setSortOrder,
localStorage.getItem('journeyListSortBy'), and router.replace to locate and
update the logic.

@github-actions github-actions bot temporarily deployed to Preview - journeys-admin January 21, 2026 02:28 Inactive
@github-actions github-actions bot temporarily deployed to Preview - journeys-admin January 21, 2026 03:02 Inactive
@github-actions github-actions bot temporarily deployed to Preview - journeys-admin January 21, 2026 21:42 Inactive
@github-actions github-actions bot requested a deployment to Preview - journeys-admin January 21, 2026 22:00 Pending
@github-actions github-actions bot temporarily deployed to Preview - journeys-admin January 21, 2026 22:05 Inactive
@github-actions github-actions bot had a problem deploying to Preview - journeys-admin January 22, 2026 01:21 Failure
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