Fixed Search filter issues (#2197)

This commit is contained in:
darth-coder00 2022-01-13 19:43:32 +05:30 committed by GitHub
parent 5714c4122b
commit ad362a31fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,6 +15,7 @@ import classNames from 'classnames';
import { cloneDeep } from 'lodash'; import { cloneDeep } from 'lodash';
import { import {
AggregationType, AggregationType,
Bucket,
FilterObject, FilterObject,
FormatedTableData, FormatedTableData,
SearchResponse, SearchResponse,
@ -169,18 +170,21 @@ const Explore: React.FC<ExploreProps> = ({
for (const newAgg of newAggregations) { for (const newAgg of newAggregations) {
for (const oldAgg of oldAggs) { for (const oldAgg of oldAggs) {
if (newAgg.title === oldAgg.title) { if (newAgg.title === oldAgg.title) {
for (const oldBucket of oldAgg.buckets) { const buckets = cloneDeep(oldAgg.buckets)
let docCount = 0; .map((item) => {
for (const newBucket of newAgg.buckets) { // eslint-disable-next-line @typescript-eslint/camelcase
if (newBucket.key === oldBucket.key) { return { ...item, doc_count: 0 };
docCount = newBucket.doc_count; })
.concat(newAgg.buckets);
const bucketHashmap = buckets.reduce((obj, item) => {
obj[item.key]
? // eslint-disable-next-line @typescript-eslint/camelcase
(obj[item.key].doc_count += item.doc_count)
: (obj[item.key] = { ...item });
break; return obj;
} }, {} as { [key: string]: Bucket });
} oldAgg.buckets = Object.values(bucketHashmap);
// eslint-disable-next-line @typescript-eslint/camelcase
oldBucket.doc_count = docCount;
}
} }
} }
} }
@ -505,7 +509,7 @@ const Explore: React.FC<ExploreProps> = ({
'tags' 'tags'
); );
const aggDatabase = getAggregationList( const aggDatabase = getAggregationList(
searchResult.resAggTag.data.aggregations, searchResult.resAggDatabase.data.aggregations,
'database' 'database'
); );