From b43d91d0b13bd61ba5d617cf2bd1ac73d8f03204 Mon Sep 17 00:00:00 2001 From: kylebuss Date: Mon, 23 Dec 2024 15:47:08 -0600 Subject: [PATCH] SF-3141 Fix selected reference books persisting between steps --- .../draft-generation-steps.component.html | 2 +- .../draft-generation-steps.component.spec.ts | 21 ++++++++----------- .../draft-generation-steps.component.ts | 12 +++++------ 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation-steps/draft-generation-steps.component.html b/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation-steps/draft-generation-steps.component.html index 13a544c8bf..de0f2fc415 100644 --- a/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation-steps/draft-generation-steps.component.html +++ b/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation-steps/draft-generation-steps.component.html @@ -126,7 +126,7 @@

{{ t("reference_books") }}

} @else { diff --git a/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation-steps/draft-generation-steps.component.spec.ts b/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation-steps/draft-generation-steps.component.spec.ts index 1388af59b6..dd9e8482ee 100644 --- a/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation-steps/draft-generation-steps.component.spec.ts +++ b/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation-steps/draft-generation-steps.component.spec.ts @@ -219,6 +219,7 @@ describe('DraftGenerationStepsComponent', () => { const trainingDataFiles: string[] = []; const translationBooks = [2]; + component.refBooksSelectedTrainingBooks = trainingBooks; component.userSelectedTrainingBooks = trainingBooks; component.userSelectedTranslateBooks = translationBooks; component.selectedTrainingDataIds = trainingDataFiles; @@ -231,13 +232,13 @@ describe('DraftGenerationStepsComponent', () => { fixture.detectChanges(); expect(component.availableTrainingBooks).toEqual(trainingBooks); expect(component.selectableSourceTrainingBooks).toEqual(trainingBooks); - expect(component.userSelectedSourceTrainingBooks).toEqual(trainingBooks); + expect(component.refBooksSelectedTrainingBooks).toEqual(trainingBooks); expect(fixture.nativeElement.querySelector('.books-appear-notice')).toBeNull(); component.onSourceTrainingBookSelect([]); fixture.detectChanges(); expect(component.selectableSourceTrainingBooks).toEqual(trainingBooks); - expect(component.userSelectedSourceTrainingBooks).toEqual([]); + expect(component.refBooksSelectedTrainingBooks).toEqual([]); expect(fixture.nativeElement.querySelector('.books-appear-notice')).toBeNull(); }); @@ -335,7 +336,7 @@ describe('DraftGenerationStepsComponent', () => { component.userSelectedTrainingBooks = trainingBooks; component.userSelectedTranslateBooks = translationBooks; component.selectedTrainingDataIds = trainingDataFiles; - component.userSelectedSourceTrainingBooks = trainingBooks; + component.refBooksSelectedTrainingBooks = trainingBooks.filter(book => !translationBooks.includes(book)); component['draftSourceProjectIds'] = { draftingSourceId: 'sourceProject', trainingSourceId: 'sourceProject' }; spyOn(component.done, 'emit'); @@ -532,7 +533,7 @@ describe('DraftGenerationStepsComponent', () => { component.userSelectedTrainingBooks = trainingBooks; component.userSelectedTranslateBooks = translationBooks; component.selectedTrainingDataIds = trainingDataFiles; - component.userSelectedSourceTrainingBooks = trainingBooks; + component.refBooksSelectedTrainingBooks = trainingBooks; component.userSelectedAdditionalSourceTrainingBooks = trainingBooks; component['draftSourceProjectIds'] = { draftingSourceId: 'sourceProject', @@ -568,20 +569,15 @@ describe('DraftGenerationStepsComponent', () => { it('does not allow selecting not selectable additional source training books', () => { const trainingBooks = [3]; const trainingDataFiles: string[] = []; - const translationBooks = [1, 2]; - component.userSelectedTrainingBooks = trainingBooks; - component.userSelectedTranslateBooks = translationBooks; + component.selectableAdditionalSourceTrainingBooks = trainingBooks; + component.userSelectedAdditionalSourceTrainingBooks = trainingBooks; component.selectedTrainingDataIds = trainingDataFiles; component['draftSourceProjectIds'] = { draftingSourceId: 'sourceProject', trainingSourceId: 'sourceProject', trainingAdditionalSourceId: 'sourceProject2' }; - component.onStepChange(); - expect(component.availableTrainingBooks).toEqual(trainingBooks); - expect(component.selectableSourceTrainingBooks).toEqual(trainingBooks); - expect(component.userSelectedSourceTrainingBooks).toEqual(trainingBooks); expect(component.selectableAdditionalSourceTrainingBooks).toEqual(trainingBooks); expect(component.userSelectedAdditionalSourceTrainingBooks).toEqual(trainingBooks); @@ -598,7 +594,7 @@ describe('DraftGenerationStepsComponent', () => { component.userSelectedTrainingBooks = trainingBooks; component.userSelectedTranslateBooks = translationBooks; component.selectedTrainingDataIds = trainingDataFiles; - component.userSelectedSourceTrainingBooks = trainingBooks; + component.refBooksSelectedTrainingBooks = trainingBooks; component.userSelectedAdditionalSourceTrainingBooks = trainingBooks; component['draftSourceProjectIds'] = { draftingSourceId: 'sourceProject', @@ -656,6 +652,7 @@ describe('DraftGenerationStepsComponent', () => { component.userSelectedTranslateBooks = translationBooks; component.selectedTrainingDataIds = trainingDataFiles; component.userSelectedSourceTrainingBooks = trainingBooks; + component.refBooksSelectedTrainingBooks = trainingBooks; component['draftSourceProjectIds'] = { draftingSourceId: 'sourceProject', trainingSourceId: 'sourceProject' }; spyOn(component.done, 'emit'); diff --git a/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation-steps/draft-generation-steps.component.ts b/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation-steps/draft-generation-steps.component.ts index 8dd14cdde9..aa75a67196 100644 --- a/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation-steps/draft-generation-steps.component.ts +++ b/src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-generation-steps/draft-generation-steps.component.ts @@ -76,6 +76,7 @@ export class DraftGenerationStepsComponent extends SubscriptionDisposable implem userSelectedSourceTrainingBooks: number[] = []; userSelectedAdditionalSourceTrainingBooks: number[] = []; + refBooksSelectedTrainingBooks: number[] = []; selectedTrainingDataIds: string[] = []; draftingSourceProjectName?: string; @@ -270,6 +271,7 @@ export class DraftGenerationStepsComponent extends SubscriptionDisposable implem // automatically select books that are newly selected as training books for (const bookNum of newBookSelections) { this.userSelectedSourceTrainingBooks.push(bookNum); + this.refBooksSelectedTrainingBooks.push(bookNum); if (this.selectableAdditionalSourceTrainingBooks.includes(bookNum)) { this.userSelectedAdditionalSourceTrainingBooks.push(bookNum); } @@ -284,7 +286,7 @@ export class DraftGenerationStepsComponent extends SubscriptionDisposable implem } onSourceTrainingBookSelect(selectedBooks: number[]): void { - this.userSelectedSourceTrainingBooks = this.selectableSourceTrainingBooks.filter(b => selectedBooks.includes(b)); + this.refBooksSelectedTrainingBooks = this.selectableSourceTrainingBooks.filter(b => selectedBooks.includes(b)); this.clearErrorMessage(); } @@ -319,10 +321,10 @@ export class DraftGenerationStepsComponent extends SubscriptionDisposable implem } this.isStepsCompleted = true; const trainingScriptureRange: ProjectScriptureRange | undefined = - this.userSelectedSourceTrainingBooks.length > 0 + this.refBooksSelectedTrainingBooks.length > 0 ? this.convertToScriptureRange( this.draftSourceProjectIds!.trainingAlternateSourceId ?? this.draftSourceProjectIds!.trainingSourceId, - this.userSelectedSourceTrainingBooks + this.refBooksSelectedTrainingBooks ) : undefined; @@ -372,9 +374,6 @@ export class DraftGenerationStepsComponent extends SubscriptionDisposable implem this.selectableAdditionalSourceTrainingBooks = this.availableAdditionalTrainingBooks.filter(b => newSelectedTrainingBooks.includes(b) ); - this.userSelectedAdditionalSourceTrainingBooks = this.selectableAdditionalSourceTrainingBooks.filter(b => - newSelectedTrainingBooks.includes(b) - ); } bookNames(books: number[]): string { @@ -434,6 +433,7 @@ export class DraftGenerationStepsComponent extends SubscriptionDisposable implem this.userSelectedAdditionalSourceTrainingBooks = this.availableAdditionalTrainingBooks.filter(b => this.initialSelectedTrainingBooks.includes(b) ); + this.refBooksSelectedTrainingBooks = [...this.userSelectedSourceTrainingBooks]; } private setInitialTrainingDataFiles(availableDataFiles: string[]): void {