Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,25 @@ import { TimeZoneFormatting } from '../formatting/TimeZoneFormatting';
import { UnionFormatting } from '../formatting/UnionFormatting';
import { UnionShowAs } from '../show-as/UnionShowAs';

const calculateTypedValue = (fields: IFieldInstance[], expression?: string) => {
const defaultResult = { cellValueType: CellValueType.String, isMultipleCellValue: false };
const calculateTypedValue = (
fields: IFieldInstance[],
expression?: string
): {
cellValueType: CellValueType;
isMultipleCellValue?: boolean;
hasError?: boolean;
} => {
const defaultResult = {
cellValueType: CellValueType.String,
isMultipleCellValue: false,
};

try {
return expression
? FormulaField.getParsedValueType(expression, keyBy(fields, 'id'))
: defaultResult;
} catch (e) {
return defaultResult;
return { ...defaultResult, hasError: true };
}
};

Expand All @@ -48,7 +58,11 @@ export const FormulaOptionsInner = (props: {
: '';
}, [expression, fields]);

const { cellValueType, isMultipleCellValue } = calculateTypedValue(fields, expression);
const {
cellValueType,
isMultipleCellValue,
hasError: expressionHasError,
} = calculateTypedValue(fields, expression);

const onExpressionChange = (expr: string) => {
const { cellValueType: newCellValueType } = calculateTypedValue(fields, expr);
Expand All @@ -59,7 +73,7 @@ export const FormulaOptionsInner = (props: {
? formatting.timeZone
: options.timeZone ?? Intl.DateTimeFormat().resolvedOptions().timeZone,
};
if (newCellValueType !== cellValueType) {
if (newCellValueType !== cellValueType || expressionHasError) {
const defaultFormatting = getDefaultFormatting(newCellValueType);
newOptions.formatting = defaultFormatting;
newOptions.showAs = undefined;
Expand Down