@@ -26,6 +26,24 @@ function toPayload(item: ExampleItem): { [key: string]: any } {
26
26
}
27
27
}
28
28
29
+ /**
30
+ * Extracts a parameter value from a query string.
31
+ *
32
+ * @param {string } q - The query string to extract the parameter from.
33
+ * @param {string } name - The name of the parameter to extract.
34
+ * @return {Array } - A tuple containing the updated query string and the extracted parameter value.
35
+ * - If the parameter is not found, the extracted value will be null.
36
+ */
37
+ function extractParamFromQuery ( q : string , name : string ) : [ string , string | null ] {
38
+ const pattern = new RegExp ( `${ name } :(".+?"|\\S+)` )
39
+ if ( pattern . test ( q ) ) {
40
+ const value = pattern . exec ( q ) ! [ 1 ]
41
+ q = q . replace ( pattern , '' )
42
+ return [ q , value ]
43
+ }
44
+ return [ q , null ]
45
+ }
46
+
29
47
function buildQueryParams (
30
48
limit : any ,
31
49
offset : string ,
@@ -39,13 +57,17 @@ function buildQueryParams(
39
57
params . append ( 'confirmed' , isChecked )
40
58
params . append ( 'ordering' , ordering )
41
59
42
- const pattern = / l a b e l : ( " .+ ?" | \S + ) /
43
- if ( pattern . test ( q ) ) {
44
- const label = pattern . exec ( q ) ! [ 1 ]
45
- params . append ( 'label' , label . replace ( / " / g, '' ) )
46
- q = q . replace ( pattern , '' )
47
- }
48
- params . append ( 'q' , q )
60
+ const customParams = [ 'label' , 'assignee' ]
61
+ let updatedQuery : string = q
62
+ customParams . forEach ( ( param : string ) => {
63
+ let value : string | null
64
+ ; [ updatedQuery , value ] = extractParamFromQuery ( updatedQuery , param )
65
+ if ( value !== null ) {
66
+ params . append ( param , value )
67
+ }
68
+ } )
69
+
70
+ params . append ( 'q' , updatedQuery )
49
71
return params . toString ( )
50
72
}
51
73
0 commit comments