From ca78e05b6e50f7df3798f3d021049dec45a9d045 Mon Sep 17 00:00:00 2001 From: milan Date: Wed, 21 Feb 2024 09:54:20 +0100 Subject: [PATCH] Fix error when deleting Mail --- api/js/etemplate/Et2Tree/Et2Tree.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/api/js/etemplate/Et2Tree/Et2Tree.ts b/api/js/etemplate/Et2Tree/Et2Tree.ts index 9f9a9f9628..3c63443a0f 100644 --- a/api/js/etemplate/Et2Tree/Et2Tree.ts +++ b/api/js/etemplate/Et2Tree/Et2Tree.ts @@ -394,9 +394,12 @@ export class Et2Tree extends Et2WidgetWithSelectMixin(LitElement) } + /** + * @return currently selected Item or First Item, if no selection was made yet + */ public getSelectedItem(): TreeItemData { - return this._currentOption + return this._currentOption || this._selectOptions[0] } /** @@ -420,6 +423,7 @@ export class Et2Tree extends Et2WidgetWithSelectMixin(LitElement) */ public getNode(_id: string): TreeItemData { + if(_id == undefined){debugger;} // TODO: Look into this._search(), find out why it doesn't always succeed return this._search(_id, this._selectOptions) ?? this.optionSearch(_id, this._selectOptions, 'id', 'item') } @@ -810,9 +814,20 @@ export class Et2Tree extends Et2WidgetWithSelectMixin(LitElement) super.updated(_changedProperties); } + /** + * + * @param _id to search for + * @param data{TreeItemData[]} structure to search in + * @return {TreeItemData} node with the given _id or null + * @private + */ private _search(_id: string, data: TreeItemData[]): TreeItemData { let res: TreeItemData = null + if (_id == undefined) + { + return null + } for (const value of data) { if (value.id === _id)