1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-20 00:08:02 +01:00

fix: project overview and search returning just single tag (#5305)

This commit is contained in:
Jaanus Sellin 2023-11-09 10:58:34 +02:00 committed by GitHub
parent 2695e38ed5
commit 8c2a052a68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 16 deletions

View File

@ -228,6 +228,26 @@ test('should search matching features by tag', async () => {
});
});
test('should return all feature tags', async () => {
await app.createFeature('my_feature_a');
await app.addTag('my_feature_a', { type: 'simple', value: 'my_tag' });
await app.addTag('my_feature_a', { type: 'simple', value: 'second_tag' });
const { body } = await searchFeatures({});
expect(body).toMatchObject({
features: [
{
name: 'my_feature_a',
tags: [
{ type: 'simple', value: 'my_tag' },
{ type: 'simple', value: 'second_tag' },
],
},
],
});
});
test('should return empty features', async () => {
const { body } = await searchFeatures({ query: '' });
expect(body).toMatchObject({ features: [] });

View File

@ -105,18 +105,6 @@ function mapInput(input: IFeatureStrategy): IFeatureStrategiesTable {
};
}
const getUniqueRows = (rows: any[]) => {
const seen = {};
return rows.filter((row) => {
const key = `${row.environment}-${row.feature_name}`;
if (seen[key]) {
return false;
}
seen[key] = true;
return true;
});
};
const sortEnvironments = (overview: IFeatureOverview) => {
return Object.values(overview).map((data: IFeatureOverview) => ({
...data,
@ -733,7 +721,7 @@ class FeatureStrategiesStore implements IFeatureStrategiesStore {
const rows = await query;
if (rows.length > 0) {
const overview = this.getFeatureOverviewData(getUniqueRows(rows));
const overview = this.getFeatureOverviewData(rows);
const features = sortEnvironments(overview);
return {
features,
@ -855,7 +843,7 @@ class FeatureStrategiesStore implements IFeatureStrategiesStore {
query = query.select(selectColumns);
const rows = await query;
if (rows.length > 0) {
const overview = this.getFeatureOverviewData(getUniqueRows(rows));
const overview = this.getFeatureOverviewData(rows);
return sortEnvironments(overview);
}
return [];
@ -864,9 +852,18 @@ class FeatureStrategiesStore implements IFeatureStrategiesStore {
getFeatureOverviewData(rows): IFeatureOverview {
return rows.reduce((acc, row) => {
if (acc[row.feature_name] !== undefined) {
acc[row.feature_name].environments.push(
FeatureStrategiesStore.getEnvironment(row),
const environmentExists = acc[
row.feature_name
].environments.some(
(existingEnvironment) =>
existingEnvironment.name === row.environment,
);
if (!environmentExists) {
acc[row.feature_name].environments.push(
FeatureStrategiesStore.getEnvironment(row),
);
}
if (this.isNewTag(acc[row.feature_name], row)) {
this.addTag(acc[row.feature_name], row);
}
@ -882,6 +879,7 @@ class FeatureStrategiesStore implements IFeatureStrategiesStore {
impressionData: row.impression_data,
environments: [FeatureStrategiesStore.getEnvironment(row)],
};
if (this.isNewTag(acc[row.feature_name], row)) {
this.addTag(acc[row.feature_name], row);
}