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

[ENG-4660] activeFilters query param #1990

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
6 changes: 4 additions & 2 deletions app/institutions/discover/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ 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 { OnSearchParams, ResourceTypeFilterValue } from 'osf-components/components/search-page/component';
import { Filter, OnSearchParams, ResourceTypeFilterValue } from 'osf-components/components/search-page/component';

export default class InstitutionDiscoverController extends Controller {
@service currentUser!: CurrentUser;

@tracked cardSearchText?: string = '';
@tracked sort?: string = '-relevance';
@tracked resourceType?: ResourceTypeFilterValue | null = null;
@tracked activeFilters?: Filter[] = [];

queryParams = ['cardSearchText', 'sort', 'resourceType'];
queryParams = ['cardSearchText', 'sort', 'resourceType', 'activeFilters'];

get defaultQueryOptions() {
return {
Expand All @@ -27,5 +28,6 @@ export default class InstitutionDiscoverController extends Controller {
this.cardSearchText = queryOptions.cardSearchText;
this.sort = queryOptions.sort;
this.resourceType = queryOptions.resourceType;
this.activeFilters = queryOptions.activeFilters;
}
}
1 change: 1 addition & 0 deletions app/institutions/discover/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
@institution={{this.model}}
@sort={{this.sort}}
@showResourceTypeFilter={{true}}
@activeFilters={{this.activeFilters}}
/>
8 changes: 5 additions & 3 deletions app/preprints/discover/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ import config from 'ember-get-config';

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

export default class PreprintDiscoverController extends Controller {
@service store!: Store;
@service theme!: Theme;

@tracked cardSearchText?: string = '';
@tracked sort?: string = '-relevance';
@tracked sort?: string = '-relevance';
@tracked activeFilters?: Filter[] = [];

queryParams = ['cardSearchText', 'sort'];
queryParams = ['cardSearchText', 'sort', 'activeFilters'];

get defaultQueryOptions() {
return {
Expand All @@ -30,5 +31,6 @@ export default class PreprintDiscoverController extends Controller {
onSearch(queryOptions: OnSearchParams) {
this.cardSearchText = queryOptions.cardSearchText;
this.sort = queryOptions.sort;
this.activeFilters = queryOptions.activeFilters;
}
}
1 change: 1 addition & 0 deletions app/preprints/discover/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
@queryParams={{this.queryParams}}
@onSearch={{action this.onSearch}}
@sort={{this.sort}}
@activeFilters={{this.activeFilters}}
/>
</div>
6 changes: 4 additions & 2 deletions app/search/controller.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import Controller from '@ember/controller';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
import { OnSearchParams, ResourceTypeFilterValue } from 'osf-components/components/search-page/component';
import { Filter, OnSearchParams, ResourceTypeFilterValue } from 'osf-components/components/search-page/component';

export default class SearchController extends Controller {
@tracked q?: string = '';
@tracked sort?: string = '-relevance';
@tracked resourceType?: ResourceTypeFilterValue | null = null;
@tracked activeFilters?: Filter[] = [];

queryParams = ['q', 'sort', 'resourceType'];
queryParams = ['q', 'sort', 'resourceType', 'activeFilters'];

@action
onSearch(queryOptions: OnSearchParams) {
this.q = queryOptions.cardSearchText;
this.sort = queryOptions.sort;
this.resourceType = queryOptions.resourceType;
this.activeFilters = queryOptions.activeFilters;
}
}
1 change: 1 addition & 0 deletions app/search/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
@sort={{this.sort}}
@resourceType={{this.resourceType}}
@page={{this.page}}
@activeFilters={{this.activeFilters}}
/>
5 changes: 4 additions & 1 deletion lib/osf-components/addon/components/search-page/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface OnSearchParams {
cardSearchText?: string;
sort?: string;
resourceType?: ResourceTypeFilterValue | null;
activeFilters?: Filter[];
}

interface SearchArgs {
Expand All @@ -63,6 +64,7 @@ interface SearchArgs {
provider?: ProviderModel;
showResourceTypeFilter: boolean;
page: string;
activeFilters: Filter[];
}

const searchDebounceTime = 100;
Expand All @@ -89,6 +91,7 @@ export default class SearchPage extends Component<SearchArgs> {
this.cardSearchText = this.args.cardSearchText;
this.sort = this.args.sort;
this.resourceType = this.args.resourceType;
this.activeFilters = A<Filter>(this.args.activeFilters);
taskFor(this.search).perform();
}

Expand Down Expand Up @@ -233,7 +236,7 @@ export default class SearchPage extends Component<SearchArgs> {
this.totalResultCount = searchResult.totalResultCount === ShareMoreThanTenThousand ? '10,000+' :
searchResult.totalResultCount;
if (this.args.onSearch) {
this.args.onSearch({cardSearchText, sort, resourceType});
this.args.onSearch({cardSearchText, sort, resourceType, activeFilters});
}
} catch (e) {
this.toast.error(e);
Expand Down
8 changes: 5 additions & 3 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 { OnSearchParams } from 'osf-components/components/search-page/component';
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';

Expand All @@ -16,9 +16,10 @@ export default class BrandedDiscover extends Controller.extend() {
@service store!: Store;

@tracked cardSearchText? = '';
@tracked sort? = '-relevance';
@tracked sort?= '-relevance';
@tracked activeFilters?: Filter[] = [];

queryParams = ['cardSearchText', 'sort'];
queryParams = ['cardSearchText', 'sort', 'activeFilters'];

get defaultQueryOptions() {
return {
Expand All @@ -30,5 +31,6 @@ export default class BrandedDiscover extends Controller.extend() {
onSearch(onSearchParams: OnSearchParams) {
this.cardSearchText = onSearchParams.cardSearchText;
this.sort = onSearchParams.sort;
this.activeFilters = onSearchParams.activeFilters;
}
}
1 change: 1 addition & 0 deletions lib/registries/addon/branded/discover/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
@sort={{this.sort}}
@onSearch={{action this.onSearch}}
@showResourceTypeFilter={{false}}
@activeFilters={{this.activeFilters}}
/>
</RegistriesWrapper>
Loading