Skip to content

Commit cc0809f

Browse files
committed
Disable configuration invocation and preview when a validation warning is present
- when showing warning, configuration list items should not be invokable. Keep its actions like pinning, editing, etc. interactive. - in configurations, when invocation is disabled, should not highlight items on hover - in web configuration editing, 'preview' should be disabled in conditions that yield warning - set 'disabled opacity' on label&icon when 'disabled invocation' - don't highlight last used configuration when 'disabled invocatin'
1 parent 6242366 commit cc0809f

4 files changed

Lines changed: 43 additions & 31 deletions

File tree

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -447,12 +447,13 @@ export const MainView: React.FC<Props> = (props) => {
447447
<UiSeparator height={8} />
448448
<UiConfigurations
449449
configurations={web_configurations}
450-
on_create={(params) =>
450+
disable_invocation={!!warning}
451+
on_create={(params) => {
451452
props.on_create_web_configuration(
452453
params?.create_on_top ? 'top' : 'bottom',
453454
params?.insertion_index
454455
)
455-
}
456+
}}
456457
on_configuration_click={(id) => {
457458
props.initialize_chats({
458459
web_configuration_name: id,
@@ -464,26 +465,26 @@ export const MainView: React.FC<Props> = (props) => {
464465
on_reorder={(reordered) => {
465466
const new_web_configurations = reordered.map((c) => {
466467
return props.web_configurations.find(
467-
(p, i) => (p.name ?? `unnamed-${i}`) === c.id
468+
(p, i) => (p.name ?? `unnamed-${i}`) == c.id
468469
)!
469470
})
470471
props.on_web_configurations_reorder(new_web_configurations)
471472
}}
472473
on_duplicate={(id) => {
473474
const idx = props.web_configurations.findIndex(
474-
(p, i) => (p.name ?? `unnamed-${i}`) === id
475+
(p, i) => (p.name ?? `unnamed-${i}`) == id
475476
)
476477
props.on_duplicate_web_configuration(idx)
477478
}}
478479
on_delete={(id) => {
479480
const idx = props.web_configurations.findIndex(
480-
(p, i) => (p.name ?? `unnamed-${i}`) === id
481+
(p, i) => (p.name ?? `unnamed-${i}`) == id
481482
)
482483
props.on_delete_web_configuration(idx)
483484
}}
484-
on_toggle_pinned={(id) =>
485+
on_toggle_pinned={(id) => {
485486
props.on_toggle_web_configuration_pinned(id)
486-
}
487+
}}
487488
selected_configuration_id={props.selected_web_configuration_name}
488489
is_collapsed={props.web_configurations_collapsed}
489490
on_toggle_collapsed={props.on_web_configurations_collapsed_change}
@@ -507,6 +508,7 @@ export const MainView: React.FC<Props> = (props) => {
507508
<UiSeparator height={8} />
508509
<UiConfigurations
509510
configurations={api_configurations_ui}
511+
disable_invocation={!!warning}
510512
on_configuration_click={props.on_api_configuration_click}
511513
on_reorder={(reordered) =>
512514
props.on_api_configurations_reorder(reordered)

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

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,10 @@ export const Panel = () => {
219219
!is_connected ||
220220
(!has_instructions && web_prompt_type != 'code-at-cursor') ||
221221
(web_prompt_type == 'code-at-cursor' &&
222-
(!currently_open_file_path || !!current_selection))
222+
(!currently_open_file_path || !!current_selection)) ||
223+
(web_prompt_type != 'code-at-cursor' &&
224+
web_prompt_type != 'no-context' &&
225+
token_count == 0)
223226

224227
const handle_apply_click = () => {
225228
post_message(vscode, {
@@ -499,26 +502,13 @@ export const Panel = () => {
499502
}
500503
title="Edit Web Configuration"
501504
header_slot={
502-
<UiTextButton
503-
on_click={handle_preview_web_configuration}
504-
disabled={is_preview_disabled}
505-
title={
506-
!is_connected
507-
? 'Unable to preview when not connected'
508-
: web_prompt_type == 'code-at-cursor' &&
509-
!currently_open_file_path
510-
? 'Cannot preview in code completion mode without an active editor'
511-
: web_prompt_type == 'code-at-cursor' &&
512-
!!current_selection
513-
? 'Unable to work with text selection'
514-
: !has_instructions &&
515-
web_prompt_type != 'code-at-cursor'
516-
? 'Enter instructions to preview'
517-
: ''
518-
}
519-
>
520-
Preview
521-
</UiTextButton>
505+
!is_preview_disabled && (
506+
<UiTextButton
507+
on_click={handle_preview_web_configuration}
508+
>
509+
Preview
510+
</UiTextButton>
511+
)
522512
}
523513
>
524514
<EditWebConfigurationForm

‎packages/ui/src/components/editor/panel/Configurations/Configurations.module.scss‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@
2424
}
2525
}
2626

27+
&--disabled-invocation {
28+
cursor: default;
29+
30+
&:hover {
31+
background-color: unset;
32+
}
33+
34+
.configurations__item__left__icon,
35+
.configurations__item__left__text {
36+
opacity: var(--disabled-opacity);
37+
}
38+
}
39+
2740
&--highlighted {
2841
background-color: var(--vscode-list-inactiveSelectionBackground);
2942

‎packages/ui/src/components/editor/panel/Configurations/Configurations.tsx‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export namespace Configurations {
2828
on_edit: (id: string) => void
2929
on_delete: (id: string) => void
3030
on_duplicate: (id: string) => void
31+
disable_invocation?: boolean
3132
is_collapsed: boolean
3233
on_toggle_collapsed: (is_collapsed: boolean) => void
3334
translations: {
@@ -57,10 +58,16 @@ export const Configurations: React.FC<Configurations.Props> = (props) => {
5758
key={configuration.id}
5859
className={cn(styles.configurations__item, {
5960
[styles['configurations__item--highlighted']]:
60-
props.selected_configuration_id == configuration.id
61+
!props.disable_invocation && props.selected_configuration_id == configuration.id,
62+
[styles['configurations__item--disabled-invocation']]:
63+
props.disable_invocation
6164
})}
62-
onClick={() => props.on_configuration_click(configuration.id)}
63-
role="button"
65+
onClick={
66+
props.disable_invocation
67+
? undefined
68+
: () => props.on_configuration_click(configuration.id)
69+
}
70+
role={props.disable_invocation ? undefined : 'button'}
6471
>
6572
<div className={styles.configurations__item__left}>
6673
{!is_dragging_disabled && (

0 commit comments

Comments
 (0)