Skip to content

Commit 4b26233

Browse files
rrromchIkvolodyayakubovskyynsemets
authored
Fix - Search (#286)
* feat(search): added generic search component * feat(search): improved search for institutions * feat(search): remove unused files * feat(search): fixed some issues * fix(search): removed comments * fix(profile): renamed it to profile * fix(updates): updates * fix(branding): Minor fixed regarding provider hero for preprints and registry * refactor(search-results-container): Encapsulated some logic, reduced duplication * refactor(search-results-container): Encapsulated tabs logic * refactor(search): Refactored partly search section for preprints and profile * refactor(search): Refactored search logic for global, institutions page, registrations page search * refactor(search): Refactored search logic for global, institutions page, registrations page search * refactor(search): Refactored search logic for profile * feat(profile): Implemented my-profile and user/:id pages * refactor(preprint-provider-discover): Removed search section that uses old approach * refactor(search): Create shared component that encapsulates search logic and reused across the app * refactor(shared-search): Extracted state model. Reduced duplications. Fixed IndexValueSearch filters * refactor(search): Using ResourceType instead of ResourceTab. Fixed params for index-value-search * refactor(search-models): Cleaned up models - renamed files, moved models to appropriate locations * refactor(index-card-search): Refactored models * fix(resource-card): Fixed resource-card component * fix(resource-card-secondary-metadata): Fixed resource-card component * fix(search): Fixed PR comments and conflicts after merge * refactor(search): Renamed OsfSearch- to GlobalSearch- * fix(unit-tests): fixed unit tests --------- Co-authored-by: volodyayakubovskyy <vyakubovskyy477@gmail.com> Co-authored-by: nsemets <nsemets@exoft.net>
1 parent c3b84df commit 4b26233

File tree

406 files changed

+3198
-12452
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

406 files changed

+3198
-12452
lines changed

src/app/app.routes.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,11 @@ import { BookmarksState, ProjectsState } from '@shared/stores';
88
import { authGuard, redirectIfLoggedInGuard } from './core/guards';
99
import { isProjectGuard } from './core/guards/is-project.guard';
1010
import { isRegistryGuard } from './core/guards/is-registry.guard';
11-
import { MyProfileResourceFiltersOptionsState } from './features/my-profile/components/filters/store';
12-
import { MyProfileResourceFiltersState } from './features/my-profile/components/my-profile-resource-filters/store';
13-
import { MyProfileState } from './features/my-profile/store';
1411
import { PreprintState } from './features/preprints/store/preprint';
12+
import { ProfileState } from './features/profile/store';
1513
import { RegistriesState } from './features/registries/store';
1614
import { LicensesHandlers, ProjectsHandlers, ProvidersHandlers } from './features/registries/store/handlers';
1715
import { FilesHandlers } from './features/registries/store/handlers/files.handlers';
18-
import { ResourceFiltersOptionsState } from './features/search/components/filters/store';
19-
import { ResourceFiltersState } from './features/search/components/resource-filters/store';
20-
import { SearchState } from './features/search/store';
2116
import { LicensesService } from './shared/services';
2217

2318
export const routes: Routes = [
@@ -71,7 +66,6 @@ export const routes: Routes = [
7166
{
7267
path: 'search',
7368
loadComponent: () => import('./features/search/search.component').then((mod) => mod.SearchComponent),
74-
providers: [provideStates([ResourceFiltersState, ResourceFiltersOptionsState, SearchState])],
7569
},
7670
{
7771
path: 'my-projects',
@@ -119,12 +113,19 @@ export const routes: Routes = [
119113
},
120114
{
121115
path: 'my-profile',
122-
loadComponent: () => import('./features/my-profile/my-profile.component').then((mod) => mod.MyProfileComponent),
123-
providers: [
124-
provideStates([MyProfileResourceFiltersState, MyProfileResourceFiltersOptionsState, MyProfileState]),
125-
],
116+
loadComponent: () =>
117+
import('./features/profile/pages/my-profile/my-profile.component').then((mod) => mod.MyProfileComponent),
118+
providers: [provideStates([ProfileState])],
126119
canActivate: [authGuard],
127120
},
121+
{
122+
path: 'user/:id',
123+
loadComponent: () =>
124+
import('./features/profile/pages/user-profile/user-profile.component').then(
125+
(mod) => mod.UserProfileComponent
126+
),
127+
providers: [provideStates([ProfileState])],
128+
},
128129
{
129130
path: 'institutions',
130131
loadChildren: () => import('./features/institutions/institutions.routes').then((r) => r.routes),

src/app/core/constants/ngxs-states.constant.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { MetadataState } from '@osf/features/metadata/store';
66
import { ProjectOverviewState } from '@osf/features/project/overview/store';
77
import { RegistrationsState } from '@osf/features/project/registrations/store';
88
import { AddonsState, CurrentResourceState, WikiState } from '@osf/shared/stores';
9+
import { GlobalSearchState } from '@shared/stores/global-search';
910
import { InstitutionsState } from '@shared/stores/institutions';
1011
import { LicensesState } from '@shared/stores/licenses';
1112
import { MyResourcesState } from '@shared/stores/my-resources';
@@ -26,4 +27,5 @@ export const STATES = [
2627
FilesState,
2728
MetadataState,
2829
CurrentResourceState,
30+
GlobalSearchState,
2931
];

src/app/core/guards/is-project.guard.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import { map, switchMap } from 'rxjs/operators';
55
import { inject } from '@angular/core';
66
import { CanMatchFn, Route, Router, UrlSegment } from '@angular/router';
77

8-
import { CurrentResourceType } from '../../shared/enums';
9-
import { CurrentResourceSelectors, GetResource } from '../../shared/stores';
8+
import { UserSelectors } from '@core/store/user';
9+
import { CurrentResourceType } from '@shared/enums';
10+
import { CurrentResourceSelectors, GetResource } from '@shared/stores';
1011

1112
export const isProjectGuard: CanMatchFn = (route: Route, segments: UrlSegment[]) => {
1213
const store = inject(Store);
@@ -19,8 +20,9 @@ export const isProjectGuard: CanMatchFn = (route: Route, segments: UrlSegment[])
1920
}
2021

2122
const currentResource = store.selectSnapshot(CurrentResourceSelectors.getCurrentResource);
23+
const currentUser = store.selectSnapshot(UserSelectors.getCurrentUser);
2224

23-
if (currentResource && currentResource.id === id) {
25+
if (currentResource && !id.startsWith(currentResource.id)) {
2426
if (currentResource.type === CurrentResourceType.Projects && currentResource.parentId) {
2527
router.navigate(['/', currentResource.parentId, 'files', id]);
2628
return true;
@@ -32,7 +34,11 @@ export const isProjectGuard: CanMatchFn = (route: Route, segments: UrlSegment[])
3234
}
3335

3436
if (currentResource.type === CurrentResourceType.Users) {
35-
router.navigate(['/profile', id]);
37+
if (currentUser && currentUser.id === currentResource.id) {
38+
router.navigate(['/profile']);
39+
} else {
40+
router.navigate(['/user', id]);
41+
}
3642
return false;
3743
}
3844

@@ -42,7 +48,7 @@ export const isProjectGuard: CanMatchFn = (route: Route, segments: UrlSegment[])
4248
return store.dispatch(new GetResource(id)).pipe(
4349
switchMap(() => store.select(CurrentResourceSelectors.getCurrentResource)),
4450
map((resource) => {
45-
if (!resource || resource.id !== id) {
51+
if (!resource || !id.startsWith(resource.id)) {
4652
return false;
4753
}
4854

@@ -57,7 +63,11 @@ export const isProjectGuard: CanMatchFn = (route: Route, segments: UrlSegment[])
5763
}
5864

5965
if (resource.type === CurrentResourceType.Users) {
60-
router.navigate(['/user', id]);
66+
if (currentUser && currentUser.id === resource.id) {
67+
router.navigate(['/profile']);
68+
} else {
69+
router.navigate(['/user', id]);
70+
}
6171
return false;
6272
}
6373

src/app/core/guards/is-registry.guard.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import { map, switchMap } from 'rxjs/operators';
55
import { inject } from '@angular/core';
66
import { CanMatchFn, Route, Router, UrlSegment } from '@angular/router';
77

8-
import { CurrentResourceType } from '../../shared/enums';
9-
import { CurrentResourceSelectors, GetResource } from '../../shared/stores';
8+
import { UserSelectors } from '@core/store/user';
9+
import { CurrentResourceType } from '@shared/enums';
10+
import { CurrentResourceSelectors, GetResource } from '@shared/stores';
1011

1112
export const isRegistryGuard: CanMatchFn = (route: Route, segments: UrlSegment[]) => {
1213
const store = inject(Store);
@@ -19,8 +20,9 @@ export const isRegistryGuard: CanMatchFn = (route: Route, segments: UrlSegment[]
1920
}
2021

2122
const currentResource = store.selectSnapshot(CurrentResourceSelectors.getCurrentResource);
23+
const currentUser = store.selectSnapshot(UserSelectors.getCurrentUser);
2224

23-
if (currentResource && currentResource.id === id) {
25+
if (currentResource && !id.startsWith(currentResource.id)) {
2426
if (currentResource.type === CurrentResourceType.Registrations && currentResource.parentId) {
2527
router.navigate(['/', currentResource.parentId, 'files', id]);
2628
return true;
@@ -32,7 +34,11 @@ export const isRegistryGuard: CanMatchFn = (route: Route, segments: UrlSegment[]
3234
}
3335

3436
if (currentResource.type === CurrentResourceType.Users) {
35-
router.navigate(['/user', id]);
37+
if (currentUser && currentUser.id === currentResource.id) {
38+
router.navigate(['/profile']);
39+
} else {
40+
router.navigate(['/user', id]);
41+
}
3642
return false;
3743
}
3844

@@ -42,7 +48,7 @@ export const isRegistryGuard: CanMatchFn = (route: Route, segments: UrlSegment[]
4248
return store.dispatch(new GetResource(id)).pipe(
4349
switchMap(() => store.select(CurrentResourceSelectors.getCurrentResource)),
4450
map((resource) => {
45-
if (!resource || resource.id !== id) {
51+
if (!resource || !id.startsWith(resource.id)) {
4652
return false;
4753
}
4854

@@ -57,7 +63,11 @@ export const isRegistryGuard: CanMatchFn = (route: Route, segments: UrlSegment[]
5763
}
5864

5965
if (resource.type === CurrentResourceType.Users) {
60-
router.navigate(['/profile', id]);
66+
if (currentUser && currentUser.id === resource.id) {
67+
router.navigate(['/profile']);
68+
} else {
69+
router.navigate(['/user', id]);
70+
}
6171
return false;
6272
}
6373

src/app/core/services/user.service.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import {
99
ProfileSettingsUpdate,
1010
User,
1111
UserData,
12+
UserDataJsonApi,
1213
UserDataResponseJsonApi,
13-
UserGetResponse,
14+
UserResponseJsonApi,
1415
UserSettings,
1516
UserSettingsGetResponse,
1617
} from '@osf/shared/models';
17-
18-
import { JsonApiService } from '../../shared/services';
18+
import { JsonApiService } from '@shared/services';
1919

2020
import { environment } from 'src/environments/environment';
2121

@@ -25,6 +25,12 @@ import { environment } from 'src/environments/environment';
2525
export class UserService {
2626
jsonApiService = inject(JsonApiService);
2727

28+
getUserById(userId: string): Observable<User> {
29+
return this.jsonApiService
30+
.get<UserResponseJsonApi>(`${environment.apiUrl}/users/${userId}/`)
31+
.pipe(map((response) => UserMapper.fromUserGetResponse(response.data)));
32+
}
33+
2834
getCurrentUser(): Observable<UserData> {
2935
return this.jsonApiService
3036
.get<UserDataResponseJsonApi>(`${environment.apiUrl}/`)
@@ -49,7 +55,7 @@ export class UserService {
4955
const patchedData = key === ProfileSettingsKey.User ? data : { [key]: data };
5056

5157
return this.jsonApiService
52-
.patch<UserGetResponse>(`${environment.apiUrl}/users/${userId}/`, {
58+
.patch<UserDataJsonApi>(`${environment.apiUrl}/users/${userId}/`, {
5359
data: { type: 'users', id: userId, attributes: patchedData },
5460
})
5561
.pipe(map((response) => UserMapper.fromUserGetResponse(response)));

src/app/features/admin-institutions/admin-institutions.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { provideHttpClientTesting } from '@angular/common/http/testing';
77
import { ComponentFixture, TestBed } from '@angular/core/testing';
88
import { ActivatedRoute, Router } from '@angular/router';
99

10+
import { InstitutionsSearchState } from '@osf/shared/stores/institutions-search';
1011
import { LoadingSpinnerComponent, SelectComponent } from '@shared/components';
11-
import { InstitutionsSearchState } from '@shared/stores';
1212

1313
import { AdminInstitutionsComponent } from './admin-institutions.component';
1414

src/app/features/admin-institutions/admin-institutions.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { ChangeDetectionStrategy, Component, inject, OnInit } from '@angular/cor
99
import { ActivatedRoute, Router, RouterOutlet } from '@angular/router';
1010

1111
import { Primitive } from '@osf/shared/helpers';
12-
import { FetchInstitutionById, InstitutionsSearchSelectors } from '@osf/shared/stores';
12+
import { FetchInstitutionById, InstitutionsSearchSelectors } from '@osf/shared/stores/institutions-search';
1313
import { LoadingSpinnerComponent, SelectComponent } from '@shared/components';
1414

1515
import { resourceTabOptions } from './constants';

src/app/features/admin-institutions/pages/institutions-preprints/institutions-preprints.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import { ActivatedRoute, Router } from '@angular/router';
1212

1313
import { AdminTableComponent } from '@osf/features/admin-institutions/components';
1414
import { InstitutionsAdminState } from '@osf/features/admin-institutions/store';
15+
import { InstitutionsSearchState } from '@osf/shared/stores/institutions-search';
1516
import { LoadingSpinnerComponent } from '@shared/components';
16-
import { InstitutionsSearchState } from '@shared/stores';
1717

1818
import { InstitutionsPreprintsComponent } from './institutions-preprints.component';
1919

src/app/features/admin-institutions/pages/institutions-preprints/institutions-preprints.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { ActivatedRoute, Router } from '@angular/router';
99
import { TABLE_PARAMS } from '@osf/shared/constants';
1010
import { SortOrder } from '@osf/shared/enums';
1111
import { Institution, QueryParams } from '@osf/shared/models';
12-
import { InstitutionsSearchSelectors } from '@osf/shared/stores';
12+
import { InstitutionsSearchSelectors } from '@osf/shared/stores/institutions-search';
1313

1414
import { AdminTableComponent } from '../../components';
1515
import { preprintsTableColumns } from '../../constants';

src/app/features/admin-institutions/pages/institutions-projects/institutions-projects.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import { ActivatedRoute } from '@angular/router';
1313
import { AdminTableComponent } from '@osf/features/admin-institutions/components';
1414
import { InstitutionsAdminState } from '@osf/features/admin-institutions/store';
1515
import { ToastService } from '@osf/shared/services';
16+
import { InstitutionsSearchState } from '@osf/shared/stores/institutions-search';
1617
import { LoadingSpinnerComponent } from '@shared/components';
17-
import { InstitutionsSearchState } from '@shared/stores';
1818

1919
import { InstitutionsProjectsComponent } from './institutions-projects.component';
2020

0 commit comments

Comments
 (0)