-
-
Notifications
You must be signed in to change notification settings - Fork 659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixed segments not being copied #2105
Changes from all commits
df21521
7ddb5e5
da0f5a8
a944bfb
d7424e3
83e1c31
150a88a
ed2e8b5
b393bcf
3519958
adc3ea7
7fdc8f3
4ef074a
4723351
cacc75d
3d2414a
5a9afb0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ import { | |
IFeatureOverview, | ||
IFeatureStrategy, | ||
IFeatureToggleQuery, | ||
ISegment, | ||
IStrategyConfig, | ||
IVariant, | ||
WeightType, | ||
|
@@ -274,12 +275,14 @@ class FeatureToggleService { | |
|
||
featureStrategyToPublic( | ||
featureStrategy: IFeatureStrategy, | ||
segments: ISegment[] = [], | ||
): Saved<IStrategyConfig> { | ||
return { | ||
id: featureStrategy.id, | ||
name: featureStrategy.strategyName, | ||
constraints: featureStrategy.constraints || [], | ||
parameters: featureStrategy.parameters, | ||
segments: segments.map((segment) => segment.id) ?? [], | ||
}; | ||
} | ||
|
||
|
@@ -321,7 +324,13 @@ class FeatureToggleService { | |
}); | ||
|
||
const tags = await this.tagStore.getAllTagsForFeature(featureName); | ||
const strategy = this.featureStrategyToPublic(newFeatureStrategy); | ||
const segments = await this.segmentService.getByStrategy( | ||
newFeatureStrategy.id, | ||
); | ||
const strategy = this.featureStrategyToPublic( | ||
newFeatureStrategy, | ||
segments, | ||
); | ||
await this.eventStore.store( | ||
new FeatureStrategyAddEvent({ | ||
project: projectId, | ||
|
@@ -376,10 +385,17 @@ class FeatureToggleService { | |
updates, | ||
); | ||
|
||
const segments = await this.segmentService.getByStrategy( | ||
strategy.id, | ||
); | ||
|
||
// Store event! | ||
const tags = await this.tagStore.getAllTagsForFeature(featureName); | ||
const data = this.featureStrategyToPublic(strategy); | ||
const preData = this.featureStrategyToPublic(existingStrategy); | ||
const data = this.featureStrategyToPublic(strategy, segments); | ||
const preData = this.featureStrategyToPublic( | ||
existingStrategy, | ||
segments, | ||
); | ||
await this.eventStore.store( | ||
new FeatureStrategyUpdateEvent({ | ||
project: projectId, | ||
|
@@ -415,8 +431,14 @@ class FeatureToggleService { | |
existingStrategy, | ||
); | ||
const tags = await this.tagStore.getAllTagsForFeature(featureName); | ||
const data = this.featureStrategyToPublic(strategy); | ||
const preData = this.featureStrategyToPublic(existingStrategy); | ||
const segments = await this.segmentService.getByStrategy( | ||
strategy.id, | ||
); | ||
const data = this.featureStrategyToPublic(strategy, segments); | ||
const preData = this.featureStrategyToPublic( | ||
existingStrategy, | ||
segments, | ||
); | ||
await this.eventStore.store( | ||
new FeatureStrategyUpdateEvent({ | ||
featureName, | ||
|
@@ -479,6 +501,7 @@ class FeatureToggleService { | |
featureName: string, | ||
environment: string = DEFAULT_ENV, | ||
): Promise<Saved<IStrategyConfig>[]> { | ||
this.logger.debug('getStrategiesForEnvironment'); | ||
const hasEnv = await this.featureEnvironmentStore.featureHasEnvironment( | ||
environment, | ||
featureName, | ||
|
@@ -490,13 +513,22 @@ class FeatureToggleService { | |
featureName, | ||
environment, | ||
); | ||
return featureStrategies.map((strat) => ({ | ||
id: strat.id, | ||
name: strat.strategyName, | ||
constraints: strat.constraints, | ||
parameters: strat.parameters, | ||
sortOrder: strat.sortOrder, | ||
})); | ||
const result = []; | ||
for (const strat of featureStrategies) { | ||
const segments = | ||
(await this.segmentService.getByStrategy(strat.id)).map( | ||
(segment) => segment.id, | ||
) ?? []; | ||
result.push({ | ||
id: strat.id, | ||
name: strat.strategyName, | ||
constraints: strat.constraints, | ||
parameters: strat.parameters, | ||
sortOrder: strat.sortOrder, | ||
segments, | ||
}); | ||
} | ||
return result; | ||
} | ||
throw new NotFoundError( | ||
`Feature ${featureName} does not have environment ${environment}`, | ||
|
@@ -718,12 +750,23 @@ class FeatureToggleService { | |
const strategy = await this.featureStrategiesStore.getStrategyById( | ||
strategyId, | ||
); | ||
return { | ||
|
||
const segments = await this.segmentService.getByStrategy(strategyId); | ||
let result: Saved<IStrategyConfig> = { | ||
id: strategy.id, | ||
name: strategy.strategyName, | ||
constraints: strategy.constraints || [], | ||
parameters: strategy.parameters, | ||
segments: [], | ||
}; | ||
|
||
if (segments && segments.length > 0) { | ||
result = { | ||
...result, | ||
segments: segments.map((segment) => segment.id), | ||
}; | ||
} | ||
Comment on lines
+763
to
+768
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a test that validates that this gives the correct result? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, if there are no segments defined, should we return an empty array? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added one here https://github.com/ivarconr/unleash-enterprise/pull/138 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @andreas-unleash It seems this is not reflected in the specification, at least I can't see a spec update for this data structure. |
||
return result; | ||
} | ||
|
||
async getEnvironmentInfo( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsure if the schema updates for public-invite belongs in this PR. Fine for now, but we should aim to separate PR concerns in the future