Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class PreprintProvidersMapper {
backgroundColor: brandRaw.attributes.background_color,
},
iri: response.links.iri,
faviconUrl: response.attributes.assets.favicon,
faviconUrl: response.attributes.assets?.favicon,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change is present because it it impossible to preview preprints locally without it

squareColorNoTransparentImageUrl: response.attributes.assets?.square_color_no_transparent,
reviewsWorkflow: response.attributes.reviews_workflow,
facebookAppId: response.attributes.facebook_app_id,
Expand Down
2 changes: 2 additions & 0 deletions src/app/features/preprints/mappers/preprints.mapper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { LicensesMapper } from '@osf/shared/mappers';
import { ApiData, JsonApiResponseWithMeta, ResponseJsonApi } from '@osf/shared/models';
import { StringOrNull } from '@shared/helpers';
import { IdentifiersMapper } from '@shared/mappers/identifiers.mapper';

import {
Preprint,
Expand Down Expand Up @@ -136,6 +137,7 @@ export class PreprintsMapper {
views: meta.metrics.views,
},
embeddedLicense: LicensesMapper.fromLicenseDataJsonApi(data.embeds.license.data),
identifiers: IdentifiersMapper.fromEmbeds(data.embeds.identifiers),
preprintDoiLink: links.preprint_doi,
articleDoiLink: links.doi,
};
Expand Down
2 changes: 2 additions & 0 deletions src/app/features/preprints/models/preprint-json-api.models.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { UserPermissions } from '@osf/shared/enums';
import { BooleanOrNull, StringOrNull } from '@osf/shared/helpers';
import { ContributorResponse, LicenseRecordJsonApi, LicenseResponseJsonApi } from '@osf/shared/models';
import { IdentifiersEmbedJsonApiResponse } from '@shared/models/identifiers/identifier-json-api';

import { ApplicabilityStatus, PreregLinkInfo, ReviewsState } from '../enums';

Expand Down Expand Up @@ -69,6 +70,7 @@ export interface PreprintEmbedsJsonApi {
data: ContributorResponse[];
};
license: LicenseResponseJsonApi;
identifiers: IdentifiersEmbedJsonApiResponse;
}

export interface PreprintMetaJsonApi {
Expand Down
2 changes: 2 additions & 0 deletions src/app/features/preprints/models/preprint.models.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { UserPermissions } from '@osf/shared/enums';
import { BooleanOrNull, StringOrNull } from '@osf/shared/helpers';
import { IdName, License, LicenseOptions } from '@osf/shared/models';
import { Identifier } from '@shared/models/identifiers/indentifier.model';

import { ApplicabilityStatus, PreregLinkInfo, ReviewsState } from '../enums';

Expand Down Expand Up @@ -43,6 +44,7 @@ export interface Preprint {
embeddedLicense?: License;
preprintDoiLink?: string;
articleDoiLink?: string;
identifiers?: Identifier[];
}

export interface PreprintFilesLinks {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Button } from 'primeng/button';
import { DialogService } from 'primeng/dynamicdialog';
import { Skeleton } from 'primeng/skeleton';

import { filter, map, of } from 'rxjs';
import { filter, map, Observable, of } from 'rxjs';

import { DatePipe, Location } from '@angular/common';
import {
Expand All @@ -19,7 +19,7 @@ import {
OnDestroy,
OnInit,
} from '@angular/core';
import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
import { takeUntilDestroyed, toObservable, toSignal } from '@angular/core/rxjs-interop';
import { ActivatedRoute, Router } from '@angular/router';

import { UserSelectors } from '@core/store/user';
Expand All @@ -46,6 +46,7 @@ import {
import { GetPreprintProviderById, PreprintProvidersSelectors } from '@osf/features/preprints/store/preprint-providers';
import { CreateNewVersion, PreprintStepperSelectors } from '@osf/features/preprints/store/preprint-stepper';
import { IS_MEDIUM, pathJoin } from '@osf/shared/helpers';
import { DataciteTrackerComponent } from '@shared/components/datacite-tracker/datacite-tracker.component';
import { ReviewPermissions, UserPermissions } from '@shared/enums';
import { MetaTagsService } from '@shared/services';
import { ContributorsSelectors } from '@shared/stores';
Expand Down Expand Up @@ -75,7 +76,7 @@ import { environment } from 'src/environments/environment';
providers: [DialogService, DatePipe],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class PreprintDetailsComponent implements OnInit, OnDestroy {
export class PreprintDetailsComponent extends DataciteTrackerComponent implements OnInit, OnDestroy {
@HostBinding('class') classes = 'flex-1 flex flex-column w-full';

private readonly router = inject(Router);
Expand Down Expand Up @@ -105,6 +106,7 @@ export class PreprintDetailsComponent implements OnInit, OnDestroy {
preprintProvider = select(PreprintProvidersSelectors.getPreprintProviderDetails(this.providerId()));
isPreprintProviderLoading = select(PreprintProvidersSelectors.isPreprintProviderDetailsLoading);
preprint = select(PreprintSelectors.getPreprint);
preprint$ = toObservable(select(PreprintSelectors.getPreprint));
isPreprintLoading = select(PreprintSelectors.isPreprintLoading);
contributors = select(ContributorsSelectors.getContributors);
areContributorsLoading = select(ContributorsSelectors.isContributorsLoading);
Expand Down Expand Up @@ -281,12 +283,19 @@ export class PreprintDetailsComponent implements OnInit, OnDestroy {
this.fetchPreprint(this.preprintId());
},
});
this.setupDataciteViewTrackerEffect().subscribe();
}

ngOnDestroy() {
this.actions.resetState();
}

protected getDoi(): Observable<string | null> {
return this.preprint$.pipe(
filter((project) => project != null),
map((project) => project?.identifiers?.find((item) => item.category == 'doi')?.value ?? null)
);
}
fetchPreprintVersion(preprintVersionId: string) {
const currentUrl = this.router.url;
const newUrl = currentUrl.replace(/[^/]+$/, preprintVersionId);
Expand Down
2 changes: 1 addition & 1 deletion src/app/features/preprints/services/preprints.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class PreprintsService {
const params = {
'metrics[views]': 'total',
'metrics[downloads]': 'total',
'embed[]': 'license',
'embed[]': ['license', 'identifiers'],
};
return this.jsonApiService
.get<
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { InstitutionsMapper } from '@shared/mappers';
import { IdentifiersMapper } from '@shared/mappers/identifiers.mapper';
import { License } from '@shared/models';

import { ProjectOverview, ProjectOverviewGetResponseJsoApi } from '../models';
Expand Down Expand Up @@ -46,12 +47,7 @@ export class ProjectOverviewMapper {
type: contributor.embeds.users.data.type,
})),
affiliatedInstitutions: InstitutionsMapper.fromInstitutionsResponse(response.embeds.affiliated_institutions),
identifiers: response.embeds.identifiers?.data.map((identifier) => ({
id: identifier.id,
type: identifier.type,
value: identifier.attributes.value,
category: identifier.attributes.category,
})),
identifiers: IdentifiersMapper.fromEmbeds(response.embeds.identifiers),
...(response.embeds.storage?.data &&
!response.embeds.storage?.errors && {
storage: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { UserPermissions } from '@osf/shared/enums';
import { Institution, InstitutionsJsonApiResponse, JsonApiResponse, License } from '@osf/shared/models';
import { Identifier, Institution, InstitutionsJsonApiResponse, JsonApiResponse, License } from '@osf/shared/models';
import { IdentifiersEmbedJsonApiResponse } from '@shared/models/identifiers/identifier-json-api';

export interface ProjectOverviewContributor {
familyName: string;
Expand Down Expand Up @@ -38,7 +39,7 @@ export interface ProjectOverview {
storageLimitStatus: string;
storageUsage: string;
};
identifiers?: ProjectIdentifiers[];
identifiers?: Identifier[];
supplements?: ProjectSupplements[];
analyticsKey: string;
currentUserCanComment: boolean;
Expand Down Expand Up @@ -100,16 +101,7 @@ export interface ProjectOverviewGetResponseJsoApi {
};
embeds: {
affiliated_institutions: InstitutionsJsonApiResponse;
identifiers: {
data: {
id: string;
type: string;
attributes: {
category: string;
value: string;
};
}[];
};
identifiers: IdentifiersEmbedJsonApiResponse;
bibliographic_contributors: {
data: {
embeds: {
Expand Down Expand Up @@ -208,13 +200,6 @@ export interface ProjectOverviewResponseJsonApi extends JsonApiResponse<ProjectO
data: ProjectOverviewGetResponseJsoApi;
}

export interface ProjectIdentifiers {
id: string;
type: string;
category: string;
value: string;
}

export interface ProjectSupplements {
id: string;
type: string;
Expand Down
8 changes: 2 additions & 6 deletions src/app/features/registry/mappers/registry-overview.mapper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { RegistryOverview, RegistryOverviewJsonApiData } from '@osf/features/registry/models';
import { ReviewPermissionsMapper } from '@osf/shared/mappers';
import { RegistrationMapper } from '@osf/shared/mappers/registration';
import { IdentifiersMapper } from '@shared/mappers/identifiers.mapper';
import { MapRegistryStatus } from '@shared/mappers/registry/map-registry-status.mapper';

export function MapRegistryOverview(data: RegistryOverviewJsonApiData): RegistryOverview | null {
Expand Down Expand Up @@ -36,12 +37,7 @@ export function MapRegistryOverview(data: RegistryOverviewJsonApiData): Registry
middleName: contributor?.embeds?.users?.data?.attributes?.middle_names,
type: contributor?.embeds?.users?.data?.type,
})),
identifiers: data.embeds.identifiers?.data.map((identifier) => ({
id: identifier.id,
type: identifier.type,
value: identifier.attributes.value,
category: identifier.attributes.category,
})),
identifiers: IdentifiersMapper.fromEmbeds(data.embeds.identifiers),
analyticsKey: data.attributes?.analyticsKey,
currentUserCanComment: data.attributes.current_user_can_comment,
currentUserPermissions: data.attributes.current_user_permissions,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { RegistrationReviewStates, RevisionReviewStates } from '@osf/shared/enums';
import { ApiData, JsonApiResponse, ProviderDataJsonApi, SchemaResponseDataJsonApi } from '@osf/shared/models';
import { IdentifiersEmbedJsonApiResponse } from '@shared/models/identifiers/identifier-json-api';

export type GetRegistryOverviewJsonApi = JsonApiResponse<RegistryOverviewJsonApiData, null>;

Expand Down Expand Up @@ -87,16 +88,7 @@ export interface RegistryOverviewJsonApiEmbed {
};
};
};
identifiers: {
data: {
id: string;
type: string;
attributes: {
category: string;
value: string;
};
}[];
};
identifiers: IdentifiersEmbedJsonApiResponse;
schema_responses: {
data: SchemaResponseDataJsonApi[];
};
Expand Down
16 changes: 15 additions & 1 deletion src/app/features/registry/registry.component.ts

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We definitely need a unit test for this file. Even if you have to enable it in the jest.config file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { select } from '@ngxs/store';

import { filter, map, Observable } from 'rxjs';

import { DatePipe } from '@angular/common';
import { ChangeDetectionStrategy, Component, effect, HostBinding, inject } from '@angular/core';
import { toObservable } from '@angular/core/rxjs-interop';
import { RouterOutlet } from '@angular/router';

import { pathJoin } from '@osf/shared/helpers';
import { MetaTagsService } from '@osf/shared/services';
import { DataciteTrackerComponent } from '@shared/components/datacite-tracker/datacite-tracker.component';

import { RegistryOverviewSelectors } from './store/registry-overview';

Expand All @@ -19,20 +23,30 @@ import { environment } from 'src/environments/environment';
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [DatePipe],
})
export class RegistryComponent {
export class RegistryComponent extends DataciteTrackerComponent {
@HostBinding('class') classes = 'flex-1 flex flex-column';

private readonly metaTags = inject(MetaTagsService);
private readonly datePipe = inject(DatePipe);

protected readonly registry = select(RegistryOverviewSelectors.getRegistry);
readonly registry$ = toObservable(select(RegistryOverviewSelectors.getRegistry));

constructor() {
super();
effect(() => {
if (this.registry()) {
this.setMetaTags();
}
});
this.setupDataciteViewTrackerEffect().subscribe();
}

protected getDoi(): Observable<string | null> {
return this.registry$.pipe(
filter((project) => project != null),
map((project) => project?.identifiers?.find((item) => item.category == 'doi')?.value ?? null)
);
}

private setMetaTags(): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { ProjectIdentifiers } from '@osf/features/project/overview/models';
import { MOCK_PROJECT_IDENTIFIERS, TranslateServiceMock } from '@shared/mocks';
import { Identifier } from '@shared/models';

import { ProjectMetadataPublicationDoiComponent } from './project-metadata-publication-doi.component';

describe('ProjectMetadataPublicationDoiComponent', () => {
let component: ProjectMetadataPublicationDoiComponent;
let fixture: ComponentFixture<ProjectMetadataPublicationDoiComponent>;

const mockIdentifiers: ProjectIdentifiers = MOCK_PROJECT_IDENTIFIERS;
const mockIdentifiers: Identifier = MOCK_PROJECT_IDENTIFIERS;

beforeEach(async () => {
await TestBed.configureTestingModule({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Card } from 'primeng/card';

import { ChangeDetectionStrategy, Component, input, output } from '@angular/core';

import { ProjectIdentifiers } from '@osf/features/project/overview/models';
import { Identifier } from '@osf/shared/models';

@Component({
selector: 'osf-project-metadata-publication-doi',
Expand All @@ -16,6 +16,6 @@ import { ProjectIdentifiers } from '@osf/features/project/overview/models';
export class ProjectMetadataPublicationDoiComponent {
openEditPublicationDoiDialog = output<void>();

identifiers = input<ProjectIdentifiers[]>([]);
identifiers = input<Identifier[]>([]);
hideEditDoi = input<boolean>(false);
}
15 changes: 15 additions & 0 deletions src/app/shared/mappers/identifiers.mapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Identifier, ResponseJsonApi } from '@shared/models';
import { IdentifiersEmbedJsonApiData } from '@shared/models/identifiers/identifier-json-api';

export class IdentifiersMapper {
static fromEmbeds(response: ResponseJsonApi<IdentifiersEmbedJsonApiData[]>): Identifier[] {
return response.data.map((rawIdentifier) => {
return {
category: rawIdentifier.attributes.category,
value: rawIdentifier.attributes.value,
id: rawIdentifier.id,
type: rawIdentifier.type,
};
});
}
}
12 changes: 12 additions & 0 deletions src/app/shared/models/identifiers/identifier-json-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ApiData, ResponseJsonApi } from '@shared/models';

export type IdentifiersEmbedJsonApiResponse = ResponseJsonApi<IdentifiersEmbedJsonApiData[]>;
export type IdentifiersEmbedJsonApiData = ApiData<IdentifierAttributes, null, null, IdentifierLinks>;

export interface IdentifierAttributes {
category: string;
value: string;
}
interface IdentifierLinks {
self: string;
}
6 changes: 6 additions & 0 deletions src/app/shared/models/identifiers/indentifier.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface Identifier {
id: string;
type: string;
category: string;
value: string;
}
2 changes: 2 additions & 0 deletions src/app/shared/models/identifiers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// export * from './identifier-json-api';
export * from './indentifier.model';
1 change: 1 addition & 0 deletions src/app/shared/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export * from './filter-labels.model';
export * from './filters';
export * from './google-drive-folder.model';
export * from './guid-response-json-api.model';
export * from './identifiers';
export * from './institutions';
export * from './language-code.model';
export * from './license';
Expand Down
Loading
Loading