Skip to content

Commit

Permalink
feat(app): sort robot lists alphabetically (#14722)
Browse files Browse the repository at this point in the history
Closes EXEC-350

There is no current logic when presenting lists of robots on the Devices tab, sending protocols slideouts, etc. Sort robots alphabetically.
  • Loading branch information
mjhuff authored and Carlos-fernandez committed May 20, 2024
1 parent 5d58801 commit aa7f7ce
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
8 changes: 4 additions & 4 deletions app/src/redux/discovery/__tests__/selectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ describe('discovery selectors', () => {
name: 'getConnectableRobots grabs robots with connectable status',
selector: discovery.getConnectableRobots,
state: MOCK_STATE,
expected: [EXPECTED_FOO, EXPECTED_BAR, EXPECTED_FIZZBUZZ],
expected: [EXPECTED_BAR, EXPECTED_FIZZBUZZ, EXPECTED_FOO],
},
{
name: 'getReachableRobots grabs robots with reachable status',
Expand All @@ -314,7 +314,7 @@ describe('discovery selectors', () => {
name: 'getUnreachableRobots grabs robots with unreachable status',
selector: discovery.getUnreachableRobots,
state: MOCK_STATE,
expected: [EXPECTED_FIZZ, EXPECTED_BUZZ],
expected: [EXPECTED_BUZZ, EXPECTED_FIZZ],
},
{
name: 'display name removes opentrons- from connectable robot names',
Expand Down Expand Up @@ -412,10 +412,10 @@ describe('discovery selectors', () => {
selector: discovery.getViewableRobots,
state: MOCK_STATE,
expected: [
EXPECTED_FOO,
EXPECTED_BAR,
EXPECTED_FIZZBUZZ,
EXPECTED_BAZ,
EXPECTED_FIZZBUZZ,
EXPECTED_FOO,
EXPECTED_QUX,
],
},
Expand Down
35 changes: 30 additions & 5 deletions app/src/redux/discovery/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import concat from 'lodash/concat'
import head from 'lodash/head'
import isEqual from 'lodash/isEqual'
import find from 'lodash/find'
import orderBy from 'lodash/orderBy'
import { createSelector, createSelectorCreator, defaultMemoize } from 'reselect'
import semver from 'semver'

Expand Down Expand Up @@ -149,31 +150,55 @@ export const getDiscoveredRobots: (

export const getConnectableRobots: GetConnectableRobots = createSelector(
getDiscoveredRobots,
robots => robots.flatMap(r => (r.status === CONNECTABLE ? [r] : []))
robots =>
orderBy(
robots.flatMap(r => (r.status === CONNECTABLE ? [r] : [])),
[robot => robot.displayName.toLowerCase()],
['asc']
)
)

export const getReachableRobots: GetReachableRobots = createSelector(
getDiscoveredRobots,
robots => robots.flatMap(r => (r.status === REACHABLE ? [r] : []))
robots =>
orderBy(
robots.flatMap(r => (r.status === REACHABLE ? [r] : [])),
[robot => robot.displayName.toLowerCase()],
['asc']
)
)

export const getUnreachableRobots: GetUnreachableRobots = createSelector(
getDiscoveredRobots,
robots => robots.flatMap(r => (r.status === UNREACHABLE ? [r] : []))
robots =>
orderBy(
robots.flatMap(r => (r.status === UNREACHABLE ? [r] : [])),
[robot => robot.displayName.toLowerCase()],
['asc']
)
)

export const getAllRobots: GetAllRobots = createSelector(
getConnectableRobots,
getReachableRobots,
getUnreachableRobots,
(cr: DiscoveredRobot[], rr: DiscoveredRobot[], ur: DiscoveredRobot[]) =>
concat<DiscoveredRobot>(cr, rr, ur)
orderBy(
concat<DiscoveredRobot>(cr, rr, ur),
[robot => robot.displayName.toLowerCase()],
['asc']
)
)

export const getViewableRobots: GetViewableRobots = createSelector(
getConnectableRobots,
getReachableRobots,
(cr: ViewableRobot[], rr: ViewableRobot[]) => concat<ViewableRobot>(cr, rr)
(cr: ViewableRobot[], rr: ViewableRobot[]) =>
orderBy(
concat<ViewableRobot>(cr, rr),
[robot => robot.displayName.toLowerCase()],
['asc']
)
)

export const getLocalRobot: GetLocalRobot = createSelector(
Expand Down

0 comments on commit aa7f7ce

Please sign in to comment.