Skip to content

Commit

Permalink
feat: Update calculation formula
Browse files Browse the repository at this point in the history
feat: Update calculation formula
  • Loading branch information
ZhaoBingyu committed Jul 20, 2023
1 parent 7be0515 commit 19376fc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
11 changes: 8 additions & 3 deletions clients/components/form-builder/linkages/calculation-formula.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ function executeFormula({ rawFormula, formActions, targetField }: ExecuteFormula
));
};
const condition = ifElse(
() => isUndefined(fieldValue) || isNull(fieldValue) ||
(isArray(fieldValue) && fieldValue.every(isEmpty)),
() =>(isArray(fieldValue) && fieldValue.every(isEmpty)), // isUndefined(fieldValue) || isNull(fieldValue) ||
() => missingValueField = true,
() => valuesAcc.values[fieldPath] = fieldValueFilter(fieldValue),
);
Expand Down Expand Up @@ -127,7 +126,13 @@ function executeFormula({ rawFormula, formActions, targetField }: ExecuteFormula
const subTableFieldKey = lineNumber ? undefined : Object.keys(values).find((key) => isArray(values[key]));
function assignValue(values: Record<string, any>, path: string): void {
try {
const resultValue = resolve(ast, values);
let hasEmpty = false;
for (const key in values) {
if (!hasEmpty) {
hasEmpty = isUndefined(values[key]) || isNull(values[key]);
}
}
const resultValue = hasEmpty ? null : resolve(ast, values);
setFieldState(path, (state) => state.value = resultValue);
} catch (err: any) {
logger.debug('execute calculation formula on form field', 'todo');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import React, { useEffect } from 'react';
import React, { useEffect, useRef } from 'react';
import { InputNumber, InputNumberProps } from 'antd';

type Props = Omit<InputNumberProps, 'onChange'> & {
onChange: (val: any) => void;
}

function NumberPicker({ defaultValue, ...other }: Props): JSX.Element {
const InputNumberRef = useRef<any>();

useEffect(()=>{
InputNumberRef?.current?.addEventListener('input', (event: any) => {
const inputValue = event.target.value;
if (inputValue === '') {
setTimeout(()=>{
other.onChange?.(null);
});
}
});
}, [InputNumberRef?.current]);

useEffect(() => {
if (other.value || other.value === 0 || other.value === null || defaultValue === undefined) {
return;
Expand All @@ -24,7 +37,7 @@ function NumberPicker({ defaultValue, ...other }: Props): JSX.Element {
other.onChange?.(val);
}

return <InputNumber {...other} onChange={handleChange} />;
return <InputNumber ref={InputNumberRef} {...other} onChange={handleChange} />;
}

export default NumberPicker;

0 comments on commit 19376fc

Please sign in to comment.