-
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
Conversation
SelectedLocationsContext, | ||
} from '../universal.discovery.module'; | ||
|
||
export const useSelectedLocationsHelpers = () => { |
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:
import { checkIsSelectable, checkIsSelected, checkIsSelectionBlocked } from '../../helpers/locations.helper';
import {
ContentTypesMapContext,
SelectedLocationsContext,
MultipleConfigContext,
ContainersOnlyContext,
AllowedContentTypesContext,
} from '../../universal.discovery.module';
const contentTypesMap = useContext(ContentTypesMapContext);
const [selectedLocations] = useContext(SelectedLocationsContext);
const [multipleItemsLimit] = useContext(MultipleConfigContext);
const containersOnly = useContext(ContainersOnlyContext);
const allowedContentTypes = useContext(AllowedContentTypesContext);
const isSelected = checkIsSelected({ location, selectedLocations });
const isNotSelectable = !checkIsSelectable({ location, contentTypesMap, allowedContentTypes, containersOnly });
const isSelectionBlocked = checkIsSelectionBlocked({ location, selectedLocations, multipleItemsLimit });
we can do:
import { useSelectedLocationsHelpers } from '../../hooks/useSelectedLocationsHelpers';
const { checkIsSelectable, checkIsSelected, checkIsSelectionBlocked } = useSelectedLocationsHelpers();
const isSelected = checkIsSelected(location);
const isNotSelectable = !checkIsSelectable(location);
const isSelectionBlocked = checkIsSelectionBlocked(location);
SelectedLocationsContext, | ||
} from '../universal.discovery.module'; | ||
|
||
export const useSelectedLocationsHelpers = () => { |
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.
I would prefer to remove the word Helper
from useSelectedLocationsHelpers
because at the hooks directory level we have a helpers directory with helpers and this can be confusing
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.
I agree with Łukasz, I think Helper
isn't even needed
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.
I think that naming this hook useSelectedLocations
would be more confusing because with such a name I would expect that the hook would return data about selected locations. But instead, it returns helpers so I think that useSelectedLocationsHelpers
precisely says what we have here and removing Helpers
from its name would make it more confusing.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
I have small issue with Wrapped
, with current name it can be read as check if IsSelectable wrapped
maybe cachedCheckIsSelectable
, or more complex
import { checkIsSelectable: checkIsSelectableHelper } from '../helpers/selected.locations.helper';
...
const checkIsSelectableWrapped = useCallback(
(location) => checkIsSelectableHelper({ location, contentTypesMap, allowedContentTypes, containersOnly }),
[contentTypesMap, allowedContentTypes, containersOnly],
);
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.
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 useCallback
here and the hook would still be valid.
e750096
to
6602c00
Compare
Quality Gate passedIssues Measures |
Merged up:
|
Related PRs:
Description:
For QA:
Documentation: