Skip to content

Commit

Permalink
Add onConfirm for items (not locations)
Browse files Browse the repository at this point in the history
  • Loading branch information
tischsoic committed Nov 27, 2024
1 parent 6308826 commit 234bf22
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 90 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
import React, { useContext } from 'react';
import React, { useCallback, useContext } from 'react';

import { AllowConfirmationContext, ConfirmContext, CancelContext, SelectedLocationsContext } from '../../universal.discovery.module';
import {
AllowConfirmationContext,
ConfirmContext,
CancelContext,
SelectedLocationsContext,
SelectedItemsContext,
ConfirmItemsContext,
} from '../../universal.discovery.module';
import { getTranslator } from '@ibexa-admin-ui/src/bundle/Resources/public/js/scripts/helpers/context.helper';

const ActionsMenu = () => {
const Translator = getTranslator();
const onConfirm = useContext(ConfirmContext);
const onItemsConfirm = useContext(ConfirmItemsContext);
const cancelUDW = useContext(CancelContext);
const allowConfirmation = useContext(AllowConfirmationContext);
const [selectedLocations] = useContext(SelectedLocationsContext);
const { selectedItems } = useContext(SelectedItemsContext);
const confirmLabel = Translator.trans(/*@Desc("Confirm")*/ 'actions_menu.confirm', {}, 'ibexa_universal_discovery_widget');
const cancelLabel = Translator.trans(/*@Desc("Discard")*/ 'actions_menu.cancel', {}, 'ibexa_universal_discovery_widget');
const isConfirmDisabled = selectedLocations.length === 0;
const isConfirmDisabled = selectedLocations.length === 0 && selectedItems.length === 0;
const handleConfirmBtnClick = useCallback(() => {
if (selectedLocations.length > 0) {
onConfirm();

return;
}

onItemsConfirm();
}, [onConfirm, selectedLocations, onItemsConfirm, selectedItems]);
const renderActionsContent = () => {
if (!allowConfirmation) {
return null;
Expand All @@ -23,7 +41,7 @@ const ActionsMenu = () => {
<button
className="c-actions-menu__confirm-btn btn ibexa-btn ibexa-btn--primary"
type="button"
onClick={() => onConfirm()}
onClick={handleConfirmBtnClick}
disabled={isConfirmDisabled}
>
{confirmLabel}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const checkIsItemSelected = (selectedItems, item) =>
const filterOutSelectedItems = (selectedItems, items) => items.filter((item) => !checkIsItemSelected(selectedItems, item));

const checkIsValidSelection = (items, isMultiple, multipleItemsLimit) =>
(!isMultiple && items.length > 1) || (isMultiple && items.length > multipleItemsLimit);
(!isMultiple && items.length > 1) || (isMultiple && multipleItemsLimit !== 0 && items.length > multipleItemsLimit);

const selectedItemsReducer = (state, action) => {
const { items, isMultiple, multipleItemsLimit } = state;
Expand Down
Loading

0 comments on commit 234bf22

Please sign in to comment.