Skip to content

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

Remove loading key from collection state

Oliver Günthere0bba41803fb
diff --git a/frontend/src/app/core/state/collection-store.ts b/frontend/src/app/core/state/collection-store.ts
index b1b16e4ca6c..77660736958 100644
--- a/frontend/src/app/core/state/collection-store.ts
+++ b/frontend/src/app/core/state/collection-store.ts
@@ -11,6 +11,7 @@ import {
} from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';
import { IHalResourceLinks } from 'core-app/core/state/hal-resource';
import idFromLink from 'core-app/features/hal/helpers/id-from-link';
+import { filter } from 'lodash';
export interface CollectionResponse {
ids:ID[];
@@ -63,18 +64,34 @@ export function collectionKey(params:ApiV3ListParameters):string {
export function setCollectionLoading<T extends { id:ID }>(
store:EntityStore<CollectionState<T>>,
collectionUrl:string,
- loading:boolean,
):void {
store.update(({ loadingCollections }) => (
{
loadingCollections: {
...loadingCollections,
- [collectionUrl]: loading,
+ [collectionUrl]: true,
},
}
));
}
+/**
+ * Mark a collection key as no longer loading
+ *
+ * @param store An entity store for the collection
+ * @param collectionUrl The key to insert the collection at
+ */
+export function removeCollectionLoading<T extends { id:ID }>(
+ store:EntityStore<CollectionState<T>>,
+ collectionUrl:string,
+):void {
+ store.update(({ loadingCollections }) => (
+ {
+ loadingCollections: filter(loadingCollections, (_, key) => key !== collectionUrl),
+ }
+ ));
+}
+
/**
* Insert a collection into the given entity store
*
diff --git a/frontend/src/app/core/state/days/day.service.ts b/frontend/src/app/core/state/days/day.service.ts
index 5f2b599ad2a..2f96090e5fd 100644
--- a/frontend/src/app/core/state/days/day.service.ts
+++ b/frontend/src/app/core/state/days/day.service.ts
@@ -14,6 +14,7 @@ import {
collectionKey,
extendCollectionElementsWithId,
insertCollectionIntoState,
+ removeCollectionLoading,
setCollectionLoading,
} from 'core-app/core/state/collection-store';
import { DayStore } from 'core-app/core/state/days/day.store';
@@ -57,7 +58,7 @@ export class DayResourceService extends ResourceCollectionService<IDay> {
fetchCollection(params:ApiV3ListParameters):Observable<IHALCollection<IDay>> {
const collectionURL = collectionKey(params);
- setCollectionLoading(this.store, collectionURL, true);
+ setCollectionLoading(this.store, collectionURL);
return this
.http
@@ -65,7 +66,7 @@ export class DayResourceService extends ResourceCollectionService<IDay> {
.pipe(
map((collection) => extendCollectionElementsWithId(collection)),
tap((collection) => insertCollectionIntoState(this.store, collection, collectionURL)),
- finalize(() => setCollectionLoading(this.store, collectionURL, false)),
+ finalize(() => removeCollectionLoading(this.store, collectionURL)),
);
}
diff --git a/frontend/src/app/core/state/resource-collection.service.ts b/frontend/src/app/core/state/resource-collection.service.ts
index 132988531e7..6e0bef1863d 100644
--- a/frontend/src/app/core/state/resource-collection.service.ts
+++ b/frontend/src/app/core/state/resource-collection.service.ts
@@ -45,6 +45,7 @@ import {
CollectionResponse,
CollectionState,
insertCollectionIntoState,
+ removeCollectionLoading,
setCollectionLoading,
} from 'core-app/core/state/collection-store';
import { omit } from 'lodash';
@@ -228,14 +229,14 @@ export abstract class ResourceCollectionService<T extends { id:ID }> {
fetchCollection(params:ApiV3ListParameters|string):Observable<IHALCollection<T>> {
const key = typeof params === 'string' ? params : collectionKey(params);
- setCollectionLoading(this.store, key, true);
+ setCollectionLoading(this.store, key);
return this
.http
.get<IHALCollection<T>>(this.basePath() + key)
.pipe(
tap((collection) => insertCollectionIntoState(this.store, collection, key)),
- finalize(() => setCollectionLoading(this.store, key, false)),
+ finalize(() => removeCollectionLoading(this.store, key)),
catchError((error:unknown) => {
this.handleCollectionLoadingError(error as HttpErrorResponse, key);
throw error;