/*! * SAPUI5 * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. */ import i18n from "../../i18n"; import Select, { $SelectSettings } from "sap/m/Select"; import { SelectType } from "sap/m/library"; import Item from "sap/ui/core/Item"; import BindingMode from "sap/ui/model/BindingMode"; import SearchModel from "sap/esh/search/ui/SearchModel"; import { DataSource } from "../../sinaNexTS/sina/DataSource"; import { UserEventType } from "../../eventlogging/UserEvents"; import { BASKET_PANEL_DOMINANCE_THRESHOLD_PERCENT } from "../../UIUtil"; import InvisibleText from "sap/ui/core/InvisibleText"; import Element from "sap/ui/core/Element"; import { callConfigExit } from "../../error/callConfigExit"; /** * @namespace sap.esh.search.ui.controls */ export default class SearchSelect extends Select { private _dataSourceSelectionModeFireQuery = false; constructor(sId?: string, settings?: $SelectSettings) { super(sId, settings); this.initStandardMode(); } private initStandardMode(): void { this.bindProperty("visible", { path: "/businessObjSearchEnabled" }); this.setAutoAdjustWidth(true); this.bindItems({ path: "/dataSources", template: new Item("", { key: "{id}", text: "{labelPlural}", }), }); this.bindProperty("selectedKey", { path: "/uiFilter/dataSource/id", mode: BindingMode.OneWay, }); this.bindProperty("tooltip", { parts: [ { path: "/uiFilter/dataSource/labelPlural", }, ], formatter: (labelPlural) => { return i18n.getText("searchInPlaceholder", [labelPlural]); }, }); this.attachChange(this.handleSelectionChange, this); this.bindProperty("enabled", { parts: [ { path: "/initializingObjSearch", }, { path: "/basketPanelWidthPercent", }, ], formatter: (initializingObjSearch: boolean, basketPanelWidthPercent: number) => !initializingObjSearch && basketPanelWidthPercent <= BASKET_PANEL_DOMINANCE_THRESHOLD_PERCENT, }); this.addStyleClass("searchSelect"); if (!Element.getElementById("searchCategoryLabel")) { new InvisibleText("searchCategoryLabel", { text: i18n.getText("searchCategoryLabel"), }).toStatic(); } if (!this.getAriaLabelledBy().includes("searchCategoryLabel")) { this.addAriaLabelledBy("searchCategoryLabel"); } } private handleSelectionChange(): void { const item = this.getSelectedItem(); if (!item) { return; } const context = item.getBindingContext(); if (!context) { return; } const dataSource = context.getObject() as DataSource; const oModel = this.getModel() as SearchModel; const dataSourceKeyOld = oModel.getDataSource().id; oModel.eventLogger.logEvent({ type: UserEventType.DROPDOWN_SELECT_DS, dataSourceKey: dataSource.id, dataSourceKeyOld, }); if (this._dataSourceSelectionModeFireQuery) { if (oModel.config.bResetSearchTermOnQuickSelectDataSourceItemPress) { oModel.setSearchBoxTerm("", false); } if (typeof oModel.config.adjustFilters === "function") { callConfigExit( "adjustFilters", oModel.config.applicationComponent, () => oModel.config.adjustFilters(oModel), oModel.errorHandler ); } } oModel.setDataSource(dataSource, this._dataSourceSelectionModeFireQuery); oModel.abortSuggestions(); } setDataSourceSelectionModeFireQuery(fireQuery: boolean): void { if (fireQuery === this._dataSourceSelectionModeFireQuery) { return; } this._dataSourceSelectionModeFireQuery = fireQuery; if (fireQuery) { this.detachChange(this.handleSelectionChange, this); this.unbindProperty("visible", false); this.unbindProperty("selectedKey", false); this.unbindProperty("tooltip", false); this.unbindProperty("enabled", false); this.unbindAggregation("items", false); this.attachChange(this.handleSelectionChange, this); this.bindItems({ path: "/config/quickSelectDataSources", template: new Item("", { key: "{id}", text: "{labelPlural}", }), }); this.bindProperty("maxWidth", { parts: [{ path: "/config/optimizeForValueHelp" }], formatter: (optimizeForValueHelp: boolean) => { this.toggleStyleClass( "sapElisaSearchSelectQuickSelectDataSourceValueHelp", optimizeForValueHelp ); return "100%"; }, }); this.bindProperty("visible", { parts: [ { path: "/config/optimizeForValueHelp" }, { path: "/config/quickSelectDataSources" }, { path: "/config/quickSelectDataSources/length" }, { path: "/count" }, ], formatter: (optimizeForValueHelp: boolean, qds: DataSource[]) => { this.toggleStyleClass( "sapElisaSearchSelectQuickSelectDataSourceValueHelp", optimizeForValueHelp ); return qds?.length > 0; }, }); this.setAutoAdjustWidth(false); this.removeStyleClass("searchSelect"); } else { this.detachChange(this.handleSelectionChange, this); this.unbindProperty("visible", false); this.unbindProperty("maxWidth", false); this.unbindAggregation("items", false); this.removeStyleClass("sapElisaSearchSelectQuickSelectDataSourceValueHelp"); this.initStandardMode(); } } getDataSourceSelectionModeFireQuery(): boolean { return this._dataSourceSelectionModeFireQuery; } setDisplayMode(mode: "icon" | "default"): void { switch (mode) { case "icon": this.setType(SelectType.IconOnly); this.setIcon("sap-icon://slim-arrow-down"); break; case "default": this.setType(SelectType.Default); break; default: break; } } static renderer = { apiVersion: 2, }; }