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

Function ValueInput

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

Source from the content-addressed store, hash-verified

990// ============================================================
991
992function ValueInput({
993 expr,
994 groupPath,
995 operandIndex,
996}: {
997 expr: ConditionExpr;
998 groupPath: Path;
999 operandIndex: number;
1000}) {
1001 const { t } = useTranslation();
1002 const { readonly, optionConfigMap } = useExprEditorCtx();
1003 const doUpdate = useImmutableUpdate(groupPath);
1004 const factor = expr.args[0] as Factor;
1005 const operator = expr.operator;
1006
1007 const optionConfig = useMemo(
1008 () => optionConfigMap.get(factor) ?? { options: [] },
1009 [optionConfigMap, factor]
1010 );
1011
1012 const isEnvironment = factor === CEL_ATTRIBUTE_RESOURCE_ENVIRONMENT_ID;
1013 const renderOptionValue = (value: string, fallbackLabel?: string) => {
1014 if (isEnvironment) {
1015 return (
1016 <EnvironmentLabel
1017 environmentName={`${environmentNamePrefix}${value}`}
1018 />
1019 );
1020 }
1021 return fallbackLabel ?? value;
1022 };
1023
1024 const hasOption = optionConfig.options.length > 0 || !!optionConfig.search;
1025 const hasMultiOption = hasOption && optionConfig.supportMultiple !== false;
1026
1027 type InputType = "INPUT" | "SINGLE-SELECT" | "MULTI-SELECT" | "MULTI-INPUT";
1028
1029 const isArrayValue = isCollectionOperator(operator);
1030
1031 let inputType: InputType;
1032 if (isArrayValue) {
1033 inputType = hasMultiOption ? "MULTI-SELECT" : "MULTI-INPUT";
1034 } else if (isStringOperator(operator)) {
1035 inputType = "INPUT";
1036 } else if (hasOption) {
1037 inputType = "SINGLE-SELECT";
1038 } else {
1039 inputType = "INPUT";
1040 }
1041
1042 const isNumberValue = isNumberFactor(factor);
1043 const isBooleanValue = isBooleanFactor(factor);
1044
1045 const getBooleanValue = (): boolean =>
1046 typeof expr.args[1] === "boolean" ? (expr.args[1] as boolean) : true;
1047 const setBooleanValue = (v: boolean) => {
1048 doUpdate((group) => {
1049 const cond = group.args[operandIndex] as ConditionExpr;

Callers

nothing calls this directly

Calls 15

isCollectionOperatorFunction · 0.90
isStringOperatorFunction · 0.90
isNumberFactorFunction · 0.90
isBooleanFactorFunction · 0.90
useExprEditorCtxFunction · 0.85
useImmutableUpdateFunction · 0.85
getNumberValueFunction · 0.85
setNumberValueFunction · 0.85
getBooleanValueFunction · 0.85
setBooleanValueFunction · 0.85
getStringValueFunction · 0.85
setStringValueFunction · 0.85

Tested by

no test coverage detected