Browse Source

fix(iot-hub): check the update again after any way back, check default converters in parallel and keep the latest run

pull/16466/head
dpinkevych 1 month ago
parent
commit
4f0151542f
Failed to extract signature
  1. 20
      ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/device-install-dialog.component.ts
  2. 41
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-installed-items-table.component.ts

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

@ -555,6 +555,15 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
return this.wizardSteps[this.stepper.selectedIndex + 1]?.label || '';
}
/** Update: coming back to the Update step checks the update again, e.g. with the configuration changed. */
private resetUpdatePlan(ws: WizardStep): void {
if (ws.type === 'progress' && !ws.progressDone && !ws.updating && !ws.checking) {
ws.entitySteps = null;
ws.reviewing = false;
ws.progressError = null;
}
}
previousStep(): void {
if (!this.stepper || this.stepper.selectedIndex <= 0) {
return;
@ -564,12 +573,7 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
if (step.updating || step.checking) {
return;
}
if (!step.progressDone) {
// Coming back to it checks the update again, e.g. with the configuration changed
step.entitySteps = null;
step.reviewing = false;
step.progressError = null;
}
this.resetUpdatePlan(step);
this.stepper.previous();
} else if (step?.type === 'progress' && step.progressError) {
this.goBackToForm();
@ -700,6 +704,10 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
onStepSelectionChange(event: StepperSelectionEvent): void {
if (event.selectedIndex <= event.previouslySelectedIndex) {
// Back through the stepper header too, not only the Back button: the Update step checks the update again
if (this.data.update) {
this.wizardSteps.slice(event.selectedIndex + 1).forEach(ws => this.resetUpdatePlan(ws));
}
return;
}
// Forward moves can come from the stepper header, which bypasses nextStep(),

41
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-installed-items-table.component.ts

@ -74,6 +74,7 @@ export class TbIotHubInstalledItemsTableComponent implements OnInit, OnChanges,
publishedVersionMap = new Map<string, ItemPublishedVersionInfo>();
// Installed device packages whose default converter differs from ThingsBoard's default converter now
converterUpdates = new Set<string>();
private converterCheckRun = 0;
updatesChecked = false;
isCheckingUpdates = false;
@ -277,35 +278,47 @@ export class TbIotHubInstalledItemsTableComponent implements OnInit, OnChanges,
* ThingsBoard's default converter now. ThingsBoard's default changes with ThingsBoard, so the package has no new version for it.
*/
private async checkConverterUpdates(): Promise<void> {
const updates = new Set<string>();
// A later load (another page, sort or search) starts another run: an earlier one finishing last mustn't win
const run = ++this.converterCheckRun;
// The package's default converter of each DEVICE package on the page
const checks: { itemId: string; converterId: string }[] = [];
// Over all installed packages, not only this page's, as the update dialog decides
let ownDefaultConverterIds: Set<string> | undefined;
for (const item of this.dataSource) {
const states = item.itemType === 'DEVICE' ? Object.values((item.descriptor as DeviceInstalledItemDescriptor)?.installState ?? {}) : [];
for (const state of states) {
let id: string = state?.defaultConverter ? state.entityOutput?.id : undefined;
const id: string = state?.defaultConverter ? state.entityOutput?.id : undefined;
if (!id) {
continue;
}
// A converter taken as it was counts only when a package installed it as its default converter
if (id && state.resolution === 'use-existing') {
if (state.resolution === 'use-existing') {
ownDefaultConverterIds ??= await loadOwnDefaultConverterIds(this.iotHubApiService);
if (!ownDefaultConverterIds.has(id)) {
id = undefined;
}
}
const converter = id ? await firstValueFrom(this.converterService.getConverter(id, {ignoreErrors: true, ignoreLoading: true}))
.catch(() => null) : null;
if (converter) {
const defaultConverter = await loadDefaultUplinkConverter(this.resourcesService, converter.integrationType,
converter.configuration.scriptLang, converter.name);
if (defaultConverter && differsFromDefaultConverter(converter, defaultConverter)) {
updates.add(item.id.id);
continue;
}
}
checks.push({ itemId: item.id.id, converterId: id });
}
}
this.converterUpdates = updates;
const changed = await Promise.all(checks.map(async ({ itemId, converterId }) => {
const converter = await firstValueFrom(this.converterService.getConverter(converterId, {ignoreErrors: true, ignoreLoading: true}))
.catch(() => null);
if (!converter) {
return null;
}
const defaultConverter = await loadDefaultUplinkConverter(this.resourcesService, converter.integrationType,
converter.configuration.scriptLang, converter.name);
return defaultConverter && differsFromDefaultConverter(converter, defaultConverter) ? itemId : null;
}));
if (run !== this.converterCheckRun) {
return;
}
this.converterUpdates = new Set(changed.filter(itemId => !!itemId));
this.cd.markForCheck();
}
getPublishedVersionInfo(item: IotHubInstalledItem): ItemPublishedVersionInfo | undefined {
return this.publishedVersionMap.get(item.itemId);
}

Loading…
Cancel
Save