Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 32 additions & 19 deletions src/pages/settings/Agents/Fields/EditPromptPage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import CollapsibleHeaderOnKeyboard from '@components/CollapsibleHeaderOnKeyboard';
import FormProvider from '@components/Form/FormProvider';
import InputWrapper from '@components/Form/InputWrapper';
import type {FormInputErrors, FormOnyxValues} from '@components/Form/types';
import type {FormInputErrors, FormOnyxValues, FormRef} from '@components/Form/types';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import Text from '@components/Text';
Expand All @@ -21,14 +21,15 @@ import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavig
import type {SettingsNavigatorParamList} from '@libs/Navigation/types';

import {PROMPT_MAX_HEIGHT_ON_KEYBOARD_OPEN_LANDSCAPE_MODE} from '@pages/settings/Agents/const';
import scrollToMultilineInput from '@pages/settings/Agents/scrollToMultilineInput';

import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';
import INPUT_IDS from '@src/types/form/EditAgentPromptForm';

import {Str} from 'expensify-common';
import React from 'react';
import React, {useRef} from 'react';
import {Platform, View} from 'react-native';

type EditPromptPageProps = PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.SETTINGS.AGENTS.EDIT_PROMPT>;
Expand All @@ -42,6 +43,9 @@ function EditPromptPage({route}: EditPromptPageProps) {
const shouldShrinkPromptInput = isInLandscapeMode && isKeyboardActive;
const accountID = route.params.accountID;
const [agentPrompt] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_AGENT_PROMPT}${accountID}`);
const formRef = useRef<FormRef>(null);
const promptTopOffsetRef = useRef(0);
const handleInputFocus = () => scrollToMultilineInput(formRef, isInLandscapeMode, promptTopOffsetRef.current);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ CONSISTENCY-12 (docs)

The declared function handleInputFocus is named for the event it is wired to (the input's onFocus) rather than the action it performs (scrolling the prompt input into view). Per STYLE.md, a callback's definition should be named for its behavior; the on*/handle* naming belongs on the JSX prop, not the function definition. A behavior-based name keeps the handler searchable by intent and reusable across triggers.

Rename the declaration to describe what it does, e.g.:

const scrollPromptIntoView = () => scrollToMultilineInput(formRef, isInLandscapeMode, promptTopOffsetRef.current);
// ...
<InputWrapper onFocus={scrollPromptIntoView} />

Reviewed at: 0f79840 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.


const validate = (values: FormOnyxValues<typeof ONYXKEYS.FORMS.EDIT_AGENT_PROMPT_FORM>): FormInputErrors<typeof ONYXKEYS.FORMS.EDIT_AGENT_PROMPT_FORM> => {
const errors: FormInputErrors<typeof ONYXKEYS.FORMS.EDIT_AGENT_PROMPT_FORM> = {};
Expand Down Expand Up @@ -88,36 +92,45 @@ function EditPromptPage({route}: EditPromptPageProps) {
/>
</CollapsibleHeaderOnKeyboard>
<FormProvider
ref={formRef}
formID={ONYXKEYS.FORMS.EDIT_AGENT_PROMPT_FORM}
validate={validate}
onSubmit={handleSubmit}
submitButtonText={translate('common.save')}
style={[styles.flex1, styles.ph5]}
shouldUseScrollView={false}
shouldUseScrollView={isInLandscapeMode}
submitFlexEnabled={false}
enabledWhenOffline
shouldHideFixErrorsAlert
shouldValidateOnChange
shouldValidateOnBlur
keyboardSubmitBehavior={CONST.KEYBOARD_SUBMIT_BEHAVIOR.SUBMIT_ONLY}
>
<View style={shouldShrinkPromptInput ? StyleUtils.getHeight(PROMPT_MAX_HEIGHT_ON_KEYBOARD_OPEN_LANDSCAPE_MODE) : [styles.flex1]}>
<InputWrapper
InputComponent={TextInput}
inputID={INPUT_IDS.PROMPT}
label={translate('editAgentPage.instructions')}
accessibilityLabel={translate('editAgentPage.instructions')}
role={CONST.ROLE.PRESENTATION}
type="markdown"
excludedMarkdownStyles={['mentionReport']}
defaultValue={Str.htmlDecode(agentPrompt?.prompt ?? '')}
multiline
containerStyles={[styles.h100]}
touchableInputWrapperStyle={[styles.flex1]}
inputStyle={[styles.flex1, styles.textAlignVerticalTop]}
/>
<View style={[styles.flex1, styles.flexColumn, styles.gap5]}>
<View
style={shouldShrinkPromptInput ? StyleUtils.getHeight(PROMPT_MAX_HEIGHT_ON_KEYBOARD_OPEN_LANDSCAPE_MODE) : [styles.flex1]}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be:

Suggested change
style={shouldShrinkPromptInput ? StyleUtils.getHeight(PROMPT_MAX_HEIGHT_ON_KEYBOARD_OPEN_LANDSCAPE_MODE) : [styles.flex1]}
style={shouldShrinkPromptInput ? StyleUtils.getHeight(PROMPT_MAX_HEIGHT_ON_KEYBOARD_OPEN_LANDSCAPE_MODE) : [isInLandscapeMode ? styles.h42 : styles.flex1]}

here or else it's broken with open keyboard when the prompt is longer:

Screen.Recording.2026-09-09.at.09.19.39.mov

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed here

onLayout={(event) => {
promptTopOffsetRef.current = event.nativeEvent.layout.y;
}}
>
<InputWrapper
InputComponent={TextInput}
inputID={INPUT_IDS.PROMPT}
label={translate('editAgentPage.instructions')}
accessibilityLabel={translate('editAgentPage.instructions')}
role={CONST.ROLE.PRESENTATION}
type="markdown"
excludedMarkdownStyles={['mentionReport']}
defaultValue={Str.htmlDecode(agentPrompt?.prompt ?? '')}
multiline
containerStyles={[styles.h100]}
touchableInputWrapperStyle={[styles.flex1]}
inputStyle={[styles.flex1, styles.textAlignVerticalTop]}
onFocus={handleInputFocus}
/>
</View>
<Text style={[styles.textMicroSupporting, styles.textAlignCenter]}>{translate('workspace.rules.agentRules.disclaimer')}</Text>
</View>
<Text style={[styles.textMicroSupporting, styles.textAlignCenter, styles.mt2]}>{translate('workspace.rules.agentRules.disclaimer')}</Text>
</FormProvider>
</ScreenWrapper>
);
Expand Down
Loading