diff --git a/ui-ngx/src/app/core/interceptors/entity-conflict.interceptor.ts b/ui-ngx/src/app/core/interceptors/entity-conflict.interceptor.ts index 6575ba4f65..43b32bab54 100644 --- a/ui-ngx/src/app/core/interceptors/entity-conflict.interceptor.ts +++ b/ui-ngx/src/app/core/interceptors/entity-conflict.interceptor.ts @@ -22,11 +22,11 @@ import { MatDialog } from '@angular/material/dialog'; import { EntityConflictDialogComponent } from '@shared/components/dialog/entity-conflict-dialog/entity-conflict-dialog.component'; -import { HasId } from '@shared/models/base-data'; -import { HasVersion } from '@shared/models/entity.models'; +import { EntityInfoData, VersionedEntity } from '@shared/models/entity.models'; import { getInterceptorConfig } from './interceptor.util'; import { isDefined } from '@core/utils'; import { InterceptorConfig } from '@core/interceptors/interceptor-config'; +import { RuleChainMetaData } from '@shared/models/rule-chain.models'; @Injectable() export class EntityConflictInterceptor implements HttpInterceptor { @@ -35,7 +35,7 @@ export class EntityConflictInterceptor implements HttpInterceptor { private dialog: MatDialog, ) {} - intercept(request: HttpRequest, next: HttpHandler): Observable> { + intercept(request: HttpRequest, next: HttpHandler): Observable> { if (!request.url.startsWith('/api/')) { return next.handle(request); } @@ -52,11 +52,11 @@ export class EntityConflictInterceptor implements HttpInterceptor { } private handleConflictError( - request: HttpRequest, + request: HttpRequest, next: HttpHandler, error: HttpErrorResponse ): Observable> { - if (getInterceptorConfig(request).ignoreVersionConflict) { + if (getInterceptorConfig(request).ignoreVersionConflict || !this.isVersionedEntity(request.body)) { return throwError(() => error); } @@ -74,12 +74,16 @@ export class EntityConflictInterceptor implements HttpInterceptor { ); } - private updateRequestVersion(request: HttpRequest): HttpRequest { + private updateRequestVersion(request: HttpRequest): HttpRequest { const body = { ...request.body, version: null }; return request.clone({ body }); } - private openConflictDialog(entity: unknown & HasId & HasVersion, message: string): Observable { + private isVersionedEntity(entity: VersionedEntity): boolean { + return !!((entity as EntityInfoData)?.id ?? (entity as RuleChainMetaData)?.ruleChainId) + } + + private openConflictDialog(entity: VersionedEntity, message: string): Observable { const dialogRef = this.dialog.open(EntityConflictDialogComponent, { disableClose: true, data: { message, entity }, diff --git a/ui-ngx/src/app/shared/components/dialog/entity-conflict-dialog/entity-conflict-dialog.component.ts b/ui-ngx/src/app/shared/components/dialog/entity-conflict-dialog/entity-conflict-dialog.component.ts index e522fa6c8f..f0ca9137f3 100644 --- a/ui-ngx/src/app/shared/components/dialog/entity-conflict-dialog/entity-conflict-dialog.component.ts +++ b/ui-ngx/src/app/shared/components/dialog/entity-conflict-dialog/entity-conflict-dialog.component.ts @@ -20,13 +20,13 @@ import { SharedModule } from '@shared/shared.module'; import { ImportExportService } from '@shared/import-export/import-export.service'; import { CommonModule } from '@angular/common'; import { entityTypeTranslations } from '@shared/models/entity-type.models'; -import { EntityInfoData } from '@shared/models/entity.models'; +import { EntityInfoData, VersionedEntity } from '@shared/models/entity.models'; import { EntityId } from '@shared/models/id/entity-id'; import { RuleChainMetaData } from '@shared/models/rule-chain.models'; interface EntityConflictDialogData { message: string; - entity: EntityInfoData | RuleChainMetaData; + entity: VersionedEntity; } @Component({ diff --git a/ui-ngx/src/app/shared/import-export/import-export.service.ts b/ui-ngx/src/app/shared/import-export/import-export.service.ts index 3963a81c1e..8db1ea95eb 100644 --- a/ui-ngx/src/app/shared/import-export/import-export.service.ts +++ b/ui-ngx/src/app/shared/import-export/import-export.service.ts @@ -55,7 +55,12 @@ import { EntityType } from '@shared/models/entity-type.models'; import { UtilsService } from '@core/services/utils.service'; import { WidgetService } from '@core/http/widget.service'; import { WidgetsBundle } from '@shared/models/widgets-bundle.model'; -import { EntityInfoData, ImportEntitiesResultInfo, ImportEntityData } from '@shared/models/entity.models'; +import { + EntityInfoData, + ImportEntitiesResultInfo, + ImportEntityData, + VersionedEntity +} from '@shared/models/entity.models'; import { RequestConfig } from '@core/http/http-utils'; import { RuleChain, RuleChainImport, RuleChainMetaData, RuleChainType } from '@shared/models/rule-chain.models'; import { RuleChainService } from '@core/http/rule-chain.service'; @@ -361,7 +366,7 @@ export class ImportExportService { }); } - public exportEntity(entityData: EntityInfoData | RuleChainMetaData): void { + public exportEntity(entityData: VersionedEntity): void { const id = (entityData as EntityInfoData).id ?? (entityData as RuleChainMetaData).ruleChainId; let fileName = (entityData as EntityInfoData).name; let preparedData; diff --git a/ui-ngx/src/app/shared/models/entity.models.ts b/ui-ngx/src/app/shared/models/entity.models.ts index 40ec570b13..51fbb8d261 100644 --- a/ui-ngx/src/app/shared/models/entity.models.ts +++ b/ui-ngx/src/app/shared/models/entity.models.ts @@ -20,6 +20,7 @@ import { EntityId } from '@shared/models/id/entity-id'; import { DeviceCredentialMQTTBasic } from '@shared/models/device.models'; import { Lwm2mSecurityConfigModels } from '@shared/models/lwm2m-security-config.models'; import { TenantId } from '@shared/models/id/tenant-id'; +import { RuleChainMetaData } from '@shared/models/rule-chain.models'; export interface EntityInfo { name?: string; @@ -191,3 +192,5 @@ export interface HasTenantId { export interface HasVersion { version?: number; } + +export type VersionedEntity = EntityInfoData & HasVersion | RuleChainMetaData;