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

Segment export (#2922)

Segment export
This commit is contained in:
sjaanus 2023-01-18 10:41:22 +02:00 committed by GitHub
parent 1ccbce23de
commit 16bca1260c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import { featureStrategySchema } from './feature-strategy-schema';
import { featureEnvironmentSchema } from './feature-environment-schema';
import { contextFieldSchema } from './context-field-schema';
import { featureTagSchema } from './feature-tag-schema';
import { segmentSchema } from './segment-schema';
export const exportResultSchema = {
$id: '#/components/schemas/exportResultSchema',
@ -41,6 +42,12 @@ export const exportResultSchema = {
$ref: '#/components/schemas/featureTagSchema',
},
},
segments: {
type: 'array',
items: {
$ref: '#/components/schemas/segmentSchema',
},
},
},
components: {
schemas: {
@ -49,6 +56,7 @@ export const exportResultSchema = {
featureEnvironmentSchema,
contextFieldSchema,
featureTagSchema,
segmentSchema,
},
},
} as const;

View File

@ -4,6 +4,7 @@ import {
IFeatureEnvironment,
IFeatureStrategy,
IFeatureStrategySegment,
ISegment,
ITag,
} from '../types/model';
import { Logger } from '../logger';
@ -37,6 +38,7 @@ export interface IExportData {
contextFields: IContextFieldDto[];
featureStrategies: IFeatureStrategy[];
featureEnvironments: IFeatureEnvironment[];
segments: ISegment[];
}
export default class ExportImportService {
@ -108,6 +110,7 @@ export default class ExportImportService {
strategySegments,
contextFields,
featureTags,
segments,
] = await Promise.all([
this.toggleStore.getAllByNames(query.features),
await this.featureEnvironmentStore.getAllByFeatures(
@ -121,6 +124,7 @@ export default class ExportImportService {
this.segmentStore.getAllFeatureStrategySegments(),
this.contextFieldStore.getAll(),
this.featureTagStore.getAll(),
this.segmentStore.getAll(),
]);
this.addSegmentsToStrategies(featureStrategies, strategySegments);
const filteredContextFields = contextFields.filter((field) =>
@ -130,12 +134,18 @@ export default class ExportImportService {
),
),
);
const filteredSegments = segments.filter((segment) =>
featureStrategies.some((strategy) =>
strategy.segments.includes(segment.id),
),
);
const result = {
features,
featureStrategies,
featureEnvironments,
contextFields: filteredContextFields,
featureTags,
segments: filteredSegments,
};
await this.eventStore.store({
type: FEATURES_EXPORTED,

View File

@ -134,8 +134,9 @@ afterAll(async () => {
});
test('exports features', async () => {
const segmentName = 'my-segment';
await createProject('default', 'default');
const segment = await createSegment({ name: 'S3', constraints: [] });
const segment = await createSegment({ name: segmentName, constraints: [] });
const strategy = {
name: 'default',
parameters: { rollout: '100', stickiness: 'default' },
@ -187,6 +188,11 @@ test('exports features', async () => {
variants: [],
},
],
segments: [
{
name: segmentName,
},
],
});
});
@ -366,6 +372,7 @@ test('import features to existing project and environment', async () => {
},
],
contextFields: [],
segments: [],
},
project: project,
environment: environment,

View File

@ -1090,6 +1090,12 @@ exports[`should serve the OpenAPI spec 1`] = `
},
"type": "array",
},
"segments": {
"items": {
"$ref": "#/components/schemas/segmentSchema",
},
"type": "array",
},
},
"required": [
"features",