From: Volker Theile Date: Tue, 20 Aug 2019 13:09:11 +0000 (+0200) Subject: mgr/dashboard: Editing RGW bucket fails because of name is already in use X-Git-Tag: v15.1.0~1514^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3aa45e1b1bcc18dec064885d8e0267722da3cd75;p=ceph.git mgr/dashboard: Editing RGW bucket fails because of name is already in use - Validate name only when creating a new bucket - Set field autofocus depending on whether a bucket is created/edited - Improve autofocus directive Fixes: https://tracker.ceph.com/issues/41314 Signed-off-by: Volker Theile --- diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-form/rgw-bucket-form.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-form/rgw-bucket-form.component.html index 43d0f467986..ce120fbf600 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-form/rgw-bucket-form.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-form/rgw-bucket-form.component.html @@ -48,7 +48,7 @@ placeholder="Name..." formControlName="bid" [readonly]="editing" - autofocus> + [autofocus]="!editing"> This field is required. @@ -72,7 +72,8 @@ + ` }) -export class CheckboxFormComponent {} +export class CheckboxFormComponent { + public edit = true; +} + +@Component({ + template: ` +
+ +
+ ` +}) +export class TextFormComponent { + foo() { + return false; + } +} describe('AutofocusDirective', () => { configureTestBed({ - declarations: [AutofocusDirective, CheckboxFormComponent, PasswordFormComponent] + declarations: [ + AutofocusDirective, + CheckboxFormComponent, + PasswordFormComponent, + TextFormComponent + ] }); it('should create an instance', () => { @@ -58,4 +78,13 @@ describe('AutofocusDirective', () => { const element = document.getElementById('x'); expect(element === document.activeElement).toBeTruthy(); }); + + it('should not focus the text form field', () => { + const fixture: ComponentFixture = TestBed.createComponent(TextFormComponent); + fixture.detectChanges(); + const focused = fixture.debugElement.query(By.css(':focus')); + expect(focused).toBeNull(); + const element = document.getElementById('x'); + expect(element !== document.activeElement).toBeTruthy(); + }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/directives/autofocus.directive.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/directives/autofocus.directive.ts index 809d8b76421..169571f3d09 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/directives/autofocus.directive.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/directives/autofocus.directive.ts @@ -1,4 +1,4 @@ -import { AfterViewInit, Directive, ElementRef } from '@angular/core'; +import { AfterViewInit, Directive, ElementRef, Input } from '@angular/core'; import * as _ from 'lodash'; @@ -6,12 +6,23 @@ import * as _ from 'lodash'; selector: '[autofocus]' // tslint:disable-line }) export class AutofocusDirective implements AfterViewInit { + private focus = true; + constructor(private elementRef: ElementRef) {} ngAfterViewInit() { const el: HTMLInputElement = this.elementRef.nativeElement; - if (_.isFunction(el.focus)) { + if (this.focus && _.isFunction(el.focus)) { el.focus(); } } + + @Input() + public set autofocus(condition: any) { + if (_.isBoolean(condition)) { + this.focus = condition; + } else if (_.isFunction(condition)) { + this.focus = condition(); + } + } }