Added fallback for non-entity conflicts
This commit is contained in:
parent
1d0c3a7598
commit
cf76f9ee8f
@ -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<unknown & HasId & HasVersion>, next: HttpHandler): Observable<HttpEvent<unknown>> {
|
||||
intercept(request: HttpRequest<VersionedEntity>, next: HttpHandler): Observable<HttpEvent<unknown>> {
|
||||
if (!request.url.startsWith('/api/')) {
|
||||
return next.handle(request);
|
||||
}
|
||||
@ -52,11 +52,11 @@ export class EntityConflictInterceptor implements HttpInterceptor {
|
||||
}
|
||||
|
||||
private handleConflictError(
|
||||
request: HttpRequest<unknown & HasId & HasVersion>,
|
||||
request: HttpRequest<VersionedEntity>,
|
||||
next: HttpHandler,
|
||||
error: HttpErrorResponse
|
||||
): Observable<HttpEvent<unknown>> {
|
||||
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<unknown & HasId & HasVersion>): HttpRequest<unknown & HasId & HasVersion> {
|
||||
private updateRequestVersion(request: HttpRequest<VersionedEntity>): HttpRequest<VersionedEntity> {
|
||||
const body = { ...request.body, version: null };
|
||||
return request.clone({ body });
|
||||
}
|
||||
|
||||
private openConflictDialog(entity: unknown & HasId & HasVersion, message: string): Observable<boolean> {
|
||||
private isVersionedEntity(entity: VersionedEntity): boolean {
|
||||
return !!((entity as EntityInfoData)?.id ?? (entity as RuleChainMetaData)?.ruleChainId)
|
||||
}
|
||||
|
||||
private openConflictDialog(entity: VersionedEntity, message: string): Observable<boolean> {
|
||||
const dialogRef = this.dialog.open(EntityConflictDialogComponent, {
|
||||
disableClose: true,
|
||||
data: { message, entity },
|
||||
|
||||
@ -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({
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user