From fe7e55393d6f8be2313c69ddddafbc6aa9c8ee05 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sat, 5 Oct 2019 20:14:35 +0200 Subject: [PATCH] Dropdown improved. --- .../references-dropdown.component.ts | 37 ++++++------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/src/Squidex/app/shared/components/references-dropdown.component.ts b/src/Squidex/app/shared/components/references-dropdown.component.ts index 97309c382..949d3b7a9 100644 --- a/src/Squidex/app/shared/components/references-dropdown.component.ts +++ b/src/Squidex/app/shared/components/references-dropdown.component.ts @@ -7,8 +7,6 @@ import { ChangeDetectionStrategy, ChangeDetectorRef, Component, forwardRef, Input, OnInit } from '@angular/core'; import { FormControl, NG_VALUE_ACCESSOR } from '@angular/forms'; -import { throwError } from 'rxjs'; -import { switchMap } from 'rxjs/operators'; import { AppLanguageDto, @@ -16,8 +14,6 @@ import { ContentDto, ContentsService, getContentValue, - SchemaDetailsDto, - SchemasService, StatefulControlComponent, Types, UIOptions @@ -28,9 +24,7 @@ export const SQX_REFERENCES_DROPDOWN_CONTROL_VALUE_ACCESSOR: any = { }; interface State { - schema?: SchemaDetailsDto | null; - - contentItems: ContentDto[]; + contents: ContentDto[]; contentNames: ContentName[]; selectedItem?: ContentName; @@ -69,19 +63,17 @@ export class ReferencesDropdownComponent extends StatefulControlComponent ({ ...s, contentNames: this.createContentNames(s.schema, s.contentItems) })); + this.next(s => ({ ...s, contentNames: this.createContentNames(s.contents) })); } public selectionControl = new FormControl(''); constructor(changeDetector: ChangeDetectorRef, uiOptions: UIOptions, private readonly appsState: AppsState, - private readonly contentsService: ContentsService, - private readonly schemasService: SchemasService + private readonly contentsService: ContentsService ) { super(changeDetector, { - schema: null, - contentItems: [], + contents: [], contentNames: [] }); @@ -116,19 +108,12 @@ export class ReferencesDropdownComponent extends StatefulControlComponent { - if (schema) { - return this.contentsService.getContents(this.appsState.appName, this.schemaId, this.itemCount, 0); - } else { - return throwError('Invalid schema'); - } - }, (schema, contents) => ({ schema, contents }))) - .subscribe(({ schema, contents }) => { + this.contentsService.getContents(this.appsState.appName, this.schemaId, this.itemCount, 0) + .subscribe(contents => { const contentItems = contents.items; - const contentNames = this.createContentNames(schema, contentItems); + const contentNames = this.createContentNames(contentItems); - this.next(s => ({ ...s, schema, contentItems, contentNames })); + this.next(s => ({ ...s, contents: contentItems, contentNames })); this.selectContent(); }, () => { @@ -160,14 +145,14 @@ export class ReferencesDropdownComponent extends StatefulControlComponent { const name = - schema.referenceFields + content.referenceFields .map(f => getContentValue(content, this.languageField, f, false)) .map(v => v.formatted) .filter(v => !!v)