From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Tue, 18 Apr 2023 02:42:24 +0000 (-0700) Subject: Fix multi-select with private items X-Git-Tag: v1.14.1~1^2~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b80c2126a3f22e7198adbebfb6938bfd1733ffba;p=thirdparty%2Fpaperless-ngx.git Fix multi-select with private items --- diff --git a/src-ui/src/app/components/common/input/select/select.component.ts b/src-ui/src/app/components/common/input/select/select.component.ts index ddf900bf6b..3d81f6f49c 100644 --- a/src-ui/src/app/components/common/input/select/select.component.ts +++ b/src-ui/src/app/components/common/input/select/select.component.ts @@ -30,14 +30,34 @@ export class SelectComponent extends AbstractInputComponent { @Input() set items(items) { - if (this.value && items.find((i) => i.id === this.value) === undefined) { - items.push({ - id: this.value, + this._items = items + if (items && this.value) this.checkForPrivateItems(this.value) + } + + writeValue(newValue: any): void { + if (newValue && this._items) { + this.checkForPrivateItems(newValue) + this.items = [...this._items] // we need to explicitly re-set items + } + super.writeValue(newValue) + } + + checkForPrivateItems(value: any) { + if (Array.isArray(value) && value.length > 0) { + value.forEach((id) => this.checkForPrivateItem(id)) + } else { + this.checkForPrivateItem(value) + } + } + + checkForPrivateItem(id) { + if (this._items.find((i) => i.id === id) === undefined) { + this._items.push({ + id: id, name: $localize`Private`, private: true, }) } - this._items = items } get items(): any[] {