-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SLO] Improve equivalent API View (#173503)
## Summary Instead of copy JSON button, show JSON in flyout with option to copy as well <img width="1728" alt="image" src="https://github.com/elastic/kibana/assets/3505601/bab00b6c-9b50-470b-9c4d-bbb6f4a31a08">
- Loading branch information
Showing
6 changed files
with
133 additions
and
74 deletions.
There are no files selected for viewing
128 changes: 128 additions & 0 deletions
128
.../plugins/observability/public/pages/slo_edit/components/common/equivalent_api_request.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,128 @@ | ||
/* | ||
* 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 { i18n } from '@kbn/i18n'; | ||
|
||
import React, { useEffect, useState } from 'react'; | ||
import { | ||
EuiButtonEmpty, | ||
EuiCodeBlock, | ||
EuiFlyout, | ||
EuiFlyoutBody, | ||
EuiFlyoutFooter, | ||
EuiFlyoutHeader, | ||
EuiSpacer, | ||
EuiText, | ||
EuiTitle, | ||
} from '@elastic/eui'; | ||
import { useFormContext } from 'react-hook-form'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
import { CreateSLOInput } from '@kbn/slo-schema'; | ||
import { CreateSLOForm } from '../../types'; | ||
import { transformCreateSLOFormToCreateSLOInput } from '../../helpers/process_slo_form_values'; | ||
|
||
export function EquivalentApiRequest({ | ||
isCreateSloLoading, | ||
isUpdateSloLoading, | ||
}: { | ||
isCreateSloLoading: boolean; | ||
isUpdateSloLoading: boolean; | ||
}) { | ||
const [isFlyoutVisible, setIsFlyoutVisible] = useState(false); | ||
|
||
const { getValues, trigger } = useFormContext<CreateSLOForm>(); | ||
|
||
const [sloData, setSloData] = useState<CreateSLOInput>(); | ||
|
||
useEffect(() => { | ||
if (!isFlyoutVisible) { | ||
return; | ||
} | ||
trigger().then((isValid) => { | ||
if (isValid) { | ||
setSloData(transformCreateSLOFormToCreateSLOInput(getValues())); | ||
} | ||
}); | ||
}, [getValues, trigger, isFlyoutVisible]); | ||
|
||
let flyout; | ||
|
||
if (isFlyoutVisible) { | ||
flyout = ( | ||
<EuiFlyout ownFocus onClose={() => setIsFlyoutVisible(false)}> | ||
<EuiFlyoutHeader hasBorder> | ||
<EuiTitle size="m"> | ||
<h2> | ||
{i18n.translate( | ||
'xpack.observability.equivalentApiRequest.h2.equivalentAPIRequestToLabel', | ||
{ defaultMessage: 'Equivalent API request' } | ||
)} | ||
</h2> | ||
</EuiTitle> | ||
</EuiFlyoutHeader> | ||
<EuiFlyoutBody> | ||
<EuiText> | ||
<FormattedMessage | ||
id="xpack.observability.equivalentApiRequest.p.useTheRESTAPILabel" | ||
defaultMessage="Use the REST API" | ||
/> | ||
</EuiText> | ||
<EuiSpacer size="s" /> | ||
<EuiCodeBlock language="javascript" isCopyable paddingSize="s"> | ||
{'POST /api/observability/slos'} | ||
</EuiCodeBlock> | ||
<EuiSpacer size="s" /> | ||
<EuiText> | ||
<FormattedMessage | ||
id="xpack.observability.equivalentApiRequest.p.withTheFollowingBodyLabel" | ||
defaultMessage="with the following body:" | ||
/> | ||
</EuiText> | ||
{sloData ? ( | ||
<EuiCodeBlock language="json" isCopyable paddingSize="s"> | ||
{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> | ||
<EuiFlyoutFooter> | ||
<EuiButtonEmpty | ||
data-test-subj="o11yEquivalentApiRequestCloseButton" | ||
iconType="cross" | ||
onClick={() => setIsFlyoutVisible(false)} | ||
flush="left" | ||
> | ||
{i18n.translate('xpack.observability.equivalentApiRequest.closeButtonEmptyLabel', { | ||
defaultMessage: 'Close', | ||
})} | ||
</EuiButtonEmpty> | ||
</EuiFlyoutFooter> | ||
</EuiFlyout> | ||
); | ||
} | ||
return ( | ||
<> | ||
<EuiButtonEmpty | ||
color="primary" | ||
iconType="copyClipboard" | ||
data-test-subj="sloFormCopyJsonButton" | ||
disabled={isCreateSloLoading || isUpdateSloLoading} | ||
onClick={() => setIsFlyoutVisible(true)} | ||
> | ||
{i18n.translate('xpack.observability.slo.sloEdit.equivalentApiRequest', { | ||
defaultMessage: 'Equivalent API request', | ||
})} | ||
</EuiButtonEmpty> | ||
{flyout} | ||
</> | ||
); | ||
} |
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
52 changes: 0 additions & 52 deletions
52
x-pack/plugins/observability/public/pages/slo_edit/hooks/use_copy_to_json.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
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