2024-05-06 05:08:03 +00:00
|
|
|
import { useFormikContext } from 'formik';
|
|
|
|
|
|
|
|
import { GitForm } from '@/react/portainer/gitops/GitForm';
|
|
|
|
import { baseEdgeStackWebhookUrl } from '@/portainer/helpers/webhookHelper';
|
|
|
|
import { RelativePathFieldset } from '@/react/portainer/gitops/RelativePathFieldset/RelativePathFieldset';
|
|
|
|
import { applySetStateAction } from '@/react-tools/apply-set-state-action';
|
2024-12-04 18:00:40 +00:00
|
|
|
import { isBE } from '@/react/portainer/feature-flags/feature-flags.service';
|
2024-05-06 05:08:03 +00:00
|
|
|
|
|
|
|
import { BoxSelector } from '@@/BoxSelector';
|
|
|
|
import { FormSection } from '@@/form-components/FormSection';
|
|
|
|
import {
|
|
|
|
editor,
|
|
|
|
git,
|
|
|
|
edgeStackTemplate,
|
|
|
|
upload,
|
|
|
|
} from '@@/BoxSelector/common-options/build-methods';
|
|
|
|
import { FileUploadForm } from '@@/form-components/FileUpload';
|
|
|
|
|
|
|
|
import { TemplateFieldset } from './TemplateFieldset/TemplateFieldset';
|
2024-11-25 04:41:09 +00:00
|
|
|
import { useRenderCustomTemplate } from './useRenderCustomTemplate';
|
2024-05-06 05:08:03 +00:00
|
|
|
import { DockerFormValues } from './types';
|
2024-06-16 04:54:00 +00:00
|
|
|
import { DockerContentField } from './DockerContentField';
|
2024-11-25 04:41:09 +00:00
|
|
|
import { useRenderAppTemplate } from './useRenderAppTemplate';
|
2024-05-06 05:08:03 +00:00
|
|
|
|
|
|
|
const buildMethods = [editor, upload, git, edgeStackTemplate] as const;
|
|
|
|
|
|
|
|
export function DockerComposeForm({
|
|
|
|
webhookId,
|
|
|
|
onChangeTemplate,
|
|
|
|
}: {
|
|
|
|
webhookId: string;
|
|
|
|
onChangeTemplate: ({
|
|
|
|
type,
|
|
|
|
id,
|
|
|
|
}: {
|
|
|
|
type: 'app' | 'custom' | undefined;
|
|
|
|
id: number | undefined;
|
|
|
|
}) => void;
|
|
|
|
}) {
|
|
|
|
const { errors, values, setValues } = useFormikContext<DockerFormValues>();
|
|
|
|
const { method } = values;
|
|
|
|
|
2024-11-25 04:41:09 +00:00
|
|
|
const { customTemplate, isInitialLoading: isCustomTemplateLoading } =
|
|
|
|
useRenderCustomTemplate(values.templateValues, setValues);
|
|
|
|
const { appTemplate, isInitialLoading: isAppTemplateLoading } =
|
|
|
|
useRenderAppTemplate(values.templateValues, setValues);
|
|
|
|
|
|
|
|
const isTemplate =
|
|
|
|
method === edgeStackTemplate.value && (customTemplate || appTemplate);
|
|
|
|
const isTemplateLoading = isCustomTemplateLoading || isAppTemplateLoading;
|
2024-05-06 05:08:03 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<FormSection title="Build Method">
|
|
|
|
<BoxSelector
|
|
|
|
options={buildMethods}
|
|
|
|
onChange={(value) => handleChange({ method: value })}
|
|
|
|
value={method}
|
|
|
|
radioName="method"
|
|
|
|
slim
|
|
|
|
/>
|
|
|
|
</FormSection>
|
|
|
|
|
|
|
|
{method === edgeStackTemplate.value && (
|
|
|
|
<TemplateFieldset
|
|
|
|
values={values.templateValues}
|
|
|
|
setValues={(templateAction) =>
|
|
|
|
setValues((values) => {
|
|
|
|
const templateValues = applySetStateAction(
|
|
|
|
templateAction,
|
|
|
|
values.templateValues
|
|
|
|
);
|
|
|
|
onChangeTemplate({
|
|
|
|
id: templateValues.templateId,
|
|
|
|
type: templateValues.type,
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
...values,
|
|
|
|
templateValues,
|
|
|
|
};
|
|
|
|
})
|
|
|
|
}
|
|
|
|
errors={errors?.templateValues}
|
2024-11-25 04:41:09 +00:00
|
|
|
isLoadingValues={isTemplateLoading}
|
2024-05-06 05:08:03 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
|
2024-11-25 04:41:09 +00:00
|
|
|
{(method === editor.value || isTemplate) && !isTemplateLoading && (
|
2024-06-16 04:54:00 +00:00
|
|
|
<DockerContentField
|
2024-05-06 05:08:03 +00:00
|
|
|
value={values.fileContent}
|
|
|
|
onChange={(value) => handleChange({ fileContent: value })}
|
2024-11-25 04:41:09 +00:00
|
|
|
readonly={
|
|
|
|
method === edgeStackTemplate.value && !!customTemplate?.GitConfig
|
|
|
|
}
|
2024-06-16 04:54:00 +00:00
|
|
|
error={errors?.fileContent}
|
|
|
|
/>
|
2024-05-06 05:08:03 +00:00
|
|
|
)}
|
|
|
|
|
|
|
|
{method === upload.value && (
|
|
|
|
<FileUploadForm
|
|
|
|
value={values.file}
|
|
|
|
onChange={(File) => handleChange({ file: File })}
|
|
|
|
required
|
|
|
|
description="You can upload a Compose file from your computer."
|
|
|
|
data-cy="stack-creation-file-upload"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{method === git.value && (
|
|
|
|
<>
|
|
|
|
<GitForm
|
|
|
|
errors={errors?.git}
|
|
|
|
value={values.git}
|
|
|
|
onChange={(gitValues) =>
|
|
|
|
setValues((values) => ({
|
|
|
|
...values,
|
|
|
|
git: {
|
|
|
|
...values.git,
|
|
|
|
...gitValues,
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
baseWebhookUrl={baseEdgeStackWebhookUrl()}
|
|
|
|
webhookId={webhookId}
|
|
|
|
/>
|
|
|
|
|
2024-12-04 18:00:40 +00:00
|
|
|
{isBE && (
|
|
|
|
<FormSection title="Advanced configurations">
|
|
|
|
<RelativePathFieldset
|
|
|
|
values={values.relativePath}
|
|
|
|
gitModel={values.git}
|
|
|
|
onChange={(relativePath) =>
|
|
|
|
setValues((values) => ({
|
|
|
|
...values,
|
|
|
|
relativePath: {
|
|
|
|
...values.relativePath,
|
|
|
|
...relativePath,
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</FormSection>
|
|
|
|
)}
|
2024-05-06 05:08:03 +00:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
|
|
|
function handleChange(newValues: Partial<DockerFormValues>) {
|
|
|
|
setValues((values) => ({
|
|
|
|
...values,
|
|
|
|
...newValues,
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|