mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Synthetics] Monitor form validate inline script (#155185)
## Summary Fixes https://github.com/elastic/kibana/issues/149299 Added inline script basic validation !! Also adjusted Test Now button to be more user friendly !! <img width="1353" alt="image" src="https://user-images.githubusercontent.com/3505601/232848294-4d6fed01-8fb3-4b3c-a3da-dfbc58c1bbd6.png"> --------- Co-authored-by: Justin Kambic <jk@elastic.co>
This commit is contained in:
parent
14f01672c7
commit
54f9f11339
2 changed files with 25 additions and 7 deletions
|
@ -895,7 +895,27 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({
|
|||
isEditFlow: isEdit,
|
||||
}),
|
||||
validation: () => ({
|
||||
validate: (value) => Boolean(value.script),
|
||||
validate: (value) => {
|
||||
// return false if script contains import or require statement
|
||||
if (
|
||||
value.script?.includes('import ') ||
|
||||
value.script?.includes('require(') ||
|
||||
value.script?.includes('journey(')
|
||||
) {
|
||||
return i18n.translate('xpack.synthetics.monitorConfig.monitorScript.invalid', {
|
||||
defaultMessage:
|
||||
'Monitor script is invalid. Inline scripts cannot be full journey scripts, they may only contain step definitions.',
|
||||
});
|
||||
}
|
||||
// should contain at least one step
|
||||
if (value.script && !value.script?.includes('step(')) {
|
||||
return i18n.translate('xpack.synthetics.monitorConfig.monitorScript.invalid.oneStep', {
|
||||
defaultMessage:
|
||||
'Monitor script is invalid. Inline scripts must contain at least one step definition.',
|
||||
});
|
||||
}
|
||||
return Boolean(value.script);
|
||||
},
|
||||
}),
|
||||
error: i18n.translate('xpack.synthetics.monitorConfig.monitorScript.error', {
|
||||
defaultMessage: 'Monitor script is required',
|
||||
|
|
|
@ -20,14 +20,14 @@ import {
|
|||
import { runOnceMonitor } from '../../../state/manual_test_runs/api';
|
||||
|
||||
export const RunTestButton = () => {
|
||||
const { watch, formState, getValues } = useFormContext();
|
||||
const { watch, formState, getValues, handleSubmit } = useFormContext();
|
||||
|
||||
const [inProgress, setInProgress] = useState(false);
|
||||
const [testRun, setTestRun] = useState<TestRun>();
|
||||
|
||||
const handleTestNow = () => {
|
||||
const config = getValues() as MonitorFieldsType;
|
||||
if (config) {
|
||||
if (config && !Object.keys(formState.errors).length) {
|
||||
setInProgress(true);
|
||||
setTestRun({
|
||||
id: uuidv4(),
|
||||
|
@ -68,9 +68,7 @@ export const RunTestButton = () => {
|
|||
disabled={isDisabled}
|
||||
aria-label={TEST_NOW_ARIA_LABEL}
|
||||
iconType="play"
|
||||
onClick={() => {
|
||||
handleTestNow();
|
||||
}}
|
||||
onClick={handleSubmit(handleTestNow)}
|
||||
>
|
||||
{RUN_TEST}
|
||||
</EuiButton>
|
||||
|
@ -111,7 +109,7 @@ const useTooltipContent = (
|
|||
|
||||
tooltipContent = isTestRunInProgress ? TEST_SCHEDULED_LABEL : tooltipContent;
|
||||
|
||||
const isDisabled = !isValid || isTestRunInProgress || !isAnyPublicLocationSelected;
|
||||
const isDisabled = isTestRunInProgress || !isAnyPublicLocationSelected;
|
||||
|
||||
return { tooltipContent, isDisabled };
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue