Skip to content

Commit

Permalink
Merge branch 'develop' into preprint-label
Browse files Browse the repository at this point in the history
  • Loading branch information
futa-ikeda authored Oct 23, 2023
2 parents 133fcb4 + 1fd3177 commit 303479d
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 21 deletions.
6 changes: 4 additions & 2 deletions app/institutions/discover/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ 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 { Filter, OnSearchParams, ResourceTypeFilterValue } from 'osf-components/components/search-page/component';
import {
Filter, OnQueryParamChangeParams, ResourceTypeFilterValue,
} from 'osf-components/components/search-page/component';

export default class InstitutionDiscoverController extends Controller {
@service currentUser!: CurrentUser;
Expand Down Expand Up @@ -35,7 +37,7 @@ export default class InstitutionDiscoverController extends Controller {
}

@action
onSearch(queryOptions: OnSearchParams) {
onQueryParamChange(queryOptions: OnQueryParamChangeParams) {
this.q = queryOptions.cardSearchText;
this.sort = queryOptions.sort;
this.resourceType = queryOptions.resourceType as ResourceTypeFilterValue;
Expand Down
2 changes: 1 addition & 1 deletion app/institutions/discover/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@query={{this.q}}
@defaultQueryOptions={{this.defaultQueryOptions}}
@queryParams={{this.queryParams}}
@onSearch={{action this.onSearch}}
@onQueryParamChange={{action this.onQueryParamChange}}
@resourceType={{this.resourceType}}
@institution={{this.model}}
@sort={{this.sort}}
Expand Down
4 changes: 2 additions & 2 deletions app/preprints/discover/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import config from 'ember-osf-web/config/environment';

import Theme from 'ember-osf-web/services/theme';
import pathJoin from 'ember-osf-web/utils/path-join';
import { Filter, OnSearchParams } from 'osf-components/components/search-page/component';
import { Filter, OnQueryParamChangeParams } from 'osf-components/components/search-page/component';

export default class PreprintDiscoverController extends Controller {
@service store!: Store;
Expand All @@ -28,7 +28,7 @@ export default class PreprintDiscoverController extends Controller {
}

@action
onSearch(queryOptions: OnSearchParams) {
onQueryParamChange(queryOptions: OnQueryParamChangeParams) {
this.q = queryOptions.cardSearchText;
this.sort = queryOptions.sort;
this.activeFilters = queryOptions.activeFilters;
Expand Down
2 changes: 1 addition & 1 deletion app/preprints/discover/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@showResourceTypeFilter={{false}}
@provider={{this.model}}
@queryParams={{this.queryParams}}
@onSearch={{action this.onSearch}}
@onQueryParamChange={{action this.onQueryParamChange}}
@sort={{this.sort}}
@activeFilters={{this.activeFilters}}
/>
Expand Down
6 changes: 4 additions & 2 deletions app/search/controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Controller from '@ember/controller';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
import { Filter, OnSearchParams, ResourceTypeFilterValue } from 'osf-components/components/search-page/component';
import {
Filter, OnQueryParamChangeParams, ResourceTypeFilterValue,
} from 'osf-components/components/search-page/component';

export default class SearchController extends Controller {
@tracked q?: string = '';
Expand All @@ -12,7 +14,7 @@ export default class SearchController extends Controller {
queryParams = ['q', 'sort', 'resourceType', 'activeFilters'];

@action
onSearch(queryOptions: OnSearchParams) {
onQueryParamChange(queryOptions: OnQueryParamChangeParams) {
this.q = queryOptions.cardSearchText;
this.sort = queryOptions.sort;
this.resourceType = queryOptions.resourceType;
Expand Down
2 changes: 1 addition & 1 deletion app/search/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@route='search'
@cardSearchText={{this.q}}
@queryParams={{this.queryParams}}
@onSearch={{action this.onSearch}}
@onQueryParamChange={{action this.onQueryParamChange}}
@showResourceTypeFilter={{true}}
@sort={{this.sort}}
@resourceType={{this.resourceType}}
Expand Down
21 changes: 15 additions & 6 deletions lib/osf-components/addon/components/search-page/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ export interface Filter {
suggestedFilterOperator?: SuggestedFilterOperators;
}

export interface OnSearchParams {
export interface OnQueryParamChangeParams {
cardSearchText?: string;
sort?: string;
resourceType?: ResourceTypeFilterValue | null;
activeFilters?: Filter[];
}

interface SearchArgs {
onSearch?: (obj: OnSearchParams) => void;
onQueryParamChange?: (obj: OnQueryParamChangeParams) => void;
cardSearchText: string;
cardSearchFilters: Filter[];
propertyCard: IndexCardModel;
Expand Down Expand Up @@ -208,9 +208,6 @@ export default class SearchPage extends Component<SearchArgs> {
try {
const cardSearchText = this.cardSearchText;
const { page, sort, activeFilters, resourceType } = this;
if (this.args.onSearch) {
this.args.onSearch({cardSearchText, sort, resourceType, activeFilters});
}
const filterQueryObject = activeFilters.reduce((acc, filter) => {
// boolean filters should look like cardSearchFilter[hasDataResource][is-present]
if (filter.suggestedFilterOperator === SuggestedFilterOperators.IsPresent) {
Expand All @@ -225,7 +222,7 @@ export default class SearchPage extends Component<SearchArgs> {
acc[filter.propertyPathKey] = currentValue ? currentValue.concat(filter.value) : [filter.value];
return acc;
}, {} as { [key: string]: any });
let resourceTypeFilter = this.resourceType as string;
let resourceTypeFilter = resourceType as string;
// If resourceType is null, we want to search all resource types
if (!resourceTypeFilter) {
resourceTypeFilter = Object.values(ResourceTypeFilterValue).join(',');
Expand Down Expand Up @@ -278,6 +275,7 @@ export default class SearchPage extends Component<SearchArgs> {
async doDebounceSearch() {
await timeout(searchDebounceTime);
this.page = '';
this.updateQueryParams();
taskFor(this.search).perform();
}

Expand All @@ -292,13 +290,15 @@ export default class SearchPage extends Component<SearchArgs> {
this.activeFilters.pushObject(filter);
}
this.page = '';
this.updateQueryParams();
taskFor(this.search).perform();
}

@action
updateSort(sortOption: SortOption) {
this.sort = sortOption.value;
this.page = '';
this.updateQueryParams();
taskFor(this.search).perform();
}

Expand All @@ -307,6 +307,15 @@ export default class SearchPage extends Component<SearchArgs> {
this.resourceType = resourceTypeOption.value;
this.activeFilters = A<Filter>([]);
this.page = '';
this.updateQueryParams();
taskFor(this.search).perform();
}

@action
updateQueryParams() {
const { cardSearchText, sort, activeFilters, resourceType } = this;
if (this.args.onQueryParamChange) {
this.args.onQueryParamChange({cardSearchText, sort, resourceType, activeFilters});
}
}
}
10 changes: 5 additions & 5 deletions lib/registries/addon/branded/discover/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { inject as service } from '@ember/service';
import Intl from 'ember-intl/services/intl';
import Media from 'ember-responsive';
import { tracked } from '@glimmer/tracking';
import { Filter, OnSearchParams } from 'osf-components/components/search-page/component';
import { Filter, OnQueryParamChangeParams } from 'osf-components/components/search-page/component';
import pathJoin from 'ember-osf-web/utils/path-join';
import config from 'ember-osf-web/config/environment';
export default class BrandedDiscover extends Controller.extend() {
Expand All @@ -27,9 +27,9 @@ export default class BrandedDiscover extends Controller.extend() {
}

@action
onSearch(onSearchParams: OnSearchParams) {
this.cardSearchText = onSearchParams.cardSearchText;
this.sort = onSearchParams.sort;
this.activeFilters = onSearchParams.activeFilters;
onQueryParamChange(onQueryParamChangeParams: OnQueryParamChangeParams) {
this.cardSearchText = onQueryParamChangeParams.cardSearchText;
this.sort = onQueryParamChangeParams.sort;
this.activeFilters = onQueryParamChangeParams.activeFilters;
}
}
2 changes: 1 addition & 1 deletion lib/registries/addon/branded/discover/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@queryParams={{this.queryParams}}
@query={{this.q}}
@sort={{this.sort}}
@onSearch={{action this.onSearch}}
@onQueryParamChange={{action this.onQueryParamChange}}
@showResourceTypeFilter={{false}}
@activeFilters={{this.activeFilters}}
/>
Expand Down

0 comments on commit 303479d

Please sign in to comment.