Skip to content

Commit

Permalink
After QA
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasOsti committed Jan 10, 2025
1 parent 97587d0 commit 4ce602b
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
title,
startingLocationId,
selectedLocations,
isInitLocationsDeselectionBlocked: true,
...config,
multiple: isSingle ? false : selectedItemsLimit !== 1,
multipleItemsLimit: selectedItemsLimit > 1 ? selectedItemsLimit - selectedItems.length : selectedItemsLimit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,11 @@
.ibexa-icon {
fill: $ibexa-color-dark;
}

&:disabled {
.ibexa-icon {
fill: $ibexa-color-dark-300;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ const FinderLeaf = ({ location }) => {
const contentTypesMap = useContext(ContentTypesMapContext);
const [, dispatchSelectedLocationsAction] = useContext(SelectedLocationsContext);
const [multiple] = useContext(MultipleConfigContext);
const { checkIsSelectable, checkIsSelected, checkIsSelectionBlocked } = useSelectedLocationsHelpers();
const { checkIsSelectable, checkIsSelected, checkIsSelectionBlocked, checkIsDeselectionBlocked } = useSelectedLocationsHelpers();
const isSelected = checkIsSelected(location);
const isNotSelectable = !checkIsSelectable(location);
const isSelectionBlocked = checkIsSelectionBlocked(location);
const isDeselectionBlocked = checkIsDeselectionBlocked(location);
const markLocation = ({ nativeEvent }) => {
const isSelectionButtonClicked = nativeEvent.target.closest('.c-udw-toggle-selection');
const isMarkedLocationClicked = location.id === markedLocationId;
Expand All @@ -49,7 +50,14 @@ const FinderLeaf = ({ location }) => {
}
};
const renderToggleSelection = () => {
return <ToggleSelection location={location} multiple={multiple} isDisabled={isSelectionBlocked} isHidden={isNotSelectable} />;
return (
<ToggleSelection
location={location}
multiple={multiple}
isDisabled={isSelectionBlocked || isDeselectionBlocked}
isHidden={isNotSelectable}
/>
);
};
const className = createCssClassNames({
'c-finder-leaf': true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ const GridViewItem = ({ location, version }) => {
const containersOnly = useContext(ContainersOnlyContext);
const contentTypeInfo = contentTypesMap[location.ContentInfo.Content.ContentType._href];
const { isContainer } = contentTypeInfo;
const { checkIsSelectable, checkIsSelected, checkIsSelectionBlocked } = useSelectedLocationsHelpers();
const { checkIsSelectable, checkIsSelected, checkIsSelectionBlocked, checkIsDeselectionBlocked } = useSelectedLocationsHelpers();
const isSelected = checkIsSelected(location);
const isNotSelectable = !checkIsSelectable(location);
const isSelectionBlocked = checkIsSelectionBlocked(location);
const isDeselectionBlocked = checkIsDeselectionBlocked(location);
const className = createCssClassNames({
'ibexa-grid-view-item': true,
'ibexa-grid-view-item--marked': markedLocationId === location.id,
Expand Down Expand Up @@ -68,7 +69,12 @@ const GridViewItem = ({ location, version }) => {
const renderToggleSelection = () => {
return (
<div className="ibexa-grid-view-item__checkbox">
<ToggleSelection location={location} multiple={multiple} isDisabled={isSelectionBlocked} isHidden={isNotSelectable} />
<ToggleSelection
location={location}
multiple={multiple}
isDisabled={isSelectionBlocked || isDeselectionBlocked}
isHidden={isNotSelectable}
/>
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ import Thumbnail from '../../../common/thumbnail/thumbnail';

import { SelectedLocationsContext, ContentTypesMapContext } from '../../universal.discovery.module';
import { getAdminUiConfig, getTranslator } from '@ibexa-admin-ui/src/bundle/Resources/public/js/scripts/helpers/context.helper';
import { useSelectedLocationsHelpers } from '../../hooks/useSelectedLocationsHelpers';

const SelectedLocationsItem = ({ location, permissions }) => {
const adminUiConfig = getAdminUiConfig();
const Translator = getTranslator();
const refSelectedLocationsItem = useRef(null);
const [, dispatchSelectedLocationsAction] = useContext(SelectedLocationsContext);
const { checkIsDeselectionBlocked } = useSelectedLocationsHelpers();
const isDeselectionBlocked = checkIsDeselectionBlocked(location);
const contentTypesMap = useContext(ContentTypesMapContext);
const clearLabel = Translator.trans(
/*@Desc("Clear selection")*/ 'selected_locations.clear_selection',
Expand Down Expand Up @@ -65,6 +68,7 @@ const SelectedLocationsItem = ({ location, permissions }) => {
onClick={removeFromSelection}
title={clearLabel}
data-tooltip-container-selector=".c-udw-tab"
disabled={isDeselectionBlocked}
>
<Icon name="discard" extraClasses="ibexa-icon--tiny-small" />
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { parse as parseTooltip } from '@ibexa-admin-ui/src/bundle/Resources/publ

import {
UDWContext,
SelectionConfigContext,
SelectedLocationsContext,
RestInfoContext,
MultipleConfigContext,
Expand All @@ -23,19 +24,23 @@ const TreeItemToggleSelection = ({ locationId, isContainer, contentTypeIdentifie
parseTooltip(document.querySelector('.c-list'));
}, []);

if (!isUDW) {
return null;
}

const { isInitLocationsDeselectionBlocked, initSelectedLocations } = useContext(SelectionConfigContext);
const [selectedLocations, dispatchSelectedLocationsAction] = useContext(SelectedLocationsContext);
const [multiple, multipleItemsLimit] = useContext(MultipleConfigContext);
const containersOnly = useContext(ContainersOnlyContext);
const allowedContentTypes = useContext(AllowedContentTypesContext);
const restInfo = useContext(RestInfoContext);

if (!isUDW) {
return null;
}

const isSelected = selectedLocations.some((selectedLocation) => selectedLocation.location.id === locationId);
const isNotSelectable =
(containersOnly && !isContainer) || (allowedContentTypes && !allowedContentTypes.includes(contentTypeIdentifier));
const isSelectionBlocked = multipleItemsLimit !== 0 && !isSelected && selectedLocations.length >= multipleItemsLimit;
const isInitSelectedLocation = initSelectedLocations.includes(locationId);
const isDeselectionBlocked = isSelected && isInitSelectedLocation && isInitLocationsDeselectionBlocked;
const location = {
id: locationId,
};
Expand All @@ -51,7 +56,12 @@ const TreeItemToggleSelection = ({ locationId, isContainer, contentTypeIdentifie

return (
<SelectedLocationsContext.Provider value={[selectedLocations, dispatchSelectedLocationsActionWrapper]}>
<ToggleSelection location={location} multiple={multiple} isDisabled={isSelectionBlocked} isHidden={isNotSelectable} />
<ToggleSelection
location={location}
multiple={multiple}
isDisabled={isSelectionBlocked || isDeselectionBlocked}
isHidden={isNotSelectable}
/>
{isNotSelectable && <div className="c-list-item__prefix-actions-item-empty" />}
</SelectedLocationsContext.Provider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import {
ContentTypesMapContext,
MultipleConfigContext,
SelectedLocationsContext,
SelectionConfigContext,
} from '../universal.discovery.module';

export const useSelectedLocationsHelpers = () => {
const [, multipleItemsLimit] = useContext(MultipleConfigContext);
const contentTypesMap = useContext(ContentTypesMapContext);
const [selectedLocations] = useContext(SelectedLocationsContext);
const { isInitLocationsDeselectionBlocked, initSelectedLocations } = useContext(SelectionConfigContext);
const containersOnly = useContext(ContainersOnlyContext);
const allowedContentTypes = useContext(AllowedContentTypesContext);
const checkIsSelectableWrapped = useCallback(
Expand All @@ -24,10 +26,17 @@ export const useSelectedLocationsHelpers = () => {
(location) => checkIsSelectionBlocked({ location, selectedLocations, multipleItemsLimit }),
[selectedLocations, multipleItemsLimit],
);
const checkIsDeselectionBlockedWrapped = (location) => {
const isLocationSelected = checkIsSelected({ location, selectedLocations });
const isInitSelectedLocation = initSelectedLocations.includes(location.id);

return isLocationSelected && isInitSelectedLocation && isInitLocationsDeselectionBlocked;
};

return {
checkIsSelectable: checkIsSelectableWrapped,
checkIsSelected: checkIsSelectedWrapped,
checkIsSelectionBlocked: checkIsSelectionBlockedWrapped,
checkIsDeselectionBlocked: checkIsDeselectionBlockedWrapped,
};
};
Loading

0 comments on commit 4ce602b

Please sign in to comment.