/*! * SAPUI5 * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. */ import { SinaObject, SinaObjectProperties } from "./SinaObject"; import { SearchResultSetItem } from "./SearchResultSetItem"; import { SearchResultSet } from "./SearchResultSet"; import { ObjectSuggestion } from "./ObjectSuggestion"; import { SearchResultSetItemAttributeBase } from "./SearchResultSetItemAttributeBase"; export interface NavigationTargetJson { targetUrl: string; text: string; icon: string; tooltip: string; target: string; } export type NavigationTracker = (navigationTarget: NavigationTarget) => void; export interface NavigationTargetOptions extends SinaObjectProperties { targetUrl?: string; targetFunction?: (context?: unknown) => void; targetFunctionCustomData?: unknown; customWindowOpenFunction?: () => void; text?: string; icon?: string; tooltip?: string; target?: string; } export class NavigationTarget extends SinaObject { targetUrl?: string; targetFunction?: (context?: unknown) => void; targetFunctionCustomData?: unknown; customWindowOpenFunction?: () => void; text?: string; icon?: string; tooltip?: string; target?: string; parent?: SearchResultSetItemAttributeBase | SearchResultSetItem | SearchResultSet | ObjectSuggestion; constructor(properties: NavigationTargetOptions) { super(properties); this.targetUrl = properties.targetUrl ?? this.targetUrl; this.targetFunction = properties.targetFunction ?? this.targetFunction; this.targetFunctionCustomData = properties.targetFunctionCustomData ?? this.targetFunctionCustomData; this.customWindowOpenFunction = properties.customWindowOpenFunction; this.text = properties.text ?? this.text; this.icon = properties.icon ?? this.icon; this.tooltip = properties.tooltip ?? this.tooltip; this.target = properties.target ?? this.target ?? "_self"; } trackNavigation() { const navigationTrackers = this.sina?.configuration?.navigationTrackers; if (!navigationTrackers) { return; } for (const navigationTracker of navigationTrackers) { navigationTracker(this); } } performNavigation(params?: { trackingOnly?: boolean; event?: unknown }): void { params = params || {}; const trackingOnly = params.trackingOnly || false; this.trackNavigation(); if (trackingOnly) { return; } if (this.targetFunction) { // 1) js target function this.targetFunction(params?.event); } else { // 2) url if (this.customWindowOpenFunction) { this.customWindowOpenFunction(); return; } if (this.target) { window.open(this.targetUrl, this.target, "noopener,noreferrer"); } else { window.open(this.targetUrl, "_blank", "noopener,noreferrer"); } } } isEqualTo(otherNavigationObject: NavigationTarget): boolean { if (!otherNavigationObject) { return false; } return ( this.targetUrl == otherNavigationObject.targetUrl && this.targetFunction === otherNavigationObject.targetFunction ); } toJson(): NavigationTargetJson { return { targetUrl: this.targetUrl, text: this.text, icon: this.icon, tooltip: this.tooltip, target: this.target, }; } }