@@ -85,26 +85,58 @@ const with_ids = (
8585 } ) )
8686}
8787
88- const ChatbotIcon : React . FC < {
89- chatbot : keyof typeof CHATBOTS
90- is_disabled : boolean
91- } > = ( params ) => {
92- const icon_variant = chatbot_to_icon [ params . chatbot ]
93-
94- if ( ! icon_variant ) return null
95-
96- return (
97- < div className = { styles . presets__item__left__icon } >
98- < Icon variant = { icon_variant } />
99- </ div >
100- )
101- }
102-
10388export const Presets : React . FC < Presets . Props > = ( props ) => {
10489 const [ highlighted_preset_name , set_highlighted_preset_name ] = useState <
10590 Record < Presets . Props [ 'web_mode' ] , string >
10691 > ( { } as any )
10792
93+ const get_is_preset_disabled = ( preset : Presets . Preset ) =>
94+ preset . chatbot &&
95+ ( ! props . is_connected ||
96+ ( props . is_in_code_completions_mode &&
97+ ( ! props . has_active_editor || props . has_active_selection ) ) ||
98+ ( props . is_in_context_dependent_mode && ! props . has_context ) ||
99+ ( ! props . is_in_code_completions_mode &&
100+ ! (
101+ props . has_instructions ||
102+ preset . prompt_prefix ||
103+ preset . prompt_suffix
104+ ) ) )
105+
106+ const get_is_ungrouped_disabled = ( ) => {
107+ for ( const p of props . presets ) {
108+ if ( ! p . chatbot ) {
109+ break
110+ }
111+ if ( p . is_default && ! get_is_preset_disabled ( p ) ) {
112+ return false
113+ }
114+ }
115+ return true
116+ }
117+
118+ const get_ungrouped_title = ( ) => {
119+ if ( ! props . is_connected ) {
120+ return props . translations . not_connected
121+ } else if ( get_is_ungrouped_disabled ( ) ) {
122+ return props . translations . no_preset_enabled_or_selected_in_this_group
123+ } else if ( props . is_in_code_completions_mode ) {
124+ return ! props . has_active_editor
125+ ? props . translations . preset_requires_active_editor
126+ : props . has_active_selection
127+ ? props . translations . preset_cannot_be_used_with_selection
128+ : props . translations . initialize_chat_with_preset
129+ } else if ( props . is_in_context_dependent_mode && ! props . has_context ) {
130+ return props . translations . add_files_to_context_first
131+ } else if (
132+ ! props . is_in_code_completions_mode &&
133+ ! props . has_instructions
134+ ) {
135+ return props . translations . type_or_add_prompt_to_use_preset
136+ }
137+ return props . translations . initialize_chat_with_preset
138+ }
139+
108140 return (
109141 < div className = { styles . container } >
110142 < div className = { styles [ 'my-presets' ] } >
@@ -116,6 +148,36 @@ export const Presets: React.FC<Presets.Props> = (props) => {
116148 </ div >
117149
118150 < div className = { styles . presets } >
151+ { props . presets [ 0 ] ?. chatbot !== undefined && (
152+ < div
153+ className = { cn ( styles . presets__item , {
154+ [ styles [ 'presets__item--ungrouped' ] ] : true ,
155+ [ styles [ 'presets__item--disabled' ] ] : get_is_ungrouped_disabled ( )
156+ } ) }
157+ onClick = { ( ) => {
158+ if ( get_is_ungrouped_disabled ( ) ) return
159+
160+ const preset_names : string [ ] = [ ]
161+ for ( const preset of props . presets ) {
162+ if ( ! preset . chatbot ) break
163+ if (
164+ preset . is_default &&
165+ ! get_is_preset_disabled ( preset )
166+ ) {
167+ preset_names . push ( preset . name )
168+ }
169+ }
170+ props . on_group_click ( preset_names )
171+ } }
172+ role = "button"
173+ title = { get_ungrouped_title ( ) }
174+ >
175+ < div className = { styles . presets__item__left } >
176+ < div className = { styles . presets__item__left__text } > Ungrouped</ div >
177+ </ div >
178+ </ div >
179+ ) }
180+
119181 < ReactSortable
120182 list = { with_ids ( props . presets ) }
121183 setList = { ( new_state ) => {
@@ -155,19 +217,6 @@ export const Presets: React.FC<Presets.Props> = (props) => {
155217 return chatbot
156218 }
157219
158- const get_is_preset_disabled = ( preset : Presets . Preset ) =>
159- preset . chatbot &&
160- ( ( false && ! props . is_connected ) ||
161- ( props . is_in_code_completions_mode &&
162- ( ! props . has_active_editor || props . has_active_selection ) ) ||
163- ( props . is_in_context_dependent_mode && ! props . has_context ) ||
164- ( ! props . is_in_code_completions_mode &&
165- ! (
166- props . has_instructions ||
167- preset . prompt_prefix ||
168- preset . prompt_suffix
169- ) ) )
170-
171220 const get_is_group_disabled = ( ) => {
172221 for ( let j = i + 1 ; j < props . presets . length ; j ++ ) {
173222 const p = props . presets [ j ]
@@ -185,7 +234,8 @@ export const Presets: React.FC<Presets.Props> = (props) => {
185234 if ( ! props . is_connected ) {
186235 return props . translations . not_connected
187236 } else if ( ! preset . chatbot && get_is_group_disabled ( ) ) {
188- return props . translations . no_preset_enabled_or_selected_in_this_group
237+ return props . translations
238+ . no_preset_enabled_or_selected_in_this_group
189239 } else if ( props . is_in_code_completions_mode ) {
190240 return ! props . has_active_editor
191241 ? props . translations . preset_requires_active_editor
0 commit comments