Repository navigation
[ENG-12722] Feature/redirect landing page #1107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
futa-ikeda
merged 1 commit into
CenterForOpenScience:feature/redirect-links
from
futa-ikeda:feature/redirect-landing-page
Nov 30, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/app/core/components/redirect-page/redirect-page.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <section | ||
| class="container flex flex-column flex-1 my-7 mx-3 p-3 align-items-center md:p-4 md:flex-row md:justify-content-between" | ||
| > | ||
| <img | ||
| class="redirect-image w-8 md:w-6" | ||
| ngSrc="assets/images/laptop-books.png" | ||
| width="500" | ||
| height="346" | ||
| priority | ||
| [alt]="'redirectPage.altText' | translate" | ||
| /> | ||
|
|
||
| <div class="flex flex-column align-items-center m-4 md:align-items-start"> | ||
| <h2>{{ 'redirectPage.header' | translate }}</h2> | ||
| <p class="mt-4">{{ 'redirectPage.message' | translate }}</p> | ||
|
|
||
| <div class="flex flex-column mt-4 gap-4 md:flex-row md:justify-content-start"> | ||
| <a class="p-button font-bold no-underline" [href]="redirectDestination()"> | ||
| {{ 'common.buttons.continue' | translate }} | ||
| </a> | ||
| <p-button severity="info" (onClick)="goBack()"> | ||
| {{ 'common.buttons.goBack' | translate }} | ||
| </p-button> | ||
| </div> | ||
| </div> | ||
| </section> | ||
19 changes: 19 additions & 0 deletions
19
src/app/core/components/redirect-page/redirect-page.component.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| @use "styles/mixins" as mix; | ||
|
|
||
| :host { | ||
| @include mix.flex-center; | ||
| flex: 1; | ||
| background: var(--gradient-3); | ||
| } | ||
|
|
||
| .container { | ||
| background: var(--white); | ||
| border-radius: 0.75rem; | ||
| box-shadow: 0 2px 4px var(--grey-outline); | ||
| color: var(--dark-blue-1); | ||
| } | ||
|
|
||
| .redirect-image { | ||
| height: auto; | ||
| object-fit: contain; | ||
| } |
111 changes: 111 additions & 0 deletions
111
src/app/core/components/redirect-page/redirect-page.component.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| import { MockProvider } from 'ng-mocks'; | ||
|
|
||
| import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
|
||
| import { WINDOW } from '@core/provider/window.provider'; | ||
| import { CurrentResource } from '@osf/shared/models/current-resource.model'; | ||
| import { CurrentResourceSelectors } from '@osf/shared/stores/current-resource/current-resource.selectors'; | ||
|
|
||
| import { provideOSFCore } from '@testing/osf.testing.provider'; | ||
| import { provideMockStore } from '@testing/providers/store-provider.mock'; | ||
|
|
||
| import { RedirectPageComponent } from './redirect-page.component'; | ||
|
|
||
| const mockResource: CurrentResource = { | ||
| id: 'mock-resource-id', | ||
| type: 'mock-resource-type', | ||
| redirectUrl: 'https://example.com', | ||
| permissions: [], | ||
| redirectAutomatically: false, | ||
| }; | ||
|
|
||
| describe('RedirectPageComponent', () => { | ||
| let component: RedirectPageComponent; | ||
| let fixture: ComponentFixture<RedirectPageComponent>; | ||
| let locationMock: { href: string }; | ||
| let historyMock: { back: ReturnType<typeof vi.fn> }; | ||
|
|
||
| afterEach(() => { | ||
| vi.useRealTimers(); | ||
| }); | ||
|
|
||
| function setup(override: Partial<CurrentResource> = {}) { | ||
| locationMock = { href: '' }; | ||
| historyMock = { back: vi.fn() }; | ||
|
|
||
| TestBed.configureTestingModule({ | ||
| imports: [RedirectPageComponent], | ||
| providers: [ | ||
| provideOSFCore(), | ||
| MockProvider(WINDOW, { | ||
| location: locationMock, | ||
| history: historyMock, | ||
| } as unknown as Window), | ||
| provideMockStore({ | ||
| signals: [ | ||
| { | ||
| selector: CurrentResourceSelectors.getCurrentResource, | ||
| value: { ...mockResource, ...override }, | ||
| }, | ||
| ], | ||
| }), | ||
| ], | ||
| }); | ||
|
|
||
| fixture = TestBed.createComponent(RedirectPageComponent); | ||
| component = fixture.componentInstance; | ||
| fixture.detectChanges(); | ||
| } | ||
|
|
||
| it('should create', () => { | ||
| setup(); | ||
| expect(component).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('should expose redirectDestination when resource has redirect URL', () => { | ||
| setup(); | ||
| expect(component.redirectDestination()).toBe(mockResource.redirectUrl); | ||
| }); | ||
|
|
||
| it('should fall back to empty redirectDestination when redirect URL is missing', () => { | ||
| setup({ redirectUrl: undefined }); | ||
| expect(component.redirectDestination()).toBe(''); | ||
| }); | ||
|
|
||
| it('should render continue link and go back button', () => { | ||
| setup(); | ||
| const continueLink = fixture.nativeElement.querySelector('a') as HTMLAnchorElement; | ||
| expect(continueLink.getAttribute('href')).toBe(mockResource.redirectUrl); | ||
| expect(fixture.nativeElement.querySelector('button')).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('should go back in history when go back is clicked', () => { | ||
| setup(); | ||
| const button = fixture.nativeElement.querySelector('button') as HTMLButtonElement; | ||
| button.click(); | ||
| expect(historyMock.back).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should not redirect when redirectDestination is empty', () => { | ||
| vi.useFakeTimers(); | ||
| setup({ redirectUrl: undefined }); | ||
| vi.advanceTimersByTime(component.redirectDelay); | ||
| expect(locationMock.href).toBe(''); | ||
| }); | ||
|
|
||
| it('should automatically redirect after redirectDelay', () => { | ||
| vi.useFakeTimers(); | ||
| setup(); | ||
| expect(locationMock.href).toBe(''); | ||
| vi.advanceTimersByTime(component.redirectDelay); | ||
| expect(locationMock.href).toBe(mockResource.redirectUrl); | ||
| }); | ||
|
|
||
| it('should not redirect if component is destroyed before redirectDelay', () => { | ||
| vi.useFakeTimers(); | ||
| setup(); | ||
| fixture.destroy(); | ||
| vi.advanceTimersByTime(component.redirectDelay); | ||
| expect(locationMock.href).toBe(''); | ||
| }); | ||
| }); |
47 changes: 47 additions & 0 deletions
47
src/app/core/components/redirect-page/redirect-page.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { select } from '@ngxs/store'; | ||
|
|
||
| import { TranslatePipe } from '@ngx-translate/core'; | ||
|
|
||
| import { Button } from 'primeng/button'; | ||
|
|
||
| import { timer } from 'rxjs'; | ||
|
|
||
| import { NgOptimizedImage } from '@angular/common'; | ||
| import { afterNextRender, ChangeDetectionStrategy, Component, computed, DestroyRef, inject } from '@angular/core'; | ||
| import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; | ||
|
|
||
| import { WINDOW } from '@core/provider/window.provider'; | ||
| import { CurrentResourceSelectors } from '@osf/shared/stores/current-resource/current-resource.selectors'; | ||
|
|
||
| @Component({ | ||
| selector: 'osf-redirect-page', | ||
| imports: [Button, NgOptimizedImage, TranslatePipe], | ||
| templateUrl: './redirect-page.component.html', | ||
| styleUrl: './redirect-page.component.scss', | ||
| changeDetection: ChangeDetectionStrategy.OnPush, | ||
| }) | ||
| export class RedirectPageComponent { | ||
| private readonly currentResource = select(CurrentResourceSelectors.getCurrentResource); | ||
| private readonly window = inject(WINDOW); | ||
| private readonly destroyRef = inject(DestroyRef); | ||
| readonly redirectDelay = 5000; | ||
| readonly redirectDestination = computed(() => this.currentResource()?.redirectUrl ?? ''); | ||
|
|
||
| constructor() { | ||
| afterNextRender(() => { | ||
| const redirectUrl = this.redirectDestination(); | ||
| if (!redirectUrl) { | ||
| return; | ||
| } | ||
| timer(this.redirectDelay) | ||
| .pipe(takeUntilDestroyed(this.destroyRef)) | ||
| .subscribe(() => { | ||
| this.window.location.href = this.redirectDestination(); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| goBack() { | ||
| this.window.history.back(); | ||
| } | ||
| } | ||
|
futa-ikeda marked this conversation as resolved.
Resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.