mirror of
https://github.com/portainer/portainer.git
synced 2025-07-19 05:19:39 +02:00
feat(oci): oci helm support [r8s-361] (#787)
This commit is contained in:
parent
b6a6ce9aaf
commit
2697d6c5d7
80 changed files with 4264 additions and 812 deletions
|
@ -1,6 +1,5 @@
|
|||
import { useQueries } from '@tanstack/react-query';
|
||||
import { compact, flatMap } from 'lodash';
|
||||
import { useMemo } from 'react';
|
||||
import { compact } from 'lodash';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import axios from '@/portainer/services/axios';
|
||||
import { withGlobalError } from '@/react-tools/react-query';
|
||||
|
@ -8,45 +7,27 @@ import { withGlobalError } from '@/react-tools/react-query';
|
|||
import { Chart, HelmChartsResponse } from '../types';
|
||||
|
||||
/**
|
||||
* React hook to fetch helm charts from the provided repositories
|
||||
* Charts from each repository are loaded independently, allowing the UI
|
||||
* to show charts as they become available instead of waiting for all
|
||||
* repositories to load
|
||||
* React hook to fetch helm charts from the provided HTTP repository.
|
||||
* Charts are loaded from the specified repository URL.
|
||||
*
|
||||
* @param userId User ID
|
||||
* @param repositories List of repository URLs to fetch charts from
|
||||
* @param repository Repository URL to fetch charts from
|
||||
* @param enabled Flag indicating if the query should be enabled
|
||||
* @returns Query result containing helm charts
|
||||
*/
|
||||
export function useHelmChartList(userId: number, repositories: string[] = []) {
|
||||
// Fetch charts from each repository in parallel as separate queries
|
||||
const chartQueries = useQueries({
|
||||
queries: useMemo(
|
||||
() =>
|
||||
repositories.map((repo) => ({
|
||||
queryKey: [userId, repo, 'helm-charts'],
|
||||
queryFn: () => getChartsFromRepo(repo),
|
||||
enabled: !!userId && repositories.length > 0,
|
||||
// one request takes a long time, so fail early to get feedback to the user faster
|
||||
retries: false,
|
||||
...withGlobalError(`Unable to retrieve Helm charts from ${repo}`),
|
||||
})),
|
||||
[repositories, userId]
|
||||
),
|
||||
export function useHelmHTTPChartList(
|
||||
userId: number,
|
||||
repository: string,
|
||||
enabled: boolean
|
||||
) {
|
||||
return useQuery({
|
||||
queryKey: [userId, repository, 'helm-charts'],
|
||||
queryFn: () => getChartsFromRepo(repository),
|
||||
enabled: !!userId && !!repository && enabled,
|
||||
// one request takes a long time, so fail early to get feedback to the user faster
|
||||
retry: false,
|
||||
...withGlobalError(`Unable to retrieve Helm charts from ${repository}`),
|
||||
});
|
||||
|
||||
// Combine the results for easier consumption by components
|
||||
const allCharts = useMemo(
|
||||
() => flatMap(compact(chartQueries.map((q) => q.data))),
|
||||
[chartQueries]
|
||||
);
|
||||
|
||||
return {
|
||||
// Data from all repositories that have loaded so far
|
||||
data: allCharts,
|
||||
// Overall loading state
|
||||
isInitialLoading: chartQueries.some((q) => q.isInitialLoading),
|
||||
// Overall error state
|
||||
isError: chartQueries.some((q) => q.isError),
|
||||
};
|
||||
}
|
||||
|
||||
async function getChartsFromRepo(repo: string): Promise<Chart[]> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue