MCPcopy
hub / github.com/buxuku/SmartSub / ValueEditor

Function ValueEditor

renderer/components/ParameterKvTable.tsx:135–214  ·  view source on GitHub ↗
({
  type,
  value,
  disabled,
  onChange,
  onCommit,
  onKeyDown,
  inputId,
  inputDataField,
})

Source from the content-addressed store, hash-verified

133}
134
135const ValueEditor: React.FC<ValueEditorProps> = ({
136 type,
137 value,
138 disabled,
139 onChange,
140 onCommit,
141 onKeyDown,
142 inputId,
143 inputDataField,
144}) => {
145 const { t } = useTranslation('parameters');
146 const raw =
147 typeof value === 'string' ? value : formatValueForInput(value, type);
148
149 if (type === 'boolean') {
150 const checked =
151 typeof value === 'boolean'
152 ? value
153 : parseDraftValue(String(value), 'boolean') === true;
154
155 return (
156 <div className="space-y-1" data-draft-field={inputDataField}>
157 <Switch
158 checked={checked}
159 disabled={disabled}
160 onCheckedChange={(next) => onChange(String(next))}
161 />
162 <p className="text-xs text-muted-foreground">
163 {t('table.booleanHint')}
164 </p>
165 </div>
166 );
167 }
168
169 if (type === 'array') {
170 const jsonError = validateArrayJson(raw);
171 const jsonErrorMessage = formatArrayError(jsonError, t);
172
173 return (
174 <div className="space-y-1">
175 <Textarea
176 id={inputId}
177 data-draft-field={inputDataField}
178 value={raw}
179 disabled={disabled}
180 placeholder={t('table.arrayPlaceholder')}
181 className={cn(
182 'min-h-[72px] font-mono text-xs',
183 jsonErrorMessage && 'border-destructive',
184 )}
185 onChange={(event) => onChange(event.target.value)}
186 onBlur={onCommit}
187 onKeyDown={onKeyDown}
188 />
189 <p className="text-xs text-muted-foreground">{t('table.arrayHint')}</p>
190 {jsonErrorMessage ? (
191 <p className="text-xs text-destructive">{jsonErrorMessage}</p>
192 ) : null}

Callers

nothing calls this directly

Calls 5

formatValueForInputFunction · 0.90
parseDraftValueFunction · 0.90
cnFunction · 0.90
validateArrayJsonFunction · 0.85
formatArrayErrorFunction · 0.85

Tested by

no test coverage detected