Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 committed Dec 19, 2023
1 parent 6334ac6 commit 519fce9
Showing 1 changed file with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import { i18n } from '@kbn/i18n';

import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';
import {
EuiButtonEmpty,
EuiCodeBlock,
Expand All @@ -19,8 +19,8 @@ import {
EuiTitle,
} from '@elastic/eui';
import { useFormContext } from 'react-hook-form';
import { useFetcher } from '@kbn/observability-shared-plugin/public';
import { FormattedMessage } from '@kbn/i18n-react';
import { CreateSLOInput } from '@kbn/slo-schema';
import { CreateSLOForm } from '../../types';
import { transformCreateSLOFormToCreateSLOInput } from '../../helpers/process_slo_form_values';

Expand All @@ -35,15 +35,17 @@ export function EquivalentApiRequest({

const { getValues, trigger } = useFormContext<CreateSLOForm>();

const { data } = useFetcher(async () => {
const [sloData, setSloData] = useState<CreateSLOInput>();

useEffect(() => {
if (!isFlyoutVisible) {
return;
}
const isValid = await trigger();
if (!isValid) {
return;
}
return transformCreateSLOFormToCreateSLOInput(getValues());
trigger().then((isValid) => {
if (isValid) {
setSloData(transformCreateSLOFormToCreateSLOInput(getValues()));
}
});
}, [getValues, trigger, isFlyoutVisible]);

let flyout;
Expand Down Expand Up @@ -79,9 +81,16 @@ export function EquivalentApiRequest({
defaultMessage="with the following body:"
/>
</EuiText>
{data && (
{sloData ? (
<EuiCodeBlock language="json" isCopyable paddingSize="s">
{JSON.stringify(data, null, 2)}
{JSON.stringify(sloData, null, 2)}
</EuiCodeBlock>
) : (
<EuiCodeBlock language="javascript" isCopyable paddingSize="s">
{i18n.translate(
'xpack.observability.equivalentApiRequest.formIsNotValidCodeBlockLabel',
{ defaultMessage: 'Form is not valid' }
)}
</EuiCodeBlock>
)}
</EuiFlyoutBody>
Expand Down

0 comments on commit 519fce9

Please sign in to comment.