diff --git a/src/frontend/app/store/helpers/entity-relations.ts b/src/frontend/app/store/helpers/entity-relations.ts index 646f1e24b5..93ee7356f5 100644 --- a/src/frontend/app/store/helpers/entity-relations.ts +++ b/src/frontend/app/store/helpers/entity-relations.ts @@ -152,13 +152,14 @@ function createSingleAction(config: HandleRelationsConfig) { function createPaginationAction(config: HandleRelationsConfig) { const { cfGuid, parentRelation, parentEntity, childRelation, childEntitiesUrl, includeRelations, populateMissing } = config; + const parentGuid = parentEntity.metadata ? parentEntity.metadata.guid : parentEntity.entity.guid; return new FetchRelationPaginatedAction( cfGuid, - parentEntity.metadata.guid, + parentGuid, parentRelation, childRelation, includeRelations, - createEntityRelationPaginationKey(parentRelation.entityKey, parentEntity.metadata.guid, childRelation.entity.relationKey), + createEntityRelationPaginationKey(parentRelation.entityKey, parentGuid, childRelation.entity.relationKey), populateMissing, childEntitiesUrl ); @@ -490,7 +491,7 @@ export function populatePaginationFromParent(store: Store, action: Pag withLatestFrom(store.select(getAPIRequestDataState)), map(([entityState, allEntities]) => { const [entityInfo, entity] = entityState; - if (!entityInfo || !entity) { + if (!entity) { return; } // Find the property name (for instance a list of routes in a parent space would have param name `routes`) diff --git a/src/frontend/app/store/reducers/api-request-data-reducer/request-data-reducer.factory.ts b/src/frontend/app/store/reducers/api-request-data-reducer/request-data-reducer.factory.ts index 17ca2cb199..68e4f624f0 100644 --- a/src/frontend/app/store/reducers/api-request-data-reducer/request-data-reducer.factory.ts +++ b/src/frontend/app/store/reducers/api-request-data-reducer/request-data-reducer.factory.ts @@ -78,7 +78,17 @@ function populateParentEntity(state, successAction) { const childRelation = parentEntityTree.rootRelation.childRelations.find(rel => rel.entityKey === successAction.apiAction.entityKey); const entityParamName = childRelation.paramName; - let newParentEntity = pathGet(`${parentEntityKey}.${parentGuid}`, state) || {}; + let newParentEntity = pathGet(`${parentEntityKey}.${parentGuid}`, state); + if (!newParentEntity) { + // We haven't yet fetched the parent entity so create one to store this list in. This can be used to fetch the child list in the future. + // NOTE - This should not contain the metadata property as the lack thereof forces the entity to fail validation and to be fetched + // properly with all it's properties + newParentEntity = { + entity: { + guid: parentGuid, + } + }; + } newParentEntity = { ...newParentEntity, entity: { diff --git a/src/frontend/app/store/reducers/pagination-reducer/pagination-reducer.helper.ts b/src/frontend/app/store/reducers/pagination-reducer/pagination-reducer.helper.ts index e877a4a01d..95fca26274 100644 --- a/src/frontend/app/store/reducers/pagination-reducer/pagination-reducer.helper.ts +++ b/src/frontend/app/store/reducers/pagination-reducer/pagination-reducer.helper.ts @@ -1,5 +1,5 @@ import { Store } from '@ngrx/store'; -import { combineLatest , Observable } from 'rxjs'; +import { combineLatest, Observable } from 'rxjs'; import { filter, first, publishReplay, refCount, switchMap, tap, distinctUntilChanged } from 'rxjs/operators'; import { PaginationMonitor } from '../../../shared/monitors/pagination-monitor';