fix(gitops): fix cursor jumps

pull/10737/head
Chaim Lev-Ari 2023-12-07 10:04:02 +01:00
parent 8567d7fa37
commit f94fb7fedd
2 changed files with 8 additions and 2 deletions

View File

@ -1,5 +1,6 @@
import { FormikErrors } from 'formik'; import { FormikErrors } from 'formik';
import { boolean, number, object, SchemaOf, string } from 'yup'; import { boolean, number, object, SchemaOf, string } from 'yup';
import { useState } from 'react';
import { GitAuthModel } from '@/react/portainer/gitops/types'; import { GitAuthModel } from '@/react/portainer/gitops/types';
import { useDebounce } from '@/react/hooks/useDebounce'; import { useDebounce } from '@/react/hooks/useDebounce';
@ -23,11 +24,12 @@ interface Props {
} }
export function AuthFieldset({ export function AuthFieldset({
value, value: initialValue,
onChange, onChange,
isAuthExplanationVisible, isAuthExplanationVisible,
errors, errors,
}: Props) { }: Props) {
const [value, setValue] = useState(initialValue); // TODO: remove this state when form is not inside angularjs
const [username, setUsername] = useDebounce( const [username, setUsername] = useDebounce(
value.RepositoryUsername || '', value.RepositoryUsername || '',
(username) => handleChange({ RepositoryUsername: username }) (username) => handleChange({ RepositoryUsername: username })
@ -139,6 +141,7 @@ export function AuthFieldset({
function handleChange(partialValue: Partial<GitAuthModel>) { function handleChange(partialValue: Partial<GitAuthModel>) {
onChange(partialValue); onChange(partialValue);
setValue((value) => ({ ...value, ...partialValue }));
} }
} }

View File

@ -1,5 +1,6 @@
import { array, boolean, object, SchemaOf, string } from 'yup'; import { array, boolean, object, SchemaOf, string } from 'yup';
import { FormikErrors } from 'formik'; import { FormikErrors } from 'formik';
import { useState } from 'react';
import { ComposePathField } from '@/react/portainer/gitops/ComposePathField'; import { ComposePathField } from '@/react/portainer/gitops/ComposePathField';
import { RefField } from '@/react/portainer/gitops/RefField'; import { RefField } from '@/react/portainer/gitops/RefField';
@ -35,7 +36,7 @@ interface Props {
} }
export function GitForm({ export function GitForm({
value, value: initialValue,
onChange, onChange,
environmentType = 'DOCKER', environmentType = 'DOCKER',
deployMethod = 'compose', deployMethod = 'compose',
@ -48,6 +49,7 @@ export function GitForm({
webhookId, webhookId,
webhooksDocs, webhooksDocs,
}: Props) { }: Props) {
const [value, setValue] = useState(initialValue); // TODO: remove this state when form is not inside angularjs
return ( return (
<FormSection title="Git repository"> <FormSection title="Git repository">
<AuthFieldset <AuthFieldset
@ -126,6 +128,7 @@ export function GitForm({
function handleChange(partialValue: Partial<GitFormModel>) { function handleChange(partialValue: Partial<GitFormModel>) {
onChange(partialValue); onChange(partialValue);
setValue((value) => ({ ...value, ...partialValue }));
} }
} }