Skip to content

Commit

Permalink
[SLO] Form, Mark fields required only when not disabled (#171876)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 authored Dec 4, 2023
1 parent 9676f89 commit e0a0168
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export function FieldSelector({
: []
).concat(createOptions(suggestions));

const isDisabled = name !== 'indicator.params.service' && !serviceName;

return (
<EuiFlexItem>
<EuiFormRow
Expand All @@ -83,15 +85,15 @@ export function FieldSelector({
defaultValue=""
name={name}
control={control}
rules={{ required: true }}
rules={{ required: !isDisabled }}
render={({ field, fieldState }) => (
<EuiComboBox
{...field}
aria-label={placeholder}
async
data-test-subj={dataTestSubj}
isClearable
isDisabled={name !== 'indicator.params.service' && !serviceName}
isDisabled={isDisabled}
isInvalid={fieldState.invalid}
isLoading={isLoading}
onChange={(selected: EuiComboBoxOptionOption[]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function IndexFieldSelector({
defaultValue={defaultValue}
name={name}
control={control}
rules={{ required: isRequired }}
rules={{ required: isRequired && !isDisabled }}
render={({ field, fieldState }) => (
<EuiComboBox<string>
{...field}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,20 @@ export function CustomKqlIndicatorTypeForm() {
<IndexSelection />
</EuiFlexItem>

<EuiFlexItem>
<IndexFieldSelector
indexFields={timestampFields}
name="indicator.params.timestampField"
label={i18n.translate('xpack.observability.slo.sloEdit.timestampField.label', {
defaultMessage: 'Timestamp field',
})}
placeholder={i18n.translate(
'xpack.observability.slo.sloEdit.timestampField.placeholder',
{ defaultMessage: 'Select a timestamp field' }
)}
isLoading={!!index && isIndexFieldsLoading}
isDisabled={!index}
isRequired
/>
</EuiFlexItem>
<IndexFieldSelector
indexFields={timestampFields}
name="indicator.params.timestampField"
label={i18n.translate('xpack.observability.slo.sloEdit.timestampField.label', {
defaultMessage: 'Timestamp field',
})}
placeholder={i18n.translate(
'xpack.observability.slo.sloEdit.timestampField.placeholder',
{ defaultMessage: 'Select a timestamp field' }
)}
isLoading={!!index && isIndexFieldsLoading}
isDisabled={!index}
isRequired
/>
</EuiFlexGroup>

<EuiFlexItem>
Expand Down

0 comments on commit e0a0168

Please sign in to comment.