From: root Date: Tue, 28 Jul 2026 06:12:40 +0000 (+0200) Subject: mgr/dashboard: fix cd-text-label-list string writeValue X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=58ef0cd98406e3dc3c3731317fe88ce1e37af209;p=ceph.git mgr/dashboard: fix cd-text-label-list string writeValue When editing services such as oauth2-proxy, backend fields like scope arrive as a single string. Spreading that string into the list turned each character into its own row. Normalize string values to one item. Fixes: https://tracker.ceph.com/issues/78808 Signed-off-by: Pedro Gonzalez Gomez --- diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/text-label-list/text-label-list.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/text-label-list/text-label-list.component.spec.ts index 4bc840655ead..13f433cd45fb 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/text-label-list/text-label-list.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/text-label-list/text-label-list.component.spec.ts @@ -41,6 +41,34 @@ describe('TextLabelListComponent', () => { expect(inputs[0].nativeElement.value).toBe(''); }); + it('should treat a string value as a single item', () => { + component.writeValue('openid profile email'); + fixture.detectChanges(); + + const inputs = fixture.debugElement.queryAll(By.css('cds-text-label input')); + expect(inputs.length).toBe(2); + expect(inputs[0].nativeElement.value).toBe('openid profile email'); + expect(inputs[1].nativeElement.value).toBe(''); + }); + + it('should not spread a string into individual characters', () => { + component.writeValue('openid'); + fixture.detectChanges(); + + const inputs = fixture.debugElement.queryAll(By.css('cds-text-label input')); + expect(inputs.length).toBe(2); + expect(inputs[0].nativeElement.value).toBe('openid'); + }); + + it('should treat null like an empty list', () => { + component.writeValue(null); + fixture.detectChanges(); + + const inputs = fixture.debugElement.queryAll(By.css('cds-text-label input')); + expect(inputs.length).toBe(1); + expect(inputs[0].nativeElement.value).toBe(''); + }); + it('should call onTouch on input changes', () => { spyOn(component as any, 'onTouched'); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/text-label-list/text-label-list.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/text-label-list/text-label-list.component.ts index 73c18bdd44c4..59309b631e36 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/text-label-list/text-label-list.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/text-label-list/text-label-list.component.ts @@ -44,8 +44,14 @@ export class TextLabelListComponent implements ControlValueAccessor { return originalValue.slice(0, -1) === value; } - writeValue(value: string[]): void { - this.values = value?.length ? [...value, ''] : ['']; + writeValue(value: string[] | string | null): void { + let items: string[] = []; + if (typeof value === 'string') { + items = value ? [value] : []; + } else if (Array.isArray(value)) { + items = [...value]; + } + this.values = items.length ? [...items, ''] : ['']; } registerOnChange(onChange: (value: string[]) => void): void {