mirror of
https://github.com/bitwarden/browser
synced 2026-02-24 00:23:17 +00:00
Creates a new `DeviceManagementComponent` that fetches devices and formats them before handing them off to a view component for display. View components: - `DeviceManagementTableComponent` - displays on medium to large screens - `DeviceManagementItemGroupComponent` - displays on small screens Feature flag: `PM14938_BrowserExtensionLoginApproval`
54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import { DevicePendingAuthRequest } from "@bitwarden/common/auth/abstractions/devices/responses/device.response";
|
|
|
|
import { DeviceDisplayData } from "./device-management.component";
|
|
|
|
export function clearAuthRequestAndResortDevices(
|
|
devices: DeviceDisplayData[],
|
|
pendingAuthRequest: DevicePendingAuthRequest,
|
|
): DeviceDisplayData[] {
|
|
return devices
|
|
.map((device) => {
|
|
if (device.pendingAuthRequest?.id === pendingAuthRequest.id) {
|
|
device.pendingAuthRequest = null;
|
|
device.loginStatus = "";
|
|
}
|
|
return device;
|
|
})
|
|
.sort(resortDevices);
|
|
}
|
|
|
|
/**
|
|
* After a device is approved/denied, it will still be at the beginning of the array,
|
|
* so we must resort the array to ensure it is in the correct order.
|
|
*
|
|
* This is a helper function that gets passed to the `Array.sort()` method
|
|
*/
|
|
function resortDevices(deviceA: DeviceDisplayData, deviceB: DeviceDisplayData) {
|
|
// Devices with a pending auth request should be first
|
|
if (deviceA.pendingAuthRequest) {
|
|
return -1;
|
|
}
|
|
if (deviceB.pendingAuthRequest) {
|
|
return 1;
|
|
}
|
|
|
|
// Next is the current device
|
|
if (deviceA.isCurrentDevice) {
|
|
return -1;
|
|
}
|
|
if (deviceB.isCurrentDevice) {
|
|
return 1;
|
|
}
|
|
|
|
// Then sort the rest by display name (alphabetically)
|
|
if (deviceA.displayName < deviceB.displayName) {
|
|
return -1;
|
|
}
|
|
if (deviceA.displayName > deviceB.displayName) {
|
|
return 1;
|
|
}
|
|
|
|
// Default
|
|
return 0;
|
|
}
|