Skip to content

Commit 3f35069

Browse files
[DURACOM-426] add labels, fix facets labels,fix onebox other info template
1 parent b29dc1e commit 3f35069

File tree

5 files changed

+127
-7
lines changed

5 files changed

+127
-7
lines changed

src/app/shared/form/builder/ds-dynamic-form-ui/models/onebox/dynamic-onebox.component.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
<ng-template #hasInfo let-entry="entry">
99
<ul class="list-unstyled mb-0">
10-
<li class="list-item text-truncate text-primary fw-bold">
10+
<li class="list-item d-flex align-items-center">
1111
@if (entry.source) {
12-
<img class="mr-2 source-icon" #imgTag [src]="getAuthoritySourceIcon(entry.source, imgTag)" [attr.alt]="('form.entry.source.' + entry.source) | translate" />
12+
<img class="source-icon" #imgTag [src]="getAuthoritySourceIcon(entry.source, imgTag)" [attr.alt]="('form.entry.source.' + entry.source) | translate" />
1313
}
14-
{{entry.value}}
14+
<div class="ms-2 text-truncate text-primary fw-bold">{{entry.value}}</div>
1515
</li>
1616
@for (item of entry.otherInformation | dsObjNgFor; track item) {
1717
<li class="list-item text-truncate text-secondary" >
@@ -25,9 +25,9 @@
2525
<ul class="list-unstyled mb-0">
2626
<li class="list-item d-flex align-items-center">
2727
@if(entry.source) {
28-
<img class="mr-2 source-icon" #imgTag [src]="getAuthoritySourceIcon(entry.source, imgTag)" [attr.alt]="('form.entry.source.' + entry.source) | translate" />
28+
<img class="source-icon" #imgTag [src]="getAuthoritySourceIcon(entry.source, imgTag)" [attr.alt]="('form.entry.source.' + entry.source) | translate" />
2929
}
30-
<div class="text-truncate text-primary font-weight-bold">{{entry.value}}</div>
30+
<div class="ms-2 text-truncate text-primary font-weight-bold">{{entry.value}}</div>
3131
@if(entry.source) {
3232
<div class="ml-2 text-truncate text-secondary">{{ ('form.entry.source.' + entry.source) | translate}}</div>
3333
}

src/app/shared/search/search-filters/search-filter/search-facet-filter/search-facet-filter.component.spec.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { Router } from '@angular/router';
1313
import { RemoteDataBuildService } from '@dspace/core/cache/builders/remote-data-build.service';
1414
import { PageInfo } from '@dspace/core/shared/page-info.model';
1515
import { AppliedFilter } from '@dspace/core/shared/search/models/applied-filter.model';
16+
import { FacetValue } from '@dspace/core/shared/search/models/facet-value.model';
1617
import { FacetValues } from '@dspace/core/shared/search/models/facet-values.model';
1718
import { FilterType } from '@dspace/core/shared/search/models/filter-type.model';
1819
import { SearchFilterConfig } from '@dspace/core/shared/search/models/search-filter-config.model';
@@ -41,6 +42,8 @@ describe('SearchFacetFilterComponent', () => {
4142
const value2 = 'test2';
4243
const value3 = 'another value3';
4344
const value4 = '52d629dc-7d2f-47b9-aa2d-258b92e45ae1';
45+
const value5 = 'test authority';
46+
const authority = '52d629dc-7d2f-47b9-aa2d-258b92e45ae1';
4447
const mockFilterConfig: SearchFilterConfig = Object.assign(new SearchFilterConfig(), {
4548
name: filterName1,
4649
filterType: FilterType.text,
@@ -72,12 +75,40 @@ describe('SearchFacetFilterComponent', () => {
7275
label: value4,
7376
value: value4,
7477
});
78+
const appliedFilter5: AppliedFilter = Object.assign(new AppliedFilter(), {
79+
filter: filterName1,
80+
operator: 'authority',
81+
label: authority,
82+
value: authority,
83+
});
84+
const facetValue1: FacetValue = Object.assign(new FacetValue(), {
85+
label: value1,
86+
value: value1,
87+
});
88+
const facetValue2: FacetValue = Object.assign(new FacetValue(), {
89+
label: value2,
90+
value: value2,
91+
});
92+
const facetValue3: FacetValue = Object.assign(new FacetValue(), {
93+
label: value3,
94+
value: value3,
95+
});
96+
const facetValue4: FacetValue = Object.assign(new FacetValue(), {
97+
label: value5,
98+
value: authority,
99+
});
75100
const values: Partial<FacetValues> = {
76101
appliedFilters: [
77102
appliedFilter1,
78103
appliedFilter2,
79104
appliedFilter3,
80105
],
106+
page: [
107+
facetValue1,
108+
facetValue2,
109+
facetValue3,
110+
facetValue4,
111+
],
81112
pageInfo: Object.assign(new PageInfo(), {
82113
currentPage: 0,
83114
}),
@@ -246,4 +277,23 @@ describe('SearchFacetFilterComponent', () => {
246277
}));
247278
});
248279
});
280+
281+
describe('when selected value has an authority', () => {
282+
let selectedValues$: BehaviorSubject<AppliedFilter[]>;
283+
284+
beforeEach(() => {
285+
selectedValues$ = new BehaviorSubject([appliedFilter5]);
286+
spyOn(searchService, 'getSelectedValuesForFilter').and.returnValue(selectedValues$);
287+
comp.ngOnInit();
288+
});
289+
290+
it('should updated the label with the one of the related FacetValue', () => {
291+
const expectedValue = Object.assign(appliedFilter5, {
292+
label: facetValue4.label,
293+
});
294+
expect(comp.selectedAppliedFilters$).toBeObservable(cold('a', {
295+
a: [expectedValue],
296+
}));
297+
});
298+
});
249299
});

src/app/shared/search/search-filters/search-filter/search-facet-filter/search-facet-filter.component.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,23 @@ import { SearchOptions } from '@dspace/core/shared/search/models/search-options.
2727
import {
2828
hasNoValue,
2929
hasValue,
30+
isNotEmpty,
3031
} from '@dspace/shared/utils/empty.util';
3132
import {
3233
BehaviorSubject,
34+
combineLatest,
3335
combineLatest as observableCombineLatest,
36+
from,
3437
Observable,
3538
of,
3639
Subscription,
3740
} from 'rxjs';
3841
import {
3942
distinctUntilChanged,
43+
filter,
4044
map,
45+
mergeMap,
46+
reduce,
4147
switchMap,
4248
take,
4349
tap,
@@ -46,6 +52,10 @@ import {
4652
import { SEARCH_CONFIG_SERVICE } from '../../../../../my-dspace-page/my-dspace-configuration.service';
4753
import { InputSuggestion } from '../../../../input-suggestions/input-suggestions.model';
4854
import { SearchService } from '../../../search.service';
55+
import {
56+
getFacetValueForType,
57+
stripOperatorFromFilterValue,
58+
} from '../../../search.utils';
4959
import { SearchConfigurationService } from '../../../search-configuration.service';
5060
import { SearchFilterService } from '../../search-filter.service';
5161

@@ -167,7 +177,29 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
167177
this.searchOptions$.subscribe(() => this.updateFilterValueList()),
168178
this.retrieveFilterValues().subscribe(),
169179
);
170-
this.selectedAppliedFilters$ = this.searchService.getSelectedValuesForFilter(this.filterConfig.name).pipe(
180+
181+
this.selectedAppliedFilters$ = combineLatest([
182+
this.searchService.getSelectedValuesForFilter(this.filterConfig.name),
183+
this.facetValues$.asObservable().pipe(
184+
mergeMap((values: FacetValues[]) => from(values).pipe(
185+
reduce((acc: FacetValue[], value: FacetValues) => acc.concat(value.page), []),
186+
)),
187+
),
188+
]).pipe(
189+
filter(([allAppliedFilters, facetValues]: [AppliedFilter[], FacetValue[]]) => isNotEmpty(facetValues)),
190+
map(([allAppliedFilters, facetValues]) =>
191+
allAppliedFilters.map((appliedValue) => {
192+
const fValue = facetValues.find((facetValue: FacetValue) => {
193+
const valueForType = getFacetValueForType(facetValue, this.filterConfig);
194+
return hasValue(valueForType) &&
195+
stripOperatorFromFilterValue(valueForType) === appliedValue.value;
196+
});
197+
198+
return hasValue(fValue)
199+
? Object.assign(appliedValue, { label: fValue.label })
200+
: appliedValue;
201+
}),
202+
),
171203
map((allAppliedFilters: AppliedFilter[]) => allAppliedFilters.filter((appliedFilter: AppliedFilter) => FACET_OPERATORS.includes(appliedFilter.operator))),
172204
distinctUntilChanged((previous: AppliedFilter[], next: AppliedFilter[]) => JSON.stringify(previous) === JSON.stringify(next)),
173205
);

src/app/shared/search/search-labels/search-labels.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="labels">
2-
@for (appliedFilter of appliedFilters$ | async; track appliedFilter) {
2+
@for (appliedFilter of appliedFilters$ | async; track appliedFilter.value) {
33
<ds-search-label-loader
44
[appliedFilter]="appliedFilter"
55
[inPlaceSearch]="inPlaceSearch">

src/assets/i18n/en.json5

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,6 +2087,44 @@
20872087

20882088
"form.other-information.orcid": "ORCID",
20892089

2090+
"form.other-information.data-person_identifier_orcid": "ORCID",
2091+
2092+
"form.other-information.person_identifier_orcid": "ORCID",
2093+
2094+
"form.other-information.data-oairecerif_author_affiliation": "Affiliation",
2095+
2096+
"form.other-information.oairecerif_author_affiliation": "Affiliation",
2097+
2098+
"form.other-information.oairecerif_editor_affiliation": "Affiliation",
2099+
2100+
"form.other-information.person_identifier_orcid": "ORCID iD",
2101+
2102+
"form.other-information.institution-affiliation-name": "Affiliation(s)",
2103+
2104+
"form.other-information.dc_relation_grantno": "Grant Number",
2105+
2106+
"form.other-information.not-available": "Not available",
2107+
2108+
"form.other-information.ror_orgunit_id": "ROR ID",
2109+
2110+
"form.other-information.ror_orgunit_type": "ROR type",
2111+
2112+
"form.other-information.ror_orgunit_acronym": "ROR acronym",
2113+
2114+
"form.other-information.ror_orgunit_countryName": "ROR country",
2115+
2116+
"form.entry.source.local": "",
2117+
2118+
"form.entry.source.orcid": "",
2119+
2120+
"form.entry.source.ror": "",
2121+
2122+
"form.entry.source.openaire": "",
2123+
2124+
"form.entry.source.zdb": "",
2125+
2126+
"form.entry.source.sherpa": "- Sherpa Romeo",
2127+
20902128
"form.remove": "Remove",
20912129

20922130
"form.save": "Save",

0 commit comments

Comments
 (0)