Skip to content

Commit 844aecf

Browse files
authored
fix(project-settings): fixed project settings bug (#569)
1 parent cbba67a commit 844aecf

File tree

11 files changed

+50
-137
lines changed

11 files changed

+50
-137
lines changed

src/app/features/preprints/services/preprints-projects.service.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ import { inject, Injectable } from '@angular/core';
44

55
import { ENVIRONMENT } from '@core/provider/environment.provider';
66
import { Primitive, StringOrNull } from '@osf/shared/helpers';
7-
import { ApiData, CreateProjectPayloadJsoApi, IdName, JsonApiResponse, NodeData } from '@osf/shared/models';
7+
import {
8+
ApiData,
9+
CreateProjectPayloadJsoApi,
10+
IdName,
11+
NodeResponseJsonApi,
12+
NodesResponseJsonApi,
13+
} from '@osf/shared/models';
814
import { JsonApiService } from '@osf/shared/services';
915

1016
import { PreprintsMapper } from '../mappers';
@@ -29,7 +35,7 @@ export class PreprintsProjectsService {
2935
params['filter[title]'] = searchTerm;
3036
}
3137

32-
return this.jsonApiService.get<JsonApiResponse<NodeData[], null>>(`${this.apiUrl}/users/me/nodes/`, params).pipe(
38+
return this.jsonApiService.get<NodesResponseJsonApi>(`${this.apiUrl}/users/me/nodes/`, params).pipe(
3339
map((response) => {
3440
return response.data.map((item) => ({
3541
id: item.id,
@@ -40,7 +46,7 @@ export class PreprintsProjectsService {
4046
}
4147

4248
getProjectById(projectId: string): Observable<IdName> {
43-
return this.jsonApiService.get<JsonApiResponse<NodeData, null>>(`${this.apiUrl}/nodes/${projectId}/`).pipe(
49+
return this.jsonApiService.get<NodeResponseJsonApi>(`${this.apiUrl}/nodes/${projectId}/`).pipe(
4450
map((response) => {
4551
return {
4652
id: response.data.id,
@@ -114,7 +120,7 @@ export class PreprintsProjectsService {
114120
},
115121
};
116122

117-
return this.jsonApiService.post<JsonApiResponse<NodeData, null>>(`${this.apiUrl}/nodes/`, payload).pipe(
123+
return this.jsonApiService.post<NodeResponseJsonApi>(`${this.apiUrl}/nodes/`, payload).pipe(
118124
map((response) => {
119125
return {
120126
id: response.data.id,

src/app/features/project/settings/components/settings-project-form-card/settings-project-form-card.component.html

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,7 @@ <h2 class="pb-4">{{ 'myProjects.settings.project' | translate }}</h2>
3434
</div>
3535

3636
<div class="flex justify-content-end w-full flex-0 border-top-1 pt-4 border-gray-300">
37-
<p-button
38-
(onClick)="deleteProject.emit()"
39-
severity="danger"
40-
[label]="'myProjects.settings.deleteProject' | translate"
41-
class="btn-full-width sm:w-10rem md:ml-auto"
42-
></p-button>
37+
<p-button (onClick)="deleteProject.emit()" severity="danger" [label]="deleteLabel() | translate"></p-button>
4338
</div>
4439
</form>
4540
</p-card>

src/app/features/project/settings/components/settings-project-form-card/settings-project-form-card.component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Button } from 'primeng/button';
44
import { Card } from 'primeng/card';
55
import { Textarea } from 'primeng/textarea';
66

7-
import { ChangeDetectionStrategy, Component, effect, input, output } from '@angular/core';
7+
import { ChangeDetectionStrategy, Component, computed, effect, input, output } from '@angular/core';
88
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
99

1010
import { TextInputComponent } from '@osf/shared/components';
@@ -34,6 +34,10 @@ export class SettingsProjectFormCardComponent {
3434
[ProjectFormControls.Description]: new FormControl(''),
3535
});
3636

37+
deleteLabel = computed(() =>
38+
this.projectDetails().parentId ? 'myProjects.settings.deleteComponent' : 'myProjects.settings.deleteProject'
39+
);
40+
3741
constructor() {
3842
this.setupFormEffects();
3943
}

src/app/features/project/settings/mappers/settings.mapper.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { UserPermissions } from '@osf/shared/enums';
22
import { InstitutionsMapper } from '@osf/shared/mappers';
3+
import { RegionsMapper } from '@osf/shared/mappers/regions';
34

45
import {
56
NodeDataJsonApi,
@@ -32,14 +33,12 @@ export class SettingsMapper {
3233
title: data.attributes.title,
3334
description: data.attributes.description,
3435
isPublic: data.attributes.public,
35-
region: {
36-
id: data.embeds?.region.data.id,
37-
name: data.embeds?.region.data.attributes.name,
38-
},
36+
region: RegionsMapper.getRegion(data?.embeds?.region?.data),
3937
affiliatedInstitutions: data.embeds
4038
? InstitutionsMapper.fromInstitutionsResponse(data.embeds.affiliated_institutions)
4139
: [],
4240
currentUserPermissions: data.attributes.current_user_permissions as UserPermissions[],
41+
parentId: data.relationships.parent?.data?.id,
4342
lastFetched: Date.now(),
4443
};
4544
}

src/app/features/project/settings/models/node-details.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ export interface NodeDetailsModel {
88
region: IdName;
99
affiliatedInstitutions: Institution[];
1010
currentUserPermissions: string[];
11+
parentId?: string;
1112
lastFetched: number;
1213
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import { InstitutionsJsonApiResponse, NodeData, ResponseDataJsonApi } from '@osf/shared/models';
1+
import {
2+
BaseNodeDataJsonApi,
3+
InstitutionsJsonApiResponse,
4+
RegionDataJsonApi,
5+
ResponseDataJsonApi,
6+
} from '@osf/shared/models';
27

38
export type NodeResponseJsonApi = ResponseDataJsonApi<NodeDataJsonApi>;
49

5-
export interface NodeDataJsonApi extends NodeData {
10+
export interface NodeDataJsonApi extends BaseNodeDataJsonApi {
611
embeds: NodeEmbedsJsonApi;
712
}
813

914
interface NodeEmbedsJsonApi {
1015
region: {
11-
data: {
12-
id: string;
13-
attributes: {
14-
name: string;
15-
};
16-
};
16+
data: RegionDataJsonApi;
1717
};
1818
affiliated_institutions: InstitutionsJsonApiResponse;
1919
}

src/app/features/project/settings/services/settings.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export class SettingsService {
7171
const params = {
7272
'embed[]': ['affiliated_institutions', 'region'],
7373
};
74+
7475
return this.jsonApiService
7576
.get<NodeResponseJsonApi>(`${this.apiUrl}/nodes/${projectId}/`, params)
7677
.pipe(map((response) => SettingsMapper.fromNodeResponse(response.data)));
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IdName, RegionsResponseJsonApi } from '@osf/shared/models';
1+
import { IdName, RegionDataJsonApi, RegionsResponseJsonApi } from '@osf/shared/models';
22

33
export class RegionsMapper {
44
static fromRegionsResponseJsonApi(response: RegionsResponseJsonApi): IdName[] {
@@ -7,4 +7,11 @@ export class RegionsMapper {
77
name: data.attributes.name,
88
}));
99
}
10+
11+
static getRegion(data: RegionDataJsonApi): IdName {
12+
return {
13+
id: data.id,
14+
name: data.attributes.name,
15+
};
16+
}
1017
}

src/app/shared/models/nodes/base-node-embeds-json-api.model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { IdentifierAttributes } from '@shared/models';
22

3-
export interface BaseNodeEmbeds {
3+
export interface BaseNodeEmbedsJsonApi {
44
bibliographic_contributors?: {
55
data: ContributorResource[];
66
};
Lines changed: 11 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
1-
export interface NodeData {
2-
id: string;
3-
type: 'nodes';
4-
attributes: NodeAttributes;
5-
relationships: NodeRelationships;
6-
links: NodeLinks;
7-
lastFetched?: number;
8-
}
1+
import { ResponseJsonApi } from '../common';
92

10-
export interface NodeResponseModel {
11-
data: NodeData;
12-
meta: NodeMeta;
13-
}
3+
import { BaseNodeDataJsonApi } from './base-node-data-json-api.model';
4+
5+
export type NodesResponseJsonApi = ResponseJsonApi<BaseNodeDataJsonApi[]>;
6+
export type NodeResponseJsonApi = ResponseJsonApi<BaseNodeDataJsonApi>;
147

158
export interface UpdateNodeRequestModel {
16-
data: UpdateNodeData;
9+
data: UpdateNodeDataJsonApi;
1710
}
1811

1912
export interface CreateProjectPayloadJsoApi {
@@ -42,109 +35,15 @@ export interface CreateProjectPayloadJsoApi {
4235
};
4336
}
4437

45-
interface NodeAttributes {
46-
title: string;
47-
description: string;
48-
category: string;
49-
custom_citation: string | null;
50-
date_created: string;
51-
date_modified: string;
52-
registration: boolean;
53-
preprint: boolean;
54-
fork: boolean;
55-
collection: boolean;
56-
tags: string[];
57-
access_requests_enabled: boolean;
58-
node_license: unknown | null;
59-
current_user_can_comment: boolean;
60-
current_user_permissions: string[];
61-
current_user_is_contributor: boolean;
62-
current_user_is_contributor_or_group_member: boolean;
63-
wiki_enabled: boolean;
64-
public: boolean;
65-
subjects: unknown[];
66-
}
67-
68-
interface RelationshipLinks {
69-
related: {
70-
href: string;
71-
meta: Record<string, unknown>;
72-
};
73-
self?: {
74-
href: string;
75-
meta: Record<string, unknown>;
76-
};
77-
}
78-
79-
interface NodeRelationships {
80-
children: { links: RelationshipLinks };
81-
comments: { links: RelationshipLinks };
82-
contributors: { links: RelationshipLinks };
83-
bibliographic_contributors: { links: RelationshipLinks };
84-
implicit_contributors: { links: RelationshipLinks };
85-
files: { links: RelationshipLinks };
86-
settings: {
87-
links: RelationshipLinks;
88-
data: { id: string; type: 'node-setting' };
89-
};
90-
wikis: { links: RelationshipLinks };
91-
forks: { links: RelationshipLinks };
92-
groups: { links: RelationshipLinks };
93-
node_links: { links: RelationshipLinks };
94-
linked_by_nodes: { links: RelationshipLinks };
95-
linked_by_registrations: { links: RelationshipLinks };
96-
parent: {
97-
links: RelationshipLinks;
98-
data: { id: string; type: 'nodes' };
99-
};
100-
identifiers: { links: RelationshipLinks };
101-
affiliated_institutions: { links: RelationshipLinks };
102-
draft_registrations: { links: RelationshipLinks };
103-
registrations: { links: RelationshipLinks };
104-
region: {
105-
links: RelationshipLinks;
106-
data: { id: string; type: 'regions' };
107-
};
108-
root: {
109-
links: RelationshipLinks;
110-
data: { id: string; type: 'nodes' };
111-
};
112-
logs: { links: RelationshipLinks };
113-
linked_nodes: { links: RelationshipLinks };
114-
linked_registrations: { links: RelationshipLinks };
115-
view_only_links: { links: RelationshipLinks };
116-
citation: {
117-
links: RelationshipLinks;
118-
data: { id: string; type: 'citation' };
119-
};
120-
preprints: { links: RelationshipLinks };
121-
storage: {
122-
links: RelationshipLinks;
123-
data: { id: string; type: 'node-storage' };
124-
};
125-
cedar_metadata_records: { links: RelationshipLinks };
126-
subjects_acceptable: { links: RelationshipLinks };
127-
}
128-
129-
interface NodeLinks {
130-
html: string;
131-
self: string;
132-
iri: string;
133-
}
134-
135-
interface NodeMeta {
136-
version: string;
38+
interface UpdateNodeDataJsonApi {
39+
id: string;
40+
type: 'nodes';
41+
attributes: UpdateNodeAttributesJsonApi;
13742
}
13843

139-
interface UpdateNodeAttributes {
44+
interface UpdateNodeAttributesJsonApi {
14045
description?: string;
14146
tags?: string[];
14247
public?: boolean;
14348
title?: string;
14449
}
145-
146-
interface UpdateNodeData {
147-
type: 'nodes';
148-
id: string;
149-
attributes: UpdateNodeAttributes;
150-
}

0 commit comments

Comments
 (0)