All files / components/list utils.js

63.16% Statements 12/19
28.57% Branches 4/14
100% Functions 2/2
63.16% Lines 12/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48    4x   4x 28x 28x                     28x     4x 28x 28x 28x 28x                     28x                   28x    
import { helper } from '@appbaseio/reactivecore';
 
const { getAggsOrder } = helper;
 
const extractQuery = props => {
	const queryToBeReturned = {};
	Iif (props.defaultQuery) {
		const evaluateQuery = props.defaultQuery([], props);
		if (evaluateQuery) {
			if (evaluateQuery.query) {
				queryToBeReturned.query = evaluateQuery.query;
			}
			if (evaluateQuery.aggs) {
				queryToBeReturned.aggs = evaluateQuery.aggs;
			}
		}
	}
	return queryToBeReturned;
};
// eslint-disable-next-line import/prefer-default-export
export const getAggsQuery = (query, props) => {
	const clonedQuery = query;
	const { dataField, size, sortBy, showMissing, missingLabel } = props;
	clonedQuery.size = 0;
	clonedQuery.aggs = {
		[dataField]: {
			terms: {
				field: dataField,
				size,
				order: getAggsOrder(sortBy || 'count'),
				...(showMissing ? { missing: missingLabel } : {}),
			},
		},
	};
 
	Iif (props.nestedField) {
		clonedQuery.aggs = {
			reactivesearch_nested: {
				nested: {
					path: props.nestedField,
				},
				aggs: clonedQuery.aggs,
			},
		};
	}
	return { ...clonedQuery, ...extractQuery(props) };
};