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.
[8.x] fix(slo): timestamp field was allowing mutliple values (elastic…
…#194311) (elastic#194562) # Backport This will backport the following commits from `main` to `8.x`: - [fix(slo): timestamp field was allowing mutliple values (elastic#194311)](elastic#194311) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Kevin Delemme","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-01T12:22:24Z","message":"fix(slo): timestamp field was allowing mutliple values (elastic#194311)","sha":"c4e2a7256b76cc94c08f34bb6dc3faeff58777f1","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","v9.0.0","backport:prev-major","ci:project-deploy-observability","Team:obs-ux-management","v8.16.0"],"title":"fix(slo): timestamp field was allowing mutliple values","number":194311,"url":"https://github.com/elastic/kibana/pull/194311","mergeCommit":{"message":"fix(slo): timestamp field was allowing mutliple values (elastic#194311)","sha":"c4e2a7256b76cc94c08f34bb6dc3faeff58777f1"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/194311","number":194311,"mergeCommit":{"message":"fix(slo): timestamp field was allowing mutliple values (elastic#194311)","sha":"c4e2a7256b76cc94c08f34bb6dc3faeff58777f1"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Kevin Delemme <[email protected]>
- Loading branch information
1 parent
e032b89
commit 6bcd396
Showing
4 changed files
with
124 additions
and
71 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
79 changes: 79 additions & 0 deletions
79
...ability_solution/slo/public/pages/slo_edit/components/common/timestamp_field_selector.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,79 @@ | ||
/* | ||
* 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 { EuiComboBox, EuiComboBoxOptionOption, EuiFormRow } from '@elastic/eui'; | ||
import { FieldSpec } from '@kbn/data-views-plugin/common'; | ||
import { i18n } from '@kbn/i18n'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { Controller, useFormContext } from 'react-hook-form'; | ||
import { Option, createOptionsFromFields } from '../../helpers/create_options'; | ||
import { CreateSLOForm } from '../../types'; | ||
|
||
interface Props { | ||
fields: FieldSpec[]; | ||
isDisabled: boolean; | ||
isLoading: boolean; | ||
} | ||
|
||
const placeholder = i18n.translate('xpack.slo.sloEdit.timestampField.placeholder', { | ||
defaultMessage: 'Select a timestamp field', | ||
}); | ||
|
||
export function TimestampFieldSelector({ fields, isDisabled, isLoading }: Props) { | ||
const { control, getFieldState } = useFormContext<CreateSLOForm>(); | ||
const [options, setOptions] = useState<Option[]>(createOptionsFromFields(fields)); | ||
|
||
useEffect(() => { | ||
setOptions(createOptionsFromFields(fields)); | ||
}, [fields]); | ||
|
||
return ( | ||
<EuiFormRow | ||
label={i18n.translate('xpack.slo.sloEdit.timestampField.label', { | ||
defaultMessage: 'Timestamp field', | ||
})} | ||
isInvalid={getFieldState('indicator.params.timestampField').invalid} | ||
> | ||
<Controller | ||
name={'indicator.params.timestampField'} | ||
control={control} | ||
rules={{ required: !isDisabled }} | ||
render={({ field, fieldState }) => { | ||
return ( | ||
<EuiComboBox<string> | ||
{...field} | ||
async | ||
placeholder={placeholder} | ||
aria-label={placeholder} | ||
isClearable | ||
isDisabled={isLoading || isDisabled} | ||
isInvalid={fieldState.invalid} | ||
isLoading={isLoading} | ||
onChange={(selected: EuiComboBoxOptionOption[]) => { | ||
if (selected.length) { | ||
return field.onChange(selected[0].value); | ||
} | ||
|
||
field.onChange(''); | ||
}} | ||
singleSelection={{ asPlainText: true }} | ||
options={options} | ||
onSearchChange={(searchValue: string) => { | ||
setOptions( | ||
createOptionsFromFields(fields, ({ value }) => value.includes(searchValue)) | ||
); | ||
}} | ||
selectedOptions={ | ||
!!fields && !!field.value ? [{ value: field.value, label: field.value }] : [] | ||
} | ||
/> | ||
); | ||
}} | ||
/> | ||
</EuiFormRow> | ||
); | ||
} |
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