fix: fix the disappearing collections when searching (#3750)

This commit is contained in:
Zeke Zhang 2024-03-19 09:00:01 +08:00 committed by GitHub
parent 86d2538a43
commit 368036923f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 18 additions and 14 deletions

View File

@ -14,6 +14,7 @@ export const DetailsBlockInitializer = ({
createBlockSchema, createBlockSchema,
templateWrap, templateWrap,
showAssociationFields, showAssociationFields,
hideChildrenIfSingleCollection,
}: { }: {
filterCollections: (options: { collection?: Collection; associationField?: CollectionFieldOptions }) => boolean; filterCollections: (options: { collection?: Collection; associationField?: CollectionFieldOptions }) => boolean;
onlyCurrentDataSource: boolean; onlyCurrentDataSource: boolean;
@ -33,6 +34,7 @@ export const DetailsBlockInitializer = ({
}, },
) => any; ) => any;
showAssociationFields?: boolean; showAssociationFields?: boolean;
hideChildrenIfSingleCollection?: boolean;
}) => { }) => {
const { insert } = useSchemaInitializer(); const { insert } = useSchemaInitializer();
const { getCollection } = useCollectionManager_deprecated(); const { getCollection } = useCollectionManager_deprecated();
@ -66,6 +68,7 @@ export const DetailsBlockInitializer = ({
filter={filterCollections} filter={filterCollections}
templateWrap={templateWrap} templateWrap={templateWrap}
showAssociationFields={showAssociationFields} showAssociationFields={showAssociationFields}
hideChildrenIfSingleCollection={hideChildrenIfSingleCollection}
/> />
); );
}; };

View File

@ -13,6 +13,7 @@ export const FormBlockInitializer = ({
componentType = 'FormItem', componentType = 'FormItem',
templateWrap, templateWrap,
showAssociationFields, showAssociationFields,
hideChildrenIfSingleCollection,
}: { }: {
filterCollections: (options: { collection?: Collection; associationField?: CollectionFieldOptions }) => boolean; filterCollections: (options: { collection?: Collection; associationField?: CollectionFieldOptions }) => boolean;
onlyCurrentDataSource: boolean; onlyCurrentDataSource: boolean;
@ -31,6 +32,7 @@ export const FormBlockInitializer = ({
}, },
) => any; ) => any;
showAssociationFields?: boolean; showAssociationFields?: boolean;
hideChildrenIfSingleCollection?: boolean;
}) => { }) => {
const { insert } = useSchemaInitializer(); const { insert } = useSchemaInitializer();
const itemConfig = useSchemaInitializerItem(); const itemConfig = useSchemaInitializerItem();
@ -80,6 +82,7 @@ export const FormBlockInitializer = ({
onlyCurrentDataSource={onlyCurrentDataSource} onlyCurrentDataSource={onlyCurrentDataSource}
hideSearch={hideSearch} hideSearch={hideSearch}
showAssociationFields={showAssociationFields} showAssociationFields={showAssociationFields}
hideChildrenIfSingleCollection={hideChildrenIfSingleCollection}
/> />
); );
}; };

View File

@ -9,11 +9,11 @@ import { Collection, CollectionFieldOptions } from '../../../../data-source';
export const FilterCollapseBlockInitializer = ({ export const FilterCollapseBlockInitializer = ({
filterCollections, filterCollections,
onlyCurrentDataSource, onlyCurrentDataSource,
showChildren, hideChildrenIfSingleCollection,
}: { }: {
filterCollections: (options: { collection?: Collection; associationField?: CollectionFieldOptions }) => boolean; filterCollections: (options: { collection?: Collection; associationField?: CollectionFieldOptions }) => boolean;
onlyCurrentDataSource: boolean; onlyCurrentDataSource: boolean;
showChildren?: boolean; hideChildrenIfSingleCollection?: boolean;
}) => { }) => {
const itemConfig = useSchemaInitializerItem(); const itemConfig = useSchemaInitializerItem();
const { insert } = useSchemaInitializer(); const { insert } = useSchemaInitializer();
@ -34,7 +34,7 @@ export const FilterCollapseBlockInitializer = ({
insert(schema); insert(schema);
}} }}
filter={filterCollections} filter={filterCollections}
showChildren={showChildren} hideChildrenIfSingleCollection={hideChildrenIfSingleCollection}
/> />
); );
}; };

View File

@ -8,11 +8,11 @@ import { Collection, CollectionFieldOptions } from '../../../../data-source';
export const FilterFormBlockInitializer = ({ export const FilterFormBlockInitializer = ({
filterCollections, filterCollections,
onlyCurrentDataSource, onlyCurrentDataSource,
showChildren, hideChildrenIfSingleCollection,
}: { }: {
filterCollections: (options: { collection?: Collection; associationField?: CollectionFieldOptions }) => boolean; filterCollections: (options: { collection?: Collection; associationField?: CollectionFieldOptions }) => boolean;
onlyCurrentDataSource: boolean; onlyCurrentDataSource: boolean;
showChildren?: boolean; hideChildrenIfSingleCollection?: boolean;
}) => { }) => {
const itemConfig = useSchemaInitializerItem(); const itemConfig = useSchemaInitializerItem();
const { insert } = useSchemaInitializer(); const { insert } = useSchemaInitializer();
@ -45,7 +45,7 @@ export const FilterFormBlockInitializer = ({
); );
}} }}
filter={filterCollections} filter={filterCollections}
showChildren={showChildren} hideChildrenIfSingleCollection={hideChildrenIfSingleCollection}
/> />
); );
}; };

View File

@ -92,6 +92,7 @@ function useRecordBlocks() {
[templateWrap, templateWrapOfAssociationDetailsWithoutPagination], [templateWrap, templateWrapOfAssociationDetailsWithoutPagination],
), ),
showAssociationFields: true, showAssociationFields: true,
hideChildrenIfSingleCollection: true,
}; };
}, },
}, },
@ -119,6 +120,7 @@ function useRecordBlocks() {
createBlockSchema: createEditFormBlock, createBlockSchema: createEditFormBlock,
templateWrap: templateWrap, templateWrap: templateWrap,
showAssociationFields: true, showAssociationFields: true,
hideChildrenIfSingleCollection: true,
}; };
}, },
useVisible() { useVisible() {
@ -305,7 +307,6 @@ export const recordBlockInitializers_deprecated = new CompatibleSchemaInitialize
} }
}, },
onlyCurrentDataSource: true, onlyCurrentDataSource: true,
showChildren: true,
}; };
}, },
}, },
@ -327,7 +328,6 @@ export const recordBlockInitializers_deprecated = new CompatibleSchemaInitialize
} }
}, },
onlyCurrentDataSource: true, onlyCurrentDataSource: true,
showChildren: true,
}; };
}, },
}, },
@ -404,7 +404,6 @@ export const recordBlockInitializers = new CompatibleSchemaInitializer(
} }
}, },
onlyCurrentDataSource: true, onlyCurrentDataSource: true,
showChildren: true,
}; };
}, },
}, },
@ -426,7 +425,6 @@ export const recordBlockInitializers = new CompatibleSchemaInitializer(
} }
}, },
onlyCurrentDataSource: true, onlyCurrentDataSource: true,
showChildren: true,
}; };
}, },
}, },

View File

@ -275,8 +275,8 @@ export interface DataBlockInitializerProps {
onlyCurrentDataSource?: boolean; onlyCurrentDataSource?: boolean;
hideSearch?: boolean; hideSearch?: boolean;
showAssociationFields?: boolean; showAssociationFields?: boolean;
/** 即使 children 只有一个时,也显示出来 */ /** 如果只有一项数据表时,不显示 children 列表 */
showChildren?: boolean; hideChildrenIfSingleCollection?: boolean;
} }
export const DataBlockInitializer = (props: DataBlockInitializerProps) => { export const DataBlockInitializer = (props: DataBlockInitializerProps) => {
@ -291,7 +291,7 @@ export const DataBlockInitializer = (props: DataBlockInitializerProps) => {
onlyCurrentDataSource, onlyCurrentDataSource,
hideSearch, hideSearch,
showAssociationFields, showAssociationFields,
showChildren, hideChildrenIfSingleCollection,
filterDataSource, filterDataSource,
} = props; } = props;
const { insert, setVisible } = useSchemaInitializer(); const { insert, setVisible } = useSchemaInitializer();
@ -327,7 +327,7 @@ export const DataBlockInitializer = (props: DataBlockInitializerProps) => {
const compiledMenuItems = useMemo(() => { const compiledMenuItems = useMemo(() => {
let children = searchedChildren.filter((item) => item.key !== 'search' && item.key !== 'empty'); let children = searchedChildren.filter((item) => item.key !== 'search' && item.key !== 'empty');
const hasAssociationField = children.some((item) => item.associationField); const hasAssociationField = children.some((item) => item.associationField);
if (!showChildren && !hasAssociationField && children.length === 1) { if (hideChildrenIfSingleCollection && !hasAssociationField && children.length === 1) {
// 只有一项可选时,直接展开 // 只有一项可选时,直接展开
children = children[0].children; children = children[0].children;
} else { } else {