fix(edge/stacks): show registry field for git [EE-5742] (#9217)

pull/9231/head
Chaim Lev-Ari 1 year ago committed by GitHub
parent 5ad83d0adb
commit fa755ffbca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -26,6 +26,8 @@ import { useCurrentUser } from '@/react/hooks/useUser';
import { useCreateGitCredentialMutation } from '@/react/portainer/account/git-credentials/git-credentials.service'; import { useCreateGitCredentialMutation } from '@/react/portainer/account/git-credentials/git-credentials.service';
import { notifyError, notifySuccess } from '@/portainer/services/notifications'; import { notifyError, notifySuccess } from '@/portainer/services/notifications';
import { EnvironmentType } from '@/react/portainer/environments/types'; import { EnvironmentType } from '@/react/portainer/environments/types';
import { Registry } from '@/react/portainer/registries/types';
import { useRegistries } from '@/react/portainer/registries/queries/useRegistries';
import { LoadingButton } from '@@/buttons'; import { LoadingButton } from '@@/buttons';
import { FormSection } from '@@/form-components/FormSection'; import { FormSection } from '@@/form-components/FormSection';
@ -36,8 +38,12 @@ import { EnvVar } from '@@/form-components/EnvironmentVariablesFieldset/types';
import { useValidateEnvironmentTypes } from '../useEdgeGroupHasType'; import { useValidateEnvironmentTypes } from '../useEdgeGroupHasType';
import { atLeastTwo } from '../atLeastTwo'; import { atLeastTwo } from '../atLeastTwo';
import { PrivateRegistryFieldset } from '../../../components/PrivateRegistryFieldset';
import { useUpdateEdgeStackGitMutation } from './useUpdateEdgeStackGitMutation'; import {
UpdateEdgeStackGitPayload,
useUpdateEdgeStackGitMutation,
} from './useUpdateEdgeStackGitMutation';
interface FormValues { interface FormValues {
groupIds: EdgeGroup['Id'][]; groupIds: EdgeGroup['Id'][];
@ -46,6 +52,7 @@ interface FormValues {
refName: string; refName: string;
authentication: GitAuthModel; authentication: GitAuthModel;
envVars: EnvVar[]; envVars: EnvVar[];
privateRegistryId?: Registry['Id'];
} }
export function GitForm({ stack }: { stack: EdgeStack }) { export function GitForm({ stack }: { stack: EdgeStack }) {
@ -117,10 +124,10 @@ export function GitForm({ stack }: { stack: EdgeStack }) {
} }
function getPayload( function getPayload(
{ authentication, autoUpdate, ...values }: FormValues, { authentication, autoUpdate, privateRegistryId, ...values }: FormValues,
credentialId: number | undefined, credentialId: number | undefined,
updateVersion: boolean updateVersion: boolean
) { ): UpdateEdgeStackGitPayload {
return { return {
updateVersion, updateVersion,
id: stack.Id, id: stack.Id,
@ -129,6 +136,10 @@ export function GitForm({ stack }: { stack: EdgeStack }) {
RepositoryGitCredentialID: credentialId, RepositoryGitCredentialID: credentialId,
}), }),
autoUpdate: transformAutoUpdateViewModel(autoUpdate, webhookId), autoUpdate: transformAutoUpdateViewModel(autoUpdate, webhookId),
registries:
typeof privateRegistryId !== 'undefined'
? [privateRegistryId]
: undefined,
...values, ...values,
}; };
} }
@ -173,6 +184,7 @@ function InnerForm({
onUpdateSettingsClick(): void; onUpdateSettingsClick(): void;
webhookId: string; webhookId: string;
}) { }) {
const registriesQuery = useRegistries();
const { values, setFieldValue, isValid, handleSubmit, errors, dirty } = const { values, setFieldValue, isValid, handleSubmit, errors, dirty } =
useFormikContext<FormValues>(); useFormikContext<FormValues>();
@ -265,6 +277,15 @@ function InnerForm({
/> />
</FormSection> </FormSection>
<PrivateRegistryFieldset
value={values.privateRegistryId}
onSelect={(value) => setFieldValue('privateRegistryId', value)}
registries={registriesQuery.data ?? []}
formInvalid={!isValid}
method="repository"
errorMessage={errors.privateRegistryId}
/>
<FormSection title="Actions"> <FormSection title="Actions">
<LoadingButton <LoadingButton
disabled={dirty || !isValid || isLoading} disabled={dirty || !isValid || isLoading}

@ -9,8 +9,9 @@ import {
import { buildUrl } from '@/react/edge/edge-stacks/queries/buildUrl'; import { buildUrl } from '@/react/edge/edge-stacks/queries/buildUrl';
import { DeploymentType, EdgeStack } from '@/react/edge/edge-stacks/types'; import { DeploymentType, EdgeStack } from '@/react/edge/edge-stacks/types';
import { EdgeGroup } from '@/react/edge/edge-groups/types'; import { EdgeGroup } from '@/react/edge/edge-groups/types';
import { Registry } from '@/react/portainer/registries/types';
interface UpdateEdgeStackGitPayload { export interface UpdateEdgeStackGitPayload {
id: EdgeStack['Id']; id: EdgeStack['Id'];
autoUpdate: AutoUpdateResponse | null; autoUpdate: AutoUpdateResponse | null;
refName: string; refName: string;
@ -18,6 +19,7 @@ interface UpdateEdgeStackGitPayload {
groupIds: EdgeGroup['Id'][]; groupIds: EdgeGroup['Id'][];
deploymentType: DeploymentType; deploymentType: DeploymentType;
updateVersion: boolean; updateVersion: boolean;
registries?: Array<Registry['Id']>;
} }
export function useUpdateEdgeStackGitMutation() { export function useUpdateEdgeStackGitMutation() {

@ -14,24 +14,24 @@ import { FormSection } from '@@/form-components/FormSection';
interface Props { interface Props {
value?: number; value?: number;
registries: Registry[]; registries: Registry[];
onChange: () => void; onChange?: () => void;
formInvalid?: boolean; formInvalid?: boolean;
errorMessage?: string; errorMessage?: string;
onSelect: (value?: number) => void; onSelect: (value?: number) => void;
isActive?: boolean; isActive?: boolean;
clearRegistries: () => void; clearRegistries?: () => void;
method?: string; method?: 'repository' | string;
} }
export function PrivateRegistryFieldset({ export function PrivateRegistryFieldset({
value, value,
registries, registries,
onChange, onChange = () => {},
formInvalid, formInvalid,
errorMessage, errorMessage,
onSelect, onSelect,
isActive, isActive,
clearRegistries, clearRegistries = () => {},
method, method,
}: Props) { }: Props) {
const [checked, setChecked] = useState(isActive || false); const [checked, setChecked] = useState(isActive || false);

Loading…
Cancel
Save