Skip to content
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

feat: add created by in search results #7285

Merged
merged 3 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/lib/features/feature-search/feature-search-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ class FeatureSearchStore implements IFeatureSearchStore {
'ft.tag_value as tag_value',
'ft.tag_type as tag_type',
'segments.name as segment_name',
'users.id as user_id',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm very careful here to avoid duplicate names

'users.name as user_name',
'users.username as user_username',
'users.email as user_email',
'users.image_url as user_image_url',
] as (string | Raw<any> | Knex.QueryBuilder)[];

const lastSeenQuery = 'last_seen_at_metrics.last_seen_at';
Expand Down Expand Up @@ -232,7 +237,12 @@ class FeatureSearchStore implements IFeatureSearchStore {
'=',
'features.name',
);
});
})
.leftJoin(
'users',
'users.id',
'features.created_by_user_id',
);

query.leftJoin('last_seen_at_metrics', function () {
this.on(
Expand Down Expand Up @@ -407,6 +417,15 @@ class FeatureSearchStore implements IFeatureSearchStore {
dependencyType: row.dependency,
environments: [],
segments: row.segment_name ? [row.segment_name] : [],
createdBy: {
id: Number(row.user_id),
name:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hiding fallback from the UI

row.user_name ||
row.user_username ||
row.user_email ||
'unknown',
imageUrl: row.user_image_url,
},
};
if (featureLifecycleEnabled) {
entry.lifecycle = row.latest_stage
Expand Down
11 changes: 10 additions & 1 deletion src/lib/features/feature-search/feature.search.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,16 @@ test('should search matching features by name', async () => {
const { body } = await searchFeatures({ query: 'feature' });

expect(body).toMatchObject({
features: [{ name: 'my_feature_a' }, { name: 'my_feature_b' }],
features: [
{
name: 'my_feature_a',
createdBy: { id: 1, name: '[email protected]' },
},
{
name: 'my_feature_b',
createdBy: { id: 1, name: '[email protected]' },
},
],
total: 2,
});
});
Expand Down
24 changes: 24 additions & 0 deletions src/lib/openapi/spec/feature-search-response-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,30 @@ export const featureSearchResponseSchema = {
},
},
},
createdBy: {
type: 'object',
description: 'User who created the feature flag',
additionalProperties: false,
required: ['id', 'name', 'imageUrl'],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decided to go for nulls instead of null + undefined. All fields will always be provided

properties: {
id: {
description: 'The user id',
type: 'integer',
example: 123,
},
name: {
description: 'Name of the user',
type: 'string',
example: 'User',
},
imageUrl: {
description: `URL used for the user profile image`,
type: 'string',
example: 'https://example.com/242x200.png',
nullable: true,
},
},
},
},
components: {
schemas: {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/openapi/spec/user-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const userSchema = {
nullable: true,
},
imageUrl: {
description: `URL used for the userprofile image`,
description: `URL used for the user profile image`,
type: 'string',
example: 'https://example.com/242x200.png',
},
Expand Down
5 changes: 5 additions & 0 deletions src/lib/types/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ export type IFeatureSearchOverview = Exclude<
> & {
dependencyType: 'parent' | 'child' | null;
environments: FeatureSearchEnvironmentSchema[];
createdBy: {
id: number;
name: string;
imageUrl: string | null;
};
};

export interface IFeatureTypeCount {
Expand Down