Skip to content

Sort Device Management devices list by most recent timestamp first#95316

Merged
arosiclair merged 2 commits into
mainfrom
claude-sortDeviceManagementList
Jul 6, 2026
Merged

Sort Device Management devices list by most recent timestamp first#95316
arosiclair merged 2 commits into
mainfrom
claude-sortDeviceManagementList

Conversation

@MelvinBot

@MelvinBot MelvinBot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

The Device Management screen was rendering devices in an arbitrary order because getDeviceLogins returned Object.values(logins).filter(...) without any sort, so the list reflected object key order rather than recency.

This change sorts the filtered device logins descending by getLastLogin — the same timestamp already displayed in each row (which is the later of lastLogin/created, so it handles the default 2008-01-01 lastLogin fallback) — so the most recently used/added device appears first. Sorting lives in the getDeviceLogins selector, keeping the sort out of the render path and reused by every consumer. lastLogin/created are ISO datetime strings, so a plain lexicographic comparison sorts them chronologically (and avoids the prefer-locale-compare-from-context rule, since a util cannot use the useLocalize hook).

Fixed Issues

$ #95307
PROPOSAL: #95307 (comment)

Tests

  1. Sign in on an account with more than one active device/session.
  2. Go to Settings → Security → Device Management.
  3. Verify the device list is ordered with the most recently used/added device at the top (descending by the relative timestamp shown on each row).

Offline tests

Same as tests.

QA Steps

Same as Tests

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

🤖 Automated AI checks run locally on the changed files (src/libs/UserUtils.ts, tests/unit/UserUtilsTest.ts):

  • npm run fmt (oxfmt) — ✅ clean
  • npm run lint-changed (eslint) — ✅ clean
  • npm run typecheck-tsgo — ✅ clean
  • npm test tests/unit/UserUtilsTest.ts — ✅ 11 passed (includes 3 new getDeviceLogins sort tests)

MelvinBot and others added 2 commits July 4, 2026 04:01
Co-authored-by: cretadn22 <cretadn22@users.noreply.github.com>
Co-authored-by: cretadn22 <cretadn22@users.noreply.github.com>
@MelvinBot MelvinBot requested a review from a team July 4, 2026 04:05
@MelvinBot

Copy link
Copy Markdown
Contributor Author

I created this PR from an upstream branch since I don't have push access to your fork.

To take ownership of this branch and be able to push updates, run:

git remote add upstream https://github.com/Expensify/App.git
git fetch upstream claude-sortDeviceManagementList
git checkout -b claude-sortDeviceManagementList upstream/claude-sortDeviceManagementList
git push -u origin claude-sortDeviceManagementList

Then you can close this PR and open a new one from your fork.

@codecov

codecov Bot commented Jul 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/libs/UserUtils.ts 82.79% <85.71%> (+4.63%) ⬆️
... and 12 files with indirect coverage changes

@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 I looked into the failing checks. No code fix is needed — nothing is actually broken by this PR.

The only failing check is PR Author Checklist / checklist, and it fails purely because the checklist boxes in the PR description aren't ticked (You completed 0 out of 41 checklist items). That's a human-only check — MelvinBot can't (and shouldn't) tick those boxes or fill in the Tests / QA Steps sections on a person's behalf.

To clear it, cretadn22 (co-author/assignee) needs to:

  • Fill out the ### Tests and ### QA Steps sections (they still have the // TODO placeholders).
  • Tick the boxes in the ### PR Author Checklist.

Everything else is green — all 28 automated code checks pass:

  • test (job 1–8), typecheck, ESLint check, Oxfmt check, Bun tests, Storybook tests, all build jobs, spellcheck, React Compiler Compliance, codecov, etc.

The two *-perf-tests (Reassure) checks were still running when I looked; they compare branch vs. baseline render performance and aren't affected by adding a .sort() to the getDeviceLogins selector, so I don't expect a regression from them.

Bottom line: there's nothing to push — the red X is the human checklist, not a code failure.

@cretadn22

Copy link
Copy Markdown
Contributor

@MelvinBot Mark this PR ready

@MelvinBot MelvinBot marked this pull request as ready for review July 4, 2026 04:18
@MelvinBot MelvinBot requested a review from a team as a code owner July 4, 2026 04:18
@melvin-bot melvin-bot Bot requested review from cretadn22 and trjExpensify and removed request for a team July 4, 2026 04:18
@melvin-bot

melvin-bot Bot commented Jul 4, 2026

Copy link
Copy Markdown

@cretadn22 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 Done — this PR is now marked Ready for review.

One heads-up before reviewers dig in: the ### Tests, ### QA Steps, and ### PR Author Checklist sections still have their // TODO placeholders and unchecked boxes. Those are human-only sections that I can't fill out on your behalf — please complete them so reviewers have the testing steps and checklist they need.

@cretadn22

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp Screenshot 2026-07-04 at 11 34 57
Android: mWeb Chrome Screenshot 2026-07-04 at 11 32 49
iOS: HybridApp Screenshot 2026-07-04 at 11 32 14
iOS: mWeb Safari Screenshot 2026-07-04 at 11 30 21
MacOS: Chrome / Safari Screenshot 2026-07-04 at 11 27 45

@melvin-bot melvin-bot Bot requested a review from arosiclair July 4, 2026 04:36
@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 Re-checked — all 35 automated code checks are now green (the perf-test checks that were still running earlier all passed). There's still nothing to push.

The single remaining ❌ is PR Author Checklist / checklist, which is a human-only check — it fails only because the checklist boxes in the PR description aren't ticked (0 out of 41 checklist items). MelvinBot can't complete those on your behalf.

To turn everything green, cretadn22 (co-author/assignee) needs to:

  • Fill in the ### Tests and ### QA Steps sections (currently // TODO placeholders).
  • Tick the boxes under ### PR Author Checklist.

@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 Re-checked — all automated checks are now green (the two Reassure *-perf-tests that were still running earlier have both passed). Nothing to push.

The single remaining red ❌ is PR Author Checklist / checklist, which fails only because the checklist boxes in the PR description aren't ticked (0 out of 41 items). That's a human-only check — MelvinBot can't tick those boxes or fill in the Tests / QA Steps sections on a person's behalf.

To turn it green, cretadn22 needs to:

  • Fill in the ### Tests and ### QA Steps sections (still showing the // TODO placeholders).
  • Tick the boxes in the ### PR Author Checklist.

There's no code failure here, so there's nothing for me to fix or push.

@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 Re-checked — still no code fix to push. Every automated check is now green (the two Reassure *-perf-tests that were running earlier have since passed).

The one red X is PR Author Checklist / checklist, which fails only because the checklist boxes in the PR description aren't ticked (0 out of 41 checklist items). That's a human-only gate — I can't tick those boxes or fill in the Tests / QA Steps sections on someone's behalf.

To turn it green, cretadn22 (co-author/assignee) needs to:

  • Replace the // TODO placeholders in the ### Tests and ### QA Steps sections with the steps you ran.
  • Tick the boxes in the ### PR Author Checklist.

Nothing in the code is failing, so there's nothing for me to commit.

@arosiclair arosiclair merged commit bb5dbec into main Jul 6, 2026
44 of 48 checks passed
@arosiclair arosiclair deleted the claude-sortDeviceManagementList branch July 6, 2026 13:02
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

🚧 arosiclair has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

OSBotify commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify

OSBotify commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/arosiclair in version: 9.4.28-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 Reviewed the changes and yes, a small help site update is warranted.

This PR sorts the Device management list so the most recently used/added device appears first (UserUtils.ts getDeviceLogins). The existing article Manage-Logged-in-Devices.md documents the device list but never mentioned its ordering, so I added one sentence noting the list is ordered by most recent activity. No other help site articles reference the device list order.

Draft help site PR: #95411

@cretadn22, please review the linked help site PR and confirm it reflects the current behavior. Then mark the linked help site PR Ready for review

@OSBotify

OSBotify commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/mountiny in version: 9.4.28-2 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

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.

4 participants