Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions cypress/e2e/integration/device/paging.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,6 @@ describe('Test Device Page', () => {
body: devices.getAll.forPaging.response
}).as('get-devices')

cy.myIntercept('GET', 'api/v1/devices/stats', {
statusCode: httpCodes.SUCCESS,
body: {
totalCount: deviceFixtures.totalCount,
connectedCount: 0,
disconnectedCount: 0,
activatedCount: 0,
discoveredCount: 0
}
}).as('get-device-stats')

cy.myIntercept('GET', /tags$/, {
statusCode: httpCodes.SUCCESS,
body: tags.getAll.success.response
Expand All @@ -42,7 +31,6 @@ describe('Test Device Page', () => {
}).as('get-powerstate')

cy.goToPage('Devices')
cy.wait('@get-device-stats')
})

it('pagination for next page', () => {
Expand Down
30 changes: 21 additions & 9 deletions src/app/devices/devices.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@

<mat-card>
<mat-card-content>
<!-- Tabs must stay visible even when the active tab has zero rows, otherwise
the user has no way to switch to a tab that does have data. -->
<mat-tab-group (selectedTabChange)="onTabChange($event.index)">
<mat-tab [label]="allTabLabel"></mat-tab>
<mat-tab [label]="activatedTabLabel"></mat-tab>
<mat-tab [label]="discoveredTabLabel"></mat-tab>
</mat-tab-group>
@if (!isCloudMode) {
<!-- Tabs must stay visible even when the active tab has zero rows, otherwise
the user has no way to switch to a tab that does have data. -->
<mat-tab-group (selectedTabChange)="onTabChange($event.index)">
<mat-tab [label]="allTabLabel"></mat-tab>
<mat-tab [label]="activatedTabLabel"></mat-tab>
<mat-tab [label]="discoveredTabLabel"></mat-tab>
</mat-tab-group>
}
@if (isNoData()) {
<h3 class="flex justify-center">
@if (!filteredTags().length) {
Expand Down Expand Up @@ -101,7 +103,7 @@ <h3 class="flex justify-center">
</mat-header-cell>
<mat-cell *matCellDef="let element" (click)="navigateTo(element.guid)">
{{ element.hostname }}
@if (element.friendlyName !== null) {
@if (element.friendlyName) {
<span>&nbsp;({{ element.friendlyName }})</span>
}
</mat-cell>
Expand Down Expand Up @@ -132,7 +134,17 @@ <h3 class="flex justify-center">
<!-- not sortable: productType is computed, not a real Device property -->
<mat-header-cell *matHeaderCellDef>{{ 'devices.table.productType.value' | translate }}</mat-header-cell>
<mat-cell *matCellDef="let element" (click)="navigateTo(element.guid)">
{{ getProductType(element) }}
<span class="product-type-chip">{{ getProductType(element) }}</span>
</mat-cell>
</ng-container>
<!-- deviceType Column -->
<ng-container matColumnDef="deviceType">
<!-- not sortable: deviceType is computed, not a real Device property -->
<mat-header-cell *matHeaderCellDef>{{ 'devices.table.type.value' | translate }}</mat-header-cell>
<mat-cell *matCellDef="let element" (click)="navigateTo(element.guid)">
<span class="device-type-chip" [class.activated]="getDeviceType(element) === 'activated'">
{{ 'devices.tabs.' + getDeviceType(element) + '.value' | translate }}
</span>
</mat-cell>
</ng-container>
<!-- tags Column -->
Expand Down
19 changes: 19 additions & 0 deletions src/app/devices/devices.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,25 @@
flex: 0 0 75px;
}

.product-type-chip,
.device-type-chip {
display: inline-flex;
align-items: center;
min-height: 30px;
padding: 0 12px;
border-radius: 16px;
background: #e5e5e5;
}

.device-type-chip {
background: #b0bec5;
}

.device-type-chip.activated {
background: #0277bd;
color: #fff;
}
Comment thread
Copilot marked this conversation as resolved.

mat-icon.addTag {
visibility: hidden;
}
Expand Down
27 changes: 27 additions & 0 deletions src/app/devices/devices.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,35 @@ describe('DevicesComponent', () => {
})
})

describe('getDeviceType', () => {
it('should return activated for a real AMT control mode', () => {
const device = { ...device01, deviceInfo: { currentMode: 'client control mode' } } as Device
expect(component.getDeviceType(device)).toBe('activated')
})

it('should return discovered when the device is not activated', () => {
const device = { ...device01, deviceInfo: { currentMode: 'not activated' } } as Device
expect(component.getDeviceType(device)).toBe('discovered')
})

it('should return discovered when currentMode is missing', () => {
const device = { ...device01, deviceInfo: undefined } as Device
expect(component.getDeviceType(device)).toBe('discovered')
})

it('should keep the computed device type logic stable for rendering', () => {
const activatedDevice = { ...device01, deviceInfo: { currentMode: 'client control mode' } } as Device
const discoveredDevice = { ...device02, deviceInfo: { currentMode: 'not activated' } } as Device

expect(component.getDeviceType(activatedDevice)).toBe('activated')
expect(component.getDeviceType(discoveredDevice)).toBe('discovered')
})
})

describe('onTabChange / server-side counts', () => {
beforeEach(() => {
component.isCloudMode = false
component.getDevices()
getDevicesSpy.mockClear()
})

Expand Down
20 changes: 17 additions & 3 deletions src/app/devices/devices.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export class DevicesComponent implements OnInit, AfterViewInit {
'guid',
'status',
'productType',
'deviceType',
'tags',
'actions',
'notification'
Expand All @@ -221,6 +222,7 @@ export class DevicesComponent implements OnInit, AfterViewInit {
'select',
'hostname',
'productType',
'deviceType',
'tags',
'actions',
'notification'
Expand Down Expand Up @@ -283,10 +285,12 @@ export class DevicesComponent implements OnInit, AfterViewInit {

getDevices(): void {
this.isLoading.set(true)
let responseTotalCount: number | undefined

// Counts (all/activated/discovered) are computed server-side and shared with
// headless/API consumers, so refresh them alongside the current page.
this.loadStats()
if (!this.isCloudMode) {
// Console exposes server-side counts for the activated/discovered tabs.
this.loadStats()
}

// Store previous selection before making the request
const prevSelected = this.selectedDevices.selected.map((d) => d.guid)
Expand All @@ -295,6 +299,7 @@ export class DevicesComponent implements OnInit, AfterViewInit {
.getDevices({ ...this.pageEvent, tags: this.filteredTags(), status: this.currentTabStatus() })
.pipe(
switchMap((res) => {
responseTotalCount = res.totalCount
if (!environment.cloud) {
return of(res.data) // Return as-is for non-cloud
}
Expand Down Expand Up @@ -335,6 +340,10 @@ export class DevicesComponent implements OnInit, AfterViewInit {
)
.subscribe((devices) => {
this.devices.data = devices
if (this.isCloudMode) {
this.serverTotalCount = responseTotalCount ?? devices.length
this.totalCount.set(this.serverTotalCount)
}

// Restore selection state on data retrieval
this.selectedDevices.clear()
Expand Down Expand Up @@ -435,6 +444,11 @@ export class DevicesComponent implements OnInit, AfterViewInit {
return ''
}

getDeviceType(device: Device): DeviceFilterStatus {
const currentMode = device.deviceInfo?.currentMode?.trim().toLowerCase()
return currentMode && currentMode !== 'not activated' ? 'activated' : 'discovered'
}
Comment thread
ShradhaGupta31 marked this conversation as resolved.

translateConnectionStatus(status?: boolean): string {
switch (status) {
case false:
Expand Down
4 changes: 4 additions & 0 deletions src/assets/i18n/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,10 @@
"description": "Table column header for product type",
"value": "نوع المنتج"
},
"devices.table.type": {
"description": "Table column header for device type",
"value": "النوع"
},
"devices.table.tags": {
"description": "عنوان عمود الجدول للعلامات",
"value": "العلامات"
Expand Down
4 changes: 4 additions & 0 deletions src/assets/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,10 @@
"description": "Table column header for product type",
"value": "Produkttyp"
},
"devices.table.type": {
"description": "Table column header for device type",
"value": "Typ"
},
"devices.table.tags": {
"description": "Tabellen-Spaltenüberschrift für Tags",
"value": "Tags"
Expand Down
4 changes: 4 additions & 0 deletions src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,10 @@
"description": "Table column header for product type",
"value": "Product Type"
},
"devices.table.type": {
"description": "Table column header for device type",
"value": "Type"
},
"devices.table.tags": {
"description": "Table column header for tags",
"value": "Tags"
Expand Down
4 changes: 4 additions & 0 deletions src/assets/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,10 @@
"description": "Table column header for product type",
"value": "Tipo de producto"
},
"devices.table.type": {
"description": "Table column header for device type",
"value": "Tipo"
},
"devices.table.tags": {
"description": "Encabezado de columna de tabla para etiquetas",
"value": "Etiquetas"
Expand Down
4 changes: 4 additions & 0 deletions src/assets/i18n/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,10 @@
"description": "Table column header for product type",
"value": "Tuotetyyppi"
},
"devices.table.type": {
"description": "Table column header for device type",
"value": "Tyyppi"
},
"devices.table.tags": {
"description": "Taulukon sarakkeen otsikko tunnisteille",
"value": "Tunnisteet"
Expand Down
4 changes: 4 additions & 0 deletions src/assets/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,10 @@
"description": "Table column header for product type",
"value": "Type de produit"
},
"devices.table.type": {
"description": "Table column header for device type",
"value": "Type"
},
"devices.table.tags": {
"description": "En-tête de colonne du tableau pour les balises",
"value": "Balises"
Expand Down
4 changes: 4 additions & 0 deletions src/assets/i18n/he.json
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,10 @@
"description": "Table column header for product type",
"value": "סוג מוצר"
},
"devices.table.type": {
"description": "Table column header for device type",
"value": "סוג"
},
"devices.table.tags": {
"description": "כותרת עמודות טבלה לתגיות",
"value": "תגיות"
Expand Down
4 changes: 4 additions & 0 deletions src/assets/i18n/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,10 @@
"description": "Table column header for product type",
"value": "Tipo di prodotto"
},
"devices.table.type": {
"description": "Table column header for device type",
"value": "Tipo"
},
"devices.table.tags": {
"description": "Intestazione della colonna della tabella per i tag",
"value": "Tag"
Expand Down
4 changes: 4 additions & 0 deletions src/assets/i18n/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,10 @@
"description": "Table column header for product type",
"value": "製品タイプ"
},
"devices.table.type": {
"description": "Table column header for device type",
"value": "タイプ"
},
"devices.table.tags": {
"description": "タグ用テーブル列ヘッダー",
"value": "タグ"
Expand Down
4 changes: 4 additions & 0 deletions src/assets/i18n/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,10 @@
"description": "Table column header for product type",
"value": "Producttype"
},
"devices.table.type": {
"description": "Table column header for device type",
"value": "Type"
},
"devices.table.tags": {
"description": "Tabelkolomkop voor tags",
"value": "Tags"
Expand Down
4 changes: 4 additions & 0 deletions src/assets/i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,10 @@
"description": "Table column header for product type",
"value": "Тип продукта"
},
"devices.table.type": {
"description": "Table column header for device type",
"value": "Тип"
},
"devices.table.tags": {
"description": "Заголовок столбца таблицы для тегов",
"value": "Теги"
Expand Down
4 changes: 4 additions & 0 deletions src/assets/i18n/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,10 @@
"description": "Table column header for product type",
"value": "Produkttyp"
},
"devices.table.type": {
"description": "Table column header for device type",
"value": "Typ"
},
"devices.table.tags": {
"description": "Tabellkolumnrubrik för taggar",
"value": "Taggar"
Expand Down
Loading