Skip to content

Commit

Permalink
Merge pull request strapi#11681 from strapi/fix/ctb-relation-target
Browse files Browse the repository at this point in the history
Fix target relation field (CTB)
  • Loading branch information
HichamELBSI authored Nov 25, 2021
2 parents 4cd5c4d + 5a9cbf7 commit 8f9cf38
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const FormModal = () => {
useEffect(() => {
if (isOpen) {
const collectionTypesForRelation = sortedContentTypesList.filter(
({ kind }) => kind === 'collectionType'
({ kind, visible }) => kind === 'collectionType' && visible
);

// Reset all the modification when opening the edit category modal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo } from 'react';
import React from 'react';
import PropTypes from 'prop-types';
import { useDispatch } from 'react-redux';
import get from 'lodash/get';
Expand All @@ -10,25 +10,17 @@ const RelationTargetPicker = ({ oneThatIsCreatingARelationWithAnother, target })
const { contentTypes, sortedContentTypesList } = useDataManager();
const dispatch = useDispatch();
// TODO: replace with an obj { relation: 'x', bidirctional: true|false }
const allowedContentTypesForRelation = useMemo(
() =>
sortedContentTypesList
.filter(obj => obj.kind === 'collectionType')
.filter(
obj =>
obj.restrictRelationsTo === null ||
(Array.isArray(obj.restrictRelationsTo) && obj.restrictRelationsTo.length > 0)
),
[sortedContentTypesList]
);
const allowedContentTypesForRelation = sortedContentTypesList
.filter(obj => obj.kind === 'collectionType' && obj.visible)
.filter(
obj =>
obj.restrictRelationsTo === null ||
(Array.isArray(obj.restrictRelationsTo) && obj.restrictRelationsTo.length > 0)
);

const plugin = get(contentTypes, [target, 'plugin'], null);

const targetFriendlyName = useMemo(() => {
const name = get(contentTypes, [target, 'schema', 'displayName'], 'error');

return name;
}, [contentTypes, target]);
const targetFriendlyName = get(contentTypes, [target, 'schema', 'displayName'], 'error');

return (
<SimpleMenu
Expand Down

0 comments on commit 8f9cf38

Please sign in to comment.