Skip to content

Commit ff0211b

Browse files
committed
refactor(search): Refactored search logic for global, institutions page, registrations page search
1 parent bb70182 commit ff0211b

File tree

19 files changed

+50
-95
lines changed

19 files changed

+50
-95
lines changed

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.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.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { TABLE_PARAMS } from '@osf/shared/constants';
1515
import { SortOrder } from '@osf/shared/enums';
1616
import { Institution, QueryParams } from '@osf/shared/models';
1717
import { ToastService } from '@osf/shared/services';
18-
import { InstitutionsSearchSelectors } from '@osf/shared/stores';
18+
import { InstitutionsSearchSelectors } from '@osf/shared/stores/institutions-search';
1919

2020
import { AdminTableComponent } from '../../components';
2121
import { projectTableColumns } from '../../constants';

src/app/features/admin-institutions/pages/institutions-registrations/institutions-registrations.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 { registrationTableColumns } from '../../constants';

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { SortOrder } from '@osf/shared/enums';
2929
import { Primitive } from '@osf/shared/helpers';
3030
import { QueryParams } from '@osf/shared/models';
3131
import { ToastService } from '@osf/shared/services';
32-
import { InstitutionsSearchSelectors } from '@osf/shared/stores';
32+
import { InstitutionsSearchSelectors } from '@osf/shared/stores/institutions-search';
3333

3434
import { AdminTableComponent } from '../../components';
3535
import { departmentOptions, userTableColumns } from '../../constants';

src/app/features/institutions/institutions.routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Routes } from '@angular/router';
44

55
import { authGuard } from '@osf/core/guards';
66
import { InstitutionsComponent } from '@osf/features/institutions/institutions.component';
7-
import { InstitutionsSearchState } from '@shared/stores';
7+
import { InstitutionsSearchState } from '@shared/stores/institutions-search';
88

99
import { InstitutionsListComponent, InstitutionsSearchComponent } from './pages';
1010

src/app/features/institutions/pages/institutions-search/institutions-search.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import {
3838
UpdateFilterValue,
3939
UpdateResourceType,
4040
UpdateSortBy,
41-
} from '@osf/shared/stores';
41+
} from '@osf/shared/stores/institutions-search';
4242
import { StringOrNull } from '@shared/helpers';
4343

4444
@Component({
Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
11
import { RegistryProviderDetails } from '@osf/features/registries/models/registry-provider.model';
2-
import { ResourceTab } from '@shared/enums';
3-
import { AsyncStateModel, DiscoverableFilter, Resource, SelectOption } from '@shared/models';
2+
import { AsyncStateModel } from '@shared/models';
3+
import { BaseSearchStateModel } from '@shared/stores';
44

5-
export interface RegistriesProviderSearchStateModel {
5+
export interface RegistriesProviderSearchStateModel extends BaseSearchStateModel {
66
currentBrandedProvider: AsyncStateModel<RegistryProviderDetails | null>;
7-
resourceType: ResourceTab;
8-
resources: AsyncStateModel<Resource[]>;
9-
filters: DiscoverableFilter[];
10-
filterValues: Record<string, string | null>;
11-
filterOptionsCache: Record<string, SelectOption[]>;
127
providerIri: string;
13-
resourcesCount: number;
14-
searchText: string;
15-
sortBy: string;
16-
first: string;
17-
next: string;
18-
previous: string;
198
}

src/app/features/registries/store/registries-provider-search/registries-provider-search.selectors.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Selector } from '@ngxs/store';
22

33
import { RegistriesProviderSearchStateModel } from '@osf/features/registries/store/registries-provider-search/registries-provider-search.model';
44
import { RegistriesProviderSearchState } from '@osf/features/registries/store/registries-provider-search/registries-provider-search.state';
5+
import { StringOrNull } from '@shared/helpers';
56
import { DiscoverableFilter, Resource, SelectOption } from '@shared/models';
67

78
import { RegistryProviderDetails } from '../../models/registry-provider.model';
@@ -38,7 +39,7 @@ export class RegistriesProviderSearchSelectors {
3839
}
3940

4041
@Selector([RegistriesProviderSearchState])
41-
static getSearchText(state: RegistriesProviderSearchStateModel): string {
42+
static getSearchText(state: RegistriesProviderSearchStateModel): StringOrNull {
4243
return state.searchText;
4344
}
4445

@@ -73,7 +74,7 @@ export class RegistriesProviderSearchSelectors {
7374
}
7475

7576
@Selector([RegistriesProviderSearchState])
76-
static getFilterValues(state: RegistriesProviderSearchStateModel): Record<string, string | null> {
77+
static getFilterValues(state: RegistriesProviderSearchStateModel): Record<string, StringOrNull> {
7778
return state.filterValues;
7879
}
7980

src/app/features/registries/store/registries-provider-search/registries-provider-search.state.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
import { RegistriesProviderSearchStateModel } from '@osf/features/registries/store/registries-provider-search/registries-provider-search.model';
2020
import { ResourcesData } from '@osf/features/search/models';
2121
import { getResourceTypes } from '@osf/shared/helpers';
22+
import { searchStateDefaults } from '@shared/constants';
2223
import { ResourceTab } from '@shared/enums';
2324
import { handleSectionError } from '@shared/helpers';
2425
import { SearchService } from '@shared/services';
@@ -31,24 +32,14 @@ import { SearchService } from '@shared/services';
3132
isLoading: false,
3233
error: null,
3334
},
34-
resources: { data: [], isLoading: false, error: null },
35-
filters: [],
36-
filterValues: {},
37-
filterOptionsCache: {},
3835
providerIri: '',
39-
resourcesCount: 0,
40-
searchText: '',
41-
sortBy: '-relevance',
42-
first: '',
43-
next: '',
44-
previous: '',
45-
resourceType: ResourceTab.All,
36+
...searchStateDefaults,
4637
},
4738
})
4839
@Injectable()
4940
export class RegistriesProviderSearchState {
50-
private readonly searchService = inject(SearchService);
51-
providersService = inject(ProvidersService);
41+
private searchService = inject(SearchService);
42+
private providersService = inject(ProvidersService);
5243

5344
private updateResourcesState(ctx: StateContext<RegistriesProviderSearchStateModel>, response: ResourcesData) {
5445
const state = ctx.getState();

0 commit comments

Comments
 (0)