-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Vis: Default editor] EUIficate Sub agg control (#37979)
* EUIficate metric agg control * Fix translation errors * Display agg error underneath the last bucket agg form control * Update functional test * Update error message * Update parent_pipeline_agg_controller.js * Fix validation when metricAgg is invalid * Show error message when a filed is selected * Delete _terms_helper.tsx * Remove extra empty line * Update parent_pipeline_agg_helper.js * Update selector for test
- Loading branch information
1 parent
f2dd96b
commit 386619e
Showing
16 changed files
with
198 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import React, { useEffect } from 'react'; | ||
import { EuiFormRow, EuiSelect } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { AggParamEditorProps } from 'ui/vis/editors/default'; | ||
import { safeMakeLabel, isCompatibleAggregation } from '../agg_utils'; | ||
|
||
const aggFilter = ['!top_hits', '!percentiles', '!percentile_ranks', '!median', '!std_dev']; | ||
const isCompatibleAgg = isCompatibleAggregation(aggFilter); | ||
const EMPTY_VALUE = 'EMPTY_VALUE'; | ||
|
||
function MetricAggParamEditor({ | ||
agg, | ||
value, | ||
showValidation, | ||
setValue, | ||
setValidity, | ||
setTouched, | ||
responseValueAggs, | ||
}: AggParamEditorProps<string>) { | ||
const label = i18n.translate('common.ui.aggTypes.metricLabel', { | ||
defaultMessage: 'Metric', | ||
}); | ||
const isValid = !!value; | ||
|
||
useEffect( | ||
() => { | ||
setValidity(isValid); | ||
}, | ||
[isValid] | ||
); | ||
|
||
useEffect( | ||
() => { | ||
if (responseValueAggs && value && value !== 'custom') { | ||
// ensure that metricAgg is set to a valid agg | ||
const respAgg = responseValueAggs | ||
.filter(isCompatibleAgg) | ||
.find(aggregation => aggregation.id === value); | ||
|
||
if (!respAgg) { | ||
setValue(); | ||
} | ||
} | ||
}, | ||
[responseValueAggs] | ||
); | ||
|
||
const options = responseValueAggs | ||
? responseValueAggs | ||
.filter(respAgg => respAgg.type.name !== agg.type.name) | ||
.map(respAgg => ({ | ||
text: i18n.translate('common.ui.aggTypes.definiteMetricLabel', { | ||
defaultMessage: 'Metric: {safeMakeLabel}', | ||
values: { | ||
safeMakeLabel: safeMakeLabel(respAgg), | ||
}, | ||
}), | ||
value: respAgg.id, | ||
disabled: !isCompatibleAgg(respAgg), | ||
})) | ||
: []; | ||
|
||
options.push({ | ||
text: i18n.translate('common.ui.aggTypes.customMetricLabel', { | ||
defaultMessage: 'Custom metric', | ||
}), | ||
value: 'custom', | ||
disabled: false, | ||
}); | ||
|
||
if (!value) { | ||
options.unshift({ text: '', value: EMPTY_VALUE, disabled: false }); | ||
} | ||
|
||
return ( | ||
<EuiFormRow label={label} fullWidth={true} isInvalid={showValidation ? !isValid : false}> | ||
<EuiSelect | ||
options={options} | ||
value={value || EMPTY_VALUE} | ||
onChange={ev => setValue(ev.target.value)} | ||
fullWidth={true} | ||
isInvalid={showValidation ? !isValid : false} | ||
onBlur={setTouched} | ||
data-test-subj={`visEditorSubAggMetric${agg.id}`} | ||
/> | ||
</EuiFormRow> | ||
); | ||
} | ||
|
||
export { MetricAggParamEditor }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,8 @@ | ||
<div ng-controller="aggParam.controller"> | ||
<div class="form-group"> | ||
<label | ||
for="visEditorSubAggMetric{{agg.id}}" | ||
i18n-id="common.ui.aggTypes.metricLabel" | ||
i18n-default-message="Metric" | ||
></label> | ||
<select | ||
id="visEditorSubAggMetric{{agg.id}}" | ||
name="metricAgg" | ||
ng-model="agg.params.metricAgg" | ||
agg="agg" | ||
required | ||
validate-agg | ||
class="form-control"> | ||
<option | ||
ng-repeat="respAgg in responseValueAggs track by respAgg.id" | ||
value="{{respAgg.id}}" | ||
ng-if="respAgg.type.name !== agg.type.name" | ||
ng-disabled="isDisabledAgg(respAgg)" | ||
ng-selected="agg.params.metricAgg === respAgg.id" | ||
i18n-id="common.ui.aggTypes.definiteMetricLabel" | ||
i18n-default-message="metric: {safeMakeLabel}" | ||
i18n-values="{ safeMakeLabel: safeMakeLabel(respAgg) }" | ||
></option> | ||
<option | ||
value="custom" | ||
ng-selected="agg.params.metricAgg === 'custom'" | ||
i18n-id="common.ui.aggTypes.customMetricLabel" | ||
i18n-default-message="Custom Metric" | ||
></option> | ||
</select> | ||
</div> | ||
<div ng-if="agg.params.metricAgg === 'custom'" class="visEditorAgg__subAgg"> | ||
<ng-form name="customMetricForm"> | ||
<vis-editor-agg-params | ||
index-pattern="agg.getIndexPattern()" | ||
agg="agg.params.customMetric" | ||
group-name="'metrics'"> | ||
</vis-editor-agg-params> | ||
</ng-form> | ||
</div> | ||
<div ng-controller="aggParam.controller" ng-show="agg.params.metricAgg === 'custom'" class="visEditorAgg__subAgg"> | ||
<vis-editor-agg-params | ||
index-pattern="agg.getIndexPattern()" | ||
agg="agg.params.customMetric" | ||
ng-if="agg.params.metricAgg === 'custom'" | ||
group-name="'metrics'"> | ||
</vis-editor-agg-params> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.