1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-19 13:29:41 +02:00

fix(app/edge-stack): edge stack create form validation (#343)

This commit is contained in:
LP B 2025-01-24 17:02:52 +01:00 committed by GitHub
parent 3ca5ab180f
commit b753371700
6 changed files with 38 additions and 43 deletions

View file

@ -29,13 +29,16 @@ export function CreateForm() {
const [webhookId] = useState(() => createWebhookId());
const [templateParams, setTemplateParams] = useTemplateParams();
const templateQuery = useTemplate(templateParams.type, templateParams.id);
const templateQuery = useTemplate(
templateParams.templateType,
templateParams.templateId
);
const validation = useValidation(templateQuery);
const mutation = useCreate({
webhookId,
template: templateQuery.customTemplate || templateQuery.appTemplate,
templateType: templateParams.type,
templateType: templateParams.templateType,
});
const initialValues = useInitialValues(templateQuery, templateParams);
@ -53,6 +56,7 @@ export function CreateForm() {
initialValues={initialValues}
onSubmit={mutation.onSubmit}
validationSchema={validation}
validateOnMount
>
<InnerForm
webhookId={webhookId}
@ -118,8 +122,8 @@ function useInitialValues(
customTemplate: CustomTemplate | undefined;
},
templateParams: {
id: number | undefined;
type: 'app' | 'custom' | undefined;
templateId: number | undefined;
templateType: 'app' | 'custom' | undefined;
}
) {
const template = templateQuery.customTemplate || templateQuery.appTemplate;
@ -139,7 +143,7 @@ function useInitialValues(
staggerConfig:
templateQuery.customTemplate?.EdgeSettings?.StaggerConfig ??
getDefaultStaggerConfig(),
method: templateParams.id ? 'template' : 'editor',
method: templateParams.templateId ? 'template' : 'editor',
git: toGitFormModel(
templateQuery.customTemplate?.GitConfig,
parseAutoUpdateResponse()
@ -149,19 +153,19 @@ function useInitialValues(
getDefaultRelativePathModel(),
enableWebhook: false,
fileContent: '',
templateValues: getTemplateValues(templateParams.type, template),
templateValues: getTemplateValues(templateParams.templateType, template),
useManifestNamespaces: false,
}),
[
templateQuery.customTemplate,
templateParams.id,
templateParams.type,
templateParams.templateId,
templateParams.templateType,
template,
]
);
if (
templateParams.id &&
templateParams.templateId &&
!templateQuery.customTemplate &&
!templateQuery.appTemplate
) {