Skip to content

Commit

Permalink
Merge branch 'main' into enable-roles-space-serverless
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlemeshko authored Oct 15, 2024
2 parents f3e47b4 + 04efa04 commit 3fbbf40
Show file tree
Hide file tree
Showing 229 changed files with 5,007 additions and 834 deletions.
13 changes: 6 additions & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,7 @@ module.exports = {
'error',
{
patterns: ['**/legacy_uptime/*'],
paths: RESTRICTED_IMPORTS,
},
],
},
Expand Down Expand Up @@ -1055,6 +1056,7 @@ module.exports = {
{
// prevents UI code from importing server side code and then webpack including it when doing builds
patterns: ['**/server/*'],
paths: RESTRICTED_IMPORTS,
},
],
},
Expand Down Expand Up @@ -1113,6 +1115,7 @@ module.exports = {
{
// prevents UI code from importing server side code and then webpack including it when doing builds
patterns: ['**/server/*'],
paths: RESTRICTED_IMPORTS,
},
],
},
Expand Down Expand Up @@ -1184,13 +1187,7 @@ module.exports = {
// to help deprecation and prevent accidental re-use/continued use of code we plan on removing. If you are
// finding yourself turning this off a lot for "new code" consider renaming the file and functions if it is has valid uses.
patterns: ['*legacy*'],
paths: [
{
name: 'react-router-dom',
importNames: ['Route'],
message: "import { Route } from '@kbn/kibana-react-plugin/public'",
},
],
paths: RESTRICTED_IMPORTS,
},
],
},
Expand Down Expand Up @@ -1348,6 +1345,7 @@ module.exports = {
{
// prevents UI code from importing server side code and then webpack including it when doing builds
patterns: ['**/server/*'],
paths: RESTRICTED_IMPORTS,
},
],
},
Expand Down Expand Up @@ -1525,6 +1523,7 @@ module.exports = {
// to help deprecation and prevent accidental re-use/continued use of code we plan on removing. If you are
// finding yourself turning this off a lot for "new code" consider renaming the file and functions if it has valid uses.
patterns: ['*legacy*'],
paths: RESTRICTED_IMPORTS,
},
],
},
Expand Down
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,8 @@ x-pack/test_serverless/**/test_suites/observability/ai_assistant @elastic/obs-ai
/x-pack/dev-tools @elastic/kibana-operations
/catalog-info.yaml @elastic/kibana-operations @elastic/kibana-tech-leads
/.devcontainer/ @elastic/kibana-operations
/.eslintrc.js @elastic/kibana-operations
/.eslintignore @elastic/kibana-operations

# Appex QA
/x-pack/test_serverless/tsconfig.json @elastic/appex-qa
Expand Down Expand Up @@ -1750,6 +1752,8 @@ x-pack/test/security_solution_cypress/cypress/tasks/expandable_flyout @elastic/
/x-pack/plugins/security_solution/common/api/detection_engine/signals_migration @elastic/security-detection-engine
/x-pack/plugins/security_solution/common/cti @elastic/security-detection-engine
/x-pack/plugins/security_solution/common/field_maps @elastic/security-detection-engine
/x-pack/test/functional/es_archives/entity/risks @elastic/security-detection-engine
/x-pack/test/functional/es_archives/entity/host_risk @elastic/security-detection-engine

/x-pack/plugins/security_solution/public/sourcerer @elastic/security-threat-hunting-investigations
/x-pack/plugins/security_solution/public/detection_engine/rule_creation @elastic/security-detection-engine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ export const transformUpdateRuleBody: RewriteResponseCase<UpdateRuleBody> = ({
...(uuid && { uuid }),
};
}),
...(alertDelay ? { alert_delay: alertDelay } : {}),
...(alertDelay !== undefined ? { alert_delay: alertDelay } : {}),
...(flapping !== undefined ? { flapping: transformUpdateRuleFlapping(flapping) } : {}),
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
*/

// Feature flag for frontend rule specific flapping in rule flyout
export const IS_RULE_SPECIFIC_FLAPPING_ENABLED = false;
export const IS_RULE_SPECIFIC_FLAPPING_ENABLED = true;
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
import { useMutation } from '@tanstack/react-query';
import type { HttpStart, IHttpFetchError } from '@kbn/core-http-browser';
import { createRule, CreateRuleBody } from '../apis/create_rule';
import { Rule } from '../types';

export interface UseCreateRuleProps {
http: HttpStart;
onSuccess?: (formData: CreateRuleBody) => void;
onSuccess?: (rule: Rule) => void;
onError?: (error: IHttpFetchError<{ message: string }>) => void;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ export interface UseLoadConnectorsProps {
http: HttpStart;
includeSystemActions?: boolean;
enabled?: boolean;
cacheTime?: number;
}

export const useLoadConnectors = (props: UseLoadConnectorsProps) => {
const { http, includeSystemActions = false, enabled = true } = props;
const { http, includeSystemActions = false, enabled = true, cacheTime } = props;

const queryFn = () => {
return fetchConnectors({ http, includeSystemActions });
Expand All @@ -27,6 +28,7 @@ export const useLoadConnectors = (props: UseLoadConnectorsProps) => {
const { data, isLoading, isFetching, isInitialLoading } = useQuery({
queryKey: ['useLoadConnectors', includeSystemActions],
queryFn,
cacheTime,
refetchOnWindowFocus: false,
enabled,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ export interface UseLoadRuleTypeAadTemplateFieldProps {
http: HttpStart;
ruleTypeId?: string;
enabled: boolean;
cacheTime?: number;
}

export const useLoadRuleTypeAadTemplateField = (props: UseLoadRuleTypeAadTemplateFieldProps) => {
const { http, ruleTypeId, enabled } = props;
const { http, ruleTypeId, enabled, cacheTime } = props;

const queryFn = () => {
if (!ruleTypeId) {
Expand All @@ -43,6 +44,7 @@ export const useLoadRuleTypeAadTemplateField = (props: UseLoadRuleTypeAadTemplat
description: getDescription(d.name, EcsFlat),
}));
},
cacheTime,
refetchOnWindowFocus: false,
enabled,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ import { RuleFormData } from '../../rule_form';
export interface UseResolveProps {
http: HttpStart;
id?: string;
cacheTime?: number;
}

export const useResolveRule = (props: UseResolveProps) => {
const { id, http } = props;
const { id, http, cacheTime } = props;

const queryFn = () => {
if (id) {
Expand All @@ -30,6 +31,7 @@ export const useResolveRule = (props: UseResolveProps) => {
queryKey: ['useResolveRule', id],
queryFn,
enabled: !!id,
cacheTime,
select: (rule): RuleFormData | null => {
if (!rule) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
import { useMutation } from '@tanstack/react-query';
import type { HttpStart, IHttpFetchError } from '@kbn/core-http-browser';
import { updateRule, UpdateRuleBody } from '../apis/update_rule';
import { Rule } from '../types';

export interface UseUpdateRuleProps {
http: HttpStart;
onSuccess?: (formData: UpdateRuleBody) => void;
onSuccess?: (rule: Rule) => void;
onError?: (error: IHttpFetchError<{ message: string }>) => void;
}

Expand Down
2 changes: 0 additions & 2 deletions packages/kbn-alerts-ui-shared/src/common/types/rule_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import { TypeRegistry } from '../type_registry';

export type { SanitizedRuleAction as RuleAction } from '@kbn/alerting-types';

export type { Flapping } from '@kbn/alerting-types';

export type RuleTypeWithDescription = RuleType<string, string> & { description?: string };

export type RuleTypeIndexWithDescriptions = Map<string, RuleTypeWithDescription>;
Expand Down
3 changes: 2 additions & 1 deletion packages/kbn-alerts-ui-shared/src/rule_form/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const DEFAULT_FREQUENCY = {
summary: false,
};

export const GET_DEFAULT_FORM_DATA = ({
export const getDefaultFormData = ({
ruleTypeId,
name,
consumer,
Expand All @@ -50,6 +50,7 @@ export const GET_DEFAULT_FORM_DATA = ({
ruleTypeId,
name,
actions,
alertDelay: { active: 1 },
};
};

Expand Down
22 changes: 16 additions & 6 deletions packages/kbn-alerts-ui-shared/src/rule_form/create_rule_form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ 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 { DEFAULT_VALID_CONSUMERS, GET_DEFAULT_FORM_DATA } from './constants';
import { DEFAULT_VALID_CONSUMERS, getDefaultFormData } from './constants';
import { RuleFormStateProvider } from './rule_form_state';
import { useCreateRule } from '../common/hooks';
import { RulePage } from './rule_page';
Expand All @@ -24,6 +24,7 @@ import {
} from './rule_form_errors';
import { useLoadDependencies } from './hooks/use_load_dependencies';
import {
getAvailableRuleTypes,
getInitialConsumer,
getInitialMultiConsumer,
getInitialSchedule,
Expand All @@ -42,7 +43,8 @@ export interface CreateRuleFormProps {
shouldUseRuleProducer?: boolean;
canShowConsumerSelection?: boolean;
showMustacheAutocompleteSwitch?: boolean;
returnUrl: string;
onCancel?: () => void;
onSubmit?: (ruleId: string) => void;
}

export const CreateRuleForm = (props: CreateRuleFormProps) => {
Expand All @@ -56,16 +58,18 @@ export const CreateRuleForm = (props: CreateRuleFormProps) => {
shouldUseRuleProducer = false,
canShowConsumerSelection = true,
showMustacheAutocompleteSwitch = false,
returnUrl,
onCancel,
onSubmit,
} = props;

const { http, docLinks, notifications, ruleTypeRegistry, i18n, theme } = plugins;
const { toasts } = notifications;

const { mutate, isLoading: isSaving } = useCreateRule({
http,
onSuccess: ({ name }) => {
onSuccess: ({ name, id }) => {
toasts.addSuccess(RULE_CREATE_SUCCESS_TEXT(name));
onSubmit?.(id);
},
onError: (error) => {
const message = parseRuleCircuitBreakerErrorMessage(
Expand All @@ -86,6 +90,7 @@ export const CreateRuleForm = (props: CreateRuleFormProps) => {
const {
isInitialLoading,
ruleType,
ruleTypes,
ruleTypeModel,
uiConfig,
healthCheckError,
Expand Down Expand Up @@ -153,7 +158,7 @@ export const CreateRuleForm = (props: CreateRuleFormProps) => {
<div data-test-subj="createRuleForm">
<RuleFormStateProvider
initialRuleFormState={{
formData: GET_DEFAULT_FORM_DATA({
formData: getDefaultFormData({
ruleTypeId,
name: `${ruleType.name} rule`,
consumer: getInitialConsumer({
Expand All @@ -174,6 +179,11 @@ export const CreateRuleForm = (props: CreateRuleFormProps) => {
minimumScheduleInterval: uiConfig?.minimumScheduleInterval,
selectedRuleTypeModel: ruleTypeModel,
selectedRuleType: ruleType,
availableRuleTypes: getAvailableRuleTypes({
consumer,
ruleTypes,
ruleTypeRegistry,
}).map(({ ruleType: rt }) => rt),
validConsumers,
flappingSettings,
canShowConsumerSelection,
Expand All @@ -185,7 +195,7 @@ export const CreateRuleForm = (props: CreateRuleFormProps) => {
}),
}}
>
<RulePage isEdit={false} isSaving={isSaving} returnUrl={returnUrl} onSave={onSave} />
<RulePage isEdit={false} isSaving={isSaving} onCancel={onCancel} onSave={onSave} />
</RuleFormStateProvider>
</div>
);
Expand Down
28 changes: 23 additions & 5 deletions packages/kbn-alerts-ui-shared/src/rule_form/edit_rule_form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,27 @@ import {
RuleFormRuleTypeError,
} from './rule_form_errors';
import { RULE_EDIT_ERROR_TEXT, RULE_EDIT_SUCCESS_TEXT } from './translations';
import { parseRuleCircuitBreakerErrorMessage } from './utils';
import { getAvailableRuleTypes, parseRuleCircuitBreakerErrorMessage } from './utils';
import { DEFAULT_VALID_CONSUMERS, getDefaultFormData } from './constants';

export interface EditRuleFormProps {
id: string;
plugins: RuleFormPlugins;
showMustacheAutocompleteSwitch?: boolean;
returnUrl: string;
onCancel?: () => void;
onSubmit?: (ruleId: string) => void;
}

export const EditRuleForm = (props: EditRuleFormProps) => {
const { id, plugins, returnUrl, showMustacheAutocompleteSwitch = false } = props;
const { id, plugins, showMustacheAutocompleteSwitch = false, onCancel, onSubmit } = props;
const { http, notifications, docLinks, ruleTypeRegistry, i18n, theme, application } = plugins;
const { toasts } = notifications;

const { mutate, isLoading: isSaving } = useUpdateRule({
http,
onSuccess: ({ name }) => {
toasts.addSuccess(RULE_EDIT_SUCCESS_TEXT(name));
onSubmit?.(id);
},
onError: (error) => {
const message = parseRuleCircuitBreakerErrorMessage(
Expand All @@ -62,6 +65,7 @@ export const EditRuleForm = (props: EditRuleFormProps) => {
const {
isInitialLoading,
ruleType,
ruleTypes,
ruleTypeModel,
uiConfig,
healthCheckError,
Expand Down Expand Up @@ -156,17 +160,31 @@ export const EditRuleForm = (props: EditRuleFormProps) => {
connectors,
connectorTypes,
aadTemplateFields,
formData: fetchedFormData,
formData: {
...getDefaultFormData({
ruleTypeId: fetchedFormData.ruleTypeId,
name: fetchedFormData.name,
consumer: fetchedFormData.consumer,
actions: fetchedFormData.actions,
}),
...fetchedFormData,
},
id,
plugins,
minimumScheduleInterval: uiConfig?.minimumScheduleInterval,
selectedRuleType: ruleType,
selectedRuleTypeModel: ruleTypeModel,
availableRuleTypes: getAvailableRuleTypes({
consumer: fetchedFormData.consumer,
ruleTypes,
ruleTypeRegistry,
}).map(({ ruleType: rt }) => rt),
flappingSettings,
validConsumers: DEFAULT_VALID_CONSUMERS,
showMustacheAutocompleteSwitch,
}}
>
<RulePage isEdit={true} isSaving={isSaving} returnUrl={returnUrl} onSave={onSave} />
<RulePage isEdit={true} isSaving={isSaving} onSave={onSave} onCancel={onCancel} />
</RuleFormStateProvider>
</div>
);
Expand Down
Loading

0 comments on commit 3fbbf40

Please sign in to comment.