Skip to content

Commit

Permalink
update method for dicts that aren't strings
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasStordeur committed Apr 30, 2024
1 parent 036e6f7 commit b59f748
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Test/Data/ServiceInstance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const nestedEditable: ServiceInstanceModelWithTargetStates = {
{
my_attr: 0,
bool_attr: null,
dict_attr: { a: "b" },
dict_attr: {},
embedded_single: { attr4: [2, 4] },
},
],
Expand Down
11 changes: 10 additions & 1 deletion src/UI/Components/ServiceInstanceForm/Components/FieldInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,17 @@ export const FieldInput: React.FC<Props> = ({
const [suggestionsList, setSuggestionsList] = useState<string[] | null>(null);

// Get the controlled value for the field
// If the value is an object or an array, it needs to be converted.
function getControlledValue(value) {
return value !== null && value !== undefined ? value : "";
if (value === null || value === undefined) {
return "";
} else if (Array.isArray(value)) {
return value.join(", ");
} else if (typeof value === "object") {
return JSON.stringify(value);
} else {
return value;
}
}

//callback was used to avoid re-render in useEffect used in SelectFormInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ test("Given createEditFormState v1 WHEN passed editable nested fields and curren
},
my_attr: 0,
bool_attr: null,
dict_attr: '{"a":"b"}',
dict_attr: "{}",
},
],
});
Expand Down

0 comments on commit b59f748

Please sign in to comment.