diff --git a/src/lib/addons/feature-event-formatter-md.ts b/src/lib/addons/feature-event-formatter-md.ts index 2b499dc1fbbc..c4609232f3ab 100644 --- a/src/lib/addons/feature-event-formatter-md.ts +++ b/src/lib/addons/feature-event-formatter-md.ts @@ -415,7 +415,11 @@ export class FeatureEventFormatterMd implements FeatureEventFormatter { preData?.constraints, data?.constraints, ); - const strategySpecificText = [usersText, constraintText] + const segmentsText = this.segmentsChangeText( + preData?.segments, + data?.segments, + ); + const strategySpecificText = [usersText, constraintText, segmentsText] .filter((x) => x.length) .join(';'); return `by updating strategy *${this.getStrategyTitle( @@ -453,11 +457,16 @@ export class FeatureEventFormatterMd implements FeatureEventFormatter { preData?.constraints, data?.constraints, ); + const segmentsText = this.segmentsChangeText( + preData?.segments, + data?.segments, + ); const strategySpecificText = [ stickinessText, rolloutText, groupIdText, constraintText, + segmentsText, ] .filter((txt) => txt.length) .join(';'); @@ -468,12 +477,20 @@ export class FeatureEventFormatterMd implements FeatureEventFormatter { private defaultStrategyChangeText(event: IEvent) { const { preData, data, environment } = event; - return `by updating strategy *${this.getStrategyTitle( - event, - )}* in *${environment}*${this.constraintChangeText( + const constraintText = this.constraintChangeText( preData?.constraints, data?.constraints, - )}`; + ); + const segmentsText = this.segmentsChangeText( + preData?.segments, + data?.segments, + ); + const strategySpecificText = [constraintText, segmentsText] + .filter((txt) => txt.length) + .join(';'); + return `by updating strategy *${this.getStrategyTitle( + event, + )}* in *${environment}*${strategySpecificText}`; } private constraintChangeText( @@ -525,6 +542,23 @@ export class FeatureEventFormatterMd implements FeatureEventFormatter { : ` constraints from ${oldConstraintText} to ${newConstraintText}`; } + private segmentsChangeText( + oldSegments: string[] = [], + newSegments: string[] = [], + ) { + const formatSegments = (segments: string[]) => { + return segments.length === 0 + ? 'empty set of segments' + : `(${segments.join(',')})`; + }; + const oldSegmentsText = formatSegments(oldSegments); + const newSegmentsText = formatSegments(newSegments); + + return oldSegmentsText === newSegmentsText + ? '' + : ` segments from ${oldSegmentsText} to ${newSegmentsText}`; + } + format(event: IEvent): { text: string; url?: string; diff --git a/src/lib/services/feature-toggle-service.ts b/src/lib/services/feature-toggle-service.ts index aca23b0795de..b365c3949f6e 100644 --- a/src/lib/services/feature-toggle-service.ts +++ b/src/lib/services/feature-toggle-service.ts @@ -718,6 +718,7 @@ class FeatureToggleService { projectId, updates.segments, ); + const existingSegments = await this.segmentService.getByStrategy(id); if (existingStrategy.id === id) { if (updates.constraints && updates.constraints.length > 0) { @@ -752,7 +753,7 @@ class FeatureToggleService { const data = this.featureStrategyToPublic(strategy, segments); const preData = this.featureStrategyToPublic( existingStrategy, - segments, + existingSegments, ); await this.eventService.storeEvent( new FeatureStrategyUpdateEvent({ @@ -789,6 +790,9 @@ class FeatureToggleService { if (existingStrategy.id === id) { existingStrategy.parameters[name] = String(value); + const existingSegments = await this.segmentService.getByStrategy( + id, + ); const strategy = await this.featureStrategiesStore.updateStrategy( id, existingStrategy, @@ -799,7 +803,7 @@ class FeatureToggleService { const data = this.featureStrategyToPublic(strategy, segments); const preData = this.featureStrategyToPublic( existingStrategy, - segments, + existingSegments, ); await this.eventService.storeEvent( new FeatureStrategyUpdateEvent({