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:
parent
a2cd401a2e
commit
87b1a2af4d
|
@ -7,11 +7,12 @@ import { MatProgressBar } from '@angular/material/progress-bar';
|
|||
import { MatSidenav } from '@angular/material/sidenav';
|
||||
import { By } from '@angular/platform-browser';
|
||||
|
||||
import { of, timer } from 'rxjs';
|
||||
import { Subject, of, timer } from 'rxjs';
|
||||
import { first, mapTo } from 'rxjs/operators';
|
||||
|
||||
import { AppComponent } from './app.component';
|
||||
import { AppModule } from './app.module';
|
||||
import { CurrentNodes } from 'app/navigation/navigation.model';
|
||||
import { DocumentService } from 'app/documents/document.service';
|
||||
import { DocViewerComponent } from 'app/layout/doc-viewer/doc-viewer.component';
|
||||
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 { MockLogger } from 'testing/logger.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 { SearchBoxComponent } from 'app/search/search-box/search-box.component';
|
||||
import { SearchResultsComponent } from 'app/shared/search-results/search-results.component';
|
||||
|
@ -826,43 +827,24 @@ describe('AppComponent', () => {
|
|||
|
||||
it(description, () => {
|
||||
createTestingModule('', mode);
|
||||
|
||||
const navService = TestBed.get(NavigationService) as NavigationService;
|
||||
const testCurrentNodes = navService.currentNodes = new Subject<CurrentNodes>();
|
||||
|
||||
initializeTest(false);
|
||||
|
||||
testCurrentNodes.next({SideNav: {url: 'foo', view: 'SideNav', nodes: []}});
|
||||
verifyNoRedirection();
|
||||
|
||||
testCurrentNodes.next({NoSideNav: {url: 'bar', view: 'SideNav', nodes: []}});
|
||||
verifyPossibleRedirection();
|
||||
|
||||
createTestingModule('resources', mode);
|
||||
initializeTest(false);
|
||||
locationService.replace.calls.reset();
|
||||
testCurrentNodes.next({});
|
||||
verifyPossibleRedirection();
|
||||
|
||||
createTestingModule('guide/aot-compiler', mode);
|
||||
initializeTest(false);
|
||||
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);
|
||||
locationService.replace.calls.reset();
|
||||
testCurrentNodes.next({SideNav: {url: 'baz', view: 'SideNav', nodes: []}});
|
||||
verifyNoRedirection();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -120,11 +120,6 @@ export class AppComponent implements OnInit {
|
|||
this.documentService.currentDocument.subscribe(doc => this.currentDocument = doc);
|
||||
|
||||
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) {
|
||||
// scroll only if on same page (most likely a change to the hash)
|
||||
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
|
||||
combineLatest(
|
||||
|
|
Loading…
Reference in New Issue