({
expr,
groupPath,
operandIndex,
}: {
expr: ConditionExpr;
groupPath: Path;
operandIndex: number;
})
| 920 | // ============================================================ |
| 921 | |
| 922 | function OperatorSelect({ |
| 923 | expr, |
| 924 | groupPath, |
| 925 | operandIndex, |
| 926 | }: { |
| 927 | expr: ConditionExpr; |
| 928 | groupPath: Path; |
| 929 | operandIndex: number; |
| 930 | }) { |
| 931 | const { readonly, factorOperatorOverrideMap: overrideMap } = |
| 932 | useExprEditorCtx(); |
| 933 | const doUpdate = useImmutableUpdate(groupPath); |
| 934 | const factor = expr.args[0] as Factor; |
| 935 | |
| 936 | const operators = useMemo( |
| 937 | () => getOperatorListByFactor(factor, overrideMap), |
| 938 | [factor, overrideMap] |
| 939 | ); |
| 940 | |
| 941 | useEffect(() => { |
| 942 | if (operators.length === 0) return; |
| 943 | if (!operators.includes(expr.operator)) { |
| 944 | doUpdate((group) => { |
| 945 | const cond = group.args[operandIndex] as ConditionExpr; |
| 946 | cond.operator = operators[0] as ConditionOperator; |
| 947 | (cond.args as unknown[])[1] = getDefaultValue( |
| 948 | cond.args[0] as Factor, |
| 949 | cond.operator |
| 950 | ); |
| 951 | }); |
| 952 | } |
| 953 | }, [operators, expr.operator]); |
| 954 | |
| 955 | return ( |
| 956 | <Select |
| 957 | value={expr.operator} |
| 958 | disabled={readonly} |
| 959 | onValueChange={(val) => { |
| 960 | doUpdate((group) => { |
| 961 | const cond = group.args[operandIndex] as ConditionExpr; |
| 962 | cond.operator = val as ConditionOperator; |
| 963 | (cond.args as unknown[])[1] = getDefaultValue( |
| 964 | cond.args[0] as Factor, |
| 965 | cond.operator |
| 966 | ); |
| 967 | }); |
| 968 | }} |
| 969 | > |
| 970 | <SelectTrigger className="shrink-0"> |
| 971 | <SelectValue> |
| 972 | {(value: string | null) => |
| 973 | value ? operatorDisplayLabel(value) : null |
| 974 | } |
| 975 | </SelectValue> |
| 976 | </SelectTrigger> |
| 977 | <SelectContent> |
| 978 | {operators.map((op) => ( |
| 979 | <SelectItem key={op} value={op}> |
nothing calls this directly
no test coverage detected