Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Commit

Permalink
Fixes related to using browser back to starting point (#4288)
Browse files Browse the repository at this point in the history
* Fix exception SidePanelService: container already set on browser back to & return from login
- hit browser back button until login screen temporarily hit
- ERROR Error: SidePanelService: container already set thrown
- This was due to DashboardBaseComponent initialising the side panel twice, once per nav from login pages
- fix is to ensure the panel service only lives in the DashboardBaseComponent rather than whole app

* Ensure initialRequest process is only set up once

* Fix issue where additional pages are refretched after return from log
- nav to marketplace. marketplace should contain over 100 services
- hit browser back to temporarily go to login page and back
- non-first pages were refetched, with one causing a 'write to protected obj' error
```
entity-request-pipeline.ts:94 TypeError: Cannot assign to read only property 'cfGuid' of object '[object Object]'
    at globalSuccessfulRequestDataMapper (cf-entity-generator.ts:173)
    at map-multi-endpoint.pipes.ts:37
    at Array.reduce (<anonymous>)
    at map-multi-endpoint.pipes.ts:35
    at Array.reduce (<anonymous>)
    at getEntities (map-multi-endpoint.pipes.ts:31)
    at map-multi-endpoint.pipes.ts:102
    at Array.map (<anonymous>)
    at mapMultiEndpointResponses (map-multi-endpoint.pipes.ts:101)
    at MapSubscriber.project (entity-pagination-request-pipeline.ts:134)
```

* Fix `+` icon in service summary page

* Fix side panel

* Revert "Fix `+` icon in service summary page"

This reverts commit e5d3916.
  • Loading branch information
richard-cox committed May 22, 2020
1 parent bc92bae commit d9fb11f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export class DashboardBaseComponent implements OnInit, OnDestroy, AfterViewInit
ngOnDestroy() {
this.mobileSub.unsubscribe();
this.closeSub.unsubscribe();
this.sidePanelService.unsetContainer();
}

isNoMarginView(route: ActivatedRouteSnapshot): boolean {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { ComponentFactory, ComponentFactoryResolver, ComponentRef, Injectable, ViewContainerRef, Inject } from '@angular/core';
import { DOCUMENT } from '@angular/common';
import {
ComponentFactory,
ComponentFactoryResolver,
ComponentRef,
Inject,
Injectable,
ViewContainerRef,
} from '@angular/core';
import { Router } from '@angular/router';
import { asapScheduler, BehaviorSubject, Observable, Subject } from 'rxjs';
import { filter, observeOn, publishReplay, refCount, tap } from 'rxjs/operators';
import { DOCUMENT } from '@angular/common';

/**
* Service to allow the overlay side panel to be shown or hidden.
Expand Down Expand Up @@ -35,6 +42,10 @@ export class SidePanelService {
this.setupRouterListener();
}

public unsetContainer() {
this.container = undefined;
}

public setContainer(container: ViewContainerRef) {
if (this.container) {
throw new Error('SidePanelService: container already set');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ function getRequestObservable(
request: HttpRequest<any>,
paginationPageIterator?: PaginationPageIterator
): Observable<PagedJetstreamResponse> {
const initialRequest = makeRequestEntityPipe(
httpClient,
request,
entityCatalog.getEndpoint(action.endpointType, action.subType),
action.endpointGuid,
action.externalRequest
);
if (action.flattenPagination && !paginationPageIterator) {
console.warn('Action requires all request pages but no page flattener was given.');
}
if (!action.flattenPagination || !paginationPageIterator) {
const initialRequest = makeRequestEntityPipe(
httpClient,
request,
entityCatalog.getEndpoint(action.endpointType, action.subType),
action.endpointGuid,
action.externalRequest
);
return initialRequest.pipe(map(response => singleRequestToPaged(response)));
}
return paginationPageIterator.mergeAllPagesEntities();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HttpRequest } from '@angular/common/http';
import { Store } from '@ngrx/store';
import { combineLatest, Observable, of, range } from 'rxjs';
import { map, mergeMap, reduce, switchMap } from 'rxjs/operators';
import { first, map, mergeMap, reduce, switchMap } from 'rxjs/operators';

import { UpdatePaginationMaxedState } from '../../actions/pagination.actions';
import { AppState } from '../../app-state';
Expand Down Expand Up @@ -95,10 +95,9 @@ export class PaginationPageIterator<R = any, E = any> {
private handleRequests(initialResponse: JetstreamResponse<R>, action: PaginatedAction, totalPages: number, totalResults: number):
Observable<[JetstreamResponse<R>, JetstreamResponse<R>[]]> {

const allResults = combineLatest(of(initialResponse), this.getAllOtherPageRequests(totalPages));

const createAllResults = () => combineLatest(of(initialResponse), this.getAllOtherPageRequests(totalPages));
if (totalResults === 0 || (this.paginationMaxedState && this.paginationMaxedState.ignoreMaxed)) {
return allResults;
return createAllResults();
}

return this.config.maxedStateStartAt(this.store, action).pipe(
Expand All @@ -114,7 +113,7 @@ export class PaginationPageIterator<R = any, E = any> {
);
return combineLatest([of(initialResponse), of([])]);
}
return allResults;
return createAllResults();
})
);
}
Expand All @@ -126,7 +125,7 @@ export class PaginationPageIterator<R = any, E = any> {
public mergeAllPagesEntities(): Observable<PagedJetstreamResponse> {
const initialRequest = this.addPageToRequest(1);
return this.makeRequest(initialRequest).pipe(
mergeMap(initialResponse => {
switchMap(initialResponse => {
const totalPages = this.config.getTotalPages(initialResponse);
const totalResults = this.config.getTotalEntities(initialResponse);
return this.handleRequests(
Expand All @@ -135,6 +134,7 @@ export class PaginationPageIterator<R = any, E = any> {
this.getValidNumber(totalPages),
this.getValidNumber(totalResults)
).pipe(
first(),
map(([initialRequestResponse, othersResponse]) => [initialRequestResponse, ...othersResponse]),
map(responsePages => this.reducePages(responsePages)),
);
Expand Down

0 comments on commit d9fb11f

Please sign in to comment.