From 82af0adc92841bf20b22e952ade7cbc6c9f36698 Mon Sep 17 00:00:00 2001 From: futa-ikeda <51409893+futa-ikeda@users.noreply.github.com> Date: Tue, 3 Oct 2023 09:27:49 -0400 Subject: [PATCH] Institutions updates (#2013) * Remove All as option for instition discover page * Use new iris field for institution identifiers * Change institution default filters by object type --- app/institutions/discover/controller.ts | 20 +++++++++++++++---- app/models/institution.ts | 1 + .../addon/components/search-page/component.ts | 16 ++++++++++----- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/app/institutions/discover/controller.ts b/app/institutions/discover/controller.ts index 87ed3942d09..7f52f572a19 100644 --- a/app/institutions/discover/controller.ts +++ b/app/institutions/discover/controller.ts @@ -10,15 +10,27 @@ export default class InstitutionDiscoverController extends Controller { @tracked q?: string = ''; @tracked sort?: string = '-relevance'; - @tracked resourceType?: ResourceTypeFilterValue | null = null; + @tracked resourceType: ResourceTypeFilterValue = ResourceTypeFilterValue.Projects; @tracked activeFilters?: Filter[] = []; queryParams = ['q', 'sort', 'resourceType', 'activeFilters']; get defaultQueryOptions() { - const identifiers = [this.model.rorIri, this.model.iri, this.model.links.html].filter(Boolean).join(','); + const identifiers = this.model.iris.join(','); + let key = 'affiliation'; + const { resourceType } = this; + switch (resourceType) { + case ResourceTypeFilterValue.Preprints: + key = 'creator.affiliation'; + break; + case ResourceTypeFilterValue.Files: + key = 'isContainedby.affiliation'; + break; + default: + break; + } return { - 'affiliation,creator.affiliation,isContainedby.affiliation': identifiers, + [key]: identifiers, }; } @@ -26,7 +38,7 @@ export default class InstitutionDiscoverController extends Controller { onSearch(queryOptions: OnSearchParams) { this.q = queryOptions.cardSearchText; this.sort = queryOptions.sort; - this.resourceType = queryOptions.resourceType; + this.resourceType = queryOptions.resourceType as ResourceTypeFilterValue; this.activeFilters = queryOptions.activeFilters; } } diff --git a/app/models/institution.ts b/app/models/institution.ts index 0ff04a7a7a1..9e2fa60ce7a 100644 --- a/app/models/institution.ts +++ b/app/models/institution.ts @@ -33,6 +33,7 @@ export default class InstitutionModel extends OsfModel { @attr('fixstring') rorIri!: string; // identifier_domain in the admin app @attr('fixstring') iri!: string; + @attr('fixstringarray') iris!: string[]; // TODO Might want to replace calls to `users` with `institutionUsers.user`? @hasMany('user', { inverse: 'institutions' }) diff --git a/lib/osf-components/addon/components/search-page/component.ts b/lib/osf-components/addon/components/search-page/component.ts index 3635f9876b0..59e37fa09ed 100644 --- a/lib/osf-components/addon/components/search-page/component.ts +++ b/lib/osf-components/addon/components/search-page/component.ts @@ -12,6 +12,7 @@ import { action } from '@ember/object'; import Media from 'ember-responsive'; import { ShareMoreThanTenThousand } from 'ember-osf-web/models/index-card-search'; +import InstitutionModel from 'ember-osf-web/models/institution'; import SearchResultModel from 'ember-osf-web/models/search-result'; import ProviderModel from 'ember-osf-web/models/provider'; import RelatedPropertyPathModel, { SuggestedFilterOperators } from 'ember-osf-web/models/related-property-path'; @@ -61,6 +62,7 @@ interface SearchArgs { resourceType?: ResourceTypeFilterValue; defaultQueryOptions: Record; provider?: ProviderModel; + institution?: InstitutionModel; showResourceTypeFilter: boolean; page: string; activeFilters: Filter[]; @@ -155,7 +157,7 @@ export default class SearchPage extends Component { } // Resource type - resourceTypeOptions: ResourceTypeOption[] = [ + defaultResourceTypeOptions: ResourceTypeOption[] = [ { display: this.intl.t('search.resource-type.all'), value: null, @@ -182,6 +184,9 @@ export default class SearchPage extends Component { }, ]; + resourceTypeOptions = this.args.institution ? this.defaultResourceTypeOptions.slice(1) + : this.defaultResourceTypeOptions; + // Sort sortOptions: SortOption[] = [ { display: this.intl.t('search.sort.relevance'), value: '-relevance' }, @@ -201,6 +206,9 @@ export default class SearchPage extends Component { try { const cardSearchText = this.cardSearchText; const { page, sort, activeFilters, resourceType } = this; + if (this.args.onSearch) { + this.args.onSearch({cardSearchText, sort, resourceType, activeFilters}); + } let filterQueryObject = activeFilters.reduce((acc, filter) => { // boolean filters should look like cardSearchFilter[hasDataResource][is-present] if (filter.suggestedFilterOperator === SuggestedFilterOperators.IsPresent) { @@ -232,7 +240,8 @@ export default class SearchPage extends Component { this.booleanFilters = searchResult.relatedProperties .filterBy('suggestedFilterOperator', SuggestedFilterOperators.IsPresent); this.relatedProperties = searchResult.relatedProperties.filter( - property => property.suggestedFilterOperator !== SuggestedFilterOperators.IsPresent, // AnyOf or AtDate + (property: RelatedPropertyPathModel) => + property.suggestedFilterOperator !== SuggestedFilterOperators.IsPresent, // AnyOf or AtDate ); this.firstPageCursor = searchResult.firstPageCursor; this.nextPageCursor = searchResult.nextPageCursor; @@ -240,9 +249,6 @@ export default class SearchPage extends Component { this.searchResults = searchResult.searchResultPage.toArray(); this.totalResultCount = searchResult.totalResultCount === ShareMoreThanTenThousand ? '10,000+' : searchResult.totalResultCount; - if (this.args.onSearch) { - this.args.onSearch({cardSearchText, sort, resourceType, activeFilters}); - } } catch (e) { this.toast.error(e); }