Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Response Ops] [Rule Form] Add Rule Form Flyout v2 #206685

Open
wants to merge 68 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 60 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
1ef801c
Hide close button when show request is open
Zacqary Jan 9, 2025
1faf112
Use EUI breakpoint variables for container breakpoints
Zacqary Jan 15, 2025
4cb5b1d
Revert "Use EUI breakpoint variables for container breakpoints"
Zacqary Jan 17, 2025
e5b287a
Decouple RuleForm component from react router
Zacqary Jan 13, 2025
74f59b7
Initially replace flyout in Discover plugin
Zacqary Jan 13, 2025
dd6e167
Replace add/edit rule flyouts with getRuleFormFlyout
Zacqary Jan 14, 2025
6dd013d
Remove missing import
Zacqary Jan 14, 2025
69eb8fa
Add isServerless flag to rule flyout
Zacqary Jan 14, 2025
74d5339
Fix metadata typing
Zacqary Jan 14, 2025
646af0f
Fix initialMetadata error
Zacqary Jan 14, 2025
d4c91d3
Add flyout close confirm and no actions callout
Zacqary Jan 14, 2025
2d61517
Fix action UI display papercuts
Zacqary Jan 14, 2025
1ffea47
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Jan 14, 2025
19f2fdc
Fix typecheck
Zacqary Jan 14, 2025
3e9ebe4
Fix bundle size
Zacqary Jan 14, 2025
70d4dab
Fix typecheck
Zacqary Jan 16, 2025
9c4d831
Lazy load rule form component from response ops package
Zacqary Jan 16, 2025
547c4da
Fix lazy loading rule form
Zacqary Jan 16, 2025
c2174d6
Begin fixing discover tests
Zacqary Jan 16, 2025
4719faf
Fix button ids on discover test
Zacqary Jan 16, 2025
51e33f9
Fix system actions test
Zacqary Jan 17, 2025
c25c283
Fix get app menu header id
Zacqary Jan 17, 2025
dc8c9ab
Fix cancelAlertFlyout function in ML anomaly tests
Zacqary Jan 17, 2025
114e98a
Fix monitor alerts journey for closing rule form flyout
Zacqary Jan 17, 2025
e3a0e7e
Create /components folder for common components
Zacqary Jan 22, 2025
dbc9712
Move confirm close modal to own component
Zacqary Jan 22, 2025
fd7abec
Replace flyout callouts and screens with confirm modals
Zacqary Jan 22, 2025
4dbc4f0
Merge branch 'main' into 195211-replace-flyout
elasticmachine Jan 23, 2025
b0f977b
Remove unused import
Zacqary Jan 23, 2025
4b806ac
Merge branch '195211-replace-flyout' of https://github.com/Zacqary/ki…
Zacqary Jan 23, 2025
13429c1
Fix ES query expression error display
Zacqary Jan 23, 2025
f557eb2
Fix errorParam ternary syntax
Zacqary Jan 23, 2025
286721f
Fix APM chypress test
Zacqary Jan 23, 2025
1fd34d0
Fix APM cypress test
Zacqary Jan 23, 2025
c437919
Reduce discover accessibility test flakiness
Zacqary Jan 23, 2025
dbbe03a
Fix data touched tracking
Zacqary Jan 23, 2025
f9f82ed
Fix custom threshold preview test
Zacqary Jan 23, 2025
f21566b
Fix monitor alerts journey
Zacqary Jan 23, 2025
0efa925
Merge remote-tracking branch 'upstream/main' into 195211-replace-flyout
Zacqary Jan 24, 2025
fb70192
Merge isServerless implementation from main
Zacqary Jan 24, 2025
4fd1228
Fix APM cypress
Zacqary Jan 24, 2025
f2e01b9
Fix some tests, improve loading prompty
Zacqary Jan 24, 2025
e6befaf
Fix initial metadata override
Zacqary Jan 24, 2025
07ee45a
Fix typecheck
Zacqary Jan 24, 2025
370a2b6
Fix i18n
Zacqary Jan 27, 2025
908d36c
Merge remote-tracking branch 'upstream/main' into 195211-replace-flyout
Zacqary Jan 27, 2025
52c6414
Fix uptime rule form flyout and observability rule params
Zacqary Jan 27, 2025
aa0287f
Fix uptime tests
Zacqary Jan 27, 2025
9ef99b5
Fix serverless search source test
Zacqary Jan 27, 2025
bb09a7d
Fix APM cypress
Zacqary Jan 27, 2025
d182820
Add debug logs to accessibility testing
Zacqary Jan 27, 2025
118a154
Fix synthetics journey
Zacqary Jan 27, 2025
b8a2e33
Fix APM cypress
Zacqary Jan 27, 2025
09d456d
Remove code path for experimental use of v1 flyout
Zacqary Jan 27, 2025
c89a707
Update synthetics journey
Zacqary Jan 28, 2025
565c974
Update uptime synthetic test and skip discover accessibility test
Zacqary Jan 28, 2025
def9107
Merge remote-tracking branch 'upstream/main' into 195211-replace-flyout
Zacqary Jan 28, 2025
3f16b58
Unskip discover accessibility test
Zacqary Jan 28, 2025
27cb8b3
Remove flyout loading check from discover test
Zacqary Jan 28, 2025
688c145
Update synthetics tests
Zacqary Jan 28, 2025
c3eff4f
Omit dataViews from RequiredRuleFormPlugins typedef
Zacqary Jan 29, 2025
3ef3181
Add encryption key to discover accessibility test
Zacqary Jan 29, 2025
756cfa8
Fix uptime journey
Zacqary Jan 29, 2025
95b14da
Merge remote-tracking branch 'upstream/main' into 195211-replace-flyout
Zacqary Jan 29, 2025
aa0abd0
Fix typecheck
Zacqary Jan 30, 2025
990a73c
Attempt synthetics test fix
Zacqary Jan 30, 2025
c4a2c9b
Merge remote-tracking branch 'upstream/main' into 195211-replace-flyout
Zacqary Jan 30, 2025
3772d57
Merge branch 'main' into 195211-replace-flyout
Zacqary Feb 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export type RuleTypeWithDescription = RuleType<string, string> & { description?:
export type RuleTypeIndexWithDescriptions = Map<string, RuleTypeWithDescription>;

export type RuleTypeParams = Record<string, unknown>;
export type RuleTypeMetaData = Record<string, unknown>;

export interface RuleFormBaseErrors {
name?: string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
export * from './src/types';
export * from './src/rule_type_modal';

export { RuleForm } from './src/rule_form';
export { RuleForm, type RuleFormProps } from './src/rule_form';

export {
fetchUiConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { EcsFlat } from '@elastic/ecs';
import { useRef } from 'react';
import { isEmpty } from 'lodash';
import { ActionVariable } from '@kbn/alerting-types';
import type { HttpStart } from '@kbn/core-http-browser';
import { useQuery } from '@tanstack/react-query';
Expand All @@ -24,12 +25,24 @@ export interface UseLoadRuleTypeAadTemplateFieldProps {
}

export const useLoadRuleTypeAadTemplateField = (props: UseLoadRuleTypeAadTemplateFieldProps) => {
const ecsFlat = useRef<Record<string, any>>({});
const { http, ruleTypeId, enabled, cacheTime } = props;

const queryFn = async () => {
if (!ruleTypeId) {
return;
}
if (isEmpty(ecsFlat.current)) {
// If we use import { EcsFlat } from '@elastic/ecs' then it will sometimes balloon the bundle size
// by about 1MB, or not, depending on how Webpack is feeling today. If you delete this dynamic import,
// it's possible that it won't make the bundle size explode, and then you will commit that change, and
// we will all continue to live our lives safe and secure, falsely believing that the danger has passed,
// until one day somebody makes another change to this package and, for mysterious, unknowable reasons,
// Webpack decides that today the bundle size shall be engorged once again.
// To avoid all that maybe just don't delete this dynamic import.
ecsFlat.current = await import('@elastic/ecs').then((ecs) => ecs.EcsFlat);
Copy link
Contributor

@jughosta jughosta Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

return fetchRuleTypeAadTemplateFields({ http, ruleTypeId });
};

Expand All @@ -44,7 +57,7 @@ export const useLoadRuleTypeAadTemplateField = (props: UseLoadRuleTypeAadTemplat
select: (dataViewFields) => {
return dataViewFields?.map<ActionVariable>((d) => ({
name: d.name,
description: getDescription(d.name, EcsFlat),
description: getDescription(d.name, ecsFlat.current),
}));
},
cacheTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ import {
CONFIRM_RULE_SAVE_CONFIRM_BUTTON_TEXT,
CONFIRM_RULE_SAVE_CANCEL_BUTTON_TEXT,
CONFIRM_RULE_SAVE_MESSAGE_TEXT,
} from '../translations';
} from '../../translations';

export interface RulePageConfirmCreateRuleProps {
export interface ConfirmCreateRuleProps {
onCancel: () => void;
onConfirm: () => void;
}

export const RulePageConfirmCreateRule = (props: RulePageConfirmCreateRuleProps) => {
export const ConfirmCreateRule = (props: ConfirmCreateRuleProps) => {
const { onCancel, onConfirm } = props;

return (
<EuiConfirmModal
data-test-subj="rulePageConfirmCreateRule"
data-test-subj="confirmCreateRuleModal"
title={CONFIRMATION_RULE_SAVE_TITLE}
onCancel={onCancel}
onConfirm={onConfirm}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export * from './confirm_create_rule';
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import React from 'react';
import { EuiConfirmModal, EuiText } from '@elastic/eui';
import {
RULE_FORM_CANCEL_MODAL_TITLE,
RULE_FORM_CANCEL_MODAL_CONFIRM,
RULE_FORM_CANCEL_MODAL_CANCEL,
RULE_FORM_CANCEL_MODAL_DESCRIPTION,
} from '../../translations';

export interface ConfirmRuleCloseRuleProps {
onCancel: () => void;
onConfirm: () => void;
}

export const ConfirmRuleClose = (props: ConfirmRuleCloseRuleProps) => {
const { onCancel, onConfirm } = props;

return (
<EuiConfirmModal
onCancel={onCancel}
onConfirm={onConfirm}
data-test-subj="confirmRuleCloseModal"
buttonColor="danger"
defaultFocusedButton="confirm"
title={RULE_FORM_CANCEL_MODAL_TITLE}
confirmButtonText={RULE_FORM_CANCEL_MODAL_CONFIRM}
cancelButtonText={RULE_FORM_CANCEL_MODAL_CANCEL}
>
<EuiText>
<p>{RULE_FORM_CANCEL_MODAL_DESCRIPTION}</p>
</EuiText>
</EuiConfirmModal>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export * from './confirm_rule_close';
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export * from './request_code_block';
export * from './confirm_create_rule';
export * from './confirm_rule_close';
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import {
UpdateRuleBody,
transformCreateRuleBody,
transformUpdateRuleBody,
} from '../common/apis';
import { BASE_ALERTING_API_PATH } from '../constants';
import { useRuleFormState } from '../hooks';
import { SHOW_REQUEST_MODAL_ERROR } from '../translations';
import { RuleFormData } from '../types';
} from '../../common/apis';
import { BASE_ALERTING_API_PATH } from '../../constants';
import { useRuleFormState } from '../../hooks';
import { SHOW_REQUEST_MODAL_ERROR } from '../../translations';
import { RuleFormData } from '../../types';

const stringifyBodyRequest = ({
formData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import React, { useCallback } from 'react';
import { EuiLoadingElastic } from '@elastic/eui';
import { toMountPoint } from '@kbn/react-kibana-mount';
import { type RuleCreationValidConsumer } from '@kbn/rule-data-utils';
import type { RuleFormData, RuleFormPlugins } from './types';
import type { RuleFormData, RuleFormPlugins, RuleTypeMetaData } from './types';
import { DEFAULT_VALID_CONSUMERS, getDefaultFormData } from './constants';
import { RuleFormStateProvider } from './rule_form_state';
import { useCreateRule } from './common/hooks';
import { RulePage } from './rule_page';
import { RuleFlyout } from './rule_flyout';
import {
RuleFormCircuitBreakerError,
RuleFormErrorPromptWrapper,
Expand Down Expand Up @@ -44,9 +45,13 @@ export interface CreateRuleFormProps {
shouldUseRuleProducer?: boolean;
canShowConsumerSelection?: boolean;
showMustacheAutocompleteSwitch?: boolean;
isFlyout?: boolean;
isServerless?: boolean;
onCancel?: () => void;
onSubmit?: (ruleId: string) => void;
onChangeMetaData?: (metadata?: RuleTypeMetaData) => void;
initialValues?: Partial<RuleFormData>;
initialMetadata?: RuleTypeMetaData;
}

export const CreateRuleForm = (props: CreateRuleFormProps) => {
Expand All @@ -61,9 +66,13 @@ export const CreateRuleForm = (props: CreateRuleFormProps) => {
shouldUseRuleProducer = false,
canShowConsumerSelection = true,
showMustacheAutocompleteSwitch = false,
isFlyout,
isServerless = false,
onCancel,
onSubmit,
onChangeMetaData,
initialMetadata,
initialValues = {},
} = props;

const { http, docLinks, notifications, ruleTypeRegistry, ...deps } = plugins;
Expand Down Expand Up @@ -158,24 +167,30 @@ export const CreateRuleForm = (props: CreateRuleFormProps) => {
);
}

const RuleFormUIComponent = isFlyout ? RuleFlyout : RulePage;

return (
<div data-test-subj="createRuleForm">
<RuleFormStateProvider
initialRuleFormState={{
formData: getDefaultFormData({
ruleTypeId,
name: `${ruleType.name} rule`,
consumer: getInitialConsumer({
consumer,
ruleType,
shouldUseRuleProducer,
}),
schedule: getInitialSchedule({
ruleType,
minimumScheduleInterval: uiConfig?.minimumScheduleInterval,
formData: {
...getDefaultFormData({
ruleTypeId,
name: `${ruleType.name} rule`,
consumer: getInitialConsumer({
consumer,
ruleType,
shouldUseRuleProducer,
}),
schedule: getInitialSchedule({
ruleType,
minimumScheduleInterval: uiConfig?.minimumScheduleInterval,
}),
actions: [],
}),
actions: [],
}),
...initialValues,
},
metadata: initialMetadata,
plugins,
connectors,
connectorTypes,
Expand All @@ -201,7 +216,13 @@ export const CreateRuleForm = (props: CreateRuleFormProps) => {
}),
}}
>
<RulePage isEdit={false} isSaving={isSaving} onCancel={onCancel} onSave={onSave} />
<RuleFormUIComponent
isEdit={false}
isSaving={isSaving}
onCancel={onCancel}
onSave={onSave}
onChangeMetaData={onChangeMetaData}
/>
</RuleFormStateProvider>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
import React, { useCallback, useMemo } from 'react';
import { EuiLoadingElastic } from '@elastic/eui';
import { toMountPoint } from '@kbn/react-kibana-mount';
import type { RuleFormData, RuleFormPlugins } from './types';
import type { RuleFormData, RuleFormPlugins, RuleTypeMetaData } from './types';
import { RuleFormStateProvider } from './rule_form_state';
import { useUpdateRule } from './common/hooks';
import { RulePage } from './rule_page';
import { RuleFlyout } from './rule_flyout';
import { RuleFormHealthCheckError } from './rule_form_errors/rule_form_health_check_error';
import { useLoadDependencies } from './hooks/use_load_dependencies';
import {
Expand All @@ -32,8 +33,11 @@ export interface EditRuleFormProps {
plugins: RuleFormPlugins;
showMustacheAutocompleteSwitch?: boolean;
connectorFeatureId?: string;
isFlyout?: boolean;
onCancel?: () => void;
onSubmit?: (ruleId: string) => void;
onChangeMetaData?: (metadata?: RuleTypeMetaData) => void;
initialMetadata?: RuleTypeMetaData;
}

export const EditRuleForm = (props: EditRuleFormProps) => {
Expand All @@ -44,6 +48,9 @@ export const EditRuleForm = (props: EditRuleFormProps) => {
connectorFeatureId = 'alerting',
onCancel,
onSubmit,
isFlyout,
onChangeMetaData,
initialMetadata,
} = props;
const { http, notifications, docLinks, ruleTypeRegistry, application, ...deps } = plugins;
const { toasts } = notifications;
Expand Down Expand Up @@ -179,6 +186,8 @@ export const EditRuleForm = (props: EditRuleFormProps) => {
return action;
});

const RuleFormUIComponent = isFlyout ? RuleFlyout : RulePage;

return (
<div data-test-subj="editRuleForm">
<RuleFormStateProvider
Expand All @@ -197,6 +206,7 @@ export const EditRuleForm = (props: EditRuleFormProps) => {
actions: actionsWithFrequency,
},
id,
metadata: initialMetadata,
plugins,
minimumScheduleInterval: uiConfig?.minimumScheduleInterval,
selectedRuleType: ruleType,
Expand All @@ -211,7 +221,13 @@ export const EditRuleForm = (props: EditRuleFormProps) => {
showMustacheAutocompleteSwitch,
}}
>
<RulePage isEdit={true} isSaving={isSaving} onSave={onSave} onCancel={onCancel} />
<RuleFormUIComponent
isEdit={true}
isSaving={isSaving}
onSave={onSave}
onCancel={onCancel}
onChangeMetaData={onChangeMetaData}
/>
</RuleFormStateProvider>
</div>
);
Expand Down
Loading