Skip to content

Commit 7940f4c

Browse files
authored
SF-3192 Fix book names on the Auto Draft page on UI language changes (#3364)
1 parent 339d287 commit 7940f4c

File tree

6 files changed

+15
-34
lines changed

6 files changed

+15
-34
lines changed

src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-preview-books/draft-preview-books.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<ng-container *transloco="let t; read: 'draft_preview_books'">
2-
@for (book of booksWithDrafts$ | async; track book.bookNumber) {
2+
@for (book of booksWithDrafts$ | async; track book.bookId) {
33
<mat-button-toggle-group
44
class="draft-book-option"
55
[disabled]="book.chaptersWithDrafts.length === 0"
66
(change)="$event.source.checked = false"
77
>
88
<mat-button-toggle class="book-name" (click)="navigate(book)">
9-
{{ bookNumberToName(book.bookNumber) }}
9+
{{ "canon.book_names." + book.bookId | transloco }}
1010
</mat-button-toggle>
1111
<mat-button-toggle class="book-more" [mat-menu-trigger-for]="menu">
1212
<mat-icon>more_vert</mat-icon>

src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-preview-books/draft-preview-books.component.spec.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { anything, capture, instance, mock, verify, when } from 'ts-mockito';
1313
import { ActivatedProjectService } from 'xforge-common/activated-project.service';
1414
import { DialogService } from 'xforge-common/dialog.service';
1515
import { ErrorReportingService } from 'xforge-common/error-reporting.service';
16-
import { I18nService } from 'xforge-common/i18n.service';
1716
import { configureTestingModule, TestTranslocoModule } from 'xforge-common/test-utils';
1817
import { UserService } from 'xforge-common/user.service';
1918
import { SFProjectProfileDoc } from '../../../core/models/sf-project-profile-doc';
@@ -27,7 +26,6 @@ import { BookWithDraft, DraftPreviewBooksComponent } from './draft-preview-books
2726

2827
const mockedActivatedProjectService = mock(ActivatedProjectService);
2928
const mockedProjectService = mock(SFProjectService);
30-
const mockedI18nService = mock(I18nService);
3129
const mockedUserService = mock(UserService);
3230
const mockedDraftHandlingService = mock(DraftHandlingService);
3331
const mockedDialogService = mock(DialogService);
@@ -43,7 +41,6 @@ describe('DraftPreviewBooks', () => {
4341
providers: [
4442
{ provide: ActivatedProjectService, useMock: mockedActivatedProjectService },
4543
{ provide: SFProjectService, useMock: mockedProjectService },
46-
{ provide: I18nService, useMock: mockedI18nService },
4744
{ provide: UserService, useMock: mockedUserService },
4845
{ provide: DraftHandlingService, useMock: mockedDraftHandlingService },
4946
{ provide: DialogService, useMock: mockedDialogService },
@@ -371,15 +368,14 @@ class TestEnvironment {
371368
} as SFProjectProfileDoc;
372369

373370
booksWithDrafts: BookWithDraft[] = [
374-
{ bookNumber: 1, canEdit: true, chaptersWithDrafts: [1, 2, 3], draftApplied: false },
375-
{ bookNumber: 2, canEdit: true, chaptersWithDrafts: [1], draftApplied: false },
376-
{ bookNumber: 3, canEdit: false, chaptersWithDrafts: [1, 2], draftApplied: false }
371+
{ bookNumber: 1, bookId: 'GEN', canEdit: true, chaptersWithDrafts: [1, 2, 3], draftApplied: false },
372+
{ bookNumber: 2, bookId: 'EXO', canEdit: true, chaptersWithDrafts: [1], draftApplied: false },
373+
{ bookNumber: 3, bookId: 'LEV', canEdit: false, chaptersWithDrafts: [1, 2], draftApplied: false }
377374
];
378375

379376
constructor(build: BuildDto | undefined = undefined) {
380377
when(mockedActivatedProjectService.changes$).thenReturn(of(this.mockProjectDoc));
381378
when(mockedActivatedProjectService.projectDoc).thenReturn(this.mockProjectDoc);
382-
when(mockedI18nService.localizeBook(1)).thenReturn('Genesis');
383379
when(
384380
mockedDraftHandlingService.getAndApplyDraftAsync(anything(), anything(), anything(), anything())
385381
).thenResolve();

src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-preview-books/draft-preview-books.component.ts

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { BehaviorSubject, firstValueFrom, map, Observable, tap } from 'rxjs';
1111
import { ActivatedProjectService } from 'xforge-common/activated-project.service';
1212
import { DialogService } from 'xforge-common/dialog.service';
1313
import { ErrorReportingService } from 'xforge-common/error-reporting.service';
14-
import { I18nService } from 'xforge-common/i18n.service';
1514
import { UICommonModule } from 'xforge-common/ui-common.module';
1615
import { UserService } from 'xforge-common/user.service';
1716
import { filterNullish } from 'xforge-common/util/rxjs-util';
@@ -34,6 +33,7 @@ import { DraftHandlingService } from '../draft-handling.service';
3433

3534
export interface BookWithDraft {
3635
bookNumber: number;
36+
bookId: string;
3737
canEdit: boolean;
3838
chaptersWithDrafts: number[];
3939
draftApplied: boolean;
@@ -61,6 +61,7 @@ export class DraftPreviewBooksComponent {
6161
draftBooks = projectDoc.data.texts
6262
.map(text => ({
6363
bookNumber: text.bookNum,
64+
bookId: Canon.bookNumberToId(text.bookNum),
6465
canEdit: text.permissions[this.userService.currentUserId] === TextInfoPermission.Write,
6566
chaptersWithDrafts: text.chapters.filter(chapter => chapter.hasDraft).map(chapter => chapter.number),
6667
draftApplied: text.chapters.filter(chapter => chapter.hasDraft).every(chapter => chapter.draftApplied)
@@ -75,6 +76,7 @@ export class DraftPreviewBooksComponent {
7576
const text: TextInfo | undefined = projectDoc.data?.texts.find(t => t.bookNum === bookNum);
7677
return {
7778
bookNumber: bookNum,
79+
bookId: Canon.bookNumberToId(bookNum),
7880
canEdit: text?.permissions?.[this.userService.currentUserId] === TextInfoPermission.Write,
7981
chaptersWithDrafts: text?.chapters?.map(ch => ch.number) ?? [],
8082
draftApplied: text?.chapters?.filter(ch => ch.hasDraft).every(ch => ch.draftApplied) ?? false
@@ -101,7 +103,6 @@ export class DraftPreviewBooksComponent {
101103
constructor(
102104
private readonly activatedProjectService: ActivatedProjectService,
103105
private readonly projectService: SFProjectService,
104-
private readonly i18n: I18nService,
105106
private readonly userService: UserService,
106107
private readonly draftHandlingService: DraftHandlingService,
107108
private readonly dialogService: DialogService,
@@ -114,22 +115,8 @@ export class DraftPreviewBooksComponent {
114115
return this.chaptersApplied.length;
115116
}
116117

117-
linkForBookAndChapter(bookNumber: number, chapterNumber: number): string[] {
118-
return [
119-
'/projects',
120-
this.activatedProjectService.projectId!,
121-
'translate',
122-
this.bookNumberToBookId(bookNumber),
123-
chapterNumber.toString()
124-
];
125-
}
126-
127-
bookNumberToBookId(bookNumber: number): string {
128-
return Canon.bookNumberToId(bookNumber);
129-
}
130-
131-
bookNumberToName(bookNumber: number): string {
132-
return this.i18n.localizeBook(bookNumber);
118+
linkForBookAndChapter(bookId: string, chapterNumber: number): string[] {
119+
return ['/projects', this.activatedProjectService.projectId!, 'translate', bookId, chapterNumber.toString()];
133120
}
134121

135122
async chooseProjectToAddDraft(bookWithDraft: BookWithDraft, paratextId?: string): Promise<void> {
@@ -197,7 +184,7 @@ export class DraftPreviewBooksComponent {
197184
}
198185

199186
navigate(book: BookWithDraft): void {
200-
this.router.navigate(this.linkForBookAndChapter(book.bookNumber, book.chaptersWithDrafts[0]), {
187+
this.router.navigate(this.linkForBookAndChapter(book.bookId, book.chaptersWithDrafts[0]), {
201188
queryParams: { 'draft-active': true, 'draft-timestamp': this.build?.additionalInfo?.dateGenerated }
202189
});
203190
}

src/SIL.XForge.Scripture/ClientApp/src/app/translate/editor/editor-draft/editor-draft.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<mat-progress-bar mode="indeterminate" color="accent"></mat-progress-bar>
44
} @else if (draftCheckState === "draft-empty") {
55
<app-notice icon="info" type="primary" mode="outline">
6-
{{ "editor_draft_tab.no_draft_notice" | transloco: { bookChapterName } }}
6+
{{ "editor_draft_tab.no_draft_notice" | transloco: { bookChapterName: this.getLocalizedBookChapter() } }}
77
<p>{{ "editor_draft_tab.click_book_to_preview" | transloco }}</p>
88
<app-draft-preview-books></app-draft-preview-books>
99
</app-notice>

src/SIL.XForge.Scripture/ClientApp/src/app/translate/editor/editor-draft/editor-draft.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ describe('EditorDraftComponent', () => {
471471
});
472472

473473
it('should return a localized book and chapter if both are not null', () => {
474-
when(mockI18nService.localizeBook(1)).thenReturn('Localized Book');
474+
when(mockI18nService.localizeBookChapter(1, 1)).thenReturn('Localized Book 1');
475475
component.bookNum = 1;
476476
component.chapter = 1;
477477
expect(component['getLocalizedBookChapter']()).toEqual('Localized Book 1');

src/SIL.XForge.Scripture/ClientApp/src/app/translate/editor/editor-draft/editor-draft.component.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ export class EditorDraftComponent implements AfterViewInit, OnChanges {
5858
draftCheckState: 'draft-unknown' | 'draft-present' | 'draft-legacy' | 'draft-empty' = 'draft-unknown';
5959
draftRevisions: Revision[] = [];
6060
selectedRevision: Revision | undefined;
61-
bookChapterName = '';
6261
generateDraftUrl?: string;
6362
targetProject?: SFProjectProfile;
6463
textDocId?: TextDocId;
@@ -268,7 +267,6 @@ export class EditorDraftComponent implements AfterViewInit, OnChanges {
268267

269268
private setInitialState(): void {
270269
this.draftCheckState = 'draft-unknown';
271-
this.bookChapterName = this.getLocalizedBookChapter();
272270
this.isDraftReady = false;
273271
this.isDraftApplied = false;
274272
this.userAppliedDraft = false;
@@ -313,12 +311,12 @@ export class EditorDraftComponent implements AfterViewInit, OnChanges {
313311
return hasContent ?? false;
314312
}
315313

316-
private getLocalizedBookChapter(): string {
314+
protected getLocalizedBookChapter(): string {
317315
if (this.bookNum == null || this.chapter == null) {
318316
return '';
319317
}
320318

321-
return this.i18n.localizeBook(this.bookNum) + ' ' + this.chapter;
319+
return this.i18n.localizeBookChapter(this.bookNum, this.chapter);
322320
}
323321

324322
private getTargetOps(): Observable<DeltaOperation[]> {

0 commit comments

Comments
 (0)