From 809c185317d53c433253d281f27d20cea3d6089f Mon Sep 17 00:00:00 2001 From: Roma Date: Tue, 14 Oct 2025 19:49:51 +0300 Subject: [PATCH] fix(global-search): Normalize quotes in search text, fixed search section init on the profile page --- .../preprint-provider-hero.component.ts | 3 ++- .../pages/landing/preprints-landing.component.ts | 3 ++- src/app/features/profile/profile.component.html | 8 +++++--- src/app/features/profile/profile.component.ts | 7 +++++-- .../registries-landing/registries-landing.component.ts | 3 ++- .../components/global-search/global-search.component.ts | 5 +++-- src/app/shared/helpers/normalize-quotes.ts | 6 ++++-- 7 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/app/features/preprints/components/preprint-provider-hero/preprint-provider-hero.component.ts b/src/app/features/preprints/components/preprint-provider-hero/preprint-provider-hero.component.ts index 634e4932b..b5dbab66f 100644 --- a/src/app/features/preprints/components/preprint-provider-hero/preprint-provider-hero.component.ts +++ b/src/app/features/preprints/components/preprint-provider-hero/preprint-provider-hero.component.ts @@ -11,6 +11,7 @@ import { RouterLink } from '@angular/router'; import { PreprintProviderDetails } from '@osf/features/preprints/models'; import { CustomDialogService } from '@osf/shared/services'; import { SearchInputComponent } from '@shared/components'; +import { normalizeQuotes } from '@shared/helpers'; import { DecodeHtmlPipe } from '@shared/pipes'; import { PreprintsHelpDialogComponent } from '../preprints-help-dialog/preprints-help-dialog.component'; @@ -31,7 +32,7 @@ export class PreprintProviderHeroComponent { triggerSearch = output(); onTriggerSearch(value: string) { - this.triggerSearch.emit(value); + this.triggerSearch.emit(normalizeQuotes(value)!); } openHelpDialog() { diff --git a/src/app/features/preprints/pages/landing/preprints-landing.component.ts b/src/app/features/preprints/pages/landing/preprints-landing.component.ts index 0464f4839..46b8a3985 100644 --- a/src/app/features/preprints/pages/landing/preprints-landing.component.ts +++ b/src/app/features/preprints/pages/landing/preprints-landing.component.ts @@ -24,6 +24,7 @@ import { } from '@osf/features/preprints/store/preprint-providers'; import { SearchInputComponent } from '@shared/components'; import { ResourceType } from '@shared/enums'; +import { normalizeQuotes } from '@shared/helpers'; import { BrandService } from '@shared/services'; @Component({ @@ -87,7 +88,7 @@ export class PreprintsLandingComponent implements OnInit, OnDestroy { } redirectToSearchPageWithValue() { - const searchValue = this.searchControl.value; + const searchValue = normalizeQuotes(this.searchControl.value); this.router.navigate(['/search'], { queryParams: { search: searchValue, tab: ResourceType.Preprint }, diff --git a/src/app/features/profile/profile.component.html b/src/app/features/profile/profile.component.html index 1df872629..7ebc21851 100644 --- a/src/app/features/profile/profile.component.html +++ b/src/app/features/profile/profile.component.html @@ -4,8 +4,10 @@ @if (user()) { -
- -
+ @if (defaultSearchFiltersInitialized()) { +
+ +
+ } } } diff --git a/src/app/features/profile/profile.component.ts b/src/app/features/profile/profile.component.ts index 142bc5f0d..e0d8260e9 100644 --- a/src/app/features/profile/profile.component.ts +++ b/src/app/features/profile/profile.component.ts @@ -1,6 +1,6 @@ import { createDispatchMap, select } from '@ngxs/store'; -import { ChangeDetectionStrategy, Component, computed, DestroyRef, inject, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, Component, computed, DestroyRef, inject, OnInit, signal } from '@angular/core'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { ActivatedRoute, Router } from '@angular/router'; @@ -39,6 +39,7 @@ export class ProfileComponent implements OnInit { isMyProfile = computed(() => !this.route.snapshot.params['id']); user = computed(() => (this.isMyProfile() ? this.loggedInUser() : this.userProfile())); + defaultSearchFiltersInitialized = signal(false); ngOnInit(): void { const userId = this.route.snapshot.params['id']; @@ -65,6 +66,7 @@ export class ProfileComponent implements OnInit { private setupMyProfile(user: UserModel): void { this.actions.setUserProfile(user); if (user?.iri) { + this.defaultSearchFiltersInitialized.set(true); this.actions.setDefaultFilterValue('creator,isContainedBy.creator', user.iri); } } @@ -72,7 +74,8 @@ export class ProfileComponent implements OnInit { private setSearchFilter(): void { const currentUser = this.user(); if (currentUser?.iri) { - this.actions.setDefaultFilterValue('creator', currentUser.iri); + this.defaultSearchFiltersInitialized.set(true); + this.actions.setDefaultFilterValue('creator,isContainedBy.creator', currentUser.iri); } } } diff --git a/src/app/features/registries/pages/registries-landing/registries-landing.component.ts b/src/app/features/registries/pages/registries-landing/registries-landing.component.ts index 12b0bc62f..fce7c13d3 100644 --- a/src/app/features/registries/pages/registries-landing/registries-landing.component.ts +++ b/src/app/features/registries/pages/registries-landing/registries-landing.component.ts @@ -23,6 +23,7 @@ import { GetRegistryProvider, RegistrationProviderSelectors, } from '@osf/shared/stores/registration-provider'; +import { normalizeQuotes } from '@shared/helpers'; import { RegistryServicesComponent } from '../../components'; import { GetRegistries, RegistriesSelectors } from '../../store'; @@ -73,7 +74,7 @@ export class RegistriesLandingComponent implements OnInit, OnDestroy { } redirectToSearchPageWithValue(): void { - const searchValue = this.searchControl.value; + const searchValue = normalizeQuotes(this.searchControl.value); this.router.navigate(['/search'], { queryParams: { search: searchValue, tab: ResourceType.Registration } }); } diff --git a/src/app/shared/components/global-search/global-search.component.ts b/src/app/shared/components/global-search/global-search.component.ts index 286d1b327..21eb74dca 100644 --- a/src/app/shared/components/global-search/global-search.component.ts +++ b/src/app/shared/components/global-search/global-search.component.ts @@ -249,10 +249,11 @@ export class GlobalSearchComponent implements OnInit, OnDestroy { .subscribe({ next: (newValue) => { if (!newValue) newValue = null; - this.actions.setSearchText(normalizeQuotes(newValue)); + const normalizedValue = normalizeQuotes(newValue); + this.actions.setSearchText(normalizedValue); this.router.navigate([], { relativeTo: this.route, - queryParams: { search: newValue }, + queryParams: { search: normalizedValue }, queryParamsHandling: 'merge', }); this.actions.fetchResources(); diff --git a/src/app/shared/helpers/normalize-quotes.ts b/src/app/shared/helpers/normalize-quotes.ts index 1649e6ef9..22f3c2fd4 100644 --- a/src/app/shared/helpers/normalize-quotes.ts +++ b/src/app/shared/helpers/normalize-quotes.ts @@ -1,3 +1,5 @@ -export function normalizeQuotes(text: string) { - return text.replace(/[\u201C\u201D]/g, '"'); +import { StringOrNull } from '@shared/helpers/types.helper'; + +export function normalizeQuotes(text: StringOrNull): StringOrNull { + return text?.replace(/[\u201C\u201D]/g, '"') ?? null; }