Skip to content

Commit 2b594d6

Browse files
committed
Consolidate prompt validation warnings into a single prop and remove the deprecated context selection modal
- create hook for frf modal - instead of showing 'make a rough context selection', show warning inside the prompt field - Warnings should be set outside the prompt field via 'warning' prop. - [Pasted text]
1 parent 2620ca9 commit 2b594d6

5 files changed

Lines changed: 93 additions & 102 deletions

File tree

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

Lines changed: 63 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ type Props = {
6666
api_edit_format: EditFormat
6767
on_chat_edit_format_change: (edit_format: EditFormat) => void
6868
on_api_edit_format_change: (edit_format: EditFormat) => void
69-
on_web_configurations_reorder: (reordered_web_configurations: WebConfiguration[]) => void
69+
on_web_configurations_reorder: (
70+
reordered_web_configurations: WebConfiguration[]
71+
) => void
7072
on_web_configuration_edit: (web_configuration_name: string) => void
7173
on_duplicate_web_configuration: (index: number) => void
7274
on_delete_web_configuration: (index: number) => void
@@ -152,6 +154,13 @@ const chatbot_to_icon: Record<keyof typeof CHATBOTS, Icon.Variant> = {
152154
export const MainView: React.FC<Props> = (props) => {
153155
const { t } = use_translation()
154156

157+
const is_in_edit_context_prompt_type =
158+
(props.mode == MODE.WEB && props.web_prompt_type == 'edit-context') ||
159+
(props.mode == MODE.API && props.api_prompt_type == 'edit-context')
160+
161+
const is_in_ask_about_context_prompt_type =
162+
props.mode == MODE.WEB && props.web_prompt_type == 'ask-about-context'
163+
155164
const is_in_code_completions_prompt_type =
156165
(props.mode == MODE.WEB && props.web_prompt_type == 'code-at-cursor') ||
157166
(props.mode == MODE.API && props.api_prompt_type == 'code-at-cursor')
@@ -168,6 +177,28 @@ export const MainView: React.FC<Props> = (props) => {
168177
const is_in_no_context_prompt_type =
169178
props.mode == MODE.WEB && props.web_prompt_type == 'no-context'
170179

180+
let warning: string | undefined
181+
if (
182+
(props.mode == MODE.API && props.api_configurations.length == 0) ||
183+
(props.mode == MODE.WEB && props.web_configurations.length == 0)
184+
) {
185+
warning = 'Add a configuration'
186+
} else if (!!props.current_selection && is_in_code_completions_prompt_type) {
187+
warning = 'Remove the text selection'
188+
} else if (
189+
is_in_code_completions_prompt_type &&
190+
!props.currently_open_file_path
191+
) {
192+
warning = 'Open a file'
193+
} else if (
194+
(is_in_edit_context_prompt_type ||
195+
is_in_find_relevant_files_prompt_type ||
196+
is_in_ask_about_context_prompt_type) &&
197+
props.token_count == 0
198+
) {
199+
warning = 'Select context files'
200+
}
201+
171202
const { current_invocation_count, handle_invocation_count_change } =
172203
use_invocation_counts({
173204
mode: props.mode,
@@ -214,23 +245,28 @@ export const MainView: React.FC<Props> = (props) => {
214245

215246
const last_choice_button_title = use_last_choice_button_title({
216247
mode: props.mode,
217-
selected_web_configuration_or_group_name: props.selected_web_configuration_name,
248+
selected_web_configuration_or_group_name:
249+
props.selected_web_configuration_name,
218250
web_configurations: props.web_configurations,
219251
selected_api_configuration_id: props.selected_api_configuration_id,
220252
api_configurations: props.api_configurations
221253
})
222254

223-
const web_configurations: UiConfigurations.Configuration[] = props.web_configurations.map(
224-
(web_configuration, index) => {
225-
const is_unnamed = !web_configuration.name || /^\(\d+\)$/.test(web_configuration.name.trim())
255+
const web_configurations: UiConfigurations.Configuration[] =
256+
props.web_configurations.map((web_configuration, index) => {
257+
const is_unnamed =
258+
!web_configuration.name ||
259+
/^\(\d+\)$/.test(web_configuration.name.trim())
226260
const display_name = is_unnamed
227261
? web_configuration.chatbot!
228262
: web_configuration.name!.replace(/ \(\d+\)$/, '')
229263

230264
const get_details = (): string[] => {
231265
const { chatbot, model, reasoning_effort } = web_configuration
232266
const model_display_name =
233-
model && chatbot ? CHATBOTS[chatbot].models?.[model]?.label || model : null
267+
model && chatbot
268+
? CHATBOTS[chatbot].models?.[model]?.label || model
269+
: null
234270

235271
const details: string[] = []
236272
if (is_unnamed) {
@@ -253,13 +289,14 @@ export const MainView: React.FC<Props> = (props) => {
253289
title: display_name,
254290
details: get_details(),
255291
is_pinned: web_configuration.is_pinned,
256-
icon: web_configuration.chatbot ? chatbot_to_icon[web_configuration.chatbot] : undefined,
292+
icon: web_configuration.chatbot
293+
? chatbot_to_icon[web_configuration.chatbot]
294+
: undefined
257295
}
258-
}
259-
)
296+
})
260297

261-
const api_configurations_ui: UiConfigurations.Configuration[] = props.api_configurations.map(
262-
(c) => {
298+
const api_configurations_ui: UiConfigurations.Configuration[] =
299+
props.api_configurations.map((c) => {
263300
const details = [c.model_provider_name]
264301
if (c.reasoning_effort) {
265302
details.push(`${c.reasoning_effort}`)
@@ -273,8 +310,7 @@ export const MainView: React.FC<Props> = (props) => {
273310
details,
274311
is_pinned: c.is_pinned
275312
}
276-
}
277-
)
313+
})
278314

279315
return (
280316
<>
@@ -393,11 +429,9 @@ export const MainView: React.FC<Props> = (props) => {
393429
on_tab_change={props.on_tab_change}
394430
on_new_tab={props.on_new_tab}
395431
on_tab_delete={props.on_tab_delete}
396-
missing_configuration={
397-
(props.mode == MODE.API && props.api_configurations.length == 0) ||
398-
(props.mode == MODE.WEB && props.web_configurations.length == 0)
399-
}
432+
warning={warning}
400433
voice_input_push_to_talk={props.voice_input_push_to_talk}
434+
token_count={props.token_count}
401435
/>
402436
<UiContextUtilisation
403437
current_context_size={props.token_count}
@@ -436,14 +470,20 @@ export const MainView: React.FC<Props> = (props) => {
436470
props.on_web_configurations_reorder(new_web_configurations)
437471
}}
438472
on_duplicate={(id) => {
439-
const idx = props.web_configurations.findIndex((p, i) => (p.name ?? `unnamed-${i}`) === id)
473+
const idx = props.web_configurations.findIndex(
474+
(p, i) => (p.name ?? `unnamed-${i}`) === id
475+
)
440476
props.on_duplicate_web_configuration(idx)
441477
}}
442478
on_delete={(id) => {
443-
const idx = props.web_configurations.findIndex((p, i) => (p.name ?? `unnamed-${i}`) === id)
479+
const idx = props.web_configurations.findIndex(
480+
(p, i) => (p.name ?? `unnamed-${i}`) === id
481+
)
444482
props.on_delete_web_configuration(idx)
445483
}}
446-
on_toggle_pinned={(id) => props.on_toggle_web_configuration_pinned(id)}
484+
on_toggle_pinned={(id) =>
485+
props.on_toggle_web_configuration_pinned(id)
486+
}
447487
selected_configuration_id={props.selected_web_configuration_name}
448488
is_collapsed={props.web_configurations_collapsed}
449489
on_toggle_collapsed={props.on_web_configurations_collapsed_change}
@@ -468,7 +508,9 @@ export const MainView: React.FC<Props> = (props) => {
468508
<UiConfigurations
469509
configurations={api_configurations_ui}
470510
on_configuration_click={props.on_api_configuration_click}
471-
on_reorder={(reordered) => props.on_api_configurations_reorder(reordered)}
511+
on_reorder={(reordered) =>
512+
props.on_api_configurations_reorder(reordered)
513+
}
472514
on_toggle_pinned={props.on_toggle_pinned_api_configuration}
473515
on_edit={props.on_edit_api_configuration}
474516
on_delete={props.on_delete_api_configuration}

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

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,6 @@ export const Panel = () => {
147147

148148
const active_prompt_type =
149149
mode == MODE.WEB ? web_prompt_type : api_prompt_type
150-
const [is_context_modal_dismissed, set_is_context_modal_dismissed] =
151-
useState(false)
152-
153-
useEffect(() => {
154-
if (active_prompt_type !== 'find-relevant-files') {
155-
set_is_context_modal_dismissed(false)
156-
}
157-
}, [active_prompt_type])
158150

159151
if (
160152
ask_about_context_instructions === undefined ||
@@ -804,26 +796,6 @@ export const Panel = () => {
804796
</div>
805797
)}
806798

807-
{active_prompt_type == 'find-relevant-files' &&
808-
token_count == 0 &&
809-
!is_context_modal_dismissed && (
810-
<div className={styles.slot}>
811-
<UiModal
812-
title="Make context selection"
813-
icon="info"
814-
on_background_click={() => set_is_context_modal_dismissed(true)}
815-
footer_slot={
816-
<UiButton
817-
is_secondary
818-
on_click={() => set_is_context_modal_dismissed(true)}
819-
>
820-
Close
821-
</UiButton>
822-
}
823-
/>
824-
</div>
825-
)}
826-
827799
{auto_closing_modal_data && (
828800
<div className={styles.slot}>
829801
<UiAutoClosingModal

‎packages/ui/src/components/editor/panel/prompts/PromptField/PromptField.stories.tsx‎

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ export const Empty = () => (
4848
on_tab_change={() => {}}
4949
on_new_tab={() => {}}
5050
on_tab_delete={() => {}}
51-
missing_configuration={false}
52-
missing_preset={false}
51+
token_count={0}
5352
/>
5453
)
5554

@@ -96,8 +95,7 @@ export const WithText = () => (
9695
on_tab_change={() => {}}
9796
on_new_tab={() => {}}
9897
on_tab_delete={() => {}}
99-
missing_configuration={false}
100-
missing_preset={false}
98+
token_count={0}
10199
/>
102100
)
103101

@@ -144,8 +142,7 @@ export const LongText = () => (
144142
on_tab_change={() => {}}
145143
on_new_tab={() => {}}
146144
on_tab_delete={() => {}}
147-
missing_configuration={false}
148-
missing_preset={false}
145+
token_count={0}
149146
/>
150147
)
151148

@@ -192,8 +189,7 @@ export const WithPlaceholderSavedContext = () => (
192189
on_tab_change={() => {}}
193190
on_new_tab={() => {}}
194191
on_tab_delete={() => {}}
195-
missing_configuration={false}
196-
missing_preset={false}
192+
token_count={0}
197193
/>
198194
)
199195

@@ -246,8 +242,7 @@ export const WithPlaceholderSelection = () => (
246242
on_tab_change={() => {}}
247243
on_new_tab={() => {}}
248244
on_tab_delete={() => {}}
249-
missing_configuration={false}
250-
missing_preset={false}
245+
token_count={0}
251246
/>
252247
)
253248

@@ -294,8 +289,7 @@ export const WithCommit = () => (
294289
on_tab_change={() => {}}
295290
on_new_tab={() => {}}
296291
on_tab_delete={() => {}}
297-
missing_configuration={false}
298-
missing_preset={false}
292+
token_count={0}
299293
/>
300294
)
301295

@@ -342,8 +336,7 @@ export const WithCommitWithQuotes = () => (
342336
on_tab_change={() => {}}
343337
on_new_tab={() => {}}
344338
on_tab_delete={() => {}}
345-
missing_configuration={false}
346-
missing_preset={false}
339+
token_count={0}
347340
/>
348341
)
349342
export const WithContextAtCommit = () => (
@@ -389,8 +382,7 @@ export const WithContextAtCommit = () => (
389382
on_tab_change={() => {}}
390383
on_new_tab={() => {}}
391384
on_tab_delete={() => {}}
392-
missing_configuration={false}
393-
missing_preset={false}
385+
token_count={0}
394386
/>
395387
)
396388

@@ -441,8 +433,7 @@ export const WithEditFormatSelector = () => {
441433
on_tab_change={() => {}}
442434
on_new_tab={() => {}}
443435
on_tab_delete={() => {}}
444-
missing_configuration={false}
445-
missing_preset={false}
436+
token_count={0}
446437
/>
447438
)
448439
}
@@ -490,8 +481,7 @@ export const WithFilePaths = () => (
490481
on_tab_change={() => {}}
491482
on_new_tab={() => {}}
492483
on_tab_delete={() => {}}
493-
missing_configuration={false}
494-
missing_preset={false}
484+
token_count={0}
495485
/>
496486
)
497487

@@ -566,15 +556,14 @@ export const WithTabs = () => {
566556
on_tab_change={set_active_index}
567557
on_new_tab={handle_new_tab}
568558
on_tab_delete={handle_tab_delete}
569-
missing_configuration={false}
570-
missing_preset={false}
559+
token_count={0}
571560
/>
572561
)
573562
}
574563

575-
export const MissingPreset = () => (
564+
export const WithWarning = () => (
576565
<PromptField
577-
value="I want to copy this even if there are no presets"
566+
value="I want to copy this even if there is a warning"
578567
chat_history={[]}
579568
on_change={(value) => console.log('Changed:', value)}
580569
on_submit={() => console.log('Submitted')}
@@ -611,7 +600,7 @@ export const MissingPreset = () => (
611600
on_tab_change={() => {}}
612601
on_new_tab={() => {}}
613602
on_tab_delete={() => {}}
614-
missing_configuration={false}
615-
missing_preset={true}
603+
token_count={0}
604+
warning="Add a configuration"
616605
/>
617606
)

0 commit comments

Comments
 (0)