Browse Source

feat(iot-hub): add find-or-create for rule chains in device install

Reuse existing rule chains by name (same pattern as device profiles).
Shared entities (device profile, rule chain) are looked up before creation.
Per-install entities (device, dashboard) are always created fresh.
pull/15347/head
Andrii Shvaika 4 months ago
parent
commit
389d8684d3
  1. 11
      ui-ngx/src/app/modules/home/pages/iot-hub/device-install-dialog/device-install-dialog.component.ts

11
ui-ngx/src/app/modules/home/pages/iot-hub/device-install-dialog/device-install-dialog.component.ts

@ -18,6 +18,7 @@ import { Component, Inject, OnInit } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { UntypedFormControl, UntypedFormGroup, Validators } from '@angular/forms';
import { firstValueFrom } from 'rxjs';
import { PageLink } from '@shared/models/page/page-link';
import { MpItemVersionView } from '@shared/models/iot-hub/iot-hub-version.models';
import { IotHubApiService } from '@core/http/iot-hub-api.service';
import { DeviceProfileService } from '@core/http/device-profile.service';
@ -356,6 +357,10 @@ export class TbDeviceInstallDialogComponent implements OnInit {
case InstallStepType.RULE_CHAIN: {
const ruleChain = template.ruleChain || template;
const metadata = template.metadata;
const existing = await this.findRuleChainByName(ruleChain.name);
if (existing) {
return existing;
}
const saved = await firstValueFrom(this.ruleChainService.saveRuleChain(ruleChain));
if (metadata) {
metadata.ruleChainId = saved.id;
@ -373,4 +378,10 @@ export class TbDeviceInstallDialogComponent implements OnInit {
const match = profiles.find(p => p.name === name);
return match ? { id: match.id.id, name: match.name } : null;
}
private async findRuleChainByName(name: string): Promise<EntityStepOutput | null> {
const page = await firstValueFrom(this.ruleChainService.getRuleChains(new PageLink(100, 0, name)));
const match = page.data.find(rc => rc.name === name);
return match ? { id: match.id.id, name: match.name } : null;
}
}

Loading…
Cancel
Save