Skip to content

Commit 982a66b

Browse files
committed
fix(wiki-list): Make rename wiki work
1 parent a8f8715 commit 982a66b

File tree

14 files changed

+183
-9
lines changed

14 files changed

+183
-9
lines changed

src/app/features/project/wiki/wiki.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
[canEdit]="hasWriteAccess()"
3737
(createWiki)="onCreateWiki()"
3838
(deleteWiki)="onDeleteWiki()"
39+
(renameWiki)="onRenameWiki()"
3940
></osf-wiki-list>
4041
@if (wikiModes().view) {
4142
<osf-view-section

src/app/features/project/wiki/wiki.component.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ export class WikiComponent {
151151
this.navigateToWiki(this.currentWikiId());
152152
}
153153

154+
onRenameWiki() {
155+
this.navigateToWiki(this.currentWikiId());
156+
}
157+
154158
onDeleteWiki() {
155159
this.actions.deleteWiki(this.currentWikiId()).pipe(tap(() => this.navigateToWiki(this.currentWikiId())));
156160
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<form [formGroup]="renameWikiForm" (ngSubmit)="submitForm()">
2+
<osf-text-input
3+
[control]="renameWikiForm.controls['name']"
4+
[placeholder]="'project.wiki.addNewWikiPlaceholder'"
5+
[maxLength]="inputLimits.fullName.maxLength"
6+
>
7+
</osf-text-input>
8+
9+
<div class="flex justify-content-end gap-2 mt-4">
10+
<p-button [label]="'common.buttons.cancel' | translate" severity="info" (onClick)="dialogRef.close()" />
11+
<p-button
12+
[label]="'common.buttons.rename' | translate"
13+
type="submit"
14+
[loading]="isSubmitting()"
15+
[disabled]="renameWikiForm.invalid"
16+
/>
17+
</div>
18+
</form>

src/app/shared/components/wiki/rename-wiki-dialog/rename-wiki-dialog.component.scss

Whitespace-only changes.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { createDispatchMap, select } from '@ngxs/store';
2+
3+
import { TranslatePipe } from '@ngx-translate/core';
4+
5+
import { Button } from 'primeng/button';
6+
import { DynamicDialogConfig, DynamicDialogRef } from 'primeng/dynamicdialog';
7+
8+
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
9+
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
10+
11+
import { InputLimits } from '@osf/shared/constants/input-limits.const';
12+
import { CustomValidators } from '@osf/shared/helpers/custom-form-validators.helper';
13+
import { ToastService } from '@osf/shared/services/toast.service';
14+
import { RenameWiki, WikiSelectors } from '@osf/shared/stores/wiki';
15+
16+
import { TextInputComponent } from '../../text-input/text-input.component';
17+
18+
@Component({
19+
selector: 'osf-rename-wiki-dialog-component',
20+
imports: [Button, ReactiveFormsModule, TranslatePipe, TextInputComponent],
21+
templateUrl: './rename-wiki-dialog.component.html',
22+
styleUrl: './rename-wiki-dialog.component.scss',
23+
changeDetection: ChangeDetectionStrategy.OnPush,
24+
})
25+
export class RenameWikiDialogComponent {
26+
readonly dialogRef = inject(DynamicDialogRef);
27+
readonly config = inject(DynamicDialogConfig);
28+
private toastService = inject(ToastService);
29+
30+
actions = createDispatchMap({ renameWiki: RenameWiki });
31+
isSubmitting = select(WikiSelectors.getWikiSubmitting);
32+
inputLimits = InputLimits;
33+
34+
renameWikiForm = new FormGroup({
35+
name: new FormControl('', {
36+
nonNullable: true,
37+
validators: [CustomValidators.requiredTrimmed(), Validators.maxLength(InputLimits.fullName.maxLength)],
38+
}),
39+
});
40+
41+
submitForm(): void {
42+
if (this.renameWikiForm.valid) {
43+
this.actions.renameWiki(this.config.data.wikiId, this.renameWikiForm.value.name ?? '').subscribe({
44+
next: (res) => {
45+
this.toastService.showSuccess('project.wiki.renameWikiSuccess');
46+
this.dialogRef.close(res);
47+
},
48+
error: (err) => {
49+
if (err?.status === 409) {
50+
this.toastService.showError('project.wiki.renameWikiConflict');
51+
}
52+
},
53+
});
54+
}
55+
}
56+
}

src/app/shared/components/wiki/wiki-list/wiki-list.component.html

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,18 @@ <h4 class="ml-2">{{ item.label | translate }}</h4>
6262
<span class="ml-2">{{ item.label | translate }}</span>
6363
}
6464
@default {
65-
<div>
66-
<i class="far fa-file"></i>
67-
<span class="ml-2">{{ item.label }}</span>
65+
<div class="flex align-items-center justify-content-between w-full">
66+
<div class="flex align-items-center">
67+
<i class="far fa-file"></i>
68+
<span class="ml-2">{{ item.label }}</span>
69+
</div>
70+
71+
<p-button
72+
icon="fas fa-pencil"
73+
styleClass="p-button-rounded p-button-text"
74+
(onClick)="openRenameWikiDialog(item.id); $event.stopPropagation()"
75+
>
76+
</p-button>
6877
</div>
6978
}
7079
}

src/app/shared/components/wiki/wiki-list/wiki-list.component.scss

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,4 @@
77
min-width: 300px;
88
width: 300px;
99
}
10-
11-
.active {
12-
background-color: var(--pr-blue-1);
13-
color: var(--white);
14-
}
1510
}

src/app/shared/components/wiki/wiki-list/wiki-list.component.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { WikiItemType } from '@osf/shared/models/wiki/wiki-type.model';
1414
import { CustomConfirmationService } from '@osf/shared/services/custom-confirmation.service';
1515
import { CustomDialogService } from '@osf/shared/services/custom-dialog.service';
1616
import { ComponentWiki } from '@osf/shared/stores/wiki';
17+
import { RenameWikiDialogComponent } from '@shared/components/wiki/rename-wiki-dialog/rename-wiki-dialog.component';
1718

1819
import { AddWikiDialogComponent } from '../add-wiki-dialog/add-wiki-dialog.component';
1920

@@ -35,6 +36,7 @@ export class WikiListComponent {
3536

3637
readonly deleteWiki = output<void>();
3738
readonly createWiki = output<void>();
39+
readonly renameWiki = output<void>();
3840

3941
private readonly customDialogService = inject(CustomDialogService);
4042
private readonly customConfirmationService = inject(CustomConfirmationService);
@@ -97,6 +99,18 @@ export class WikiListComponent {
9799
.onClose.subscribe(() => this.createWiki.emit());
98100
}
99101

102+
openRenameWikiDialog(wikiId: string) {
103+
this.customDialogService
104+
.open(RenameWikiDialogComponent, {
105+
header: 'project.wiki.renameWiki',
106+
width: '448px',
107+
data: {
108+
wikiId: wikiId,
109+
},
110+
})
111+
.onClose.subscribe(() => this.renameWiki.emit());
112+
}
113+
100114
openDeleteWikiDialog(): void {
101115
this.customConfirmationService.confirmDelete({
102116
headerKey: 'project.wiki.deleteWiki',

src/app/shared/mappers/wiki/wiki.mapper.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
HomeWikiGetResponse,
55
WikiGetResponse,
66
WikiModel,
7+
WikiRenameResponse,
78
WikiVersion,
89
WikiVersionJsonApi,
910
} from '@osf/shared/models/wiki/wiki.model';
@@ -18,6 +19,14 @@ export class WikiMapper {
1819
};
1920
}
2021

22+
static fromRenameWikiResponse(data: WikiRenameResponse): WikiModel {
23+
return {
24+
id: data.id,
25+
name: data.attributes.name,
26+
kind: data.attributes.kind,
27+
};
28+
}
29+
2130
static fromGetHomeWikiResponse(response: HomeWikiGetResponse): HomeWiki {
2231
return {
2332
id: response.id,

src/app/shared/models/wiki/wiki.model.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ export interface WikiGetResponse {
5858
};
5959
}
6060

61+
export interface WikiRenameResponse {
62+
id: string;
63+
type: string;
64+
attributes: {
65+
name: string;
66+
kind: string;
67+
};
68+
}
69+
6170
export interface ComponentsWikiGetResponse {
6271
id: string;
6372
type: string;

0 commit comments

Comments
 (0)