feat: use visible before use component props (#1182)

Co-authored-by: sealday <sealday@gmail.com>
Reviewed-on: daoyoucloud/tachybase#1182
This commit is contained in:
sealday 2024-06-13 13:21:43 +08:00
parent 1472e5910c
commit 725b466d62
2 changed files with 13 additions and 5 deletions

View File

@ -1,5 +1,6 @@
import React, { FC, memo, useEffect, useMemo, useRef } from 'react'; import React, { FC, memo, useEffect, useMemo, useRef } from 'react';
import { useFieldComponentName } from '../../../common/useFieldComponentName';
import { useFindComponent } from '../../../schema-component'; import { useFindComponent } from '../../../schema-component';
import { import {
SchemaSettingsActionModalItem, SchemaSettingsActionModalItem,
@ -17,7 +18,6 @@ import {
} from '../../../schema-settings/SchemaSettings'; } from '../../../schema-settings/SchemaSettings';
import { SchemaSettingItemContext } from '../context'; import { SchemaSettingItemContext } from '../context';
import { SchemaSettingsItemType } from '../types'; import { SchemaSettingsItemType } from '../types';
import { useFieldComponentName } from '../../../common/useFieldComponentName';
export interface SchemaSettingsChildrenProps { export interface SchemaSettingsChildrenProps {
children: SchemaSettingsItemType[]; children: SchemaSettingsItemType[];
@ -70,6 +70,15 @@ export const SchemaSettingsChildren: FC<SchemaSettingsChildrenProps> = (props) =
const useChildrenDefault = () => undefined; const useChildrenDefault = () => undefined;
const useComponentPropsDefault = () => undefined; const useComponentPropsDefault = () => undefined;
const useVisibleDefault = () => true; const useVisibleDefault = () => true;
const InternalComponent = ({ Component, componentProps, useComponentProps, children }) => {
const useComponentPropsRes = useComponentProps();
return (
<Component {...componentProps} {...useComponentPropsRes}>
{children}
</Component>
);
};
export const SchemaSettingsChild: FC<SchemaSettingsItemType> = memo((props) => { export const SchemaSettingsChild: FC<SchemaSettingsItemType> = memo((props) => {
const { const {
useVisible = useVisibleDefault, useVisible = useVisibleDefault,
@ -82,7 +91,6 @@ export const SchemaSettingsChild: FC<SchemaSettingsItemType> = memo((props) => {
componentProps, componentProps,
} = props as any; } = props as any;
const useChildrenRes = useChildren(); const useChildrenRes = useChildren();
const useComponentPropsRes = useComponentProps();
const findComponent = useFindComponent(); const findComponent = useFindComponent();
const componentChildren = useMemo(() => { const componentChildren = useMemo(() => {
const res = [...(useChildrenRes || []), ...(children || [])]; const res = [...(useChildrenRes || []), ...(children || [])];
@ -106,11 +114,11 @@ export const SchemaSettingsChild: FC<SchemaSettingsItemType> = memo((props) => {
return ( return (
<SchemaSettingItemContext.Provider value={props}> <SchemaSettingItemContext.Provider value={props}>
<C {...componentProps} {...useComponentPropsRes}> <InternalComponent Component={C} useComponentProps={useComponentProps} componentProps={componentProps}>
{Array.isArray(componentChildren) && componentChildren.length > 0 && ( {Array.isArray(componentChildren) && componentChildren.length > 0 && (
<SchemaSettingsChildren>{componentChildren}</SchemaSettingsChildren> <SchemaSettingsChildren>{componentChildren}</SchemaSettingsChildren>
)} )}
</C> </InternalComponent>
</SchemaSettingItemContext.Provider> </SchemaSettingItemContext.Provider>
); );
}); });

View File

@ -195,7 +195,7 @@ export const InternalTabs = observer((props) => {
if (fuzzysearch(filter, item?.label) || filterItem?.length) { if (fuzzysearch(filter, item?.label) || filterItem?.length) {
return { return {
...item, ...item,
childrenItems: filterItem.length ? filterItem : item.childrenItems, childrenItems: filterItem?.length ? filterItem : item.childrenItems,
}; };
} }
}) })