Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
patrykkopycinski committed Mar 9, 2020
1 parent 9c3445e commit 6ebdfc5
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,11 @@ import { AlertAction } from '../../../../../../../../../plugins/triggers_actions

type ThrottleSelectField = typeof SelectField;

const ACTION_TYPES = [
const SUPPORTED_ACTION_TYPES = [
{ id: '.email', name: 'Email', enabled: true },
{ id: '.index', name: 'Index', enabled: false },
{ id: '.pagerduty', name: 'PagerDuty', enabled: true },
{ id: '.server-log', name: 'Server log', enabled: false },
{ id: '.servicenow', name: 'servicenow', enabled: false },
{ id: '.slack', name: 'Slack', enabled: true },
{ id: '.webhook', name: 'Webhook', enabled: false },
{ id: '.example-action', name: 'Example Action', enabled: false },
{ id: '.webhook', name: 'Webhook', enabled: true },
];

const DEFAULT_ACTION_GROUP_ID = 'default';
Expand All @@ -49,7 +45,7 @@ const getMessageVariables = memoizeOne(() => {
});

export const RuleActionsField: ThrottleSelectField = ({ field }) => {
const { http, toastNotifications, triggers_actions_ui } = useKibana().services;
const { http, triggers_actions_ui } = useKibana().services;
const actionTypeRegistry = triggers_actions_ui.actionTypeRegistry;
const messageVariables = getMessageVariables();

Expand Down Expand Up @@ -79,7 +75,6 @@ export const RuleActionsField: ThrottleSelectField = ({ field }) => {

return (
<ActionForm
toastNotifications={toastNotifications}
actions={field.value as AlertAction[]}
messageVariables={messageVariables}
defaultActionGroupId={DEFAULT_ACTION_GROUP_ID}
Expand All @@ -88,7 +83,7 @@ export const RuleActionsField: ThrottleSelectField = ({ field }) => {
setActionParamsProperty={setActionParamsProperty}
http={http}
actionTypeRegistry={actionTypeRegistry}
actionTypes={ACTION_TYPES}
actionTypes={SUPPORTED_ACTION_TYPES}
defaultActionMessage={DEFAULT_ACTION_MESSAGE}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,17 @@ const StepRuleActionsComponent: FC<StepRuleActionsProps> = ({
}
}, [form]);

// console.error('ss', myStepData, form.getFormData());
// useEffect(() => {
// if (!form) return;

// const subscription = form.subscribe(updatedData => {
// setMyStepData({ ...updatedData.data.raw, ...stepActionsDefaultValue });
// });

// return subscription.unsubscribe;
// }, [form]);

console.error('ss', myStepData, form.getFormData());

return isReadOnlyView && myStepData != null ? (
<StepContentWrapper addPadding={addPadding}>
Expand All @@ -104,7 +114,7 @@ const StepRuleActionsComponent: FC<StepRuleActionsProps> = ({
},
}}
/>
{form.getFormData().throttle !== stepActionsDefaultValue.throttle && (
{myStepData.throttle !== stepActionsDefaultValue.throttle && (
<>
<EuiSpacer />
<UseField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ import { SelectField } from '../../../../../shared_imports';

export const THROTTLE_OPTIONS = [
{ value: 'no_actions', text: 'Perform no actions' },
{ value: 'signal', text: 'On each signal detected' },
{ value: 'rule', text: 'On each rule execution' },
{ value: '5m', text: '5 minutes' },
{ value: '1h', text: 'Hourly' },
{ value: '1d', text: 'Daily' },
// { value: '5m', text: '5 minutes' },
// { value: '1h', text: 'Hourly' },
// { value: '1d', text: 'Daily' },
];

type ThrottleSelectField = typeof SelectField;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,11 @@ export const signalRulesAlertType = ({

if (throttle && throttle !== 'no_actions') {
const alertInstance = services.alertInstanceFactory(ruleId!);

const newSignalsCount = noReIndexResult.hits.total.value;
const currentSignalsCount = alertInstance.getState().signalsCount ?? 0;
const signalsCount = currentSignalsCount + newSignalsCount;

alertInstance
.replaceState({
signalsCount,
signalsCount: newSignalsCount,
})
.scheduleActions('default', {
inputIndexes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ interface ActionAccordionFormProps {
setActionParamsProperty: (key: string, value: any, index: number) => void;
http: HttpSetup;
actionTypeRegistry: TypeRegistry<ActionTypeModel>;
toastNotifications: Pick<
toastNotifications?: Pick<
ToastsApi,
'get$' | 'add' | 'remove' | 'addSuccess' | 'addWarning' | 'addDanger' | 'addError'
>;
Expand Down

0 comments on commit 6ebdfc5

Please sign in to comment.