Skip to content

Commit

Permalink
refactor: move callbacks in separate function declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
Devessier committed Dec 3, 2024
1 parent aafb8b1 commit 943dca6
Showing 1 changed file with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,29 @@ export const FormSelectFieldInput = ({
onPersist(variableName);
};

const handleDisplayModeClick = () => {
if (draftValue.type !== 'static') {
throw new Error(
'This function can only be called when editing a static value.',
);
}

setDraftValue({
...draftValue,
editingMode: 'edit',
});

setHotkeyScopeAndMemorizePreviousScope(hotkeyScope);
};

const handleSelectEnter = (itemId: string) => {
const option = filteredOptions.find((option) => option.value === itemId);
if (isDefined(option)) {
onSubmit(option.value);
resetSelectedItem();
}
};

useScopedHotkeys(
Key.Escape,
() => {
Expand Down Expand Up @@ -187,14 +210,7 @@ export const FormSelectFieldInput = ({
<>
<StyledDisplayModeContainer
data-open={draftValue.editingMode === 'edit'}
onClick={() => {
setDraftValue({
...draftValue,
editingMode: 'edit',
});

setHotkeyScopeAndMemorizePreviousScope(hotkeyScope);
}}
onClick={handleDisplayModeClick}
>
<VisibilityHidden>Edit</VisibilityHidden>

Expand All @@ -212,15 +228,7 @@ export const FormSelectFieldInput = ({
selectableListId={SINGLE_RECORD_SELECT_BASE_LIST}
selectableItemIdArray={optionIds}
hotkeyScope={hotkeyScope}
onEnter={(itemId) => {
const option = filteredOptions.find(
(option) => option.value === itemId,
);
if (isDefined(option)) {
onSubmit(option.value);
resetSelectedItem();
}
}}
onEnter={handleSelectEnter}
>
<SelectInput
parentRef={selectWrapperRef}
Expand Down

0 comments on commit 943dca6

Please sign in to comment.