Skip to content
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

Merged
merged 1 commit into from
Nov 25, 2024

Conversation

tischsoic
Copy link
Contributor

@tischsoic tischsoic commented Nov 19, 2024

🎫 Issue IBX-9227

Related PRs:

Description:

For QA:

Documentation:

@tischsoic tischsoic added Bug Something isn't working Ready for review labels Nov 19, 2024
@tischsoic tischsoic self-assigned this Nov 19, 2024
@tischsoic tischsoic changed the base branch from main to 4.6 November 19, 2024 10:38
SelectedLocationsContext,
} from '../universal.discovery.module';

export const useSelectedLocationsHelpers = () => {
Copy link
Contributor Author

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 = () => {
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor Author

@tischsoic tischsoic Nov 20, 2024

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(
Copy link
Contributor

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],
);

Copy link
Contributor Author

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.

@tischsoic tischsoic force-pushed the IBX-9227-multipleItemsLimit-not-respected branch from e750096 to 6602c00 Compare November 20, 2024 11:55
@dew326 dew326 merged commit 56724ee into 4.6 Nov 25, 2024
28 checks passed
@dew326 dew326 deleted the IBX-9227-multipleItemsLimit-not-respected branch November 25, 2024 13:11
@tischsoic
Copy link
Contributor Author

Merged up:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working QA approved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants