Skip to content

Commit

Permalink
display EQL options diff
Browse files Browse the repository at this point in the history
  • Loading branch information
maximpn committed Nov 21, 2024
1 parent 1eedbd2 commit 45bfabc
Showing 1 changed file with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,25 @@ export const getSubfieldChangesForEqlQuery = (
): SubfieldChange[] => {
const changes: SubfieldChange[] = [];

const oldQuery = stringifyToSortedJson(oldFieldValue?.query);
const newQuery = stringifyToSortedJson(newFieldValue?.query);
const subFieldNames: Array<keyof DiffableAllFields['eql_query']> = [
'query',
'filters',
'event_category_override',
'tiebreaker_field',
'timestamp_field',
];

if (oldQuery !== newQuery) {
changes.push({
subfieldName: 'query',
oldSubfieldValue: oldQuery,
newSubfieldValue: newQuery,
});
}

const oldFilters = stringifyToSortedJson(oldFieldValue?.filters);
const newFilters = stringifyToSortedJson(newFieldValue?.filters);
for (const subFieldName of subFieldNames) {
const oldValue = stringifyToSortedJson(oldFieldValue?.[subFieldName]);
const newValue = stringifyToSortedJson(newFieldValue?.[subFieldName]);

if (oldFilters !== newFilters) {
changes.push({
subfieldName: 'filters',
oldSubfieldValue: oldFilters,
newSubfieldValue: newFilters,
});
if (newValue !== oldValue) {
changes.push({
subfieldName: subFieldName,
oldSubfieldValue: oldValue,
newSubfieldValue: newValue,
});
}
}

return changes;
Expand Down

0 comments on commit 45bfabc

Please sign in to comment.