Skip to content

Commit

Permalink
chore: use lodash to check equality in schema filtering helper
Browse files Browse the repository at this point in the history
  • Loading branch information
BCerki committed Jul 28, 2023
1 parent b85aa40 commit 8dab0c1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/lib/theme/schemaFilteringHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { JSONSchema7 } from "json-schema";
import { isEqual } from "lodash";

// The two functions below filter out fields from the formSchema that have not changed from the previous revision so the summary ignores these fields
// This is mainly used when the form has multiple fields within it and we want to check each field data with the previous revision
Expand All @@ -22,14 +23,17 @@ export const getSchemaAndDataIncludingCalculatedValues = (

for (const key of Object.keys(filteredSchema.properties)) {
// null new data with undefined old data occurs when an optional form (e.g. budgets) is created but not filled

if (
formDataIncludingCalculatedValues?.[key] === null &&
oldFormDataIncludingCalculatedValues?.[key] === undefined
) {
delete filteredSchema.properties[key];
} else if (
formDataIncludingCalculatedValues?.[key] ===
oldFormDataIncludingCalculatedValues?.[key]
isEqual(
formDataIncludingCalculatedValues?.[key],
oldFormDataIncludingCalculatedValues?.[key]
)
) {
delete filteredSchema.properties[key];
} else newDataObject[key] = formDataIncludingCalculatedValues?.[key];
Expand Down

0 comments on commit 8dab0c1

Please sign in to comment.