Skip to content

Commit 9484258

Browse files
committed
Ensure chart values are set
1 parent 846eae1 commit 9484258

2 files changed

Lines changed: 17 additions & 18 deletions

File tree

x-pack/platform/plugins/shared/dataset_quality/public/rule_types/degraded_docs/rule_form/rule_condition_chart.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ import {
2222
asPercent,
2323
} from './chart_preview/chart_preview_helper';
2424

25-
interface ChartOptions {
26-
interval?: string;
27-
}
28-
2925
export interface RuleConditionChartProps {
3026
threshold: number[];
3127
comparator: COMPARATORS;
@@ -34,7 +30,6 @@ export interface RuleConditionChartProps {
3430
dataView?: DataView;
3531
groupBy?: string | string[];
3632
timeRange: TimeRange;
37-
chartOptions?: ChartOptions;
3833
}
3934

4035
export function RuleConditionChart({
@@ -45,30 +40,30 @@ export function RuleConditionChart({
4540
dataView,
4641
groupBy,
4742
timeRange,
48-
chartOptions: { interval } = {},
4943
}: RuleConditionChartProps) {
5044
const {
5145
services: { http, uiSettings },
5246
} = useKibanaContextForPlugin();
47+
const chartInterval = timeSize && timeUnit ? `${timeSize}${timeUnit}` : undefined;
5348

5449
const { loading, value, error } = useAbortableAsync(
5550
async ({ signal }) => {
56-
if (dataView && timeRange.from && timeRange.to) {
51+
if (dataView && timeRange.from && timeRange.to && chartInterval) {
5752
return http.get<PreviewChartResponse>(
5853
'/internal/dataset_quality/rule_types/degraded_docs/chart_preview',
5954
{
6055
query: {
6156
index: dataView?.getIndexPattern(),
6257
start: timeRange?.from,
6358
end: timeRange?.to,
64-
interval: interval || `${timeSize}${timeUnit}`,
59+
interval: chartInterval,
6560
groupBy: rison.encodeArray(Array.isArray(groupBy) ? groupBy : [groupBy]),
6661
},
6762
}
6863
);
6964
}
7065
},
71-
[http, dataView, groupBy, interval, timeRange?.from, timeRange?.to, timeSize, timeUnit]
66+
[http, dataView, groupBy, chartInterval, timeRange?.from, timeRange?.to]
7267
);
7368

7469
return (

x-pack/platform/plugins/shared/dataset_quality/public/rule_types/degraded_docs/rule_form/rule_form.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ export const RuleForm: React.FunctionComponent<
192192
};
193193

194194
const selectedOptions = [...getPreSelectedOptions(), ...getUserSelectedOptions(groupBy)];
195+
const normalizedThreshold = threshold ?? defaultRuleParams.threshold!;
196+
const normalizedComparator = (comparator ?? defaultRuleParams.comparator) as COMPARATORS;
197+
const normalizedTimeSize = timeSize || defaultRuleParams.timeSize!;
198+
const normalizedTimeUnit = (timeUnit ?? defaultRuleParams.timeUnit) as TimeUnitChar;
195199

196200
return (
197201
<>
@@ -247,8 +251,8 @@ export const RuleForm: React.FunctionComponent<
247251
/>
248252

249253
<ThresholdExpression
250-
thresholdComparator={comparator ?? defaultRuleParams.comparator}
251-
threshold={threshold}
254+
thresholdComparator={normalizedComparator}
255+
threshold={normalizedThreshold}
252256
onChangeSelectedThresholdComparator={(value) => updateProperty('comparator', value)}
253257
onChangeSelectedThreshold={(value) => updateProperty('threshold', value)}
254258
errors={errors}
@@ -257,20 +261,20 @@ export const RuleForm: React.FunctionComponent<
257261
/>
258262

259263
<RuleConditionChart
260-
threshold={threshold}
261-
comparator={comparator as COMPARATORS}
262-
timeSize={timeSize}
263-
timeUnit={timeUnit as TimeUnitChar}
264+
threshold={normalizedThreshold}
265+
comparator={normalizedComparator}
266+
timeSize={normalizedTimeSize}
267+
timeUnit={normalizedTimeUnit}
264268
dataView={dataView}
265269
groupBy={groupBy}
266-
timeRange={{ from: `now-${(timeSize ?? 1) * 20}${timeUnit}`, to: 'now' }}
270+
timeRange={{ from: `now-${normalizedTimeSize * 20}${normalizedTimeUnit}`, to: 'now' }}
267271
/>
268272

269273
<EuiSpacer size="l" />
270274

271275
<ForLastExpression
272-
timeWindowSize={timeSize}
273-
timeWindowUnit={timeUnit}
276+
timeWindowSize={normalizedTimeSize}
277+
timeWindowUnit={normalizedTimeUnit}
274278
errors={{
275279
timeSize: [],
276280
timeUnit: [],

0 commit comments

Comments
 (0)