Fix refactor selectableList broke hotkey onEnter behavior (#11562)
This commit is contained in:
@ -2,7 +2,7 @@ import { ActionDisplayProps } from '@/action-menu/actions/display/components/Act
|
|||||||
import { getActionLabel } from '@/action-menu/utils/getActionLabel';
|
import { getActionLabel } from '@/action-menu/utils/getActionLabel';
|
||||||
import { CommandMenuItem } from '@/command-menu/components/CommandMenuItem';
|
import { CommandMenuItem } from '@/command-menu/components/CommandMenuItem';
|
||||||
import { SelectableItem } from '@/ui/layout/selectable-list/components/SelectableItem';
|
import { SelectableItem } from '@/ui/layout/selectable-list/components/SelectableItem';
|
||||||
import { useListenToEnterHotkeyOnListItem } from '@/ui/layout/selectable-list/hooks/useListenToEnterHotkeyOnListItem';
|
import { useSelectableListListenToEnterHotkeyOnItem } from '@/ui/layout/selectable-list/hooks/useSelectableListListenToEnterHotkeyOnItem';
|
||||||
import { AppHotkeyScope } from '@/ui/utilities/hotkey/types/AppHotkeyScope';
|
import { AppHotkeyScope } from '@/ui/utilities/hotkey/types/AppHotkeyScope';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { isDefined } from 'twenty-shared/utils';
|
import { isDefined } from 'twenty-shared/utils';
|
||||||
@ -25,7 +25,7 @@ export const ActionListItem = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useListenToEnterHotkeyOnListItem({
|
useSelectableListListenToEnterHotkeyOnItem({
|
||||||
hotkeyScope: AppHotkeyScope.CommandMenuOpen,
|
hotkeyScope: AppHotkeyScope.CommandMenuOpen,
|
||||||
itemId: action.key,
|
itemId: action.key,
|
||||||
onEnter: handleClick,
|
onEnter: handleClick,
|
||||||
|
|||||||
@ -1,21 +1,24 @@
|
|||||||
|
import { SelectableListComponentInstanceContext } from '@/ui/layout/selectable-list/states/contexts/SelectableListComponentInstanceContext';
|
||||||
import { selectedItemIdComponentState } from '@/ui/layout/selectable-list/states/selectedItemIdComponentState';
|
import { selectedItemIdComponentState } from '@/ui/layout/selectable-list/states/selectedItemIdComponentState';
|
||||||
import { useScopedHotkeys } from '@/ui/utilities/hotkey/hooks/useScopedHotkeys';
|
import { useScopedHotkeys } from '@/ui/utilities/hotkey/hooks/useScopedHotkeys';
|
||||||
import { getSnapshotValue } from '@/ui/utilities/recoil-scope/utils/getSnapshotValue';
|
import { getSnapshotValue } from '@/ui/utilities/recoil-scope/utils/getSnapshotValue';
|
||||||
|
import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';
|
||||||
import { isNonEmptyString } from '@sniptt/guards';
|
import { isNonEmptyString } from '@sniptt/guards';
|
||||||
import { useRecoilCallback } from 'recoil';
|
import { useRecoilCallback } from 'recoil';
|
||||||
import { Key } from 'ts-key-enum';
|
import { Key } from 'ts-key-enum';
|
||||||
|
|
||||||
export const useListenToEnterHotkeyOnListItem = ({
|
export const useSelectableListListenToEnterHotkeyOnItem = ({
|
||||||
hotkeyScope,
|
hotkeyScope,
|
||||||
|
|
||||||
itemId,
|
itemId,
|
||||||
onEnter,
|
onEnter,
|
||||||
}: {
|
}: {
|
||||||
hotkeyScope: string;
|
hotkeyScope: string;
|
||||||
|
|
||||||
itemId: string;
|
itemId: string;
|
||||||
onEnter: () => void;
|
onEnter: () => void;
|
||||||
}) => {
|
}) => {
|
||||||
|
const instanceId = useAvailableComponentInstanceIdOrThrow(
|
||||||
|
SelectableListComponentInstanceContext,
|
||||||
|
);
|
||||||
useScopedHotkeys(
|
useScopedHotkeys(
|
||||||
Key.Enter,
|
Key.Enter,
|
||||||
useRecoilCallback(
|
useRecoilCallback(
|
||||||
@ -24,7 +27,7 @@ export const useListenToEnterHotkeyOnListItem = ({
|
|||||||
const selectedItemId = getSnapshotValue(
|
const selectedItemId = getSnapshotValue(
|
||||||
snapshot,
|
snapshot,
|
||||||
selectedItemIdComponentState.atomFamily({
|
selectedItemIdComponentState.atomFamily({
|
||||||
instanceId: itemId,
|
instanceId,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -32,7 +35,7 @@ export const useListenToEnterHotkeyOnListItem = ({
|
|||||||
onEnter?.();
|
onEnter?.();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[itemId, onEnter],
|
[instanceId, itemId, onEnter],
|
||||||
),
|
),
|
||||||
hotkeyScope,
|
hotkeyScope,
|
||||||
[itemId, onEnter],
|
[itemId, onEnter],
|
||||||
Reference in New Issue
Block a user