From 092a57f8b9b27e5b80d9a904d0ddda66429ccd59 Mon Sep 17 00:00:00 2001 From: jacekpluta <73617938+jacekpluta@users.noreply.github.com> Date: Mon, 28 Oct 2024 10:41:52 +0100 Subject: [PATCH] [ACS-8907] Remove query / question from input on the results page (#4189) * [ACS-8907] Remove query / question from input on the results page * [ACS-8907] Remove query / question from input on the results page --- .../search-ai-input-container.component.html | 2 +- ...earch-ai-input-container.component.spec.ts | 6 +- .../search-ai-input-container.component.ts | 2 +- .../search-ai-input.component.spec.ts | 59 ++++++++++--------- .../search-ai-input.component.ts | 17 ++---- .../search-ai-results.component.html | 2 +- 6 files changed, 42 insertions(+), 46 deletions(-) diff --git a/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-input-container/search-ai-input-container.component.html b/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-input-container/search-ai-input-container.component.html index 0ca1d4b14c..83e2cde329 100644 --- a/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-input-container/search-ai-input-container.component.html +++ b/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-input-container/search-ai-input-container.component.html @@ -2,7 +2,7 @@ [searchTerm]="(inputState$ | async).searchTerm" [placeholder]="placeholder" [agentId]="agentId" - [useStoredNodes]="useStoredNodes"> + [usedInAiResultsPage]="usedInAiResultsPage"> { expect(inputComponent.agentId).toBe(component.agentId); }); - it('should have assigned correct useStoredNodes flag', () => { - component.useStoredNodes = true; + it('should have assigned correct usedInAiResultsPage flag', () => { + component.usedInAiResultsPage = true; fixture.detectChanges(); - expect(inputComponent.useStoredNodes).toBeTrue(); + expect(inputComponent.usedInAiResultsPage).toBeTrue(); }); it('should set inputState$ to toggleSearchAiInput$ from the service on ngOnInit', () => { diff --git a/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-input-container/search-ai-input-container.component.ts b/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-input-container/search-ai-input-container.component.ts index ffba9d9606..e05923b839 100644 --- a/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-input-container/search-ai-input-container.component.ts +++ b/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-input-container/search-ai-input-container.component.ts @@ -48,7 +48,7 @@ export class SearchAiInputContainerComponent implements OnInit { @Input() agentId: string; @Input() - useStoredNodes: boolean; + usedInAiResultsPage: boolean; inputState$: Observable; isKnowledgeRetrievalPage = false; diff --git a/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-input/search-ai-input.component.spec.ts b/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-input/search-ai-input.component.spec.ts index 80aab55963..6891e90aab 100644 --- a/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-input/search-ai-input.component.spec.ts +++ b/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-input/search-ai-input.component.spec.ts @@ -56,8 +56,18 @@ describe('SearchAiInputComponent', () => { let agents$: Subject; let dialog: MatDialog; let activatedRoute: ActivatedRoute; + let userPreferencesService: UserPreferencesService; let agentList: Agent[]; + const newSelectionState: SelectionState = { + ...selectionState, + file: { + entry: { + id: 'some-id' + } + } as NodeEntry + }; + const prepareBeforeTest = (): void => { selectionState = { nodes: [], @@ -94,6 +104,10 @@ describe('SearchAiInputComponent', () => { loader = TestbedHarnessEnvironment.loader(fixture); agents$ = new Subject(); dialog = TestBed.inject(MatDialog); + userPreferencesService = TestBed.inject(UserPreferencesService); + spyOn(userPreferencesService, 'get').and.returnValue(JSON.stringify(newSelectionState)); + spyOn(userPreferencesService, 'set'); + spyOn(TestBed.inject(AgentService), 'getAgents').and.returnValue(agents$); agentList = [ { id: '1', @@ -108,7 +122,6 @@ describe('SearchAiInputComponent', () => { avatarUrl: undefined } ]; - spyOn(TestBed.inject(AgentService), 'getAgents').and.returnValue(agents$); prepareBeforeTest(); }); @@ -143,12 +156,24 @@ describe('SearchAiInputComponent', () => { expect(component.queryControl.value).toBe(query); }); - it('should set queryControl value to query param if searchTerm is not defined', () => { - component.searchTerm = undefined; + it('should set queryControl value to "some new query" if usedInAiResultsPage is equal to false', () => { + const query = 'some new query'; + component.usedInAiResultsPage = false; + component.searchTerm = query; component.ngOnInit(); - expect(component.queryControl.value).toBe('some query'); + expect(component.queryControl.value).toBe('some new query'); + }); + + it('should set queryControl value to empty string if usedInAiResultsPage is equal to true', () => { + const query = 'some new query'; + component.usedInAiResultsPage = true; + component.searchTerm = query; + + component.ngOnInit(); + + expect(component.queryControl.value).toBe(''); }); it('should get agents on init', () => { @@ -285,7 +310,6 @@ describe('SearchAiInputComponent', () => { it('should be disabled by default', () => { activatedRoute.snapshot.queryParams = { query: '' }; - component.ngOnInit(); fixture.detectChanges(); @@ -320,7 +344,6 @@ describe('SearchAiInputComponent', () => { describe('Submitting', () => { let checkSearchAvailabilitySpy: jasmine.Spy<(selectedNodesState: SelectionState, maxSelectedNodes?: number) => string>; let notificationService: NotificationService; - let userPreferencesService: UserPreferencesService; let submitButton: DebugElement; let queryInput: MatInputHarness; let submittingTrigger: () => void; @@ -334,8 +357,6 @@ describe('SearchAiInputComponent', () => { modalAiService = TestBed.inject(ModalAiService); checkSearchAvailabilitySpy = spyOn(TestBed.inject(SearchAiService), 'checkSearchAvailability'); notificationService = TestBed.inject(NotificationService); - userPreferencesService = TestBed.inject(UserPreferencesService); - spyOn(userPreferencesService, 'set'); spyOn(notificationService, 'showError'); queryInput = await loader.getHarness(MatInputHarness); submitButton = fixture.debugElement.query(By.directive(MatButton)); @@ -376,16 +397,7 @@ describe('SearchAiInputComponent', () => { }); it('should call checkSearchAvailability on SearchAiService with parameter based on value returned by UserPreferencesService', () => { - component.useStoredNodes = true; - const newSelectionState: SelectionState = { - ...selectionState, - file: { - entry: { - id: 'some-id' - } - } as NodeEntry - }; - spyOn(userPreferencesService, 'get').and.returnValue(JSON.stringify(newSelectionState)); + component.usedInAiResultsPage = true; component.ngOnInit(); submittingTrigger(); @@ -400,16 +412,7 @@ describe('SearchAiInputComponent', () => { }); it('should call set on UserPreferencesService with parameter based on value returned by UserPreferencesService', () => { - component.useStoredNodes = true; - const newSelectionState: SelectionState = { - ...selectionState, - file: { - entry: { - id: 'some-id' - } - } as NodeEntry - }; - spyOn(userPreferencesService, 'get').and.returnValue(JSON.stringify(newSelectionState)); + component.usedInAiResultsPage = true; component.ngOnInit(); submittingTrigger(); diff --git a/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-input/search-ai-input.component.ts b/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-input/search-ai-input.component.ts index 7516ea5011..327040f397 100644 --- a/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-input/search-ai-input.component.ts +++ b/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-input/search-ai-input.component.ts @@ -48,7 +48,6 @@ import { } from '@angular/material/tooltip'; import { ModalAiService } from '../../../../services/modal-ai.service'; import { Agent } from '@alfresco/js-api'; -import { ActivatedRoute } from '@angular/router'; const MatTooltipOptions: MatTooltipDefaultOptions = { ...MAT_TOOLTIP_DEFAULT_OPTIONS_FACTORY(), @@ -87,7 +86,7 @@ export class SearchAiInputComponent implements OnInit, OnDestroy { agentId: string; @Input() - useStoredNodes: boolean; + usedInAiResultsPage: boolean; @Input() searchTerm: string; @@ -124,20 +123,14 @@ export class SearchAiInputComponent implements OnInit, OnDestroy { private agentService: AgentService, private userPreferencesService: UserPreferencesService, private translateService: TranslateService, - private modalAiService: ModalAiService, - private route: ActivatedRoute + private modalAiService: ModalAiService ) {} ngOnInit(): void { - if (this.searchTerm) { - this.queryControl.setValue(this.searchTerm); - } else if (this.route.snapshot?.queryParams?.query?.length > 0) { - this.queryControl.setValue(this.route.snapshot.queryParams.query); - } else { - this.queryControl.setValue(null); - } + const queryValue = this.usedInAiResultsPage ? '' : this.searchTerm || ''; + this.queryControl.setValue(queryValue); - if (!this.useStoredNodes) { + if (!this.usedInAiResultsPage) { this.store .select(getAppSelection) .pipe(takeUntil(this.onDestroy$)) diff --git a/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-results/search-ai-results.component.html b/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-results/search-ai-results.component.html index 2d68fd091d..e861a0cb2e 100644 --- a/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-results/search-ai-results.component.html +++ b/projects/aca-content/src/lib/components/knowledge-retrieval/search-ai/search-ai-results/search-ai-results.component.html @@ -3,7 +3,7 @@ class="aca-page-layout-header" placeholder="KNOWLEDGE_RETRIEVAL.SEARCH.RESULTS_PAGE.QUERY_INPUT_PLACEHOLDER" [agentId]="agentId" - [useStoredNodes]="true" + [usedInAiResultsPage]="true" *ngIf="!hasError && agentId">