feat: fix through collections inherits filter (#1394)

* feat: fix  through collections inherits filter

* feat:  foreignkey disabled when collectionfield override
This commit is contained in:
katherinehhh 2023-01-29 00:11:45 +08:00 committed by GitHub
parent 1272523b12
commit 0d30366aba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 11 deletions

View File

@ -85,7 +85,7 @@ export const ConfigurationTable = () => {
?.filter((item) => !(item.autoCreate && item.isThrough)) ?.filter((item) => !(item.autoCreate && item.isThrough))
.filter((item) => .filter((item) =>
targetScope targetScope
? targetScope['template']?.includes(item.template) || targetScope['name']?.includes(item.name) ? targetScope['template']?.includes(item.template) || targetScope[field.props.name]?.includes(item.name)
: true, : true,
) )
.map((item: any) => ({ .map((item: any) => ({

View File

@ -128,23 +128,26 @@ const getIsOverriding = (currentFields, record) => {
}; };
export const OverridingFieldAction = (props) => { export const OverridingFieldAction = (props) => {
const { scope, getContainer, item: record, children, currentCollection } = props; const { scope, getContainer, item: record, children, currentCollection } = props;
const { target } = record; const { target, through } = record;
const { getInterface, getCurrentCollectionFields, getChildrenCollections } = useCollectionManager(); const { getInterface, getCurrentCollectionFields, getChildrenCollections } = useCollectionManager();
const [visible, setVisible] = useState(false); const [visible, setVisible] = useState(false);
const [schema, setSchema] = useState({}); const [schema, setSchema] = useState({});
const api = useAPIClient(); const api = useAPIClient();
const { t } = useTranslation(); const { t } = useTranslation();
const compile = useCompile(); const compile = useCompile();
const childCollections = const getFilterCollections = (filterKey) => {
target && const childCollections =
getChildrenCollections(target) filterKey &&
?.map((v) => v.name) getChildrenCollections(filterKey)
.concat([target]); ?.map((v) => v.name)
.concat([filterKey]);
return childCollections;
};
const [data, setData] = useState<any>({}); const [data, setData] = useState<any>({});
const currentFields = getCurrentCollectionFields(currentCollection); const currentFields = getCurrentCollectionFields(currentCollection);
const disabled = getIsOverriding(currentFields, record); const disabled = getIsOverriding(currentFields, record);
return ( return (
<RecordProvider record={record}> <RecordProvider record={{ ...record, collectionName: record.__parent.name }}>
<ActionContext.Provider value={{ visible, setVisible }}> <ActionContext.Provider value={{ visible, setVisible }}>
<a <a
//@ts-ignore //@ts-ignore
@ -189,8 +192,9 @@ export const OverridingFieldAction = (props) => {
useCancelAction, useCancelAction,
showReverseFieldConfig: !data?.reverseField, showReverseFieldConfig: !data?.reverseField,
createOnly: true, createOnly: true,
override: true,
isOverride: true, isOverride: true,
targetScope: { name: childCollections }, targetScope: { target: getFilterCollections(target), through: getFilterCollections(through) },
...scope, ...scope,
}} }}
/> />

View File

@ -190,7 +190,7 @@ export const m2m: IField = {
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-component': 'Input', 'x-component': 'Input',
'x-validator': 'uid', 'x-validator': 'uid',
'x-disabled': '{{ !createOnly }}', 'x-disabled': '{{ !createOnly||override }}',
}, },
}, },
}, },
@ -224,7 +224,7 @@ export const m2m: IField = {
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-component': 'Input', 'x-component': 'Input',
'x-validator': 'uid', 'x-validator': 'uid',
'x-disabled': '{{ !createOnly }}', 'x-disabled': '{{ !createOnly||override }}',
}, },
}, },
}, },