Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/app/app.routes.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ export const serverRoutes: ServerRoute[] = [
path: ':id/overview',
renderMode: RenderMode.Server,
},
{
path: ':id/metadata/:recordId',
renderMode: RenderMode.Server,
},
{
path: ':id/files/**',
renderMode: RenderMode.Server,
Expand Down
18 changes: 11 additions & 7 deletions src/app/core/services/osf-config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,24 @@ export class OSFConfigService {
* On the server, this is skipped as config is only needed in the browser.
*/
async load(): Promise<void> {
if (!this.config && isPlatformBrowser(this.platformId)) {
if (this.config) return;

if (isPlatformBrowser(this.platformId)) {
this.config = await lastValueFrom<ConfigModel>(
this.http.get<ConfigModel>('/assets/config/config.json').pipe(
shareReplay(1),
catchError(() => of({} as ConfigModel))
)
);
} else {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.config = ((globalThis as any).__SSR_CONFIG__ ?? {}) as ConfigModel;
}

// Apply every key from config to environment
for (const [key, value] of Object.entries(this.config)) {
// eslint-disable-next-line
// @ts-ignore
this.environment[key] = value;
}
for (const [key, value] of Object.entries(this.config)) {
// eslint-disable-next-line
// @ts-ignore
this.environment[key] = value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ describe('FileDetailComponent', () => {
} as unknown as jest.Mocked<DataciteService>;

const mockRoute: Partial<ActivatedRoute> = {
params: of({ providerId: 'osf', preprintId: 'p1' }),
queryParams: of({ providerId: 'osf', preprintId: 'p1' }),
params: of({ providerId: 'osf', fileGuid: 'file-1' }),
queryParams: of({ providerId: 'osf', fileGuid: 'file-1' }),
};
(MOCK_STORE.selectSignal as jest.Mock).mockImplementation((selector) => {
switch (selector) {
Expand Down Expand Up @@ -79,6 +79,7 @@ describe('FileDetailComponent', () => {
}).compileComponents();
fixture = TestBed.createComponent(FileDetailComponent);
component = fixture.componentInstance;
document.head.innerHTML = '';
fixture.detectChanges();
});

Expand All @@ -95,4 +96,15 @@ describe('FileDetailComponent', () => {
it('should call dataciteService.logIdentifiableView on start ', () => {
expect(dataciteService.logIdentifiableView).toHaveBeenCalledWith(component.fileMetadata$);
});

it('should add signposting tags during SSR', () => {
fixture.detectChanges();

const linkTags = Array.from(document.head.querySelectorAll('link[rel="linkset"]'));
expect(linkTags.length).toBe(2);
expect(linkTags[0].getAttribute('href')).toBe('http://localhost:4200/metadata/file-1/?format=linkset');
expect(linkTags[0].getAttribute('type')).toBe('application/linkset');
expect(linkTags[1].getAttribute('href')).toBe('http://localhost:4200/metadata/file-1/?format=linkset-json');
expect(linkTags[1].getAttribute('type')).toBe('application/linkset+json');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
effect,
HostBinding,
inject,
OnDestroy,
OnInit,
signal,
} from '@angular/core';
import { takeUntilDestroyed, toObservable } from '@angular/core/rxjs-interop';
Expand Down Expand Up @@ -47,6 +49,7 @@ import { pathJoin } from '@osf/shared/helpers/path-join.helper';
import { CustomConfirmationService } from '@osf/shared/services/custom-confirmation.service';
import { DataciteService } from '@osf/shared/services/datacite/datacite.service';
import { MetaTagsService } from '@osf/shared/services/meta-tags.service';
import { SignpostingService } from '@osf/shared/services/signposting.service';
import { ToastService } from '@osf/shared/services/toast.service';
import { ViewOnlyLinkHelperService } from '@osf/shared/services/view-only-link-helper.service';
import { FileDetailsModel } from '@shared/models/files/file.model';
Expand Down Expand Up @@ -94,7 +97,7 @@ import {
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [DatePipe],
})
export class FileDetailComponent {
export class FileDetailComponent implements OnInit, OnDestroy {
@HostBinding('class') classes = 'flex flex-column flex-1 w-full h-full';

readonly store = inject(Store);
Expand All @@ -111,6 +114,7 @@ export class FileDetailComponent {
private readonly translateService = inject(TranslateService);
private readonly environment = inject(ENVIRONMENT);
private readonly clipboard = inject(Clipboard);
private readonly signpostingService = inject(SignpostingService);

readonly dataciteService = inject(DataciteService);

Expand Down Expand Up @@ -284,6 +288,16 @@ export class FileDetailComponent {
this.dataciteService.logIdentifiableView(this.fileMetadata$).pipe(takeUntilDestroyed(this.destroyRef)).subscribe();
}

ngOnInit(): void {
this.signpostingService.addSignposting(this.fileGuid);
}

ngOnDestroy(): void {
if (this.fileGuid) {
this.signpostingService.removeSignpostingLinkTags();
}
}

getIframeLink(version: string) {
const url = this.getMfrUrlWithVersion(version);
if (url) {
Expand Down
11 changes: 10 additions & 1 deletion src/app/features/metadata/metadata.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
DestroyRef,
effect,
inject,
OnDestroy,
OnInit,
signal,
} from '@angular/core';
Expand All @@ -24,6 +25,7 @@ import { MetadataResourceEnum } from '@osf/shared/enums/metadata-resource.enum';
import { ResourceType } from '@osf/shared/enums/resource-type.enum';
import { CustomConfirmationService } from '@osf/shared/services/custom-confirmation.service';
import { CustomDialogService } from '@osf/shared/services/custom-dialog.service';
import { SignpostingService } from '@osf/shared/services/signposting.service';
import { ToastService } from '@osf/shared/services/toast.service';
import { CollectionsSelectors, GetProjectSubmissions } from '@osf/shared/stores/collections';
import {
Expand Down Expand Up @@ -117,14 +119,15 @@ import {
styleUrl: './metadata.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MetadataComponent implements OnInit {
export class MetadataComponent implements OnInit, OnDestroy {
private readonly activeRoute = inject(ActivatedRoute);
private readonly router = inject(Router);
private readonly destroyRef = inject(DestroyRef);
private readonly customDialogService = inject(CustomDialogService);
private readonly toastService = inject(ToastService);
private readonly customConfirmationService = inject(CustomConfirmationService);
private readonly environment = inject(ENVIRONMENT);
private readonly signpostingService = inject(SignpostingService);

private resourceId = '';

Expand Down Expand Up @@ -264,12 +267,18 @@ export class MetadataComponent implements OnInit {
this.actions.getCedarTemplates();
this.actions.fetchSelectedSubjects(this.resourceId, this.resourceType());

this.signpostingService.addMetadataSignposting(this.resourceId);

if (this.isProjectType()) {
this.actions.getProjectSubmissions(this.resourceId);
}
}
}

ngOnDestroy(): void {
this.signpostingService.removeSignpostingLinkTags();
}

onTabChange(tabId: string | number): void {
const tab = this.tabs().find((x) => x.id === tabId.toString());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ describe('PreprintDetailsComponent SSR Tests', () => {
store = TestBed.inject(Store);
fixture = TestBed.createComponent(PreprintDetailsComponent);
component = fixture.componentInstance;
document.head.innerHTML = '';
});

it('should render PreprintDetailsComponent server-side without errors', () => {
Expand All @@ -475,6 +476,17 @@ describe('PreprintDetailsComponent SSR Tests', () => {
expect(component).toBeTruthy();
});

it('should add signposting tags during SSR', () => {
fixture.detectChanges();

const linkTags = Array.from(document.head.querySelectorAll('link[rel="linkset"]'));
expect(linkTags.length).toBe(2);
expect(linkTags[0].getAttribute('href')).toBe('http://localhost:4200/metadata/preprint-1/?format=linkset');
expect(linkTags[0].getAttribute('type')).toBe('application/linkset');
expect(linkTags[1].getAttribute('href')).toBe('http://localhost:4200/metadata/preprint-1/?format=linkset-json');
expect(linkTags[1].getAttribute('type')).toBe('application/linkset+json');
});

it('should not access browser-only APIs during SSR', () => {
const platformId = TestBed.inject(PLATFORM_ID);
expect(platformId).toBe('server');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { FixSpecialCharPipe } from '@osf/shared/pipes/fix-special-char.pipe';
import { CustomDialogService } from '@osf/shared/services/custom-dialog.service';
import { DataciteService } from '@osf/shared/services/datacite/datacite.service';
import { MetaTagsService } from '@osf/shared/services/meta-tags.service';
import { SignpostingService } from '@osf/shared/services/signposting.service';
import { ToastService } from '@osf/shared/services/toast.service';
import { ContributorsSelectors } from '@osf/shared/stores/contributors';

Expand Down Expand Up @@ -104,6 +105,7 @@ export class PreprintDetailsComponent implements OnInit, OnDestroy {
private readonly prerenderReady = inject(PrerenderReadyService);
private readonly platformId = inject(PLATFORM_ID);
private readonly isBrowser = isPlatformBrowser(this.platformId);
private readonly signpostingService = inject(SignpostingService);

private readonly environment = inject(ENVIRONMENT);

Expand Down Expand Up @@ -304,6 +306,8 @@ export class PreprintDetailsComponent implements OnInit, OnDestroy {
this.actions.getPreprintProviderById(this.providerId());
this.fetchPreprint(this.preprintId());

this.signpostingService.addSignposting(this.preprintId());

this.dataciteService.logIdentifiableView(this.preprint$).pipe(takeUntilDestroyed(this.destroyRef)).subscribe();
}

Expand All @@ -313,6 +317,8 @@ export class PreprintDetailsComponent implements OnInit, OnDestroy {
this.actions.clearCurrentProvider();
}

this.signpostingService.removeSignpostingLinkTags();

this.helpScoutService.unsetResourceType();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ describe('ProjectOverviewComponent SSR Tests', () => {
store = TestBed.inject(Store);
fixture = TestBed.createComponent(ProjectOverviewComponent);
component = fixture.componentInstance;
document.head.innerHTML = '';
});

it('should render ProjectOverviewComponent server-side without errors', () => {
Expand All @@ -285,6 +286,17 @@ describe('ProjectOverviewComponent SSR Tests', () => {
expect(component).toBeTruthy();
});

it('should add signposting tags during SSR', () => {
fixture.detectChanges();

const linkTags = Array.from(document.head.querySelectorAll('link[rel="linkset"]'));
expect(linkTags.length).toBe(2);
expect(linkTags[0].getAttribute('href')).toBe('http://localhost:4200/metadata/project-123/?format=linkset');
expect(linkTags[0].getAttribute('type')).toBe('application/linkset');
expect(linkTags[1].getAttribute('href')).toBe('http://localhost:4200/metadata/project-123/?format=linkset-json');
expect(linkTags[1].getAttribute('type')).toBe('application/linkset+json');
});

it('should not call browser-only actions in ngOnDestroy during SSR', () => {
const dispatchSpy = jest.spyOn(store, 'dispatch');

Expand Down
10 changes: 9 additions & 1 deletion src/app/features/project/overview/project-overview.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
effect,
HostBinding,
inject,
OnDestroy,
OnInit,
PLATFORM_ID,
} from '@angular/core';
Expand All @@ -35,6 +36,7 @@ import { ViewOnlyLinkMessageComponent } from '@osf/shared/components/view-only-l
import { Mode } from '@osf/shared/enums/mode.enum';
import { ResourceType } from '@osf/shared/enums/resource-type.enum';
import { CustomDialogService } from '@osf/shared/services/custom-dialog.service';
import { SignpostingService } from '@osf/shared/services/signposting.service';
import { ToastService } from '@osf/shared/services/toast.service';
import { ViewOnlyLinkHelperService } from '@osf/shared/services/view-only-link-helper.service';
import {
Expand Down Expand Up @@ -93,7 +95,7 @@ import {
],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ProjectOverviewComponent implements OnInit {
export class ProjectOverviewComponent implements OnInit, OnDestroy {
@HostBinding('class') classes = 'flex flex-1 flex-column w-full h-full';

private readonly route = inject(ActivatedRoute);
Expand All @@ -104,6 +106,7 @@ export class ProjectOverviewComponent implements OnInit {
private readonly customDialogService = inject(CustomDialogService);
private readonly platformId = inject(PLATFORM_ID);
private readonly isBrowser = isPlatformBrowser(this.platformId);
private readonly signpostingService = inject(SignpostingService);

submissions = select(CollectionsModerationSelectors.getCollectionSubmissions);
collectionProvider = select(CollectionsSelectors.getCollectionProvider);
Expand Down Expand Up @@ -193,9 +196,14 @@ export class ProjectOverviewComponent implements OnInit {
this.actions.getBookmarksId();
this.actions.getComponents(projectId);
this.actions.getLinkedProjects(projectId);
this.signpostingService.addSignposting(projectId);
}
}

ngOnDestroy(): void {
this.signpostingService.removeSignpostingLinkTags();
}

handleOpenMakeDecisionDialog() {
this.customDialogService
.open(MakeDecisionDialogComponent, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ describe('RegistryOverviewComponent', () => {
}).compileComponents();
fixture = TestBed.createComponent(RegistryOverviewComponent);
component = fixture.componentInstance;
document.head.innerHTML = '';
});

it('should render server-side without errors', () => {
Expand All @@ -638,6 +639,16 @@ describe('RegistryOverviewComponent', () => {
expect(component).toBeTruthy();
});

it('should add signposting tags during SSR', () => {
fixture.detectChanges();
const linkTags = Array.from(document.head.querySelectorAll('link[rel="linkset"]'));
expect(linkTags.length).toBe(2);
expect(linkTags[0].getAttribute('href')).toBe('http://localhost:4200/metadata/registry-1/?format=linkset');
expect(linkTags[0].getAttribute('type')).toBe('application/linkset');
expect(linkTags[1].getAttribute('href')).toBe('http://localhost:4200/metadata/registry-1/?format=linkset-json');
expect(linkTags[1].getAttribute('type')).toBe('application/linkset+json');
});

it('should not access browser-only APIs during SSR', () => {
const platformId = TestBed.inject(PLATFORM_ID);
expect(platformId).toBe('server');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
effect,
HostBinding,
inject,
OnDestroy,
OnInit,
signal,
} from '@angular/core';
import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
Expand All @@ -32,6 +34,7 @@ import { toCamelCase } from '@osf/shared/helpers/camel-case';
import { SchemaResponse } from '@osf/shared/models/registration/schema-response.model';
import { CustomDialogService } from '@osf/shared/services/custom-dialog.service';
import { LoaderService } from '@osf/shared/services/loader.service';
import { SignpostingService } from '@osf/shared/services/signposting.service';
import { ToastService } from '@osf/shared/services/toast.service';
import { ViewOnlyLinkHelperService } from '@osf/shared/services/view-only-link-helper.service';
import { GetBookmarksCollectionId } from '@osf/shared/stores/bookmarks';
Expand Down Expand Up @@ -75,7 +78,7 @@ import {
styleUrl: './registry-overview.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class RegistryOverviewComponent {
export class RegistryOverviewComponent implements OnInit, OnDestroy {
@HostBinding('class') classes = 'flex-1 flex flex-column w-full h-full';
private readonly route = inject(ActivatedRoute);
private readonly router = inject(Router);
Expand All @@ -84,6 +87,7 @@ export class RegistryOverviewComponent {
private readonly viewOnlyService = inject(ViewOnlyLinkHelperService);
private readonly customDialogService = inject(CustomDialogService);
private readonly loaderService = inject(LoaderService);
private readonly signpostingService = inject(SignpostingService);

readonly registry = select(RegistrySelectors.getRegistry);
readonly isRegistryLoading = select(RegistrySelectors.isRegistryLoading);
Expand Down Expand Up @@ -169,6 +173,14 @@ export class RegistryOverviewComponent {
.subscribe();
}

ngOnInit(): void {
this.signpostingService.addSignposting(this.registryId());
}

ngOnDestroy(): void {
this.signpostingService.removeSignpostingLinkTags();
}

openRevision(revisionIndex: number): void {
this.selectedRevisionIndex.set(revisionIndex);
}
Expand Down
8 changes: 8 additions & 0 deletions src/app/shared/models/signposting.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const LINKSET_TYPE = 'application/linkset';
export const LINKSET_JSON_TYPE = 'application/linkset+json';

export interface SignpostingLink {
rel: string;
href: string;
type: string;
}
Loading