Skip to content

Commit

Permalink
fix: prop control to filter out experience content types
Browse files Browse the repository at this point in the history
  • Loading branch information
YvesRijckaert committed Oct 14, 2024
1 parent 05beff8 commit dbdb5c7
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ interface CreateEntryMenuTrigger {
customDropdownItems?: React.ReactNode;
children: CreateEntryMenuTriggerChild;
menuProps?: Omit<MenuProps, 'children'>;
filterExperienceTypes?: boolean;
}

export const CreateEntryMenuTrigger = ({
Expand All @@ -87,6 +88,7 @@ export const CreateEntryMenuTrigger = ({
customDropdownItems,
children,
menuProps,
filterExperienceTypes = true,
}: CreateEntryMenuTrigger) => {
const [isOpen, setOpen] = useState(false);
const [isSelecting, setSelecting] = useState(false);
Expand All @@ -107,13 +109,15 @@ export const CreateEntryMenuTrigger = ({
// Filter out content types with the Contentful:ExperienceType annotation
const filteredContentTypes = useMemo(
() =>
contentTypes.filter((contentType) => {
const annotations = get(contentType, 'metadata.annotations.ContentType', []);
return !annotations.some(
(annotation) => get(annotation, 'sys.id') === 'Contentful:ExperienceType'
);
}),
[contentTypes]
filterExperienceTypes
? contentTypes.filter((contentType) => {
const annotations = get(contentType, 'metadata.annotations.ContentType', []);
return !annotations.some(
(annotation) => get(annotation, 'sys.id') === 'Contentful:ExperienceType'
);
})
: contentTypes,
[contentTypes, filterExperienceTypes]
);

const hasDropdown = contentTypes.length > 1 || !!customDropdownItems;
Expand Down Expand Up @@ -258,4 +262,5 @@ export const CreateEntryMenuTrigger = ({
CreateEntryMenuTrigger.defaultProps = {
testId: 'create-entry-button-menu-trigger',
contentTypesLabel: 'All Content Types',
filterExperienceTypes: true,
};

0 comments on commit dbdb5c7

Please sign in to comment.