Fix: include base href when opening global search result in new window (#10066)

This commit is contained in:
shamoon 2025-05-27 15:59:17 -07:00 committed by GitHub
parent f39463ff4e
commit c40a7751b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 4 deletions

View File

@ -529,6 +529,17 @@ describe('GlobalSearchComponent', () => {
expect(dispatchSpy).toHaveBeenCalledTimes(2) // once for keydown, second for click expect(dispatchSpy).toHaveBeenCalledTimes(2) // once for keydown, second for click
}) })
it('should support using base href in navigateOrOpenInNewWindow', () => {
jest
.spyOn(component['locationStrategy'], 'getBaseHref')
.mockReturnValue('/base/')
const openSpy = jest.spyOn(window, 'open')
const event = new Event('click')
event['ctrlKey'] = true
component.primaryAction(DataType.Document, { id: 1 }, event as any)
expect(openSpy).toHaveBeenCalledWith('/base/documents/1', '_blank')
})
it('should support title content search and advanced search', () => { it('should support title content search and advanced search', () => {
const qfSpy = jest.spyOn(documentListViewService, 'quickFilter') const qfSpy = jest.spyOn(documentListViewService, 'quickFilter')
component.query = 'test' component.query = 'test'

View File

@ -1,4 +1,4 @@
import { NgTemplateOutlet } from '@angular/common' import { LocationStrategy, NgTemplateOutlet } from '@angular/common'
import { import {
Component, Component,
ElementRef, ElementRef,
@ -99,7 +99,8 @@ export class GlobalSearchComponent implements OnInit {
private permissionsService: PermissionsService, private permissionsService: PermissionsService,
private toastService: ToastService, private toastService: ToastService,
private hotkeyService: HotKeyService, private hotkeyService: HotKeyService,
private settingsService: SettingsService private settingsService: SettingsService,
private locationStrategy: LocationStrategy
) { ) {
this.queryDebounce = new Subject<string>() this.queryDebounce = new Subject<string>()
@ -421,10 +422,13 @@ export class GlobalSearchComponent implements OnInit {
extras: Object = {} extras: Object = {}
) { ) {
if (newWindow) { if (newWindow) {
const url = this.router.serializeUrl( const serializedUrl = this.router.serializeUrl(
this.router.createUrlTree(commands, extras) this.router.createUrlTree(commands, extras)
) )
window.open(url, '_blank') const baseHref = this.locationStrategy.getBaseHref()
const fullUrl =
baseHref.replace(/\/+$/, '') + '/' + serializedUrl.replace(/^\/+/, '')
window.open(fullUrl, '_blank')
} else { } else {
this.router.navigate(commands, extras) this.router.navigate(commands, extras)
} }