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

feat: more powerful feature search by type (#7267)

This commit is contained in:
Mateusz Kwasniewski 2024-06-04 15:13:11 +02:00 committed by GitHub
parent 0db5bc193f
commit 2069af427a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 20 additions and 19 deletions

View File

@ -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]);

View File

@ -93,7 +93,6 @@ class FeatureSearchStore implements IFeatureSearchStore {
{
userId,
searchParams,
type,
status,
offset,
limit,
@ -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) {

View File

@ -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);
};
@ -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' }],

View File

@ -27,7 +27,7 @@ export interface IFeatureSearchParams {
segment?: string;
createdAt?: string;
state?: string;
type?: string[];
type?: string;
tag?: string;
status?: string[][];
offset: number;

View File

@ -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',
},
{