Skip to content

Commit

Permalink
Update institution discover default query options (#1993)
Browse files Browse the repository at this point in the history
* Update institution discover default query options

* Update link; Combine default qps

* Add accessService qp if appropriate

* No labels, just keys
  • Loading branch information
futa-ikeda authored Sep 13, 2023
1 parent 5209722 commit 4558767
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 28 deletions.
5 changes: 2 additions & 3 deletions app/institutions/discover/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { inject as service } from '@ember/service';
import CurrentUser from 'ember-osf-web/services/current-user';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import pathJoin from 'ember-osf-web/utils/path-join';
import config from 'ember-get-config';
import { Filter, OnSearchParams, ResourceTypeFilterValue } from 'osf-components/components/search-page/component';

export default class InstitutionDiscoverController extends Controller {
Expand All @@ -18,8 +16,9 @@ export default class InstitutionDiscoverController extends Controller {
queryParams = ['cardSearchText', 'sort', 'resourceType', 'activeFilters'];

get defaultQueryOptions() {
const identifiers = [this.model.rorIri, this.model.iri, this.model.links.html].filter(Boolean).join(',');
return {
affiliation: pathJoin(config.OSF.url, 'institutions', this.model.id),
'affiliation,creator.affiliation,isContainedby.affiliation': identifiers,
};
}

Expand Down
3 changes: 3 additions & 0 deletions app/models/institution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export default class InstitutionModel extends OsfModel {
@attr('object') assets?: Assets;
@attr('boolean', { defaultValue: false }) currentUserIsAdmin!: boolean;
@attr('date') lastUpdated!: Date;
@attr('fixstring') rorIri!: string;
// identifier_domain in the admin app
@attr('fixstring') iri!: string;

// TODO Might want to replace calls to `users` with `institutionUsers.user`?
@hasMany('user', { inverse: 'institutions' })
Expand Down
15 changes: 0 additions & 15 deletions app/models/related-property-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,6 @@ export default class RelatedPropertyPathModel extends OsfModel {

getLocalizedString = new GetLocalizedPropertyHelper(getOwner(this));

get shortFormLabel() {
const labelArray = [];
// propertyPath is likely an array of length 1,
// unless it is nested property(e.g. file's isContainedBy.funder, file's isContainedBy.license)
for (const property of this.propertyPath) {
const label = this.getLocalizedString.compute(
[property as unknown as Record<string, LanguageText[]>, 'shortFormLabel'],
);
if (label) {
labelArray.push(label);
}
}
return labelArray.join(',');
}

get displayLabel() {
// propertyPath is likely an array of length 1,
// unless it is nested property(e.g. file's isContainedBy.funder, file's isContainedBy.license)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
title={{value.displayLabel}}
{{on 'click' (fn @toggleFilter (hash
propertyVisibleLabel=this.visibleLabel
propertyShortFormLabel=value.propertyPathKey
propertyPathKey=value.propertyPathKey
label=value.displayLabel
value='is-present'
suggestedFilterOperator='is-present'
Expand Down
18 changes: 12 additions & 6 deletions lib/osf-components/addon/components/search-page/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Intl from 'ember-intl/services/intl';
import { A } from '@ember/array';
import Store from '@ember-data/store';
import { action } from '@ember/object';
import config from 'ember-get-config';
import Media from 'ember-responsive';

import { ShareMoreThanTenThousand } from 'ember-osf-web/models/index-card-search';
Expand Down Expand Up @@ -37,7 +38,7 @@ interface SortOption {

export interface Filter {
propertyVisibleLabel: string;
propertyShortFormLabel: string; // OSFMAP shorthand label
propertyPathKey: string; // OSFMAP shorthand label
value: string;
label: string;
suggestedFilterOperator?: SuggestedFilterOperators;
Expand Down Expand Up @@ -66,6 +67,7 @@ interface SearchArgs {
activeFilters: Filter[];
}

const osfURL = config.OSF.url;
const searchDebounceTime = 100;

export default class SearchPage extends Component<SearchArgs> {
Expand Down Expand Up @@ -203,13 +205,13 @@ export default class SearchPage extends Component<SearchArgs> {
let filterQueryObject = activeFilters.reduce((acc, filter) => {
// boolean filters should look like cardSearchFilter[hasDataResource][is-present]
if (filter.suggestedFilterOperator === SuggestedFilterOperators.IsPresent) {
acc[filter.propertyShortFormLabel] = {};
acc[filter.propertyShortFormLabel][filter.value] = true;
acc[filter.propertyPathKey] = {};
acc[filter.propertyPathKey][filter.value] = true;
return acc;
}
// other filters should look like cardSearchFilter[propertyName]=IRI
const currentValue = acc[filter.propertyShortFormLabel];
acc[filter.propertyShortFormLabel] = currentValue ? currentValue.concat(filter.value) : [filter.value];
const currentValue = acc[filter.propertyPathKey];
acc[filter.propertyPathKey] = currentValue ? currentValue.concat(filter.value) : [filter.value];
return acc;
}, {} as { [key: string]: any });
let resourceTypeFilter = this.resourceType as string;
Expand All @@ -218,6 +220,10 @@ export default class SearchPage extends Component<SearchArgs> {
resourceTypeFilter = Object.values(ResourceTypeFilterValue).join(',');
}
filterQueryObject['resourceType'] = resourceTypeFilter;
// Add the accessService if we are not serving locally
if (!osfURL.includes('localhost')) {
filterQueryObject['accessService'] = osfURL; // Only fetch items from the current OSF environment
}
filterQueryObject = { ...filterQueryObject, ...this.args.defaultQueryOptions };
this.filterQueryObject = filterQueryObject;
const searchResult = await this.store.queryRecord('index-card-search', {
Expand Down Expand Up @@ -264,7 +270,7 @@ export default class SearchPage extends Component<SearchArgs> {
@action
toggleFilter(filter: Filter) {
const filterIndex = this.activeFilters.findIndex(
f => f.propertyShortFormLabel === filter.propertyShortFormLabel && f.value === filter.value,
f => f.propertyPathKey === filter.propertyPathKey && f.value === filter.value,
);
if (filterIndex > -1) {
this.activeFilters.removeAt(filterIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default class FilterFacet extends Component<FilterFacetArgs> {
const card = this.selectedProperty.indexCard;
const filter = {
propertyVisibleLabel: property.displayLabel,
propertyShortFormLabel: property.shortFormLabel,
propertyPathKey: property.propertyPathKey,
label: card.get('label'),
value: card.get('resourceId'),
};
Expand Down Expand Up @@ -110,7 +110,7 @@ export default class FilterFacet extends Component<FilterFacetArgs> {
const valueSearch = await this.store.queryRecord('index-value-search', {
cardSearchText,
cardSearchFilter,
valueSearchPropertyPath: property.shortFormLabel,
valueSearchPropertyPath: property.propertyPathKey,
valueSearchText: filterString || '',
'page[cursor]': page,
sort,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
title={{value.indexCard.label}}
{{on 'click' (fn @toggleFilter (hash
propertyVisibleLabel=@property.displayLabel
propertyShortFormLabel=@property.shortFormLabel
propertyPathKey=@property.propertyPathKey
label=value.indexCard.label
value=value.indexCard.resourceId)
)}}
Expand Down
2 changes: 2 additions & 0 deletions mirage/factories/institution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export default Factory.extend<Institution & InstitutionTraits>({
lastUpdated() {
return faker.date.recent();
},
iri: faker.internet.url,
rorIri: faker.internet.url,
withMetrics: trait<Institution>({
afterCreate(institution, server) {
const userMetrics = server.createList('institution-user', 15);
Expand Down
3 changes: 3 additions & 0 deletions mirage/views/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ export function cardSearch(_: Schema, __: Request) {
type: 'related-property-path',
id: 'propertyMatch1',
attributes: {
propertyPathKey: 'rights',
matchEvidence: [
{
'@type': ['https://share.osf.io/vocab/2023/trove/IriMatchEvidence'],
Expand Down Expand Up @@ -340,6 +341,7 @@ export function cardSearch(_: Schema, __: Request) {
type: 'related-property-path',
id: 'propertyMatch2',
attributes: {
propertyPathKey: 'datePublished',
matchEvidence: [
{
'@type': ['https://share.osf.io/vocab/2023/trove/IriMatchEvidence'],
Expand Down Expand Up @@ -377,6 +379,7 @@ export function cardSearch(_: Schema, __: Request) {
type: 'related-property-path',
id: 'propertyMatch3',
attributes: {
propertyPathKey: 'funder',
matchEvidence: [
{
'@type': ['https://share.osf.io/vocab/2023/trove/IriMatchEvidence'],
Expand Down

0 comments on commit 4558767

Please sign in to comment.