/*! * SAPUI5 * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. */ import i18n from "../i18n"; import Text from "sap/m/Text"; import Toolbar from "sap/m/Toolbar"; // import ToolbarSpacer from "sap/m/ToolbarSpacer"; import { ToolbarDesign } from "sap/m/library"; import { OrderBy } from "../SearchModelTypes"; import { SortAttribute } from "../SearchResultBaseFormatter"; /** * @namespace sap.esh.search.ui.controls */ export default class SearchSortBar extends Toolbar { private sortText: Text; constructor(sId?: string) { super(sId); // blue bar this.setProperty("design", ToolbarDesign.Info); this.addStyleClass("sapUshellSearchSortContextualBar"); // filter text string this.sortText = new Text(this.getId() + "-sortText", { text: { parts: [{ path: "/orderBy" }, { path: "/sortableAttributes" }], formatter: this.sortFormatter, }, tooltip: { parts: [{ path: "orderBy" }, { path: "/sortableAttributes" }], formatter: this.sortFormatter, }, }).addStyleClass("sapUshellSearchSortText"); this.sortText.setMaxLines(1); this.addContent(this.sortText); // // filter middle space // this.addContent(new ToolbarSpacer()); } sortFormatter(orderByObject: OrderBy, sortableAttributes: Array): string { if (!orderByObject || !orderByObject?.orderBy || !orderByObject?.sortOrder || !sortableAttributes) { return ""; } const sortOrderFormatted = orderByObject.sortOrder === "ASC" ? i18n.getText("sorted_ASC") : i18n.getText("sorted_DESC"); const orderByFormatted = sortableAttributes.find( (attr) => attr.attributeId === orderByObject?.orderBy )?.name; return ( i18n.getText("sorted_by") + " " + orderByFormatted + " (" + orderByObject?.orderBy + ") " + sortOrderFormatted ); } onAfterRendering(oEvent): void { super.onAfterRendering(oEvent); // don't have model until after rendering // // attach press action // this.resetButton.attachPress(() => { // const model = this.getModel() as SearchModel; // model.eventLogger.logEvent({ // type: UserEventType.CLEAR_ALL_FILTERS, // dataSourceKey: model.getDataSource().id, // }); // model.resetFilterByFilterConditions(true); // }); // add aria label const filterText = document.querySelector(".sapUshellSearchSortText"); if (filterText) { filterText.setAttribute("aria-label", i18n.getText("sorted_by_aria_label")); } } static renderer = { apiVersion: 2, }; }