Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
lanzhenw committed Oct 7, 2024
1 parent f80aaef commit 804d0ab
Showing 1 changed file with 56 additions and 108 deletions.
164 changes: 56 additions & 108 deletions app/packages/core/src/plugins/SchemaIO/components/DropdownView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,52 +122,6 @@ export default function DropdownView(props: ViewPropsType) {
}
);

// const { MenuProps = {}, ...selectProps } = getComponentProps(
// props,
// "select",
// {
// sx: {
// // custom input style for icon only control
// ...(icon
// ? {
// "&.MuiInputBase-root.MuiOutlinedInput-root.MuiInputBase-colorPrimary": {
// backgroundColor: "transparent !important",
// borderRadius: "0 !important",
// border: "none !important",
// boxShadow: "none !important",
// "&:hover, &:focus": {
// backgroundColor: "transparent !important",
// boxShadow: "none !important",
// },
// },
// "& .MuiSelect-select": {
// padding: 0,
// background: "transparent",
// "&:focus": {
// background: "transparent",
// },
// },
// "& .MuiInputBase-root": {
// background: "transparent",
// },
// "& .MuiOutlinedInput-notchedOutline": {
// border: "none",
// },
// "& .MuiSelect-icon": {
// display: "none",
// },
// }
// : {
// ".MuiSelect-select": {
// padding: "0.45rem 2rem 0.45rem 1rem",
// opacity: selected ? 1 : 0.5,
// },
// }),
// ...getFieldSx({ color, variant }),
// },
// }
// );

// dynamically import the icon component
useEffect(() => {
if (icon && iconImports[icon]) {
Expand All @@ -187,69 +141,63 @@ export default function DropdownView(props: ViewPropsType) {
);
};

const renderMenuDropdown = () => (
<Select
key={key}
disabled={readOnly}
autoFocus={autoFocus(props)}
defaultValue={computedDefaultValue}
size="small"
fullWidth
displayEmpty
title={compact ? description : undefined}
renderValue={(value) => {
if (icon) {
return renderIcon();
}
const unselected = value?.length === 0;
setSelected(!unselected);
if (unselected) {
if (compact) {
return placeholder || label;
}
return placeholder;
}
if (multiple) {
return value.map((item) => choiceLabels[item] || item).join(", ");
}
return choiceLabels[value] || value;
}}
onChange={(e) => {
const value = e.target.value;
const computedValue =
Array.isArray(value) && type !== "array"
? value.join(separator)
: value;
onChange(path, computedValue);
setUserChanged();
}}
multiple={multiple}
{...selectProps}
MenuProps={{
...MenuProps,
sx: {
zIndex: (theme) => theme.zIndex.operatorPalette + 1,
...(MenuProps?.sx || {}),
},
}}
>
{choices.map(({ value, ...choice }) => (
<MenuItem
key={value}
value={value}
{...getComponentProps(props, "optionContainer")}
>
<ChoiceMenuItemBody {...choice} {...props} />
</MenuItem>
))}
</Select>
);

return icon ? (
renderMenuDropdown()
) : (
return (
<FieldWrapper {...props} hideHeader={compact}>
{renderMenuDropdown()}
<Select
key={key}
disabled={readOnly}
autoFocus={autoFocus(props)}
defaultValue={computedDefaultValue}
size="small"
fullWidth
displayEmpty
title={compact ? description : undefined}
renderValue={(value) => {
if (icon) {
return renderIcon();
}
const unselected = value?.length === 0;
setSelected(!unselected);
if (unselected) {
if (compact) {
return placeholder || label;
}
return placeholder;
}
if (multiple) {
return value.map((item) => choiceLabels[item] || item).join(", ");
}
return choiceLabels[value] || value;
}}
onChange={(e) => {
const value = e.target.value;
const computedValue =
Array.isArray(value) && type !== "array"
? value.join(separator)
: value;
onChange(path, computedValue);
setUserChanged();
}}
multiple={multiple}
{...selectProps}
MenuProps={{
...MenuProps,
sx: {
zIndex: (theme) => theme.zIndex.operatorPalette + 1,
...(MenuProps?.sx || {}),
},
}}
>
{choices.map(({ value, ...choice }) => (
<MenuItem
key={value}
value={value}
{...getComponentProps(props, "optionContainer")}
>
<ChoiceMenuItemBody {...choice} {...props} />
</MenuItem>
))}
</Select>
</FieldWrapper>
);
}

0 comments on commit 804d0ab

Please sign in to comment.