Skip to content

Commit

Permalink
fix: remove duplicate dropdown custom renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
dcshzj committed Jul 18, 2024
1 parent 549ceae commit 3457c9c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,31 @@ export function JsonFormsAnyOfControl({
uischemas,
)

const variants = anyOfRenderInfos.map((anyOfRenderInfo) => ({
label: anyOfRenderInfo.label,
value: anyOfRenderInfo.label,
}))
const variants = anyOfRenderInfos.map((anyOfRenderInfo) => {
const option = String(anyOfRenderInfo.schema.const || anyOfRenderInfo.label)

return {
label: option.charAt(0).toUpperCase() + option.slice(1),
value: option,
}
})

const [variant, setVariant] = useState(anyOfRenderInfos[0]?.label || "")

return (
<Box py={2}>
<FormControl isRequired>
<FormLabel>Variant</FormLabel>
<SingleSelect
value={variant}
name={label}
items={variants}
isClearable={false}
onChange={setVariant}
/>
</FormControl>
<>
<Box py={2}>
<FormControl isRequired>
<FormLabel>{label || "Variant"}</FormLabel>
<SingleSelect
value={variant}
name={label}
items={variants}
isClearable={false}
onChange={setVariant}
/>
</FormControl>
</Box>

{anyOfRenderInfos.map(
(anyOfRenderInfo) =>
Expand All @@ -68,7 +74,7 @@ export function JsonFormsAnyOfControl({
/>
),
)}
</Box>
</>
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function JsonFormsDropdownControl({
}: ControlProps & OwnPropsOfEnum) {
const [dropdownValue, setDropdownValue] = useState(data || "")

if (!options || (options.length === 1 && !!schema.default)) {
if (!options || (options.length === 1 && !!schema.const)) {
return null
}

Expand Down

0 comments on commit 3457c9c

Please sign in to comment.