Skip to content

Commit 573d951

Browse files
committed
[ML] Fix type error and comments from review
1 parent 4fd072b commit 573d951

2 files changed

Lines changed: 23 additions & 14 deletions

File tree

x-pack/plugins/transform/public/app/sections/create_transform/components/aggregation_list/agg_label_form.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@ import { i18n } from '@kbn/i18n';
1010

1111
import { EuiButtonIcon, EuiFlexGroup, EuiFlexItem, EuiPopover } from '@elastic/eui';
1212

13-
import {
14-
AggName,
15-
isPivotAggsConfigPercentiles,
16-
PivotAggsConfig,
17-
PivotAggsConfigWithUiSupportDict,
18-
} from '../../../../common';
13+
import { AggName, PivotAggsConfig, PivotAggsConfigWithUiSupportDict } from '../../../../common';
1914

2015
import { PopoverForm } from './popover_form';
2116

x-pack/plugins/transform/public/app/sections/create_transform/components/aggregation_list/popover_form.tsx

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,27 @@ function getDefaultPercents(defaultData: PivotAggsConfig): number[] | undefined
4646
if (isPivotAggsConfigPercentiles(defaultData)) {
4747
return defaultData.percents;
4848
}
49+
}
50+
51+
function parsePercentsInput(inputValue: string | undefined) {
52+
if (inputValue !== undefined) {
53+
const strVals: string[] = inputValue.split(',');
54+
const percents: number[] = [];
55+
for (const str of strVals) {
56+
if (str.trim().length > 0 && isNaN(str as any) === false) {
57+
const val = Number(str);
58+
if (val >= 0 && val <= 100) {
59+
percents.push(val);
60+
} else {
61+
return [];
62+
}
63+
}
64+
}
4965

50-
return undefined;
66+
return percents;
67+
}
68+
69+
return [];
5170
}
5271

5372
function isPercentsInputValid(inputValue: string | undefined) {
@@ -85,12 +104,7 @@ export const PopoverForm: React.FC<Props> = ({ defaultData, otherAggNames, onCha
85104
}
86105

87106
function updatePercents(inputValue: string) {
88-
const isInputValid = isPercentsInputValid(inputValue);
89-
if (isInputValid === true) {
90-
setPercents(inputValue.split(',').map(Number));
91-
} else {
92-
setPercents([]);
93-
}
107+
setPercents(parsePercentsInput(inputValue));
94108
}
95109

96110
function getUpdatedItem(): PivotAggsConfig {
@@ -153,7 +167,7 @@ export const PopoverForm: React.FC<Props> = ({ defaultData, otherAggNames, onCha
153167
}
154168

155169
const validPercents =
156-
agg === PIVOT_SUPPORTED_AGGS.PERCENTILES && isPercentsInputValid(percentsText);
170+
agg === PIVOT_SUPPORTED_AGGS.PERCENTILES && parsePercentsInput(percentsText).length > 0;
157171

158172
let formValid = validAggName;
159173
if (formValid && agg === PIVOT_SUPPORTED_AGGS.PERCENTILES) {

0 commit comments

Comments
 (0)