Skip to content

Commit 589aeef

Browse files
committed
Implement a context selection modal that appears when the find-relevant-files mode is active and token count is zero
- set this [Fragment] only once - current behavior: when changing prompt type to 'find relevant files' we're showing a temporary modal. Expected behavior: the shown modal is non-dismissable for as long as there are some tokens in the context. - current behavior: when changing prompt type to 'find relevant files' we're showing a temporary modal that auto-closes after 3 seconds. Expected behavior: the modal is shown as long as token count is 0. - modal without footer looks like this: - [Fragment] should show 'close' button and be backround-click dismissable
1 parent e00122f commit 589aeef

5 files changed

Lines changed: 39 additions & 26 deletions

File tree

‎apps/editor/src/views/panel/frontend/Main/Main.tsx‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ type Props = {
8181
on_tab_delete: (index: number) => void
8282
missing_web_configuration?: boolean
8383
voice_input_push_to_talk: boolean
84+
token_count: number
8485
}
8586

8687
export const Main: React.FC<Props> = (props) => {
@@ -102,7 +103,6 @@ export const Main: React.FC<Props> = (props) => {
102103
useState<string[]>()
103104
const [find_relevant_files_history, set_find_relevant_files_history] =
104105
useState<string[]>()
105-
const [token_count, set_token_count] = useState<number>(0)
106106
const [chat_edit_format, set_chat_edit_format] = useState<EditFormat>()
107107
const [api_edit_format, set_api_edit_format] = useState<EditFormat>()
108108
const [caret_position_to_set, set_caret_position_to_set] = useState<
@@ -138,9 +138,6 @@ export const Main: React.FC<Props> = (props) => {
138138
set_code_completions_history(message.code_at_cursor || [])
139139
set_find_relevant_files_history(message.find_relevant_files || [])
140140
break
141-
case 'TOKEN_COUNT_UPDATED':
142-
set_token_count(message.token_count)
143-
break
144141
case 'WEB_CONFIGURATION_CREATED':
145142
props.on_web_configuration_edit(message.web_configuration)
146143
break
@@ -671,7 +668,7 @@ export const Main: React.FC<Props> = (props) => {
671668
on_quick_action_click={handle_quick_action_click}
672669
current_selection={props.current_selection}
673670
chat_history={current_history || []}
674-
token_count={token_count}
671+
token_count={props.token_count}
675672
web_prompt_type={props.web_prompt_type}
676673
api_prompt_type={props.api_prompt_type}
677674
context_size_warning_threshold={props.context_size_warning_threshold}

‎apps/editor/src/views/panel/frontend/Panel.tsx‎

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ export const Panel = () => {
8282
handle_tab_change,
8383
handle_new_tab,
8484
handle_tab_delete,
85-
voice_input_push_to_talk
85+
voice_input_push_to_talk,
86+
token_count
8687
} = use_panel(vscode)
8788

8889
const {
@@ -148,27 +149,14 @@ export const Panel = () => {
148149
const { viewing_donations, set_viewing_donations, ...donations_state } =
149150
use_latest_donations()
150151

151-
const prev_active_prompt_type = useRef(
152-
mode == MODE.WEB ? web_prompt_type : api_prompt_type
153-
)
152+
const active_prompt_type = mode == MODE.WEB ? web_prompt_type : api_prompt_type
153+
const [is_find_files_modal_dismissed, set_is_find_files_modal_dismissed] = useState(false)
154154

155155
useEffect(() => {
156-
const active_prompt_type =
157-
mode == MODE.WEB ? web_prompt_type : api_prompt_type
158-
159-
if (
160-
active_prompt_type == 'find-relevant-files' &&
161-
prev_active_prompt_type.current != 'find-relevant-files' &&
162-
prev_active_prompt_type.current !== undefined
163-
) {
164-
set_auto_closing_modal_data({
165-
title:
166-
'Context temporarily cleared, make rough selection on the file tree',
167-
type: 'info'
168-
})
156+
if (active_prompt_type !== 'find-relevant-files' || token_count > 0) {
157+
set_is_find_files_modal_dismissed(false)
169158
}
170-
prev_active_prompt_type.current = active_prompt_type
171-
}, [web_prompt_type, api_prompt_type, mode])
159+
}, [active_prompt_type, token_count])
172160

173161
if (
174162
ask_about_context_instructions === undefined ||
@@ -426,6 +414,7 @@ export const Panel = () => {
426414
on_new_tab={handle_new_tab}
427415
on_tab_delete={handle_tab_delete}
428416
voice_input_push_to_talk={voice_input_push_to_talk}
417+
token_count={token_count}
429418
/>
430419
</div>
431420
<div
@@ -813,6 +802,24 @@ export const Panel = () => {
813802
</div>
814803
)}
815804

805+
{active_prompt_type == 'find-relevant-files' && token_count == 0 && !is_find_files_modal_dismissed && (
806+
<div className={styles.slot}>
807+
<UiModal
808+
title="Make rough context selection"
809+
icon="info"
810+
on_background_click={() => set_is_find_files_modal_dismissed(true)}
811+
footer_slot={
812+
<UiButton
813+
is_secondary
814+
on_click={() => set_is_find_files_modal_dismissed(true)}
815+
>
816+
Close
817+
</UiButton>
818+
}
819+
/>
820+
</div>
821+
)}
822+
816823
{auto_closing_modal_data && (
817824
<div className={styles.slot}>
818825
<UiAutoClosingModal

‎apps/editor/src/views/panel/frontend/hooks/panel/use-panel.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const use_panel = (vscode: any) => {
2828
const [chat_input_focus_key, set_chat_input_focus_key] = useState(0)
2929
const [chat_input_focus_and_select_key, set_chat_input_focus_and_select_key] =
3030
useState(0)
31+
const [token_count, set_token_count] = useState<number>(0)
3132

3233
const {
3334
ask_about_context_instructions,
@@ -156,6 +157,8 @@ export const use_panel = (vscode: any) => {
156157
set_active_view('home')
157158
} else if (message.command == 'VOICE_INPUT_PUSH_TO_TALK') {
158159
set_voice_input_push_to_talk(message.enabled)
160+
} else if (message.command == 'TOKEN_COUNT_UPDATED') {
161+
set_token_count(message.token_count)
159162
}
160163
}
161164
window.addEventListener('message', handle_message)
@@ -292,6 +295,7 @@ export const use_panel = (vscode: any) => {
292295
handle_tab_change,
293296
handle_new_tab,
294297
handle_tab_delete,
295-
voice_input_push_to_talk
298+
voice_input_push_to_talk,
299+
token_count
296300
}
297301
}

‎packages/ui/src/components/editor/panel/modals/Modal/Modal.module.scss‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454
&--with-icon {
5555
padding-top: 6px;
5656
}
57+
58+
&--without-content {
59+
padding-bottom: 16px;
60+
}
5761
}
5862

5963
.scrollable {

‎packages/ui/src/components/editor/panel/modals/Modal/Modal.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ export const Modal: React.FC<Props> = (props) => {
6666
{props.title && (
6767
<div
6868
className={cn(styles.title, {
69-
[styles['title--with-icon']]: !!props.icon
69+
[styles['title--with-icon']]: !!props.icon,
70+
[styles['title--without-content']]: !props.content_slot
7071
})}
7172
>
7273
{props.title}

0 commit comments

Comments
 (0)