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

Prevent trying to upsert an empty collection (#10591)

Oliver Günther50746933e094
diff --git a/frontend/src/app/core/state/collection-store.ts b/frontend/src/app/core/state/collection-store.ts
index b686e40b50a..5f706d0ffeb 100644
--- a/frontend/src/app/core/state/collection-store.ts
+++ b/frontend/src/app/core/state/collection-store.ts
@@ -113,11 +113,17 @@ export function insertCollectionIntoState<T extends { id:ID }>(
collection:IHALCollection<T>,
collectionUrl:string,
):void {
+ const { elements } = collection._embedded as { elements:undefined|T[] };
+
// Some JSON endpoints return no elements result if there are no elements
- const ids = collection._embedded.elements?.map((el) => el.id) || [];
+ const ids = elements?.map((el) => el.id) || [];
applyTransaction(() => {
- store.upsertMany(collection._embedded.elements);
+ // Avoid inserting when elements is not defined
+ if (elements && elements.length > 0) {
+ store.upsertMany(collection._embedded.elements);
+ }
+
store.update(({ collections }) => (
{
collections: {