From 52ca1a87bc0f7bff7b58714f127a2c389fb46618 Mon Sep 17 00:00:00 2001 From: Justin Kambic Date: Tue, 28 Mar 2023 10:59:43 -0400 Subject: [PATCH] [Synthetics/Alerting] Add a param flag to hide the interval controls from edit form (#152607) ## Summary Fixes #152430. We need to be able to hide from the UI the capability of the user to edit the interval for our rule in the edit form. To achieve this, I've simply added a flag to the rule's `params` field, and picked that flag up on the form to hide the elements in question. Shouldn't have any impact elsewhere for users of this form. If there's a better method of achieving this please let me know and I'll revise. --- .../default_status_alert.journey.ts | 4 +- .../alerts/hooks/use_synthetics_alert.ts | 1 + .../sections/rule_form/rule_add.tsx | 2 + .../sections/rule_form/rule_form.tsx | 92 ++++++++++--------- .../triggers_actions_ui/public/types.ts | 2 + 5 files changed, 55 insertions(+), 46 deletions(-) diff --git a/x-pack/plugins/synthetics/e2e/journeys/synthetics/alert_rules/default_status_alert.journey.ts b/x-pack/plugins/synthetics/e2e/journeys/synthetics/alert_rules/default_status_alert.journey.ts index 666366b9555e4..ae8ffeed83431 100644 --- a/x-pack/plugins/synthetics/e2e/journeys/synthetics/alert_rules/default_status_alert.journey.ts +++ b/x-pack/plugins/synthetics/e2e/journeys/synthetics/alert_rules/default_status_alert.journey.ts @@ -58,8 +58,6 @@ journey(`DefaultStatusAlert`, async ({ page, params }) => { await page.isDisabled(byTestId('xpack.synthetics.toggleAlertFlyout')); await page.click(byTestId('xpack.synthetics.toggleAlertFlyout')); await page.waitForSelector('text=Edit rule'); - await page.selectOption(byTestId('intervalInputUnit'), { label: 'second' }); - await page.fill(byTestId('intervalInput'), '20'); await page.click(byTestId('saveEditedRuleButton')); await page.waitForSelector("text=Updated 'Synthetics internal alert'"); }); @@ -94,6 +92,8 @@ journey(`DefaultStatusAlert`, async ({ page, params }) => { await page.click(byTestId('syntheticsMonitorManagementTab')); await page.click(byTestId('syntheticsMonitorOverviewTab')); + await page.waitForTimeout(5 * 1000); + const totalDown = await page.textContent( byTestId('xpack.uptime.synthetics.overview.status.down') ); diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/alerts/hooks/use_synthetics_alert.ts b/x-pack/plugins/synthetics/public/apps/synthetics/components/alerts/hooks/use_synthetics_alert.ts index 3b1ec20345ae4..2f7dd459bc927 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/alerts/hooks/use_synthetics_alert.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/alerts/hooks/use_synthetics_alert.ts @@ -39,6 +39,7 @@ export const useSyntheticsAlert = (isOpen: boolean) => { } return triggersActionsUi.getEditRuleFlyout({ onClose: () => dispatch(setAlertFlyoutVisible(false)), + hideInterval: true, initialRule: alert, }); }, [alert, dispatch, triggersActionsUi]); diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/rule_form/rule_add.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/rule_form/rule_add.tsx index ec1f298b58ba0..d27abe0831441 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/rule_form/rule_add.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/rule_form/rule_add.tsx @@ -48,6 +48,7 @@ const RuleAdd = ({ initialValues, reloadRules, onSave, + hideInterval, metadata: initialMetadata, filteredRuleTypes, ...props @@ -264,6 +265,7 @@ const RuleAdd = ({ ruleTypeRegistry={ruleTypeRegistry} metadata={metadata} filteredRuleTypes={filteredRuleTypes} + hideInterval={hideInterval} onChangeMetaData={onChangeMetaData} /> diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/rule_form/rule_form.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/rule_form/rule_form.tsx index 40a8d7f5722e8..7105ab930beb4 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/rule_form/rule_form.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/rule_form/rule_form.tsx @@ -97,6 +97,7 @@ interface RuleFormProps> { setHasActionsWithBrokenConnector?: (value: boolean) => void; metadata?: MetaData; filteredRuleTypes?: string[]; + hideInterval?: boolean; connectorFeatureId?: string; onChangeMetaData: (metadata: MetaData) => void; } @@ -114,6 +115,7 @@ export const RuleForm = ({ actionTypeRegistry, metadata, filteredRuleTypes: ruleTypeToFilter, + hideInterval, connectorFeatureId = AlertingConnectorFeatureId, onChangeMetaData, }: RuleFormProps) => { @@ -582,50 +584,52 @@ export const RuleForm = ({ ) : null} - - 0} - error={errors['schedule.interval']} - > - - - 0} - value={ruleInterval || ''} - name="interval" - data-test-subj="intervalInput" - onChange={(e) => { - const value = e.target.value; - if (value === '' || INTEGER_REGEX.test(value)) { - const parsedValue = value === '' ? '' : parseInt(value, 10); - setRuleInterval(parsedValue || undefined); - setScheduleProperty('interval', `${parsedValue}${ruleIntervalUnit}`); - } - }} - /> - - - { - setRuleIntervalUnit(e.target.value); - setScheduleProperty('interval', `${ruleInterval}${e.target.value}`); - }} - data-test-subj="intervalInputUnit" - /> - - - - + {hideInterval !== true && ( + + 0} + error={errors['schedule.interval']} + > + + + 0} + value={ruleInterval || ''} + name="interval" + data-test-subj="intervalInput" + onChange={(e) => { + const value = e.target.value; + if (value === '' || INTEGER_REGEX.test(value)) { + const parsedValue = value === '' ? '' : parseInt(value, 10); + setRuleInterval(parsedValue || undefined); + setScheduleProperty('interval', `${parsedValue}${ruleIntervalUnit}`); + } + }} + /> + + + { + setRuleIntervalUnit(e.target.value); + setScheduleProperty('interval', `${ruleInterval}${e.target.value}`); + }} + data-test-subj="intervalInputUnit" + /> + + + + + )} {canShowActions && defaultActionGroupId && diff --git a/x-pack/plugins/triggers_actions_ui/public/types.ts b/x-pack/plugins/triggers_actions_ui/public/types.ts index 05cf37aecad84..763d96105a30a 100644 --- a/x-pack/plugins/triggers_actions_ui/public/types.ts +++ b/x-pack/plugins/triggers_actions_ui/public/types.ts @@ -408,6 +408,7 @@ export interface RuleEditProps> { onClose: (reason: RuleFlyoutCloseReason, metadata?: MetaData) => void; /** @deprecated use `onSave` as a callback after an alert is saved*/ reloadRules?: () => Promise; + hideInterval?: boolean; onSave?: (metadata?: MetaData) => Promise; metadata?: MetaData; ruleType?: RuleType; @@ -423,6 +424,7 @@ export interface RuleAddProps> { initialValues?: Partial; /** @deprecated use `onSave` as a callback after an alert is saved*/ reloadRules?: () => Promise; + hideInterval?: boolean; onSave?: (metadata?: MetaData) => Promise; metadata?: MetaData; ruleTypeIndex?: RuleTypeIndex;