Skip to content

Commit c9b6623

Browse files
authored
[ENG-10138] Unable to view my preprints due to removed contributor (#861)
- Ticket: [ENG-10138] - Feature flag: n/a ## Summary of Changes 1. Fixed issues with my preprints.
1 parent af287e0 commit c9b6623

16 files changed

Lines changed: 77 additions & 106 deletions

src/app/features/preprints/mappers/preprints.mapper.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { StringOrNull } from '@osf/shared/helpers/types.helper';
2+
import { ContributorsMapper } from '@osf/shared/mappers/contributors';
23
import { IdentifiersMapper } from '@osf/shared/mappers/identifiers.mapper';
34
import { LicensesMapper } from '@osf/shared/mappers/licenses.mapper';
45
import { ApiData, JsonApiResponseWithMeta, ResponseJsonApi } from '@osf/shared/models/common/json-api.model';
@@ -170,20 +171,13 @@ export class PreprintsMapper {
170171
>
171172
): PreprintShortInfoWithTotalCount {
172173
return {
173-
data: response.data.map((preprintData) => {
174-
return {
175-
id: preprintData.id,
176-
title: replaceBadEncodedChars(preprintData.attributes.title),
177-
dateModified: preprintData.attributes.date_modified,
178-
contributors: preprintData.embeds.bibliographic_contributors.data.map((contrData) => {
179-
return {
180-
id: contrData.id,
181-
name: contrData.embeds.users.data.attributes.full_name,
182-
};
183-
}),
184-
providerId: preprintData.relationships.provider.data.id,
185-
};
186-
}),
174+
data: response.data.map((preprintData) => ({
175+
id: preprintData.id,
176+
title: replaceBadEncodedChars(preprintData.attributes.title),
177+
dateModified: preprintData.attributes.date_modified,
178+
contributors: ContributorsMapper.getContributors(preprintData.embeds?.bibliographic_contributors?.data),
179+
providerId: preprintData.relationships.provider.data.id,
180+
})),
187181
totalCount: response.meta.total,
188182
};
189183
}

src/app/features/preprints/models/preprint.models.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { UserPermissions } from '@osf/shared/enums/user-permissions.enum';
22
import { BooleanOrNull, StringOrNull } from '@osf/shared/helpers/types.helper';
3-
import { IdNameModel } from '@shared/models/common/id-name.model';
3+
import { ContributorModel } from '@osf/shared/models/contributors/contributor.model';
44
import { IdentifierModel } from '@shared/models/identifiers/identifier.model';
55
import { LicenseModel, LicenseOptions } from '@shared/models/license/license.model';
66

@@ -57,7 +57,7 @@ export interface PreprintShortInfo {
5757
id: string;
5858
title: string;
5959
dateModified: string;
60-
contributors: IdNameModel[];
60+
contributors: ContributorModel[];
6161
providerId: string;
6262
}
6363

src/app/features/preprints/pages/my-preprints/my-preprints.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<tr class="cursor-pointer" (click)="navigateToPreprintDetails(item)">
5555
<td>{{ item.title | fixSpecialChar }}</td>
5656
<td>
57-
<osf-list-info-shortener [data]="item.contributors" />
57+
<osf-contributors-list-shortener [data]="item.contributors" />
5858
</td>
5959
<td>{{ item.dateModified | date: 'MMM d, y, h:mm a' }}</td>
6060
</tr>

src/app/features/preprints/pages/my-preprints/my-preprints.component.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { TitleCasePipe } from '@angular/common';
66
import { ComponentFixture, TestBed } from '@angular/core/testing';
77
import { ActivatedRoute, Router } from '@angular/router';
88

9-
import { ListInfoShortenerComponent } from '@osf/shared/components/list-info-shortener/list-info-shortener.component';
9+
import { ContributorsListShortenerComponent } from '@osf/shared/components/contributors-list-shortener/contributors-list-shortener.component';
1010
import { SearchInputComponent } from '@osf/shared/components/search-input/search-input.component';
1111
import { SubHeaderComponent } from '@osf/shared/components/sub-header/sub-header.component';
1212
import { DEFAULT_TABLE_PARAMS } from '@osf/shared/constants/default-table-params.constants';
@@ -54,7 +54,7 @@ describe('MyPreprintsComponent', () => {
5454
imports: [
5555
MyPreprintsComponent,
5656
OSFTestingModule,
57-
...MockComponents(SubHeaderComponent, SearchInputComponent, ListInfoShortenerComponent),
57+
...MockComponents(SubHeaderComponent, SearchInputComponent, ContributorsListShortenerComponent),
5858
MockPipe(TitleCasePipe),
5959
],
6060
providers: [

src/app/features/preprints/pages/my-preprints/my-preprints.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
2323
import { FormControl } from '@angular/forms';
2424
import { ActivatedRoute, Router } from '@angular/router';
2525

26-
import { ListInfoShortenerComponent } from '@osf/shared/components/list-info-shortener/list-info-shortener.component';
26+
import { ContributorsListShortenerComponent } from '@osf/shared/components/contributors-list-shortener/contributors-list-shortener.component';
2727
import { SearchInputComponent } from '@osf/shared/components/search-input/search-input.component';
2828
import { SubHeaderComponent } from '@osf/shared/components/sub-header/sub-header.component';
2929
import { DEFAULT_TABLE_PARAMS } from '@osf/shared/constants/default-table-params.constants';
@@ -46,7 +46,7 @@ import { FetchMyPreprints, MyPreprintsSelectors } from '../../store/my-preprints
4646
TableModule,
4747
Skeleton,
4848
DatePipe,
49-
ListInfoShortenerComponent,
49+
ContributorsListShortenerComponent,
5050
TitleCasePipe,
5151
FixSpecialCharPipe,
5252
],
Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,21 @@
1-
import { Store } from '@ngxs/store';
2-
31
import { MockComponent } from 'ng-mocks';
42

5-
import { of } from 'rxjs';
6-
7-
import { signal } from '@angular/core';
83
import { ComponentFixture, TestBed } from '@angular/core/testing';
94

105
import { GlobalSearchComponent } from '@osf/shared/components/global-search/global-search.component';
6+
import { SEARCH_TAB_OPTIONS } from '@osf/shared/constants/search-tab-options.const';
117

128
import { SearchComponent } from './search.component';
139

14-
describe.skip('SearchComponent', () => {
10+
describe('SearchComponent', () => {
1511
let component: SearchComponent;
1612
let fixture: ComponentFixture<SearchComponent>;
17-
let store: Store;
1813

1914
beforeEach(async () => {
2015
await TestBed.configureTestingModule({
2116
imports: [SearchComponent, MockComponent(GlobalSearchComponent)],
22-
providers: [],
2317
}).compileComponents();
2418

25-
store = TestBed.inject(Store);
26-
jest.spyOn(store, 'selectSignal').mockReturnValue(signal(''));
27-
jest.spyOn(store, 'dispatch').mockReturnValue(of(undefined));
28-
2919
fixture = TestBed.createComponent(SearchComponent);
3020
component = fixture.componentInstance;
3121
fixture.detectChanges();
@@ -34,4 +24,17 @@ describe.skip('SearchComponent', () => {
3424
it('should create', () => {
3525
expect(component).toBeTruthy();
3626
});
27+
28+
it('should initialize searchTabOptions with SEARCH_TAB_OPTIONS', () => {
29+
expect(component.searchTabOptions).toEqual(SEARCH_TAB_OPTIONS);
30+
});
31+
32+
it('should render template with correct structure', () => {
33+
const hostElement = fixture.debugElement.nativeElement;
34+
const containerDiv = hostElement.querySelector('div.mt-6.pt-5');
35+
expect(containerDiv).toBeTruthy();
36+
37+
const globalSearch = containerDiv.querySelector('osf-global-search');
38+
expect(globalSearch).toBeTruthy();
39+
});
3740
});

src/app/shared/components/list-info-shortener/list-info-shortener.component.html renamed to src/app/shared/components/contributors-list-shortener/contributors-list-shortener.component.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44
@if (dataValue && dataValue.length > 0) {
55
<div class="flex flex-row gap-1">
66
@for (item of dataValue.slice(0, limitValue); track item.id) {
7-
{{ item.name }}{{ $last ? '' : ', ' }}
7+
{{ item.fullName }}{{ $last ? '' : ', ' }}
88
}
99

1010
@if (dataValue.length > limitValue) {
1111
<p [pTooltip]="tooltipData" tooltipPosition="bottom" autoHide="false">
1212
{{ 'common.labels.and' | translate }} {{ dataValue.length - limitValue }} {{ 'common.labels.more' | translate }}
1313
</p>
14+
1415
<ng-template #tooltipData>
1516
@for (item of dataValue.slice(limitValue); track item.id) {
1617
<div>
17-
{{ item.name }}
18+
{{ item.fullName }}
1819
</div>
1920
}
2021
</ng-template>

src/app/shared/components/list-info-shortener/list-info-shortener.component.scss renamed to src/app/shared/components/contributors-list-shortener/contributors-list-shortener.component.scss

File renamed without changes.

src/app/shared/components/list-info-shortener/list-info-shortener.component.spec.ts renamed to src/app/shared/components/contributors-list-shortener/contributors-list-shortener.component.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ import { ComponentRef } from '@angular/core';
22
import { ComponentFixture, TestBed } from '@angular/core/testing';
33
import { By } from '@angular/platform-browser';
44

5-
import { ListInfoShortenerComponent } from './list-info-shortener.component';
5+
import { ContributorsListShortenerComponent } from './contributors-list-shortener.component';
66

7-
describe('ListInfoShortenerComponent', () => {
8-
let component: ListInfoShortenerComponent;
9-
let fixture: ComponentFixture<ListInfoShortenerComponent>;
10-
let componentRef: ComponentRef<ListInfoShortenerComponent>;
7+
describe('ContributorsListShortenerComponent', () => {
8+
let component: ContributorsListShortenerComponent;
9+
let fixture: ComponentFixture<ContributorsListShortenerComponent>;
10+
let componentRef: ComponentRef<ContributorsListShortenerComponent>;
1111

1212
beforeEach(async () => {
1313
await TestBed.configureTestingModule({
14-
imports: [ListInfoShortenerComponent],
14+
imports: [ContributorsListShortenerComponent],
1515
}).compileComponents();
1616

17-
fixture = TestBed.createComponent(ListInfoShortenerComponent);
17+
fixture = TestBed.createComponent(ContributorsListShortenerComponent);
1818
component = fixture.componentInstance;
1919
componentRef = fixture.componentRef;
2020
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { TranslatePipe } from '@ngx-translate/core';
2+
3+
import { Tooltip } from 'primeng/tooltip';
4+
5+
import { ChangeDetectionStrategy, Component, input } from '@angular/core';
6+
7+
import { ContributorModel } from '@osf/shared/models/contributors/contributor.model';
8+
9+
@Component({
10+
selector: 'osf-contributors-list-shortener',
11+
imports: [Tooltip, TranslatePipe],
12+
templateUrl: './contributors-list-shortener.component.html',
13+
styleUrl: './contributors-list-shortener.component.scss',
14+
changeDetection: ChangeDetectionStrategy.OnPush,
15+
})
16+
export class ContributorsListShortenerComponent {
17+
data = input<ContributorModel[]>([]);
18+
limit = input<number>(2);
19+
}

0 commit comments

Comments
 (0)