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

aggregation: make the name customizable #375

Merged
merged 1 commit into from
Apr 14, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ <h5 class="mb-0">
'fa-chevron-down': !expand && aggregationFilters.length == 0,
'fa-chevron-right': aggregationFilters.length > 0
}"></i>
{{ aggregation.key | translate | ucfirst }}
{{ (aggregation.name || aggregation.key) | translate | ucfirst }}
</button>
</h5>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ import { Component, Input } from '@angular/core';
})
export class RecordSearchAggregationComponent {
/** Aggregation data */
@Input() aggregation: { key: string, bucketSize: any, doc_count?: number, value: { buckets: Array<any> }, type: string, config?: any };
@Input() aggregation: {
key: string,
bucketSize: any,
doc_count?: number,
value: { buckets: Array<any> },
type: string,
config?: any,
name?: string
};
/** Current selected values */
@Input() aggregationsFilters = [];
/** If true, by default buckets are displayed. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export class RecordSearchPageComponent implements OnInit, OnDestroy {
preFilters?: any,
listHeaders?: any,
itemHeaders?: any,
aggregationsName?: any,
aggregationsOrder?: Array<string>,
aggregationsExpand?: Array<string>,
aggregationsBucketSize?: number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,14 @@ describe('RecordSearchComponent', () => {
it('should reorder aggregations', waitForAsync(() => {
component.currentType = 'documents';
const result = [
{ key: 'author', bucketSize: null, doc_count: null, value: { buckets: [] }, type: 'terms', config: null},
{ key: 'language', bucketSize: null, doc_count: null, value: { buckets: [] }, type: 'terms', config: null},
{ key: 'author', bucketSize: null, doc_count: null, value: { buckets: [] }, type: 'terms', config: null, name: null},
{ key: 'language', bucketSize: null, doc_count: null, value: { buckets: [] }, type: 'terms', config: null, name: null},
];
expect(component.aggregationsOrder(aggregations)).toEqual(result);

const resultOrder = [
{ key: 'language', bucketSize: null, doc_count: null, value: { buckets: [] }, type: 'terms', config: null},
{ key: 'author', bucketSize: null, doc_count: null, value: { buckets: [] }, type: 'terms', config: null},
{ key: 'language', bucketSize: null, doc_count: null, value: { buckets: [] }, type: 'terms', config: null, name: null},
{ key: 'author', bucketSize: null, doc_count: null, value: { buckets: [] }, type: 'terms', config: null, name: null},
];
component['_config'] = { key: 'documents', aggregationsOrder: ['language', 'author'] };
expect(component.aggregationsOrder(aggregations)).toEqual(resultOrder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy {
preFilters?: any,
listHeaders?: any,
itemHeaders?: any,
aggregationsName?: any,
aggregationsOrder?: Array<string>,
aggregationsExpand?: Array<string>,
aggregationsBucketSize?: number,
Expand Down Expand Up @@ -585,7 +586,8 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy {
doc_count: aggr[key].doc_count || null,
value: { buckets: aggr[key].buckets },
type: aggr[key].type || 'terms',
config: aggr[key].config || null
config: aggr[key].config || null,
name: aggr[key].name || this._aggregationName(key)
});
}
});
Expand All @@ -597,7 +599,8 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy {
doc_count: aggr[key].doc_count || null,
value: { buckets: aggr[key].buckets },
type: aggr[key].type || 'terms',
config: aggr[key].config || null
config: aggr[key].config || null,
name: aggr[key].name || this._aggregationName(key)
});
});
}
Expand Down Expand Up @@ -841,4 +844,15 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy {
}
return this._config.index ? this._config.index : this._config.key;
}

/**
* Get personalized name for current aggregation
* @param key - string, aggregation key
* @return string or null
*/
private _aggregationName(key: string): string | null {
return this._config.aggregationsName && key in this._config.aggregationsName
? this._config.aggregationsName[key]
: null;
}
}