de802b1447
This PR removes any V2 naming in state management logic and some minor utils and hooks. It has a lot of changes but nearly all of them were made by the rename functionality of vscode which is deterministic, so it shouldn't introduce any regression. QA has been made on this PR on the main features of the app without any noticeable issue. Also renamed some other v2 naming related items : - TextInputV2 => TextInput - TextInput => SettingsTextInput - ObjectFilterDropdownFilterSelectMenuItemV2 => ObjectFilterDropdownFilterSelectMenuItem - useInitDraftValueV2 => useInitDraftValue - useOpenRecordTableCellV2 => useOpenRecordTableCell
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import { hasUserSelectedCommandState } from '@/command-menu/states/hasUserSelectedCommandState';
|
|
import { useSelectableList } from '@/ui/layout/selectable-list/hooks/useSelectableList';
|
|
import { selectedItemIdComponentState } from '@/ui/layout/selectable-list/states/selectedItemIdComponentState';
|
|
import { useRecoilComponentValue } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValue';
|
|
import { useEffect } from 'react';
|
|
import { useRecoilValue } from 'recoil';
|
|
import { isDefined } from 'twenty-shared/utils';
|
|
|
|
export const CommandMenuDefaultSelectionEffect = ({
|
|
selectableItemIds,
|
|
}: {
|
|
selectableItemIds: string[];
|
|
}) => {
|
|
const { setSelectedItemId } = useSelectableList('command-menu-list');
|
|
|
|
const selectedItemId = useRecoilComponentValue(
|
|
selectedItemIdComponentState,
|
|
'command-menu-list',
|
|
);
|
|
|
|
const hasUserSelectedCommand = useRecoilValue(hasUserSelectedCommandState);
|
|
|
|
useEffect(() => {
|
|
if (
|
|
isDefined(selectedItemId) &&
|
|
selectableItemIds.includes(selectedItemId) &&
|
|
hasUserSelectedCommand
|
|
) {
|
|
return;
|
|
}
|
|
|
|
if (selectableItemIds.length > 0) {
|
|
setSelectedItemId(selectableItemIds[0]);
|
|
}
|
|
}, [
|
|
hasUserSelectedCommand,
|
|
selectableItemIds,
|
|
selectedItemId,
|
|
setSelectedItemId,
|
|
]);
|
|
|
|
return null;
|
|
};
|