-
Notifications
You must be signed in to change notification settings - Fork 35
app-catalog: Display current and latest app versions in list #387
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 | ||||
---|---|---|---|---|---|---|
|
@@ -44,3 +44,32 @@ export function fetchChartValues(packageID: string, packageVersion: string) { | |||||
}, | ||||||
}).then(response => response.text()); | ||||||
} | ||||||
|
||||||
export async function fetchLatestAppVersion(chartName: string): Promise<string> { | ||||||
if (!chartName) { | ||||||
return '—'; | ||||||
} | ||||||
|
||||||
try { | ||||||
const url = new URL('https://artifacthub.io/api/v1/packages/search'); | ||||||
url.searchParams.set('offset', '0'); | ||||||
url.searchParams.set('limit', '5'); | ||||||
url.searchParams.set('facets', 'false'); | ||||||
url.searchParams.set('kind', '0'); | ||||||
url.searchParams.set('ts_query_web', chartName); | ||||||
|
||||||
const response = await fetch(url.toString()); | ||||||
const dataResponse = await response.json(); | ||||||
const packages: any[] = dataResponse?.packages ?? []; | ||||||
|
||||||
const lowerChartName = chartName.toLowerCase(); | ||||||
const selectedPackage = | ||||||
packages.find( | ||||||
p => p?.name?.toLowerCase() === lowerChartName || p?.normalized_name === lowerChartName | ||||||
) ?? packages[0]; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The fallback to
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one seems a valid point? |
||||||
|
||||||
return selectedPackage?.app_version ?? '—'; | ||||||
} catch { | ||||||
return '—'; | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -8,10 +8,22 @@ import { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} from '@kinvolk/headlamp-plugin/lib/CommonComponents'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { Box } from '@mui/material'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { useEffect, useState } from 'react'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { fetchLatestAppVersion } from '../../api/charts'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { listReleases } from '../../api/releases'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const formatVersion = (v?: string) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const s = (v ?? '').trim(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (!s || s === '—') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return '—'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return s.startsWith('v') ? s : `v${s}`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should add a v to it if it's not there. Some version numbers don't use v in there, so adding it could be confusing to people. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export default function ReleaseList({ fetchReleases = listReleases }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const [releases, setReleases] = useState<Array<any> | null>(null); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const [latestMap, setLatestMap] = useState<Record<string, string>>({}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fetchReleases().then(response => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -23,6 +35,21 @@ export default function ReleaseList({ fetchReleases = listReleases }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, []); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (!releases?.length) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
setLatestMap({}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Promise.all( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
releases.map(async r => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const chartName = r?.chart?.metadata?.name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const v = chartName ? await fetchLatestAppVersion(chartName).catch(() => '—') : '—'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return [r.name, v] as const; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+38
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This implementation makes parallel API calls for each release without any rate limiting or batching. Consider adding a delay between requests or implementing batching to avoid overwhelming the ArtifactHub API, especially with large numbers of installed applications.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems valid too? It looks like the exact rate limits are not documented: https://artifacthub.io/docs/topics/faq/#what-are-the-api-rate-limits I guess 100+ charts is not uncommon. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
).then(entries => setLatestMap(Object.fromEntries(entries))); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, [releases]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<SectionBox title="Installed" textAlign="center" paddingTop={2}> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<SimpleTable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -56,8 +83,12 @@ export default function ReleaseList({ fetchReleases = listReleases }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
getter: release => release.namespace, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
label: 'App Version', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
getter: release => release.chart.metadata.appVersion, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
label: 'Current Version', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
getter: release => formatVersion(release.chart.metadata.appVersion), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
label: 'Latest Version', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
getter: release => formatVersion(latestMap[release?.name]), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
label: 'Version', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one needs docs.