1-
2-
31// Build parameters object from props, filtering out undefined values
42export function buildParams ( props , filterKeys ) {
53 const params = { } ;
6-
4+
75 // Add filter parameters
8- filterKeys . forEach ( key => {
6+ filterKeys . forEach ( ( key ) => {
97 const propKey = toCamelCase ( key ) ;
108 if ( props [ propKey ] ) {
119 // Handle arrays by joining them with commas for the API
@@ -16,15 +14,15 @@ export function buildParams(props, filterKeys) {
1614 }
1715 }
1816 } ) ;
19-
17+
2018 // Add pagination parameters
2119 if ( props . limit !== undefined ) {
2220 params . limit = props . limit ;
2321 }
2422 if ( props . page !== undefined ) {
2523 params . page = props . page ;
2624 }
27-
25+
2826 return params ;
2927}
3028
@@ -35,53 +33,28 @@ export function toCamelCase(str) {
3533
3634// Convert camelCase to snake_case for API parameters
3735export function toSnakeCase ( str ) {
38- return str . replace ( / [ A - Z ] / g, letter => `_${ letter . toLowerCase ( ) } ` ) ;
36+ return str . replace ( / [ A - Z ] / g, ( letter ) => `_${ letter . toLowerCase ( ) } ` ) ;
3937}
4038
4139// Generate filter summary for execution summary
4240export function generateFilterSummary ( props , filterKeys ) {
4341 const appliedFilters = [ ] ;
44-
45- filterKeys . forEach ( key => {
42+
43+ filterKeys . forEach ( ( key ) => {
4644 const propKey = toCamelCase ( key ) ;
4745 const value = props [ propKey ] ;
4846 if ( value ) {
49- const label = key . replace ( / _ / g, " " ) . replace ( / \b \w / g, l => l . toUpperCase ( ) ) ;
47+ const label = key . replace ( / _ / g, " " ) . replace ( / \b \w / g, ( l ) => l . toUpperCase ( ) ) ;
5048 // Handle arrays by joining them for display
51- const displayValue = Array . isArray ( value ) ? value . join ( ", " ) : value ;
49+ const displayValue = Array . isArray ( value )
50+ ? value . join ( ", " )
51+ : value ;
5252 appliedFilters . push ( `${ label } : ${ displayValue } ` ) ;
5353 }
5454 } ) ;
55-
56- return appliedFilters . length > 0 ? ` with filters: ${ appliedFilters . join ( ", " ) } ` : "" ;
57- }
58-
59-
6055
61- // Generate props object for an endpoint
62- export function generateEndpointProps ( app , endpoint ) {
63- const props = {
64- [ app . app ] : app , // Add the app reference
65- } ;
66-
67- // Add filter props based on endpoint configuration
68- endpoint . filters . forEach ( filterKey => {
69- const propKey = toCamelCase ( filterKey ) ;
70- props [ propKey ] = {
71- type : "string" ,
72- label : filterKey . replace ( / _ / g, " " ) . replace ( / \b \w / g, l => l . toUpperCase ( ) ) ,
73- description : `Filter by ${ filterKey . replace ( / _ / g, " " ) } ` ,
74- optional : true ,
75- } ;
76- } ) ;
77-
78- // Add common pagination props
79- props . limit = {
80- propDefinition : [ app , "limit" ] ,
81- } ;
82- props . page = {
83- propDefinition : [ app , "page" ] ,
84- } ;
85-
86- return props ;
56+ return appliedFilters . length > 0
57+ ? ` with filters: ${ appliedFilters . join ( ", " ) } `
58+ : "" ;
8759}
60+
0 commit comments