Skip to content

Commit

Permalink
Fixed include/exclude regexp.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuznietsov committed Oct 27, 2022
1 parent 87042ff commit 7eb9001
Showing 1 changed file with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ const getOrderByWithAgg = ({
};
};

const filterOutEmptyValues = (values: string | Array<number | string>): number[] | string[] => {
if (typeof values === 'string') {
return Boolean(values) ? [] : [values];
}

return values.filter((v): v is string | number => {
if (typeof v === 'string') {
return Boolean(v);
}
return true;
}) as string[] | number[];
};

export const convertToTermsParams = ({
agg,
dataView,
Expand All @@ -88,17 +101,9 @@ export const convertToTermsParams = ({

return {
size: agg.aggParams.size ?? 10,
include: agg.aggParams.include
? Array.isArray(agg.aggParams.include)
? agg.aggParams.include
: [agg.aggParams.include]
: [],
include: agg.aggParams.include ? filterOutEmptyValues(agg.aggParams.include) : [],
includeIsRegex: agg.aggParams.includeIsRegex,
exclude: agg.aggParams.exclude
? Array.isArray(agg.aggParams.exclude)
? agg.aggParams.exclude
: [agg.aggParams.exclude]
: [],
exclude: agg.aggParams.exclude ? filterOutEmptyValues(agg.aggParams.exclude) : [],
excludeIsRegex: agg.aggParams.excludeIsRegex,
otherBucket: agg.aggParams.otherBucket,
orderDirection: agg.aggParams.order?.value ?? 'desc',
Expand Down

0 comments on commit 7eb9001

Please sign in to comment.