diff --git a/app/institutions/dashboard/-components/object-list/component-test.ts b/app/institutions/dashboard/-components/object-list/component-test.ts index e7fa68b053..c7bab5ccb5 100644 --- a/app/institutions/dashboard/-components/object-list/component-test.ts +++ b/app/institutions/dashboard/-components/object-list/component-test.ts @@ -71,7 +71,7 @@ module('Integration | institutions | dashboard | -components | object-list', hoo assert.dom('[data-test-page-tab="summary"]').exists('Summary tab exists'); // Elements in the top bar are present - assert.dom('[data-test-object-count]').containsText('10 total thingies', 'Object count is correct'); + assert.dom('[data-test-object-count]').containsText('10,000+ total thingies', 'Object count is correct'); assert.dom('[data-test-toggle-filter-button]').exists('Filter button exists'); assert.dom('[data-test-customize-columns-button]').exists('Columns button exists'); diff --git a/app/models/index-card-search.ts b/app/models/index-card-search.ts index 5421da16dc..91066e0f5f 100644 --- a/app/models/index-card-search.ts +++ b/app/models/index-card-search.ts @@ -1,5 +1,7 @@ +import { inject as service } from '@ember/service'; import Model, { AsyncHasMany, attr, hasMany } from '@ember-data/model'; import {Links} from 'jsonapi-typescript'; +import Intl from 'ember-intl/services/intl'; import RelatedPropertyPathModel from './related-property-path'; import SearchResultModel from './search-result'; @@ -10,12 +12,12 @@ export interface SearchFilter { filterType?: string; } -export const ShareMoreThanTenThousand = 'trove:ten-thousands-and-more'; - export default class IndexCardSearchModel extends Model { + @service intl!: Intl; + @attr('string') cardSearchText!: string; @attr('array') cardSearchFilters!: SearchFilter[]; - @attr('string') totalResultCount!: number | typeof ShareMoreThanTenThousand; + @attr totalResultCount!: number | object; @attr('object') links!: Links; @hasMany('search-result', { inverse: null }) @@ -47,6 +49,14 @@ export default class IndexCardSearchModel extends Model { } return null; } + + get displayCount(): number | string { + return ( + typeof this.totalResultCount === 'number' + ? this.totalResultCount + : this.intl.t('search.ten-thousand-plus') + ); + } } declare module 'ember-data/types/registries/model' { diff --git a/lib/osf-components/addon/components/index-card-searcher/component.ts b/lib/osf-components/addon/components/index-card-searcher/component.ts index c2e69d870b..453e5b9848 100644 --- a/lib/osf-components/addon/components/index-card-searcher/component.ts +++ b/lib/osf-components/addon/components/index-card-searcher/component.ts @@ -23,7 +23,7 @@ export default class IndexCardSearcher extends Component debounceTime = this.args.debounceTime || 1000; @tracked searchResults: SearchResultModel[] = []; - @tracked totalResultCount = 0; + @tracked totalResultCount: number | string = 0; @tracked relatedProperties?: RelatedPropertyPathModel[] = []; @tracked booleanFilters?: RelatedPropertyPathModel[] = []; @@ -71,7 +71,7 @@ export default class IndexCardSearcher extends Component this.nextPageCursor = searchResult.nextPageCursor; this.prevPageCursor = searchResult.prevPageCursor; this.searchResults = searchResult.searchResultPage.toArray(); - this.totalResultCount = searchResult.totalResultCount; + this.totalResultCount = searchResult.displayCount; return searchResult; } catch (error) { diff --git a/lib/osf-components/addon/components/search-page/component.ts b/lib/osf-components/addon/components/search-page/component.ts index 7217d24958..ee95e84d1d 100644 --- a/lib/osf-components/addon/components/search-page/component.ts +++ b/lib/osf-components/addon/components/search-page/component.ts @@ -11,7 +11,6 @@ import Store from '@ember-data/store'; import { action } from '@ember/object'; import Media from 'ember-responsive'; -import { ShareMoreThanTenThousand } from 'ember-osf-web/models/index-card-search'; import InstitutionModel from 'ember-osf-web/models/institution'; import SearchResultModel from 'ember-osf-web/models/search-result'; import ProviderModel from 'ember-osf-web/models/provider'; @@ -83,7 +82,7 @@ export default class SearchPage extends Component { @tracked relatedProperties?: RelatedPropertyPathModel[] = []; @tracked booleanFilters?: RelatedPropertyPathModel[] = []; @tracked page?: string = ''; - @tracked totalResultCount?: number | {'@id': string}; + @tracked totalResultCount?: number | string; @tracked firstPageCursor?: string | null; @tracked prevPageCursor?: string | null; @tracked nextPageCursor?: string | null; @@ -263,8 +262,7 @@ export default class SearchPage extends Component { this.nextPageCursor = searchResult.nextPageCursor; this.prevPageCursor = searchResult.prevPageCursor; this.searchResults = searchResult.searchResultPage.toArray(); - this.totalResultCount = searchResult.totalResultCount?.['@id'] === ShareMoreThanTenThousand ? '10,000+' : - searchResult.totalResultCount; + this.totalResultCount = searchResult.displayCount; } catch (e) { this.toast.error(e); } diff --git a/mirage/views/search.ts b/mirage/views/search.ts index 376b6c0943..bdb826bad2 100644 --- a/mirage/views/search.ts +++ b/mirage/views/search.ts @@ -300,7 +300,7 @@ export function cardSearch(_: Schema, request: Request) { ], }, ], - totalResultCount: 10, + totalResultCount: {'@id': 'trove:ten-thousands-and-more'}, }, relationships: { relatedProperties: { diff --git a/translations/en-us.yml b/translations/en-us.yml index 24d29d8274..e568ed6c76 100644 --- a/translations/en-us.yml +++ b/translations/en-us.yml @@ -602,6 +602,7 @@ search: search-help-label: 'Help tutorial' total-results: '{count} {count, plural, one {result} other {results} }' no-results: 'No results found' + ten-thousand-plus: '10,000+' resource-type: search-by: 'Search by object type' all: 'All'