forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SLO] Add/edit form mark optional fields (elastic#175807)
## Summary Fixes elastic/observability-dev#3049 Add/edit form mark optional fields !! <img width="593" alt="image" src="https://github.com/elastic/kibana/assets/3505601/909155f4-4b8a-4444-a2ad-ac0770c56929">
- Loading branch information
Showing
13 changed files
with
149 additions
and
361 deletions.
There are no files selected for viewing
42 changes: 0 additions & 42 deletions
42
x-pack/plugins/observability/public/hooks/slo/use_fetch_index_pattern_fields.ts
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
70 changes: 70 additions & 0 deletions
70
x-pack/plugins/observability/public/pages/slo_edit/components/common/group_by_field.tsx
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,70 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { ALL_VALUE } from '@kbn/slo-schema'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { EuiCallOut, EuiIconTip } from '@elastic/eui'; | ||
import React from 'react'; | ||
import { DataView } from '@kbn/data-views-plugin/common'; | ||
import { useFormContext } from 'react-hook-form'; | ||
import { OptionalText } from './optional_text'; | ||
import { useFetchGroupByCardinality } from '../../../../hooks/slo/use_fetch_group_by_cardinality'; | ||
import { CreateSLOForm } from '../../types'; | ||
import { IndexFieldSelector } from './index_field_selector'; | ||
|
||
export function GroupByField({ dataView, isLoading }: { dataView?: DataView; isLoading: boolean }) { | ||
const { watch } = useFormContext<CreateSLOForm>(); | ||
|
||
const groupByFields = dataView?.fields?.filter((field) => field.aggregatable) ?? []; | ||
const index = watch('indicator.params.index'); | ||
const timestampField = watch('indicator.params.timestampField'); | ||
const groupByField = watch('groupBy'); | ||
|
||
const { isLoading: isGroupByCardinalityLoading, data: groupByCardinality } = | ||
useFetchGroupByCardinality(index, timestampField, groupByField); | ||
|
||
return ( | ||
<> | ||
<IndexFieldSelector | ||
indexFields={groupByFields} | ||
name="groupBy" | ||
defaultValue={ALL_VALUE} | ||
label={ | ||
<span> | ||
{i18n.translate('xpack.observability.slo.sloEdit.groupBy.label', { | ||
defaultMessage: 'Group by', | ||
})}{' '} | ||
<EuiIconTip | ||
content={i18n.translate('xpack.observability.slo.sloEdit.groupBy.tooltip', { | ||
defaultMessage: 'Create individual SLOs for each value of the selected field.', | ||
})} | ||
position="top" | ||
/> | ||
</span> | ||
} | ||
labelAppend={<OptionalText />} | ||
placeholder={i18n.translate('xpack.observability.slo.sloEdit.groupBy.placeholder', { | ||
defaultMessage: 'Select an optional field to group by', | ||
})} | ||
isLoading={!!index && isLoading} | ||
isDisabled={!index} | ||
/> | ||
{!isGroupByCardinalityLoading && !!groupByCardinality && ( | ||
<EuiCallOut | ||
size="s" | ||
iconType={groupByCardinality.isHighCardinality ? 'warning' : ''} | ||
color={groupByCardinality.isHighCardinality ? 'warning' : 'primary'} | ||
title={i18n.translate('xpack.observability.slo.sloEdit.groupBy.cardinalityInfo', { | ||
defaultMessage: | ||
"Selected group by field '{groupBy}' will generate at least {card} SLO instances based on the last 24h sample data.", | ||
values: { card: groupByCardinality.cardinality, groupBy: groupByField }, | ||
})} | ||
/> | ||
)} | ||
</> | ||
); | ||
} |
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
20 changes: 20 additions & 0 deletions
20
x-pack/plugins/observability/public/pages/slo_edit/components/common/optional_text.tsx
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,20 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { EuiText } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import React from 'react'; | ||
|
||
export function OptionalText() { | ||
return ( | ||
<EuiText size="xs" color="subdued"> | ||
{i18n.translate('xpack.observability.slo.sloEdit.optionalLabel', { | ||
defaultMessage: 'Optional', | ||
})} | ||
</EuiText> | ||
); | ||
} |
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.