XY Fix percentile with decimals (#123709)

This commit is contained in:
Joe Reuter 2022-01-26 12:24:00 +01:00 committed by GitHub
parent 16642e0028
commit 03c8d08026
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View file

@ -129,6 +129,22 @@ describe('isPercentileIdEqualToSeriesId', () => {
expect(isEqual).toBeFalsy();
});
it('should be equal for column with percentile with decimal points', () => {
const seriesColumnId = '1';
const columnId = `${seriesColumnId}['95.5']`;
const isEqual = isPercentileIdEqualToSeriesId(columnId, seriesColumnId);
expect(isEqual).toBeTruthy();
});
it('should not be equal for column with percentile with decimal points equal to seriesColumnId', () => {
const seriesColumnId = '1';
const columnId = `2['1.3']`;
const isEqual = isPercentileIdEqualToSeriesId(columnId, seriesColumnId);
expect(isEqual).toBeFalsy();
});
it('should not be equal for column with percentile, where columnId contains seriesColumnId', () => {
const seriesColumnId = '1';
const columnId = `${seriesColumnId}2.1`;

View file

@ -79,8 +79,16 @@ export const getSplitSeriesAccessorFnMap = (
};
// For percentile, the aggregation id is coming in the form %s.%d, where %s is agg_id and %d - percents
export const getSafeId = (columnId?: number | string | null) =>
(columnId || '').toString().split('.')[0];
export const getSafeId = (columnId?: number | string | null) => {
const id = String(columnId);
// only multi-value aggs like percentiles are allowed to contain dots and [
const isMultiValueId = id.includes('[') || id.includes('.');
if (!isMultiValueId) {
return id;
}
const baseId = id.substring(0, id.indexOf('[') !== -1 ? id.indexOf('[') : id.indexOf('.'));
return baseId;
};
export const isPercentileIdEqualToSeriesId = (
columnId: number | string | null | undefined,