MCPcopy Create free account
hub / github.com/bytebase/bytebase / OperatorSelect

Function OperatorSelect

frontend/src/react/components/ExprEditor.tsx:922–986  ·  view source on GitHub ↗
({
  expr,
  groupPath,
  operandIndex,
}: {
  expr: ConditionExpr;
  groupPath: Path;
  operandIndex: number;
})

Source from the content-addressed store, hash-verified

920// ============================================================
921
922function 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}>

Callers

nothing calls this directly

Calls 6

getOperatorListByFactorFunction · 0.90
operatorDisplayLabelFunction · 0.90
useExprEditorCtxFunction · 0.85
useImmutableUpdateFunction · 0.85
doUpdateFunction · 0.85
getDefaultValueFunction · 0.85

Tested by

no test coverage detected