@@ -25,7 +25,7 @@ import { getAPI } from '@/api'
2525 * @param {string } itemsKey - Optional key for items array in response. If not provided, will be deduced from apiName
2626 * @returns {Promise<boolean> } - Returns true if no items exist (advisory should be shown), false otherwise
2727 */
28- export async function hasNoItems ( store , apiName , params = { } , filterFunc = null , itemsKey = null ) {
28+ export async function hasNoItems ( store , apiName , params = { } , filterFunc = null , responseKey = null , itemsKey = null ) {
2929 if ( ! ( apiName in store . getters . apis ) ) {
3030 return false
3131 }
@@ -55,22 +55,17 @@ export async function hasNoItems (store, apiName, params = {}, filterFunc = null
5555 allParams . pageSize = 1
5656 }
5757
58- console . debug ( `Checking if API ${ apiName } has no items with params` , allParams )
59-
6058 try {
6159 const json = await getAPI ( apiName , allParams )
6260 // Auto-derive response key: listNetworks -> listnetworksresponse
63- const responseKey = `${ apiName . toLowerCase ( ) } response`
64- const items = json ?. [ responseKey ] ?. [ itemsKey ] || [ ]
61+ const apiResponseKey = responseKey || `${ apiName . toLowerCase ( ) } response`
62+ const items = json ?. [ apiResponseKey ] ?. [ itemsKey ] || [ ]
6563 if ( filterFunc ) {
66- const a = ! items . some ( filterFunc )
67- console . debug ( `API ${ apiName } has ${ items . length } items, after filter has items: ${ items . filter ( filterFunc ) [ 0 ] } , returning ${ a } ` )
68- const it = items . filter ( filterFunc )
69- console . debug ( `Filtered items:` , it )
70- return a
64+ return ! items . some ( filterFunc )
7165 }
7266 return items . length === 0
7367 } catch ( error ) {
68+ console . error ( `Failed to fetch items for advisory check via API ${ apiName } ` , error )
7469 return false
7570 }
7671}
0 commit comments