From cce0ab57fa6f94010ef0ac5d22a74344fb29abe5 Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 16 Feb 2024 08:59:11 -0700 Subject: [PATCH] Et2Tree: Get all admin tree leaf actions working --- .../etemplate/Et2Select/Et2WidgetWithSelectMixin.ts | 6 +++--- api/js/etemplate/Et2Tree/Et2Tree.ts | 11 ++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/api/js/etemplate/Et2Select/Et2WidgetWithSelectMixin.ts b/api/js/etemplate/Et2Select/Et2WidgetWithSelectMixin.ts index fc8c185b8f..cffcbc495e 100644 --- a/api/js/etemplate/Et2Select/Et2WidgetWithSelectMixin.ts +++ b/api/js/etemplate/Et2Select/Et2WidgetWithSelectMixin.ts @@ -172,14 +172,14 @@ export const Et2WidgetWithSelectMixin = >(supe * * @return SelectOption | null */ - public optionSearch(value : string, options : SelectOption[] = null, childKey : string = "value") : SelectOption | null + public optionSearch(value : string, options : SelectOption[] = null, searchKey : string = "value", childKey : string = "value") : SelectOption | null { let result = null; let search = function(options, value) { return options.find((option) => { - if(!Array.isArray(option.value) && option.value == value) + if(!Array.isArray(option[searchKey]) && option[searchKey] == value) { result = option; } @@ -187,7 +187,7 @@ export const Et2WidgetWithSelectMixin = >(supe { return search(option[childKey], value); } - return option.value == value; + return option[searchKey] == value; }); } search(options ?? this.select_options, value); diff --git a/api/js/etemplate/Et2Tree/Et2Tree.ts b/api/js/etemplate/Et2Tree/Et2Tree.ts index 54f4a3ba26..84b81ae6d9 100644 --- a/api/js/etemplate/Et2Tree/Et2Tree.ts +++ b/api/js/etemplate/Et2Tree/Et2Tree.ts @@ -405,8 +405,8 @@ export class Et2Tree extends Et2WidgetWithSelectMixin(LitElement) */ public getNode(_id: string): TreeItemData { - - return this._search(_id, this._selectOptions) + // 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') } /** @@ -637,7 +637,7 @@ export class Et2Tree extends Et2WidgetWithSelectMixin(LitElement) this.handleLazyLoading(selectOption).then((result) => { // TODO: We already have the right option in context. Look into this.getNode(), find out why it's there. It doesn't do a deep search. - const parentNode = selectOption ?? this.getNode(selectOption.id) ?? this.optionSearch(selectOption.id, this._selectOptions, 'item'); + const parentNode = selectOption ?? this.getNode(selectOption.id) ?? this.optionSearch(selectOption.id, this._selectOptions, 'id', 'item'); parentNode.item = [...result.item] this.requestUpdate("_selectOptions") }) @@ -660,7 +660,7 @@ export class Et2Tree extends Et2WidgetWithSelectMixin(LitElement) @sl-selection-change=${ (event: any) => { this._previousOption = this._currentOption ?? (this.value.length ? this.getNode(this.value) : null); - this._currentOption = this.getNode(event.detail.selection[0].id); + this._currentOption = this.getNode(event.detail.selection[0].id) ?? this.optionSearch(event.detail.selection[0].id, this._selectOptions, 'id', 'item'); const ids = event.detail.selection.map(i => i.id); this.value = this.multiple ? ids ?? [] : ids[0] ?? ""; event.detail.previous = this._previousOption?.id; @@ -806,7 +806,8 @@ export class Et2Tree extends Et2WidgetWithSelectMixin(LitElement) { res = value return res - } else if (_id.startsWith(value.id)) + } + else if(_id.startsWith(value.id) && typeof value.item !== "undefined") { res = this._search(_id, value.item) }