OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Add collection function that triggers only when loaded
Oliver Günther7af630317347
diff --git a/frontend/src/app/core/state/capabilities/capabilities.service.spec.ts b/frontend/src/app/core/state/capabilities/capabilities.service.spec.tsindex c922d3bc95d..40116c3f8c5 100644--- a/frontend/src/app/core/state/capabilities/capabilities.service.spec.ts+++ b/frontend/src/app/core/state/capabilities/capabilities.service.spec.ts@@ -155,7 +155,7 @@ describe('Capabilities service', () => {expect(req.request.method).toBe('GET');const url = URI(req.request.url);const filterParams = new URLSearchParams(url.query()).get('filters') as string;- const context = JSON.parse(filterParams)[1].context.values[0] as string+ const context = JSON.parse(filterParams)[1].context.values[0] as string;let elements:ICapability[];switch (context) {diff --git a/frontend/src/app/core/state/capabilities/capabilities.service.ts b/frontend/src/app/core/state/capabilities/capabilities.service.tsindex 2bc96239491..36c729cbeae 100644--- a/frontend/src/app/core/state/capabilities/capabilities.service.ts+++ b/frontend/src/app/core/state/capabilities/capabilities.service.ts@@ -6,7 +6,6 @@ import {map,switchMap,take,- tap,} from 'rxjs/operators';import { Observable } from 'rxjs';import { HttpClient } from '@angular/common/http';@@ -14,10 +13,7 @@ import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';import { ToastService } from 'core-app/shared/components/toaster/toast.service';import { IHALCollection } from 'core-app/core/apiv3/types/hal-collection.type';import { ApiV3ListParameters } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';-import {- collectionKey,- insertCollectionIntoState,-} from 'core-app/core/state/collection-store';+import { collectionKey } from 'core-app/core/state/collection-store';import { ICapability } from 'core-app/core/state/capabilities/capability.model';import { CapabilitiesStore } from 'core-app/core/state/capabilities/capabilities.store';import {@@ -70,13 +66,13 @@ export class CapabilitiesResourceService extends ResourceCollectionService<ICapapublic require$(params:ApiV3ListParameters):Observable<ICapability[]> {const key = collectionKey(params);if (this.collectionExists(key) || this.collectionLoading(key)) {- return this.collection(key);+ return this.loadedCollection(key);}return this.fetchCapabilities(params).pipe(- switchMap(() => this.collection(key)),+ switchMap(() => this.loadedCollection(key)),);}diff --git a/frontend/src/app/core/state/capabilities/capability.model.ts b/frontend/src/app/core/state/capabilities/capability.model.tsindex 5ae883253ae..6fa186c2993 100644--- a/frontend/src/app/core/state/capabilities/capability.model.ts+++ b/frontend/src/app/core/state/capabilities/capability.model.ts@@ -1,7 +1,6 @@import {IHalOptionalTitledLink,IHalResourceLink,- IHalResourceLinks,} from 'core-app/core/state/hal-resource';export interface ICapabilityHalResourceLinks {diff --git a/frontend/src/app/core/state/resource-collection.service.ts b/frontend/src/app/core/state/resource-collection.service.tsindex d280511c4c4..5fa7361c0dc 100644--- a/frontend/src/app/core/state/resource-collection.service.ts+++ b/frontend/src/app/core/state/resource-collection.service.ts@@ -33,7 +33,6 @@ import {} from '@datorama/akita';import { Observable } from 'rxjs';import {- catchError,filter,finalize,map,@@ -42,6 +41,7 @@ import {} from 'rxjs/operators';import {collectionKey,+ CollectionResponse,CollectionState,insertCollectionIntoState,setCollectionLoading,@@ -50,7 +50,6 @@ import { omit } from 'lodash';import isDefinedEntity from 'core-app/core/state/is-defined-entity';import { ApiV3ListParameters } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';import { IHALCollection } from 'core-app/core/apiv3/types/hal-collection.type';-import { ICapability } from 'core-app/core/state/capabilities/capability.model';import { HttpClient } from '@angular/common/http';export type CollectionStore<T> = EntityStore<CollectionState<T>>;@@ -66,12 +65,36 @@ export abstract class ResourceCollectionService<T extends { id:ID }> {* @param key The collection key to fetch*/collection(key:string):Observable<T[]> {+ return this+ .collectionState(key)+ .pipe(+ switchMap((collection) => this.query.selectMany(collection?.ids || [])),+ );+ }++ /**+ * Return a collection observable that triggers only when the collection is loaded.+ * @param key+ */+ loadedCollection(key:string):Observable<T[]> {+ return this+ .collectionState(key)+ .pipe(+ filter((collection) => !!collection),+ switchMap((collection:CollectionResponse) => this.query.selectMany(collection.ids)),+ );+ }++ /**+ * Return a collection observable that triggers only when the collection is loaded.+ * @param key+ */+ collectionState(key:string):Observable<CollectionResponse|undefined> {return this.query.select().pipe(- map((state) => state.collections[key]?.ids),- switchMap((fileLinkIds) => this.query.selectMany(fileLinkIds)),+ map((state) => state.collections[key]),);}@@ -158,7 +181,7 @@ export abstract class ResourceCollectionService<T extends { id:ID }> {/*** Fetch a given collection, ensuring it is being flagged as loaded*/- protected fetchCollection(http:HttpClient, basePath:string, params:ApiV3ListParameters) {+ protected fetchCollection(http:HttpClient, basePath:string, params:ApiV3ListParameters):Observable<IHALCollection<T>> {const key = collectionKey(params);setCollectionLoading(this.store, key, true);diff --git a/frontend/src/app/features/bim/ifc_models/ifc-viewer/ifc-viewer.component.ts b/frontend/src/app/features/bim/ifc_models/ifc-viewer/ifc-viewer.component.tsindex c8a9cef82d2..fca726213a9 100644--- a/frontend/src/app/features/bim/ifc_models/ifc-viewer/ifc-viewer.component.ts+++ b/frontend/src/app/features/bim/ifc_models/ifc-viewer/ifc-viewer.component.ts@@ -84,7 +84,8 @@ export class IFCViewerComponent implements OnInit, OnDestroy, AfterViewInit {@ViewChild('inspectorPane') inspectorElement:ElementRef;- constructor(private I18n:I18nService,+ constructor(+ private I18n:I18nService,private elementRef:ElementRef,public ifcData:IfcModelsDataService,private ifcViewerService:IFCViewerService,diff --git a/frontend/src/app/features/invite-user-modal/principal/principal-search.component.ts b/frontend/src/app/features/invite-user-modal/principal/principal-search.component.tsindex 6cf64622ac0..af48eff521e 100644--- a/frontend/src/app/features/invite-user-modal/principal/principal-search.component.ts+++ b/frontend/src/app/features/invite-user-modal/principal/principal-search.component.ts@@ -93,6 +93,7 @@ export class PrincipalSearchComponent extends UntilDestroyedMixin implements OnIreturn false;}+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-explicit-anyreturn !!input && !elements.find((el:any) => el.name === input);}),);diff --git a/frontend/src/app/features/invite-user-modal/project-selection/project-selection.component.ts b/frontend/src/app/features/invite-user-modal/project-selection/project-selection.component.tsindex a651adfd7a0..bba6e199965 100644--- a/frontend/src/app/features/invite-user-modal/project-selection/project-selection.component.ts+++ b/frontend/src/app/features/invite-user-modal/project-selection/project-selection.component.ts@@ -6,6 +6,7 @@ import {EventEmitter,Output,ElementRef,+ ChangeDetectorRef,} from '@angular/core';import {AbstractControl,@@ -99,6 +100,7 @@ export class ProjectSelectionComponent implements OnInit {readonly apiV3Service:ApiV3Service,readonly currentUserService:CurrentUserService,readonly capabilitiesService:CapabilitiesResourceService,+ readonly cdRef:ChangeDetectorRef,) {}ngOnInit():void {@@ -119,6 +121,7 @@ export class ProjectSelectionComponent implements OnInit {).subscribe((projectInviteCapabilities) => {this.projectInviteCapabilities = projectInviteCapabilities;+ this.cdRef.detectChanges();});}