Skip to content

Commit

Permalink
rename non blocking error codes to warning codes
Browse files Browse the repository at this point in the history
  • Loading branch information
maximpn committed Dec 6, 2024
1 parent b5e7635 commit c3e5c91
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ const EQL_FIELD_NAME = i18n.translate(
}
);

export const NON_BLOCKING_ERROR_CODES = [
export const VALIDATION_WARNING_CODES = [
ESQL_ERROR_CODES.INVALID_ESQL,
EQL_ERROR_CODES.FAILED_REQUEST,
EQL_ERROR_CODES.INVALID_EQL,
EQL_ERROR_CODES.MISSING_DATA_SOURCE,
] as const;

export const ERROR_CODE_FIELD_NAME_MAP: Readonly<Record<string, string>> = {
export const VALIDATION_WARNING_CODE_FIELD_NAME_MAP: Readonly<Record<string, string>> = {
[ESQL_ERROR_CODES.INVALID_ESQL]: ESQL_FIELD_NAME,
[EQL_ERROR_CODES.FAILED_REQUEST]: EQL_FIELD_NAME,
[EQL_ERROR_CODES.INVALID_EQL]: EQL_FIELD_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
import { schema as scheduleRuleSchema } from '../components/step_schedule_rule/schema';
import { getSchema as getActionsRuleSchema } from '../../rule_creation/components/step_rule_actions/get_schema';
import { useFetchIndex } from '../../../common/containers/source';
import { NON_BLOCKING_ERROR_CODES } from '../../rule_creation/constants/non_blocking_error_codes';
import { VALIDATION_WARNING_CODES } from '../../rule_creation/constants/validation_warning_codes';

export interface UseRuleFormsProps {
defineStepDefault: DefineStepRule;
Expand All @@ -48,7 +48,7 @@ export const useRuleForms = ({
// DEFINE STEP FORM
const { form: defineStepForm } = useFormWithWarnings<DefineStepRule>({
defaultValue: defineStepDefault,
options: { stripEmptyFields: false, warningValidationCodes: NON_BLOCKING_ERROR_CODES },
options: { stripEmptyFields: false, warningValidationCodes: VALIDATION_WARNING_CODES },
schema: defineRuleSchema,
});
const [defineStepFormData] = useFormData<DefineStepRule | {}>({
Expand All @@ -68,7 +68,7 @@ export const useRuleForms = ({
);
const { form: aboutStepForm } = useFormWithWarnings<AboutStepRule>({
defaultValue: aboutStepDefault,
options: { stripEmptyFields: false, warningValidationCodes: NON_BLOCKING_ERROR_CODES },
options: { stripEmptyFields: false, warningValidationCodes: VALIDATION_WARNING_CODES },
schema: typeDependentAboutRuleSchema,
});
const [aboutStepFormData] = useFormData<AboutStepRule | {}>({
Expand All @@ -79,7 +79,7 @@ export const useRuleForms = ({
// SCHEDULE STEP FORM
const { form: scheduleStepForm } = useFormWithWarnings<ScheduleStepRule>({
defaultValue: scheduleStepDefault,
options: { stripEmptyFields: false, warningValidationCodes: NON_BLOCKING_ERROR_CODES },
options: { stripEmptyFields: false, warningValidationCodes: VALIDATION_WARNING_CODES },
schema: scheduleRuleSchema,
});
const [scheduleStepFormData] = useFormData<ScheduleStepRule | {}>({
Expand All @@ -92,7 +92,7 @@ export const useRuleForms = ({
const schema = useMemo(() => getActionsRuleSchema({ actionTypeRegistry }), [actionTypeRegistry]);
const { form: actionsStepForm } = useFormWithWarnings<ActionsStepRule>({
defaultValue: actionsStepDefault,
options: { stripEmptyFields: false, warningValidationCodes: NON_BLOCKING_ERROR_CODES },
options: { stripEmptyFields: false, warningValidationCodes: VALIDATION_WARNING_CODES },
schema,
});
const [actionsStepFormData] = useFormData<ActionsStepRule | {}>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ import { useKibana, useUiSetting$ } from '../../../../common/lib/kibana';
import { RulePreview } from '../../components/rule_preview';
import { getIsRulePreviewDisabled } from '../../components/rule_preview/helpers';
import { useStartMlJobs } from '../../../rule_management/logic/use_start_ml_jobs';
import { ERROR_CODE_FIELD_NAME_MAP } from '../../../rule_creation/constants/non_blocking_error_codes';
import { VALIDATION_WARNING_CODE_FIELD_NAME_MAP } from '../../../rule_creation/constants/validation_warning_codes';
import { extractValidationMessages } from '../../../rule_creation/logic/extract_validation_messages';
import { NextStep } from '../../components/next_step';
import { useRuleForms, useRuleIndexPattern } from '../form';
Expand Down Expand Up @@ -442,7 +442,10 @@ const CreateRulePageComponent: React.FC = () => {
const submitRule = useCallback(
async (enabled: boolean) => {
const { valid, warnings } = await validateAllSteps();
const warningMessages = extractValidationMessages(warnings, ERROR_CODE_FIELD_NAME_MAP);
const warningMessages = extractValidationMessages(
warnings,
VALIDATION_WARNING_CODE_FIELD_NAME_MAP
);

if (!valid || !(await confirmValidationErrors(warningMessages))) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ import { useStartTransaction } from '../../../../common/lib/apm/use_start_transa
import { SINGLE_RULE_ACTIONS } from '../../../../common/lib/apm/user_actions';
import { useGetSavedQuery } from '../../../../detections/pages/detection_engine/rules/use_get_saved_query';
import { extractValidationMessages } from '../../../rule_creation/logic/extract_validation_messages';
import { ERROR_CODE_FIELD_NAME_MAP } from '../../../rule_creation/constants/non_blocking_error_codes';
import { VALIDATION_WARNING_CODE_FIELD_NAME_MAP } from '../../../rule_creation/constants/validation_warning_codes';
import { useRuleForms, useRuleIndexPattern } from '../form';
import { useEsqlIndex, useEsqlQueryForAboutStep } from '../../hooks';
import { CustomHeaderPageMemo } from '..';
Expand Down Expand Up @@ -448,7 +448,7 @@ const EditRulePageComponent: FC<{ rule: RuleResponse }> = ({ rule }) => {
...scheduleRuleWarnings,
...ruleActionsWarnings,
],
ERROR_CODE_FIELD_NAME_MAP
VALIDATION_WARNING_CODE_FIELD_NAME_MAP
);

if (!(await confirmValidationErrors(warnings))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import * as i18n from '../../translations';
import type { RuleFieldEditComponentProps } from './rule_field_edit_component_props';
import { useConfirmValidationErrorsModal } from '../../../../../../../common/hooks/use_confirm_validation_errors_modal';
import {
ERROR_CODE_FIELD_NAME_MAP,
NON_BLOCKING_ERROR_CODES,
} from '../../../../../../rule_creation/constants/non_blocking_error_codes';
VALIDATION_WARNING_CODE_FIELD_NAME_MAP,
VALIDATION_WARNING_CODES,
} from '../../../../../../rule_creation/constants/validation_warning_codes';

type RuleFieldEditComponent = React.ComponentType<RuleFieldEditComponentProps>;

Expand Down Expand Up @@ -68,7 +68,10 @@ export function RuleFieldEditFormWrapper({

const handleSubmit = useCallback<FormWithWarningsSubmitHandler>(
async (formData: FormData, isValid: boolean, { warnings }) => {
const warningMessages = extractValidationMessages(warnings, ERROR_CODE_FIELD_NAME_MAP);
const warningMessages = extractValidationMessages(
warnings,
VALIDATION_WARNING_CODE_FIELD_NAME_MAP
);

if (!isValid || !(await confirmValidationErrors(warningMessages))) {
return;
Expand Down Expand Up @@ -97,7 +100,7 @@ export function RuleFieldEditFormWrapper({
serializer,
onSubmit: handleSubmit,
options: {
warningValidationCodes: NON_BLOCKING_ERROR_CODES,
warningValidationCodes: VALIDATION_WARNING_CODES,
},
});

Expand Down

0 comments on commit c3e5c91

Please sign in to comment.