Skip to content

Commit ca9a7cb

Browse files
authored
fix(global-search): Normalize quotes in search text, fixed search section init on the profile page (#657)
1 parent c7e7780 commit ca9a7cb

File tree

7 files changed

+23
-12
lines changed

7 files changed

+23
-12
lines changed

src/app/features/preprints/components/preprint-provider-hero/preprint-provider-hero.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { RouterLink } from '@angular/router';
1111
import { PreprintProviderDetails } from '@osf/features/preprints/models';
1212
import { CustomDialogService } from '@osf/shared/services';
1313
import { SearchInputComponent } from '@shared/components';
14+
import { normalizeQuotes } from '@shared/helpers';
1415
import { DecodeHtmlPipe } from '@shared/pipes';
1516

1617
import { PreprintsHelpDialogComponent } from '../preprints-help-dialog/preprints-help-dialog.component';
@@ -31,7 +32,7 @@ export class PreprintProviderHeroComponent {
3132
triggerSearch = output<string>();
3233

3334
onTriggerSearch(value: string) {
34-
this.triggerSearch.emit(value);
35+
this.triggerSearch.emit(normalizeQuotes(value)!);
3536
}
3637

3738
openHelpDialog() {

src/app/features/preprints/pages/landing/preprints-landing.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
} from '@osf/features/preprints/store/preprint-providers';
2525
import { SearchInputComponent } from '@shared/components';
2626
import { ResourceType } from '@shared/enums';
27+
import { normalizeQuotes } from '@shared/helpers';
2728
import { BrandService } from '@shared/services';
2829

2930
@Component({
@@ -87,7 +88,7 @@ export class PreprintsLandingComponent implements OnInit, OnDestroy {
8788
}
8889

8990
redirectToSearchPageWithValue() {
90-
const searchValue = this.searchControl.value;
91+
const searchValue = normalizeQuotes(this.searchControl.value);
9192

9293
this.router.navigate(['/search'], {
9394
queryParams: { search: searchValue, tab: ResourceType.Preprint },

src/app/features/profile/profile.component.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
@if (user()) {
55
<osf-profile-information [currentUser]="user()" [showEdit]="isMyProfile()" (editProfile)="toProfileSettings()" />
66

7-
<div class="mt-6">
8-
<osf-global-search [resourceTabOptions]="resourceTabOptions" />
9-
</div>
7+
@if (defaultSearchFiltersInitialized()) {
8+
<div class="mt-6">
9+
<osf-global-search [resourceTabOptions]="resourceTabOptions" />
10+
</div>
11+
}
1012
}
1113
}

src/app/features/profile/profile.component.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createDispatchMap, select } from '@ngxs/store';
22

3-
import { ChangeDetectionStrategy, Component, computed, DestroyRef, inject, OnInit } from '@angular/core';
3+
import { ChangeDetectionStrategy, Component, computed, DestroyRef, inject, OnInit, signal } from '@angular/core';
44
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
55
import { ActivatedRoute, Router } from '@angular/router';
66

@@ -39,6 +39,7 @@ export class ProfileComponent implements OnInit {
3939

4040
isMyProfile = computed(() => !this.route.snapshot.params['id']);
4141
user = computed(() => (this.isMyProfile() ? this.loggedInUser() : this.userProfile()));
42+
defaultSearchFiltersInitialized = signal<boolean>(false);
4243

4344
ngOnInit(): void {
4445
const userId = this.route.snapshot.params['id'];
@@ -65,14 +66,16 @@ export class ProfileComponent implements OnInit {
6566
private setupMyProfile(user: UserModel): void {
6667
this.actions.setUserProfile(user);
6768
if (user?.iri) {
69+
this.defaultSearchFiltersInitialized.set(true);
6870
this.actions.setDefaultFilterValue('creator,isContainedBy.creator', user.iri);
6971
}
7072
}
7173

7274
private setSearchFilter(): void {
7375
const currentUser = this.user();
7476
if (currentUser?.iri) {
75-
this.actions.setDefaultFilterValue('creator', currentUser.iri);
77+
this.defaultSearchFiltersInitialized.set(true);
78+
this.actions.setDefaultFilterValue('creator,isContainedBy.creator', currentUser.iri);
7679
}
7780
}
7881
}

src/app/features/registries/pages/registries-landing/registries-landing.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
GetRegistryProvider,
2424
RegistrationProviderSelectors,
2525
} from '@osf/shared/stores/registration-provider';
26+
import { normalizeQuotes } from '@shared/helpers';
2627

2728
import { RegistryServicesComponent } from '../../components';
2829
import { GetRegistries, RegistriesSelectors } from '../../store';
@@ -73,7 +74,7 @@ export class RegistriesLandingComponent implements OnInit, OnDestroy {
7374
}
7475

7576
redirectToSearchPageWithValue(): void {
76-
const searchValue = this.searchControl.value;
77+
const searchValue = normalizeQuotes(this.searchControl.value);
7778

7879
this.router.navigate(['/search'], { queryParams: { search: searchValue, tab: ResourceType.Registration } });
7980
}

src/app/shared/components/global-search/global-search.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,11 @@ export class GlobalSearchComponent implements OnInit, OnDestroy {
249249
.subscribe({
250250
next: (newValue) => {
251251
if (!newValue) newValue = null;
252-
this.actions.setSearchText(normalizeQuotes(newValue));
252+
const normalizedValue = normalizeQuotes(newValue);
253+
this.actions.setSearchText(normalizedValue);
253254
this.router.navigate([], {
254255
relativeTo: this.route,
255-
queryParams: { search: newValue },
256+
queryParams: { search: normalizedValue },
256257
queryParamsHandling: 'merge',
257258
});
258259
this.actions.fetchResources();
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
export function normalizeQuotes(text: string) {
2-
return text.replace(/[\u201C\u201D]/g, '"');
1+
import { StringOrNull } from '@shared/helpers/types.helper';
2+
3+
export function normalizeQuotes(text: StringOrNull): StringOrNull {
4+
return text?.replace(/[\u201C\u201D]/g, '"') ?? null;
35
}

0 commit comments

Comments
 (0)