1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-31 00:16:47 +01:00

feat: render segments changes in feature strategy update event messages (#4950)

## About the changes

Segment changes in predata and data columns were both showing the new
segments list

Adds formatting of what's changed with segments to feature strategy
update events, so when a user changes the strategy from using
constraints, to using segments instead, it's communicated in event
updates

results in: 

admin updated
[sample-toggle](http://localhost/projects/default/features/sample-toggle)
in project [default](http://localhost/projects/default) by updating
strategy Sample Strategy in development constraints from [userId is one
of (1,2,3)] to empty set of constraints; segments from empty set of
segments to (1)


Closes #
#4912 

### Important files

- `src/lib/services/feature-toggle-service.ts` - Segment changes in
preData and data
- `src/lib/addons/feature-event-formatter-md.ts` - Formatting segments

## Discussion points

This is an SR least effort PR - we should plan a task where we look at
how to render this list of segments in a more comprehensible way (it's
just rendering ids now)
This commit is contained in:
David Leek 2023-10-09 09:11:39 +02:00 committed by GitHub
parent e0faa3e842
commit e065e2a455
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 7 deletions

View File

@ -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;

View File

@ -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({