diff --git a/app/institutions/discover/controller.ts b/app/institutions/discover/controller.ts index ffb5706ddb4..9922687f444 100644 --- a/app/institutions/discover/controller.ts +++ b/app/institutions/discover/controller.ts @@ -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; @@ -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; diff --git a/app/institutions/discover/template.hbs b/app/institutions/discover/template.hbs index 35b22695a50..b684f5d5eef 100644 --- a/app/institutions/discover/template.hbs +++ b/app/institutions/discover/template.hbs @@ -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}} diff --git a/app/preprints/discover/controller.ts b/app/preprints/discover/controller.ts index af7d5ec281a..749764034a5 100644 --- a/app/preprints/discover/controller.ts +++ b/app/preprints/discover/controller.ts @@ -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; @@ -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; diff --git a/app/preprints/discover/template.hbs b/app/preprints/discover/template.hbs index 1f2d9544ebe..9310db5a518 100644 --- a/app/preprints/discover/template.hbs +++ b/app/preprints/discover/template.hbs @@ -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}} /> diff --git a/app/search/controller.ts b/app/search/controller.ts index e8ed982aa50..fbfa7ec1f15 100644 --- a/app/search/controller.ts +++ b/app/search/controller.ts @@ -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 = ''; @@ -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; diff --git a/app/search/template.hbs b/app/search/template.hbs index ac29113295b..bde47e6cccc 100644 --- a/app/search/template.hbs +++ b/app/search/template.hbs @@ -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}} diff --git a/lib/osf-components/addon/components/search-page/component.ts b/lib/osf-components/addon/components/search-page/component.ts index fe9e80df328..6bf191b82d4 100644 --- a/lib/osf-components/addon/components/search-page/component.ts +++ b/lib/osf-components/addon/components/search-page/component.ts @@ -46,7 +46,7 @@ export interface Filter { suggestedFilterOperator?: SuggestedFilterOperators; } -export interface OnSearchParams { +export interface OnQueryParamChangeParams { cardSearchText?: string; sort?: string; resourceType?: ResourceTypeFilterValue | null; @@ -54,7 +54,7 @@ export interface OnSearchParams { } interface SearchArgs { - onSearch?: (obj: OnSearchParams) => void; + onQueryParamChange?: (obj: OnQueryParamChangeParams) => void; cardSearchText: string; cardSearchFilters: Filter[]; propertyCard: IndexCardModel; @@ -208,9 +208,6 @@ 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}); - } const filterQueryObject = activeFilters.reduce((acc, filter) => { // boolean filters should look like cardSearchFilter[hasDataResource][is-present] if (filter.suggestedFilterOperator === SuggestedFilterOperators.IsPresent) { @@ -225,7 +222,7 @@ export default class SearchPage extends Component { 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(','); @@ -278,6 +275,7 @@ export default class SearchPage extends Component { async doDebounceSearch() { await timeout(searchDebounceTime); this.page = ''; + this.updateQueryParams(); taskFor(this.search).perform(); } @@ -292,6 +290,7 @@ export default class SearchPage extends Component { this.activeFilters.pushObject(filter); } this.page = ''; + this.updateQueryParams(); taskFor(this.search).perform(); } @@ -299,6 +298,7 @@ export default class SearchPage extends Component { updateSort(sortOption: SortOption) { this.sort = sortOption.value; this.page = ''; + this.updateQueryParams(); taskFor(this.search).perform(); } @@ -307,6 +307,15 @@ export default class SearchPage extends Component { this.resourceType = resourceTypeOption.value; this.activeFilters = A([]); 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}); + } + } } diff --git a/lib/registries/addon/branded/discover/controller.ts b/lib/registries/addon/branded/discover/controller.ts index 722451d17f3..c03b0130e74 100644 --- a/lib/registries/addon/branded/discover/controller.ts +++ b/lib/registries/addon/branded/discover/controller.ts @@ -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() { @@ -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; } } diff --git a/lib/registries/addon/branded/discover/template.hbs b/lib/registries/addon/branded/discover/template.hbs index 1d9d0d6b45e..6d6cd0793be 100644 --- a/lib/registries/addon/branded/discover/template.hbs +++ b/lib/registries/addon/branded/discover/template.hbs @@ -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}} />