Skip to content

Commit

Permalink
add merge values to final diffable rule
Browse files Browse the repository at this point in the history
  • Loading branch information
maximpn committed Sep 10, 2024
1 parent a8c6c23 commit 298f486
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { useCallback, useMemo, useState } from 'react';
import type { FieldsDiff } from '../../../../../../common/api/detection_engine';
import {
ThreeWayDiffConflict,
type DiffableAllFields,
Expand Down Expand Up @@ -89,10 +90,26 @@ function calcFinalDiffableRule(
): DiffableRule {
return {
...convertRuleToDiffable(ruleUpgradeInfo.target_rule),
...convertRuleFieldsDiffToDiffable(ruleUpgradeInfo.diff.fields),
...ruleResolvedConflicts,
} as DiffableRule;
}

/**
* Assembles a `DiffableRule` from rule fields diff `merge_value`s.
*/
function convertRuleFieldsDiffToDiffable(
ruleFieldsDiff: FieldsDiff<Record<string, unknown>>
): Partial<DiffableRule> {
const mergeVersionRule: Record<string, unknown> = {};

for (const fieldName of Object.keys(ruleFieldsDiff)) {
mergeVersionRule[fieldName] = ruleFieldsDiff[fieldName].merged_version;
}

return mergeVersionRule;
}

function calcUnresolvedConflicts(
ruleUpgradeInfo: RuleUpgradeInfoForReview,
ruleResolvedConflicts: RuleResolvedConflicts
Expand Down

0 comments on commit 298f486

Please sign in to comment.