@@ -13,19 +13,21 @@ import {renderConditionEditor} from '../../shared/condition_editor.utils';
1313
1414import {
1515 Condition ,
16+ ConditionOperator ,
1617 ConditionTarget ,
18+ createConditionGroup ,
19+ createDefaultPromptItemGroup ,
20+ createDefaultStageContextPromptItem ,
21+ createShuffleConfig ,
22+ getConditionTargetsFromStages ,
1723 PromptItem ,
18- PromptItemType ,
1924 PromptItemGroup ,
25+ PromptItemType ,
26+ SeedStrategy ,
27+ ShuffleConfig ,
2028 StageContextPromptItem ,
2129 StageKind ,
2230 TextPromptItem ,
23- createDefaultStageContextPromptItem ,
24- createDefaultPromptItemGroup ,
25- getConditionTargetsFromStages ,
26- ShuffleConfig ,
27- SeedStrategy ,
28- createShuffleConfig ,
2931} from '@deliberation-lab/utils' ;
3032
3133import { styles } from './structured_prompt_editor.scss' ;
@@ -211,13 +213,32 @@ export class EditorComponent extends MobxLitElement {
211213 }
212214
213215 const conditionTargets = this . getConditionTargets ( ) ;
216+ const supportsConditions =
217+ this . supportsConditions ( ) && conditionTargets . length > 0 ;
218+
219+ return items . map ( ( item , index ) => {
220+ const hasCondition = item . condition !== undefined ;
214221
215- return items . map (
216- ( item , index ) => html `
222+ return html `
217223 < div class ="prompt-item-wrapper ${ isNested ? 'nested' : '' } ">
218224 < div class ="prompt-item-row ">
219225 < div class ="prompt-item-editor "> ${ this . renderItemEditor ( item ) } </ div >
220226 < div class ="prompt-item-actions ">
227+ ${ supportsConditions && item . type !== PromptItemType . GROUP
228+ ? html `
229+ < pr-icon-button
230+ icon ="rule "
231+ color =${ hasCondition ? 'primary' : 'neutral' }
232+ variant ="default"
233+ size="small"
234+ title=${ hasCondition
235+ ? 'Remove display condition'
236+ : 'Add display condition' }
237+ @click=${ ( ) => this . toggleCondition ( item ) }
238+ >
239+ </ pr-icon-button >
240+ `
241+ : nothing }
221242 < pr-icon-button
222243 icon ="arrow_upward "
223244 color ="neutral "
@@ -244,42 +265,44 @@ export class EditorComponent extends MobxLitElement {
244265 </ pr-icon-button >
245266 </ div >
246267 </ div >
247- ${ this . renderPromptItemCondition ( item , conditionTargets ) }
268+ ${ hasCondition
269+ ? this . renderPromptItemCondition ( item , conditionTargets )
270+ : nothing }
248271 </ div >
249- ` ,
250- ) ;
272+ ` ;
273+ } ) ;
274+ }
275+
276+ private toggleCondition ( item : PromptItem ) {
277+ if ( item . condition !== undefined ) {
278+ // Remove condition
279+ this . updatePromptItem ( item , { condition : undefined } ) ;
280+ } else {
281+ // Add an empty condition group - user will add conditions via the editor
282+ this . updatePromptItem ( item , {
283+ condition : createConditionGroup ( ConditionOperator . AND , [ ] ) ,
284+ } ) ;
285+ }
251286 }
252287
253288 private renderPromptItemCondition (
254289 item : PromptItem ,
255290 conditionTargets : ConditionTarget [ ] ,
256291 ) {
257- // Don't show condition editor for GROUP items (they contain other items that can have conditions)
258- if ( item . type === PromptItemType . GROUP ) {
259- return nothing ;
260- }
261-
262- // Conditions are only supported for private chat stages (not group chat)
263- if ( ! this . supportsConditions ( ) ) {
264- return nothing ;
265- }
266-
267292 const onConditionChange = ( condition : Condition | undefined ) => {
268293 this . updatePromptItem ( item , { condition} ) ;
269294 } ;
270295
271- const conditionEditor = renderConditionEditor ( {
272- condition : item . condition ,
273- targets : conditionTargets ,
274- canEdit : this . experimentEditor . canEditStages ,
275- onConditionChange,
276- } ) ;
277-
278- if ( conditionEditor === nothing ) {
279- return nothing ;
280- }
281-
282- return html ` < div class ="prompt-item-condition "> ${ conditionEditor } </ div > ` ;
296+ return html `
297+ < div class ="prompt-item-condition ">
298+ ${ renderConditionEditor ( {
299+ condition : item . condition ,
300+ targets : conditionTargets ,
301+ canEdit : this . experimentEditor . canEditStages ,
302+ onConditionChange,
303+ } ) }
304+ </ div >
305+ ` ;
283306 }
284307
285308 private renderTextPromptItemEditor ( item : TextPromptItem ) {
0 commit comments