Skip to content

Commit

Permalink
copied change from monorepo
Browse files Browse the repository at this point in the history
  • Loading branch information
John Teague committed Jan 27, 2025
1 parent 50be7ac commit b438a69
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/process/calculation/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import { JSONLogicEvaluator } from 'modules/jsonlogic';
import { JSONLogicEvaluator } from "modules/jsonlogic";
import {
ProcessorFn,
ProcessorFnSync,
CalculationScope,
CalculationContext,
ProcessorInfo,
FetchScope,
} from 'types';
import { set } from 'lodash';
import { normalizeContext } from 'utils/formUtil';
} from "types";
import { set } from "lodash";
import { normalizeContext } from "utils/formUtil";

export const shouldCalculate = (context: CalculationContext): boolean => {
// this is a sample change
const { component, config } = context;
if (!component.calculateValue || (config?.server && !component.calculateServer)) {
if (
!component.calculateValue ||
(config?.server && !component.calculateServer)
) {
return false;
}
return true;
Expand All @@ -34,7 +38,11 @@ export const calculateProcessSync: ProcessorFnSync<CalculationScope> = (
: normalizeContext(calculationContext);
evalContextValue.value = value || null;
if (!scope.calculated) scope.calculated = [];
const newValue = JSONLogicEvaluator.evaluate(component.calculateValue, evalContextValue, 'value');
const newValue = JSONLogicEvaluator.evaluate(
component.calculateValue,
evalContextValue,
"value",
);

// Only set a new value if it is not "null" which would be the case if no calculation occurred.
if (newValue !== null) {
Expand All @@ -54,7 +62,7 @@ export const calculateProcess: ProcessorFn<CalculationScope> = async (
};

export const calculateProcessInfo: ProcessorInfo<CalculationContext, void> = {
name: 'calculate',
name: "calculate",
process: calculateProcess,
processSync: calculateProcessSync,
shouldProcess: shouldCalculate,
Expand Down

0 comments on commit b438a69

Please sign in to comment.