-
-
Notifications
You must be signed in to change notification settings - Fork 658
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: filter features by type #5160
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 2 Ignored Deployments
|
in: 'query', | ||
}, | ||
] as const; | ||
|
||
export type FeatureSearchQueryParameters = FromQueryParams< | ||
typeof featureSearchQueryParameters | ||
export type FeatureSearchQueryParameters = Partial< |
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.
All query params are optional
@@ -19,6 +19,14 @@ export interface FeatureConfigurationClient { | |||
variants: IVariant[]; | |||
dependencies?: IDependency[]; | |||
} | |||
|
|||
export interface IFeatureSearchParams { |
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.
This type mixes data from query params and userId so decided to create a custom type that is used by store and service
@@ -542,6 +542,9 @@ class FeatureStrategiesStore implements IFeatureStrategiesStore { | |||
.whereILike('features.name', `%${queryString}%`) | |||
.orWhereIn('features.name', tagQuery); | |||
} | |||
if (type) { | |||
query = query.whereIn('features.type', type); |
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.
this is the whole query logic added by this PR
await app.createFeature({ name: 'my_feature_a', type: 'release' }); | ||
await app.createFeature({ name: 'my_feature_b', type: 'experimental' }); | ||
|
||
const { body } = await filterFeaturesByType([ |
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.
showing one matching type and one that is not used
@@ -71,10 +71,13 @@ export default class FeatureSearchController extends Controller { | |||
res: Response, | |||
): Promise<void> { | |||
if (this.config.flagResolver.isEnabled('featureSearchAPI')) { | |||
const { query = '', projectId = '' } = req.query; | |||
const { query, projectId, type } = req.query; |
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.
no need for default values
expectedCode = 200, | ||
) => { | ||
return app.request | ||
.get(`/api/admin/search/features?query=${query}&projectId=${projectId}`) | ||
.expect(expectedCode); | ||
}; | ||
|
||
const filterFeaturesByType = async (types: string[], expectedCode = 200) => { | ||
const typeParams = types.map((type) => `type[]=${type}`).join('&'); |
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.
this is how we handle array in query params
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.
Nice work. LGTM!
About the changes
Can filter search results by one or many feature types.
Based on this example it's easy to add other filter types. The important part of research here was handling multiple values in query params.
Important files
Discussion points