Skip to content

Commit

Permalink
[Metrics UI] Fix alignment and allow clearing metric value (#66589)
Browse files Browse the repository at this point in the history
* Fix alignment and allow clearing metric value

* Add rds latency formatter

* Simplify css

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
phillipb and elasticmachine authored May 14, 2020
1 parent 2cf2633 commit d3206cd
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,8 @@ export const METRIC_FORMATTERS: MetricFormatters = {
formatter: InfraFormatterType.number,
template: '{{value}} seconds',
},
['rdsLatency']: {
formatter: InfraFormatterType.number,
template: '{{value}} ms',
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,31 @@ export const Expressions: React.FC<Props> = props => {
[onFilterChange]
);

const preFillAlertCriteria = useCallback(() => {
const md = alertsContext.metadata;
if (md && md.options) {
setAlertParams('criteria', [
{
...defaultExpression,
metric: md.options.metric!.type,
} as InventoryMetricConditions,
]);
} else {
setAlertParams('criteria', [defaultExpression]);
}
}, [alertsContext.metadata, setAlertParams]);

const preFillAlertFilter = useCallback(() => {
const md = alertsContext.metadata;
if (md && md.filter) {
setAlertParams('filterQueryText', md.filter);
setAlertParams(
'filterQuery',
convertKueryToElasticSearchQuery(md.filter, derivedIndexPattern) || ''
);
}
}, [alertsContext.metadata, derivedIndexPattern, setAlertParams]);

useEffect(() => {
const md = alertsContext.metadata;
if (!alertParams.nodeType) {
Expand All @@ -195,31 +220,19 @@ export const Expressions: React.FC<Props> = props => {
}
}

if (!alertParams.criteria) {
if (md && md.options) {
setAlertParams('criteria', [
{
...defaultExpression,
metric: md.options.metric!.type,
} as InventoryMetricConditions,
]);
} else {
setAlertParams('criteria', [defaultExpression]);
}
if (alertParams.criteria && alertParams.criteria.length) {
setTimeSize(alertParams.criteria[0].timeSize);
setTimeUnit(alertParams.criteria[0].timeUnit);
} else {
preFillAlertCriteria();
}

if (!alertParams.filterQuery) {
if (md && md.filter) {
setAlertParams('filterQueryText', md.filter);
setAlertParams(
'filterQuery',
convertKueryToElasticSearchQuery(md.filter, derivedIndexPattern) || ''
);
}
preFillAlertFilter();
}

if (!alertParams.sourceId) {
setAlertParams('sourceId', source?.id);
setAlertParams('sourceId', source?.id || 'default');
}
}, [alertsContext.metadata, derivedIndexPattern, defaultExpression, source]); // eslint-disable-line react-hooks/exhaustive-deps

Expand All @@ -235,11 +248,13 @@ export const Expressions: React.FC<Props> = props => {
</h4>
</EuiText>
<StyledExpression>
<NodeTypeExpression
options={nodeTypes}
value={alertParams.nodeType || 'host'}
onChange={updateNodeType}
/>
<StyledExpressionRow>
<NodeTypeExpression
options={nodeTypes}
value={alertParams.nodeType || 'host'}
onChange={updateNodeType}
/>
</StyledExpressionRow>
</StyledExpression>
<EuiSpacer size={'xs'} />
{alertParams.criteria &&
Expand Down Expand Up @@ -425,11 +440,13 @@ export const ExpressionRow: React.FC<ExpressionRowProps> = props => {
/>
</StyledExpression>
{metric && (
<StyledExpression>
<div style={{ display: 'flex', alignItems: 'center', height: '100%' }}>
<div>{metricUnit[metric]?.label || ''}</div>
</div>
</StyledExpression>
<div
style={{
alignSelf: 'center',
}}
>
<EuiText size={'s'}>{metricUnit[metric]?.label || ''}</EuiText>
</div>
)}
</StyledExpressionRow>
</EuiFlexItem>
Expand Down Expand Up @@ -502,4 +519,5 @@ const metricUnit: Record<string, { label: string }> = {
s3UploadBytes: { label: 'bytes' },
s3DownloadBytes: { label: 'bytes' },
sqsOldestMessage: { label: 'seconds' },
rdsLatency: { label: 'ms' },
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface Props {
metric?: { value: SnapshotMetricType; text: string };
metrics: Array<{ value: string; text: string }>;
errors: IErrorObject;
onChange: (metric: SnapshotMetricType) => void;
onChange: (metric?: SnapshotMetricType) => void;
popupPosition?:
| 'upCenter'
| 'upLeft'
Expand Down Expand Up @@ -65,11 +65,11 @@ export const MetricExpression = ({ metric, metrics, errors, onChange, popupPosit
}
)}
value={metric?.text || firstFieldOption.text}
isActive={aggFieldPopoverOpen || !metric}
isActive={Boolean(aggFieldPopoverOpen || (errors.metric && errors.metric.length > 0))}
onClick={() => {
setAggFieldPopoverOpen(true);
}}
color={metric ? 'secondary' : 'danger'}
color={errors.metric?.length ? 'danger' : 'secondary'}
/>
}
isOpen={aggFieldPopoverOpen}
Expand All @@ -89,16 +89,12 @@ export const MetricExpression = ({ metric, metrics, errors, onChange, popupPosit
</ClosablePopoverTitle>
<EuiFlexGroup>
<EuiFlexItem grow={false} className="actOf__aggFieldContainer">
<EuiFormRow
fullWidth
isInvalid={errors.metric.length > 0 && metric !== undefined}
error={errors.metric}
>
<EuiFormRow fullWidth isInvalid={errors.metric.length > 0} error={errors.metric}>
<EuiComboBox
fullWidth
singleSelection={{ asPlainText: true }}
data-test-subj="availablefieldsOptionsComboBox"
isInvalid={errors.metric.length > 0 && metric !== undefined}
isInvalid={errors.metric.length > 0}
placeholder={firstFieldOption.text}
options={availablefieldsOptions}
noSuggestions={!availablefieldsOptions.length}
Expand All @@ -110,6 +106,8 @@ export const MetricExpression = ({ metric, metrics, errors, onChange, popupPosit
if (selectedOptions.length > 0) {
onChange(selectedOptions[0].value as SnapshotMetricType);
setAggFieldPopoverOpen(false);
} else {
onChange();
}
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ const METRIC_FORMATTERS: MetricFormatters = {
formatter: InfraFormatterType.number,
template: '{{value}} seconds',
},
['rdsLatency']: {
formatter: InfraFormatterType.number,
template: '{{value}} ms',
},
};

export const createInventoryMetricFormatter = (metric: SnapshotMetricInput) => (
Expand Down

0 comments on commit d3206cd

Please sign in to comment.