|
1 | 1 | import type { DeviceModelV1 } from '@seamapi/types/devicedb' |
| 2 | +import { useMemo } from 'react' |
2 | 3 |
|
3 | 4 | import { SupportedDeviceFilterResultRow } from 'lib/seam/components/SupportedDeviceTable/SupportedDeviceFilterResultRow.js' |
4 | 5 | import { SupportedDeviceManufacturerSection } from 'lib/seam/components/SupportedDeviceTable/SupportedDeviceManufacturerSection.js' |
@@ -33,6 +34,11 @@ export function SupportedDeviceContent({ |
33 | 34 | } |
34 | 35 | ) |
35 | 36 |
|
| 37 | + const groupedDeviceModels = useMemo( |
| 38 | + () => groupDeviceModelsByManufacturer(deviceModels ?? []), |
| 39 | + [deviceModels] |
| 40 | + ) |
| 41 | + |
36 | 42 | if (isLoading) { |
37 | 43 | return ( |
38 | 44 | <div className='seam-supported-device-table-content-state-block'> |
@@ -91,15 +97,22 @@ export function SupportedDeviceContent({ |
91 | 97 |
|
92 | 98 | return ( |
93 | 99 | <> |
94 | | - {Object.entries(groupDeviceModelsByManufacturer(deviceModels)).map( |
95 | | - ([manufacturerId, models]) => ( |
96 | | - <SupportedDeviceManufacturerSection |
97 | | - key={manufacturerId} |
98 | | - manufacturerId={manufacturerId} |
99 | | - deviceModels={models} |
100 | | - /> |
| 100 | + {Object.entries(groupedDeviceModels) |
| 101 | + .sort( |
| 102 | + (e1, e2) => |
| 103 | + e1[1][0]?.manufacturer.display_name.localeCompare( |
| 104 | + e2[1][0]?.manufacturer.display_name ?? '' |
| 105 | + ) ?? 0 |
101 | 106 | ) |
102 | | - )} |
| 107 | + .map(([manufacturerId, models]) => { |
| 108 | + return ( |
| 109 | + <SupportedDeviceManufacturerSection |
| 110 | + key={manufacturerId} |
| 111 | + manufacturerId={manufacturerId} |
| 112 | + deviceModels={models} |
| 113 | + /> |
| 114 | + ) |
| 115 | + })} |
103 | 116 | </> |
104 | 117 | ) |
105 | 118 | } |
@@ -136,9 +149,9 @@ function EmptyResult({ |
136 | 149 | ) |
137 | 150 | } |
138 | 151 |
|
139 | | -function groupDeviceModelsByManufacturer( |
| 152 | +const groupDeviceModelsByManufacturer = ( |
140 | 153 | deviceModels: UseDeviceModelsData |
141 | | -): Record<string, DeviceModelV1[]> { |
| 154 | +): Record<string, DeviceModelV1[]> => { |
142 | 155 | const result: Record<string, DeviceModelV1[]> = {} |
143 | 156 |
|
144 | 157 | for (const model of deviceModels) { |
|
0 commit comments