Browse Source

refactor(iot-hub): unify result-type ordering, drop dashboard support

- Apply the same DEVICE → SOLUTION_TEMPLATE → WIDGET → CALCULATED_FIELD →
  ALARM_RULE → RULE_CHAIN ordering to the home search popup and the
  search component, so all entry points group results consistently.
- Drop DASHBOARD entirely from the search component (route, installed
  counts, type order) and filter it out of the home search popup
  groups.
- Add ALARM_RULE to the search component (compact-card layout, route
  alarm-rules, installed-count handling).
- Remove the "Add from IoT Hub" header action and addDashboardFromIotHub
  handler from the dashboards page, plus the now-unused
  IotHubActionsService / ItemType imports and constructor injection.
pull/15615/head
Igor Kulikov 1 month ago
parent
commit
d3a2d43e32
  1. 20
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.ts
  2. 18
      ui-ngx/src/app/modules/home/pages/dashboard/dashboards-table-config.resolver.ts
  3. 12
      ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts

20
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.ts

@ -39,8 +39,8 @@ interface SortOption {
}
const TYPE_ORDER: ItemType[] = [
ItemType.WIDGET, ItemType.DASHBOARD, ItemType.SOLUTION_TEMPLATE, ItemType.DEVICE,
ItemType.CALCULATED_FIELD, ItemType.RULE_CHAIN
ItemType.DEVICE, ItemType.SOLUTION_TEMPLATE, ItemType.WIDGET,
ItemType.CALCULATED_FIELD, ItemType.ALARM_RULE, ItemType.RULE_CHAIN
];
@Component({
@ -80,8 +80,8 @@ export class TbIotHubSearchComponent implements OnInit, OnDestroy {
installedWidgets: IotHubInstalledItem[] = [];
installedSolutionTemplates: IotHubInstalledItem[] = [];
installedDeviceCounts: Record<string, number> = {};
installedDashboardCounts: Record<string, number> = {};
installedCalcFieldCounts: Record<string, number> = {};
installedAlarmRuleCounts: Record<string, number> = {};
installedRuleChainCounts: Record<string, number> = {};
private searchSubject = new Subject<string>();
@ -176,7 +176,9 @@ export class TbIotHubSearchComponent implements OnInit, OnDestroy {
// Type helpers
isCompactType(type: ItemType): boolean {
return type === ItemType.CALCULATED_FIELD || type === ItemType.RULE_CHAIN;
return type === ItemType.CALCULATED_FIELD
|| type === ItemType.ALARM_RULE
|| type === ItemType.RULE_CHAIN;
}
getTypeLabel(type: ItemType): string {
@ -187,9 +189,9 @@ export class TbIotHubSearchComponent implements OnInit, OnDestroy {
getTypeRoute(type: ItemType): string {
switch (type) {
case ItemType.WIDGET: return 'widgets';
case ItemType.DASHBOARD: return 'dashboards';
case ItemType.SOLUTION_TEMPLATE: return 'solution-templates';
case ItemType.CALCULATED_FIELD: return 'calculated-fields';
case ItemType.ALARM_RULE: return 'alarm-rules';
case ItemType.RULE_CHAIN: return 'rule-chains';
case ItemType.DEVICE: return 'devices';
default: return 'widgets';
@ -217,10 +219,10 @@ export class TbIotHubSearchComponent implements OnInit, OnDestroy {
switch (item.type) {
case ItemType.DEVICE:
return this.installedDeviceCounts[item.itemId] || 0;
case ItemType.DASHBOARD:
return this.installedDashboardCounts[item.itemId] || 0;
case ItemType.CALCULATED_FIELD:
return this.installedCalcFieldCounts[item.itemId] || 0;
case ItemType.ALARM_RULE:
return this.installedAlarmRuleCounts[item.itemId] || 0;
case ItemType.RULE_CHAIN:
return this.installedRuleChainCounts[item.itemId] || 0;
default:
@ -311,15 +313,15 @@ export class TbIotHubSearchComponent implements OnInit, OnDestroy {
widgets: this.iotHubApiService.getInstalledItems(pageLink, ItemType.WIDGET, undefined, config),
solutionTemplates: this.iotHubApiService.getInstalledItems(pageLink, ItemType.SOLUTION_TEMPLATE, undefined, config),
deviceCounts: this.iotHubApiService.getInstalledItemCounts(ItemType.DEVICE, config),
dashboardCounts: this.iotHubApiService.getInstalledItemCounts(ItemType.DASHBOARD, config),
calcFieldCounts: this.iotHubApiService.getInstalledItemCounts(ItemType.CALCULATED_FIELD, config),
alarmRuleCounts: this.iotHubApiService.getInstalledItemCounts(ItemType.ALARM_RULE, config),
ruleChainCounts: this.iotHubApiService.getInstalledItemCounts(ItemType.RULE_CHAIN, config)
}).subscribe(results => {
this.installedWidgets = results.widgets.data;
this.installedSolutionTemplates = results.solutionTemplates.data;
this.installedDeviceCounts = results.deviceCounts;
this.installedDashboardCounts = results.dashboardCounts;
this.installedCalcFieldCounts = results.calcFieldCounts;
this.installedAlarmRuleCounts = results.alarmRuleCounts;
this.installedRuleChainCounts = results.ruleChainCounts;
});
}

18
ui-ngx/src/app/modules/home/pages/dashboard/dashboards-table-config.resolver.ts

@ -77,9 +77,6 @@ import {
EntityAliasesDialogComponent,
EntityAliasesDialogData
} from '@home/components/alias/entity-aliases-dialog.component';
import { ItemType } from '@shared/models/iot-hub/iot-hub-item.models';
import { IotHubActionsService } from '@home/components/iot-hub/iot-hub-actions.service';
@Injectable()
export class DashboardsTableConfigResolver {
@ -92,7 +89,6 @@ export class DashboardsTableConfigResolver {
private dialogService: DialogService,
private homeDialogs: HomeDialogsService,
private importExport: ImportExportService,
private iotHubActions: IotHubActionsService,
private translate: TranslateService,
private datePipe: DatePipe,
private router: Router,
@ -352,12 +348,6 @@ export class DashboardsTableConfigResolver {
icon: 'file_upload',
isEnabled: () => true,
onAction: ($event) => this.importDashboard($event)
},
{
name: this.translate.instant('iot-hub.add-from-iot-hub'),
icon: 'store',
isEnabled: () => true,
onAction: ($event) => this.addDashboardFromIotHub($event)
}
);
}
@ -397,14 +387,6 @@ export class DashboardsTableConfigResolver {
}
}
addDashboardFromIotHub(_$event: Event) {
this.iotHubActions.addItem(ItemType.DASHBOARD).subscribe(result => {
if (result?.descriptor?.type === 'DASHBOARD' && result.descriptor.dashboardId?.id) {
this.router.navigateByUrl(`dashboards/${result.descriptor.dashboardId.id}`);
}
});
}
importDashboard(_$event: Event) {
this.importExport.importDashboard(this.editMissingAliases.bind(this)).subscribe(
(dashboard) => {

12
ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts

@ -52,6 +52,11 @@ interface SearchResultGroup {
items: MpItemVersionView[];
}
const SEARCH_GROUP_ORDER: ItemType[] = [
ItemType.DEVICE, ItemType.SOLUTION_TEMPLATE, ItemType.WIDGET,
ItemType.CALCULATED_FIELD, ItemType.ALARM_RULE, ItemType.RULE_CHAIN
];
@Component({
selector: 'tb-iot-hub-home',
standalone: false,
@ -524,6 +529,9 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy {
private groupSearchResults(items: MpItemVersionView[]): SearchResultGroup[] {
const groupMap = new Map<ItemType, MpItemVersionView[]>();
for (const item of items) {
if (!SEARCH_GROUP_ORDER.includes(item.type)) {
continue;
}
let list = groupMap.get(item.type);
if (!list) {
list = [];
@ -531,6 +539,8 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy {
}
list.push(item);
}
return Array.from(groupMap.entries()).map(([type, groupItems]) => ({ type, items: groupItems }));
return SEARCH_GROUP_ORDER
.filter(type => groupMap.has(type))
.map(type => ({ type, items: groupMap.get(type) }));
}
}

Loading…
Cancel
Save