refactor(docs-infra): avoid hard-coding URLs to redirect on archive mode (#30894)

Related discussion:
https://github.com/angular/angular/pull/30894#pullrequestreview-246731995

PR Close #30894
This commit is contained in:
George Kalpakas 2019-06-09 22:22:02 +03:00 committed by Igor Minar
parent a2cd401a2e
commit 87b1a2af4d
2 changed files with 25 additions and 40 deletions

View File

@ -7,11 +7,12 @@ import { MatProgressBar } from '@angular/material/progress-bar';
import { MatSidenav } from '@angular/material/sidenav'; import { MatSidenav } from '@angular/material/sidenav';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { of, timer } from 'rxjs'; import { Subject, of, timer } from 'rxjs';
import { first, mapTo } from 'rxjs/operators'; import { first, mapTo } from 'rxjs/operators';
import { AppComponent } from './app.component'; import { AppComponent } from './app.component';
import { AppModule } from './app.module'; import { AppModule } from './app.module';
import { CurrentNodes } from 'app/navigation/navigation.model';
import { DocumentService } from 'app/documents/document.service'; import { DocumentService } from 'app/documents/document.service';
import { DocViewerComponent } from 'app/layout/doc-viewer/doc-viewer.component'; import { DocViewerComponent } from 'app/layout/doc-viewer/doc-viewer.component';
import { Deployment } from 'app/shared/deployment.service'; import { Deployment } from 'app/shared/deployment.service';
@ -22,7 +23,7 @@ import { Logger } from 'app/shared/logger.service';
import { MockLocationService } from 'testing/location.service'; import { MockLocationService } from 'testing/location.service';
import { MockLogger } from 'testing/logger.service'; import { MockLogger } from 'testing/logger.service';
import { MockSearchService } from 'testing/search.service'; import { MockSearchService } from 'testing/search.service';
import { NavigationNode } from 'app/navigation/navigation.service'; import { NavigationNode, NavigationService } from 'app/navigation/navigation.service';
import { ScrollService } from 'app/shared/scroll.service'; import { ScrollService } from 'app/shared/scroll.service';
import { SearchBoxComponent } from 'app/search/search-box/search-box.component'; import { SearchBoxComponent } from 'app/search/search-box/search-box.component';
import { SearchResultsComponent } from 'app/shared/search-results/search-results.component'; import { SearchResultsComponent } from 'app/shared/search-results/search-results.component';
@ -826,43 +827,24 @@ describe('AppComponent', () => {
it(description, () => { it(description, () => {
createTestingModule('', mode); createTestingModule('', mode);
const navService = TestBed.get(NavigationService) as NavigationService;
const testCurrentNodes = navService.currentNodes = new Subject<CurrentNodes>();
initializeTest(false); initializeTest(false);
testCurrentNodes.next({SideNav: {url: 'foo', view: 'SideNav', nodes: []}});
verifyNoRedirection();
testCurrentNodes.next({NoSideNav: {url: 'bar', view: 'SideNav', nodes: []}});
verifyPossibleRedirection(); verifyPossibleRedirection();
createTestingModule('resources', mode); locationService.replace.calls.reset();
initializeTest(false); testCurrentNodes.next({});
verifyPossibleRedirection(); verifyPossibleRedirection();
createTestingModule('guide/aot-compiler', mode); locationService.replace.calls.reset();
initializeTest(false); testCurrentNodes.next({SideNav: {url: 'baz', view: 'SideNav', nodes: []}});
verifyNoRedirection();
createTestingModule('start', mode);
initializeTest(false);
verifyNoRedirection();
createTestingModule('tutorial', mode);
initializeTest(false);
verifyNoRedirection();
createTestingModule('tutorial/toh-pt1', mode);
initializeTest(false);
verifyNoRedirection();
createTestingModule('docs', mode);
initializeTest(false);
verifyNoRedirection();
createTestingModule('cli', mode);
initializeTest(false);
verifyNoRedirection();
createTestingModule('api', mode);
initializeTest(false);
verifyNoRedirection();
createTestingModule('api/core/getPlatform', mode);
initializeTest(false);
verifyNoRedirection(); verifyNoRedirection();
}); });
}); });

View File

@ -120,11 +120,6 @@ export class AppComponent implements OnInit {
this.documentService.currentDocument.subscribe(doc => this.currentDocument = doc); this.documentService.currentDocument.subscribe(doc => this.currentDocument = doc);
this.locationService.currentPath.subscribe(path => { this.locationService.currentPath.subscribe(path => {
// Redirect to docs if we are in archive mode and are not hitting a docs page
// (i.e. we have arrived at a marketing page)
if (this.deployment.mode === 'archive' && !/^(docs$|api|cli|guide|start|tutorial)/.test(path)) {
this.locationService.replace('docs');
}
if (path === this.currentPath) { if (path === this.currentPath) {
// scroll only if on same page (most likely a change to the hash) // scroll only if on same page (most likely a change to the hash)
this.scrollService.scroll(); this.scrollService.scroll();
@ -138,7 +133,15 @@ export class AppComponent implements OnInit {
} }
}); });
this.navigationService.currentNodes.subscribe(currentNodes => this.currentNodes = currentNodes); this.navigationService.currentNodes.subscribe(currentNodes => {
this.currentNodes = currentNodes;
// Redirect to docs if we are in archive mode and are not hitting a docs page
// (i.e. we have arrived at a marketing page)
if (this.deployment.mode === 'archive' && !currentNodes[sideNavView]) {
this.locationService.replace('docs');
}
});
// Compute the version picker list from the current version and the versions in the navigation map // Compute the version picker list from the current version and the versions in the navigation map
combineLatest( combineLatest(