diff --git a/libs/shared/src/lib/components/controls/resource-select/resource-select.component.ts b/libs/shared/src/lib/components/controls/resource-select/resource-select.component.ts index 4fb555a4d1..f668376c5a 100644 --- a/libs/shared/src/lib/components/controls/resource-select/resource-select.component.ts +++ b/libs/shared/src/lib/components/controls/resource-select/resource-select.component.ts @@ -80,17 +80,7 @@ export class ResourceSelectComponent extends GraphQLSelectComponent { this.valueField = 'id'; this.textField = 'name'; this.filterable = true; - this.searchChange.pipe(takeUntil(this.destroy$)).subscribe((value) => { - this.onSearchChange(value); - }); - } - - /** - * Override GraphQLSelectComponent onOpenSelect to only load query when - * select menu is open for the first time. - * - */ - public override onOpenSelect(): void { + /** Initialize resource query with the component automatically*/ if (!this.query) { this.query = this.apollo.watchQuery({ query: GET_RESOURCES, @@ -99,15 +89,10 @@ export class ResourceSelectComponent extends GraphQLSelectComponent { sortField: 'name', }, }); - - this.query.valueChanges - .pipe(takeUntil(this.queryChange$), takeUntil(this.destroy$)) - .subscribe(({ data, loading }) => { - this.queryName = Object.keys(data)[0]; - this.updateValues(data, loading); - }); } - super.onOpenSelect(); + this.searchChange.pipe(takeUntil(this.destroy$)).subscribe((value) => { + this.onSearchChange(value); + }); } /** diff --git a/libs/shared/src/lib/survey/components/resource-dropdown/resource-dropdown.component.html b/libs/shared/src/lib/survey/components/resource-dropdown/resource-dropdown.component.html index 153e2931fa..c0e069f5e9 100644 --- a/libs/shared/src/lib/survey/components/resource-dropdown/resource-dropdown.component.html +++ b/libs/shared/src/lib/survey/components/resource-dropdown/resource-dropdown.component.html @@ -3,7 +3,7 @@ diff --git a/libs/shared/src/lib/survey/components/resource-dropdown/resource-dropdown.component.ts b/libs/shared/src/lib/survey/components/resource-dropdown/resource-dropdown.component.ts index 7f74858dd0..e010b5d3f9 100644 --- a/libs/shared/src/lib/survey/components/resource-dropdown/resource-dropdown.component.ts +++ b/libs/shared/src/lib/survey/components/resource-dropdown/resource-dropdown.component.ts @@ -6,15 +6,15 @@ import { } from '@angular/core'; import { UntypedFormControl } from '@angular/forms'; import { Apollo } from 'apollo-angular'; +import { Subject } from 'rxjs'; +import { takeUntil } from 'rxjs/operators'; +import { QuestionAngular } from 'survey-angular-ui'; import { Resource, ResourceQueryResponse, } from '../../../models/resource.model'; import { GET_SHORT_RESOURCE_BY_ID } from './graphql/queries'; -import { takeUntil } from 'rxjs/operators'; -import { QuestionAngular } from 'survey-angular-ui'; import { QuestionResourceDropdownModel } from './resource-dropdown.model'; -import { Subject } from 'rxjs'; /** * This component is used to create a dropdown where the user can select a resource. @@ -29,7 +29,7 @@ export class ResourceDropdownComponent implements OnInit { /** Selected resource */ - public selectedResource?: Resource; + public selectedResource: Resource[] = []; /** Resource control */ public resourceControl!: UntypedFormControl; @@ -54,13 +54,6 @@ export class ResourceDropdownComponent override ngOnInit(): void { super.ngOnInit(); - this.resourceControl = new UntypedFormControl(this.model.value ?? ''); - this.resourceControl.valueChanges - .pipe(takeUntil(this.destroy$)) - .subscribe((value) => { - this.model.value = value; - this.model.obj.gridFieldsSettings = null; - }); if (this.model.value) { this.apollo .query({ @@ -71,9 +64,17 @@ export class ResourceDropdownComponent }) .subscribe(({ data }) => { if (data.resource) { - this.selectedResource = data.resource; + this.selectedResource = [data.resource]; + this.changeDetectorRef.detectChanges(); } }); } + this.resourceControl = new UntypedFormControl(this.model.value ?? ''); + this.resourceControl.valueChanges + .pipe(takeUntil(this.destroy$)) + .subscribe((value) => { + this.model.value = value; + this.model.obj.gridFieldsSettings = null; + }); } } diff --git a/libs/ui/src/lib/graphql-select/graphql-select.component.ts b/libs/ui/src/lib/graphql-select/graphql-select.component.ts index 4621f961a1..746d77e8e2 100644 --- a/libs/ui/src/lib/graphql-select/graphql-select.component.ts +++ b/libs/ui/src/lib/graphql-select/graphql-select.component.ts @@ -533,9 +533,10 @@ export class GraphQLSelectComponent const selectedElements = this.selectedElements.filter( (selectedElement) => selectedElement && - !elements.find( - (node) => node[this.valueField] === selectedElement[this.valueField] - ) + (this.isSurveyQuestion || + !elements.find( + (node) => node[this.valueField] === selectedElement[this.valueField] + )) ); this.cachedElements = updateQueryUniqueValues(this.cachedElements, [ ...selectedElements,