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:
parent
0db5bc193f
commit
2069af427a
@ -75,6 +75,14 @@ export class FeatureSearchService {
|
|||||||
if (parsed) queryParams.push(parsed);
|
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) => {
|
['tag', 'segment', 'project'].forEach((field) => {
|
||||||
if (params[field]) {
|
if (params[field]) {
|
||||||
const parsed = this.parseOperatorValue(field, params[field]);
|
const parsed = this.parseOperatorValue(field, params[field]);
|
||||||
|
@ -93,7 +93,6 @@ class FeatureSearchStore implements IFeatureSearchStore {
|
|||||||
{
|
{
|
||||||
userId,
|
userId,
|
||||||
searchParams,
|
searchParams,
|
||||||
type,
|
|
||||||
status,
|
status,
|
||||||
offset,
|
offset,
|
||||||
limit,
|
limit,
|
||||||
@ -175,10 +174,6 @@ class FeatureSearchStore implements IFeatureSearchStore {
|
|||||||
'features.description',
|
'features.description',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (type) {
|
|
||||||
query.whereIn('features.type', type);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (status && status.length > 0) {
|
if (status && status.length > 0) {
|
||||||
query.where((builder) => {
|
query.where((builder) => {
|
||||||
for (const [envName, envStatus] of status) {
|
for (const [envName, envStatus] of status) {
|
||||||
|
@ -102,10 +102,9 @@ const searchFeaturesWithOffset = async (
|
|||||||
.expect(expectedCode);
|
.expect(expectedCode);
|
||||||
};
|
};
|
||||||
|
|
||||||
const filterFeaturesByType = async (types: string[], expectedCode = 200) => {
|
const filterFeaturesByType = async (typeParams: string, expectedCode = 200) => {
|
||||||
const typeParams = types.map((type) => `type[]=${type}`).join('&');
|
|
||||||
return app.request
|
return app.request
|
||||||
.get(`/api/admin/search/features?${typeParams}`)
|
.get(`/api/admin/search/features?type=${typeParams}`)
|
||||||
.expect(expectedCode);
|
.expect(expectedCode);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -219,10 +218,9 @@ test('should filter features by type', async () => {
|
|||||||
type: 'experimental',
|
type: 'experimental',
|
||||||
});
|
});
|
||||||
|
|
||||||
const { body } = await filterFeaturesByType([
|
const { body } = await filterFeaturesByType(
|
||||||
'experimental',
|
'IS_ANY_OF:experimental,kill-switch',
|
||||||
'kill-switch',
|
);
|
||||||
]);
|
|
||||||
|
|
||||||
expect(body).toMatchObject({
|
expect(body).toMatchObject({
|
||||||
features: [{ name: 'my_feature_b' }],
|
features: [{ name: 'my_feature_b' }],
|
||||||
|
@ -27,7 +27,7 @@ export interface IFeatureSearchParams {
|
|||||||
segment?: string;
|
segment?: string;
|
||||||
createdAt?: string;
|
createdAt?: string;
|
||||||
state?: string;
|
state?: string;
|
||||||
type?: string[];
|
type?: string;
|
||||||
tag?: string;
|
tag?: string;
|
||||||
status?: string[][];
|
status?: string[][];
|
||||||
offset: number;
|
offset: number;
|
||||||
|
@ -37,13 +37,13 @@ export const featureSearchQueryParameters = [
|
|||||||
{
|
{
|
||||||
name: 'type',
|
name: 'type',
|
||||||
schema: {
|
schema: {
|
||||||
type: 'array',
|
type: 'string',
|
||||||
items: {
|
example: 'IS:release',
|
||||||
type: 'string',
|
pattern:
|
||||||
example: 'release',
|
'^(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',
|
in: 'query',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user