1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-02 20:35:25 +02:00

chore(template/git): sync frontend code from ee (#11343)

This commit is contained in:
Oscar Zhou 2024-03-18 08:55:26 +13:00 committed by GitHub
parent 04de06c07f
commit d9ae249ffe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 77 additions and 16 deletions

View file

@ -147,7 +147,8 @@ export function AuthFieldset({
export function gitAuthValidation(
gitCredentials: Array<GitCredential>,
isAuthEdit: boolean
isAuthEdit: boolean,
isCreatedFromCustomTemplate: boolean
): SchemaOf<GitAuthModel> {
return object({
RepositoryAuthentication: boolean().default(false),
@ -160,7 +161,8 @@ export function gitAuthValidation(
.default(''),
RepositoryPassword: string()
.when(['RepositoryAuthentication', 'RepositoryGitCredentialID'], {
is: (auth: boolean, id: number) => auth && !id && !isAuthEdit,
is: (auth: boolean, id: number) =>
auth && !id && !isAuthEdit && !isCreatedFromCustomTemplate,
then: string().required('Password is required'),
})
.default(''),

View file

@ -16,6 +16,7 @@ interface Props {
isCompose: boolean;
model: GitFormModel;
isDockerStandalone: boolean;
createdFromCustomTemplateId?: number;
}
export function ComposePathField({
@ -25,6 +26,7 @@ export function ComposePathField({
model,
isDockerStandalone,
errors,
createdFromCustomTemplateId,
}: Props) {
const [inputValue, updateInputValue] = useStateWrapper(value, onChange);
@ -64,6 +66,7 @@ export function ComposePathField({
placeholder={isCompose ? 'docker-compose.yml' : 'manifest.yml'}
model={model}
inputId="stack_repository_path"
createdFromCustomTemplateId={createdFromCustomTemplateId}
/>
) : (
<Input

View file

@ -13,6 +13,7 @@ export function PathSelector({
dirOnly,
readOnly,
inputId,
createdFromCustomTemplateId,
}: {
value: string;
onChange(value: string): void;
@ -21,6 +22,7 @@ export function PathSelector({
dirOnly?: boolean;
readOnly?: boolean;
inputId: string;
createdFromCustomTemplateId?: number;
}) {
const creds = getAuthentication(model);
const payload = {
@ -29,6 +31,7 @@ export function PathSelector({
reference: model.RepositoryReferenceName,
tlsSkipVerify: model.TLSSkipVerify,
dirOnly,
createdFromCustomTemplateId,
...creds,
};
const enabled = Boolean(

View file

@ -73,7 +73,7 @@ export function Primary({
return (
<Formik
initialValues={initialValues}
validationSchema={() => buildGitValidationSchema([])}
validationSchema={() => buildGitValidationSchema([], false)}
onSubmit={() => {}}
>
{({ values, errors, setValues }) => (

View file

@ -34,6 +34,7 @@ interface Props {
baseWebhookUrl?: string;
webhookId?: string;
webhooksDocs?: string;
createdFromCustomTemplateId?: number;
}
export function GitForm({
@ -49,6 +50,7 @@ export function GitForm({
baseWebhookUrl,
webhookId,
webhooksDocs,
createdFromCustomTemplateId,
}: Props) {
const [value, setValue] = useState(initialValue); // TODO: remove this state when form is not inside angularjs
const webhooksDocsUrl = useDocsUrl(webhooksDocs);
@ -69,6 +71,7 @@ export function GitForm({
handleChange({ RepositoryURLValid: value })
}
model={value}
createdFromCustomTemplateId={createdFromCustomTemplateId}
errors={errors.RepositoryURL}
/>
@ -78,6 +81,7 @@ export function GitForm({
model={value}
error={errors.RepositoryReferenceName}
isUrlValid={value.RepositoryURLValid}
createdFromCustomTemplateId={createdFromCustomTemplateId}
/>
<ComposePathField
@ -89,6 +93,7 @@ export function GitForm({
model={value}
isDockerStandalone={isDockerStandalone}
errors={errors.ComposeFilePathInRepository}
createdFromCustomTemplateId={createdFromCustomTemplateId}
/>
{isAdditionalFilesFieldVisible && (
@ -137,16 +142,18 @@ export function GitForm({
export async function validateGitForm(
gitCredentials: Array<GitCredential>,
formValues: GitFormModel
formValues: GitFormModel,
isCreatedFromCustomTemplate: boolean
) {
return validateForm<GitFormModel>(
() => buildGitValidationSchema(gitCredentials),
() => buildGitValidationSchema(gitCredentials, isCreatedFromCustomTemplate),
formValues
);
}
export function buildGitValidationSchema(
gitCredentials: Array<GitCredential>
gitCredentials: Array<GitCredential>,
isCreatedFromCustomTemplate: boolean
): SchemaOf<GitFormModel> {
return object({
RepositoryURL: string()
@ -171,5 +178,7 @@ export function buildGitValidationSchema(
RepositoryURLValid: boolean().default(false),
AutoUpdate: autoUpdateValidation().nullable(),
TLSSkipVerify: boolean().default(false),
}).concat(gitAuthValidation(gitCredentials, false)) as SchemaOf<GitFormModel>;
}).concat(
gitAuthValidation(gitCredentials, false, isCreatedFromCustomTemplate)
) as SchemaOf<GitFormModel>;
}

View file

@ -26,6 +26,7 @@ interface Props {
onChange(value: string): void;
onChangeRepositoryValid(value: boolean): void;
model: GitFormModel;
createdFromCustomTemplateId?: number;
errors?: string;
}
@ -34,6 +35,7 @@ export function GitFormUrlField({
onChange,
onChangeRepositoryValid,
model,
createdFromCustomTemplateId,
errors,
}: Props) {
const queryClient = useQueryClient();
@ -42,7 +44,12 @@ export function GitFormUrlField({
const [force, setForce] = useState(false);
const repoStatusQuery = useCheckRepo(
value,
{ creds, force, tlsSkipVerify: model.TLSSkipVerify },
{
creds,
force,
tlsSkipVerify: model.TLSSkipVerify,
createdFromCustomTemplateId,
},
{
onSettled(isValid) {
onChangeRepositoryValid(!!isValid);

View file

@ -20,6 +20,7 @@ interface Props {
error?: string;
isUrlValid?: boolean;
stackId?: StackId;
createdFromCustomTemplateId?: number;
}
export function RefField({
@ -29,6 +30,7 @@ export function RefField({
error,
isUrlValid,
stackId,
createdFromCustomTemplateId,
}: Props) {
const [inputValue, updateInputValue] = useStateWrapper(value, onChange);
const inputId = 'repository-reference-field';
@ -51,6 +53,7 @@ export function RefField({
model={model}
isUrlValid={isUrlValid}
stackId={stackId}
createdFromCustomTemplateId={createdFromCustomTemplateId}
/>
</Wrapper>
) : (

View file

@ -13,11 +13,13 @@ export function RefSelector({
onChange,
isUrlValid,
stackId,
createdFromCustomTemplateId,
inputId,
}: {
model: RefFieldModel;
value: string;
stackId?: StackId;
createdFromCustomTemplateId?: number;
onChange: (value: string) => void;
isUrlValid?: boolean;
inputId: string;
@ -26,6 +28,7 @@ export function RefSelector({
const payload = {
repository: model.RepositoryURL,
stackId,
createdFromCustomTemplateId,
tlsSkipVerify: model.TLSSkipVerify,
...creds,
};

View file

@ -15,6 +15,7 @@ interface CheckRepoOptions {
creds?: Creds;
force?: boolean;
tlsSkipVerify?: boolean;
createdFromCustomTemplateId?: number;
}
export function useCheckRepo(
@ -43,7 +44,12 @@ export async function checkRepo(
try {
await axios.post<string[]>(
'/gitops/repo/refs',
{ repository, tlsSkipVerify: options.tlsSkipVerify, ...options.creds },
{
repository,
tlsSkipVerify: options.tlsSkipVerify,
createdFromCustomTemplateId: options.createdFromCustomTemplateId,
...options.creds,
},
force ? { params: { force } } : {}
);
return true;

View file

@ -6,6 +6,7 @@ interface RefsPayload {
repository: string;
username?: string;
password?: string;
createdFromCustomTemplateID?: number;
tlsSkipVerify?: boolean;
}

View file

@ -9,6 +9,7 @@ interface SearchPayload {
username?: string;
password?: string;
tlsSkipVerify?: boolean;
createdFromCustomTemplateId?: number;
}
export function useSearch(payload: SearchPayload, enabled: boolean) {

View file

@ -57,7 +57,8 @@ export function useValidation({
}),
Git: mixed().when('Method', {
is: git.value,
then: () => buildGitValidationSchema(gitCredentialsQuery.data || []),
then: () =>
buildGitValidationSchema(gitCredentialsQuery.data || [], false),
}),
Variables: variablesValidation(),
EdgeSettings: viewType === 'edge' ? edgeFieldsetValidation() : mixed(),

View file

@ -47,7 +47,7 @@ export function useValidation({
FileContent: string().required('Template is required.'),
Git: isGit
? buildGitValidationSchema(gitCredentialsQuery.data || [])
? buildGitValidationSchema(gitCredentialsQuery.data || [], false)
: mixed(),
Variables: variablesValidation(),
EdgeSettings: viewType === 'edge' ? edgeFieldsetValidation() : mixed(),