@@ -8,25 +8,26 @@ import {CSSResultGroup, html, nothing, TemplateResult} from 'lit';
88import { customElement , property } from 'lit/decorators.js' ;
99
1010import { core } from '../../core/core' ;
11- import { AuthService } from '../../services/auth.service' ;
1211import { ExperimentEditor } from '../../services/experiment.editor' ;
1312import { renderConditionEditor } from '../../shared/condition_editor.utils' ;
1413
1514import {
1615 Condition ,
16+ ConditionOperator ,
1717 ConditionTarget ,
18+ createConditionGroup ,
19+ createDefaultPromptItemGroup ,
20+ createDefaultStageContextPromptItem ,
21+ createShuffleConfig ,
22+ getConditionTargetsFromStages ,
1823 PromptItem ,
19- PromptItemType ,
2024 PromptItemGroup ,
25+ PromptItemType ,
26+ SeedStrategy ,
27+ ShuffleConfig ,
2128 StageContextPromptItem ,
2229 StageKind ,
2330 TextPromptItem ,
24- createDefaultStageContextPromptItem ,
25- createDefaultPromptItemGroup ,
26- getConditionTargetsFromStages ,
27- ShuffleConfig ,
28- SeedStrategy ,
29- createShuffleConfig ,
3031} from '@deliberation-lab/utils' ;
3132
3233import { styles } from './structured_prompt_editor.scss' ;
@@ -36,7 +37,6 @@ import {styles} from './structured_prompt_editor.scss';
3637export class EditorComponent extends MobxLitElement {
3738 static override styles : CSSResultGroup = [ styles ] ;
3839
39- private readonly authService = core . getService ( AuthService ) ;
4040 private readonly experimentEditor = core . getService ( ExperimentEditor ) ;
4141
4242 @property ( ) prompt : PromptItem [ ] = [ ] ;
@@ -213,13 +213,32 @@ export class EditorComponent extends MobxLitElement {
213213 }
214214
215215 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 ;
216221
217- return items . map (
218- ( item , index ) => html `
222+ return html `
219223 < div class ="prompt-item-wrapper ${ isNested ? 'nested' : '' } ">
220224 < div class ="prompt-item-row ">
221225 < div class ="prompt-item-editor "> ${ this . renderItemEditor ( item ) } </ div >
222226 < 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 }
223242 < pr-icon-button
224243 icon ="arrow_upward "
225244 color ="neutral "
@@ -246,43 +265,44 @@ export class EditorComponent extends MobxLitElement {
246265 </ pr-icon-button >
247266 </ div >
248267 </ div >
249- ${ this . renderPromptItemCondition ( item , conditionTargets ) }
268+ ${ hasCondition
269+ ? this . renderPromptItemCondition ( item , conditionTargets )
270+ : nothing }
250271 </ div >
251- ` ,
252- ) ;
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+ }
253286 }
254287
255288 private renderPromptItemCondition (
256289 item : PromptItem ,
257290 conditionTargets : ConditionTarget [ ] ,
258291 ) {
259- // Don't show condition editor for GROUP items (they contain other items that can have conditions)
260- if ( item . type === PromptItemType . GROUP ) {
261- return nothing ;
262- }
263-
264- // Conditions are only supported for private chat stages (not group chat)
265- if ( ! this . supportsConditions ( ) ) {
266- return nothing ;
267- }
268-
269292 const onConditionChange = ( condition : Condition | undefined ) => {
270293 this . updatePromptItem ( item , { condition} ) ;
271294 } ;
272295
273- const conditionEditor = renderConditionEditor ( {
274- condition : item . condition ,
275- targets : conditionTargets ,
276- showAlphaFeatures : this . authService . showAlphaFeatures ,
277- canEdit : this . experimentEditor . canEditStages ,
278- onConditionChange,
279- } ) ;
280-
281- if ( conditionEditor === nothing ) {
282- return nothing ;
283- }
284-
285- 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+ ` ;
286306 }
287307
288308 private renderTextPromptItemEditor ( item : TextPromptItem ) {
0 commit comments