Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search bug fixes #2019

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/institutions/discover/template.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{{page-title this.model.name}}

<SearchPage
@route='search'
@query={{this.q}}
Expand Down
2 changes: 1 addition & 1 deletion app/models/preprint-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { attr, hasMany, AsyncHasMany, belongsTo, AsyncBelongsTo } from '@ember-d
import { computed } from '@ember/object';
import { alias } from '@ember/object/computed';
import { inject as service } from '@ember/service';
import config from 'ember-get-config';
import config from 'ember-osf-web/config/environment';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why these weren't a bigger problem.

import Intl from 'ember-intl/services/intl';
import BrandModel from 'ember-osf-web/models/brand';

Expand Down
2 changes: 1 addition & 1 deletion app/settings/account/-components/opt-out/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { tracked } from '@glimmer/tracking';
import CurrentUserService from 'ember-osf-web/services/current-user';
import { restartableTask } from 'ember-concurrency';
import { waitFor } from '@ember/test-waiters';
import config from 'ember-get-config';
import config from 'ember-osf-web/config/environment';
import IntlService from 'ember-intl/services/intl';

import captureException, { getApiErrorMessage } from 'ember-osf-web/utils/capture-exception';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Component from '@ember/component';
import { action, computed } from '@ember/object';
import { alias } from '@ember/object/computed';
import { inject as service } from '@ember/service';
import config from 'ember-get-config';
import config from 'ember-osf-web/config/environment';
import Intl from 'ember-intl/services/intl';
import Media from 'ember-responsive';
import Session from 'ember-simple-auth/services/session';
Expand Down
16 changes: 13 additions & 3 deletions lib/osf-components/addon/components/search-page/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,17 @@ export default class SearchPage extends Component<SearchArgs> {
if (this.args.onSearch) {
this.args.onSearch({cardSearchText, sort, resourceType, activeFilters});
}
let filterQueryObject = activeFilters.reduce((acc, filter) => {
const filterQueryObject = activeFilters.reduce((acc, filter) => {
// boolean filters should look like cardSearchFilter[hasDataResource][is-present]
if (filter.suggestedFilterOperator === SuggestedFilterOperators.IsPresent) {
acc[filter.propertyPathKey] = {};
acc[filter.propertyPathKey][filter.value] = true;
return acc;
}
// other filters should look like cardSearchFilter[propertyName]=IRI
const currentValue = acc[filter.propertyPathKey];
// other filters should look like cardSearchFilter[propertyName]=IRI
// or cardSearchFilter[propertyName] = IRI1, IRI2
// Logic below is to handle the case where there are multiple filters for the same property
acc[filter.propertyPathKey] = currentValue ? currentValue.concat(filter.value) : [filter.value];
return acc;
}, {} as { [key: string]: any });
Expand All @@ -227,7 +229,15 @@ export default class SearchPage extends Component<SearchArgs> {
resourceTypeFilter = Object.values(ResourceTypeFilterValue).join(',');
}
filterQueryObject['resourceType'] = resourceTypeFilter;
filterQueryObject = { ...filterQueryObject, ...this.args.defaultQueryOptions };
if (this.args.defaultQueryOptions) {
const { defaultQueryOptions } = this.args;
const defaultQueryOptionKeys = Object.keys(this.args.defaultQueryOptions);
defaultQueryOptionKeys.forEach(key => {
const currentValue = filterQueryObject[key];
const defaultValue = defaultQueryOptions[key];
filterQueryObject[key] = currentValue ? currentValue.concat(defaultValue) : [defaultValue];
});
}
this.filterQueryObject = filterQueryObject;
const searchResult = await this.store.queryRecord('index-card-search', {
cardSearchText,
Expand Down
3 changes: 1 addition & 2 deletions lib/registries/addon/branded/discover/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import Media from 'ember-responsive';
import { tracked } from '@glimmer/tracking';
import { Filter, OnSearchParams } from 'osf-components/components/search-page/component';
import pathJoin from 'ember-osf-web/utils/path-join';
import config from 'ember-get-config';

import config from 'ember-osf-web/config/environment';
export default class BrandedDiscover extends Controller.extend() {
@service media!: Media;
@service intl!: Intl;
Expand Down
2 changes: 1 addition & 1 deletion lib/registries/addon/branded/index/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Route from '@ember/routing/route';
import config from 'ember-get-config';
import config from 'ember-osf-web/config/environment';
export default class BrandedRegistriesIndexRoute extends Route {
beforeModel() {
const params: { providerId?: string } = this.paramsFor('branded');
Expand Down
2 changes: 1 addition & 1 deletion mirage/serializers/preprint-provider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ModelInstance } from 'ember-cli-mirage';
import config from 'ember-get-config';
import config from 'ember-osf-web/config/environment';
import PreprintProvider from 'ember-osf-web/models/preprint-provider';
import ApplicationSerializer, { SerializedRelationships } from './application';

Expand Down