mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-10-05 22:22:14 +00:00
fix: update JSON handling in ConfigField component (#480)
* fix: update JSON handling in ConfigField component * cr --------- Co-authored-by: bracesproul <braceasproul@gmail.com>
This commit is contained in:
parent
ed923a98ca
commit
45e1a67171
2 changed files with 9 additions and 17 deletions
|
|
@ -91,9 +91,9 @@ export function ConfigField({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const parsedJson = JSON.parse(jsonString);
|
JSON.parse(jsonString);
|
||||||
|
|
||||||
handleChange(parsedJson);
|
handleChange(jsonString);
|
||||||
setJsonError(null);
|
setJsonError(null);
|
||||||
} catch {
|
} catch {
|
||||||
if (isExternallyManaged && externalSetValue) {
|
if (isExternallyManaged && externalSetValue) {
|
||||||
|
|
@ -108,7 +108,8 @@ export function ConfigField({
|
||||||
const handleFormatJson = (jsonString: string) => {
|
const handleFormatJson = (jsonString: string) => {
|
||||||
try {
|
try {
|
||||||
const parsed = JSON.parse(jsonString);
|
const parsed = JSON.parse(jsonString);
|
||||||
handleChange(parsed);
|
const formattedJson = JSON.stringify(parsed, null, 2);
|
||||||
|
handleChange(formattedJson);
|
||||||
setJsonError(null);
|
setJsonError(null);
|
||||||
} catch {
|
} catch {
|
||||||
setJsonError("Invalid JSON format");
|
setJsonError("Invalid JSON format");
|
||||||
|
|
@ -257,16 +258,13 @@ export function ConfigField({
|
||||||
"border-red-500 focus:border-red-500 focus-visible:ring-red-500",
|
"border-red-500 focus:border-red-500 focus-visible:ring-red-500",
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<div className="flex w-full items-start justify-between gap-2 pt-1">
|
<div className="flex w-full items-center justify-between gap-2 pt-1">
|
||||||
{" "}
|
|
||||||
{/* Use items-start */}
|
{/* Use items-start */}
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={() => handleFormatJson(currentValue ?? "")}
|
onClick={() => handleFormatJson(currentValue ?? "")}
|
||||||
disabled={
|
disabled={!currentValue || typeof currentValue !== "string"}
|
||||||
!currentValue || typeof currentValue !== "string" || !!jsonError
|
|
||||||
}
|
|
||||||
className="mt-1"
|
className="mt-1"
|
||||||
>
|
>
|
||||||
Format
|
Format
|
||||||
|
|
@ -274,15 +272,10 @@ export function ConfigField({
|
||||||
{jsonError && (
|
{jsonError && (
|
||||||
<Alert
|
<Alert
|
||||||
variant="destructive"
|
variant="destructive"
|
||||||
className="flex-grow px-3 py-1"
|
className="flex items-center gap-2 rounded-md py-1"
|
||||||
>
|
>
|
||||||
<div className="flex items-center gap-2">
|
<AlertCircle className="mb-1" />
|
||||||
{" "}
|
<AlertDescription>{jsonError}</AlertDescription>
|
||||||
<AlertCircle className="h-4 w-4 flex-shrink-0" />{" "}
|
|
||||||
<AlertDescription className="text-xs">
|
|
||||||
{jsonError}
|
|
||||||
</AlertDescription>
|
|
||||||
</div>
|
|
||||||
</Alert>
|
</Alert>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -184,7 +184,6 @@ export function ConfigManager() {
|
||||||
step={config.step}
|
step={config.step}
|
||||||
value={configs[DEFAULT_CONFIG_KEY]?.[config.label]}
|
value={configs[DEFAULT_CONFIG_KEY]?.[config.label]}
|
||||||
setValue={(value) => {
|
setValue={(value) => {
|
||||||
console.log("setting value!", value);
|
|
||||||
updateConfig(DEFAULT_CONFIG_KEY, config.label, value);
|
updateConfig(DEFAULT_CONFIG_KEY, config.label, value);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue