From b5e7635f6ca3f33ff38650d058ad2a7d9f4c05bb Mon Sep 17 00:00:00 2001 From: Maxim Palenov Date: Fri, 6 Dec 2024 10:22:08 +0100 Subject: [PATCH] rename FormWithWarm to FormWithWarnings --- .../extract_validation_results.ts | 0 .../form_hook_with_warnings.ts} | 2 +- .../index.ts | 4 ++-- .../use_form_with_warnings.test.tsx} | 8 +++---- .../use_form_with_warnings.ts} | 22 +++++++++---------- .../validation_results.ts | 0 .../rule_creation_ui/pages/form.tsx | 10 ++++----- .../fields/rule_field_edit_form_wrapper.tsx | 8 +++---- 8 files changed, 27 insertions(+), 27 deletions(-) rename x-pack/plugins/security_solution/public/common/hooks/{use_form_with_warn => use_form_with_warnings}/extract_validation_results.ts (100%) rename x-pack/plugins/security_solution/public/common/hooks/{use_form_with_warn/form_hook_with_warn.ts => use_form_with_warnings/form_hook_with_warnings.ts} (81%) rename x-pack/plugins/security_solution/public/common/hooks/{use_form_with_warn => use_form_with_warnings}/index.ts (73%) rename x-pack/plugins/security_solution/public/common/hooks/{use_form_with_warn/use_form_with_warn.test.tsx => use_form_with_warnings/use_form_with_warnings.test.tsx} (96%) rename x-pack/plugins/security_solution/public/common/hooks/{use_form_with_warn/use_form_with_warn.ts => use_form_with_warnings/use_form_with_warnings.ts} (88%) rename x-pack/plugins/security_solution/public/common/hooks/{use_form_with_warn => use_form_with_warnings}/validation_results.ts (100%) diff --git a/x-pack/plugins/security_solution/public/common/hooks/use_form_with_warn/extract_validation_results.ts b/x-pack/plugins/security_solution/public/common/hooks/use_form_with_warnings/extract_validation_results.ts similarity index 100% rename from x-pack/plugins/security_solution/public/common/hooks/use_form_with_warn/extract_validation_results.ts rename to x-pack/plugins/security_solution/public/common/hooks/use_form_with_warnings/extract_validation_results.ts diff --git a/x-pack/plugins/security_solution/public/common/hooks/use_form_with_warn/form_hook_with_warn.ts b/x-pack/plugins/security_solution/public/common/hooks/use_form_with_warnings/form_hook_with_warnings.ts similarity index 81% rename from x-pack/plugins/security_solution/public/common/hooks/use_form_with_warn/form_hook_with_warn.ts rename to x-pack/plugins/security_solution/public/common/hooks/use_form_with_warnings/form_hook_with_warnings.ts index 3de8421528f74..eb823cd19d25d 100644 --- a/x-pack/plugins/security_solution/public/common/hooks/use_form_with_warn/form_hook_with_warn.ts +++ b/x-pack/plugins/security_solution/public/common/hooks/use_form_with_warnings/form_hook_with_warnings.ts @@ -7,7 +7,7 @@ import type { FormHook, FormData, ValidationError } from '../../../shared_imports'; -export interface FormHookWithWarn +export interface FormHookWithWarnings extends FormHook { getValidationWarnings(): ValidationError[]; } diff --git a/x-pack/plugins/security_solution/public/common/hooks/use_form_with_warn/index.ts b/x-pack/plugins/security_solution/public/common/hooks/use_form_with_warnings/index.ts similarity index 73% rename from x-pack/plugins/security_solution/public/common/hooks/use_form_with_warn/index.ts rename to x-pack/plugins/security_solution/public/common/hooks/use_form_with_warnings/index.ts index 5d6d54ed44462..29e5c064b1a7a 100644 --- a/x-pack/plugins/security_solution/public/common/hooks/use_form_with_warn/index.ts +++ b/x-pack/plugins/security_solution/public/common/hooks/use_form_with_warnings/index.ts @@ -5,5 +5,5 @@ * 2.0. */ -export type * from './form_hook_with_warn'; -export * from './use_form_with_warn'; +export type * from './form_hook_with_warnings'; +export * from './use_form_with_warnings'; diff --git a/x-pack/plugins/security_solution/public/common/hooks/use_form_with_warn/use_form_with_warn.test.tsx b/x-pack/plugins/security_solution/public/common/hooks/use_form_with_warnings/use_form_with_warnings.test.tsx similarity index 96% rename from x-pack/plugins/security_solution/public/common/hooks/use_form_with_warn/use_form_with_warn.test.tsx rename to x-pack/plugins/security_solution/public/common/hooks/use_form_with_warnings/use_form_with_warnings.test.tsx index 08072b64a1ee3..c9c9a939458e2 100644 --- a/x-pack/plugins/security_solution/public/common/hooks/use_form_with_warn/use_form_with_warn.test.tsx +++ b/x-pack/plugins/security_solution/public/common/hooks/use_form_with_warnings/use_form_with_warnings.test.tsx @@ -10,8 +10,8 @@ import { act, fireEvent, render, screen, waitFor } from '@testing-library/react' import { TextField } from '@kbn/es-ui-shared-plugin/static/forms/components'; import type { FieldConfig } from '../../../shared_imports'; import { Form, UseField } from '../../../shared_imports'; -import type { FormWithWarnSubmitHandler } from './use_form_with_warn'; -import { useFormWithWarn } from './use_form_with_warn'; +import type { FormWithWarningsSubmitHandler } from './use_form_with_warnings'; +import { useFormWithWarnings } from './use_form_with_warnings'; describe('useFormWithWarn', () => { describe('isValid', () => { @@ -174,12 +174,12 @@ describe('useFormWithWarn', () => { }); interface TestFormProps { - onSubmit?: FormWithWarnSubmitHandler; + onSubmit?: FormWithWarningsSubmitHandler; warningValidationCodes: string[]; } function TestForm({ onSubmit, warningValidationCodes }: TestFormProps): JSX.Element { - const { form } = useFormWithWarn({ + const { form } = useFormWithWarnings({ onSubmit, options: { warningValidationCodes, diff --git a/x-pack/plugins/security_solution/public/common/hooks/use_form_with_warn/use_form_with_warn.ts b/x-pack/plugins/security_solution/public/common/hooks/use_form_with_warnings/use_form_with_warnings.ts similarity index 88% rename from x-pack/plugins/security_solution/public/common/hooks/use_form_with_warn/use_form_with_warn.ts rename to x-pack/plugins/security_solution/public/common/hooks/use_form_with_warnings/use_form_with_warnings.ts index 5feb43fd52127..191ba82f0943c 100644 --- a/x-pack/plugins/security_solution/public/common/hooks/use_form_with_warn/use_form_with_warn.ts +++ b/x-pack/plugins/security_solution/public/common/hooks/use_form_with_warnings/use_form_with_warnings.ts @@ -9,26 +9,26 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import { isEmpty } from 'lodash'; import type { FormHook } from '../../../shared_imports'; import { useForm, type FormConfig, type FormData } from '../../../shared_imports'; -import type { FormHookWithWarn } from './form_hook_with_warn'; +import type { FormHookWithWarnings } from './form_hook_with_warnings'; import { extractValidationResults } from './extract_validation_results'; import type { ValidationResults } from './validation_results'; -export type FormWithWarnSubmitHandler = ( +export type FormWithWarningsSubmitHandler = ( formData: T, isValid: boolean, validationResults: ValidationResults ) => Promise; -interface FormWithWarnConfig +interface FormWithWarningsConfig extends Omit, 'onSubmit'> { - onSubmit?: FormWithWarnSubmitHandler; + onSubmit?: FormWithWarningsSubmitHandler; options: FormConfig['options'] & { warningValidationCodes: Readonly; }; } -interface UseFormWithWarnReturn { - form: FormHookWithWarn; +interface UseFormWithWarningsReturn { + form: FormHookWithWarnings; } /** @@ -49,7 +49,7 @@ interface UseFormWithWarnReturn( - formConfig: FormWithWarnConfig -): UseFormWithWarnReturn { +export function useFormWithWarnings( + formConfig: FormWithWarningsConfig +): UseFormWithWarningsReturn { const { onSubmit, options: { warningValidationCodes }, diff --git a/x-pack/plugins/security_solution/public/common/hooks/use_form_with_warn/validation_results.ts b/x-pack/plugins/security_solution/public/common/hooks/use_form_with_warnings/validation_results.ts similarity index 100% rename from x-pack/plugins/security_solution/public/common/hooks/use_form_with_warn/validation_results.ts rename to x-pack/plugins/security_solution/public/common/hooks/use_form_with_warnings/validation_results.ts diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_creation_ui/pages/form.tsx b/x-pack/plugins/security_solution/public/detection_engine/rule_creation_ui/pages/form.tsx index 17211f447800f..ad4d37045ba70 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_creation_ui/pages/form.tsx +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_creation_ui/pages/form.tsx @@ -7,7 +7,7 @@ import { useState, useMemo, useEffect } from 'react'; import type { DataViewBase } from '@kbn/es-query'; -import { useFormWithWarn } from '../../../common/hooks/use_form_with_warn'; +import { useFormWithWarnings } from '../../../common/hooks/use_form_with_warnings'; import { isThreatMatchRule } from '../../../../common/detection_engine/utils'; import type { AboutStepRule, @@ -46,7 +46,7 @@ export const useRuleForms = ({ triggersActionsUi: { actionTypeRegistry }, } = useKibana().services; // DEFINE STEP FORM - const { form: defineStepForm } = useFormWithWarn({ + const { form: defineStepForm } = useFormWithWarnings({ defaultValue: defineStepDefault, options: { stripEmptyFields: false, warningValidationCodes: NON_BLOCKING_ERROR_CODES }, schema: defineRuleSchema, @@ -66,7 +66,7 @@ export const useRuleForms = ({ () => (isThreatMatchRule(defineStepData.ruleType) ? threatMatchAboutSchema : aboutRuleSchema), [defineStepData.ruleType] ); - const { form: aboutStepForm } = useFormWithWarn({ + const { form: aboutStepForm } = useFormWithWarnings({ defaultValue: aboutStepDefault, options: { stripEmptyFields: false, warningValidationCodes: NON_BLOCKING_ERROR_CODES }, schema: typeDependentAboutRuleSchema, @@ -77,7 +77,7 @@ export const useRuleForms = ({ const aboutStepData = 'name' in aboutStepFormData ? aboutStepFormData : aboutStepDefault; // SCHEDULE STEP FORM - const { form: scheduleStepForm } = useFormWithWarn({ + const { form: scheduleStepForm } = useFormWithWarnings({ defaultValue: scheduleStepDefault, options: { stripEmptyFields: false, warningValidationCodes: NON_BLOCKING_ERROR_CODES }, schema: scheduleRuleSchema, @@ -90,7 +90,7 @@ export const useRuleForms = ({ // ACTIONS STEP FORM const schema = useMemo(() => getActionsRuleSchema({ actionTypeRegistry }), [actionTypeRegistry]); - const { form: actionsStepForm } = useFormWithWarn({ + const { form: actionsStepForm } = useFormWithWarnings({ defaultValue: actionsStepDefault, options: { stripEmptyFields: false, warningValidationCodes: NON_BLOCKING_ERROR_CODES }, schema, diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_details/three_way_diff/final_edit/fields/rule_field_edit_form_wrapper.tsx b/x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_details/three_way_diff/final_edit/fields/rule_field_edit_form_wrapper.tsx index 10cc816e93904..136a357832562 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_details/three_way_diff/final_edit/fields/rule_field_edit_form_wrapper.tsx +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_details/three_way_diff/final_edit/fields/rule_field_edit_form_wrapper.tsx @@ -8,8 +8,8 @@ import React, { useCallback, useEffect } from 'react'; import { EuiButtonEmpty, EuiFlexGroup } from '@elastic/eui'; import { extractValidationMessages } from '../../../../../../rule_creation/logic/extract_validation_messages'; -import type { FormWithWarnSubmitHandler } from '../../../../../../../common/hooks/use_form_with_warn'; -import { useFormWithWarn } from '../../../../../../../common/hooks/use_form_with_warn'; +import type { FormWithWarningsSubmitHandler } from '../../../../../../../common/hooks/use_form_with_warnings'; +import { useFormWithWarnings } from '../../../../../../../common/hooks/use_form_with_warnings'; import { Form } from '../../../../../../../shared_imports'; import type { FormSchema, FormData } from '../../../../../../../shared_imports'; import type { @@ -66,7 +66,7 @@ export function RuleFieldEditFormWrapper({ const { modal, confirmValidationErrors } = useConfirmValidationErrorsModal(); - const handleSubmit = useCallback( + const handleSubmit = useCallback( async (formData: FormData, isValid: boolean, { warnings }) => { const warningMessages = extractValidationMessages(warnings, ERROR_CODE_FIELD_NAME_MAP); @@ -90,7 +90,7 @@ export function RuleFieldEditFormWrapper({ ] ); - const { form } = useFormWithWarn({ + const { form } = useFormWithWarnings({ schema: ruleFieldFormSchema, defaultValue: getDefaultValue(fieldName, finalDiffableRule), deserializer: deserialize,