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: filter features by type #5160

Merged
merged 3 commits into from
Oct 26, 2023
Merged

feat: filter features by type #5160

merged 3 commits into from
Oct 26, 2023

Conversation

kwasniew
Copy link
Contributor

@kwasniew kwasniew commented Oct 26, 2023

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

@vercel
Copy link

vercel bot commented Oct 26, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
unleash-docs ⬜️ Ignored (Inspect) Visit Preview Oct 26, 2023 1:03pm
unleash-monorepo-frontend ⬜️ Ignored (Inspect) Visit Preview Oct 26, 2023 1:03pm

in: 'query',
},
] as const;

export type FeatureSearchQueryParameters = FromQueryParams<
typeof featureSearchQueryParameters
export type FeatureSearchQueryParameters = Partial<
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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);
Copy link
Contributor Author

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([
Copy link
Contributor Author

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;
Copy link
Contributor Author

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('&');
Copy link
Contributor Author

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

Copy link
Contributor

@andreas-unleash andreas-unleash left a comment

Choose a reason for hiding this comment

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

Nice work. LGTM!

@kwasniew kwasniew merged commit 0c8d070 into main Oct 26, 2023
8 checks passed
@kwasniew kwasniew deleted the filter-features-by-type branch October 26, 2023 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants