Skip to content

Commit

Permalink
fix: limits check should also support unlimited agreements (#806)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardtreier authored Aug 28, 2024
1 parent 9ab4084 commit 1c945e9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ export class AssetDetailDialogDataService {
};
}

dataOfferDetails(dataOffer: DataOffer): AssetDetailDialogData {
dataOfferDetails(
dataOffer: DataOffer,
consumingLimitsExceeded: boolean,
): AssetDetailDialogData {
const asset = dataOffer.asset;
const propertyGridGroups = [
this.assetPropertyGridGroupBuilder.buildAssetPropertiesGroup(asset, null),
Expand All @@ -66,6 +69,7 @@ export class AssetDetailDialogDataService {
asset: asset,
dataOffer,
propertyGridGroups,
consumingLimitsExceeded,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface AssetDetailDialogData {
propertyGridGroups: PropertyGridGroup[];
asset: UiAssetMapped;
dataOffer?: DataOffer;
consumingLimitsExceeded?: boolean;
contractAgreement?: ContractAgreementCardMapped;
showDeleteButton?: boolean;
showEditButton?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,9 @@ export class AssetDetailDialogComponent implements OnDestroy {

setData(data: AssetDetailDialogData) {
this.data = data;
this.limitsExceeded = data.consumingLimitsExceeded ?? null;
this.asset = this.data.asset;
this.propGroups = this.data.propertyGridGroups;

if (this.limitsExceeded == null && this.data.type === 'data-offer') {
this.connectorLimitsService
.isConsumingAgreementLimitExceeded()
.subscribe((limitsExceeded) => {
this.limitsExceeded = limitsExceeded;
});
}
}

onContactClick() {
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/services/connector-limits.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ export class ConnectorLimitsService {
const max = limits.maxActiveConsumingContractAgreements;
const current = limits.numActiveConsumingContractAgreements;

return max != null && current >= max;
return max != null && max >= 0 && current >= max;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import {
Subject,
distinctUntilChanged,
sampleTime,
switchMap,
} from 'rxjs';
import {filter, map} from 'rxjs/operators';
import {AssetDetailDialogDataService} from '../../../../component-library/catalog/asset-detail-dialog/asset-detail-dialog-data.service';
import {AssetDetailDialogService} from '../../../../component-library/catalog/asset-detail-dialog/asset-detail-dialog.service';
import {ConnectorLimitsService} from '../../../../core/services/connector-limits.service';
import {DataOffer} from '../../../../core/services/models/data-offer';
import {value$} from '../../../../core/utils/form-group-utils';
import {CatalogBrowserFetchDetailDialogComponent} from '../catalog-browser-fetch-detail-dialog/catalog-browser-fetch-detail-dialog.component';
Expand Down Expand Up @@ -38,6 +40,7 @@ export class CatalogBrowserPageComponent implements OnInit, OnDestroy {
private catalogBrowserPageService: CatalogBrowserPageService,
private catalogApiUrlService: CatalogApiUrlService,
private matDialog: MatDialog,
private connectorLimitsService: ConnectorLimitsService,
) {}

ngOnInit(): void {
Expand All @@ -54,10 +57,18 @@ export class CatalogBrowserPageComponent implements OnInit, OnDestroy {
}

onDataOfferClick(dataOffer: DataOffer) {
const data = this.assetDetailDialogDataService.dataOfferDetails(dataOffer);
this.assetDetailDialogService
.open(data, this.ngOnDestroy$)
.pipe(filter((it) => !!it?.refreshList))
this.connectorLimitsService
.isConsumingAgreementLimitExceeded()
.pipe(
switchMap((isConsumingLimitsExceeded) => {
const data = this.assetDetailDialogDataService.dataOfferDetails(
dataOffer,
isConsumingLimitsExceeded,
);
return this.assetDetailDialogService.open(data, this.ngOnDestroy$);
}),
filter((it) => !!it?.refreshList),
)
.subscribe(() => this.fetch$.next(null));
}

Expand Down

0 comments on commit 1c945e9

Please sign in to comment.