Skip to content

Commit

Permalink
feat: more powerful feature search by type (#7267)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew authored Jun 4, 2024
1 parent 0db5bc1 commit 2069af4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
8 changes: 8 additions & 0 deletions src/lib/features/feature-search/feature-search-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ export class FeatureSearchService {
if (parsed) queryParams.push(parsed);
}

if (params.type) {
const parsed = this.parseOperatorValue(
'features.type',
params.type,
);
if (parsed) queryParams.push(parsed);
}

['tag', 'segment', 'project'].forEach((field) => {
if (params[field]) {
const parsed = this.parseOperatorValue(field, params[field]);
Expand Down
5 changes: 0 additions & 5 deletions src/lib/features/feature-search/feature-search-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ class FeatureSearchStore implements IFeatureSearchStore {
{
userId,
searchParams,
type,
status,
offset,
limit,
Expand Down Expand Up @@ -175,10 +174,6 @@ class FeatureSearchStore implements IFeatureSearchStore {
'features.description',
]);

if (type) {
query.whereIn('features.type', type);
}

if (status && status.length > 0) {
query.where((builder) => {
for (const [envName, envStatus] of status) {
Expand Down
12 changes: 5 additions & 7 deletions src/lib/features/feature-search/feature.search.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,9 @@ const searchFeaturesWithOffset = async (
.expect(expectedCode);
};

const filterFeaturesByType = async (types: string[], expectedCode = 200) => {
const typeParams = types.map((type) => `type[]=${type}`).join('&');
const filterFeaturesByType = async (typeParams: string, expectedCode = 200) => {
return app.request
.get(`/api/admin/search/features?${typeParams}`)
.get(`/api/admin/search/features?type=${typeParams}`)
.expect(expectedCode);
};

Expand Down Expand Up @@ -219,10 +218,9 @@ test('should filter features by type', async () => {
type: 'experimental',
});

const { body } = await filterFeaturesByType([
'experimental',
'kill-switch',
]);
const { body } = await filterFeaturesByType(
'IS_ANY_OF:experimental,kill-switch',
);

expect(body).toMatchObject({
features: [{ name: 'my_feature_b' }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface IFeatureSearchParams {
segment?: string;
createdAt?: string;
state?: string;
type?: string[];
type?: string;
tag?: string;
status?: string[][];
offset: number;
Expand Down
12 changes: 6 additions & 6 deletions src/lib/openapi/spec/feature-search-query-parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ export const featureSearchQueryParameters = [
{
name: 'type',
schema: {
type: 'array',
items: {
type: 'string',
example: 'release',
},
type: 'string',
example: 'IS:release',
pattern:
'^(IS|IS_NOT|IS_ANY_OF|IS_NONE_OF):(.*?)(,([a-zA-Z0-9_]+))*$',
},
description: 'The list of feature types to filter by',
description:
'The feature flag type to filter by. The type can be specified with an operator. The supported operators are IS, IS_NOT, IS_ANY_OF, IS_NONE_OF.',
in: 'query',
},
{
Expand Down

0 comments on commit 2069af4

Please sign in to comment.