({
expr,
groupPath,
operandIndex,
}: {
expr: ConditionExpr;
groupPath: Path;
operandIndex: number;
})
| 843 | // ============================================================ |
| 844 | |
| 845 | function FactorSelect({ |
| 846 | expr, |
| 847 | groupPath, |
| 848 | operandIndex, |
| 849 | }: { |
| 850 | expr: ConditionExpr; |
| 851 | groupPath: Path; |
| 852 | operandIndex: number; |
| 853 | }) { |
| 854 | const { t } = useTranslation(); |
| 855 | const { |
| 856 | readonly, |
| 857 | factorList, |
| 858 | factorOperatorOverrideMap: overrideMap, |
| 859 | } = useExprEditorCtx(); |
| 860 | const doUpdate = useImmutableUpdate(groupPath); |
| 861 | const factor = expr.args[0] as Factor; |
| 862 | |
| 863 | useEffect(() => { |
| 864 | if (factorList.length === 0) return; |
| 865 | if (!factorList.includes(factor)) { |
| 866 | doUpdate((group) => { |
| 867 | const cond = group.args[operandIndex] as ConditionExpr; |
| 868 | const newFactor = factorList[0]; |
| 869 | (cond.args as unknown[])[0] = newFactor; |
| 870 | const operators = getOperatorListByFactor(newFactor, overrideMap); |
| 871 | if (operators.length > 0 && !operators.includes(cond.operator)) { |
| 872 | cond.operator = operators[0] as ConditionOperator; |
| 873 | } |
| 874 | (cond.args as unknown[])[1] = getDefaultValue(newFactor, cond.operator); |
| 875 | }); |
| 876 | } |
| 877 | }, [factor, factorList]); |
| 878 | |
| 879 | return ( |
| 880 | <Select |
| 881 | value={factor} |
| 882 | disabled={readonly} |
| 883 | onValueChange={(val) => { |
| 884 | doUpdate((group) => { |
| 885 | const cond = group.args[operandIndex] as ConditionExpr; |
| 886 | (cond.args as unknown[])[0] = val as Factor; |
| 887 | // Reset operator when factor changes |
| 888 | const newFactor = val as Factor; |
| 889 | const operators = getOperatorListByFactor(newFactor, overrideMap); |
| 890 | if (operators.length > 0 && !operators.includes(cond.operator)) { |
| 891 | cond.operator = operators[0] as ConditionOperator; |
| 892 | } |
| 893 | (cond.args as unknown[])[1] = getDefaultValue( |
| 894 | newFactor, |
| 895 | cond.operator |
| 896 | ); |
| 897 | }); |
| 898 | }} |
| 899 | > |
| 900 | <SelectTrigger className="shrink-0"> |
| 901 | <SelectValue> |
| 902 | {(value: string | null) => |
nothing calls this directly
no test coverage detected