Skip to content

Commit

Permalink
Merge pull request #34 from ibexa/merge-IBX-1264-IBX-1267
Browse files Browse the repository at this point in the history
Merge IBX-1264 IBX-1267
  • Loading branch information
dew326 authored Oct 21, 2021
2 parents 132795a + ccf33f9 commit 4b0efb5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/bundle/Resources/public/js/scripts/core/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,14 @@
}

init() {
if (this.container.dataset.initialized) {
console.warn("Dropdown has already been initialized!");

return;
}

this.container.dataset.initialized = true;

const selectedItems = this.getSelectedItems();
const isEmpty = !selectedItems.length;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ContentOnTheFlyConfigContext,
SelectedLocationsContext,
MultipleConfigContext,
ContentTypesMapContext,
} from '../../universal.discovery.module';

const ContentCreateButton = ({ isDisabled }) => {
Expand All @@ -19,6 +20,7 @@ const ContentCreateButton = ({ isDisabled }) => {
const [selectedLocations, dispatchSelectedLocationsAction] = useContext(SelectedLocationsContext);
const [multiple, multipleItemsLimit] = useContext(MultipleConfigContext);
const { hidden, allowedLocations } = useContext(ContentOnTheFlyConfigContext);
const contentTypesMap = useContext(ContentTypesMapContext);
const createLabel = Translator.trans(/*@Desc("Create")*/ 'create_content.create', {}, 'universal_discovery_widget');
const toggleContentCreateVisibility = () => {
window.eZ.helpers.tooltips.hideAll();
Expand All @@ -32,12 +34,14 @@ const ContentCreateButton = ({ isDisabled }) => {
);
}

const contentTypeInfo = contentTypesMap[selectedLocation?.location?.ContentInfo.Content.ContentType._href];
const isAllowedLocation = selectedLocation && (!allowedLocations || allowedLocations.includes(selectedLocation.parentLocationId));
const hasAccess =
!selectedLocation ||
!selectedLocation.permissions ||
(selectedLocation.permissions && selectedLocation.permissions.create.hasAccess);
const isLimitReached = multiple && multipleItemsLimit !== 0 && selectedLocations.length >= multipleItemsLimit;
const isContainer = contentTypeInfo?.isContainer ?? true;

if (hidden) {
return null;
Expand All @@ -47,7 +51,7 @@ const ContentCreateButton = ({ isDisabled }) => {
<div className="c-content-create-button">
<button
className="c-content-create-button__btn btn ibexa-btn ibexa-btn--ghost ibexa-btn--no-text"
disabled={isDisabled || !hasAccess || !isAllowedLocation || isLimitReached}
disabled={isDisabled || !hasAccess || !isAllowedLocation || isLimitReached || !isContainer}
onClick={toggleContentCreateVisibility}
data-tooltip-container-selector=".c-top-menu"
title={createLabel}>
Expand Down

0 comments on commit 4b0efb5

Please sign in to comment.