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) => { export const SchemaInitializerSubMenu: FC<SchemaInitializerSubMenuProps> = (props) => {
const { children, title, name = uid(), onOpenChange, icon, ...others } = props; const { children, title, name = uid(), onOpenChange, icon, ...others } = props;
const compile = useCompile(); 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(() => { const items = useMemo(() => {
return [ return [

View File

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

View File

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