-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IBX-9227: Restore multipleItemsLimit cehcks in UDW #1396
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,10 @@ | |
} | ||
} | ||
} | ||
|
||
&--not-selectable { | ||
cursor: not-allowed; | ||
} | ||
} | ||
|
||
&__cell:first-child { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export const checkIsSelectable = ({ location, contentTypesMap, allowedContentTypes, containersOnly }) => { | ||
const contentType = contentTypesMap[location.ContentInfo.Content.ContentType._href]; | ||
const { isContainer, identifier } = contentType; | ||
const isAllowedContentType = allowedContentTypes?.includes(identifier) ?? true; | ||
|
||
return (!containersOnly || isContainer) && isAllowedContentType; | ||
}; | ||
|
||
export const checkIsSelected = ({ location, selectedLocations }) => | ||
selectedLocations.some((selectedLocation) => selectedLocation.location.id === location.id); | ||
|
||
export const checkIsSelectionBlocked = ({ location, selectedLocations, multipleItemsLimit }) => | ||
multipleItemsLimit !== 0 && selectedLocations.length >= multipleItemsLimit && !checkIsSelected({ location, selectedLocations }); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { useCallback, useContext } from 'react'; | ||
|
||
import { checkIsSelectable, checkIsSelected, checkIsSelectionBlocked } from '../helpers/selected.locations.helper'; | ||
import { | ||
AllowedContentTypesContext, | ||
ContainersOnlyContext, | ||
ContentTypesMapContext, | ||
MultipleConfigContext, | ||
SelectedLocationsContext, | ||
} from '../universal.discovery.module'; | ||
|
||
export const useSelectedLocationsHelpers = () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer to remove the word There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with Łukasz, I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that naming this hook |
||
const [, multipleItemsLimit] = useContext(MultipleConfigContext); | ||
const contentTypesMap = useContext(ContentTypesMapContext); | ||
const [selectedLocations] = useContext(SelectedLocationsContext); | ||
const containersOnly = useContext(ContainersOnlyContext); | ||
const allowedContentTypes = useContext(AllowedContentTypesContext); | ||
const checkIsSelectableWrapped = useCallback( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have small issue with
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would disagree about cached because there is nothing about caching here, but about wrapping the original helper function so that some parameters are provided by the hook. We can remove |
||
(location) => checkIsSelectable({ location, contentTypesMap, allowedContentTypes, containersOnly }), | ||
[contentTypesMap, allowedContentTypes, containersOnly], | ||
); | ||
const checkIsSelectedWrapped = useCallback((location) => checkIsSelected({ location, selectedLocations }), [selectedLocations]); | ||
const checkIsSelectionBlockedWrapped = useCallback( | ||
(location) => checkIsSelectionBlocked({ location, selectedLocations, multipleItemsLimit }), | ||
[selectedLocations, multipleItemsLimit], | ||
); | ||
|
||
return { | ||
checkIsSelectable: checkIsSelectableWrapped, | ||
checkIsSelected: checkIsSelectedWrapped, | ||
checkIsSelectionBlocked: checkIsSelectionBlockedWrapped, | ||
}; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: I created a hook which wraps helpers so that instead of having to do something like this:
we can do: