mirror of
https://github.com/portainer/portainer.git
synced 2025-08-08 23:35:31 +02:00
fix(app templates): load app template for deployment [BE-11382] (#141)
This commit is contained in:
parent
20e3d3a15b
commit
c0c7144539
23 changed files with 453 additions and 60 deletions
|
@ -26,11 +26,11 @@ export function HelmRepositoryDatatableActions({ selectedItems }: Props) {
|
|||
'repository',
|
||||
'repositories'
|
||||
)}?`}
|
||||
data-cy="credentials-deleteButton"
|
||||
data-cy="helmRepository-deleteButton"
|
||||
/>
|
||||
<AddButton
|
||||
to="portainer.account.createHelmRepository"
|
||||
data-cy="credentials-addButton"
|
||||
data-cy="helmRepository-addButton"
|
||||
>
|
||||
Add Helm repository
|
||||
</AddButton>
|
||||
|
|
|
@ -6,9 +6,12 @@ import { AppTemplate } from '../types';
|
|||
|
||||
import { buildUrl } from './build-url';
|
||||
|
||||
export function useFetchTemplateFile(id?: AppTemplate['id']) {
|
||||
export function useAppTemplateFile(
|
||||
id?: AppTemplate['id'],
|
||||
{ enabled }: { enabled?: boolean } = {}
|
||||
) {
|
||||
return useQuery(['templates', id, 'file'], () => fetchFilePreview(id!), {
|
||||
enabled: !!id,
|
||||
enabled: !!id && enabled,
|
||||
});
|
||||
}
|
||||
|
|
@ -12,6 +12,11 @@ import { TemplateViewModel } from '../view-model';
|
|||
|
||||
import { buildUrl } from './build-url';
|
||||
|
||||
export type AppTemplatesResponse = {
|
||||
version: string;
|
||||
templates: Array<AppTemplate>;
|
||||
};
|
||||
|
||||
export function useAppTemplates<T = Array<TemplateViewModel>>({
|
||||
environmentId,
|
||||
select,
|
||||
|
@ -43,15 +48,10 @@ export function useAppTemplate(
|
|||
id: AppTemplate['id'] | undefined,
|
||||
{ enabled }: { enabled?: boolean } = {}
|
||||
) {
|
||||
const templateListQuery = useAppTemplates({ enabled: !!id && enabled });
|
||||
|
||||
const template = templateListQuery.data?.find((t) => t.Id === id);
|
||||
|
||||
return {
|
||||
data: template,
|
||||
isLoading: templateListQuery.isInitialLoading,
|
||||
error: templateListQuery.error,
|
||||
};
|
||||
return useAppTemplates({
|
||||
enabled: !!id && enabled,
|
||||
select: (templates) => templates.find((t) => t.Id === id),
|
||||
});
|
||||
}
|
||||
|
||||
async function getTemplatesWithRegistry(
|
||||
|
@ -75,10 +75,7 @@ async function getTemplatesWithRegistry(
|
|||
|
||||
export async function getAppTemplates() {
|
||||
try {
|
||||
const { data } = await axios.get<{
|
||||
version: string;
|
||||
templates: Array<AppTemplate>;
|
||||
}>(buildUrl());
|
||||
const { data } = await axios.get<AppTemplatesResponse>(buildUrl());
|
||||
return data;
|
||||
} catch (err) {
|
||||
throw parseAxiosError(err);
|
||||
|
|
|
@ -5,7 +5,7 @@ import { useCurrentUser } from '@/react/hooks/useUser';
|
|||
import { StackType } from '@/react/common/stacks/types';
|
||||
|
||||
import { Platform } from '../../types';
|
||||
import { useFetchTemplateFile } from '../../app-templates/queries/useFetchTemplateFile';
|
||||
import { useAppTemplateFile } from '../../app-templates/queries/useAppTemplateFile';
|
||||
import { getDefaultEdgeTemplateSettings } from '../types';
|
||||
|
||||
import { FormValues, Method } from './types';
|
||||
|
@ -31,7 +31,7 @@ export function useInitialValues({
|
|||
params: { fileContent = '' },
|
||||
} = useCurrentStateAndParams();
|
||||
|
||||
const fileContentQuery = useFetchTemplateFile(appTemplateId);
|
||||
const fileContentQuery = useAppTemplateFile(appTemplateId);
|
||||
if (fileContentQuery.isInitialLoading) {
|
||||
return undefined;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue