-
Notifications
You must be signed in to change notification settings - Fork 1.3k
ui: refactor advisories enabled usage and more #12676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,71 @@ | ||||||||
| // Licensed to the Apache Software Foundation (ASF) under one | ||||||||
| // or more contributor license agreements. See the NOTICE file | ||||||||
| // distributed with this work for additional information | ||||||||
| // regarding copyright ownership. The ASF licenses this file | ||||||||
| // to you under the Apache License, Version 2.0 (the | ||||||||
| // "License"); you may not use this file except in compliance | ||||||||
| // with the License. You may obtain a copy of the License at | ||||||||
| // | ||||||||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||||||||
| // | ||||||||
| // Unless required by applicable law or agreed to in writing, | ||||||||
| // software distributed under the License is distributed on an | ||||||||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||||||||
| // KIND, either express or implied. See the License for the | ||||||||
| // specific language governing permissions and limitations | ||||||||
| // under the License. | ||||||||
| import { getAPI } from '@/api' | ||||||||
|
|
||||||||
| /** | ||||||||
| * Generic helper to check if an API has no items (useful for advisory conditions) | ||||||||
| * @param {Object} store - Vuex store instance | ||||||||
| * @param {string} apiName - Name of the API to call (e.g., 'listNetworks') | ||||||||
| * @param {Object} params - Optional parameters to merge with defaults | ||||||||
| * @param {Function} filterFunc - Optional function to filter items. If provided, returns true if no items match the filter. | ||||||||
| * @param {string} itemsKey - Optional key for items array in response. If not provided, will be deduced from apiName | ||||||||
| * @returns {Promise<boolean>} - Returns true if no items exist (advisory should be shown), false otherwise | ||||||||
| */ | ||||||||
| export async function hasNoItems (store, apiName, params = {}, filterFunc = null, responseKey = null, itemsKey = null) { | ||||||||
| if (!(apiName in store.getters.apis)) { | ||||||||
| return false | ||||||||
| } | ||||||||
|
|
||||||||
| // If itemsKey not provided, deduce it from apiName | ||||||||
| if (!itemsKey) { | ||||||||
| // Remove 'list' prefix: listNetworks -> Networks | ||||||||
| let key = apiName.replace(/^list/i, '') | ||||||||
| // Convert to lowercase | ||||||||
| key = key.toLowerCase() | ||||||||
| // Handle plural forms: remove trailing 's' or convert 'ies' to 'y' | ||||||||
| if (key.endsWith('ies')) { | ||||||||
| key = key.slice(0, -3) + 'y' | ||||||||
| } else if (key.endsWith('s')) { | ||||||||
| key = key.slice(0, -1) | ||||||||
| } | ||||||||
| itemsKey = key | ||||||||
| } | ||||||||
|
|
||||||||
| const allParams = { | ||||||||
| listall: true, | ||||||||
| ...params | ||||||||
| } | ||||||||
|
|
||||||||
| if (filterFunc == null) { | ||||||||
| allParams.page = 1 | ||||||||
| allParams.pageSize = 1 | ||||||||
| } | ||||||||
|
|
||||||||
| try { | ||||||||
| const json = await getAPI(apiName, allParams) | ||||||||
| // Auto-derive response key: listNetworks -> listnetworksresponse | ||||||||
| const apiResponseKey = responseKey || `${apiName.toLowerCase()}response` | ||||||||
| const items = json?.[apiResponseKey]?.[itemsKey] || [] | ||||||||
| if (filterFunc) { | ||||||||
| return !items.some(filterFunc) | ||||||||
| } | ||||||||
| return items.length === 0 | ||||||||
| } catch (error) { | ||||||||
|
||||||||
| } catch (error) { | |
| } catch (error) { | |
| console.error(`Failed to fetch items for advisory check via API ${apiName}`, error) |
Uh oh!
There was an error while loading. Please reload this page.