Skip to content

Commit

Permalink
get alert from raw types fix
Browse files Browse the repository at this point in the history
  • Loading branch information
guskovaue committed Nov 8, 2023
1 parent 63ab319 commit 1124408
Showing 1 changed file with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
RuleTypeParams,
RuleWithLegacyId,
PartialRuleWithLegacyId,
isSystemAction,
} from '../../types';
import {
ruleExecutionStatusFromRaw,
Expand All @@ -23,8 +24,9 @@ import {
} from '../../lib';
import { UntypedNormalizedRuleType } from '../../rule_type_registry';
import { getActiveScheduledSnoozes } from '../../lib/is_rule_snoozed';
import { injectReferencesIntoActions, injectReferencesIntoParams } from '../common';
import { injectReferencesIntoParams } from '../common';
import { RulesClientContext } from '../types';
import { transformRawActionsToDomainActions } from '../../application/rule/transforms/transform_raw_actions_to_domain_actions';

export interface GetAlertFromRawParams {
id: string;
Expand Down Expand Up @@ -118,14 +120,22 @@ export function getPartialRuleFromRaw<Params extends RuleTypeParams>(
})
: null;
const includeMonitoring = monitoring && !excludeFromPublicApi;

const rule: PartialRule<Params> = {
id,
notifyWhen,
...omit(partialRawRule, excludeFromPublicApi ? [...context.fieldsToExcludeFromPublicApi] : ''),
// we currently only support the Interval Schedule type
// Once we support additional types, this type signature will likely change
schedule: schedule as IntervalSchedule,
actions: actions ? injectReferencesIntoActions(id, actions, references || []) : [],
actions: actions
? transformRawActionsToDomainActions({
ruleId: id,
actions,
references: references || [],
isSystemAction: context.isSystemAction,
})
: [],
params: injectReferencesIntoParams(id, ruleType, params, references || []) as Params,
...(excludeFromPublicApi ? {} : { snoozeSchedule: snoozeScheduleDates ?? [] }),
...(includeSnoozeData && !excludeFromPublicApi
Expand Down Expand Up @@ -161,7 +171,12 @@ export function getPartialRuleFromRaw<Params extends RuleTypeParams>(

if (omitGeneratedValues) {
if (rule.actions) {
rule.actions = rule.actions.map((ruleAction) => omit(ruleAction, 'alertsFilter.query.dsl'));
rule.actions = rule.actions.map((ruleAction) => {
if (!isSystemAction(ruleAction)) {
return omit(ruleAction, 'alertsFilter.query.dsl');
}
return ruleAction;
});
}
}

Expand Down

0 comments on commit 1124408

Please sign in to comment.