fix: hide child when useVisible() is false (#3803)

This commit is contained in:
jack zhang 2024-03-23 11:14:56 +08:00 committed by GitHub
parent e82a33f1f7
commit b879d11235
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 8 deletions

View File

@ -72,7 +72,8 @@ export const SchemaInitializerMenu: FC<MenuProps> = (props) => {
export const SchemaInitializerSubMenu: FC<SchemaInitializerSubMenuProps> = (props) => {
const { children, title, name = uid(), onOpenChange, icon, ...others } = props;
const compile = useCompile();
const childrenItems = useSchemaInitializerMenuItems(children, name);
const validChildren = children?.filter((item) => (item.useVisible ? item.useVisible() : true));
const childrenItems = useSchemaInitializerMenuItems(validChildren, name);
const items = useMemo(() => {
return [

View File

@ -35,9 +35,9 @@ export function useSchemaSettingsRender<T = {}>(name: string, options?: UseSchem
}
return {
exists: true,
render: (options2?: UseSchemaSettingsRenderOptions) => {
const key = JSON.stringify(options) || '{}';
if (renderCache.current[key]) {
render: (options2: UseSchemaSettingsRenderOptions = {}) => {
const key = JSON.stringify(options2);
if (key && renderCache.current[key]) {
return renderCache.current[key];
}
return (renderCache.current[key] = React.createElement(SchemaSettingsWrapper, {

View File

@ -40,10 +40,6 @@ export interface SchemaSettingItemGroupType extends SchemaSettingsItemCommon<Sch
type: 'itemGroup';
}
export interface SchemaSettingItemSubMenuType extends SchemaSettingsItemCommon<SchemaSettingsSubMenuProps> {
type: 'subMenu';
}
export interface SchemaSettingItemDividerProps extends SchemaSettingsItemCommon {
type: 'divider';
}
@ -76,6 +72,10 @@ export type SchemaSettingItemActionModalType = SchemaSettingsItemCommon<SchemaSe
type: 'actionModal';
};
export interface SchemaSettingItemSubMenuType extends SchemaSettingsItemCommon<SchemaSettingsSubMenuProps> {
type: 'subMenu';
}
export interface SchemaSettingItemComponentType<T = {}> extends SchemaSettingsItemCommon<T> {
Component: string | ComponentType<T>;
}
@ -90,6 +90,7 @@ export type SchemaSettingItemAllBuiltType =
| SchemaSettingItemModalType
| SchemaSettingItemItemType
| SchemaSettingItemSelectType
| SchemaSettingItemSubMenuType
| SchemaSettingItemGroupType;
export type SchemaSettingsItemType = SchemaSettingItemComponentType | SchemaSettingItemAllBuiltType;